-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtestAll.sh
More file actions
executable file
·133 lines (113 loc) · 3.11 KB
/
testAll.sh
File metadata and controls
executable file
·133 lines (113 loc) · 3.11 KB
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
#!/usr/bin/env bash
if [ "`whoami`" != "root" ]; then
echo "Run this as root!"
echo ""
exit 1
fi
. common/start_functions.sh
# remove all old results
find . -type f -name 'TESTRESULTS*' -exec rm {} +
parallel_jobs=0
if test "$1" = "seq"; then
parallel_jobs=1
elif test "$1" = "-j"; then
parallel_jobs=$2
if ! [[ "$parallel_jobs" =~ ^[0-9]+$ ]] || test $parallel_jobs -eq 0; then
echo "Not able to run in parallel with '$parallel_jobs', try running:"
echo "\$ $0 seq"
echo "or"
echo "\$ $0 -j [number_of_jobs]"
echo ""
exit 1
fi
else
parallel_jobs=$(($(nproc)/2))
if test "$parallel_jobs" -eq 0; then
parallel_jobs=1
fi
fi
imunes -i
if test -z "$TESTS"; then
# put longer tests near the beginning
tests=(BGP DNS+Mail+WEB OSPF DHCP6+RSOL RIP DHCP Ping Traceroute services ipsec44 ipsec46 ipsec64 ipsec66 functional_tests/rj45 functional_tests/rj45_vlan functional_tests/extelem functional_tests/empty_ifaces)
if isOSfreebsd; then
tests+=('gif')
fi
else
tests=($TESTS)
fi
echo "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*"
if test $parallel_jobs -eq 1; then
echo "# Sequential mode"
else
echo "# Parallel mode - max $parallel_jobs tests running in background"
echo "# Please wait until everything has finished."
fi
test -z "$DETAILS" && echo -n "# "
next_idx=0
running_ctr=0
done_running=""
currently_running=""
old_done_running=""
old_currently_running=""
while true; do
if test $next_idx -lt ${#tests[@]} && test $running_ctr -lt $parallel_jobs; then
dir=${tests[$next_idx]}
next_idx=$((next_idx+1))
test -z "$DETAILS" && echo -n "$dir "
if ! test -d "$dir"; then
continue
fi
cd $dir
sh test.sh > TESTRESULTS 2>&1 &
curpid=$!
pidvar=pid_$curpid
eval $pidvar=$dir
pids="$pids $curpid"
cd - > /dev/null
if test -z "$SKIP_SLEEP"; then
sleep 3
fi
fi
running_ctr=0
new_pids=""
currently_running=""
for p in $pids; do
pvar=pid_$p
ps $p > /dev/null 2>&1
if test $? -eq 0; then
running_ctr=$((running_ctr+1))
new_pids="$new_pids $p"
currently_running="$currently_running ${!pvar}"
else
done_running="$done_running ${!pvar}"
fi
done
if test -n "$DETAILS"; then
if test "$done_running" != "$old_done_running" || test "$currently_running" != "$old_currently_running"; then
if test -n "$done_running" && test -n "$currently_running"; then
echo -en "# DONE:$done_running | RUNNING:$currently_running\r"
elif test -n "$done_running"; then
echo -en "# DONE:$done_running \r"
elif test -n "$currently_running"; then
echo -en "# RUNNING:$currently_running\r"
fi
old_done_running=$done_running
old_currently_running=$currently_running
fi
fi
test -z "$new_pids" && test $next_idx -ge ${#tests[@]} && break
pids=$new_pids
sleep 1
done
echo ""
echo ""
echo "Finished."
if find . -type f -name 'TESTRESULTS*' -exec grep -q "^There were errors." {} +; then
echo ""
echo "Please look at the logs:"
find . -type f -name 'TESTRESULTS*' -exec grep "^There were errors." {} +
exit 1
else
echo "OK."
fi