diff options
author | dzwdz | 2022-10-08 16:05:37 +0200 |
---|---|---|
committer | dzwdz | 2022-10-08 16:07:04 +0200 |
commit | f25b6a7d38f1a4b656e3a7ad431afcf535f1fdce (patch) | |
tree | 83199e9a70cc903ce46d0f30cc1a74ccfc6e729b /src/user/app/tests/kernel/fdlimit.c | |
parent | e83dca9817614d0dc77ce1e5dc13eed44b61eb2f (diff) |
tests: some tests for when a process has no free handles
Diffstat (limited to 'src/user/app/tests/kernel/fdlimit.c')
-rw-r--r-- | src/user/app/tests/kernel/fdlimit.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/user/app/tests/kernel/fdlimit.c b/src/user/app/tests/kernel/fdlimit.c new file mode 100644 index 0000000..d22af13 --- /dev/null +++ b/src/user/app/tests/kernel/fdlimit.c @@ -0,0 +1,49 @@ +#include "../tests.h" +#include <camellia/flags.h> +#include <errno.h> +#include <unistd.h> + +static void test_fdlimit_pipe(void) { + handle_t ends[2]; + handle_t h[2] = {-1, -1}; + for (;;) { + handle_t cur = _syscall_open("/", 1, OPEN_READ); + if (cur == -EMFILE) break; + test(cur >= 0); + h[0] = h[1]; + h[1] = cur; + } + test(h[0] >= 0); /* we need at least two handles */ + + test(_syscall_pipe(ends, 0) == -EMFILE); + test(_syscall_open("/", 1, OPEN_READ) == -EMFILE); + + close(h[1]); + test(_syscall_pipe(ends, 0) == -EMFILE); + test(_syscall_open("/", 1, OPEN_READ) == h[1]); + test(_syscall_open("/", 1, OPEN_READ) == -EMFILE); + + close(h[0]); + close(h[1]); + test(_syscall_pipe(ends, 0) == 0); +} + +static void test_fdlimit_fork(void) { + for (;;) { + handle_t cur = _syscall_open("/", 1, OPEN_READ); + if (cur == -EMFILE) break; + test(cur >= 0); + } + + if (!_syscall_fork(0, NULL)) _syscall_exit(123); + + test(_syscall_fork(FORK_NEWFS, NULL) == -EMFILE); + test(_syscall_await() == 123); + test(_syscall_await() == ~0); +} + +void r_k_fdlimit(void) { + /* all these tests implicitly test if the vfs returns -EMFILE */ + run_test(test_fdlimit_pipe); + run_test(test_fdlimit_fork); +} |