-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_test.sh
executable file
·76 lines (64 loc) · 1.89 KB
/
run_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
#!/bin/bash
# Usage:
# ./run_test.sh (runs all tests)
# ./run_test.sh path_to/my_test.cfg (run one or more tests)
#
# The parent directory of a cfg file should contain the "streamer" executable
set -eu # Exit on errors
top_dir=$(dirname "$0") # Top directory
run_test() {
# Arguments: config file, top directory
dir=$(dirname "$1")
cfg=$(basename "$1")
# Execute the test in the directory of the .cfg file
start=`date +%s`
(cd "$dir" && ../streamer "$cfg" > run.log ||
{ cat run.log; return 1; })
end=`date +%s`
runtime_sec=$((end-start))
if (($? != 0)); then
echo "FAILED $1"
return
fi
log_name="${cfg/.cfg/_rtest.log}"
log_a="$dir/$log_name"
log_b="$dir/output/$log_name"
# Compare log files
if "$2"/tools/compare_logs.py "$log_a" "$log_b"; then
echo "PASSED $1 (${runtime_sec} s)"
else
echo "FAILED $1 (${runtime_sec} s)"
fi
}
# Use array to store test results
declare -a test_results
if (( "$#" > 0 )); then
# Run given tests (note that this does not compile the code)
for cfg in "$@"; do
out=$(run_test "$cfg" "$top_dir")
echo "$out"
results+=("$out")
done
else
# Run all tests
declare -a test_dirs=(
"programs/standard_1d/tests"
"programs/standard_2d/tests"
"programs/standard_3d/tests"
"programs/dielectric_2d/tests"
)
for dir in "${test_dirs[@]}"; do
# Compile in parent folder and make sure 'output' exists
(cd "$dir" && make -j -C .. --silent && mkdir -p output)
# Loop over the .cfg files
for cfg in "$dir"/*.cfg; do
out=$(run_test "$cfg" "$top_dir")
echo "$out"
results+=("$out")
done
done
fi
# Check if any of the results contained "FAILED"
if [[ "${results[@]}" =~ "FAILED" ]]; then
exit 1
fi