opnsense-src/tests/sys/audit
Alex Richardson df093aa946 tests/sys/audit: Avoid race caused by starting auditd(8) for testing
In the CheriBSD CI we reproducibly see the first test in sys/audit
(administrative:acct_failure) fail due to a missing startup message.
It appears this is caused by a race condition when starting auditd:
`service auditd onestart` returns as soon as the initial auditd() parent
exits (after the daemon(3) call).
We can avoid this problem by setting up the auditd infrastructure
in-process: libauditd contains audit_quick_{start,stop}() functions that
look like they are ideally suited to this task.
This patch also avoids forking lots of shell processes for each of the 418
tests by using `auditon(A_SENDTRIGGER, &trigger, sizeof(trigger))` to check
for a running auditd(8) instead of using `service auditd onestatus`.

With these two changes (and D28388 to fix the XFAIL'd test) I can now
boot and run `cd /usr/tests/sys/audit && kyua test` without any failures
in a single-core QEMU instance. Before there would always be at least one
failed test.

Besides making the tests more reliable in CI, a nice side-effect of this
change is that it also significantly speeds up running them by avoiding
lots of fork()/execve() caused by shell scripts:
Running kyua test on an AArch64 QEMU took 315s before and now takes 68s,
so it's roughly 3.5 times faster. This effect is even larger when running
on a CHERI-RISC-V QEMU since emulating CHERI instructions on an x86 host
is noticeably slower than emulating AArch64.

Test Plan: aarch64+amd64 QEMU no longer fail.

Reviewed By:	asomers
Differential Revision: https://reviews.freebsd.org/D28451
2021-02-18 14:02:48 +00:00
..
administrative.c tests/sys/audit: Avoid race caused by starting auditd(8) for testing 2021-02-18 14:02:48 +00:00
file-attribute-access.c tests/sys/audit: Skip extattr tests if extattrs are not supported 2021-02-02 09:55:19 +00:00
file-attribute-modify.c tests/sys/audit: Skip extattr tests if extattrs are not supported 2021-02-02 09:55:19 +00:00
file-close.c tests: audit: mark closefrom test an expected fail for now 2020-04-14 23:36:03 +00:00
file-create.c audit(4): Fix file descriptor leaks in ATF tests 2018-06-13 17:01:57 +00:00
file-delete.c audit(4): Fix file descriptor leaks in ATF tests 2018-06-13 17:01:57 +00:00
file-read.c
file-write.c audit(4): Fix file descriptor leaks in ATF tests 2018-06-13 17:01:57 +00:00
inter-process.c audit(4): add tests for pipe, posix_openpt, shm_open, and shm_unlink 2018-06-26 19:26:07 +00:00
ioctl.c audit(4): add tests for ioctl(2) 2018-06-19 01:32:33 +00:00
Makefile tests/sys/audit: Avoid race caused by starting auditd(8) for testing 2021-02-18 14:02:48 +00:00
miscellaneous.c audit(4): add tests for sysctl(3) and sysarch(2) 2018-07-29 20:34:44 +00:00
network.c Fix audit of chflagsat, lgetfh, and setfib 2018-07-22 14:11:52 +00:00
open.c audit(4): improve formatting in tests/sys/audit/open.c 2018-06-15 15:36:10 +00:00
process-control.c Fix and simplify code by using ATF_REQUIRE_FEATURE macro 2019-04-01 14:21:32 +00:00
utils.c tests/sys/audit: Avoid race caused by starting auditd(8) for testing 2021-02-18 14:02:48 +00:00
utils.h tests/sys/audit: Skip extattr tests if extattrs are not supported 2021-02-02 09:55:19 +00:00