-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·64 lines (53 loc) · 1.18 KB
/
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
set -e
case "$OSTYPE" in
"darwin"*)
echo "macOS is not supported"
exit 1
;;
esac
cd "$(dirname "$0")"
TARGET_PID=$$ # PID of benchmark.sh
clean() {
if [ ! -z $PID ]; then
kill $PID
fi
}
trap clean 0 1 2 3 6 15
run_test() {
EXPECTED_EXIT_CODE=$1; shift
echo
echo Running: \"$@\"
(
set +e
eval "$@"
EXIT_CODE=$?
echo "Exit code $EXIT_CODE, expected $EXPECTED_EXIT_CODE"
if [ "$EXIT_CODE" != "$EXPECTED_EXIT_CODE" ]; then
echo "FAILED"
exit 1
fi
echo "PASSED"
)
}
run_suit() {
EXPECTED_EXIT_CODE=$1; shift
COMMAND="$1"; shift
echo ----------------------------
echo Command: \"$COMMAND\"
echo Process names to match: $@
echo Expected exit code: $EXPECTED_EXIT_CODE
eval "$COMMAND" &
PID=$!
sleep 1 # give processes time to start
echo Process tree:
pstree -g $TARGET_PID
echo
run_test $EXPECTED_EXIT_CODE "./pscheck.sh $TARGET_PID $@"
run_test $EXPECTED_EXIT_CODE "./pscheck $TARGET_PID $@"
kill -KILL $PID
PID=
echo
}
run_suit 1 'timeout 5 tail -f /dev/null' 'dummy'
run_suit 0 'timeout 5 tail -f /dev/null' 'dummy' 'tail'
run_suit 1 'timeout -s STOP -k 5 0.5 tail -f /dev/null' 'dummy' 'tail'