diff options
Diffstat (limited to 'src/user/tests/pipe.c')
-rw-r--r-- | src/user/tests/pipe.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/user/tests/pipe.c b/src/user/tests/pipe.c index e973993..2e964f9 100644 --- a/src/user/tests/pipe.c +++ b/src/user/tests/pipe.c @@ -13,7 +13,7 @@ void test_pipe(void) { /* test regular reads / writes */ assert(_syscall_pipe(ends, 0) >= 0); - if (!_syscall_fork(0, NULL)) { + if (!fork()) { /* those repeated asserts ensure that you can't read/write to the wrong ends */ assert(_syscall_read(ends[1], buf, 16, 0) < 0); assert(_syscall_write(ends[0], buf, 16, 0) < 0); @@ -45,70 +45,70 @@ void test_pipe(void) { _syscall_await(); } - _syscall_close(ends[0]); - _syscall_close(ends[1]); + close(ends[0]); + close(ends[1]); /* writing to pipes with one end closed */ assert(_syscall_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { - if (!_syscall_fork(0, NULL)) { - _syscall_close(ends[1]); + if (!fork()) { + close(ends[1]); assert(_syscall_read(ends[0], buf, 16, 0) < 0); _syscall_exit(0); } } - _syscall_close(ends[1]); + close(ends[1]); for (int i = 0; i < 16; i++) _syscall_await(); - _syscall_close(ends[0]); + 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]); + if (!fork()) { + close(ends[0]); assert(_syscall_write(ends[1], buf, 16, 0) < 0); _syscall_exit(0); } } - _syscall_close(ends[0]); + close(ends[0]); for (int i = 0; i < 16; i++) _syscall_await(); - _syscall_close(ends[1]); + close(ends[1]); /* queueing */ assert(_syscall_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { - if (!_syscall_fork(0, NULL)) { + if (!fork()) { assert(_syscall_write(ends[1], pipe_msgs[0], 5, -1) == 5); _syscall_exit(0); } } - _syscall_close(ends[1]); + 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]); + close(ends[0]); assert(_syscall_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { - if (!_syscall_fork(0, NULL)) { + if (!fork()) { 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]); + 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]); + close(ends[1]); // not a to.do detect when all processes that can read are stuck on writing to the pipe and vice versa |