Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Collect test times for sharness #4959

Merged
merged 1 commit into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 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 bc6bf844ef4e4cd468bc1ec96f2d6af738eb8d2f 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 22:01:45 +0200
Subject: [PATCH] Generate partial JUnit reports

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

diff --git a/sharness.sh b/sharness.sh
index 6750ff7..7d9915a 100644
index 6750ff7..336e426 100644
--- a/sharness.sh
+++ b/sharness.sh
@@ -1,4 +1,4 @@
Expand Down Expand Up @@ -46,13 +46,13 @@ index 6750ff7..7d9915a 100644
+esc=$(printf '\033')
+
+esc_xml() {
+ sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"$esc"'/\&#27;/g; s///g;'
+ sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"$esc"'//g; s///g;'
+}
+
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,78 @@ test_have_prereq() {
test $total_prereq = $ok_prereq
}

Expand All @@ -65,10 +65,13 @@ index 6750ff7..7d9915a 100644
+
+ test_name=$1
+ tc_file=".junit/case-$(printf "%04d" $test_count)"
+ time_sec="$(cat .junit/time | xargs printf '%04d' | sed -e 's/\(...\)$/.\1/g')"
+
+ echo "$(expr $(cat .junit/time_total) + $(cat .junit/time) )" > .junit/time_total
+
+ 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 +92,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,7 +131,7 @@ index 6750ff7..7d9915a 100644
}

# Public: Execute commands in debug mode.
@@ -310,7 +369,11 @@ test_pause() {
@@ -310,15 +372,25 @@ test_pause() {
test_eval_() {
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
Expand All @@ -141,7 +144,21 @@ index 6750ff7..7d9915a 100644
}

test_run_() {
@@ -355,8 +418,18 @@ test_skip_() {
test_cleanup=:
expecting_failure=$2
+
+ start_time_ms=$(date "+%s%3N");
test_eval_ "$1"
eval_ret=$?

+ if test -n "$TEST_GENERATE_JUNIT"; then
+ echo $(expr $(date "+%s%3N") - ${start_time_ms} ) > .junit/time;
+ fi
+
if test "$chain_lint" = "t"; then
test_eval_ "(exit 117) && $1"
if test "$?" != 117; then
@@ -355,8 +427,18 @@ test_skip_() {
of_prereq=" of $test_prereq"
fi

Expand All @@ -152,7 +169,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 +179,7 @@ index 6750ff7..7d9915a 100644
: true
;;
*)
@@ -403,7 +476,7 @@ test_expect_success() {
@@ -403,7 +485,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 +188,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 +524,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,30 +197,32 @@ 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 +757,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 +767,16 @@ test_done() {
failed $test_failure

EOF
+
+ if test -n "$TEST_GENERATE_JUNIT"; then
+ time_sec="$(cat .junit/time_total | xargs printf "%04d" | sed -e 's/\(...\)$/.\1/g')"
+
+ cat >>"$junit_results_path" <<-EOF
+ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" package="sharness$(uname -s).${SHARNESS_TEST_NAME}">
+ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" package="sharness$(uname -s).${SHARNESS_TEST_NAME}" time="${time_sec}">
+ $(find .junit -name 'case-*' | sort | xargs cat)
+ </testsuite>
+ EOF
+ fi
fi

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

Expand All @@ -213,18 +232,19 @@ 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 +867,12 @@ mkdir -p "$test_dir" || exit 1
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$test_dir" || exit 1

+# Prepare JUnit report dir
+if test -n "$TEST_GENERATE_JUNIT"; then
+ mkdir -p .junit
+ echo 0 > .junit/time_total
+fi
+
this_test=${SHARNESS_TEST_FILE##*/}
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=17

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