Newer
Older
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash
#set -xv
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1 (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
if [ -s $OPENAIR_DIR/cmake_targets/tools/build_helper ] ; then
source $OPENAIR_DIR/cmake_targets/tools/build_helper
else
echo "Error: no file in the file tree: is OPENAIR_DIR variable set?"
exit 1
fi
source $OPENAIR_DIR/cmake_targets/tools/test_helper
SUDO="sudo -E"
tdir=$OPENAIR_DIR/cmake_targets/autotests
rm -fr $tdir/bin
mkdir -p $tdir/bin
results_file="$tdir/log/results_autotests.xml"
#\param $1 -> name of test case
#\param $2 -> name of executable
#\param $3 -> arguments for running the program
#\param $4 -> search expression
#\param $5 -> search expression which should NOT be found (for ex. segmentation fault)
#\param $6 -> number of runs
#\param $7 -> tags to help identify the test case for readability in output xml file
#\param $8 => test config file params to be modified
#\param $9 -> desc to help identify the test case for readability in output xml file
function test_run() {
xUnit_start
test_case_name=$1
log_dir=$tdir/log/$test_case_name
log_file=$log_dir/test.$1.log.txt
main_exec=$2
exec_args=$3
search_expr_array=("${!4}")
search_expr_negative=$5
nruns=${6}
tags=${7}
test_config_file=${8}
desc=${9}
xmlfile_testcase=$log_dir/test.$1.xml
#Temporary log file where execution log is stored.
temp_exec_log=$log_dir/temp_log.txt
export OPENAIR_LOGDIR=$log_dir
rm -fr $log_dir
mkdir -p $log_dir
echo "" > $temp_exec_log
echo "start at $(date)" > "$log_file"
#echo "log_dir = $log_dir"
#echo "log_file = $log_file"
#echo "exec_file = $exec_file"
#echo "exec_args = $exec_args"
#echo "search_expr = $search_expr"
#echo "nruns = $nruns"
#echo "desc = $desc"
tags_array=()
read -a tags_array <<<"$tags"
desc_array=()
readarray -t desc_array <<<"$desc"
main_exec_args_array=()
readarray -t main_exec_args_array <<< "$exec_args"
if [ ! -f $main_exec ]; then
echo_fatal "no executable $main_exec found"
fi
tags_array_index=0
for main_exec_args_array_index in "${main_exec_args_array[@]}"
do
global_result=PASS
result_string=""
PROPER_DESC=`echo ${desc_array[$tags_array_index]} | sed -e "s@^.*Test cases.*(Test@Test@" -e "s@^ *(@@" -e"s/)$//" -e "s/),$//"`
echo_info "$PROPER_DESC"
for (( run_index=1; run_index <= $nruns; run_index++ ))
do
temp_exec_log="$log_dir/test.$test_case_name.${tags_array[$tags_array_index]}.run_$run_index"
echo "Executing test case $test_case_name.${tags_array[$tags_array_index]}, Run Index = $run_index, Execution Log file = $temp_exec_log"
echo "-----------------------------------------------------------------------------" > "$temp_exec_log"
echo "<EXECUTION LOG Test Case = $test_case_name.${tags_array[$tags_array_index]}, Run = $run_index >" >> "$temp_exec_log"
echo "Executing $main_exec $main_exec_args_array_index at $(date)" >> "$temp_exec_log"
uname -a >> "$temp_exec_log"
time "$main_exec" $main_exec_args_array_index >> "$temp_exec_log" 2>&1 &
done
wait
for (( run_index=1; run_index <= $nruns; run_index++ ))
do
temp_exec_log="$log_dir/test.$test_case_name.${tags_array[$tags_array_index]}.run_$run_index"
echo "</EXECUTION LOG Test Case = $test_case_name.${tags_array[$tags_array_index]}, Run = $run_index >" >> $temp_exec_log 2>&1
cat "$temp_exec_log" >> "$log_file" 2>&1
result=PASS
for search_expr in "${search_expr_array[@]}"
do
grep -Eq "$search_expr" $temp_exec_log || result=FAIL
done
#If we find a negative search result then there is crash of program and test case is failed even if above condition is true
grep -q -iE "$search_expr_negative" $temp_exec_log && result=FAIL
if [ "$result" != PASS ]; then
echo_error "$test_case_name.${tags_array[$tags_array_index]} RUN = $run_index Result = FAIL"
else
echo_success "$test_case_name.${tags_array[$tags_array_index]} RUN = $run_index Result = PASS"
fi
result_string=$result_string" Run_$run_index =$result"
if [ $result != PASS ] ; then
global_result=FAIL
fi
done #End of for loop (nindex)
echo "END at $(date)" >> "$log_file"
if [ "$global_result" != PASS ]; then
echo_error "execution $test_case_name.${tags_array[$tags_array_index]} {$PROPER_DESC} Run_Result = \"$result_string\" Result = FAIL"
xUnit_fail "execution" "$test_case_name.${tags_array[$tags_array_index]}" "FAIL" "$result_string" "$xmlfile_testcase" "$PROPER_DESC"
else
echo_success "execution $test_case_name.${tags_array[$tags_array_index]} {$PROPER_DESC} Run_Result = \"$result_string\" Result = PASS "
xUnit_success "execution" "$test_case_name.${tags_array[$tags_array_index]}" "PASS" "$result_string" "$xmlfile_testcase" "$PROPER_DESC"
fi
let "tags_array_index++"
done
}
dlog=$OPENAIR_DIR/cmake_targets/autotests/log
exec_dir=$OPENAIR_DIR/cmake_targets/ran_build/build
xml_conf="$OPENAIR_DIR/cmake_targets/autotests/test_case_list.xml"
function print_help() {
echo_info '
This program runs automated test cases
Options
-c | --config
Set the configuration file to execute (default: $xml_conf)
-d | --exec-dir
Set directory of executables (default: $exec_dir)
-g | --run-group
Run test cases in a group. For example, ./run_exec_autotests "0101* 010102"
-h | --help
This help
'
}
function main () {
RUN_GROUP=0
test_case_group=""
test_case_group_array=()
test_case_array=()
echo_info "Note that the user should be sudoer for executing certain commands, for example loading kernel modules"
until [ -z "$1" ]; do
case "$1" in
-c|--config)
xml_conf=$2
echo "setting xml_conf to $xml_conf"
shift 2;;
-d|--exec-dir)
exec_dir=$2
echo "setting exec_dir to $exec_dir"
shift 2;;
-g | --run-group)
RUN_GROUP=1
test_case_group=$2
test_case_group=`sed "s/\+/\*/g" <<< "${test_case_group}"` # Replace + with * for bash string substituion
echo_info "Will execute test cases only in group $test_case_group"
shift 2;;
-h | --help)
print_help
exit 1;;
*)
print_help
echo_fatal "Unknown option $1"
break;;
esac
done
tmpfile=`mktemp`
$SUDO echo $HOME > $tmpfile
tstsudo=`cat $tmpfile`
if [ "$tstsudo" != "$HOME" ]; then
echo_error "$USER does not have sudo privileges. Exiting"
exit
fi
rm -fr $tmpfile
test_case_excl_list=`xmlstarlet sel -t -v "/testCaseList/TestCaseExclusionList" $xml_conf`
test_case_excl_list=`sed "s/\+/\*/g" <<< "$test_case_excl_list" ` # Replace + with * for bash string substituion
echo "Test Case Exclusion List = $test_case_excl_list "
read -a test_case_excl_array <<< "$test_case_excl_list"
test_case_list=`xmlstarlet sel -T -t -m /testCaseList/testCase -s A:N:- "@id" -v "@id" -n $xml_conf`
echo "test_case_list = $test_case_list"
readarray -t test_case_array <<<"$test_case_list"
read -a test_case_group_array <<< "$test_case_group"
for search_expr in "${test_case_array[@]}"
do
flag_run_test_case=0
# search if this test case needs to be executed
if [ "$RUN_GROUP" -eq "1" ]; then
for search_group in "${test_case_group_array[@]}"
do
if [[ $search_expr == $search_group ]];then
flag_run_test_case=1
echo_info "Test case $search_expr match found in group"
break
fi
done
else
flag_run_test_case=1
fi
for search_excl in "${test_case_excl_array[@]}"
do
if [[ $search_expr == $search_excl ]];then
flag_run_test_case=0
echo_info "Test case $search_expr match found in test case excl group. Will skip the test case for execution..."
break
fi
done
#We skip this test case if it is not in the group list
if [ "$flag_run_test_case" -ne "1" ]; then
continue
fi
name=$search_expr
desc=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/desc" $xml_conf`
main_exec=$exec_dir/`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/main_exec" $xml_conf`
main_exec_args=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/main_exec_args" $xml_conf`
search_expr_true=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/search_expr_true" $xml_conf`
search_expr_false=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/search_expr_false" $xml_conf`
nruns=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/nruns" $xml_conf`
tags=`xmlstarlet sel -t -v "/testCaseList/testCase[@id='$search_expr']/tags" $xml_conf`
echo "name = $name"
echo "Description = $desc"
echo "main_exec = $main_exec"
echo "main_exec_args = $main_exec_args"
echo "search_expr_true = $search_expr_true"
echo "search_expr_false = $search_expr_false"
echo "tags = $tags"
echo "nruns = $nruns"
search_array_true=()
IFS=\" #set the shell field separator
set -f #dont try to glob
#set -- $search_expr_true #split on $IFS
for i in $search_expr_true
do echo "i = $i"
if [ -n "$i" ] && [ "$i" != " " ]; then
search_array_true+=("$i")
#echo "inside i = \"$i\" "
fi
done
unset IFS
#echo "arg1 = ${search_array_true[0]}"
#echo " arg2 = ${search_array_true[1]}"
test_run \
"$name" \
"$main_exec" \
"$main_exec_args" \
"search_array_true[@]" \
"$search_expr_false" \
"$nruns" \
"$tags" \
"$test_config_file" \
"$desc"
done
}
uname -a
main "$@"
xUnit_write "$results_file"
echo "Test Results are written to $results_file"