summaryrefslogtreecommitdiffstats
path: root/test/units/TEST-81-GENERATORS.debug-generator.sh
blob: ef1e205aacfeee6fda2048b391374d81a20e177a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# shellcheck disable=SC2235
set -eux
set -o pipefail

# shellcheck source=test/units/generator-utils.sh
. "$(dirname "$0")/generator-utils.sh"

GENERATOR_BIN="/usr/lib/systemd/system-generators/systemd-debug-generator"
OUT_DIR="$(mktemp -d /tmp/debug-generator.XXX)"

at_exit() {
    rm -frv "${OUT_DIR:?}"
}

trap at_exit EXIT

test -x "${GENERATOR_BIN:?}"

# Potential FIXME:
#   - debug-generator should gracefully handle duplicated mask/wants
#   - also, handle gracefully empty mask/wants
ARGS=(
    "systemd.mask=masked-no-suffix"
    "systemd.mask=masked.service"
    "systemd.mask=masked.socket"
    "systemd.wants=wanted-no-suffix"
    "systemd.wants=wanted.service"
    "systemd.wants=wanted.mount"
    "rd.systemd.mask=masked-initrd.service"
    "rd.systemd.wants=wanted-initrd.service"
)

# Regular (non-initrd) scenario
#
: "debug-shell: regular"
CMDLINE="ro root=/ ${ARGS[*]} rd.systemd.debug_shell"
SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_eq "$OUT_DIR/early/masked-no-suffix.service" /dev/null
link_eq "$OUT_DIR/early/masked.service" /dev/null
link_eq "$OUT_DIR/early/masked.socket" /dev/null
link_endswith "$OUT_DIR/early/default.target.wants/wanted-no-suffix.service" /lib/systemd/system/wanted-no-suffix.service
link_endswith "$OUT_DIR/early/default.target.wants/wanted.service" /lib/systemd/system/wanted.service
link_endswith "$OUT_DIR/early/default.target.wants/wanted.mount" /lib/systemd/system/wanted.mount
# Following stuff should be ignored, as it's prefixed with rd.
test ! -h "$OUT_DIR/early/masked-initrd.service"
test ! -h "$OUT_DIR/early/default.target.wants/wants-initrd.service"
test ! -h "$OUT_DIR/early/default.target.wants/debug-shell.service"
test ! -d "$OUT_DIR/early/initrd.target.wants"

# Let's re-run the generator with systemd.debug_shell that should be honored
: "debug-shell: regular + systemd.debug_shell"
CMDLINE="$CMDLINE systemd.debug_shell"
SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_endswith "$OUT_DIR/early/default.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service

# Same thing, but with custom tty
: "debug-shell: regular + systemd.debug_shell=/dev/tty666"
CMDLINE="$CMDLINE systemd.debug_shell=/dev/tty666"
SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_endswith "$OUT_DIR/early/default.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service
grep -F "/dev/tty666" "$OUT_DIR/early/debug-shell.service.d/50-tty.conf"

# Same thing, but with custom tty using systemd.default_debug_tty
: "debug-shell: regular + systemd.default_debug_tty=/dev/tty666 systemd.debug_shell=yes"
CMDLINE="$CMDLINE systemd.default_debug_tty=/dev/tty666 systemd.debug_shell=yes"
SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_endswith "$OUT_DIR/early/default.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service
grep -F "/dev/tty666" "$OUT_DIR/early/debug-shell.service.d/50-tty.conf"

# Now override the default target via systemd.unit=
: "debug-shell: regular + systemd.unit="
CMDLINE="$CMDLINE systemd.unit=my-fancy.target"
SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_eq "$OUT_DIR/early/masked-no-suffix.service" /dev/null
link_eq "$OUT_DIR/early/masked.service" /dev/null
link_eq "$OUT_DIR/early/masked.socket" /dev/null
link_endswith "$OUT_DIR/early/my-fancy.target.wants/wanted-no-suffix.service" /lib/systemd/system/wanted-no-suffix.service
link_endswith "$OUT_DIR/early/my-fancy.target.wants/wanted.service" /lib/systemd/system/wanted.service
link_endswith "$OUT_DIR/early/my-fancy.target.wants/wanted.mount" /lib/systemd/system/wanted.mount
link_endswith "$OUT_DIR/early/my-fancy.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service
test ! -d "$OUT_DIR/early/default.target.wants"


# Initrd scenario
: "debug-shell: initrd"
CMDLINE="ro root=/ ${ARGS[*]} systemd.debug_shell"
SYSTEMD_IN_INITRD=1 SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_eq "$OUT_DIR/early/masked-initrd.service" /dev/null
link_endswith "$OUT_DIR/early/initrd.target.wants/wanted-initrd.service" /lib/systemd/system/wanted-initrd.service
# The non-initrd stuff (i.e. without the rd. suffix) should be ignored in
# this case
test ! -h "$OUT_DIR/early/masked-no-suffix.service"
test ! -h "$OUT_DIR/early/masked.service"
test ! -h "$OUT_DIR/early/masked.socket"
test ! -h "$OUT_DIR/early/initrd.target.wants/debug-shell.service"
test ! -d "$OUT_DIR/early/default.target.wants"

# Again, but with rd.systemd.debug_shell
: "debug-shell: initrd + rd.systemd.debug_shell"
CMDLINE="$CMDLINE rd.systemd.debug_shell"
SYSTEMD_IN_INITRD=1 SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_endswith "$OUT_DIR/early/initrd.target.wants/debug-shell.service" /lib/systemd/system/debug-shell.service

# Override the default target
: "debug-shell: initrd + rd.systemd.unit"
CMDLINE="$CMDLINE rd.systemd.unit=my-fancy-initrd.target"
SYSTEMD_IN_INITRD=1 SYSTEMD_PROC_CMDLINE="$CMDLINE" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
link_eq "$OUT_DIR/early/masked-initrd.service" /dev/null
link_endswith "$OUT_DIR/early/my-fancy-initrd.target.wants/wanted-initrd.service" /lib/systemd/system/wanted-initrd.service
test ! -d "$OUT_DIR/early/initrd.target.wants"