]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-02.sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
7 MAX_QUEUE_SIZE
=${NPROC:-2}
8 TESTS_GLOB
=${TESTS_GLOB:-test-*}
9 mapfile
-t TEST_LIST
< <(find /usr
/lib
/systemd
/tests
/ -maxdepth 1 -type f
-name "${TESTS_GLOB}")
12 rm -fv /failed-tests
/skipped-tests
/skipped
14 # Check & report test results
18 function report_result
() {
19 if [[ $# -ne 2 ]]; then
20 echo >&2 "check_result: missing arguments"
27 if [[ $ret -ne 0 && $ret != 77 ]]; then
28 echo "$name failed with $ret"
29 echo "$name" >>/failed-tests
31 echo "--- $name begin ---"
33 echo "--- $name end ---"
35 elif [[ $ret == 77 ]]; then
37 echo "$name" >>/skipped-tests
39 echo "--- $name begin ---"
41 echo "--- $name end ---"
45 echo "$name" >>/testok
48 systemd-cat
echo "--- $name ---"
49 systemd-cat
cat "/$name.log"
52 # Associative array for running tasks, where running[test-path]=PID
54 for task
in "${TEST_LIST[@]}"; do
55 # If there's MAX_QUEUE_SIZE running tasks, keep checking the running queue
56 # until one of the tasks finishes, so we can replace it.
57 while [[ ${#running[@]} -ge $MAX_QUEUE_SIZE ]]; do
58 for key
in "${!running[@]}"; do
59 if ! kill -0 "${running[$key]}" &>/dev
/null
; then
60 # Task has finished, report its result and drop it from the queue
61 wait "${running[$key]}" && ec
=0 || ec
=$?
62 report_result
"$key" $ec
64 # Break from inner for loop and outer while loop to skip
65 # the sleep below when we find a free slot in the queue
70 # Precisely* calculated constant to keep the spinlock from burning the CPU(s)
74 if [[ -x $task ]]; then
75 log_file
="/${task##*/}.log"
81 # Wait for remaining running tasks
82 for key
in "${!running[@]}"; do
83 wait ${running[$key]} && ec
=0 || ec
=$?
84 report_result
"$key" $ec
88 # Test logs are sometimes lost, as the system shuts down immediately after