blob: 12c235d3c622c85b9b4f6f0850878e1af273931f (
plain)
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/sh
basedir="$(dirname "$0")"
[ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
die()
{
echo "$*"
exit 1
}
cleanup()
{
[ -f "$test_time_file" ] && {
rm -f "$test_time_file"
test_time_file=
}
}
# $1=interpreter $2=awl_file ($3..$x additional options to awlsimcli)
run_test()
{
local interpreter="$1"
local awl="$2"
shift; shift
echo -n "Running test '$(basename "$awl")' ..."
command time -o "$test_time_file" -f '%E' \
"$interpreter" "$basedir/../awlsimcli" --quiet --onecycle --extended-insns \
--hardware dummy:inputAddressBase=7:outputAddressBase=8:dummyParam=True \
"$@" \
"$awl" ||\
die "Test failed"
echo " [$(cat "$test_time_file")]"
}
# $1=interpreter, $2=directory
run_test_directory()
{
local interpreter="$1"
local directory="$2"
echo "--- Entering directory '$directory'"
for entry in "$directory"/*; do
[ -d "$entry" ] && continue
[ "$(echo -n "$entry" | tail -c4)" = ".awl" ] || continue
run_test "$interpreter" "$entry"
done
for entry in "$directory"/*; do
[ -d "$entry" ] || continue
run_test_directory "$interpreter" "$entry"
done
echo "--- Leaving directory '$directory'"
}
# Run coreserver tests.
# $1=interpreter
run_server_tests()
{
local interpreter="$1"
echo "--- Running coreserver tests"
for testfile in shutdown.awl; do
run_test "$interpreter" "$basedir/$testfile" \
--spawn-backend --interpreter "$interpreter"
done
echo "--- Finished coreserver tests"
}
# $@=testfiles
do_tests()
{
for interpreter in "$opt_interpreter" python3 python2.7 pypy; do
[ -z "$interpreter" ] && continue
which "$interpreter" >/dev/null 2>&1 || {
echo "=== WARNING: '$interpreter' interpreter not found. Test skipped."
echo
continue
}
echo "=== Running tests with '$interpreter' interpreter."
if [ $# -eq 0 ]; then
run_test_directory "$interpreter" "$basedir"
run_server_tests "$interpreter"
else
for opt in "$@"; do
if [ -d "$opt" ]; then
run_test_directory "$interpreter" "$opt"
else
run_test "$interpreter" "$opt"
fi
done
fi
echo
[ -n "$opt_interpreter" ] && break
done
}
trap cleanup EXIT INT TERM
test_time_file="$(mktemp --tmpdir=/tmp awlsim-test-time.XXXXXX)"
opt_interpreter=
while [ $# -ge 1 ]; do
[ "$(echo "$1" | cut -c1)" != "-" ] && break
case "$1" in
-i|--interpreter)
shift
opt_interpreter="$1"
which "$opt_interpreter" >/dev/null 2>&1 ||\
die "Interpreter '${opt_interpreter}' not found"
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
do_tests "$@"
exit 0
|