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