-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_wrap.sh
executable file
·122 lines (103 loc) · 3.1 KB
/
test_wrap.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
#!/bin/bash
#set -x
cmd="$*"
run_num=0
run_status=()
level=()
run_cmd() {
echo "Running test run_num=$run_num: $1"
echo "Command: $*"
echo "----------------------------------------------------------------------------"
$@ & # run in background
my_pid=$! # get process id
bin_name="$(ps -p $my_pid -o comm=)" # get running process name associated with that pid
echo running pid is $my_pid and process is $bin_name
sleep_cnt=0
while [ -d /proc/$my_pid ]
do
if [[ "$sleep_cnt" -gt 600 ]]; then # set timeout to be 30 mins
curl http://localhost:5000/api/v1/dumpStackTrace
sleep 10 # sleep for a while for dump stack trace log to finish flushing;
echo Killing $my_pid $bin_name because of timeout
kill -9 $my_pid
exit 1
fi
sleep 3
((sleep_cnt++))
done
echo "$my_pid $bin_name completed running, checking return status"
wait $my_pid
# The variable $? always holds the exit code of the last command to finish.
# Here it holds the exit code of $my_pid, since wait exits with that code.
status=$?
echo The exit status of the process was $status
if [ $status -eq 0 ] ; then
echo "---------------------------------------------------------------------------"
echo "Test success run_num=$run_num: $1"
run_status+=("Success")
else
echo "---------------------------------------------------------------------------"
echo "Test failed run_num=$run_num: $1"
run_status+=("FAILED")
fi
echo "*******************************************************************************************"
}
report() {
echo "######################################"
echo "Report:"
echo "----------"
printf "%-7s %-10s %-20s\n" "Run#" "Status" "DbgLevel"
for i in ${!run_status[@]}; do
printf "%-7d %-10s %-20s\n" $((i+1)) ${run_status[$i]} "${level[$i]}"
done
echo "######################################"
}
read -r -a array <<< "$*"
log_mods=""
if [ ${array[0]} == "--retry_log_mods" ] ; then
log_mods="${array[1]}"
base_cmd=""
for i in `seq 3 ${#array[@]}`; do
i=$((i-1))
base_cmd="$base_cmd ${array[$i]}"
done
else
base_cmd="$*"
fi
echo "Log mods for retry = " $log_mods
echo "*******************************************************************************************"
cmd="$base_cmd"
level+=("Normal")
run_cmd $cmd
if [ ${run_status[$run_num]} == "Success" ] ; then
report
exit 0
fi
if [ "$log_mods" != "" ] ; then
run_num=$(($run_num+1))
cmd="$base_cmd --log_mods $log_mods"
level+=("$log_mods")
run_cmd $cmd
if [ ${run_status[$run_num]} != "Success" ] ; then
report
exit 1
fi
fi
#run_num=$(($run_num+1))
#cmd="$base_cmd -v trace"
#level+=("All mods trace")
#run_cmd $cmd
#if [ ${run_status[$run_num]} != "Success" ] ; then
# report
# exit 1
#fi
#run_num=$(($run_num+1))
#cmd="$base_cmd -v debug"
#level+=("All mods debug")
#run_cmd $cmd
#if [ ${run_status[$run_num]} != "Success" ] ; then
# report
# exit 1
#fi
report
exit 1