-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_tests.sh
executable file
·206 lines (167 loc) · 3.96 KB
/
run_tests.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#! /bin/bash
# SPDX-License-Identifier: MIT License
LOG_FILE=./run_tests.log
function log()
{
if [ $verbose -ne 0 ]; then
echo "$@" | tee -a $LOG_FILE
else
echo "$@" >>$LOG_FILE
fi
}
function say()
{
echo "$@" | tee -a $LOG_FILE
}
function run_cmd()
{
local cmd="$@"
log "#> "$cmd
if [ $verbose -ne 0 ]; then
eval "$cmd" 2>&1 | tee -a $LOG_FILE
else
eval "$cmd" >>$LOG_FILE 2>&1
fi
if [ $? -ne 0 ]; then
say " command failed, see" $LOG_FILE "for results"
exit -1
fi
}
running_total=0
running_passed=0
running_failed=0
function update_test_results()
{
running_total=0
running_passed=0
running_failed=0
while IFS= read -r line; do
if [ -n "${line}" ]; then
read -a l_array <<< $line
if [ "${l_array[0]}" = "Total" ]; then
running_total=$(( running_total + l_array[2] ))
elif [ "${l_array[0]}" = "Passed:" ]; then
running_passed=$(( running_passed + l_array[1] ))
elif [ "${l_array[0]}" = "Failed:" ]; then
running_failed=$(( running_failed + l_array[1] ))
fi
fi
done < $LOG_FILE
}
function print_results()
{
local saved_total=$running_total
local saved_passed=$running_passed
local saved_failed=$running_failed
local total
local passed
local failed
update_test_results
total=$((running_total - saved_total))
passed=$((running_passed - saved_passed))
failed=$((running_failed - saved_failed))
echo " Total Tests:" $total", Passed:" $passed", Failed:" $failed
echo ""
}
function do_build()
{
local settings="$@"
# build libhsmp with specified settings
# if ./configure script does not exist run autogen.sh to generate it
if [ ! -f ./configure ]; then
say "## Running autogen.sh to create configure script"
run_cmd ./autogen.sh
fi
say "## Configuring libhsmp ("$settings")"
run_cmd ./configure $settings
say "## Building libhsmp"
log ""
run_cmd make clean
log ""
run_cmd make
log ""
}
function run_all_tests()
{
local settings="$@"
do_build $settings
# Run test as normal user
say "## Testing libhsmp as a regular user ("$settings")"
run_cmd LD_LIBRARY_PATH=./.libs ./.libs/hsmp_test $VERBOSE $TESTCASE
print_results
log ""
log ""
# Run test as super user
say "## Testing libhsmp as a privileged user ("$settings")"
run_cmd sudo LD_LIBRARY_PATH=./.libs ./.libs/hsmp_test $VERBOSE $TESTCASE
print_results
log ""
log ""
# Run test with seteuid
#
# For now -e and -f don't work together so skip this test
# if -f is specified.
if [ -z "$TESTCASE" ]; then
say "## Testing libhsmp using a seteuid program ("$settings")"
chmod u+s ./hsmp_test_static
run_cmd sudo ./hsmp_test_static -e $VERBOSE
chmod u-s ./hsmp_test_static
print_results
log ""
log ""
fi
}
# Specifying the -v option will cause all test output to be displayed
# on the console in addition to the log file.
#
# We set VERBOSE here so that all test cases are run with verbose
# output, the additional information in the log file will aid in
# debugging.
verbose=0
VERBOSE="-v"
while getopts "vf:l" arg; do
case "${arg}" in
v)
VERBOSE="-v"
verbose=$(( verbose + 1 ))
;;
f)
TESTCASE="-f ${OPTARG}"
;;
l)
LOG_FILE=${OPTARG}
;;
esac
done
if [ -f "$LOG_FILE" ]; then
rm $LOG_FILE
fi
#Log header
say "libhsmp test run -" `date`
log "#> uname -a"
log `uname -a`
log ""
log "libhsmp libraries..."
log "pwd =" `pwd`
log "LD_LIBRARY_PATH=./.libs"
log "#> ls -l ./.libs/libhsmp.so*"
log "$(ls -l ./.libs/libhsmp.so*)"
log ""
log ""
# Run tests with default settings
run_all_tests
run_all_tests --enable-debug
run_all_tests --enable-fam17
run_all_tests --enable-fam17 --enable-debug
# There is no real need to run all tests with debug-pci enabled
# but we should at least do a build to ensure nothing has been
# broken.
do_build --enable-fam17 --enable-debug --enable-debug-pci
# Print overall Reults
echo "Complete test output saved in "$LOG_FILE
say ""
say "Overall Test Results:"
say "#####################"
say "Total Tests: "$running_total
say "Passed: "$running_passed
say "Failed: "$running_failed