-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.sh
executable file
·141 lines (123 loc) · 3.07 KB
/
runtests.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
#########################
# SSM runtime test script
#########################
#
# Use this script to run all tests and compare against expected output, which
# can found in test/{examples,tests}.out). Example and test outputs are written
# to build/{examples,tests}.out, respectively.
#
# If Valgrind is installed, this script also uses it to check for memory errors.
# Valgrind output is written to build/{examples,tests}.vg-out.
set -euf
set -o pipefail
BUILD_DIR=./build
declare -a VG_FLAGS=("--leak-check=full" "--show-leak-kinds=all")
scriptname="$(basename "$0")"
say () {
echo "[$scriptname]" "$@" >&2
}
run () {
local exe="$BUILD_DIR/$1"
shift
echo "$exe" "$@"
echo "$exe" "$@" >&2
set +e
"$exe" "$@" 2>&1 | sed 's/^/# /'
local exit_code="$?"
set -e
if [ "$exit_code" -ne 0 ]; then
say "Non-zero exit code $exit_code encountered while running:" "$exe" "$@"
exit "$exit_code"
fi
}
vg () {
local exe="$BUILD_DIR/$1"
shift
echo valgrind "${VG_FLAGS[@]}" "$exe" "$@"
echo valgrind "${VG_FLAGS[@]}" "$exe" "$@" >&2
set +e
valgrind "${VG_FLAGS[@]}" "$exe" "$@" 2>&1 | sed 's/^/# /'
local exit_code="$?"
set -e
if [ "$exit_code" -ne 0 ]; then
say "Non-zero exit code $exit_code encountered with valgrind:" "$exe" "$@"
exit "$exit_code"
fi
}
make clean
make exes tests
if ! [ -d "$BUILD_DIR" ] ; then
echo "Could not find build directory: $BUILD_DIR. Quitting."
exit 1
fi
rm -f "$BUILD_DIR/examples.out"
{
run fib
run fib 4
run fib 5
run fib 13
run fib 15
run onetwo
run clock
run counter
run list
run list 2048
run closures
run map-closure
} >> "$BUILD_DIR/examples.out"
if diff "$BUILD_DIR/examples.out" test/examples.out &> "$BUILD_DIR/examples.diff" ; then
say "Example output matches expected."
else
say "Example output differs from expected:"
cat "$BUILD_DIR/examples.diff"
exit 1
fi
rm -f "$BUILD_DIR/test-scheduler.out"
{
run test_test-scheduler
} >> "$BUILD_DIR/test-scheduler.out"
if diff "$BUILD_DIR/test-scheduler.out" test/test-scheduler.out &> "$BUILD_DIR/test-scheduler.diff" ; then
say "Test-scheduler output matches expected."
else
say "Test-scheduler output differs from expected:"
cat "$BUILD_DIR/test-scheduler.diff"
exit 1
fi
rm -f "$BUILD_DIR/test-mem.out"
{
run test_test-mem
} >> "$BUILD_DIR/test-mem.out"
if diff "$BUILD_DIR/test-mem.out" test/test-mem.out &> "$BUILD_DIR/test-mem.diff" ; then
say "Test-mem output matches expected."
else
say "Test-mem output differs from expected:"
cat "$BUILD_DIR/test-mem.diff"
exit 1
fi
make clean
make exes tests
if which valgrind >/dev/null ; then
rm -f "$BUILD_DIR/examples.vg-out"
{
vg fib
vg fib 4
vg fib 5
vg fib 13
vg fib 15
vg onetwo
vg clock
vg counter
vg list
vg list 2048
vg closures
vg map-closure
} >> "$BUILD_DIR/examples.vg-out"
say "Examples do not have any memory errors"
{
vg test_test-scheduler
} >> "$BUILD_DIR/tests.out"
say "Tests do not have any memory errors"
else
say "Warning: valgrind not found in PATH. Skipping memory tests."
fi