github/workflows/pycopy-test: Upgrade Pycopy to 3.6.1.
[ScratchABlock.git] / run_tests
blob8cc40aef42db384786104b34c3c3316e2e395202
1 #!/bin/bash
3 if [ -z "$PYTHON" ]; then
4 PYTHON=python3
5 fi
7 failed() {
8 echo "TESTS FAILED!"
9 exit 1
12 if [ -z "$1" -o "$1" == "unit" ]; then
13 echo "=== test_unit ==="
14 $PYTHON -m nose --version || nose_missing=1
15 if [ -z "$nose_missing" ]; then
16 $PYTHON -m nose -v || failed
20 test_roundtrip() {
21 echo "=== test_roundtrip ==="
22 for f in tests/pseudoc-roundtrip/*.lst; do
23 echo $f
24 $PYTHON ./parse_asm.py --roundtrip --addr-width=2 --inst-indent=1 $f > $f.out || failed
25 diff -u $f.exp $f.out || failed
26 done
29 test_dump_c() {
30 echo "=== test_dump_c ==="
31 for f in tests/dump-c/*.lst; do
32 echo $f
33 $PYTHON ./dump_c.py $f > $f.out || failed
34 diff -u $f.exp $f.out || failed
35 done
38 test_xform() {
39 echo "=== test_xform ==="
41 pat='*'
42 if [ ! -z "$1" ]; then
43 pat="$1"
46 for f in tests/$pat.lst; do
47 echo $f
48 $PYTHON ./apply_xform.py --debug --annotate-calls --funcdb=none --format=none $f || failed
49 diff -u $f.exp.bb $f.out.bb || failed
50 if [ -f $f.exp.dot ]; then
51 diff -u $f.exp.dot $f.out.dot || failed
53 done
56 test_decomp() {
57 echo "=== test_decomp ==="
58 for dir in tests/decomp/*; do
59 if [ -d $dir ]; then
60 echo $dir
61 #dir=$(dirname $f)
62 rm -f $dir/funcdb.yaml
63 $PYTHON ./apply_xform.py --log-level=WARNING --script script_decompile --format=c $dir || failed
64 rm -f $dir/funcdb.yaml
65 $PYTHON ./apply_xform.py --log-level=ERROR --script script_decompile --format=c \
66 --no-dead --no-comments --output-suffix=.out.clean $dir || failed
67 for f in $dir/*.lst; do
68 diff -u $f.exp $f.out || failed
69 diff -u $f.exp.clean $f.out.clean || failed
70 done
72 done
75 test_cfg2pseudoc() {
76 echo "=== test_cfg2pseudoc ==="
77 for f in tests/cfg2pseudoc/*.dot; do
78 if echo $f | grep -q -E '(0|out)\.dot'; then
79 continue
81 echo $f
82 $PYTHON ./sabl_cfg2pseudoc.py $f > $f.lst || failed
83 diff -u $f.lst.exp $f.lst || failed
84 $PYTHON ./apply_xform.py --debug --funcdb=none $f.lst >/dev/null
85 done
88 # Be sure to remove any older test output, to miss a case when no new output
89 # is produced.
90 find tests -name '*.out*' -exec rm {} \;
92 if [ -z "$1" -o "$1" == "roundtrip" ]; then
93 test_roundtrip
95 if [ -z "$1" -o "$1" == "dump_c" ]; then
96 test_dump_c
98 if [ -z "$1" -o "$1" == "xform" ]; then
99 test_xform $2
101 if [ -z "$1" -o "$1" == "decomp" ]; then
102 test_decomp
104 if [ -z "$1" -o "$1" == "cfg2pseudoc" ]; then
105 test_cfg2pseudoc
108 echo "TESTS PASSED"
109 if [ -n "$nose_missing" ]; then
110 echo
111 echo "WARNING: unit tests were not run due to missing 'nose' package for python3"