mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-21 16:59:07 +08:00
ci: change VM's /exitstatus format to prepare it for several results
We recently introduced a summary for the results of the different groups of tests for the CI, displayed after the machine is shut down. There are currently two groups, "bpftool" and "vm_tests". We want to split the latter into different subgroups. For that, we will make each group of tests that runs in the VM print its exit status to the /exitstatus file. In preparation for this, let's update the format of this /exitstatus file. Instead of containing just an integer, it now contains a line with a group name, a colon, and the integer result. This is easy enough to parse on the other end. We also drop the associative array, and iterate on /exitstatus instead to produce the summary: this way, the order of the checks is preserved.
This commit is contained in:
committed by
Andrii Nakryiko
parent
7f11cd48d6
commit
385b2d1738
@@ -410,22 +410,22 @@ LIBBPF_PATH="${REPO_ROOT}" \
|
|||||||
REPO_PATH="${REPO_PATH}" \
|
REPO_PATH="${REPO_PATH}" \
|
||||||
VMLINUX_BTF=$(realpath ${source_vmlinux}) ${VMTEST_ROOT}/build_selftests.sh
|
VMLINUX_BTF=$(realpath ${source_vmlinux}) ${VMTEST_ROOT}/build_selftests.sh
|
||||||
|
|
||||||
declare -A test_results
|
|
||||||
|
|
||||||
travis_fold start bpftool_checks "Running bpftool checks..."
|
travis_fold start bpftool_checks "Running bpftool checks..."
|
||||||
|
bpftool_exitstatus=
|
||||||
if [[ "${KERNEL}" = 'LATEST' ]]; then
|
if [[ "${KERNEL}" = 'LATEST' ]]; then
|
||||||
# "&& true" does not change the return code (it is not executed if the
|
# "&& true" does not change the return code (it is not executed if the
|
||||||
# Python script fails), but it prevents the trap on ERR set at the top
|
# Python script fails), but it prevents the trap on ERR set at the top
|
||||||
# of this file to trigger on failure.
|
# of this file to trigger on failure.
|
||||||
"${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf/test_bpftool_synctypes.py" && true
|
"${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf/test_bpftool_synctypes.py" && true
|
||||||
test_results["bpftool"]=$?
|
bpftool_exitstatus=$?
|
||||||
if [[ ${test_results["bpftool"]} -eq 0 ]]; then
|
if [[ "$bpftool_exitstatus" -eq 0 ]]; then
|
||||||
print_notice bpftool_checks "bpftool checks passed successfully."
|
print_notice bpftool_checks "bpftool checks passed successfully."
|
||||||
else
|
else
|
||||||
print_error bpftool_checks "bpftool checks returned ${test_results["bpftool"]}."
|
print_error bpftool_checks "bpftool checks returned ${bpftool_exitstatus}."
|
||||||
fi
|
fi
|
||||||
|
bpftool_exitstatus="bpftool:${bpftool_exitstatus}"
|
||||||
else
|
else
|
||||||
echo "Consistency checks skipped."
|
echo "bpftool checks skipped."
|
||||||
fi
|
fi
|
||||||
travis_fold end bpftool_checks
|
travis_fold end bpftool_checks
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ cat <<HERE >"$tmp"
|
|||||||
"#!/bin/sh
|
"#!/bin/sh
|
||||||
|
|
||||||
echo 'Skipping setup commands'
|
echo 'Skipping setup commands'
|
||||||
echo 0 > /exitstatus
|
echo vm_start:0 > /exitstatus
|
||||||
chmod 644 /exitstatus
|
chmod 644 /exitstatus
|
||||||
HERE
|
HERE
|
||||||
|
|
||||||
@@ -476,7 +476,10 @@ set -eux
|
|||||||
echo 'Running setup commands'
|
echo 'Running setup commands'
|
||||||
${setup_envvars}
|
${setup_envvars}
|
||||||
set +e; ${setup_cmd}; exitstatus=\$?; set -e
|
set +e; ${setup_cmd}; exitstatus=\$?; set -e
|
||||||
echo \$exitstatus > /exitstatus
|
# If setup command did not write its exit status to /exitstatus, do it now
|
||||||
|
if [[ -s /exitstatus ]]; then
|
||||||
|
echo setup_cmd:\$exitstatus > /exitstatus
|
||||||
|
fi
|
||||||
chmod 644 /exitstatus
|
chmod 644 /exitstatus
|
||||||
HERE
|
HERE
|
||||||
fi
|
fi
|
||||||
@@ -533,29 +536,31 @@ fi
|
|||||||
-drive file="$IMG",format=raw,index=1,media=disk,if=virtio,cache=none \
|
-drive file="$IMG",format=raw,index=1,media=disk,if=virtio,cache=none \
|
||||||
-kernel "$vmlinuz" -append "root=/dev/vda rw console=$console kernel.panic=-1 $APPEND"
|
-kernel "$vmlinuz" -append "root=/dev/vda rw console=$console kernel.panic=-1 $APPEND"
|
||||||
|
|
||||||
if exitstatus="$(guestfish --ro -a "$IMG" -i cat /exitstatus 2>/dev/null)"; then
|
# Set exit status to 1 if at least one group test returned non-0
|
||||||
|
exitfile="${bpftool_exitstatus}${bpftool_exitstatus:+\n}"
|
||||||
|
exitfile+="$(guestfish --ro -a "$IMG" -i cat /exitstatus 2>/dev/null)"
|
||||||
|
exitstatus="$(echo -e "$exitfile" | awk --field-separator ':' \
|
||||||
|
'BEGIN { s=0 } { if ($2) {s=1} } END { print s }')"
|
||||||
|
|
||||||
|
if [[ "$exitstatus" =~ ^[0-9]+$ ]]; then
|
||||||
printf '\nTests exit status: %s\n' "$exitstatus" >&2
|
printf '\nTests exit status: %s\n' "$exitstatus" >&2
|
||||||
else
|
else
|
||||||
printf '\nCould not read tests exit status\n' >&2
|
printf '\nCould not read tests exit status ("%s")\n' "$exitstatus" >&2
|
||||||
exitstatus=1
|
exitstatus=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
travis_fold end shutdown
|
travis_fold end shutdown
|
||||||
|
|
||||||
test_results["vm_tests"]=$exitstatus
|
|
||||||
|
|
||||||
# Final summary - Don't use a fold, keep it visible
|
# Final summary - Don't use a fold, keep it visible
|
||||||
echo -e "\033[1;33mTest Results:\033[0m"
|
echo -e "\033[1;33mTest Results:\033[0m"
|
||||||
for testgroup in ${!test_results[@]}; do
|
echo -e "$exitfile" | while read result; do
|
||||||
|
testgroup=${result%:*}
|
||||||
|
status=${result#*:}
|
||||||
# Print final result for each group of tests
|
# Print final result for each group of tests
|
||||||
if [[ ${test_results[$testgroup]} -eq 0 ]]; then
|
if [[ "$status" -eq 0 ]]; then
|
||||||
printf "%20s: \033[1;32mPASS\033[0m\n" $testgroup
|
printf "%20s: \033[1;32mPASS\033[0m\n" "$testgroup"
|
||||||
else
|
else
|
||||||
printf "%20s: \033[1;31mFAIL\033[0m\n" $testgroup
|
printf "%20s: \033[1;31mFAIL\033[0m (returned %s)\n" "$testgroup" "$status"
|
||||||
fi
|
|
||||||
# Make exitstatus > 0 if at least one test group has failed
|
|
||||||
if [[ ${test_results[$testgroup]} -ne 0 ]]; then
|
|
||||||
exitstatus=1
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user