Commit graph

185 commits

Author SHA1 Message Date
Yu Watanabe e5cc6d107c meson: move several test declarations
One of the notable change is that previously test-sysusers.sh was installed
unconditionally, but now it is installed only when sysusers is enabled.

Another change is that test-sysv-generator is now re-introduced which
was mistakenly dropped by 6c713961ab.
2023-08-03 20:33:52 +09:00
Yu Watanabe 0b01cac59a meson: drop non-existent test directories 2023-06-16 10:43:06 +09:00
Jan Janssen 739a62bb40 meson: Use fs module in more places 2023-06-14 16:05:52 +02:00
Yu Watanabe 65f2ff7998
Merge pull request #27685 from keszybz/the-semiannual-excercise-in-output-narrowing
The semiannual excercise in output narrowing
2023-05-19 03:04:47 +09:00
Zbigniew Jędrzejewski-Szmek 02e0f430a0 meson: rename "dist-check" suite to "dist"
*Now* one of those tests is the longest, let's make them a bit shorter.
2023-05-18 17:18:11 +02:00
Frantisek Sumsal 5656759d06 test: get rid of the busybox stuff
It already required a lot of workarounds, since the busybox utilities
often work differently than their "full" counterparts, and putting
the container together using our "tools" is quite simple anyway.
2023-05-17 23:22:54 +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 a8faac7dae test: merge TEST-10-ISSUE-2467 with 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
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
Daan De Meyer 3ceb96e018 test: Install systemd-networkd-tests.py when install_tests is enabled 2023-03-29 12:18:42 +02:00
Franck Bui c18cc7f7fb meson: make sure the unit test scripts find testdata/ even if they are not installed in the same directory
testdata/ is shared by both the unit tests and the integration tests. Hence it
makes sense to place them right under /usr/lib/systemd/tests/ while the tests
themself are located under dedicated sub-directories:

     /usr/lib/systemd/tests/
     ├── integration-tests
     ├── testdata
     └── unit-tests
         ├── testdata -> ../testdata

However the unit tests implemented as shell scripts (such as
test-fstab-generator.sh) expect to find testdata/ where the scripts are
installed, ie they do something like:

  src="$(dirname "$0")/testdata/test-fstab-generator"

This patch installs a symlink in 'unitestsdir' named "testdata" and that points
to whatever value 'testdata_dir' is set.
2023-03-24 14:10:04 +01:00
Franck Bui 539ee7ab11 meson: define testdata_dir globally 2023-03-24 14:10:02 +01:00
Franck Bui 26c2b30277 test: install unit tests in a dedicated subdirectory below '$testsdir'
/usr/lib/systemd/tests may contain more than the unit tests. For example on
SUSE we also install the integration tests there.

Putting the unit tests in a dedicated directory named 'unit-tests' makes the
layout cleaner.

Note that `run-unit-tests.py` has not been moved so we don't need to adjust
(Fedora) packaging and users also don't need to descend into the subdirectory.
2023-03-24 14:08:57 +01:00
Zbigniew Jędrzejewski-Szmek 2f809d29e8 test-coredump-util: add tests for parse_aux()
The test files are /proc//auxv files copies from various architecutres
signified by the file name suffix.

Those tests are fairly simple, but when we run them on n architectures, we do
~n² cross-arch tests.
2023-03-23 18:06:46 +01:00
Mike Yuan b64f5ddaca
test: add tests for NOTIFYACCESS override through sd_notify 2023-03-22 19:22:10 +08:00
Jan Janssen e8509329d7 ci: Adjust for new EFI build 2023-03-10 11:41:08 +01:00
Jan Janssen dfca5587cf tree-wide: Drop gnu-efi
This drops all mentions of gnu-efi and its manual build machinery. A
future commit will bring bootloader builds back. A new bootloader meson
option is now used to control whether to build sd-boot and its userspace
tooling.
2023-03-10 11:41:03 +01:00
Michal Koutný edd84b8e4b meson: Copy files with git only in true git repository
When mkosi is run from git-worktree(1), the .git is not a repository
directory but a textfile pointing to the real git dir
(e.g. /home/user/systemd/.git/worktrees/systemd-worktree). This git dir
is not bind mounted into build environment and it fails with:

