Commit graph

3656 commits

Author SHA1 Message Date
Frantisek Sumsal 378db9e2b9 test: add a couple of tests for machinectl 2023-05-13 00:26:38 +02:00
Frantisek Sumsal c2df08b5b8 test: clean up the nspawn tests a bit 2023-05-12 18:05:29 +02:00
Yu Watanabe 531a6233d1
Merge pull request #27603 from mrc0mmand/more-test-shenanigans
test: merge PID1-related tests into TEST-07-PID1
2023-05-11 16:48:13 +09:00
Frantisek Sumsal 15bbc0c107 test: abstract the common test parts into a utility script
Also, instead of bailing out on the first failed subtest, always run all
subtests and print a summary at the end (with an appropriate exit code).
2023-05-10 21:26:26 +02:00
Frantisek Sumsal 3a4b86264e test: merge TEST-20-MAINPIDGAMES into TEST-07-PID1 2023-05-10 21:26:26 +02:00
Frantisek Sumsal d8d8380a35 test: merge TEST-51-ISSUE-16115 into TEST-07-PID1 2023-05-10 21:26:26 +02:00
Frantisek Sumsal 11562ee585 test: merge TEST-47-ISSUE-14566 into TEST-07-PID1 2023-05-10 21:26:26 +02:00
Frantisek Sumsal 8412cdf4fd test: move TEST-23's units into a dedicated subfolder
To remain consistent with other tests.
2023-05-10 21:26:26 +02:00
Frantisek Sumsal 51b6dbf75a test: merge TEST-12-ISSUE-3171 into TEST-07-PID1 2023-05-10 21:26:26 +02:00
Daan De Meyer 1fd5ec5697 tmpfiles: Add merge support for copy files action
If '+' is specified with 'C', let's merge the tree with any existing
tree.
2023-05-10 18:08:07 +02:00
Daan De Meyer e57b7020d2 repart: Fix deny list logic
Until now, we always excluded the top level directories that were
covered by child partition mount points, regardless of the source
directory and the target directory of the copy files operation.
This means that even if we were populating a XBOOTLDR partition, if
there was an EFI partition in the image, we'd exclude /boot
unconditionally, leading to the XBOOTLDR partition to be empty.

Also, because of the same cause, if we were copying a nested source
directory (e.g. /abc/def) to the root directory in the root
partition, if /abc/def/usr existed and was populated with files and
directories, the root partition would have those files under /usr,
even if a /usr partition was defined.

To fix these issues, instead of unconditionally excluding the top
level partition mount points under <source>, let's make sure that
when we're copying files from any source directory to the root
directory of a root partition, that we exclude the partition mount
point directories under the source directory instead of the top
level ones.
2023-05-10 18:07:47 +02:00
Frantisek Sumsal 33dff897b9 test: merge TEST-11-ISSUE-3166 into TEST-07-PID1 2023-05-10 14:29:38 +02:00
Frantisek Sumsal a8faac7dae test: merge TEST-10-ISSUE-2467 with TEST-07-PID1 2023-05-10 14:29:38 +02:00
Frantisek Sumsal 4966a31ba3 test: merge TEST-09-ISSUE-2691 into TEST-07-PID1 2023-05-10 14:29:38 +02:00
Frantisek Sumsal cd62ba42a4 test: merge TEST-08-ISSUE-2730 into TEST-07-PID1 2023-05-10 14:29:38 +02:00
Frantisek Sumsal 09c033a276 test: rename TEST-07-ISSUE-1981 to TEST-07-PID1 2023-05-10 12:38:57 +02:00
Frantisek Sumsal a9fe7f66e8 test: slightly extend systemd-cryptenroll coverage 2023-05-09 22:47:42 +02:00
Frantisek Sumsal 920eb35db9 test: TEST-70-TPM2 cleanup
No functional changes.
2023-05-09 21:18:36 +02:00
Frantisek Sumsal b6869359e6 test: add coverage for #27533
Issue: https://github.com/systemd/systemd/issues/27533
Fix: https://github.com/systemd/systemd/pull/27553
2023-05-09 19:59:13 +02:00
Frantisek Sumsal 5e8656e101 test: discard kill's output 2023-05-09 19:55:04 +02:00
Frantisek Sumsal 539af5c441 test: merge unit file related tests into TEST-23-UNIT-FILE
Rename TEST-23-TYPE-EXEC to TEST-23-UNIT-FILE and merge it with
following tests:
  - TEST-37-RUNTIMEDIRECTORYPRESERV
  - TEST-40-EXEC-COMMAND-EX
  - TEST-41-ONESHOT-RESTART
  - TEST-42-EXECSTOPPOST
  - TEST-57-ONSUCCESS-UPHOLD
