diff --git a/test/integration-tests/README.md b/test/integration-tests/README.md index ea3f4f5efb..4fea50660f 100644 --- a/test/integration-tests/README.md +++ b/test/integration-tests/README.md @@ -133,6 +133,10 @@ that make use of `run_testcases`. `TEST_SKIP_TESTCASE=testcase`: takes a space separated list of testcases to skip. +`TEST_SAVE_JOURNAL=0|1|fail`: When `0`, journal file will be removed on exit. +When `1`, journal file will be saved at `$BUILD_DIR/test/journal`. When `fail`, +journal file will be saved only when the test is failed. Defaults to `fail`. + `TEST_JOURNAL_USE_TMP=1`: Write test journal to `/tmp` while the test is in progress and only move the journal to its final location in the build directory (`$BUILD_DIR/test/journal`) when the test is finished. diff --git a/test/integration-tests/TEST-10-MOUNT/meson.build b/test/integration-tests/TEST-10-MOUNT/meson.build new file mode 100644 index 0000000000..77370ce458 --- /dev/null +++ b/test/integration-tests/TEST-10-MOUNT/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +integration_tests += [ + integration_test_template + { + 'name' : fs.name(meson.current_source_dir()), + 'vm' : true, + }, +] diff --git a/test/integration-tests/integration-test-wrapper.py b/test/integration-tests/integration-test-wrapper.py index 999fef9edc..34908e7ed9 100755 --- a/test/integration-tests/integration-test-wrapper.py +++ b/test/integration-tests/integration-test-wrapper.py @@ -660,7 +660,12 @@ def main() -> None: journal_file = Path(shutil.move(journal_file, dst)) if shell or (result.returncode in (args.exit_code, 77) and not coredumps and not sanitizer): - exit(0 if shell or result.returncode == args.exit_code else 77) + exit_code = 0 if shell or result.returncode == args.exit_code else 77 + exit_str = 'succeeded' if exit_code == 0 else 'skipped' + else: + # 0 also means we failed so translate that to a non-zero exit code to mark the test as failed. + exit_code = result.returncode or 1 + exit_str = 'failed' if journal_file.exists(): ops = [] @@ -678,10 +683,11 @@ def main() -> None: ops += [f'journalctl --file {journal_file} --no-hostname -o short-monotonic -u {args.unit} -p info'] - print(f'Test failed, relevant logs can be viewed with: \n\n{(" && ".join(ops))}\n', file=sys.stderr) + print( + f'Test {exit_str}, relevant logs can be viewed with: \n\n{(" && ".join(ops))}\n', file=sys.stderr + ) - # 0 also means we failed so translate that to a non-zero exit code to mark the test as failed. - exit(result.returncode or 1) + exit(exit_code) if __name__ == '__main__': diff --git a/test/integration-tests/meson.build b/test/integration-tests/meson.build index 19cd5b5310..08eb724dd2 100644 --- a/test/integration-tests/meson.build +++ b/test/integration-tests/meson.build @@ -43,6 +43,7 @@ foreach dirname : [ 'TEST-07-PID1', 'TEST-08-INITRD', 'TEST-09-REBOOT', + 'TEST-10-MOUNT', 'TEST-13-NSPAWN', 'TEST-15-DROPIN', 'TEST-16-EXTEND-TIMEOUT', diff --git a/test/units/TEST-10-MOUNT.sh b/test/units/TEST-10-MOUNT.sh new file mode 100755 index 0000000000..b4c867918f --- /dev/null +++ b/test/units/TEST-10-MOUNT.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# shellcheck source=test/units/test-control.sh +. "$(dirname "$0")"/test-control.sh +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +teardown_test_dependencies() ( + set +eux + + if mountpoint /tmp/deptest; then + umount /tmp/deptest + fi + + if [[ -n "${LOOP}" ]]; then + losetup -d "${LOOP}" || : + fi + if [[ -n "${LOOP_0}" ]]; then + losetup -d "${LOOP_0}" || : + fi + if [[ -n "${LOOP_1}" ]]; then + losetup -d "${LOOP_1}" || : + fi + + rm -f /tmp/TEST-60-MOUNT-RATELIMIT-dependencies-0.img + rm -f /tmp/TEST-60-MOUNT-RATELIMIT-dependencies-1.img + + rm -f /run/systemd/system/tmp-deptest.mount + systemctl daemon-reload + + return 0 +) + +setup_loop() { + truncate -s 30m "/tmp/TEST-60-MOUNT-RATELIMIT-dependencies-${1?}.img" + sfdisk --wipe=always "/tmp/TEST-60-MOUNT-RATELIMIT-dependencies-${1?}.img" </run/systemd/system/tmp-deptest.mount </run/systemd/system/tmp-deptest.mount </run/systemd/journald.conf.d/99-ratelimit.conf <