-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test
60 lines (43 loc) · 1.56 KB
/
run_test
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
#!/bin/bash
set -e
# Print help usage if there are fewer then 3 positional arguments
if [ $# -lt 3 ] ; then
echo "Usage: $0 TIMEOUT NUM_OF_WORKERS PATH_TO_PROG [ADDITIONAL_ARGS]"
exit 1
fi
# Read important values from positional args into named vars
TIMEOUT=$1
NUM_OF_WORKERS=$2
shift 2
# Create temporary file
tmp_file=$(mktemp)
# Invoke mimpirun with appropriate timeout and arguments
# "|| true" used to ignore ./mimpirun return code
result=0
if [ -z ${VALGRIND+x} ]; then
timeout "$TIMEOUT" ./mimpirun "$NUM_OF_WORKERS" "$@" 2> "$tmp_file" || true
else
LC="${TIMEOUT: -1}"
if [ "$LC" = "s" ]; then
TIMEOUT=${TIMEOUT::-1}
fi
TIMEOUT=$(echo "$TIMEOUT * 20" | bc)
if [ $(echo "$TIMEOUT > 1000" | bc) = "1" ] ; then
echo "SKIPPING TEST::TOO LONG" >&2
exit 0
fi
timeout "$TIMEOUT" valgrind -q --track-origins=yes --trace-children=yes --track-fds=yes --leak-check=full --show-leak-kinds=all ./mimpirun "$NUM_OF_WORKERS" "$@" 2> "$tmp_file" || true
NUM_OF_PROGRAMS=$(($NUM_OF_WORKERS+1))
test "$(grep -c '==' "$tmp_file")" -ne "0" && result=4
fi
# Check if all workers finished successfully
# - num of <<success>> is equal to number of created workers
test "$(grep -c '<<success>>' "$tmp_file")" -ne "$NUM_OF_WORKERS" && result=3
# Check if error has been detected - <<error>> was found in stderr
grep "<<error>>" "$tmp_file" > /dev/null && result=2
# Print stderr in case of error
test "$result" -ne 0 && cat "$tmp_file" >&2
# Remove temporary file
rm "$tmp_file"
# Exit with appropriate return code
exit "$result"