]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-11-ISSUE-3166/test.sh
tests: don't fail if QEMU is not available
[thirdparty/systemd.git] / test / TEST-11-ISSUE-3166 / test.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3166"
5
6 . $TEST_BASE_DIR/test-functions
7 SKIP_INITRD=yes
8
9 check_result_qemu() {
10 ret=1
11 mkdir -p $TESTDIR/root
12 mount ${LOOPDEV}p1 $TESTDIR/root
13 [[ -e $TESTDIR/root/testok ]] && ret=0
14 [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
15 cp -a $TESTDIR/root/var/log/journal $TESTDIR
16 umount $TESTDIR/root
17 [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
18 ls -l $TESTDIR/journal/*/*.journal
19 test -s $TESTDIR/failed && ret=$(($ret+1))
20 return $ret
21 }
22
23 test_run() {
24 if run_qemu; then
25 check_result_qemu || return 1
26 else
27 dwarn "can't run QEMU, skipping"
28 fi
29 return 0
30 }
31
32 test_setup() {
33 create_empty_image
34 mkdir -p $TESTDIR/root
35 mount ${LOOPDEV}p1 $TESTDIR/root
36
37 # Create what will eventually be our root filesystem onto an overlay
38 (
39 LOG_LEVEL=5
40 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
41
42 setup_basic_environment
43 dracut_install false touch
44
45 # setup the testsuite service
46 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
47 [Unit]
48 Description=Testsuite service
49 After=multi-user.target
50
51 [Service]
52 ExecStart=/test-fail-on-restart.sh
53 Type=oneshot
54 EOF
55
56 cat >$initdir/etc/systemd/system/fail-on-restart.service <<EOF
57 [Unit]
58 Description=Fail on restart
59
60 [Service]
61 Type=simple
62 ExecStart=/bin/false
63 Restart=always
64 EOF
65
66
67 cat >$initdir/test-fail-on-restart.sh <<'EOF'
68 #!/bin/bash -x
69
70 systemctl start fail-on-restart.service
71 active_state=$(systemctl show --property ActiveState fail-on-restart.service)
72 while [[ "$active_state" == "ActiveState=activating" || "$active_state" == "ActiveState=active" ]]; do
73 sleep 1
74 active_state=$(systemctl show --property ActiveState fail-on-restart.service)
75 done
76 systemctl is-failed fail-on-restart.service || exit 1
77 touch /testok
78 EOF
79
80 chmod 0755 $initdir/test-fail-on-restart.sh
81 setup_testsuite
82 ) || return 1
83
84 ddebug "umount $TESTDIR/root"
85 umount $TESTDIR/root
86 }
87
88 test_cleanup() {
89 umount $TESTDIR/root 2>/dev/null
90 [[ $LOOPDEV ]] && losetup -d $LOOPDEV
91 return 0
92 }
93
94 do_test "$@"