Add more advanced round-trip test target that runs decompiled output back
through the originating Python compiler (Linux only for now)
This commit is contained in:
@@ -65,7 +65,13 @@ if(POLICY CMP0037)
|
|||||||
# Don't complain about adding a target named "test"
|
# Don't complain about adding a target named "test"
|
||||||
cmake_policy(SET CMP0037 OLD)
|
cmake_policy(SET CMP0037 OLD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_target(test "${CMAKE_CURRENT_SOURCE_DIR}/pycdc_test.sh"
|
add_custom_target(test "${CMAKE_CURRENT_SOURCE_DIR}/pycdc_test.sh"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/tests"
|
"${CMAKE_CURRENT_SOURCE_DIR}/tests"
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
add_dependencies(test pycdc)
|
add_dependencies(test pycdc)
|
||||||
|
|
||||||
|
add_custom_target(rt_test "${CMAKE_CURRENT_SOURCE_DIR}/pycdc_rt_test.sh"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/tests"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
add_dependencies(rt_test test)
|
||||||
|
116
pycdc_rt_test.sh
Executable file
116
pycdc_rt_test.sh
Executable file
@@ -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
|
@@ -1,6 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
testdir="$1"
|
testdir="$1"
|
||||||
|
|
||||||
|
if [[ -z "$testdir" ]]
|
||||||
|
then
|
||||||
|
echo "Missing required parameter: testdir" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p tests
|
mkdir -p tests
|
||||||
|
|
||||||
fails=0
|
fails=0
|
||||||
|
40
tests/python-builds/Python-1.5.2.patch
Normal file
40
tests/python-builds/Python-1.5.2.patch
Normal file
@@ -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;
|
13
tests/python-builds/Python-2.5.6.patch
Normal file
13
tests/python-builds/Python-2.5.6.patch
Normal file
@@ -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)"' \
|
Reference in New Issue
Block a user