]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-24-UNIT-TESTS/testsuite.sh
test-network: change default sleep time of start_networkd()
[thirdparty/systemd.git] / test / TEST-24-UNIT-TESTS / testsuite.sh
1 #!/bin/bash
2 #set -ex
3 #set -o pipefail
4
5 NPROC=$(nproc)
6 MAX_QUEUE_SIZE=${NPROC:-2}
7 IFS=$'\n' TEST_LIST=($(ls /usr/lib/systemd/tests/test-*))
8
9 # Check & report test results
10 # Arguments:
11 # $1: test path
12 # $2: test exit code
13 function report_result() {
14 if [[ $# -ne 2 ]]; then
15 echo >&2 "check_result: missing arguments"
16 exit 1
17 fi
18
19 local name="${1##*/}"
20 local ret=$2
21
22 if [[ $ret -ne 0 && $ret != 77 ]]; then
23 echo "$name failed with $ret"
24 echo "$name" >> /failed-tests
25 {
26 echo "--- $name begin ---"
27 cat "/$name.log"
28 echo "--- $name end ---"
29 } >> /failed
30 elif [[ $ret == 77 ]]; then
31 echo "$name skipped"
32 echo "$name" >> /skipped-tests
33 {
34 echo "--- $name begin ---"
35 cat "/$name.log"
36 echo "--- $name end ---"
37 } >> /skipped
38 else
39 echo "$name OK"
40 echo "$name" >> /testok
41 fi
42
43 systemd-cat echo "--- $name ---"
44 systemd-cat cat "/$name.log"
45 }
46
47 # Associative array for running tasks, where running[test-path]=PID
48 declare -A running=()
49 for task in "${TEST_LIST[@]}"; do
50 # If there's MAX_QUEUE_SIZE running tasks, keep checking the running queue
51 # until one of the tasks finishes, so we can replace it.
52 while [[ ${#running[@]} -ge $MAX_QUEUE_SIZE ]]; do
53 for key in "${!running[@]}"; do
54 if ! kill -0 ${running[$key]} &>/dev/null; then
55 # Task has finished, report its result and drop it from the queue
56 wait ${running[$key]}
57 ec=$?
58 report_result "$key" $ec
59 unset running["$key"]
60 # Break from inner for loop and outer while loop to skip
61 # the sleep below when we find a free slot in the queue
62 break 2
63 fi
64 done
65
66 # Precisely* calculated constant to keep the spinlock from burning the CPU(s)
67 sleep 0.01
68 done
69
70 if [[ -x $task ]]; then
71 log_file="/${task##*/}.log"
72 $task &> "$log_file" &
73 running[$task]=$!
74 fi
75 done
76
77 # Wait for remaining running tasks
78 for key in "${!running[@]}"; do
79 wait ${running[$key]}
80 ec=$?
81 report_result "$key" $ec
82 unset running["$key"]
83 done
84
85 exit 0