2023-05-10 02:39:12 +09:00
Zbigniew Jędrzejewski-Szmek 711169905e test: use sed and grep instead of perl
This gets rid of the all-but-one remaining uses of perl. I tested the new code
on my machine, so I'm fairly confident that it works as expected.

install_iscsi() has one majestic perl invocation, but we can't get rid of it
easily: it extends the code of tgt-admin to print some list of files. Obviously
this only works because tgt-admin is written in perl, and perl will be installed
if tgt-admin is installed. install_iscsi() is used in TEST-64-UDEV-STORAGE
conditionally if tgtadm is installed, so this can stay as is.
2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek b370f050f8 test-execute: use bash instead of perl
I think this is easier to grok too.
2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek 21ec66420a test-udev: skip test on python3.6 2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek dcbbc7cef5 test/run-unit-tests, TEST-02: skip tests where the interpeter is not installed
When the interpeter is missing, we get an exit code of 127. Let's treat those
tests as skipped too. If we could run the test far enough so that it could do
the check itself, it would return 77 anyway.

$ test/asdf; echo $?
exec: Failed to execute process 'test/asdf': The file specified the interpreter '/bin/asdf', which is not an executable command.
127
$ test/asdf; echo $?
/usr/bin/env: ‘/bin/asdf’: No such file or directory
127

This should resolve the problem that TEST-02 fails or Debian's 'unit-tests' fail
when python3 is not installed. Installing python3 via the mechanism that is
used to construct TEST images, i.e. the dracut dependency chasing scheme, would
be a lot of work for python with its modules in multiple locations and hundreds
of little files. So I think it OK to just skip the test there, and also in
other cases where python is not available.
2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek 0454cf05d3 test: rework how udev-test is invoked
As part of the build, we would populate build/test/sys/ using
sys-script.py, and then udev-test.p[ly] would create a tmpfs instance
on build/test/tmpfs and copy the sys tree to build/test/tmpfs/sys.

Also, we had udev-test.p[ly] which called test-udev. test-udev was
marked as a manual test and installed, but neither udev-test.p[ly] or
sys-script.py were.

test-udev is renamed to udev-rule-runner, which reduces confusion and
frees up the test-udev name. udev-test.py is renamed to test-udev.py.
All three files are now installed.

test-udev.py is modified to internally call sys-script.py to set up the
sys tree. Copying and creating it from scratch should take the same
amount of time. We avoid having a magic directory, everything is now
done underneath a temporary directory.

test-udev.py is now a normal installed test, and run-unit-tests.py will
pick it up. When test-udev.py is invoked from meson, the path to
udev-rule-runner is passed via envvar; when it is invoked via
run-unit-tests.py or directly, it looks for udev-rule-runner in a relative
path.

The goal of this whole change is to let Debian drop the 'udev' test.
It called sys-script.py and udev-test.pl from the source directory and
had to recreate a bunch of the logic. Now test-udev.py will now be called
via 'upstream'.
2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek 09ea351b6f test: drop udev-test.pl 2023-05-09 08:11:10 +02:00
Zbigniew Jędrzejewski-Szmek f2c02d232e test: rewrite udev-test.pl in Python
I tried to keep this a 1:1 rewrite with the same field names.
Nevertheless, some changes were made:
- exp_add_error and exp_rem_error are dropped. Those fields meant that
  "./test-udev add <devpath>" actually succeeded, but symlinks were not
  created, and exp_links was ignored and could contain bogus content.
  Instead, exp_links and not_exp_links are adjusted to not contain
  garbage and the tests check that "./test-udev add" succeeds and that
  the links are as expected from exp_links and not_exp_links.
- cleanup was only used in one rule, and that rule was expected to fail,
  so cleanup wasn't actually necessary. So the cleanup field and the
  logic to call cleanup from individual tests is removed.
- a bunch of fields were set, but didn't seem to be connected to any
  implementation: not_exp_name, not_exp_test.
  e62acc3159 did a rewrite of some of the
  tests and it seems that not_exp_test was added by mistake and
  not_exp_name was left behind by mistake.
  In Python, the field list is declared in the class, so it's harder to
  assign an unused attribute. Those uses were converted to not_exp_links.
- in most rules, r"""…""" is used, so that escaping is not necessary.
- the logic to generate devices was only used in one place, and the
  generator function also had provisions to handle arguments that were
  never given. all_block_devs() is made much simpler.
- Descriptions that started with a capital letter were shortened
  and lowercased.
- no special test case counting is done. pytest just counts the cases
  (Rules objects).
- the output for failures is also removed. If something goes wrong, the
  user can use pytest --pdb or such to debug the issue.
- perl version used a semaphore to manage udev runners, and would fork,
  optionally wait a bit, and then start the runner. In the python
  version, we just spawn them all and wait for them to exit. It's not
  very convenient to call fork() from python, so instead the runner
  was modified (in previous commit) to wait.

