diff options
| author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2021-06-07 11:53:46 +0100 |
|---|---|---|
| committer | Alexander Richardson <alexander.richardson@cl.cam.ac.uk> | 2021-09-10 11:35:54 +0000 |
| commit | 42bf011f65a1aa5b7dcb664026b02c48170d07a5 (patch) | |
| tree | 3d9efc65a41edf8e16f9e785e34c4e6be7a6fa0b /tests | |
| parent | test-runner: Implement is_debugger_attached() for FreeBSD (diff) | |
| download | wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar.gz wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar.bz2 wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar.lz wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar.xz wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.tar.zst wayland-42bf011f65a1aa5b7dcb664026b02c48170d07a5.zip | |
test-helpers: use sysctl() to count open fds on FreeBSD
This allows running the tests on FreeBSD without mounting fdescfs.
Previously you had to run `mount -t fdescfs -o linrdlnk null /dev/fd` to
get file descriptors >=3 listed in /dev/fd.
Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-helpers.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test-helpers.c b/tests/test-helpers.c index 4cdd1fc..3535744 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -41,6 +41,27 @@ #include "test-runner.h" +#if defined(__FreeBSD__) +#include <sys/sysctl.h> + +/* + * On FreeBSD, get file descriptor information using sysctl() since that does + * not depend on a mounted fdescfs (which provides /dev/fd/N for N > 2). + */ +int +count_open_fds(void) +{ + int error; + int nfds; + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_NFDS, 0 }; + size_t len; + + len = sizeof(nfds); + error = sysctl(mib, 4, &nfds, &len, NULL, 0); + assert(error == 0 && "sysctl KERN_PROC_NFDS failed."); + return nfds; +} +#else int count_open_fds(void) { @@ -68,6 +89,7 @@ count_open_fds(void) return count; } +#endif void exec_fd_leak_check(int nr_expected_fds) |
