]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-02-UNITTESTS/test.sh
Merge pull request #18863 from keszybz/cmdline-escaping
[thirdparty/systemd.git] / test / TEST-02-UNITTESTS / test.sh
1 #!/usr/bin/env bash
2 set -e
3
4 TEST_DESCRIPTION="Run unit tests under containers"
5 RUN_IN_UNPRIVILEGED_CONTAINER=yes
6
7 # embed some newlines in the kernel command line to stress our test suite
8 KERNEL_APPEND="
9
10 frobnicate!
11
12 $KERNEL_APPEND
13 "
14
15 # shellcheck source=test/test-functions
16 . "${TEST_BASE_DIR:?}/test-functions"
17
18 check_result_nspawn() {
19 local workspace="${1:?}"
20 local ret=1
21
22 [[ -e "$workspace/testok" ]] && ret=0
23
24 if [[ -s "$workspace/failed" ]]; then
25 ret=$((ret + 1))
26 echo "=== Failed test log ==="
27 cat "$workspace/failed"
28 else
29 if [[ -s "$workspace/skipped" ]]; then
30 echo "=== Skipped test log =="
31 cat "$workspace/skipped"
32 fi
33 if [[ -s "$workspace/testok" ]]; then
34 echo "=== Passed tests ==="
35 cat "$workspace/testok"
36 fi
37 fi
38
39 save_journal "$workspace/var/log/journal"
40 _umount_dir "${initdir:?}"
41
42 [[ -n "${TIMED_OUT:=}" ]] && ret=1
43 return $ret
44 }
45
46 check_result_qemu() {
47 local ret=1
48
49 mount_initdir
50 [[ -e "${initdir:?}/testok" ]] && ret=0
51
52 if [[ -s "$initdir/failed" ]]; then
53 ret=$((ret + 1))
54 echo "=== Failed test log ==="
55 cat "$initdir/failed"
56 else
57 if [[ -s "$initdir/skipped" ]]; then
58 echo "=== Skipped test log =="
59 cat "$initdir/skipped"
60 fi
61 if [[ -s "$initdir/testok" ]]; then
62 echo "=== Passed tests ==="
63 cat "$initdir/testok"
64 fi
65 fi
66
67 save_journal "$initdir/var/log/journal"
68 _umount_dir "$initdir"
69
70 [[ -n "${TIMED_OUT:=}" ]] && ret=1
71 return $ret
72 }
73
74 do_test "$@"