> fatal: not a git repository: /home/user/systemd/.git/worktrees/systemd-worktree
> test/meson.build:190:16: ERROR: Command `/usr/bin/env -u GIT_WORK_TREE /usr/bin/git --git-dir=/root/src/.git ls-files ':/test/dmidecode-dumps/*.bin'` failed with status 128.

There is already a fallback to use shell globbing instead of ls-files,
use it with git worktrees as well.
2023-03-02 15:04:40 +00:00
Zbigniew Jędrzejewski-Szmek 50f2c32cd5 tests: add a simple test that bootctl output is valid json
python's json.tool module is used because it does validation. jq is more forgiving.
Also, json is in the stdlib, so it should be always available.
2022-12-01 18:01:00 +01:00
Andrew Stone 01532c2d16 test: Move testsuite-03 units to .units directory 2022-08-25 16:32:31 -07:00
Zbigniew Jędrzejewski-Szmek 4e8295f42d test-compare-versions: basic test for systemd-analyze compare-versions 2022-05-19 11:07:28 +02:00
Eli Schwartz ac3eda3489 meson: use better shellscript argument passing
Passing potentially arbitrary data into a shellscript is potentially
very broken if you do not correctly quote it for use. This quoting must
be done as part of the interpretation of the data itself, e.g. python's
shlex.quote; simply formatting it into a string with double quotes is
NOT sufficient.

An alternative is to communicate the data reliably via argv to the shell
process, and allow the shell to internally handle it via `"$1"`, which
is quote-safe and will expand the data from argv as a single tokenized
word.
2022-05-16 03:04:16 +09:00
Jan Janssen 14056a52c6 meson: Use meson test suite feature
This makes it easier to only test a subset of tests without having
to specify them all on the command line:
    meson test -C build --suite headers
2022-05-04 16:11:34 +02:00
Zbigniew Jędrzejewski-Szmek 50c5f5a3d9 test: add test for systemctl link & enable
This test has overlap with test-install-root, but it tests things at a
different level, so I think it's useful to add. It immediately shows various
bugs which will be fixed in later patches.
2022-03-29 16:17:56 +02:00
Frantisek Sumsal 55c09511e1 test: check systemd RPM macros
Make sure our RPM macros work as intended. Based on the original PR
(#16464) by Mikhail Novosyolov.

Co-authored-by: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
2022-03-06 13:07:20 +09:00
Daan De Meyer e93ada9821 meson: Add missing test dependencies
Currently, running "meson build" followed by "meson test -C build"
will result in many failed tests due to missing dependencies. This
commit adds the missing dependencies to make sure no tests fail.
2022-01-22 01:56:03 +09:00
Jan Janssen 3a469802f4 meson: Use echo to list files
No need to invoke ls when we are just interested in file names.
Also, the cd to source root makes the output identical to
"git ls-files" (relative instead of absolute paths).
2022-01-11 14:56:33 +01:00
Jan Janssen 68a06b3cdf meson: Add check argument to remaining run_command() calls 2022-01-11 14:56:30 +01:00
Yu Watanabe 8cc8a073a8 test: add test cases for fstab-generator 2022-01-07 00:58:50 +09:00
Yu Watanabe b322e683ac meson: install test-network-generator-conversion.sh even if networkd is not enabled
Follow-up for 987dd89c77.
2022-01-06 20:14:39 +09:00
Jan Janssen db7f5ab68f test: Add BCD unit test 2021-12-11 21:32:29 +01:00
Luca Boccassi 082c676165 meson: exclude .gitattributes when using install_subdir
It picks the whole content of the directory by default, but we don't
want to install .gitattributes files. Add it to all invocations, not
just the ones on subdirs with .gitattributes, so that we don't regress
in the future.

Fixes #21715
2021-12-10 07:30:58 +01:00
Franck Bui be0cc2ce6c test-keymap-util: always use kbd-model-map we ship
This test makes assumptions on the availability of some mappings contained in
kbd-model-map and therefore strongly relies on the version shipped by
upstream. IOW the test is likely to fail if it's installed on a system with a
more comprehensive kbd-model-map.

This patch makes the upstream kbd-model-map file available via a symlink in
test/testdata/test-keymap-util dir and makes sure that this specific version is
always used by test-keymap-util regardless of whether the test is installed and
run on a different system or directly run (optionally via meson) from the
project working dir.
2021-11-02 16:48:55 +01:00
Frantisek Sumsal 140557021a test: don't install test-network-generator-conversion.sh w/o networkd
otherwise TEST-02 will fail:

```
=== Failed test log ===
--- test-network-generator-conversion.sh begin ---
+ [[ -n '' ]]
+ [[ -x /usr/lib/systemd/systemd-network-generator ]]
+ [[ -x /lib/systemd/systemd-network-generator ]]
+ exit 1
--- test-network-generator-conversion.sh end ---
```

Before:
```
$ meson build -Dnetworkd=false -Dinstall-tests=true
$ ninja -C build
$ DESTDIR=$PWD/test-install ninja -C build install
$ find test-install/ -name test-network-generator-conversion.sh
test-install/usr/lib/systemd/tests/test-network-generator-conversion.sh
```

After:
```
$ find test-install/ -name test-network-generator-conversion.sh
<no output>
```
2021-10-20 22:04:45 +01:00
Daan De Meyer 9727f2427f core: Check unit start rate limiting earlier
Fixes #17433. Currently, if any of the validations we do before we
check start rate limiting fail, we can still enter a busy loop as
no rate limiting gets applied. A common occurence of this scenario
is path units triggering a service that fails a condition check.

To fix the issue, we simply move up start rate limiting checks to
be the first thing we do when starting a unit. To achieve this,
we add a new method to the unit vtable and implement it for the
relevant unit types so that we can do the start rate limit checks
earlier on.
2021-08-25 13:26:14 +01:00
Zbigniew Jędrzejewski-Szmek fce9abb227 meson: use a/b instead of join_paths(a,b)
It is nicer and shorter.
2021-07-27 19:32:35 +02:00
Zbigniew Jędrzejewski-Szmek 0b5f1bd49e meson: use maps for udev program paths 2021-07-27 18:58:42 +02:00
Zbigniew Jędrzejewski-Szmek 097c072d83 meson: use conf configuration_data object to generate test-sysusers.sh
I wanted to use jinja2 templating here too, but it's hard to get right:
custom_target() strips the executable bit by default (unlike configure_file
apparently). custom_target() has install_mode setting, but it was only added
in meson-0.47, so it can't be used while we support 0.46. And without the
executable bit the test is not invoked properly. For example, "root-unittests"
in the debian package calls test-* after installation, so the executable bit
there is necessary. It would be possible to adjust the file mode after the
fact, but it would make things more complicated.

So let's use the native meson substitutions here. We don't need anything more
fancy.
2021-05-19 10:24:43 +09:00
Zbigniew Jędrzejewski-Szmek 0f4c4f3824 meson: call find_program() once and reuse the variable everywhere
Meson 0.58 has gotten quite bad with emitting a message every time
a quoted command is used:
Program /home/zbyszek/src/systemd-work/tools/meson-make-symlink.sh found: YES (/home/zbyszek/src/systemd-work/tools/meson-make-symlink.sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program xsltproc found: YES (/usr/bin/xsltproc)
Configuring custom-entities.ent using configuration
Message: Skipping bootctl.1 because ENABLE_EFI is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Message: Skipping journal-remote.conf.5 because HAVE_MICROHTTPD is false
Message: Skipping journal-upload.conf.5 because HAVE_MICROHTTPD is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Message: Skipping loader.conf.5 because ENABLE_EFI is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
...

Let's suffer one message only for each command. Hopefully we can silence
even this when https://github.com/mesonbuild/meson/issues/8642 is
resolved.
2021-05-14 14:21:27 +02:00
Zbigniew Jędrzejewski-Szmek ecd1bfdd3c hwdb-test: pass an explit path to systemd-hwdb
https://github.com/systemd/systemd/pull/19316 failed with:
[1065/1670] Linking target systemd-hwdb
--- command ---
14:28:29 /root/src/test/hwdb-test.sh
--- stdout ---
./systemd-hwdb does not exist, please build first

I'm not sure what is going on here… In principle meson says that tests may be
called from any directory, but in practice is was always the build directory.
So far we were relying on systemd-hwdb being present in '.', and this worked.
Either way, it's nicer to pass the exact path, so let's do that.
2021-04-28 11:32:58 +02:00
Yu Watanabe a79e17234d meson.build: drop unused variable 2021-01-19 07:04:19 +09:00
Yu Watanabe 0703d2f6c4 test: move test-systemd-tmpfiles.py from src/test to test
As the other test scripts, e.g. test-sysusers.sh, are located under
test rather than src/test.
2021-01-19 07:04:19 +09:00
Zbigniew Jędrzejewski-Szmek a412ec5714 meson: fix git ls-files invocations during rebase
Normally ls-files prints the full path to files from the repo root. But when
$GIT_WORK_TREE is set, ls-files prints paths relative to the current
directory. When rebasing, $GIT_WORK_TREE is set in the commands executed from
'rebase -x'. This causes problems if meson config is touched and the meson
reconfigures itself. ($GIT_WORK_TREE shouldn't be relevant, since the paths that
ls-files reports don't depend on the work tree, but whatever.) Let's unset
GIT_WORK_TREE to avoid the issue.

$ (cd test; git --git-dir=$PWD/../.git ls-files ':/test/dmidecode-dumps/*.bin')
test/dmidecode-dumps/HP-Z600.bin
test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin
test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin

$ (cd test; GIT_WORK_TREE=$PWD/.. git --git-dir=$PWD/../.git ls-files ':/test/dmidecode-dumps/*.bin')
dmidecode-dumps/HP-Z600.bin
dmidecode-dumps/Lenovo-ThinkPad-X280.bin
dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin

Fixes #18148.
2021-01-09 09:22:26 +09:00
Zbigniew Jędrzejewski-Szmek 2b7b142e97 meson: make each dmidecode a separate test
This allows them to be executed in parallel and also gives us
better reporting.

The dump files are renamed to avoid repeating "dmidecode-dump", since that
string is already present in the subdirectory name.
2020-12-17 09:21:29 +01:00
Bastien Nocera 2bfb92a978 meson: Disable dmi_memory_id on arches without DMI 2020-12-16 19:21:19 +01:00
Bastien Nocera 4dd465cb4e udev: Extract RAM properties from DMI information
Add memory_id program to set properties about the physical memory
devices in the system. This is useful on machines with removable memory
modules to show how the machine can be upgraded, and on all devices to
detect the actual RAM size, without relying on the OS accessible amount.

Closes: #16651
2020-12-16 18:32:29 +01:00
Lennart Poettering 6dd16814a5
Merge pull request #17079 from keszybz/late-exec-resolution
Resolve executable paths before execution, use fexecve()
2020-12-03 14:58:20 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek a6d9111c67 core/execute: fall back to execve() for scripts
fexecve() fails with ENOENT and we need a fallback. Add appropriate test.
2020-11-06 15:14:13 +01:00
Zbigniew Jędrzejewski-Szmek bd7e6aa73a test/TEST-21-SYSUSERS: turn into a unit test
All this test does is manipulate text files in a subdir specified with --testroot.
It can be a normal unittest without the overhead of creating a machine image.

As a bonus, also test the .standalone version.
2020-10-01 17:52:51 +02:00
Zbigniew Jędrzejewski-Szmek a18c7865be meson: do not install testdata when -Dinstall-tests=false
Fixes #16447.
2020-07-14 14:57:04 +02:00
Jay Burger a1ba8c5b71 feature to honor first shutdown request to completion
Create unit tests per established norm at position 52

check in_set first before getting unit
2020-06-24 09:42:01 +02:00
Zbigniew Jędrzejewski-Szmek fbaa11372b test: convert TEST-35-NETWORK-GENERATOR into a unit test 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 94370e627f test: move TEST-28-PERCENTJ-WANTEDBY setup to static files 2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 2b5981b40a test: move TEST-16-EXTEND-TIMEOUT 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 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 c84752398b test: move TEST-08-ISSUE-2730 setup to static files and meson scripts
Unfortunately meson does not install symlinks, but copies the symlink
destination instead. So symlinks need to be created by a script.
This commit adds both symlinks in test/testsuite-08.units/ and meson
scriptlet calls. Strictly speaking, the first is not necessary, since nothing
reads stuff directly from the source tree.
2020-03-28 11:46:47 +01:00
Zbigniew Jędrzejewski-Szmek 1ed5556e56 test: move most of TEST-06-* setup to static files 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 80769cb66c meson: use install_subdir() to install files
This gives us slightly less control, but we don't need to update the
file list...
2020-03-22 10:22:42 +01:00
Zbigniew Jędrzejewski-Szmek 7b43295346 tests: move unit files to units/ subdirectory
We have a bazillion of those unit files, and keeping them all directly in tests/
has become rather unwieldy.
2020-03-19 16:23:27 +01:00
Nate Jones ecf63c9102 execute: Make '+' exec prefix ignore PrivateTmp=yes
The man pages state that the '+' prefix in Exec* directives should
ignore filesystem namespacing options such as PrivateTmp. Now it does.

This is very similar to #8842, just with PrivateTmp instead of
PrivateDevices.
2020-02-29 19:32:01 +09:00
Lennart Poettering e56a8790a0 test: add test for https://github.com/systemd/systemd/issues/14560 2020-01-20 17:19:51 +01:00
Anita Zhang b6657e2c53 test: add test case for PrivateDevices=y and Group=daemon
For root, group enforcement needs to come after PrivateDevices=y set up
according to 096424d123. Add a test to
verify this is the case.
2019-12-18 11:09:30 -08:00
Kevin Kuehler 07cab0f72b tests: Add capability tests for ProtectKernelLogs 2019-11-11 12:12:02 -08:00
Zbigniew Jędrzejewski-Szmek 4f10b80786 Rename udev's hwdb/ to hwdb.d/
As in the parent commit, this makes the name consistent with the
rest of the source tree and the actuall installation path.
2019-10-10 00:53:09 +01:00
Anita Zhang 31cd5f63ce core: ExecCondition= for services
Closes #10596
2019-07-17 11:35:02 +02:00
Michal Koutný 594057fd99 tests: Check trivial loop between two jobs
job_compare return value is undefined in case the jobs have a loop
between them, so better make a test to make sure transaction cycle
detection catches it.
2019-06-26 23:16:31 +02:00
Michal Koutný 804cdabc31 tests: Check job ordering on execution cycles
The test-engine Test2 tests the cycle detection when units a, b and d
all start at once

    ,-------------------after-----------------,
    v                                         |
    a/start ---after---> d/start ---after---> b/start

Extend the test with Test11 that adds i.service which causes a and d
stop (by unordered Conflicts=) while starting b. Because stops precede
starts, we effectively eliminate the job cycle and all transaction jobs
should be applicable.

    ,-------------------after-----------------,
    v                                         |
    a/stop <---after--- d/stop <---after--- b/start
    .                   .                     ^
    .                   .                     |
     '. . . . . . . . . i/start ---after------'
2019-06-26 23:16:31 +02:00
Chris Down c52db42b78 cgroup: Implement default propagation of MemoryLow with DefaultMemoryLow
In cgroup v2 we have protection tunables -- currently MemoryLow and
MemoryMin (there will be more in future for other resources, too). The
design of these protection tunables requires not only intermediate
cgroups to propagate protections, but also the units at the leaf of that
resource's operation to accept it (by setting MemoryLow or MemoryMin).

This makes sense from an low-level API design perspective, but it's a
good idea to also have a higher-level abstraction that can, by default,
propagate these resources to children recursively. In this patch, this
happens by having descendants set memory.low to N if their ancestor has
DefaultMemoryLow=N -- assuming they don't set a separate MemoryLow
value.

Any affected unit can opt out of this propagation by manually setting
`MemoryLow` to some value in its unit configuration. A unit can also
stop further propagation by setting `DefaultMemoryLow=` with no
argument. This removes further propagation in the subtree, but has no
effect on the unit itself (for that, use `MemoryLow=0`).

Our use case in production is simplifying the configuration of machines
which heavily rely on memory protection tunables, but currently require
tweaking a huge number of unit files to make that a reality. This
directive makes that significantly less fragile, and decreases the risk
of misconfiguration.

After this patch is merged, I will implement DefaultMemoryMin= using the
same principles.
2019-04-12 17:23:58 +02:00
Zbigniew Jędrzejewski-Szmek 054d871d41 test-execute: block /sys not /proc
As explained in the previous commit, blocking /proc can cause us
to go into a long loop or fail the test.
2019-03-15 15:46:41 +01:00
Yu Watanabe 7e46b29bd3 test: add a testcase for ProtectHome=tmpfs vs ProtectSystem=strict 2019-03-13 11:53:59 +09:00
Anita Zhang 7ca69792e5 core: add ':' prefix to ExecXYZ= skip env var substitution 2019-02-20 17:58:14 +01:00
Frantisek Sumsal bb0e960448 meson: bump timeout for test-udev to 180s
On some (mainly virtual) machines the last test takes more than 30
seconds, which causes unnecessary fails, as the test itself is working
properly.
2019-01-21 11:33:54 +01:00
Chris Down c72703e26d cgroup: Add DisableControllers= directive to disable controller in subtree
Some controllers (like the CPU controller) have a performance cost that
is non-trivial on certain workloads. While this can be mitigated and
improved to an extent, there will for some controllers always be some
overheads associated with the benefits gained from the controller.
Inside Facebook, the fix applied has been to disable the CPU controller
forcibly with `cgroup_disable=cpu` on the kernel command line.

This presents a problem: to disable or reenable the controller, a reboot
is required, but this is quite cumbersome and slow to do for many
thousands of machines, especially machines where disabling/enabling a
stateful service on a machine is a matter of several minutes.

Currently systemd provides some configuration knobs for these in the
form of `[Default]CPUAccounting`, `[Default]MemoryAccounting`, and the
like. The limitation of these is that Default*Accounting is overrideable
by individual services, of which any one could decide to reenable a
controller within the hierarchy at any point just by using a controller
feature implicitly (eg. `CPUWeight`), even if the use of that CPU
feature could just be opportunistic. Since many services are provided by
the distribution, or by upstream teams at a particular organisation,
it's not a sustainable solution to simply try to find and remove
offending directives from these units.

This commit presents a more direct solution -- a DisableControllers=
directive that forcibly disallows a controller from being enabled within
a subtree.
2018-12-03 15:40:31 +00:00
Lennart Poettering ad191df836
Merge pull request #10134 from keszybz/test-runner
Some test-related fixed and a test runner for installed tests
2018-10-05 20:35:30 +02:00
Yu Watanabe e913b7988f
test-execute: add a test for systemcall filter (#10273)
This adds a test for issue #9939 which is fixed by
a5404992cc (#9942).
2018-10-05 14:46:30 +09:00
Zbigniew Jędrzejewski-Szmek c74a3f973e fuzz: unify the "fuzz-regressions" directory with the main corpus
There isn't really much need to keep them separate. Anything which is a good
corpus entry can be used as a smoke test, and anything which which is a
regression test can just as well be inserted into the corpus.

The only functional difference from this patch (apart from different paths in
output) is that the regression tests are now zipped together with the rest of
the corpus.

$ meson configure build -Dslow-tests=true && ninja -C build test
...
307/325 fuzz-dns-packet:issue-7888:address      OK       0.06 s
308/325 fuzz-dns-packet:oss-fuzz-5465:address   OK       0.04 s
309/325 fuzz-journal-remote:crash-5a8f03d4c3a46fcded39527084f437e8e4b54b76:address  OK       0.07 s
310/325 fuzz-journal-remote:crash-96dee870ea66d03e89ac321eee28ea63a9b9aa45:address  OK       0.05 s
311/325 fuzz-journal-remote:oss-fuzz-8659:address  OK       0.05 s
312/325 fuzz-journal-remote:oss-fuzz-8686:address  OK       0.07 s
313/325 fuzz-unit-file:oss-fuzz-6884:address    OK       0.06 s
314/325 fuzz-unit-file:oss-fuzz-6885:address    OK       0.05 s
315/325 fuzz-unit-file:oss-fuzz-6886:address    OK       0.05 s
316/325 fuzz-unit-file:oss-fuzz-6892:address    OK       0.05 s
317/325 fuzz-unit-file:oss-fuzz-6897:address    OK       0.05 s
318/325 fuzz-unit-file:oss-fuzz-6897-evverx:address  OK       0.06 s
319/325 fuzz-unit-file:oss-fuzz-6908:address    OK       0.07 s
320/325 fuzz-unit-file:oss-fuzz-6917:address    OK       0.07 s
321/325 fuzz-unit-file:oss-fuzz-6977:address    OK       0.13 s
322/325 fuzz-unit-file:oss-fuzz-6977-unminimized:address  OK       0.12 s
323/325 fuzz-unit-file:oss-fuzz-7004:address    OK       0.05 s
324/325 fuzz-unit-file:oss-fuzz-8064:address    OK       0.05 s
325/325 fuzz-unit-file:oss-fuzz-8827:address    OK       0.52 s
2018-10-02 09:41:25 +02:00
Zbigniew Jędrzejewski-Szmek 3762f8e316 tests: add a runner for installed tests
We have "installed tests", but don't provide an easy way to run them.

The protocol is very simple: each test must return 0 for success, 77 means
"skipped", anything else is an error. In addition, we want to print test
output only if the test failed.

I wrote this simple script. It is pretty basic, but implements the functions
listed above. Since it is written in python it should be easy to add option
parsing (like running only specific tests, or running unsafe tests, etc.)

I looked at the following alternatives:
- Ubuntu root-unittests: this works, but just dumps all output to the terminal,
  has no coloring.
- @ssahani's test runner [2]
  It uses the unittest library and the test suite was implented as a class, and
  doesn't implement any of the functions listed above.
- cram [3,4]
  cram runs our tests, but does not understand the "ignore the output" part,
  has not support for our magic skip code (it uses hardcoded 80 instead),
  and seems dead upstream.
- meson test
  Here the idea would be to provide an almost-empty meson.build file under
  /usr/lib/systemd/tests/ that would just define all the tests. This would
  allow us to reuse the test runner we use normally. Unfortunately meson requires
  a build directory and configuration to be done before running tests. This
  would be possible, but seems a lot of effort to just run a few binaries.

[1] 242c96addb/debian/tests/root-unittests
[2] https://github.com/systemd/systemd-fedora-ci/blob/master/upstream/systemd-upstream-tests.py
[3] https://bitheap.org/cram/
[4] https://pypi.org/project/pytest-cram/

Fixes #10069.
2018-09-24 15:42:50 +02:00
Yu Watanabe fd1939fbe7 meson: do not build tests by default when '-Dtests=false'
[zj: it is still possible to build tests explicitly by calling
     ninja -C build test-name. This way we have full flexibility.]
2018-09-13 12:07:34 +02:00
Zbigniew Jędrzejewski-Szmek 938be08926 meson: disable _all_ tests when -Dtests=false
Back in 08318a2c5a, value "false" was enabled for
'-Dtests=', but various tests were not conditionalized properly. So even with
-Dtests=false -Dslow-tests=false we'd run 120 tests. Let's make this consistent.
2018-09-13 12:07:34 +02:00
Yu Watanabe 9f82d685f3 test: add tests for DynamicUser= with static User= whose UID and GID are different 2018-07-26 16:32:10 +09:00
Zsolt Dollenstein 566b7d23eb Add support for opening files for appending
Addresses part of #8983
2018-07-20 03:54:22 -07:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Yu Watanabe 2b633119a0 test: add test for trailing dot in WorkingDirectory= and RuntimeDirectory= 2018-06-03 23:59:51 +09:00
Yu Watanabe 1dcf96c29f test: add tests for merging RestrictNamespaces= 2018-05-05 11:07:37 +09:00
Yu Watanabe cfa24ca0e6 test: add tests for PrivateDevices= with '+' prefix 2018-05-01 13:44:24 +09:00
Lennart Poettering 2cb36f7c1e
Merge pull request #8575 from keszybz/non-absolute-paths
Do not require absolute paths in ExecStart and friends
2018-04-17 15:54:10 +02:00
Zbigniew Jędrzejewski-Szmek 5008da1ec1 systemd: do not require absolute paths in ExecStart
Absolute paths make everything simple and quick, but sometimes this requirement
can be annoying. A good example is calling 'test', which will be located in
/usr/bin/ or /bin depending on the distro. The need the provide the full path
makes it harder a portable unit file in such cases.

This patch uses a fixed search path (DEFAULT_PATH which was already used as the
default value of $PATH), and if a non-absolute file name is found, it is
immediately resolved to a full path using this search path when the unit is
loaded. After that, everything behaves as if an absolute path was specified. In
particular, the executable must exist when the unit is loaded.
2018-04-16 16:09:46 +02:00
Lennart Poettering 7ce49e656b test: add test for prefix unit loading 2018-04-13 11:34:48 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Zbigniew Jędrzejewski-Szmek b1ffacb631 tests: skip udev-test when perl is not installed 2018-03-22 15:57:56 +01:00
Zbigniew Jędrzejewski-Szmek 1fd8edb53a test-umount: add a simple test for swap_list_get()
The implementation seems buggy:
/* test_swap_list("/home/zbyszek/src/systemd/test/test-umount/example.swaps") */
path=0 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile2 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
2018-03-16 10:12:50 +01:00