diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /test/units/TEST-74-AUX-UTILS.modules-load.sh | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/units/TEST-74-AUX-UTILS.modules-load.sh')
-rwxr-xr-x | test/units/TEST-74-AUX-UTILS.modules-load.sh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/units/TEST-74-AUX-UTILS.modules-load.sh b/test/units/TEST-74-AUX-UTILS.modules-load.sh new file mode 100755 index 0000000..ceac826 --- /dev/null +++ b/test/units/TEST-74-AUX-UTILS.modules-load.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +MODULES_LOAD_BIN="/usr/lib/systemd/systemd-modules-load" +CONFIG_FILE="/run/modules-load.d/99-test.conf" + +at_exit() { + rm -rfv "${CONFIG_FILE:?}" +} + +trap at_exit EXIT + +if systemd-detect-virt -cq; then + echo "Running in a container, skipping the systemd-modules-load test..." + exit 0 +fi + +ORIG_MODULES_LOAD_CONFIG="$(systemd-analyze cat-config modules-load.d)" + +# Check if we have required kernel modules +modprobe --all --resolve-alias dummy + +mkdir -p /run/modules-load.d/ + +"$MODULES_LOAD_BIN" +"$MODULES_LOAD_BIN" --help +"$MODULES_LOAD_BIN" --version + +# Explicit config file +modprobe -v --all --remove dummy +printf "dummy" >"$CONFIG_FILE" +"$MODULES_LOAD_BIN" "$CONFIG_FILE" |& tee /tmp/out.log +grep -E "Inserted module .*dummy" /tmp/out.log + +# Implicit config file +modprobe -v --all --remove dummy +printf "dummy" >"$CONFIG_FILE" +"$MODULES_LOAD_BIN" |& tee /tmp/out.log +grep -E "Inserted module .*dummy" /tmp/out.log + +# Valid & invalid data mixed together +modprobe -v --all --remove dummy +cat >"$CONFIG_FILE" <<EOF + +dummy +dummy +dummy + dummy +dummy + \\n\n\n\\\\\\ + +dumm!@@123##2455 +# This is a comment +$(printf "%.0sx" {0..4096}) +dummy +dummy +foo-bar-baz +1 +" +' +EOF +"$MODULES_LOAD_BIN" |& tee /tmp/out.log +grep -E "^Inserted module .*dummy" /tmp/out.log +grep -E "^Failed to find module .*foo-bar-baz" /tmp/out.log +(! grep -E "This is a comment" /tmp/out.log) +# Each module should be loaded only once, even if specified multiple times +[[ "$(grep -Ec "^Inserted module" /tmp/out.log)" -eq 1 ]] +[[ "$(grep -Ec "^Failed to find module" /tmp/out.log)" -eq 7 ]] + +# Command line arguments +modprobe -v --all --remove dummy +# Make sure we have no config files left over that might interfere with +# following tests +rm -fv "$CONFIG_FILE" +[[ "$ORIG_MODULES_LOAD_CONFIG" == "$(systemd-analyze cat-config modules-load.d)" ]] +CMDLINE="ro root= modules_load= modules_load=, / = modules_load=foo-bar-baz,dummy modules_load=dummy,dummy,dummy" +SYSTEMD_PROC_CMDLINE="$CMDLINE" "$MODULES_LOAD_BIN" |& tee /tmp/out.log +grep -E "^Inserted module .*dummy" /tmp/out.log +grep -E "^Failed to find module .*foo-bar-baz" /tmp/out.log +# Each module should be loaded only once, even if specified multiple times +[[ "$(grep -Ec "^Inserted module" /tmp/out.log)" -eq 1 ]] + +(! "$MODULES_LOAD_BIN" --nope) +(! "$MODULES_LOAD_BIN" /foo/bar/baz) |