ci: Collect test times for sharness
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Apr 21, 2018 at 18:58 UTC
9b4296d9fd5c4358c1f0e6d60c10d887ad1f1fd4
2 files changed
+41
-21
test/sharness/lib/0001-Generate-partial-JUnit-reports.patch
+40
-20
@@ -1,14 +1,14 @@
1
-From 76b34f25b2bacdd30138b25ccbe0672d76a1632a Mon Sep 17 00:00:00 2001
1
+From bc6bf844ef4e4cd468bc1ec96f2d6af738eb8d2f Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?=C5=81ukasz=20Magiera?= <magik6k@gmail.com>
3
-Date: Thu, 22 Mar 2018 06:11:01 +0100
3
+Date: Sat, 21 Apr 2018 22:01:45 +0200
4
Subject: [PATCH] Generate partial JUnit reports
5
6
---
7
- sharness.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
8
- 1 file changed, 96 insertions(+), 6 deletions(-)
7
+ sharness.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++++---
8
+ 1 file changed, 108 insertions(+), 6 deletions(-)
9
10
diff --git a/sharness.sh b/sharness.sh
11
-index 6750ff7..7d9915a 100644
11
+index 6750ff7..336e426 100644
12
--- a/sharness.sh
13
+++ b/sharness.sh
14
@@ -1,4 +1,4 @@
@@ -46,13 +46,13 @@ index 6750ff7..7d9915a 100644
46
+esc=$(printf '\033')
47
+
48
+esc_xml() {
49
-+ sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"$esc"'/\/g; s///g;'
49
++ sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"$esc"'//g; s///g;'
50
+}
51
+
52
test -n "$test_description" || error "Test script did not set test_description."
53
54
if test "$help" = "t"; then
55
-@@ -251,30 +265,75 @@ test_have_prereq() {
55
+@@ -251,30 +265,78 @@ test_have_prereq() {
56
test $total_prereq = $ok_prereq
57
}
58
@@ -65,10 +65,13 @@ index 6750ff7..7d9915a 100644
65
+
66
+ test_name=$1
67
+ tc_file=".junit/case-$(printf "%04d" $test_count)"
68
++ time_sec="$(cat .junit/time | xargs printf '%04d' | sed -e 's/\(...\)$/.\1/g')"
69
++
70
++ echo "$(expr $(cat .junit/time_total) + $(cat .junit/time) )" > .junit/time_total
71
+
72
+ shift
73
+ cat > "$tc_file" <<-EOF
71
-+ <testcase name="$test_count - $(echo $test_name | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}">
74
++ <testcase name="$test_count - $(echo $test_name | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="${time_sec}">
75
+ $@
76
+ EOF
77
+
@@ -89,7 +92,7 @@ index 6750ff7..7d9915a 100644
92
+ fi
93
+
94
+ echo "</testcase>" >> "$tc_file"
92
-+ rm -f .junit/tout .junit/terr
95
++ rm -f .junit/tout .junit/terr .junit/time
96
+}
97
+
98
# You are not expected to call test_ok_ and test_failure_ directly, use
@@ -128,7 +131,7 @@ index 6750ff7..7d9915a 100644
131
}
132
133
# Public: Execute commands in debug mode.
131
-@@ -310,7 +369,11 @@ test_pause() {
134
+@@ -310,15 +372,25 @@ test_pause() {
135
test_eval_() {
136
# This is a separate function because some tests use
137
# "return" to end a test_expect_success block early.
@@ -141,7 +144,21 @@ index 6750ff7..7d9915a 100644
144
}
145
146
test_run_() {
144
-@@ -355,8 +418,18 @@ test_skip_() {
147
+ test_cleanup=:
148
+ expecting_failure=$2
149
++
150
++ start_time_ms=$(date "+%s%3N");
151
+ test_eval_ "$1"
152
+ eval_ret=$?
153
+
154
++ if test -n "$TEST_GENERATE_JUNIT"; then
155
++ echo $(expr $(date "+%s%3N") - ${start_time_ms} ) > .junit/time;
156
++ fi
157
++
158
+ if test "$chain_lint" = "t"; then
159
+ test_eval_ "(exit 117) && $1"
160
+ if test "$?" != 117; then
161
+@@ -355,8 +427,18 @@ test_skip_() {
162
of_prereq=" of $test_prereq"
163
fi
164
@@ -152,7 +169,7 @@ index 6750ff7..7d9915a 100644
169
+
170
+ if test -n "$TEST_GENERATE_JUNIT"; then
171
+ cat > ".junit/case-$(printf "%04d" $test_count)" <<-EOF
155
-+ <testcase name="$test_count - $(echo $2 | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}">
172
++ <testcase name="$test_count - $(echo $2 | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="0">
173
+ <skipped>
174
+ skip $(echo $1 | esc_xml) (missing $missing_prereq${of_prereq})
175
+ </skipped>
@@ -162,7 +179,7 @@ index 6750ff7..7d9915a 100644
179
: true
180
;;
181
*)
165
-@@ -403,7 +476,7 @@ test_expect_success() {
182
+@@ -403,7 +485,7 @@ test_expect_success() {
183
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
184
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_success"
185
export test_prereq
@@ -171,7 +188,7 @@ index 6750ff7..7d9915a 100644
188
say >&3 "expecting success: $2"
189
if test_run_ "$2"; then
190
test_ok_ "$1"
174
-@@ -442,7 +515,7 @@ test_expect_failure() {
191
+@@ -442,7 +524,7 @@ test_expect_failure() {
192
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
193
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_failure"
194
export test_prereq
@@ -180,7 +197,7 @@ index 6750ff7..7d9915a 100644
197
say >&3 "checking known breakage: $2"
198
if test_run_ "$2" expecting_failure; then
199
test_known_broken_ok_ "$1"
183
-@@ -675,6 +748,7 @@ test_done() {
200
+@@ -675,6 +757,7 @@ test_done() {
201
test_results_dir="$SHARNESS_TEST_DIRECTORY/test-results"
202
mkdir -p "$test_results_dir"
203
test_results_path="$test_results_dir/${SHARNESS_TEST_FILE%.$SHARNESS_TEST_EXTENSION}.$$.counts"
@@ -188,14 +205,16 @@ index 6750ff7..7d9915a 100644
205
206
cat >>"$test_results_path" <<-EOF
207
total $test_count
191
-@@ -684,6 +758,14 @@ test_done() {
208
+@@ -684,6 +767,16 @@ test_done() {
209
failed $test_failure
210
211
EOF
212
+
213
+ if test -n "$TEST_GENERATE_JUNIT"; then
214
++ time_sec="$(cat .junit/time_total | xargs printf "%04d" | sed -e 's/\(...\)$/.\1/g')"
215
++
216
+ cat >>"$junit_results_path" <<-EOF
198
-+ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" package="sharness$(uname -s).${SHARNESS_TEST_NAME}">
217
++ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" package="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="${time_sec}">
218
+ $(find .junit -name 'case-*' | sort | xargs cat)
219
+ </testsuite>
220
+ EOF
@@ -203,7 +222,7 @@ index 6750ff7..7d9915a 100644
222
fi
223
224
if test "$test_fixed" != 0; then
206
-@@ -745,6 +827,9 @@ export PATH SHARNESS_BUILD_DIRECTORY
225
+@@ -745,6 +838,9 @@ export PATH SHARNESS_BUILD_DIRECTORY
226
SHARNESS_TEST_FILE="$0"
227
export SHARNESS_TEST_FILE
228
@@ -213,18 +232,19 @@ index 6750ff7..7d9915a 100644
232
# Prepare test area.
233
test_dir="trash directory.$(basename "$SHARNESS_TEST_FILE" ".$SHARNESS_TEST_EXTENSION")"
234
test -n "$root" && test_dir="$root/$test_dir"
216
-@@ -771,6 +856,11 @@ mkdir -p "$test_dir" || exit 1
235
+@@ -771,6 +867,12 @@ mkdir -p "$test_dir" || exit 1
236
# in subprocesses like git equals our $PWD (for pathname comparisons).
237
cd -P "$test_dir" || exit 1
238
239
+# Prepare JUnit report dir
240
+if test -n "$TEST_GENERATE_JUNIT"; then
241
+ mkdir -p .junit
242
++ echo 0 > .junit/time_total
243
+fi
244
+
245
this_test=${SHARNESS_TEST_FILE##*/}
246
this_test=${this_test%.$SHARNESS_TEST_EXTENSION}
247
for skp in $SKIP_TESTS; do
248
--
229
-2.16.2
249
+2.17.0
250
test/sharness/lib/install-sharness.sh
+1
-1
@@ -7,7 +7,7 @@
7
8
# settings
9
version=5eee9b51b5621cec95a64018f0cc779963b230d2
10
-patch_version=8
10
+patch_version=17
11
12
urlprefix=https://github.com/mlafeldt/sharness.git
13
if test ! -n "$clonedir" ; then