Commit graph

571 commits

Author SHA1 Message Date
Frantisek Sumsal b22d90e594 test: generate a custom initrd for TEST-24 if $INITRD is unset
Co-Authored-By: Yu Watanabe <watanabe.yu+github@gmail.com>
2022-05-26 15:04:56 +02:00
Evgeny Vereshchagin d0880faa5d tests: ignore dbus-broker-launcher
There are memory leaks there https://github.com/bus1/dbus-broker/issues/289
and it crashes from time to time
https://github.com/matusmarhefka/dfuzzer/issues/20#issuecomment-1114097840
so let's just skip it by analogy with dbus-daemon to avoid
reports that have nothing to do with systemd itself.

It's kind of a part of https://github.com/systemd/systemd/pull/22547
2022-05-12 14:44:01 +09:00
Zbigniew Jędrzejewski-Szmek 3e8caa34d6 docs: use lowercase "qemu" and other minor tweaks to test docs
We used both "qemu" and "QEMU", let's use the lower-case version everywhere
since it's also the name of the binary and the version that people are
most familiar with.

The stuff under test/ is not only for the integeration tests, but also
for various other test-related stuff, so adjust the docs a bit.
2022-05-04 12:58:43 +02:00
Evgeny Vereshchagin 8e78dca982 tests: make valgrind_wrapper track file descriptors 2022-05-03 20:51:56 +00:00
Evgeny Vereshchagin c66e2f6c2c tests: make it possible to install valgrind 2022-05-03 20:50:39 +00:00
wangyuhang cca3050b9e test: use cp for journal copying when systemd-journal-remote non-existent 2022-04-25 08:27:17 +00:00
Yu Watanabe 7be87278a3
Merge pull request #23021 from fbuihuu/tmpfiles-fix-precedence-with-plus-sign
Tmpfiles fix precedence with plus sign
2022-04-16 01:36:51 +09:00
Frantisek Sumsal 3c9af05cae test: add MD-related tests to TEST-64 2022-04-14 00:12:02 +09:00
Franck Bui eef72224a8 test: adapt install_pam() for openSUSE
limits.conf is installed in /usr/etc/security for openSUSE.
2022-04-11 11:22:39 +02:00
Frantisek Sumsal 1b2e3b8bff test: ignore missing coverage in TEST-02
Since c6552ad we now try to collect coverage even in situations where
it's basically impossible (like in test-mount-util where the whole / is
mounted as read-only). As dealing with this is not worth the trouble,
let's ignore the missing coverage errors thrown by gcov in such cases.
2022-04-07 12:45:13 +02:00
Frantisek Sumsal 41d1aaea64 test: use flock when calling mkfs.btrfs
As stated in https://github.com/systemd/systemd/issues/21819#issuecomment-1064377645
`mkfs.btrfs` doesn't hold the lock for the whole duration of
`mkfs.btrfs`, thus causing unexpected races & test fails. Let's
wrap the `mkfs.btrfs` calls in an flock wrapper to mitigate this.

Hopefully fixes: #21819
2022-03-25 10:28:07 +09:00
Grigori Goronzy fd8b924820 cryptenroll: add tests for TPM2 unlocking
Add tests for enrolling and unlocking. Various cases are tested:

- Default PCR 7 policy w/o PIN, good and bad cases (wrong PCR)
- PCR 7 + PIN policy, good and bad cases (wrong PCR, wrong PIN)
- Non-default PCR 0+7 policy w/o PIN, good and bad cases (wrong PCR 0)

v2: rename test, fix tss2 library installation, fix CI failures
v3: fix ppc64, load module
2022-03-15 21:17:00 +01:00
Luca Boccassi 4f2dba98ad TEST-29: do not pass -q to mk/unsquashfs, not supported on CentOS 8 2022-03-08 18:02:09 +09:00
Zbigniew Jędrzejewski-Szmek 13391986b5 TEST-29: trim output a bit
IIUC, pipefail doesn't matter for a sequence of commands joined with &&, and we
don't have any pipes. And such a failing expression also does not trigger an
exit, so the set +e/set -e were noops.
2022-03-07 14:31:36 +01:00
Frantisek Sumsal 93c3b6989b test: set ReadWritePaths= only for units from TEST-20
as setting it system-wide has some undesirable side-effects.

Follow-up to b6fc524.
2022-02-17 14:45:21 +00:00
Evgeny Vereshchagin bf6ef6b6a9 tests: allow running all the services with SYSTEMD_LOG_LEVEL
It should make it easier to figure out what exactly services do there.
For example, with SYSTEMD_LOG_LEVEL=debug userdbd (v249) prints
```
varlink-5: New incoming message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{}}
```
before it crashes and systemd-resolved prints
```
varlink-21: New incoming message: {"method":"io.systemd.Resolve.ResolveAddress","parameters":{"address":[127,0,0,1],"flags":0,"ifindex":1000000,"family":0}}
```
and those messages are helpful (especially when scripts causing them
aren't clever enough to keep track of random stuff they send to systemd
:-))
2022-02-16 07:50:51 +03:00
Frantisek Sumsal b6fc52408a test: set ReadWritePaths=$BUILD_DIR when running w/ coverage
otherwise units using `DynamicUser=yes` won't be able to write the
coverage stats (currently affecting TEST-20-MAINPIDGAMES).

`DynamicUser=yes` implies `ProtectSystem=strict` and
`ProtectHome=read-only` and can't be overridden hence we need to
utilize `ReadWritePaths=` to work around that.
2022-02-14 21:59:33 +00:00
Frantisek Sumsal d282e57e2a test: check for (possibly) missing test coverage
If the test logs contain lines like:

```
...systemd-resolved[735885]: profiling:/systemd-meson-build/src/shared/libsystemd-shared-250.a.p/base-filesystem.c.gcda:Cannot open
```

it means we're possibly missing some coverage since gcov can't write the stats,
usually due to the sandbox being too restrictive (e.g. ProtectSystem=yes,
ProtectHome=yes) or the $BUILD_DIR being inaccessible to non-root users.
2022-02-14 12:20:02 +01:00
Frantisek Sumsal e4c822e9ac test: set ACLs for the build dir when built with coverage
Otherwise unprivileged processes (like systemd-resolved) can't write
coverage data.
2022-02-14 11:58:54 +01:00
Frantisek Sumsal d10d562bd4 test: lvm 2.03.15 dropped the static autoactivation
so install the respective generator only if we're running with older
lvm versions.

