-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_library.sh
146 lines (114 loc) · 2.96 KB
/
test_library.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
#!/bin/bash
#maximum_test_count=1
maximum_test_count=9999
function biosal_filter_time_value()
{
local time_value
local seconds
local minutes
local hours
local token_count
local new_time_value
time_value=$1
if test $(echo $time_value | grep "s" | wc -l) -gt 0
then
new_time_value=$(echo $time_value|sed 's/h/ /g'|sed 's/m/ /g'|sed 's/s//g')
hours=0
minutes=0
seconds=0
token_count=$(echo "$new_time_value" | wc -w)
#echo "token_count $token_count"
# only seconds
if test $token_count -eq 1
then
# nothing to do
seconds=$new_time_value
# minutes and seconds
elif test $token_count -eq 2
then
seconds=$(echo "$new_time_value" | awk '{print $2}')
minutes=$(echo "$new_time_value" | awk '{print $1}')
# hours, minutes, seconds
elif test $token_count -eq 3
then
seconds=$(echo "$new_time_value" | awk '{print $3}')
minutes=$(echo "$new_time_value" | awk '{print $2}')
hours=$(echo "$new_time_value" | awk '{print $1}')
fi
# remove decimal point
seconds=$(echo $seconds | sed 's/\./ /g'|awk '{print $1}')
#echo "hours $hours minutes $minutes seconds $seconds"
time_value=$(($hours * 60 * 60 + $minutes * 60 + $seconds))
fi
if test $time_value = "-"
then
time_value=0
fi
echo $time_value
}
function biosal_shell_summarize_test_result()
{
local title
local passed
local failed
local all
title=$1
passed=$2
failed=$3
all=$(($passed + $failed))
echo -n $title
echo -n " PASSED $passed / $all"
if test $failed -gt 0
then
echo -n " FAILED $failed / $all"
fi
echo ""
}
function biosal_test_junit_open_xml_stream()
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
echo "<testsuites>"
}
function get_date()
{
# \see http://askubuntu.com/questions/355188/date-format-in-unix
date +%Y-%m-%dT%H:%M:%S%z
}
function biosal_test_junit_start_testsuite()
{
local timestamp
local name
local count
local total_failures
name=$1
count=$2
total_failures=$3
timestamp=$(get_date)
echo "<testsuite package=\"biosal\" name=\"$name\" tests=\"$count\" failures=\"$total_failures\" timestamp=\"$timestamp\">"
}
function biosal_test_junit_close_xml_stream()
{
echo "</testsuites>"
}
function biosal_test_junit_end_testsuite()
{
echo " </testsuite>"
}
function biosal_test_junit_emit_testcase()
{
local classname
local name
local time_value
local error
classname=$1
name=$2
time_value=$3
error=$4
time_value=$(biosal_filter_time_value $time_value)
echo " <testcase classname=\"$classname\" name=\"$name\" time=\"$time_value\">"
if test "$error" != ""
then
echo "<error message=\"$error\"></error>"
fi
echo " </testcase>"
}