forked from zrax/pycdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpycdc_rt_test.sh
executable file
·125 lines (106 loc) · 3.2 KB
/
pycdc_rt_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/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 -LfO# "$url"
tar xzf "$tarball"
if [[ -f "${srcdir}/scripts/python-builds/Python-${version}.patch" ]]; then
cd "Python-${version}"
patch -p1 < "${srcdir}/scripts/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
shopt -s nullglob
rtsources=("$testdir"/*.pyc.src.py)
shopt -u nullglob
if (( ${#rtsources[@]} == 0 )); then
echo "No decompyled sources found in $testdir"
exit 1
fi
for srcf in "${rtsources[@]}"; 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