See: https://sourceware.org/git/?p=lvm2.git;a=commit;h=ee8fb0310c53ed003a43b324c99cdfd891dd1a7c
2022-02-09 22:36:25 +01:00
Frantisek Sumsal f723740871 test: introduce `get_cgroup_hierarchy() helper
which returns the host's cgroup hierarchy (unified, hybrid, or legacy).
2022-02-01 22:13:45 +01:00
Frantisek Sumsal 6f73ef8b30 test: copy portable profiles into the image if they don't exist there
If we're built with `-Dportable=false`, the portable profiles won't get
installed into the image. Since we need only the profile files and
nothing else, let's copy them into the image explicitly in such case.
2022-01-31 17:09:30 +00:00
Yu Watanabe 256ce2e889
Merge pull request #21838 from lnussel/logind-refactor
Logind shutdown refactor
2022-01-31 19:45:33 +09:00
Luca Boccassi 3fa80e5e75 core: do not attempt to add 'private' symlinks when RootImage/RootDirectory are used
A bind mount is added directly from private on the host to the actual
destination directory, no need for the symlinks (which cannot be created
as the bind mount happens first and creates the target as an actual directory)

Fixes https://github.com/systemd/systemd/issues/22264
2022-01-28 00:54:10 +00:00
Luca Boccassi 392d46d7a8 test: use mksquashfs -noappend
Makes the setup idempotent, as mksquashfs by default attempts to
append to an existing image
2022-01-27 14:21:29 +00:00
Luca Boccassi d76f0de746 test: rename service used in TEST-29-PORTABLE to avoid conflict
There's an app0.service in the extension app0.raw, so don't use the same
name for a unit in minimal.raw
2022-01-27 14:21:29 +00:00
Ludwig Nussel 48f3bc5cc4 test: add shutdown test
Wraps nspawn to be able to use pexpect. The test logs in on the console
and runs screen. In one screen window it types in shutdown commands and
checks whether a wall message was sent to the other.
2022-01-25 17:43:13 +01:00
Ludwig Nussel b13a8b5b37 test: mark partition bootable
Make test suite partition bootable so nspawn can use the image directly.
Useful for local testing.

https://systemd.io/DISCOVERABLE_PARTITIONS/
2021-12-29 19:23:26 +00:00
Zbigniew Jędrzejewski-Szmek ff254eea8f test: ignore the error about our own libraries missing during image creation
19:50:59 F: Missing a shared library required by /var/tmp/systemd-test.NIPT2q/root/lib/systemd/libsystemd-core-250.so.
19:50:59 F: Run "ldd /var/tmp/systemd-test.NIPT2q/root/lib/systemd/libsystemd-core-250.so" to find out what it is.
19:50:59 F: libsystemd-shared-250.so => not found
19:50:59 F: Cannot create a test image.
2021-12-25 15:18:50 +09:00
Yu Watanabe 92ecc87512 test: install losetup by default
Preparation for the next commit.
2021-12-20 23:34:27 +09:00
Franck Bui 051ea718f2 TEST-10: don't attempt to write a byte to the socket
Writing a byte to test10.socket is actually the root cause of issue #19154:
depending on the timing, it's possible that PID1 closes the socket before socat
(or nc, it doesn't matter which tool is actually used) tries to write that one
byte to the socket. In this case writing to the socket returns EPIPE, which
causes socat to exit(1) and subsequently make the test fail.

Since we're only interested in connecting to the socket and triggering the rate
limit of the socket, this patch removes the parts that write the single byte to
the socket, which should remove the race for good.

Since it shouldn't matter whether the test uses socat or nc, let's switch back
to nc and hence remove the sole user of socat. The exit status of nc is however
ignored because some versions might choke when the socket is closed
unexpectedly.
2021-12-07 08:29:09 +09:00
Luca Boccassi 56f2a72919 elf-util: switch libelf/libdw to dlopen()
In order to avoid inflating the dependency list for the core
library, use dlopen when inspecting elfs, since it's only
used in two non-core executables.
2021-11-30 16:49:59 +00:00
Frantisek Sumsal 72f9e485ce test: create a dummy LSan suppression file in the minimal image
otherwise gcc's ASan complains (unlike clang's) when the image is used -
e.g. in TEST-29 or TEST-50.

```
[   17.328705] testsuite-29.sh[361]: + portablectl --profile=trusted attach --now --runtime /usr/share/minimal_0.raw app0
...
[   20.978649] systemd[1]: Starting app0-foo.service...
[   21.104844] kernel: loop0: detected capacity change from 0 to 24960
[   20.999559] systemd[1]: Starting app0.service...
[   21.126022] kernel: loop1: detected capacity change from 0 to 24960
...
[   21.861087] cat[422]: AddressSanitizer: failed to read suppressions file '/systemd-lsan.supp'
[   21.868634] cat[421]: AddressSanitizer: failed to read suppressions file '/systemd-lsan.supp'
[   21.877941] systemd[1]: app0.service: Control process exited, code=exited, status=1/FAILURE
[   21.878836] systemd[1]: app0.service: Failed with result 'exit-code'.
[   21.905712] systemd[1]: Failed to start app0.service.
```

Follow-up to f201f34477.
2021-11-26 18:15:51 +00:00
Lennart Poettering 9ead418413 test: test new SYSEXT_SCOPE=/PORTABLE_PREFIXES= fields in TEST-29 2021-11-23 22:55:49 +01:00
Frantisek Sumsal f201f34477 test: suppress certain leaks reported by LSan
so we can run TEST-46 under sanitizers once again.

`systemd-homed` runs fsck on home directories, which reports a memory
leak we're not interested in. Let's introduce an LSan suppression file
to get around this. Since the patterns in the suppression file are
matched using basic substring match[0], they're a bit cumbersome, but
should get the work one.

[0] https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions

Example leaks (as reported by TEST-46):
```
systemd-homed[1333]: =================================================================
systemd-homed[1333]: ==1333==ERROR: LeakSanitizer: detected memory leaks
systemd-homed[1333]: Direct leak of 24 byte(s) in 1 object(s) allocated from:
systemd-homed[1333]:     #0 0x7f0c8facccd1 in calloc (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xf4cd1)
systemd-homed[1333]:     #1 0x558d9494ff67  (/usr/bin/fsck+0x3f67)
systemd-homed[1333]: Direct leak of 6 byte(s) in 1 object(s) allocated from:
systemd-homed[1333]:     #0 0x7f0c8fa906c1 in strdup (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xb86c1)
systemd-homed[1333]:     #1 0x558d949518fd  (/usr/bin/fsck+0x58fd)
systemd-homed[1333]: SUMMARY: AddressSanitizer: 30 byte(s) leaked in 2 allocation(s).
systemd-homed[1337]: ==1337==WARNING: Symbolizer was blocked from starting itself!
systemd-homed[1337]: =================================================================
systemd-homed[1337]: ==1337==ERROR: LeakSanitizer: detected memory leaks
systemd-homed[1337]: Direct leak of 67584 byte(s) in 1 object(s) allocated from:
systemd-homed[1337]:     #0 0x7f01edb84b19  (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xf4b19)
systemd-homed[1337]:     #1 0x7f01e8326829  (/usr/bin/../lib/libLLVM-12.so+0xb46829)
systemd-homed[1337]: SUMMARY: AddressSanitizer: 67584 byte(s) leaked in 1 allocation(s).
```

With the suppression file:
```
systemd-homed[1339]: -----------------------------------------------------
systemd-homed[1339]: Suppressions used:
systemd-homed[1339]:   count      bytes template
systemd-homed[1339]:       2         30 /bin/fsck$
systemd-homed[1339]: -----------------------------------------------------
systemd-homed[1343]: ==1343==WARNING: Symbolizer was blocked from starting itself!
systemd-homed[1343]: -----------------------------------------------------
systemd-homed[1343]: Suppressions used:
systemd-homed[1343]:   count      bytes template
systemd-homed[1343]:       1      67584 /lib/libLLVM
systemd-homed[1343]: -----------------------------------------------------
```
2021-11-22 20:52:56 +01:00
Frantisek Sumsal c049acb22e test: fix a couple of "new" shellcheck-related issues
related to https://github.com/koalaman/shellcheck/wiki/SC2295
2021-11-22 20:52:56 +01:00
Frantisek Sumsal e50d743f99 test: support the new lvm udev autoactivation
Introduced in lvm 2.03.14.
See: https://sourceware.org/git/?p=lvm2.git;a=commit;h=67722b312390cdab29c076c912e14bd739c5c0f6
2021-11-01 20:55:38 +01:00
Frantisek Sumsal 35382a9da3 test: merge coverage reports from previous test runs
Relevant mainly for tests which utilize both QEMU and nspawn.
2021-10-25 11:35:47 +02:00
Frantisek Sumsal d2a39812fd test: rename the global service override file for coverage runs
Otherwise we break TEST-15-DROPIN, since it uses
/usr/lib/systemd/system/service.d/override.conf in some of its
sub-tests.
2021-10-23 22:10:24 +02:00
Frantisek Sumsal 035af7adfe test: disable ProtectHome= when collecting coverage as well
Depending on the location of the original build dir, either ProtectHome=
or ProtectSystem= may get in the way when creating the gcov metadata
files.

Follow-up to:
    * 02d7e73013
    * 6c9efba677
2021-10-23 21:27:20 +02:00
Frantisek Sumsal 7a6c5b6ab5 test: make the coverage check safer for non-compiled builds 2021-10-21 18:34:21 +02:00
Frantisek Sumsal 02d7e73013 test: loosen sandbox restrictions for integration tests as well
Otherwise we miss quite a lot of coverage (mainly from logind,
hostnamed, networkd, and possibly others), since they can't write their
reports with `ProtectSystem=strict`.
2021-10-21 18:06:36 +02:00
Frantisek Sumsal 0b5fe54ff5 test: collect coverage in a couple more codepaths
Otherwise we'd miss coverage from TEST-{02,24,61}, since they don't go
through the "standard" `check_result_common` hook.

Follow-up to 7bf20e48bd.
2021-10-20 16:46:58 +01:00
Luca Boccassi c82dc15b9f test: create and merge code coverage reports in integration tests
If -Db_coverage=true is used at build time, then ARTIFACT_DIRECTORY/TEST-XX-FOO.coverage-info
files are created with code coverage data, and run-integration-test.sh also
merges them into ARTIFACT_DIRECTORY/merged.coverage-info since the coveralls.io
helpers accept only a single file.
2021-10-04 16:40:49 +01:00
Zbigniew Jędrzejewski-Szmek 8f5bcd615b licensing: add forgotten spdx headers
Those are all "our" files, but we forgot to add the headers,
most likely because of non-standard file extensions.
2021-10-01 14:45:00 +02:00
Frantisek Sumsal 1c3f490f23 test: shellcheck-ify test scripts 2021-09-30 12:12:00 +02:00
Frantisek Sumsal 7074c047c1 test: explicitly report if we fail to install a file into the image 2021-09-29 10:05:21 +02:00
Frantisek Sumsal f4e64b6e34 test: add an iSCSI helper 2021-09-29 10:05:21 +02:00
Luca Boccassi 3a18c0e5f2
Merge pull request #20806 from fbuihuu/test-make-debug-tools-optional
test: make the installation of the debug tools optional in the image
2021-09-22 12:01:59 +01:00
Franck Bui 9fbb13acbc test: wc is needed by test/units/testsuite-50.sh 2021-09-22 09:04:52 +02:00
Franck Bui f7d47cc862 test: make the installation of the debug tools optional in the image 2021-09-22 08:37:34 +02:00
Luca Boccassi 71a80dcc0b
Merge pull request #20690 from DaanDeMeyer/oomd-user-services
oom: Support for user services
2021-09-21 15:39:48 +01:00
Daan De Meyer 064a5c1438 oom: Add support for user unit ManagedOOM property updates
Compared to PID1 where systemd-oomd has to be the client to PID1
because PID1 is a more privileged process than systemd-oomd, systemd-oomd
is the more privileged process compared to a user manager so we have
user managers be the client whereas systemd-oomd is now the server.

The same varlink protocol is used between user managers and systemd-oomd
to deliver ManagedOOM property updates. systemd-oomd now sets up a varlink
server that user managers connect to to send ManagedOOM property updates.

We also add extra validation to make sure that non-root senders don't
send updates for cgroups they don't own.

The integration test was extended to repeat the chill/bloat test using
a user manager instead of PID1.
2021-09-20 13:53:11 +01:00
Frantisek Sumsal babe935563 test: add a btrfs helper 2021-09-18 20:44:34 +02:00
Frantisek Sumsal 4999f3688f test: add an LVM helper 2021-09-14 19:15:13 +02:00
Frantisek Sumsal e3d9a2e74f test: install dmevent service and socket 2021-09-14 19:15:13 +02:00
Frantisek Sumsal bac05644a7 test: specify the rootfs by label
otherwise the boot might fail when attaching multiple SATA devices to
the VM.
2021-09-14 19:15:13 +02:00
Frantisek Sumsal 9e7c3bd48c test: add a multipath helper 2021-09-12 18:38:42 +02:00
Frantisek Sumsal 39e1753673 test: rename dracut_install to image_install
The `dracut_install` is a misnomer, since the systemd integration test
suite is based on the original dracut's test suite, and not all the
references to dracut has been edited out. Let's fix that.
2021-09-08 22:41:20 +09:00
Franck Bui ce380c2f09 test: make sure to include all haveged unit files
Recent versions of haveged relies on haveged-switch-root.service too.
2021-09-01 20:40:55 +01:00
Yu Watanabe 42867dfeef test-execute: add a testcase for MountAPIVFS=no 2021-08-26 02:54:37 +09:00
Frantisek Sumsal faca95e115 test: make sure test timeout has a higher priority than a pass
otherwise we might mark tests where something crashes during shutdown as
successful, as happened in one of the recent TEST-01-BASIC runs:

```
testsuite-01.service: About to execute rm -f /failed /testok
testsuite-01.service: Forked rm as 606
testsuite-01.service: Executing: rm -f /failed /testoktestsuite-01.service: Changed dead -> start-pre
         Starting TEST-01-BASIC...
...
Child 606 (rm) died (code=exited, status=0/SUCCESS)
testsuite-01.service: Child 606 belongs to testsuite-01.service.
testsuite-01.service: Control process exited, code=exited, status=0/SUCCESS (success)
testsuite-01.service: Got final SIGCHLD for state start-pre.
testsuite-01.service: Passing 0 fds to service
testsuite-01.service: About to execute sh -e -x -c "systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok"
testsuite-01.service: Forked sh as 607
testsuite-01.service: Changed start-pre -> start
testsuite-01.service: Executing: sh -e -x -c "systemctl --state=failed --no-legend --no-pager >/failed ; systemctl daemon-reload ; echo OK >/testok"systemd-journald.service: Got notification message from PID 560 (FDSTORE=1)S
...
testsuite-01.service: Child 607 belongs to testsuite-01.service.
testsuite-01.service: Main process exited, code=exited, status=0/SUCCESS (success)
testsuite-01.service: Deactivated successfully.
testsuite-01.service: Service will not restart (restart setting)
testsuite-01.service: Changed start -> dead
testsuite-01.service: Job 207 testsuite-01.service/start finished, result=done
[  OK  ] Finished TEST-01-BASIC.
...
end.service: About to execute /bin/sh -x -c "systemctl poweroff --no-block"
end.service: Forked /bin/sh as 623end.service: Executing: /bin/sh -x -c "systemctl poweroff --no-block"
...
end.service: Job 213 end.service/start finished, result=canceled
Caught <SEGV>, dumped core as pid 624.
Freezing execution.

CentOS Linux 8
Kernel 4.18.0-305.12.1.el8_4.x86_64 on an x86_64 (ttyS0)

