forked from zrax/pycdc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more advanced round-trip test target that runs decompiled output …
…back through the originating Python compiler (Linux only for now)
- Loading branch information
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/bin/bash | ||
|
||
testdir="$1" | ||
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
startdir="$(pwd)" | ||
|
||
if [[ -z "$testdir" ]]; then | ||
echo "Missing required parameter: testdir" >&2 | ||
exit 1 | ||
fi | ||
|
||
py_versions=('1.5.2' '2.2.3' '2.5.6' '2.6.9' '2.7.12' '3.1.5' '3.4.5' '3.5.2') | ||
py_url="http://www.python.org/ftp/python" | ||
|
||
# Make subcommand errors fatal | ||
set -e | ||
|
||
fetch_python() { | ||
local url="$1" | ||
local tarball="${url##*/}" | ||
local version="$2" | ||
|
||
if [[ ! -d "Python-${version}" ]]; then | ||
echo "Downloading Python ${version}" | ||
curl -LO# "$url" | ||
tar xzf "$tarball" | ||
if [[ -f "${srcdir}/tests/python-builds/Python-${version}.patch" ]]; then | ||
cd "Python-${version}" | ||
patch -p1 < "${srcdir}/tests/python-builds/Python-${version}.patch" | ||
cd .. | ||
fi | ||
fi | ||
} | ||
|
||
cd "$startdir" | ||
mkdir -p python-builds | ||
cd python-builds | ||
|
||
# Special case for Python 1.5 | ||
fetch_python "${py_url}/src/py152.tgz" "1.5.2" | ||
|
||
for pv in ${py_versions[@]:1}; do | ||
fetch_python "${py_url}/${pv}/Python-${pv}.tgz" "$pv" | ||
done | ||
|
||
for pv in ${py_versions[@]}; do | ||
if [[ ! -x "Python-${pv}/python" ]]; then | ||
echo -n "Building Python ${pv}... " | ||
cd "Python-${pv}" | ||
rm -f "../Python-${pv}.conf.log" | ||
rm -f "../Python-${pv}.build.log" | ||
if ! ./configure > "../Python-${pv}.conf.log" 2>&1 ; then | ||
echo "Configure failed!" | ||
echo "See python-builds/Python-${pv}.conf.log for details" | ||
exit 1 | ||
fi | ||
if ! make > "../Python-${pv}.build.log" 2>&1 ; then | ||
echo "Build failed!" | ||
echo "See python-builds/Python-${pv}.build.log for details" | ||
exit 1 | ||
fi | ||
cd .. | ||
echo "Success!" | ||
fi | ||
done | ||
|
||
# Run any .pyc.src files in $testdir back through its respective python compiler | ||
cd "$startdir" | ||
|
||
fails=0 | ||
files=() | ||
errors=() | ||
|
||
set +e | ||
|
||
for srcf in "$testdir"/*.pyc.src; do | ||
# There's probably a better way... | ||
srcver=$(grep '# File: .* (Python [0-9]\.[0-9]\+)$' "$srcf" | sed -e 's/.* (Python //' -e 's/)//') | ||
|
||
_found=0 | ||
for version in ${py_versions[@]}; do | ||
if [[ "${version%.*}" == "$srcver" ]]; then | ||
_found=1 | ||
base="tests/$(basename "$srcf")" | ||
python-builds/Python-${version}/python \ | ||
-c "import py_compile; py_compile.compile('$srcf')" 2>"$base.rterr" | ||
if (( $? )) || [[ -s "$base.rterr" ]]; then | ||
let fails+=1 | ||
files+=("$srcf") | ||
errors+=("$(cat "$base.rterr")") | ||
echo -ne "\033[31m.\033[m" | ||
else | ||
echo -ne "\033[32m.\033[m" | ||
fi | ||
fi | ||
done | ||
|
||
if (( _found == 0 )); then | ||
let fails+=1 | ||
files+=("$srcf") | ||
errors+=("No python compiler found for $srcf ($srcver)") | ||
echo -ne "\033[31m.\033[m" | ||
fi | ||
done | ||
|
||
if (( $fails == 0 )) | ||
then | ||
echo -e "\n\nAll tests passed!" | ||
else | ||
echo -e "\n\n$fails tests failed:" | ||
for ((i=0; i<${#files[@]}; i++)) | ||
do | ||
echo -e "\t\033[31m${files[i]}\033[m" | ||
echo -e "${errors[i]}\n" | ||
done | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
diff --git a/Objects/fileobject.c b/Objects/fileobject.c | ||
index b0eb332..e1aa559 100644 | ||
--- a/Objects/fileobject.c | ||
+++ b/Objects/fileobject.c | ||
@@ -587,7 +587,7 @@ file_readinto(f, args) | ||
*/ | ||
|
||
static PyObject * | ||
-getline(f, n) | ||
+_py_getline(f, n) | ||
PyFileObject *f; | ||
int n; | ||
{ | ||
@@ -709,7 +709,7 @@ PyFile_GetLine(f, n) | ||
} | ||
if (((PyFileObject*)f)->f_fp == NULL) | ||
return err_closed(); | ||
- return getline((PyFileObject *)f, n); | ||
+ return _py_getline((PyFileObject *)f, n); | ||
} | ||
|
||
/* Python method */ | ||
@@ -729,7 +729,7 @@ file_readline(f, args) | ||
return PyString_FromString(""); | ||
if (n < 0) | ||
n = 0; | ||
- return getline(f, n); | ||
+ return _py_getline(f, n); | ||
} | ||
|
||
static PyObject * | ||
@@ -823,7 +823,7 @@ file_readlines(f, args) | ||
goto error; | ||
if (sizehint > 0) { | ||
/* Need to complete the last line */ | ||
- PyObject *rest = getline(f, 0); | ||
+ PyObject *rest = _py_getline(f, 0); | ||
if (rest == NULL) { | ||
Py_DECREF(line); | ||
goto error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/Makefile.pre.in b/Makefile.pre.in | ||
index 25a82af..9700faa 100644 | ||
--- a/Makefile.pre.in | ||
+++ b/Makefile.pre.in | ||
@@ -458,7 +458,7 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \ | ||
$(SIGNAL_OBJS) \ | ||
$(MODOBJS) \ | ||
$(srcdir)/Modules/getbuildinfo.c | ||
- $(CC) -c $(PY_CFLAGS) -DSVNVERSION=\"`LC_ALL=C $(SVNVERSION)`\" -o $@ $(srcdir)/Modules/getbuildinfo.c | ||
+ $(CC) -c $(PY_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c | ||
|
||
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile | ||
$(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ |