1#!/bin/bash 2 3usage() { 4 echo "Usage: $0 tests-dir xml-out" 5} 6 7xml_out=$2 8if [ -z "$xml_out" ]; then 9 xml_out=/dev/null 10fi 11printf '<?xml version="1.0" encoding="UTF-8"?>\n' > "$xml_out" 12printf '<testsuites name="tools.tests">\n' >> "$xml_out" 13printf ' <testsuite name="tools.tests">\n' >> "$xml_out" 14failed= 15for f in "$1"/*; do 16 if [ ! -x "$f" ]; then 17 echo "SKIP: $f not executable" 18 continue 19 fi 20 echo "Running $f" 21 time_start=$EPOCHREALTIME 22 "$f" 2>&1 | tee /tmp/out 23 ret=${PIPESTATUS[0]} 24 time_end=$EPOCHREALTIME 25 time_delta="$(bc <<<"$time_end - $time_start")" 26 printf ' <testcase name="%s" time="%f">\n' "$f" "$time_delta" >> "$xml_out" 27 if [ "$ret" -ne 0 ]; then 28 echo "FAILED: $f" 29 failed+=" $f" 30 printf ' <failure type="failure" message="binary %s exited with code %d">\n' "$f" "$ret" >> "$xml_out" 31 printf '<![CDATA[' >> "$xml_out" 32 # TODO: Escape ']]>' if necessary 33 cat /tmp/out >> "$xml_out" 34 printf ']]>\n' >> "$xml_out" 35 printf ' </failure>\n' >> "$xml_out" 36 else 37 echo "PASSED" 38 fi 39 printf ' </testcase>\n' >> "$xml_out" 40done 41printf ' </testsuite>\n' >> "$xml_out" 42printf '</testsuites>\n' >> "$xml_out" 43 44if [ -n "$failed" ]; then 45 exit 1 46fi 47