H login: qemu-kvm: terminating on signal 15 from pid 80134 (timeout)
E: Test timed out after 600s
Spawning getter /root/systemd/build/journalctl -o export -D /var/tmp/systemd-test.0UYjAS/root/var/log/journal/ca6031c2491543fe8286c748258df8d1...
Finishing after writing 15125 entries
Spawning getter /root/systemd/build/journalctl -o export -D /var/tmp/systemd-test.0UYjAS/root/var/log/journal/remote...
Finishing after writing 0 entries
-rw-r-----. 1 root root 25165824 Aug 20 12:26 /var/tmp/systemd-test.0UYjAS/system.journal
TEST-01-BASIC RUN: Basic systemd setup [OK]
...
2021-08-21 06:40:25 +09:00
Lennart Poettering dc131951b5
Merge pull request #18385 from kinvolk/mauricio/restrict-network-interfaces
Add RestrictNetworkInterfaces=
2021-08-20 03:41:11 +02:00
Luca Boccassi 468d9bc901
Merge pull request #20436 from fbuihuu/add-no-build-support-on-opensuse
Add no build support on opensuse
2021-08-19 21:11:31 +01:00
Mauricio Vásquez 00d6fceeb3 tests: add integration test for RestrictNetworkInterfaces=
Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
2021-08-19 07:25:01 -05:00
Franck Bui d93857ae09 test: if haveged is part of initrd it needs to be installed in the image too
Otherwise haveged won't survive when switching root from initrd to host making
haveged service in host fail.
2021-08-18 17:37:55 +02:00
Franck Bui 138f761904 test: adapt install_pam() for openSUSE
On openSUSE the default pam config files are shipped in /usr/etc/pam.d.

Also empty password is not allowed by default.
2021-08-18 17:37:55 +02:00
Franck Bui dfd73ccb14 test: don't try to find BUILD_DIR when NO_BUILD is set
NO_BUILD=1 indicates that we want to test systemd from the local system and not
the one from the local build. Hence there should be no need to call
find-build-dir.sh when NO_BUID=1 especially since it's likely that the script
will fail to find a local build in this case.

This avoids find-build-dir.sh to emit 'Specify build directory with $BUILD_DIR'
message when NO_BUILD=1 and no local build can be found.

This introduces a behavior change though: systemd from the local system will
always be preferred when NO_BUILD=1 even if a local build can be found.
2021-08-18 17:37:55 +02:00
Franck Bui abf062674e test: add support for NO_BUILD=1 on openSUSE 2021-08-18 17:37:24 +02:00
Luca Boccassi 9a4b883be2 extension-release: search for other files if expected name not found
In some cases image names are unpredictable - some orchestrators/deployment
tools like to mangle names to suit their internal formats. In these cases,
the requirement that the extension-release file matches exactly the image
name where it's contained cannot work.

Allow falling back to loading the first regular file which name starts with
'extension-release' located in /usr/lib/extension-release.d/ and tagged with
a user.extension-release.strict extended attribute with a true value, if the
one with the expected name cannot be found.
2021-08-17 13:04:44 +01:00
Frantisek Sumsal 46db176f8c test: use a correct kernel binary on ppc64le machines
Ubuntu calls the kernel binary as `vmlinux-*`, but RHEL/CentOS uses
the "standard" `vmlinuz-` prefix.

Follow-up to eaa602cb14.
2021-08-09 22:12:18 +01:00
Zbigniew Jędrzejewski-Szmek 4f11590f9b
Merge pull request #20399 from mrc0mmand/test-tweaks
test: yet another fix for ASan detection
2021-08-09 10:06:23 +02:00
Frantisek Sumsal 6476676b84 test: skip a harmless ldd error when installing test libs
Skip a harmless error when running the tests on a system with a significantly
older systemd version (ldd tries to resolve the unprefixed RPATH for libsystemd.so.0,
which is in this case older than the already installed libsystemd.so.0 in $initdir).
The issue is triggered by installing test dependencies in install_missing_libraries().

Spotted on CentOS 8.

```
$ ldd /var/tmp/systemd-test.nZO11F/root/lib/systemd/tests/test-sd-device-thread
/var/tmp/systemd-test.nZO11F/root/lib/systemd/tests/test-sd-device-thread: /lib64/libsystemd.so.0: version `LIBSYSTEMD_240' not found (required by /var/tmp/systemd-test.nZO11F/root/lib/systemd/tests/test-sd-device-thread)
        linux-vdso64.so.1 (0x00007fffb79d0000)
        libclang_rt.asan-powerpc64le.so => /usr/lib64/clang/11.0.0/lib/linux/libclang_rt.asan-powerpc64le.so (0x00007fffb6ef0000)
        libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007fffb6d20000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fffb6cd0000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fffb6ab0000)

$ LD_LIBRARY_PATH=/var/tmp/systemd-test.nZO11F/root/lib64/ ldd /var/tmp/systemd-test.nZO11F/root/lib/systemd/tests/test-sd-device-thread
        linux-vdso64.so.1 (0x00007fffaba80000)
        libclang_rt.asan-powerpc64le.so => /usr/lib64/clang/11.0.0/lib/linux/libclang_rt.asan-powerpc64le.so (0x00007fffaafa0000)
        libsystemd.so.0 => /var/tmp/systemd-test.nZO11F/root/lib64/libsystemd.so.0 (0x00007fffaa5f0000)
        libpthread.so.0 => /var/tmp/systemd-test.nZO11F/root/lib64/libpthread.so.0 (0x00007fffaa5a0000)
        libc.so.6 => /var/tmp/systemd-test.nZO11F/root/lib64/libc.so.6 (0x00007fffaa380000)

```
2021-08-09 10:04:40 +02:00
Frantisek Sumsal 25e399948b test: make busybox TEST-13-only dependency
to make running other tests a bit easier on distributions which don't have
busybox in repositories (CentOS).
2021-08-08 19:43:23 +02:00
Frantisek Sumsal 2d50e3c7bc test: yet another fix for ASan detection
This time for ppc64le:

```
100737c4:	5d 55 f9 4b 	bl      10008d20 <00000024.plt_call.__asan_report_load8>
100737f4:	4d 55 f9 4b 	bl      10008d40 <00000024.plt_call.__asan_handle_no_return>
10073884:	5d 50 f9 4b 	bl      100088e0 <00000024.plt_call.__asan_init>
1007388c:	75 54 f9 4b 	bl      10008d00 <00000024.plt_call.__asan_version_mismatch_check_v8>
100738a0:	41 36 f9 4b 	bl      10006ee0 <00000024.plt_call.__asan_register_globals>
100738f0:	71 4c f9 4b 	bl      10008560 <00000024.plt_call.__asan_unregister_globals>
```
2021-08-08 19:33:10 +02:00
Frantisek Sumsal 84817bfdb3 test: attempt to install only kernel modules for each subsystem
When `linux-headers` is installed on Arch Linux, it stores the module
source tree in the kernel module directory, which is then picked up by
`find` and we get a lot of harmless but annoying errors:

```
...
modprobe: FATAL: Module Kconfig.iosched not found in directory /lib/modules/5.13.7-arch1-1
modprobe: FATAL: Module Kconfig not found in directory /lib/modules/5.13.7-arch1-1
modprobe: FATAL: Module Kconfig not found in directory /lib/modules/5.13.7-arch1-1
modprobe: FATAL: Module dm-mpath.h not found in directory /lib/modules/5.13.7-arch1-1
modprobe: FATAL: Module dm-bio-prison-v2.h not found in directory /lib/modules/5.13.7-arch1-1
modprobe: FATAL: Module raid0.h not found in directory /lib/modules/5.13.7-arch1-1
...
```

Let's fix this by trying to install only kernel modules (*.ko files with
an optional compression).
2021-08-08 16:06:41 +01:00
Frantisek Sumsal 8bf79f0553 test: correctly detect ASan on s390x
s390x uses BRAS(L) instead of CALL(Q), e.g.:

```
 1009528:	c0 e5 ff ff f8 a0 	brasl	%r14,1008668 <__asan_report_load1@plt>
 10095f0:	c0 e5 ff ff ea ec 	brasl	%r14,1006bc8 <__asan_stack_malloc_4@plt>
 10097f8:	c0 e5 ff ff f8 f8 	brasl	%r14,10089e8 <__asan_report_load8@plt>
```

x86_64 for reference:

```
  4011f3:	e8 48 fe ff ff       	callq  401040 <__asan_report_load1@plt>
  401227:	e8 24 fe ff ff       	callq  401050 <__asan_report_load8@plt>
  401251:	e8 da fd ff ff       	callq  401030 <__asan_init@plt>
