]> git.ipfire.org Git - thirdparty/systemd.git/commit
test: rewrite udev-test.pl in Python
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 May 2023 20:40:38 +0000 (22:40 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 9 May 2023 06:11:10 +0000 (08:11 +0200)
commitf2c02d232eeb0c7d53089c586b72620383466e8f
tree09f079e13c08639210d07719c188a41d447f5d04
parent495658d43c72d3a1496c8181bb1fcec84a76d66c
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.
  e62acc3159935781f05fa59c48e5a74e85c61ce2 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.
test/meson.build
test/udev-test.py [new file with mode: 0755]