-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-tests
executable file
·139 lines (120 loc) · 3.78 KB
/
run-tests
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
134
135
136
137
138
139
#!/usr/bin/env sh
##################################################
# Automation script for running tests #
# A default tolerance value of 1 second is used. #
##################################################
if [ "$(uname)" = FreeBSD ]; then
packetdrill=/usr/local/bin/packetdrill
else
packetdrill=/usr/bin/packetdrill
fi
directory="$1"
extension=".pkt"
TOLERANCE_USECS=1000000
trap clean_up HUP INT TERM
clean_up() {
printf "\nCleaning up..."
rm -f tests_list temp.log
exit 1
}
file=tests_list # contains the list of ".pkt" files in case the argument is empty or a directory
pkt_file_flag=0 # tracks whether the argument is a ".pkt" file
# Check if path to packetdrill binary is set
if [ -z $packetdrill ]; then
printf "Please set the value of \$packetdrill variable to the path of packetdrill binary on your machine.\n"
exit 1
fi
# Handle invalid argument
if [ ! -z "$directory" ] && [ ! -e "$directory" ]; then
echo "File not found!"
exit 1
fi
# Check if the argument is a ".pkt" file
if test "${directory#*$extension}" != "$directory"; then
pkt_file_flag=1
fi
# Check if the argument is a directory
if [ ! -z "$directory" ]; then
# Avoid generating "tests_list" in every run
if [ $pkt_file_flag = 0 ] && [ ! -f "$directory/tests_list" ]; then
sh update-test-list "$directory/tests_list" "$directory"
fi
file="$directory/tests_list"
else
sh update-test-list tests_list
fi
delay=0.2 # delay between subsequent tests run
run=0 # number of tests run
skipped=0 # number of tests skipped
passed=0 # number of tests passed
failed=0 # number of tests failed
# Modify values depending on return status
check_status() {
run=$((run + 1))
if [ "$result" = 1 ]; then
{
printf "Test Name: %s\n" "$testname" >> error.log
printf "\---------------------------------------------------------\n"
cat temp.log
printf "\n"
} >> error.log
printf "\033[31mFAILED\033[39m\n"
printf "\---------------------------------------------------------------\n"
failed=$((failed + 1))
else
printf "\033[33mPASSED\033[39m\n"
printf "\---------------------------------------------------------------\n"
passed=$((passed + 1))
fi
}
rm -f error.log
{
printf "Error log of tests run at %s\n" "$(date)"
printf "===============================================================\n\n"
} > error.log
printf "\nScript Name Result\n"
printf "===============================================================\n"
# Check if a single test script or a directory is given as argument
if [ $pkt_file_flag = 1 ]; then
printf "%-55.55s " "$directory"
if [ -e "$directory" ]; then
rm -f temp.log
$packetdrill -v --tolerance_usecs=$TOLERANCE_USECS "$directory" >> temp.log 2>&1
result=$?
testname=$(basename "$directory")
check_status
else
printf "\033[32mSKIPPED\033[39m\n"
skipped=$((skipped + 1))
fi
else
while IFS= read -r test
do
printf "%-55.55s " "$test"
sleep $delay
if [ -e "${test}".pkt ]; then
rm -f temp.log
$packetdrill -v --tolerance_usecs=$TOLERANCE_USECS "${test}".pkt >> temp.log 2>&1
result=$?
testname=$(basename "$test")
check_status
else
printf "\033[32mSKIPPED\033[39m\n"
skipped=$((skipped + 1))
fi
done< "$file"
rm -f temp.log tests_list
fi
if [ $run = 0 ]; then
printf "\033[32mMake sure that you have specified the correct .pkt file\033[39m\n"
exit 1
fi
printf "\nSummary\n"
printf "===========================\n"
printf "Number of tests run: %6d\n" $run
printf "Number of tests passed: %3d\n" $passed
printf "Number of tests failed: %3d\n" $failed
printf "Number of tests skipped: %2d\n\n" $skipped
if [ $failed -ne 0 ]; then
printf "\nView the log file \"error.log\" for details\n"
fi