```
2021-07-29 23:59:08 +01:00
Frantisek Sumsal eca81d0792 test: don't explicitly disable SELinux
We don't install any policies by default, so it shouldn't interfere with
anything (and it would save me some headache).
2021-07-14 20:27:23 +02:00
Frantisek Sumsal e68e473ba2 test: strip binaries by default
Since 23f8e01 we always kept binaries unstripped, since $STRIP_BINARIES
is unset by default.
2021-07-09 14:59:11 +02:00
Frantisek Sumsal 23f8e01912 test: unify handling of boolean values
Let's unify handling of the boolean values throughout the test-functions
code, since we use 0/1, true/false, and yes/no almost randomly in many
places, so picking the right values during CI configuration can be a real
pain.
2021-07-04 21:12:39 +01:00
Dan Streetman d3b8e38409 test: optionally, only save test journal for failing tests
Saving the journal for passing tests creates a huge amount of unneeded
data stored for each full test run. Add a env var to allow saving the
journal only for failed tests.
2021-07-03 10:48:31 +01:00
Frantisek Sumsal eb70d9450c test: correctly mask supporting services in tests, take #2
Due to a little misunderstanding the last patch doesn't work as
expected, since test_create_image() is called only for the first image
(usually TEST-01-BASIC), and all subsequent images are then (possibly)
modified with test_append_files().

Follow-up to 179ca4d2b1.
2021-06-24 16:26:19 +01:00
Yu Watanabe b905f3bbba
Merge pull request #19990 from mrc0mmand/test-tweaks
A couple of stability-related test tweaks
2021-06-23 01:45:04 +09:00
Frantisek Sumsal 179ca4d2b1 test: correctly mask supporting services in tests
It turns out the "supporting services" were run in _all_ tests if
TEST-01-BASIC was run as the first test (which is usually the case),
since with the original condition in test_create_image() we would skip
the masking and then propagate the change to the default image used by
other tests. This has been causing multiple bogus test timeouts
(especially when the hwdb was being rebuilt in tests with short
timeouts, like TEST-52-HONORFIRSTSHUTDOWN).

Let's "fix" this by making the call to mask_supporting_services()
uncoditional and override the test_create_image() function in
TEST-01-BASIC to avoid the masking in this single case.
2021-06-22 12:34:31 +02:00
Luca Boccassi fa1fdd3099 test: move custom result checks from TEST-02-UNITTESTS to test-functions 2021-06-21 20:45:56 +01:00
Luca Boccassi 35cde9e935 test: install nls modules, required by vfat
kernel: FAT-fs (loop0p2): codepage cp437 not found
kernel: FAT-fs (loop0p2): IO charset ascii not found
2021-06-21 19:47:38 +01:00
Frantisek Sumsal 29bff80b5c test: drop the mawk-incompatible expression
The three-argument match() is a GNU AWK extension, thus breaking the
compatibility with mawk (used on Ubuntu/Debian, for example). Let's
replace it with a (hopefully) more portable sed expression to drop the
inadvertently introduced gawk dependency.

Fixes: #19957
2021-06-17 21:44:32 +01:00
Luca Boccassi 63878c52be test: do not run 'meson configure' if NO_BUILD is set
There is no build tree and packages are used, so it cannot work. Unlikely
that static linking has been set for those builds anyway.

Fixes https://github.com/systemd/systemd/issues/19955
2021-06-17 17:21:17 +09:00
Frantisek Sumsal e7848266da test: add a testcase for issue #19895 2021-06-15 23:18:06 +01:00
Zbigniew Jędrzejewski-Szmek dce95d0b15 test/TEST-17-UDEV: use default image
No need to build a separate 700MB image to save 3080 bytes in the default image.
2021-06-12 11:19:04 +02:00
Luca Boccassi c5fd89adcd core: make libbpf a dlopen() dependency 2021-05-25 12:59:26 +01:00
Yu Watanabe a83a7d1e9e test: drop default ACL from $TESTDIR
This fixes an issue introduced by the commit 954c77c251.

For some reasons, setting default ACL on $TESTDIR makes TEST-29-PORTABLE
fail. Let's drop the default ACL, and set ACL on saved results instead.

Fixes #19519.
2021-05-06 11:28:00 +02:00
Yu Watanabe 853401a6bc test: increase image size when static library or standalone binaries are installed 2021-05-06 11:28:00 +02:00
Zbigniew Jędrzejewski-Szmek b086a89695
Merge pull request #19453 from keszybz/consider-instance-aliases
Consider instance aliases
2021-05-05 11:23:42 +02:00
Zbigniew Jędrzejewski-Szmek ea0d33e2af tests: use "H" as the hostname
"systemd-testsuite" gets in the way when grepping for "testsuite-*.sh".
Also, the name doesn't matter for anything, so let's just use something
very short to save space.
2021-05-05 11:04:59 +02:00
Zbigniew Jędrzejewski-Szmek c0d4409219 test: properly catch tests error with no /testok or empty /failed
When editing this function in 7bf20e48bd, I couldn't
decide whether to initialize ret at the top and only reset it on success, or
whether to assign a value in each branch. In the end I did neither ;( So if the
test finished without creating any of the result files, we would echo a
message, but return "success".

But there was bigger confusion with /failed: some tests create it empty, some
don't. I think we may want to do away pre-creation of /failed completely, and
assume the test failed unless /testok is found. But I'm leaving that for later
rework. For now let's just make sure we report return success only if /testok
or /skipped is found.
2021-05-04 13:36:05 +02:00
Yu Watanabe 7afc8abdf3
Merge pull request #19487 from mrc0mmand/test-all-services-in-TEST-01
test: don't mask "supporting" services in TEST-01-BASIC
2021-05-03 12:15:29 +09:00
Frantisek Sumsal d49b881eaf test: fix a yet another pipefail + pipe race
Basically the same scenario as in
a33e2692e1, where `awk` exits as soon
as it finds a match, thus sending SIGPIPE to `ldd` if it's not fast
enough. That, in combination with `set -o pipefail` causes random &
unexpected fails, like:

```
No journal files were found.
-rw-r----- 1 root root 16777216 Apr 30 10:31
/var/tmp/TEST-01-BASIC_sanitizers-nspawn/system.journal
TEST-01-BASIC RUN: Basic systemd setup [OK]
systemd is not linked against the ASan DSO
gcc does this by default, for clang compile with -shared-libasan
make: *** [Makefile:2: clean-again] Error 1
make: Leaving directory '/build/test/TEST-01-BASIC'
```
2021-05-01 15:05:16 +09:00
Frantisek Sumsal 7776b22521 test: don't mask "supporting" services in TEST-01-BASIC
This got lost during one of the code de-duplication attempts.
2021-04-30 21:02:41 +02:00
Frantisek Sumsal 6695c41c31 test: add a couple of hooks for the check_result_*() functions
So we don't have to duplicate the whole functions if we need to inject
some test-specific checks.
2021-04-26 19:24:41 +02:00
Frantisek Sumsal c4cd6205e0 test: "detect" the test number automagically
Specifying the test number manually is tedious and prone to errors (as
recently proven). Since we have all the necessary data to work out the
test number, let's do it automagically.
2021-04-26 19:20:18 +02:00
Frantisek Sumsal 732a487fad
Merge pull request #19383 from keszybz/test58-fixes
Fixes for TEST-58-REPART and ExecStart deserialization logic
2021-04-26 19:16:44 +02:00
Zbigniew Jędrzejewski-Szmek 954c77c251 tests: use setfacl to give $SUDO_USER read permissions on artifacts
We have to invoke the tests as superuser, and not being able to read
the journal as the invoking user is annoying. I don't think there are
any security considerations here, since the invoking user can already
put arbitrary code in the Makefile and test scripts which get executed
with root privileges.
2021-04-23 20:19:09 +02:00
Zbigniew Jędrzejewski-Szmek 7bf20e48bd test: move the logic to support /skipped into shared logic
The logic to query test state was rather complex. I don't quite grok the point
of ret=$((ret+1))… But afaics, the precise result was always ignored by the
caller anyway.
2021-04-23 15:12:35 +02:00
Zbigniew Jędrzejewski-Szmek 0dd77c159a tests: install mkfs.ext4, mkfs.vfat and modules into the test image
This allows TEST-58-REPART to at least start. It fails later with with loopback
device errors.
2021-04-23 15:11:38 +02:00
Frantisek Sumsal 94009c27f4 test: rewrite kernel module handling
This code was partially broken, since the firmware directory was
undefined. Also, some of the parts were a dead code, since they relied
on code from the original dracut test suite.
2021-04-16 19:05:59 +02:00
Frantisek Sumsal 0f1947059b test: use arrays when applicable 2021-04-16 19:05:55 +02:00
Frantisek Sumsal a33e2692e1 test: avoid using pipes in certain cases
`command -v <bin> | grep ...` can under certain conditions cause the
`command` to exit with SIGPIPE, which in combination with `set -o
pipefail` means that the tests sometimes randomly die during setup.
Let's avoid using pipes in such cases.
2021-04-16 19:05:42 +02:00
Frantisek Sumsal 96af59aabb test: use set -o pipefail
This breaks some existing loops which previously ignored if the piped
program exited with EC >0. Rewrite them to mitigate this (and also make
them more robust in some cases).
2021-04-16 19:05:37 +02:00
Frantisek Sumsal 1b8fcd9c63 test: shell code cleanup
Just some basic stuff, like double quotes around strings, using
predictable values for possibly unset variables, formatting, etc.
2021-04-16 18:49:37 +02:00
Zbigniew Jędrzejewski-Szmek 0ee994836c TEST-*: use spacing before redirection operator, but not after
<< EOF → <<EOF
> foo < bar → >foo <bar
2021-04-08 20:21:50 +02:00
Zbigniew Jędrzejewski-Szmek 129cb6e249 shared/calendarspec: when mktime() moves us backwards, jump forward
When trying to calculate the next firing of 'Sun *-*-* 01:00:00', we'd fall
into an infinite loop, because mktime() moves us "backwards":

Before this patch:
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
...

We rely on mktime() normalizing the time. The man page does not say that it'll
move the time forward, but our algorithm relies on this. So let's catch this
case explicitly.

With this patch:
$ TZ=Europe/Dublin faketime 2021-03-21 build/systemd-analyze calendar --iterations=5 'Sun *-*-* 01:00:00'
Normalized form: Sun *-*-* 01:00:00
    Next elapse: Sun 2021-03-21 01:00:00 GMT
       (in UTC): Sun 2021-03-21 01:00:00 UTC
       From now: 59min left
       Iter. #2: Sun 2021-04-04 01:00:00 IST
       (in UTC): Sun 2021-04-04 00:00:00 UTC
       From now: 1 weeks 6 days left           <---- note the 2 week jump here
       Iter. #3: Sun 2021-04-11 01:00:00 IST
       (in UTC): Sun 2021-04-11 00:00:00 UTC
       From now: 2 weeks 6 days left
       Iter. #4: Sun 2021-04-18 01:00:00 IST
       (in UTC): Sun 2021-04-18 00:00:00 UTC
       From now: 3 weeks 6 days left
       Iter. #5: Sun 2021-04-25 01:00:00 IST
       (in UTC): Sun 2021-04-25 00:00:00 UTC
       From now: 1 months 4 days left

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1941335.
2021-03-23 00:35:02 +01:00
Frantisek Sumsal 5acfe54e98 test: fix permissions of the ASan udev workaround
otherwise udev complains about the file being world-writable:
systemd-udevd[228]: Configuration file /etc/udev/rules.d/00-set-LD_PRELOAD.rules is marked world-writable. Please remove world writability permission bits. Proceeding anyway.

Fixes: systemd/systemd-centos-ci#354
2021-03-11 00:28:13 +09:00
Frantisek Sumsal 9f6235e1b4 test: fix TEST-50-DISSECT under sanitizers
This test would normally get stuck when trying to mount the verity image
due to:

systemd-udevd[299]: dm-0: '/usr/sbin/dmsetup udevflags 6293812'(err) '==371==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.'
systemd-udevd[299]: dm-0: Process '/usr/sbin/dmsetup udevflags 6293812' failed with exit code 1
...
systemd-udevd[299]: dm-0: '/usr/sbin/dmsetup udevcomplete 6293812'(err) '==372==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.'
systemd-udevd[299]: dm-0: Process '/usr/sbin/dmsetup udevcomplete 6293812' failed with exit code 1.
systemd-udevd[299]: dm-0: Command "/usr/sbin/dmsetup udevcomplete 6293812" returned 1 (error), ignoring.

so let's add a simple udev rule which sets $LD_PRELOAD for the block
subsystem.

Also, install the ASan library along with necessary dependencies into
the verity minimal image, to get rid of the annoying (yet harmless)
errors about missing library from $LD_LIBRARY.
2021-03-06 22:44:00 +01:00
Frantisek Sumsal 648fd18924 test: tidy up the ASan-related stuff 2021-03-06 22:43:58 +01:00
Frantisek Sumsal 3b5fc147d6 test: disable at_exit LSan check for dbus.service
When running integration tests under sanitizers D-Bus fails to
shutdown cleanly, causing unnecessary noise in the logs:

```
dbus-daemon[272]: ==272==LeakSanitizer has encountered a fatal error.
dbus-daemon[272]: ==272==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
dbus-daemon[272]: ==272==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
```

Since we're not "sanitizing" D-Bus anyway let's disable LSan's at_exit
check for the dbus.service to get rid of this error.
2021-03-06 11:27:04 +09:00
Luca Boccassi 93f597013a Add ExtensionImages directive to form overlays
Add support for overlaying images for services on top of their
root fs, using a read-only overlay.
2021-02-23 15:34:46 +00:00
Luca Boccassi 0761da386a test: avoid leaking open loop devices
When a subshell is used ('make' or 'make all') the LOOPDEV environment
variable, which is used to store the opened loop device, is lost.
So the cleanup on trap/exit doesn't do anything, and the loop
device used to mount the test image is left around.

Avoid using a subshell to fix the issue.
2021-02-17 18:55:05 +01:00
Luca Boccassi 7eba0c50f5 test: install binaries from local d/control file
The source package in the apt cache might be older than the
packaging from salsa.debian.org/systemd-team/systemd so it might not
list all the current binary packages.
This is currently the case for systemd-timesyncd, so TEST-30 fails.

Simply grep the control file rather than using apt-cache when iterating
over the packages contents.
2021-02-15 10:17:39 +01:00
Zbigniew Jędrzejewski-Szmek b3c57df0f5
Merge pull request #18401 from anitazha/oomdxattr
oomd: implement avoid/omit support for cgroups
2021-02-13 10:00:31 +01:00
Luca Boccassi 8b535f3aac test: setup var/tmp in the test image as well 2021-02-10 18:54:12 +00:00
Luca Boccassi e763342091 test: add empty /etc/resolv.conf in test image
Portable services have a BindPath pointing to it, so it needs to
be available in the image
2021-02-10 18:54:12 +00:00
Luca Boccassi 9785c44dd8 test-50-dissect: move minimal image setup to common setup function
So that it can be re-used for other tests by simply setting
TEST_INSTALL_VERITY_MINIMAL=1 in test.sh, without having to
replicate the setup commands.
2021-02-10 18:54:12 +00:00
Frantisek Sumsal 2de908aead test: count call instructions as well
Binaries on the latest Arch Linux use `call` instructions instead of
`callq`, which breaks the ASan detection and eventually the image
building process (due to insufficient space).
2021-02-10 20:20:31 +03:00
Anita Zhang 59331b8e29 oom: implement avoid/omit xattr support
There may be situations where a cgroup should be protected from killing
or deprioritized as a candidate. In FB oomd xattrs are used to bias oomd
away from supervisor cgroups and towards worker cgroups in container
tasks. On desktops this can be used to protect important units with
unpredictable resource consumption.

The patch allows systemd-oomd to understand 2 xattrs:
"user.oomd_avoid" and "user.oomd_omit". If systemd-oomd sees these
xattrs set to 1 on a candidate cgroup (i.e. while attempting to kill something)
AND the cgroup is owned by root, it will either deprioritize the cgroup as
a candidate (avoid) or remove it completely as a candidate (omit).

Usage is restricted to root owned cgroups to prevent situations where an
unprivileged user can set their own cgroups lower in the kill priority than
another user's (and prevent them from omitting their units from
systemd-oomd killing).
2021-02-09 02:27:40 -08:00
Luca Boccassi 21be71eefb test: fix 'make clean' not removing shared image 2021-01-29 09:56:45 +00:00
Dan Streetman 8fa038085e test/test-functions: allow installing systemd files from local system
Add NO_BUILD var to allow testing with no local build, by installing
local systemd files into the image.

This only works for debian-like distros currently, that use the
tools 'apt' and 'dpkg' for package management.
2021-01-26 17:09:48 -05:00
Dan Streetman 12d31e4ea5 test: find $BUILD_DIR in test-functions, remove from other scripts
The $BUILD_DIR is only used in test-functions, and doesn't need to
be specified in any other scripts. Additionally, to be able to allow
the integration test suite to be run against locally installed binaries,
instead of built binaries, moving BUILD_DIR logic completely into
test-functions allows later patches to be simpler.
2021-01-26 17:09:48 -05:00
Dan Streetman 42f3b48c97 test/test-functions: add variables for several dir locations 2021-01-26 17:09:39 -05:00
Dan Streetman 1918406900 test/test-functions: move var assignment
This makes no code change, only moves a small block of vars higher in the
file. This makes the next commit a bit easier to read.
2021-01-26 16:05:49 -05:00
Luca Boccassi d9e606e89f tests: build the image once and then copy/extend it
Building custom images for each test takes a lot of time.
Build the default one, and if the test needs incompatible changes
just copy it and extend it instead.
2021-01-24 13:07:39 +00:00
Zbigniew Jędrzejewski-Szmek 6eab0c6dba Revert "test-functions: make sure we test our own libudev instead of the host libudev"
This reverts commit 73484ecff9.

3976f372ae moved libudev.so to be built in the
main directory, so this addition to $LD_LIBRARY_PATH is now obsolete.

After that commit, we build the following shared libraries:

build/libnss_myhostname.so.2
build/libnss_mymachines.so.2
build/libnss_resolve.so.2
build/libnss_systemd.so.2
build/libsystemd.so.0.30.0
build/libudev.so.1.7.0
build/pam_systemd.so
build/pam_systemd_home.so
build/src/boot/efi/stub.so
build/src/boot/efi/systemd_boot.so
build/src/shared/libsystemd-shared-247.so

EFI stubs don't matter, and libsystemd-shared-nnn.so is loaded through rpath,
and is doesn't need to and shouldn't be in $LD_LIBRARY_PATH. In effect, we only
ever need to add the main build directory to the search path.
2021-01-20 14:04:52 +09:00
Lennart Poettering b5e0c17654 test: improve a log message while building test images 2021-01-19 13:41:42 +01:00
Luca Boccassi fa7a3cd00e test: run strace with -f and copy log out 2021-01-18 17:24:05 +00:00
Luca Boccassi a9d34376e6 test: skip missing optional libraries in image install
Not all optional libraries might be available on developers machines,
so log and skip.
Also some pkg-config files are broken (eg: tss2 on Debian Stable) so
skip if the required variables are missing, and improve logs.
2021-01-18 17:24:05 +00:00
Luca Boccassi eb3785f367 tests: add TEST_PREFER_NSPAWN variable to run as many as possible under nspawn
By default the test suite prefers qemu, and uses nspawn only if
a test specifically says it doesn't support qemu.
Add a variable to allow flipping the default, and run as many
tests under nspawn as possible.
2021-01-01 21:33:16 +00:00
Luca Boccassi 51d56d3be0 tests: add TEST_QEMU_ONLY variable to run only tests where qemu is mandatory
Allows to split the test run in two parts. Most tests can run under
nspawn which is much faster, and they can be ran in one chunk with
TEST_NO_QEMU=1. The qemu-only tests, which are just a handful, can
be ran in another chunk with TEST_QEMU_ONLY=1.

Allows autopkgtest to be split in two parts.
2021-01-01 21:33:16 +00:00
Luca Boccassi aeac20fc69 test: shortcut skip if both TEST_NO_QEMU and TEST_NO_NSPAWN are set
Allows to run all tests in bulk with TEST_NO_QEMU, skipping those where it is
mandatory, without wasting time building the image.
2021-01-01 21:33:16 +00:00
Luca Boccassi 0515e4c17d test: check for binariers in [usr/][s]bin
The image build function greps for ExecStart lines in unit files, but some
of them (eg: systemd-firstboot) do not use a full path.
It then falls back to 'type -P' but that only works if you have the binary
installed. For optional binaries like systemd-firstboot, the installation
can then fail.

Manually check if the binary already exists in /[usr/][s]bin.
2021-01-01 21:33:16 +00:00
Luca Boccassi 53a1c94480 test: use pkg-config to get user unit dir when installing dbus user socket
Usually on Debian ROOTLIBDIR is /lib/<arch triplet>, which is not the right place.
Use pkg-config since we define it, and then fallback to /usr/lib/systemd/user which is
the canonical location.
On both Debian&friends and Fedora dbus/dbus-broker install the user socket/service
under /usr/lib/systemd/user, not /lib/systemd/systemd/user.
2021-01-01 21:33:16 +00:00
Lennart Poettering a60d5b2f38 test: add tpm2 and fido2 libs to dlopen test 2020-12-17 20:02:24 +01:00
Frantisek Sumsal f26d091460 test: drop the trailing whitespace from the QEMU version check
I suspect the original version of the regex was written on a system,
which prints both the QEMU version and the QEMU package version in the
--version output, like Fedora:

$ /bin/qemu-system-x86_64 --version
QEMU emulator version 4.2.1 (qemu-4.2.1-1.fc32)
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

However, Arch Linux prints only the QEMU version:
$ /bin/qemu-system-x86_64 --version
QEMU emulator version 5.2.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers

This causes the awk regex to not match the version string, since there's
no whitespace after it, causing the version check to fail (as well as the
TEST-36-NUMAPOLICY) as well.

Follow-up for 43b49470d1.
2020-12-16 16:38:26 +01:00
Christian Ehrhardt 43b49470d1 test: use modern qemu numa arguments
Upgrading to qemu 5.2 breaks TEST-36-NUMAPOLICY like:
  qemu-system-x86_64: total memory for NUMA nodes (0x0) should
  equal RAM size (0x20000000)

Use the new (as in >=2014) form of memdev in test 36:
 -object memory-backend-ram,id=mem0,size=512M -numa node,memdev=mem0,nodeid=0

Since some target systems are as old as qemu 1.5.3 (CentOS7) but the new
kind to specify was added in qemu 2.1 this needs to add version parsing and
add the argument only when qemu is >=5.2.

Fixes #17986.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2020-12-16 05:16:41 +09:00
Luca Boccassi b7fca1b059 test: pull in weak deps into tests
(Pulled from @bluca's comment here:
https://github.com/systemd/systemd/pull/17884#issuecomment-740005624 and
turned into a commit by @poettering)
2020-12-09 13:34:49 +01:00
Dan Streetman 3965279c67 test/test-functions: copy /usr/lib/pam.d into $initdir
The systemd-user file has been moved from /etc/pam.d into /usr/lib/pam.d,
so test-functions needs to copy it from /usr/lib/pam.d instead.

This will copy it from either location.
2020-11-23 17:17:19 -05:00
Anita Zhang e4ff80404a test: add basic memory pressure extended test for oomd
Simple test to generate a lot of pressure in one unit and assert that
systemd-oomd kills the right one.
2020-10-22 17:04:22 -07:00
Lennart Poettering 73484ecff9 test-functions: make sure we test our own libudev instead of the host libudev
When invoking "ldd" to find dependency libraries we already set
$LD_LIBRARY_PATH to point to our own build tree, so that our libraries
are checked, not the host libraries. This is not sufficient howeever, as
libudev is built in a subdir. Add that, too.
2020-09-01 17:40:12 +02:00
Zbigniew Jędrzejewski-Szmek 9f927e46ac test/test-functions: do not execute strip_binaries twice
It is called from setup_basic_environment(), which also calls install_symtemd()
a bit earlier, so in effect it would be called twice.
2020-08-27 13:10:30 +02:00
Zbigniew Jędrzejewski-Szmek ae6c598791 tests/TEST-50: support the case when /etc/os-release is present
We have four legal cases:
1. /usr/lib/os-release exists and /etc/os-release is a symlink to it
2. both exist but /etc/os-release is not a symlink to /usr/lib/os-release
3. only /usr/lib/os-release exists
4. only /etc/os-release exists

The generic setup code in test-functions and create-busybox-image didn't handle
case 3.

The test-specific code in TEST-50 didn't handle 2 (because the general setup
code would only install /etc/os-release in the image and
grep -f /usr/lib/os-release would not work) and 4 (same reason) and would fail
in case 3 in generic setup.
2020-08-27 13:08:14 +02:00
Elisei Roca 2aa5a13aa9 test: adapt test-functions for SUSE 2020-07-22 10:42:42 +02:00
Frantisek Sumsal 8f843190ff test: bump the timeout for systemd-hwdb-update.service under ASan
Since the hwdb update from a79be2f807
the systemd-hwdb-update service started timing out under ASan when
compiled with gcc, as we started tripping over the 3 minutes timeout.

This affects only gcc runs, since the current gcc on Arch still suffers
from the detect_stack_use_after_return performance penalty[0]. Until
the fixed gcc is present in the respective repositories, let's bump
the timeout to 4 minutes, as we might not be able to upgrade right
away, due to systemd/systemd#16199.

Before the hwdb update:
[ 7958.292540] systemd[63]: systemd-hwdb-update.service: Executing: /usr/bin/time systemd-hwdb update
[ 7958.304005] systemd[1]: systemd-journald.service: Got notification message from PID 44 (FDSTORE=1)
[ 7958.314434] systemd[1]: systemd-journald.service: Added fd 3 (n/a) to fd store.
[ 8008.520082] systemd[1]: systemd-journald.service: Got notification message from PID 44 (WATCHDOG=1)
[ 8068.520151] systemd[1]: systemd-journald.service: Got notification message from PID 44 (WATCHDOG=1)
[ 8125.682843] time[63]: 84.47user 82.92system 2:47.50elapsed 99%CPU (0avgtext+0avgdata 811512maxresident)k
[ 8125.682843] time[63]: 0inputs+19680outputs (0major+25000853minor)pagefaults 0swaps

After the hwdb update:
[ 6215.491958] systemd[63]: systemd-hwdb-update.service: Executing: /usr/bin/time systemd-hwdb update
[ 6215.503380] systemd[1]: systemd-journald.service: Got notification message from PID 44 (FDSTORE=1)
[ 6215.514172] systemd[1]: systemd-journald.service: Added fd 3 (n/a) to fd store.
[ 6329.392918] systemd[1]: systemd-journald.service: Got notification message from PID 44 (WATCHDOG=1)
[ 6394.920205] time[63]: 89.48user 89.98system 2:59.55elapsed 99%CPU (0avgtext+0avgdata 812764maxresident)k
[ 6394.920205] time[63]: 0inputs+20568outputs (0major+27318354minor)pagefaults 0swaps

[0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94910
2020-06-29 16:07:11 +02:00
Elisei Roca 9e1732924d
test-functions: read /usr/etc/nsswitch.conf if /etc/nsswitch.conf does not exist (#16195)
See this for more info why and since when this change is needed: https://build.opensuse.org/request/show/807179.
2020-06-23 07:42:15 +02:00
Frantisek Sumsal e47add9edc test: make TEST-02-CRYPTSETUP a bit more robust
Prompted by systemd/systemd#16111.

* check if /var is a mountpoint - if not, something went wrong. In case
  of systemd/systemd#16111 the /failed file was created, because
  systemd-cryptsetup failed, but it ended up being empty, making the result
  check incorrectly pass
* forward journal messages to console - if we fail to mount /var,
  journald won't flush logs to the persistent storage and we end up
  empty handed and with no clue what went wrong

For example, without systemd/systemd#16111 and with this patch:
...
[FAILED] Failed to start systemd-cryptsetup@varcrypt.service.
See 'systemctl status systemd-cryptsetup@varcrypt.service' for details.
[DEPEND] Dependency failed for cryptsetup.target.
...
[    3.882451] systemd-cryptsetup[581]: Key file /etc/varkey is world-readable. This is not a good idea!
[    3.883946] systemd-cryptsetup[581]: WARNING: Locking directory /run/cryptsetup is missing!
[    3.884846] systemd-cryptsetup[581]: Failed to load Bitlocker superblock on device /dev/disk/by-uuid/180ba5ef-873b-4018-9968-47c23431f71a: Invalid argument
...
[    4.099451] sh[606]: + mountpoint /var
[    4.100025] sh[603]: + systemctl poweroff --no-block
[    4.101636] systemd[1]: Finished systemd-user-sessions.service.
[    4.102598] sh[608]: /var is not a mountpoint
[FAILED] Failed to start testsuite-02.service.
2020-06-10 17:42:25 +02:00
Jay Burger eed44b715d fix_test_function_timeout 2020-05-30 12:01:29 +02:00
Frantisek Sumsal 2991fa41e4 test: create public images by default
Let's create new images public by default and then symlink/copy them
into the respective private directories afterwards, not the other way
around. This should fix a nasty race condition in parallel runs where
one tests attempts to copy the backing public image at the same moment
another test is already modifying it.
2020-05-27 08:41:02 +02:00
Frantisek Sumsal 7a57256c73 test: introduce TEST_PARALLELIZE to support running tests in parallel
Support running tests in parallel by switching to copying of the
base image instead of symlinking it..

This still requires some setup steps, like running `make setup` on tests
which have unique $IMAGE_NAME beforehand (and sequentially), otherwise
they'll all try to create the same base image when started in parallel,
leading to nasty issues. However, as running the integration tests in
parallel is such an unusual use case it should be good enough, for now.
2020-05-17 10:48:16 +02:00
Frantisek Sumsal e89450921f test: fix public/private image detection and prefer the latter one 2020-05-17 10:46:34 +02:00
Zbigniew Jędrzejewski-Szmek b76ef59756
Merge pull request #13512 from msekletar/freezer
core: introduce support for cgroup freezer
2020-05-01 07:52:29 +02:00
Dan Streetman cad6727906 test: find path for systemd-journal-remote
As Debian/Ubuntu use /lib/systemd instead of /usr/lib/systemd,
add systemd-journal-remote to the list of programs that test-functions
detects the correct path to, and replace its direct usage with
$SYSTEMD_JOURNAL_REMOTE

Also use $JOURNALCTL instead of journalctl.

Also minor correction in install_plymouth() to look in /lib/... as
well as /usr/lib/... and /etc/...
2020-04-30 22:33:47 +02:00
Michal Sekletár d446ae89c0 test: add test for cgroup v2 freezer support 2020-04-30 19:02:55 +02:00
Frantisek Sumsal 80b44b38b5 test: correctly clean up test artifacts
Remove the artifact files indicating test result (testok, failed, and
skipped) just before running the test so we always get the latest and
most relevant result instead of incorrectly consuming previous results.

Discovered in https://github.com/systemd/systemd/pull/15378#issuecomment-616801873
2020-04-22 08:57:38 +02:00
Lennart Poettering e46736fbb6 units: use correct path to refer to plymouth
This doesn't really matter, since in non-/usr-merged systems plymouth
needs to be in /bin and on merged ones it doesn't matter, but it is
still prettier to insert the right path, and avoid /bin on merged
systems, since it's just a compat symlink.

Replaces: #15351
2020-04-16 16:33:01 +02:00
Zbigniew Jędrzejewski-Szmek 8cf85bb575
Merge pull request #15281 from keszybz/functional-test-rework
Post-merge tweaks to the functional tests
2020-04-12 19:31:53 +02:00
Zbigniew Jędrzejewski-Szmek 20f938ff7f test: print path to build directory on misconfiguration
This way it's easier to see when a wrong $BUILD_DIR was passed.
2020-03-31 15:13:13 +02:00
Zbigniew Jędrzejewski-Szmek 6e5b51d94a test: run loop device cleanup in more cases 2020-03-31 14:37:20 +02:00
Zbigniew Jędrzejewski-Szmek f1416431b6 test: optionally print the journal after tests
This is hopefully the last bit of functionality from
https://salsa.debian.org/systemd-team/systemd/-/blob/debian/master/debian/tests/upstream.
2020-03-31 12:31:10 +02:00
Zbigniew Jędrzejewski-Szmek f9eb2d51da test: use systemd-journal-remote for journal copying, support $ARTIFACT_DIRECTORY
Using s-j-remote fixes the following issue: when coalescing files from multiple
inputs, simply copying all files with into the the same directory might
potentially mess things up, because a newer system.journal might overwrite an
older journal. This happens because we run multiple tests from the same image,
and need to clean out the directory after each run.

By using systemd-journal-remote, we nicely coalesce all files. This has the
advantage that if there aren't too many logs, we end up with just one journal
file.

ARTIFACT_DIRECTORY is for ubuntuautopackagetests, where the journal files are
copied to a separate directory to preserve after tests have been run. This
functionality can now be recreated by setting
ARTIFACT_DIRECTORY=$AUTOPKGTEST_ARTIFACTS.
2020-03-31 12:31:10 +02:00
Zbigniew Jędrzejewski-Szmek 8943daf813 test: use a helper function to move the journal files 2020-03-31 12:31:10 +02:00
Zbigniew Jędrzejewski-Szmek a455e75a30 test: use systemd.status-unit-format=name in all but one test
We want to test the traditional output, but the non-default one is generally
much nicer for debugging (and takes less space...).
2020-03-31 12:31:10 +02:00
Zbigniew Jędrzejewski-Szmek 8af10ca3fc test: print test of name in output 2020-03-28 12:37:28 +01:00
Zbigniew Jędrzejewski-Szmek 1506edca91 test: stop caching loopdev
It is more trouble than it is worth. The setup is of a loopback device
is very quick, so it's better to always create it when needed and
immediately drop afterwards.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek 693ad298e9 test: perform partial cleanup after each test is run
This causes the unprivileged-nspawn-root directory to be removed
after running one test. The advantage is that we reduce the maximum
disk-space use quite a bit (47*400 MB → about 18GB).
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek 108d00a6b2 test: simplify the Makefiles
has-overflow was a temporary hack that was removed in
844da987ef (Oct. 2016). All the makefiles
can be the same, and all the targets can be handled identically.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek ec43f6862e test: run tests directly from the loopback device
Before, we'd copy the test tree into nspawn-root, and run the tests from there.
This is OK, and doesn't actually take much extra time. But it uses quite a lot
of extra disk space. So let's make things a bit more efficient by running
directly from the image file.

We still run the unprivileged nspawn tests from a copy. Once the kernel
implements fs shift, we can do away with that too.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek eb1290ef35 test: wipe journal files after test
Otherwise they accumulate and create noise.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek b74a306197 test: echo a message when the tests fails
Sometimes it is not clear from the preceding output that there was a
failure.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek 9d84eb2053 test/TEST-01: allow running w/o -Dinstall-tests=true
This is useful for sanitizer builds under CI, see
https://github.com/systemd/systemd-centos-ci/pull/202#issuecomment-566476592.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek 8c3534b5db test: rework how images are created
Before, we'd create a separate image for each test, in
/var/tmp/systemd-test.XXXXX/rootdisk.img. Most of the images
where very similar, except that each one had some unit files installed
specifically for the test. The installation of those custom unit files
was removed in previous commits (all the unit files are always installed).

The new approach is to only create as few distinct images as possible.
We have:
default.img: the "normal" image suitable for almost all the tests
basic.img: the same as default image but doesn't mask any services
cryptsetup.img: p2 is used for encrypted /var
badid.img: /etc/machine-id is overwritten with stuff
selinux.img: with selinux added for fun and fun
and a few others:

ls -l build/test/*img
lrwxrwxrwx 1 root root 38 Mar 21 21:23 build/test/badid.img -> /var/tmp/systemd-test.PJFFeo/badid.img
lrwxrwxrwx 1 root root 38 Mar 21 21:17 build/test/basic.img -> /var/tmp/systemd-test.na0xOI/basic.img
lrwxrwxrwx 1 root root 43 Mar 21 21:18 build/test/cryptsetup.img -> /var/tmp/systemd-test.Tzjv06/cryptsetup.img
lrwxrwxrwx 1 root root 40 Mar 21 21:19 build/test/default.img -> /var/tmp/systemd-test.EscAsS/default.img
lrwxrwxrwx 1 root root 39 Mar 21 21:22 build/test/nspawn.img -> /var/tmp/systemd-test.HSebKo/nspawn.img
lrwxrwxrwx 1 root root 40 Mar 21 21:20 build/test/selinux.img -> /var/tmp/systemd-test.daBjbx/selinux.img
lrwxrwxrwx 1 root root 39 Mar 21 21:21 build/test/test08.img -> /var/tmp/systemd-test.OgnN8Z/test08.img

I considered trying to use the same image everywhere. It would probably be
possible, but it would be very brittle. By using separate images where it is
necessary we keep various orthogonal modifications independent.

The way that images are cached is complicated by the fact that we still
want to keep them in /var/tmp. Thus, an image is created on first use and
linked to from build/test/ so it can be found by other tests.

Tests cannot be run in parallel. I think that is an acceptable limitation.
Creation of the images was probably taking more resources then the actual
tests, so we should be better off anyway.
2020-03-28 11:51:29 +01:00
Zbigniew Jędrzejewski-Szmek 4962ed9f33 test: make sure to reset state before starting integration tests 2020-03-28 11:51:27 +01:00
Zbigniew Jędrzejewski-Szmek 8a59e79c09 test: mount root rw and drop /etc/fstab
We had an fstab for the sole purpose of remounting "/" rw. Mounting root ro
is a pointless excercise in obsolete approaches. More importantly, the nspawn
image is now the same as the qemu one.
2020-03-28 11:51:13 +01:00
Zbigniew Jędrzejewski-Szmek 50b836518c test: drop cargo-cult line
p2 is only used in the cryptsetup test...
2020-03-28 11:51:13 +01:00
Zbigniew Jędrzejewski-Szmek 80c53fe7d5 test: improve reporting a bit 2020-03-28 11:51:13 +01:00
Zbigniew Jędrzejewski-Szmek 70ce817ccb test: de-duplicate test_setup() functions
Now we will run setup_nspawn_root() in some case where do don't need to.
2020-03-28 11:51:11 +01:00
Zbigniew Jędrzejewski-Szmek e29e4d5742 test: convert TEST-45 to a normal meson test
On my laptop, it now takes 0.23 s. We don't need the overhead of creating
an image and spawning a machine to mangle a file in /tmp.
2020-03-28 11:50:38 +01:00
Zbigniew Jędrzejewski-Szmek d0ac89a1e8 test: move TEST-43-* setup to static files
Setup of lingering is dropped. I don't think it's necessary for anything,
because the unit is still pulled in from the testsuite service.
2020-03-28 11:46:48 +01:00
Zbigniew Jędrzejewski-Szmek bdfd515ad1 test: move TEST-42-EXECSTOPPOST setup to static files 2020-03-28 11:46:48 +01:00
Zbigniew Jędrzejewski-Szmek 7eeeab205d test: move TEST-30-ONCLOCKCHANGE setup to static files
The two timezone files are now installed in the global setup. I am not too
happy about this, but it still seems better than to create a completely
separate image just for this.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 6e796683df test: move TEST-25-IMPORT setup to static files
Also run mask_supporting_services() here.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek f4c40fd754 test: move TEST-24-UNIT-TESTS setup to static files
I picked the list of zone files to install by grepping through the code. This
is is a bit brittle, but installing all of them takes a while, and more
importantly, writes a lot of lines to the log.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek c0b97b0fc8 test: move TEST-22-TMPFILES setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek e5badaf335 test: move most of TEST-13-NSPAWN-SMOKE setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek d10029bba4 test: move TEST-12-ISSUE-3171 setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 3ac189d8aa test: move TEST-11-ISSUE-3166 setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 8c6d58f65d test: move TEST-10-ISSUE-2467 setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 4110a6deb9 test: use shell arrays and remove duplicates
The tool lists are obviously not empty, so let's remove the test if they are.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 4caa1ac794 test/TEST-06: make autorelabel.service a static file too 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 9901a6ad2e test: convert TEST-04-JOURNAL to generic image 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek fe85f2bb9c test: move TEST-01-BASIC setup to static files
After this commit, only tests that were converted will work, because the
interface to test_run() changed.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 5f28f3ddaf test: allow overriding EFI_MOUNT like other variables 2020-03-22 10:22:42 +01:00
Jörg Thalheim ff12a7954c treewide: more portable bash shebangs
As in 2a5fcfae02
and in 3e67e5c992
using /usr/bin/env allows bash to be looked up in PATH
rather than being hard-coded.

As with the previous changes the same arguments apply
- distributions have scripts to rewrite shebangs on installation and
  they know what locations to rely on.
- For tests/compilation we should rather rely on the user to have setup
  there PATH correctly.

In particular this makes testing from git easier on NixOS where do not provide
/bin/bash to improve compose-ability.
2020-03-05 17:27:07 +01:00
Zbigniew Jędrzejewski-Szmek 33eb1f2497 tree-wide: drop printk.devkmsg=on setting in various places
Since 6123dfaa72 this should not be necessary anymore.
2020-03-03 15:02:53 +01:00
Frantisek Sumsal 2273ecfeda test: don't install /etc/securetty
Having /etc/securetty in test containers prevents root from logging into
them:

```
Jan 31 10:15:11 systemd-testsuite login[69]: pam_securetty(login:auth): access denied: tty 'pts/0' is not secure !
Jan 31 10:15:11 systemd-testsuite login[69]: FAILED LOGIN 1 FROM pts/0 FOR root, Authentication failure
```
2020-02-01 11:55:17 +01:00
Evgeny Vereshchagin 9a1862bfa6 tests: unset LD_PRELOAD in testsuite.service when it's run under ASan
This should help to address the "grep" issue we ran into in
https://github.com/systemd/systemd-centos-ci/pull/217.
2020-01-31 13:13:04 +01:00
Filipe Brandenburger a49ad4c482 core: add test case for PrivateUsers=true in user manager
The test exercises that PrivateTmp=yes and ProtectHome={read-only,tmpfs}
directives work as expected when PrivateUsers=yes in a user manager.

Some code is also added to test-functions to help set up test cases that
exercise the user manager.
2019-12-18 11:09:30 -08:00
Lennart Poettering 5bb4503d3a test-functions: make sure we use the right library path for binaries without RPATH
Meson appears to set the rpath only for some binaries it builds, but not
all. (The rules are not clear to me, but that's besides the point of
this commit).

Let's make sure if our test script operates on a binary that has no
rpath set we fall back preferably to the BUILD_DIR rather than directly
to the host.

This matters if a test uses a libsystemd symbol introduced in a version
newer than the one on the host. In that case "ldd" will not work on the
test binary if rpath is not set. With this fix that behaviour is
corrected, and "ldd" works correctly even in this case.

(Or in other words: before this fix on binaries lacking rpath we'd base
dependency info on the libraries of the host, not the buidl tree, if
they exist in both.)
2019-11-28 09:20:40 +01:00
Filipe Brandenburger 14e0259b49 test: Disable LUKS devices from initramfs in QEMU tests
We currently use the host's kernel and initramfs in our QEMU tests.

If the host is running on an encrypted LUKS partition, then the initramfs
will have a crypttab setup looking for the particular root disk it needs to
encrypt before booting into the system.

However, this disk obviously doesn't exist in our QEMU VM, so it turns out
our tests end up waiting for this device to become available, which will
never actually happen, and boot hangs for 90s until that service times out.

[***   ] A start job is running for /dev/disk/by-uuid/01234567-abcd-1234-abcd-0123456789ab (20s / 1min 30s)

In order to prevent this issue, let's pass "rd.luks=0" to disable LUKS in
the initramfs only as part of our default kernel command-line in our QEMU
tests.

This is enough to disable this behavior and prevent the timeout, while at
the same time doesn't conflict with our tests that actually check for LUKS
behavior in the systemd running under test (such as TEST-02-CRYPTSETUP).

Tested: `sudo make -C TEST-02-CRYPTSETUP/ clean setup run`
2019-11-13 19:55:18 -08:00
Zbigniew Jędrzejewski-Szmek 51fa85913c test: add function to reduce copied setup boilerplate
Many tests were also masking systemd-machined.service. But machined
should only start when activated, so having it not masked shouldn't be
noticable. TEST-25-IMPORT needs it.
2019-10-08 09:10:12 +02:00
Zbigniew Jędrzejewski-Szmek c78c095b1e nspawn: rename UNIFIED_CGROUP_HIERARCHY to SYSTEMD_NSPAWN_UNIFIED_HIERARCHY
We should never have used an unprefixed environment variable name.
All other systemd-nspawn variables have the "SYSTEMD_NSPAWN_" prefix,
and all other systemd variables have the "SYSTEMD_" prefix.

The new variable name takes precedence, but we fall back to checking the
old one. If only the old one is found, a warning is emitted.

In addition, SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="" is accepted as an override
to avoid looking for the old variable name.

We have a variable with the same name ($UNIFIED_CGROUP_HIERARCHY) in tests,
which governs both systemd-nspawn and qemu behaviour. It is not renamed.
2019-10-01 10:21:13 -07:00
Frantisek Sumsal 501deda1ce test: allow use of nested KVM
Introduce TEST_NESTED_KVM variable, which allows use of nested KVM for
QEMU VMs (which is disabled by default by KVM autodetection).
2019-09-27 15:42:38 -07:00
Dan Streetman adcc450f46 test/test-functions: use truncate instead of dd to create testbed image
This avoids unnecessary noise in the stderr logs which dd always produces,
such as:

0+0 records in
0+0 records out
0 bytes copied, 0.000155284 s, 0.0 kB/s

Using truncate should not result in any functional change; the image will
still be created as a sparse file of the size specified.
2019-08-25 15:37:51 +09:00
Dan Streetman 84c49ad197 test/test-functions: use binaries from $BUILD_DIR or installed system
In Ubuntu CI, we test binaries from the installed system, not from
$BUILD_DIR, so use the appropriate binary.  Most of the calls to the
binaries are part of checking/processing asan-built binaries, and so
did not apply to Ubuntu CI, except for generating noise in the stderr
log like:

objdump: '/tmp/autopkgtest.83yGoI/build.fHB/src/test/TEST-01-BASIC/systemd-journald': No such file

However this also applies to the call to systemd-nspawn, which the debian
upstream test wrapper was sed-adjusting to use the installed binary
instead of the binary in $BUILD_DIR.  This commit allows removing that
sed processing of the test-functions file during Ubuntu CI test.
2019-08-25 15:36:47 +09:00
Dan Streetman 8c03df36fe test/test-functions: add mkdir to import_initdir
This dir is created by create_empty_image_rootdir, as well as indirectly
by some other functions, but it should be created by import_initdir so
the newly-exported $initdir exists and can be used immediately without
relying on other functions to create it.
2019-08-17 12:29:15 -04:00
Dan Streetman 0036ce06cb test: replace $TESTDIR/root with $initdir
The $initdir var is already set to $TESTDIR/root, it should be used
instead of direct use of $TESTDIR/root.
2019-08-17 12:29:08 -04:00
Dan Streetman 9e19a8b028 test/test-functions: avoid stderr noise, only umount on cleanup if mountpoint
Only umount it during cleanup if the $TESTDIR/root dir is a mountpoint.
This avoids adding noise to the stderr log such as:

mountpoint: /var/tmp/systemd-test.waLOFT/root: No such file or directory
2019-08-17 12:28:41 -04:00
Daniel Black f364a17dd1 test: ppc64* qemu is qemu-system-ppc64 2019-08-14 07:43:29 +00:00
Frantisek Sumsal 215bffe1b8 test: store coredumps in journal
To make debugging much easier, especially for crashes in tests under
QEMU, let's store the entire coredump bundle in the systemd journal,
which is usually kept around by various CIs. Right now, we usually end
up with a journal, but without the coredump itself, which is pretty
useless.
2019-08-13 07:09:57 +00:00
Frantisek Sumsal 761ce2a4ba test: allow overriding QEMU_OPTIONS from the outside 2019-08-05 13:48:29 +02:00
Dan Streetman 65dd488fe1 test: convert all uses of '|| true' into '|| :'
No change in functionality; just use the shorter || :
2019-07-19 13:47:21 +09:00
Zbigniew Jędrzejewski-Szmek 4a747647b3
Merge pull request #13082 from ddstreet/minor
Minor fixes in test framework
2019-07-17 08:44:01 +02:00
Dan Streetman 59279e9618 test/test-functions: fix install_dmeventd to correctly install bin/libs 2019-07-17 08:34:48 +02:00
Dan Streetman e96386521c test/test-functions: instmods call to find should use -type f
without using -type f, the logs print an error such as:

E:  E: modprobe: FATAL: Module asymmetric_keys not found in directory /lib/modules/4.15.0-54-generic

while this doesn't appear to cause problems, it can be extremely
distracting when trying to debug real failures.
2019-07-16 18:05:15 -04:00
Dan Streetman d391ee10a0 test: when stripping binaries, ignore case in suppressing "File format not recognized"
The grep -v matches all lowercase, but "file" is captialized; just ignore case so
it's suppressed for either all lowercase or capital File.
2019-07-16 18:05:15 -04:00
Dan Streetman f85bc044e5 test: ignore errors during test cleanup, so cleanup can finish
Also move TESTDIR and STATEFILE removal into test_cleanup
2019-07-16 18:05:15 -04:00
Dan Streetman ec4cab49c9 test: add create_empty_image_rootdir() to simplify testcase setup
Almost all tests were manually mounting/unmounting $TESTDIR/root
from the loopback image; this moves all that into test-functions
so the test setup functions are simplier.

Also add test_setup_cleanup() function, to cleanup what is mounted
by create_empty_image_rootdir()
2019-07-16 18:05:15 -04:00
Evgeny Vereshchagin 038bf640e9 tests: bump up QEMU_MEM 2019-07-16 15:01:26 +00:00
Evgeny Vereshchagin 869250e6b8
Merge pull request #12992 from mrc0mmand/test-functions-fixes
Various test/test-functions fixes/improvements
2019-07-09 02:27:39 +03:00
Frantisek Sumsal 71a0de36e5 test: be a little bit more verbose when installing service binaries 2019-07-08 21:10:21 +02:00
Frantisek Sumsal 3cdb93d07b test: correctly handle installation of newly introduced binaries
In certain cases we might attempt to install a binary which is already
present in the test image, yet it's missing from the host system.
In such cases, let's check if the binary indeed exists in the image
before doing any other chcecks. If it does, immediately return with
success.

This was discovered during installation of
/usr/lib/systemd/systemd-bless-boot, which was not present in Ubuntu CI
(as the installed systemd was from the Ubuntu repositories), and the
binary itself was already in the image thanks to `ninja install`.
However, during extraction of binaries from the systemd service files,
another attempt to install this binary was made, which failed due to
`find_binary` being unable to find it.
2019-07-08 21:05:51 +02:00
Frantisek Sumsal f5f8cc7aed test: make ASAN/UBSAN_OPTIONS overridable from the outside
This should allow us to tweak the ASAN_OPTIONS and UBSAN_OPTIONS env
variables for integration tests as well
2019-07-09 02:00:14 +09:00
Frantisek Sumsal 37ee8dc80f test: improve handling of ASan under clang
Running integration tests with ASan is somewhat tricky to begin with, as
we need to pre-load the ASan runtime DSO for certain services (like
dbus), otherwise they won't start or behave as expected. In case of gcc
this is pretty easy, as we need the runtime DSO during compilation, so
it's already present on the host system. For clang things get more
complicated, as ASan is compiled in statically by default, thus to
enable the necessary dynamic-ish behavior one needs to compile with
-shared-libasan and then correctly set LD_PRELOAD_PATH, as the runtime
libraries are not in a standard library path.
2019-05-27 17:46:07 +02:00
Zbigniew Jędrzejewski-Szmek 9e099c9fd8
Merge pull request #12431 from poettering/tmpfiles-chmod-chown-order
tmpfiles: run chown() before chmod()
2019-05-22 17:23:28 +02:00
Zbigniew Jędrzejewski-Szmek 95cff2a794 test: search $BOOT for kernel+initrd
$BOOT is the preferred location for kernel images. If $BOOT does not
exist, -x will print the path to ESP, so well fall back to previous
behaviour.
2019-05-19 12:05:21 +02:00
Evgeny Vereshchagin a5372344ea tests: override a hard-coded timeout that kicks in too early (under ASan+UBSan)
The test has failed two times today: https://travis-ci.org/systemd/systemd/jobs/530750626
and https://travis-ci.org/systemd/systemd/jobs/530759465.
2019-05-12 03:37:36 +02:00
Evgeny Vereshchagin 6141c6c99b tests: redirect the stdout/stderr of journald to a file (under ASan+UBSan)
Sometimes UBSan sends its reports to stderr regardless of what is specified in log_path
Let's try to catch them by redirecting stderr (and stdout just in case) to a file
See https://github.com/systemd/systemd/pull/12524#issuecomment-491108821
2019-05-12 03:37:36 +02:00
Evgeny Vereshchagin abf9b52ccd tests: redirect UBsan reports to a file
so that they won't end up in /dev/null
2019-05-12 03:37:36 +02:00
Frantisek Sumsal 54a3790ccb test: allow SKIP_INITRD override
Certain distributions (e.g. Arch Linux) require booting with initrd, as
they lack support for commonly used filesystems in the kernel (i.e. the
support is compiled in as modules)
2019-05-09 20:11:31 +02:00
Frantisek Sumsal aaef1ed21d test: don't preload libasan for systemd-remount-fs.service
The `mount` utility has an unexpected behavior when run with libasan,
causing false-positives during the integration testing.

For example, on Arch Linux with LD_PRELOAD pointing to libasan:
```
bash-5.0# mount -o remount,rw -v /
mount: /dev/sda1 mounted on /.
bash-5.0# echo $?
1
```
However:
```
bash-5.0# LD_PRELOAD= mount -o remount,rw -v /
mount: /dev/sda1 mounted on /.
bash-5.0# echo $?
0
```
Further investigation with strace shows a LeakSanitizer error:
```
bash-5.0# strace -s 512 mount -o remount,rw -v /
...
write(2, "==355==LeakSanitizer has encountered a fatal error.\n", 52) = -1 EBADF (Bad file descriptor)
write(2, "ReportFile::Write() can't output requested buffer!\n", 51) = -1 EBADF (Bad file descriptor)
exit_group(1)                           = ?
+++ exited with 1 +++
```

Let's workaround this by clearing the LD_PRELOAD variable for
systemd-remount-fs.service
2019-05-09 20:11:20 +02:00
Lennart Poettering 908665f4e9 test-functions: follow fedora dbus-daemon/dbus-broker rearrangements
Apparently dbus.service is now a symlink to either dbus-broker.service
or dbus-daemon.service. Copy in the right target service in each case.
2019-04-30 09:18:23 +02:00
Zbigniew Jędrzejewski-Szmek cc5549ca12 scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)

Also remove the few vim config lines that were left. We should either have them
on all files, or none.

Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-12 08:30:31 +02:00
Zbigniew Jędrzejewski-Szmek 408c9a07e5 test: filter out messages when stripping binaries
We would get an error for every script, which is just noise.
2019-04-12 08:23:41 +02:00
Frantisek Sumsal b43c2c01e9 test: allow overriding of the KVM detection using TEST_NO_KVM
By default the run_qemu() function enables KVM automatically
if it detects the /dev/kvm char device and if the machine is not
already a KVM one. Let's add a TEST_NO_KVM env variable to suppress
this detection.
2019-03-16 18:59:07 +01:00
Frantisek Sumsal c81a46b904 test: introduce INTERACTIVE_DEBUG
Make the interactive debugging of (particularly QEMU) machines less
painful, by replacing the default vt220 TERM with linux one, and
by not shutting down the machine after running the test itself.
2019-03-16 18:59:01 +01:00
Frantisek Sumsal 6d67286fc3 test: unify indentation 2019-03-16 15:49:43 +01:00
Lennart Poettering 9bbd37845c
Merge pull request #11988 from keszybz/test-binaries-installation
Install more requires binaries for tests
2019-03-15 13:06:11 +01:00
Frantisek Sumsal 32983312ed test: bump the second partition size to 50MB
10MB is not enough for a LUKS2 partition.
2019-03-15 06:12:23 +01:00
Zbigniew Jędrzejewski-Szmek 98b0439f08 tests: install /usr/bin/dbus-broker when using dbus-broker
We'd install the service file, and then dbus-broker-launcher because it is
mentioned in ExecStart=, but not the main executable, so nothing would work.
Let's just install dbus-broker executables if found. They are small, so this
doesn't matter much, and is much easier than figuring the exact conditions
under which dbus-broker will be used instead of dbus-daemon.
2019-03-14 15:52:38 +01:00
Frantisek Sumsal 0ae4456c93 test: avoid double-fsck'ing of the rootfs on Arch
Since systemd 206 the combination of systemd and mkinitcpio
causes, under certain conditions, the rootfs to be double fsck'd.

Symptoms:
```
:: performing fsck on '/dev/sda1'
systemd: clean, 3523/125488 files, 141738/501760 blocks
********************** WARNING **********************
*                                                   *
*  The root device is not configured to be mounted  *
*  read-write! It may be fsck'd again later.        *
*                                                   *
*****************************************************
<snip>
[  OK  ] Started File System Check on Root Device
```

This occurs when neither 'ro' or 'rw', or only 'ro' is present
on the kernel command line. The solution is to mount the roofs
as read-write on the kernel command line, so systemd knows to not fsck
it again.
2019-03-13 17:05:31 +01:00
Zbigniew Jędrzejewski-Szmek 1e46047066 tests: install "head" in the image
For #11915.
2019-03-13 16:35:23 +01:00
Frantisek Sumsal 3f50fff536 test: don't overwrite TESTDIR if already set 2019-03-13 10:30:25 +01:00
Frantisek Sumsal 5bfb2a93a4 test: try to determine QEMU_SMP dynamically
If the QEMU_SMP value has not been explicitly set, try to determine it
from the number of online CPUs using the nproc utility. If this approach
fails, fall back to the default value QEMU_SMP=1.

This change should significantly help when running integration tests
under QEMU on multicore systems.
2019-03-08 21:28:26 +01:00