The test can be called as:
  (cd build && sudo pytest -v ../test/udev-test.py)
  sudo meson test -C build udev-test.py -v

I think this generally provides functionality that is close to the perl
version. It seems some of the checks are now more fully implemented.
Support for strace/gdb/valgrind is missing.

Runtime goes down: 8.36 s → 5.78 s.
2023-05-09 08:11:10 +02:00
Frantisek Sumsal 380a36582d test: add a test case for #27521
Which got resolved by e652663a04.
2023-05-05 22:15:23 +02:00
Frantisek Sumsal 24e91e08f8 core: check the unit type more thoroughly when deserializing
Resolves: #27523
2023-05-05 22:15:23 +02:00
Frantisek Sumsal cc938f1ce0 shared: refuse fd == INT_MAX
Since we do `FD_TO_PTR(fd)` that expands to `INT_TO_PTR(fd) + 1` which
triggers an integer overflow.

Resolves: #27522
2023-05-05 22:15:23 +02:00
Frantisek Sumsal b003e2c7a6 test: clean up the test script even further
Most notably:
  - use `systemd-id128 new` instead of `journalctl --new-id128`
  - move all temporary files to /tmp
  - wrap repetitive checks in a function
2023-05-03 18:32:00 +02:00
Frantisek Sumsal 8077d99fd2 test: vacuum the journal after the "stress test"
To make the rest of the test significantly faster.
2023-05-03 17:37:09 +02:00
Frantisek Sumsal 23f83ba768 test: slightly extend checks on corrupted journals 2023-05-03 17:32:36 +02:00
Frantisek Sumsal c4039ceb9e test: further extend our collection of corrupted journals
And make adding them slightly easier.

Provides coverage for b5335da7a5.
2023-05-03 17:22:37 +02:00
Yu Watanabe a76dc1f3a0
Merge pull request #27504 from mrc0mmand/fuzz-manager-serialize
test: add a simple fuzzer for manager serialization
2023-05-03 21:45:26 +09:00
Frantisek Sumsal 740831076c shared: reject empty attachment path 2023-05-03 10:09:53 +02:00
Frantisek Sumsal 1febf60f9d shared: ignore invalid valink socket fd when deserializing 2023-05-03 10:09:53 +02:00
Frantisek Sumsal 45b1017488 core: fix NULL pointer dereference during deserialization 2023-05-03 10:09:53 +02:00
Frantisek Sumsal 24e6759cbc test: add a simple fuzzer for manager serialization 2023-05-03 10:09:53 +02:00
Yu Watanabe e94756c566 test: replace sleep with timeout
If the test environment is too slow, then sleeping 2 seconds may not be
sufficient.
2023-05-02 11:09:18 +02:00
Yu Watanabe 8e2449a5c9 test-network: add workaround for bug in iproute2 v6.2.0
Closes #27473.
2023-05-01 20:02:15 +02:00
Frantisek Sumsal 0f69a4e9ae test: test journalctl with corrupted journals
Last month I monkey-patched journald to produce a small (64K) but valid
journal and used that as an input to four AFL fuzzers. After a month it
generated quite a nice corpora (4738 test cases) and after filtering
and minimizing it I was left with 619 unique journals with various
levels of corruption that probe the journal code.

It seems to detect past issues like systemd#26567, etc.
2023-05-01 10:14:12 +02:00
Frantisek Sumsal de965f4893 test: clean up the test script a bit 2023-05-01 15:47:04 +09:00
Frantisek Sumsal 992e06df08 test: make sure the test units have a test- prefix
So when collecting coverage the test-.service dropin works as
expected.

Follow-up to 969f5f3cea.
2023-04-29 16:59:08 +02:00
Frantisek Sumsal edea0d6ac5 test: match all messages with the FILE field
As the systemd-pstore process is quite short lived, it might sometimes
lack the necessary metadata to make matching against a unit or a syslog
tag work. Since we already use a cursor file to make the matching window
small as possible, let's just drop the unit match completely and hope
for the best.

Resolves: #27453
2023-04-29 16:58:40 +02:00
Yu Watanabe 843cb225ad test: add tests for "systemctl stop" vs triggering by path unit 2023-04-29 09:10:28 +09:00
Yu Watanabe 2e701a7946 test: create temporary units under /run 2023-04-29 09:10:28 +09:00
Luca Boccassi 398d858d1c
Merge pull request #27437 from mrc0mmand/pstore
test: add a couple of tests for systemd-pstore
2023-04-28 16:14:09 +01:00
Frantisek Sumsal 6858e32d73 test: add a couple of tests for systemd-pstore 2023-04-28 13:16:45 +02:00