]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-11-ISSUE-3166/test.sh
test: add function to reduce copied setup boilerplate
[thirdparty/systemd.git] / test / TEST-11-ISSUE-3166 / test.sh
1 #!/bin/bash
2 set -e
3 TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/3166"
4 TEST_NO_NSPAWN=1
5
6 . $TEST_BASE_DIR/test-functions
7
8 test_setup() {
9 create_empty_image_rootdir
10
11 # Create what will eventually be our root filesystem onto an overlay
12 (
13 LOG_LEVEL=5
14 eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
15
16 setup_basic_environment
17 mask_supporting_services
18 dracut_install false touch
19
20 # setup the testsuite service
21 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
22 [Unit]
23 Description=Testsuite service
24
25 [Service]
26 ExecStart=/test-fail-on-restart.sh
27 Type=oneshot
28 EOF
29
30 cat >$initdir/etc/systemd/system/fail-on-restart.service <<EOF
31 [Unit]
32 Description=Fail on restart
33 StartLimitIntervalSec=1m
34 StartLimitBurst=3
35
36 [Service]
37 Type=simple
38 ExecStart=/bin/false
39 Restart=always
40 EOF
41
42
43 cat >$initdir/test-fail-on-restart.sh <<'EOF'
44 #!/bin/bash -x
45
46 systemctl start fail-on-restart.service
47 active_state=$(systemctl show --property ActiveState fail-on-restart.service)
48 while [[ "$active_state" == "ActiveState=activating" || "$active_state" == "ActiveState=active" ]]; do
49 sleep 1
50 active_state=$(systemctl show --property ActiveState fail-on-restart.service)
51 done
52 systemctl is-failed fail-on-restart.service || exit 1
53 touch /testok
54 EOF
55
56 chmod 0755 $initdir/test-fail-on-restart.sh
57 setup_testsuite
58 )
59 }
60
61 do_test "$@"