diff options
author | dzwdz | 2022-07-09 20:47:13 +0200 |
---|---|---|
committer | dzwdz | 2022-07-09 20:47:13 +0200 |
commit | fff36661c92f30685e2d83825a11b67ad8921a0e (patch) | |
tree | 7711025c8ad988e48a5925c546151e6c1cfa96fe /src/init | |
parent | fcfb57c12ce4544017098092a66f8427584c1879 (diff) |
kernel/pipes: process queueing
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/tests/pipe.c | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/src/init/tests/pipe.c b/src/init/tests/pipe.c index e03c485..a980cb8 100644 --- a/src/init/tests/pipe.c +++ b/src/init/tests/pipe.c @@ -51,28 +51,68 @@ void test_pipe(void) { /* writing to pipes with one end closed */ assert(_syscall_pipe(ends, 0) >= 0); - if (!_syscall_fork(0, NULL)) { - _syscall_close(ends[1]); - assert(_syscall_read(ends[0], buf, 16, 0) < 0); - _syscall_exit(0); - } else { - _syscall_close(ends[1]); + for (int i = 0; i < 16; i++) { + if (!_syscall_fork(0, NULL)) { + _syscall_close(ends[1]); + assert(_syscall_read(ends[0], buf, 16, 0) < 0); + _syscall_exit(0); + } + } + _syscall_close(ends[1]); + for (int i = 0; i < 16; i++) _syscall_await(); + _syscall_close(ends[0]); + + assert(_syscall_pipe(ends, 0) >= 0); + for (int i = 0; i < 16; i++) { + if (!_syscall_fork(0, NULL)) { + _syscall_close(ends[0]); + assert(_syscall_write(ends[1], buf, 16, 0) < 0); + _syscall_exit(0); + } } + _syscall_close(ends[0]); + for (int i = 0; i < 16; i++) + _syscall_await(); + _syscall_close(ends[1]); + + /* queueing */ assert(_syscall_pipe(ends, 0) >= 0); - if (!_syscall_fork(0, NULL)) { - _syscall_close(ends[0]); - assert(_syscall_write(ends[1], buf, 16, 0) < 0); - _syscall_exit(0); - } else { - _syscall_close(ends[0]); + for (int i = 0; i < 16; i++) { + if (!_syscall_fork(0, NULL)) { + assert(_syscall_write(ends[1], pipe_msgs[0], 5, -1) == 5); + _syscall_exit(0); + } + } + _syscall_close(ends[1]); + for (int i = 0; i < 16; i++) { + assert(_syscall_read(ends[0], buf, sizeof buf, 0) == 5); _syscall_await(); } + assert(_syscall_read(ends[0], buf, sizeof buf, 0) < 0); + _syscall_close(ends[0]); + + assert(_syscall_pipe(ends, 0) >= 0); + for (int i = 0; i < 16; i++) { + if (!_syscall_fork(0, NULL)) { + memset(buf, 0, sizeof buf); + assert(_syscall_read(ends[0], buf, 5, -1) == 5); + assert(!memcmp(buf, pipe_msgs[1], 5)); + _syscall_exit(0); + } + } + _syscall_close(ends[0]); + for (int i = 0; i < 16; i++) { + assert(_syscall_write(ends[1], pipe_msgs[1], 5, -1) == 5); + _syscall_await(); + } + assert(_syscall_write(ends[1], pipe_msgs[1], 5, -1) < 0); + _syscall_close(ends[1]); + // not a to.do detect when all processes that can read are stuck on writing to the pipe and vice versa // it seems like linux just lets the process hang endlessly. // TODO kill process that's waiting on a pipe - // TODO queue } |