Files
xen/automation/scripts/run-tools-tests
T
Marek Marczykowski-Górecki b0a94e392c automation: add jobs running tests from tools/tests/*
There are a bunch of tests in tools/tests/, let them run in CI.
For each subdirectory expect "make run" will run the test, and observe
its exit code. This way, adding new tests is easy, and they will be
automatically picked up.

For better visibility, log test output to junit xml format, and let
gitlab ingest it. Set SUT_ADDR variable with name/address of the system
under test, so a network can be used to extract the file. The actual
address is set using DHCP. And for the test internal network, still add
the 192.168.0.1 IP (but don't replace the DHCP-provided one).

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@amd.com>
(cherry picked from commit fc10d6ecdd)
2025-05-07 15:28:02 +01:00

48 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
usage() {
echo "Usage: $0 tests-dir xml-out"
}
xml_out=$2
if [ -z "$xml_out" ]; then
xml_out=/dev/null
fi
printf '<?xml version="1.0" encoding="UTF-8"?>\n' > "$xml_out"
printf '<testsuites name="tools.tests">\n' >> "$xml_out"
printf ' <testsuite name="tools.tests">\n' >> "$xml_out"
failed=
for dir in "$1"/*; do
[ -d "$dir" ] || continue
echo "Running test in $dir"
printf ' <testcase name="%s">\n' "$dir" >> "$xml_out"
ret=
for f in "$dir"/*; do
[ -f "$f" ] || continue
[ -x "$f" ] || continue
"$f" 2>&1 | tee /tmp/out
ret=$?
if [ "$ret" -ne 0 ]; then
echo "FAILED: $ret"
failed+=" $dir"
printf ' <failure type="failure" message="binary %s exited with code %d">\n' "$f" "$ret" >> "$xml_out"
# TODO: could use xml escaping... but current tests seems to
# produce sane output
cat /tmp/out >> "$xml_out"
printf ' </failure>\n' >> "$xml_out"
else
echo "PASSED"
fi
done
if [ -z "$ret" ]; then
printf ' <skipped type="skipped" message="no executable test found in %s"/>\n' "$dir" >> "$xml_out"
fi
printf ' </testcase>\n' >> "$xml_out"
done
printf ' </testsuite>\n' >> "$xml_out"
printf '</testsuites>\n' >> "$xml_out"
if [ -n "$failed" ]; then
exit 1
fi