Skip to content

Commit

Permalink
ci: Collect test times for sharness
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Apr 21, 2018
1 parent 8b383da commit d57d5b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
43 changes: 25 additions & 18 deletions test/sharness/lib/0001-Generate-partial-JUnit-reports.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
From 76b34f25b2bacdd30138b25ccbe0672d76a1632a Mon Sep 17 00:00:00 2001
From 57babdc669bb6b730f590865bcc39d9cb834f294 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Magiera?= <magik6k@gmail.com>
Date: Thu, 22 Mar 2018 06:11:01 +0100
Date: Sat, 21 Apr 2018 19:26:10 +0200
Subject: [PATCH] Generate partial JUnit reports

---
sharness.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 96 insertions(+), 6 deletions(-)
sharness.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 103 insertions(+), 6 deletions(-)

diff --git a/sharness.sh b/sharness.sh
index 6750ff7..7d9915a 100644
index 6750ff7..cfae17a 100644
--- a/sharness.sh
+++ b/sharness.sh
@@ -1,4 +1,4 @@
Expand Down Expand Up @@ -52,7 +52,7 @@ index 6750ff7..7d9915a 100644
test -n "$test_description" || error "Test script did not set test_description."

if test "$help" = "t"; then
@@ -251,30 +265,75 @@ test_have_prereq() {
@@ -251,30 +265,76 @@ test_have_prereq() {
test $total_prereq = $ok_prereq
}

Expand All @@ -65,10 +65,11 @@ index 6750ff7..7d9915a 100644
+
+ test_name=$1
+ tc_file=".junit/case-$(printf "%04d" $test_count)"
+ time_sec="$(cat .junit/time | sed -e 's/\(...\)$/.\1/g')"
+
+ shift
+ cat > "$tc_file" <<-EOF
+ <testcase name="$test_count - $(echo $test_name | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}">
+ <testcase name="$test_count - $(echo $test_name | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="${time_sec}">
+ $@
+ EOF
+
Expand All @@ -89,7 +90,7 @@ index 6750ff7..7d9915a 100644
+ fi
+
+ echo "</testcase>" >> "$tc_file"
+ rm -f .junit/tout .junit/terr
+ rm -f .junit/tout .junit/terr .junit/time
+}
+
# You are not expected to call test_ok_ and test_failure_ directly, use
Expand Down Expand Up @@ -128,20 +129,26 @@ index 6750ff7..7d9915a 100644
}

# Public: Execute commands in debug mode.
@@ -310,7 +369,11 @@ test_pause() {
@@ -310,7 +370,17 @@ test_pause() {
test_eval_() {
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
- eval </dev/null >&3 2>&4 "$*"
+ if test -n "$TEST_GENERATE_JUNIT"; then
+ date "+%s%3N" > .junit/start
+
+ eval </dev/null > >(tee -a .junit/tout >&3) 2> >(tee -a .junit/terr >&4) "$*"
+ status=$?
+
+ echo $(expr $(date "+%s%3N") - $(cat ".junit/start") ) > .junit/time
+ return ${status}
+ else
+ eval </dev/null >&3 2>&4 "$*"
+ fi
}

test_run_() {
@@ -355,8 +418,18 @@ test_skip_() {
@@ -355,8 +425,18 @@ test_skip_() {
of_prereq=" of $test_prereq"
fi

Expand All @@ -152,7 +159,7 @@ index 6750ff7..7d9915a 100644
+
+ if test -n "$TEST_GENERATE_JUNIT"; then
+ cat > ".junit/case-$(printf "%04d" $test_count)" <<-EOF
+ <testcase name="$test_count - $(echo $2 | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}">
+ <testcase name="$test_count - $(echo $2 | esc_xml)" classname="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="0">
+ <skipped>
+ skip $(echo $1 | esc_xml) (missing $missing_prereq${of_prereq})
+ </skipped>
Expand All @@ -162,7 +169,7 @@ index 6750ff7..7d9915a 100644
: true
;;
*)
@@ -403,7 +476,7 @@ test_expect_success() {
@@ -403,7 +483,7 @@ test_expect_success() {
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_success"
export test_prereq
Expand All @@ -171,7 +178,7 @@ index 6750ff7..7d9915a 100644
say >&3 "expecting success: $2"
if test_run_ "$2"; then
test_ok_ "$1"
@@ -442,7 +515,7 @@ test_expect_failure() {
@@ -442,7 +522,7 @@ test_expect_failure() {
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_failure"
export test_prereq
Expand All @@ -180,15 +187,15 @@ index 6750ff7..7d9915a 100644
say >&3 "checking known breakage: $2"
if test_run_ "$2" expecting_failure; then
test_known_broken_ok_ "$1"
@@ -675,6 +748,7 @@ test_done() {
@@ -675,6 +755,7 @@ test_done() {
test_results_dir="$SHARNESS_TEST_DIRECTORY/test-results"
mkdir -p "$test_results_dir"
test_results_path="$test_results_dir/${SHARNESS_TEST_FILE%.$SHARNESS_TEST_EXTENSION}.$$.counts"
+ junit_results_path="$test_results_dir/${SHARNESS_TEST_FILE%.$SHARNESS_TEST_EXTENSION}.$$.xml.part"

cat >>"$test_results_path" <<-EOF
total $test_count
@@ -684,6 +758,14 @@ test_done() {
@@ -684,6 +765,14 @@ test_done() {
failed $test_failure

EOF
Expand All @@ -203,7 +210,7 @@ index 6750ff7..7d9915a 100644
fi

if test "$test_fixed" != 0; then
@@ -745,6 +827,9 @@ export PATH SHARNESS_BUILD_DIRECTORY
@@ -745,6 +834,9 @@ export PATH SHARNESS_BUILD_DIRECTORY
SHARNESS_TEST_FILE="$0"
export SHARNESS_TEST_FILE

Expand All @@ -213,7 +220,7 @@ index 6750ff7..7d9915a 100644
# Prepare test area.
test_dir="trash directory.$(basename "$SHARNESS_TEST_FILE" ".$SHARNESS_TEST_EXTENSION")"
test -n "$root" && test_dir="$root/$test_dir"
@@ -771,6 +856,11 @@ mkdir -p "$test_dir" || exit 1
@@ -771,6 +863,11 @@ mkdir -p "$test_dir" || exit 1
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$test_dir" || exit 1

Expand All @@ -226,5 +233,5 @@ index 6750ff7..7d9915a 100644
this_test=${this_test%.$SHARNESS_TEST_EXTENSION}
for skp in $SKIP_TESTS; do
--
2.16.2
2.17.0

2 changes: 1 addition & 1 deletion test/sharness/lib/install-sharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# settings
version=5eee9b51b5621cec95a64018f0cc779963b230d2
patch_version=8
patch_version=10

urlprefix=https://github.com/mlafeldt/sharness.git
if test ! -n "$clonedir" ; then
Expand Down

0 comments on commit d57d5b2

Please sign in to comment.