ITS#10499 tests: record test results as junit.xml

This commit is contained in:
Ondřej Kuzník 2026-04-30 15:34:26 +01:00 committed by Quanah Gibson-Mount
parent 252153aa0b
commit 9cbcfe748a
4 changed files with 99 additions and 4 deletions

1
.gitignore vendored
View file

@ -119,3 +119,4 @@ tests/schema
tests/testdata
tests/testrun
tests/run
tests/junit*

View file

@ -36,6 +36,7 @@ fi
echo ">>>>> $(timer) Executing all LDAP tests for $BACKEND"
junit_setup "$BACKEND"
if [ -n "$NOEXIT" ]; then
echo "Result Test" > $TESTWD/results
fi
@ -63,24 +64,45 @@ for CMD in $SRCDIR/scripts/test*; do
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
START=`date +%s`
if [ -n "$TESTINST" ]; then
if [ -n "$JUNIT_OUTPUT" ]; then
# capture the output so we can paste it into the report
{ $CMD 2>&1; echo $? > "$JUNIT_RC"; } | tee "$JUNIT_LOG"
RC=`cat "$JUNIT_RC"`
elif [ -n "$TESTINST" ]; then
$CMD 2>&1
RC=$?
else
$CMD
RC=$?
fi
RC=$?
END=`date +%s`
if test $RC -eq 0 ; then
MSG=">>>>> $(timer) Finished $BCMD for $BACKEND after $(( $END - $START )) seconds."
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
if [ -n "$JUNIT_OUTPUT" ]; then
printf '\t<testcase classname="%s" name="%s" time="%d"/>\n' \
"$BACKEND" "$BCMD" "$(( $END - $START ))" \
>> "$JUNIT_TMP"
fi
else
MSG=">>>>> $(timer) Failed $BCMD for $BACKEND after $(( $END - $START )) seconds"
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
FAILCOUNT=`expr $FAILCOUNT + 1`
if [ -n "$JUNIT_OUTPUT" ]; then
{
printf '\t<testcase classname="%s" name="%s" time="%d">\n' \
"$BACKEND" "$BCMD" "$(( $END - $START ))"
printf '\t\t<failure message="exited with %s">' "$RC"
xml_escape < "$JUNIT_LOG"
echo ' </failure>'
echo ' </testcase>'
} >> "$JUNIT_TMP"
fi
if [ -n "$NOEXIT" ]; then
echo "Continuing."
else
@ -94,6 +116,14 @@ for CMD in $SRCDIR/scripts/test*; do
echo "$MSG"
SKIPCOUNT=`expr $SKIPCOUNT + 1`
RC="-"
if [ -n "$JUNIT_OUTPUT" ]; then
{
printf '\t<testcase classname="%s" name="%s" time="0">\n' \
"$BACKEND" "$BCMD"
echo ' <skipped/>'
echo ' </testcase>'
} >> "$JUNIT_TMP"
fi
fi
if [ -n "$NOEXIT" ]; then

View file

@ -20,3 +20,37 @@ timer() {
date -u $DATEOPT$delta +%T
fi
}
xml_escape() {
sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
}
junit_finalize() {
[ -n "$JUNIT_OUTPUT" ] || return 0
[ -f "$JUNIT_TMP" ] || return 0
JUNIT_END=`date +%s`
JUNIT_TOTAL=`grep -c '<testcase' "$JUNIT_TMP" 2>/dev/null`
[ -z "$JUNIT_TOTAL" ] && JUNIT_TOTAL=0
{
echo '<?xml version="1.0" encoding="UTF-8"?>'
printf '<testsuite name="%s" tests="%d" failures="%d" skipped="%d" time="%d">\n' \
"$JUNIT_NAME" "$JUNIT_TOTAL" "$FAILCOUNT" "$SKIPCOUNT" \
"$(( $JUNIT_END - $JUNIT_START ))"
cat "$JUNIT_TMP"
echo '</testsuite>'
} > "$JUNIT_OUTPUT"
rm -f "$JUNIT_TMP" "$JUNIT_LOG" "$JUNIT_RC"
}
junit_setup() {
JUNIT_NAME="${1:-$BACKEND}"
JUNIT_OUTPUT="${JUNIT_OUTPUT-$TESTWD/junit$TESTINST-$JUNIT_NAME.xml}"
if [ -n "$JUNIT_OUTPUT" ]; then
JUNIT_TMP="$TESTWD/junit_tmp$TESTINST"
JUNIT_LOG="$TESTWD/junit_current$TESTINST.log"
JUNIT_RC="$TESTWD/junit_current$TESTINST.rc"
: > "$JUNIT_TMP"
JUNIT_START=`date +%s`
trap junit_finalize EXIT
fi
}

View file

@ -36,6 +36,7 @@ fi
echo ">>>>> $(timer) Executing all LDAP tests for the Load Balancer"
junit_setup "lloadd+$BACKEND"
if [ -n "$NOEXIT" ]; then
echo "Result Test" > $TESTWD/results
fi
@ -62,24 +63,45 @@ for CMD in $SRCDIR/scripts/lloadd/test*; do
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
START=`date +%s`
if [ -n "$TESTINST" ]; then
if [ -n "$JUNIT_OUTPUT" ]; then
# capture the output so we can paste it into the report
{ $CMD 2>&1; echo $? > "$JUNIT_RC"; } | tee "$JUNIT_LOG"
RC=`cat "$JUNIT_RC"`
elif [ -n "$TESTINST" ]; then
$CMD 2>&1
RC=$?
else
$CMD
RC=$?
fi
RC=$?
END=`date +%s`
if test $RC -eq 0 ; then
MSG=">>>>> $(timer) Finished $BCMD for lloadd+$BACKEND after $(( $END - $START )) seconds."
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
if [ -n "$JUNIT_OUTPUT" ]; then
printf '\t<testcase classname="%s" name="%s" time="%d"/>\n' \
"$BACKEND" "$BCMD" "$(( $END - $START ))" \
>> "$JUNIT_TMP"
fi
else
MSG=">>>>> $(timer) Failed $BCMD for lloadd+$BACKEND after $(( $END - $START )) seconds"
[ -n "$TESTINST" ] && echo "$MSG" >&2
echo "$MSG"
FAILCOUNT=`expr $FAILCOUNT + 1`
if [ -n "$JUNIT_OUTPUT" ]; then
{
printf '\t<testcase classname="%s" name="%s" time="%d">\n' \
"$BACKEND" "$BCMD" "$(( $END - $START ))"
printf '\t\t<failure message="exited with %s">' "$RC"
xml_escape < "$JUNIT_LOG"
echo ' </failure>'
echo ' </testcase>'
} >> "$JUNIT_TMP"
fi
if [ -n "$NOEXIT" ]; then
echo "Continuing."
else
@ -93,6 +115,14 @@ for CMD in $SRCDIR/scripts/lloadd/test*; do
echo "$MSG"
SKIPCOUNT=`expr $SKIPCOUNT + 1`
RC="-"
if [ -n "$JUNIT_OUTPUT" ]; then
{
printf '\t<testcase classname="%s" name="%s" time="0">\n' \
"$BACKEND" "$BCMD"
echo ' <skipped/>'
echo ' </testcase>'
} >> "$JUNIT_TMP"
fi
fi
if [ -n "$NOEXIT" ]; then