]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10499 tests: record test results as junit.xml
authorOndřej Kuzník <ondra@mistotebe.net>
Thu, 30 Apr 2026 14:34:26 +0000 (15:34 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 14 May 2026 19:58:38 +0000 (19:58 +0000)
.gitignore
tests/scripts/all
tests/scripts/functions.sh
tests/scripts/lloadd-all

index ec97386edc214268b4dc06e5c79abd28abc23e37..63d93ede7f2b70c0e740fc9e1bfb6f74dd66e04e 100644 (file)
@@ -119,3 +119,4 @@ tests/schema
 tests/testdata
 tests/testrun
 tests/run
+tests/junit*
index e29cd31cd9b88c1593f23b75ef17dec917ace1e7..8ea81971e1a86d67d6e8fcf564d84c48319c6ca0 100755 (executable)
@@ -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
index d441fec68d9bfad9984f8b76f957ac565fe25c8a..b7e9ca259899e1a602d5abbcbb9f2000cd99acf8 100755 (executable)
@@ -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
+}
index 083da39974e0b3238c5ca2e0a89b212fe38d9167..7d5bec4871414e82283db926bf91be4bd78681e6 100755 (executable)
@@ -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