forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_race.sh
executable file
·80 lines (56 loc) · 1.68 KB
/
check_race.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
@INCLUDE_COMMON@
echo
echo ELEKTRA RACE TESTS
echo
check_version
#set -x
echo "Will skip the test, because it is sensible to ulimit settings and race might hang"
exit 0
RACE="@RACE_COMMAND@"
RACEKEYS=user:/test/race/keys
if [ "x$("$KDB" ls $RACEKEYS | wc -l 2> /dev/null)" != "x0" ]; then
echo "There are already keys in $RACEKEYS"
exit 1
fi
if $RACE | grep "This program tests race condition in Elektra"; then
echo "Doing race tests"
else
echo "No $RACE tool installed"
exit 0
fi
do_race_test() {
RES=$($RACE $*)
succeed_if "$RACE $* did not run successfully with error $?"
WHERE=user:/test/race/keys
KEYS=$("$KDB" ls "$WHERE")
succeed_if "could not run $KDB ls $WHERE successfully"
WON=$(echo "$RES" | grep won)
SHOULD=$(echo "$WON" | wc -l)
IS=$(echo "$KEYS" | wc -l)
RUNNING=$(ps aux | grep race | grep -v grep | grep -v check)
OUTPUT="\nFOR $*\nwith KEYS: $KEYS\nWON: $WON\nIS: $IS and RUNNING: $RUNNING\n\n"
echo "test $*: $SHOULD - $IS"
[ "$SHOULD" -ge "$IS" ]
succeed_if "The resolver has a race condition: $SHOULD is smaller than $IS! $OUTPUT"
# currently multiple winners are possible as the test seems to
# be flawed in multi-process setup
#[ "$SHOULD" -le "1" ]
#succeed_if "race had not one or zero, but $SHOULD, winner(s)! $OUTPUT"
[ "$IS" -eq "1" ]
succeed_if "keyset had not one, but $IS, key(s)! $OUTPUT"
"$KDB" rm -r $WHERE
succeed_if "could not remove key! $OUTPUT"
}
do_race_test 13 1 13
do_race_test 1 13 13
do_race_test 20 1 20
do_race_test 1 20 20
do_race_test 1 200 200
do_race_test 200 1 200
do_race_test 1 333 333
do_race_test 333 1 333
do_race_test 1 500 500
do_race_test 10 20 200
do_race_test 20 10 200
do_race_test 20 20 400
end_script