diff options
Diffstat (limited to 'src/user/tests')
-rw-r--r-- | src/user/tests/main.c | 28 | ||||
-rw-r--r-- | src/user/tests/pipe.c | 34 | ||||
-rw-r--r-- | src/user/tests/semaphore.c | 8 | ||||
-rw-r--r-- | src/user/tests/stress.c | 4 |
4 files changed, 37 insertions, 37 deletions
diff --git a/src/user/tests/main.c b/src/user/tests/main.c index fd5ffca..5bfd3aa 100644 --- a/src/user/tests/main.c +++ b/src/user/tests/main.c @@ -5,7 +5,7 @@ #include <shared/syscalls.h> static void run_forked(void (*fn)()) { - if (!_syscall_fork(0, NULL)) { + if (!fork()) { fn(); _syscall_exit(0); } else { @@ -24,7 +24,7 @@ static void test_await(void) { int counts[16] = {0}; for (int i = 0; i < 16; i++) - if (!_syscall_fork(0, NULL)) + if (!fork()) _syscall_exit(i); while ((ret = _syscall_await()) != ~0) { @@ -42,12 +42,12 @@ static void test_faults(void) { * reap all its children */ int await_cnt = 0; - if (!_syscall_fork(0, NULL)) { // invalid memory access + if (!fork()) { // invalid memory access asm volatile("movb $69, 0" ::: "memory"); printf("this shouldn't happen"); _syscall_exit(-1); } - if (!_syscall_fork(0, NULL)) { // #GP + if (!fork()) { // #GP asm volatile("hlt" ::: "memory"); printf("this shouldn't happen"); _syscall_exit(-1); @@ -90,7 +90,7 @@ static void test_memflag(void) { memset(page, 77, 4096); // write to it _syscall_memflag(page, 4096, 0); // free it - if (!_syscall_fork(0, NULL)) { + if (!fork()) { memset(page, 11, 4096); // should segfault _syscall_exit(0); } else { @@ -118,8 +118,8 @@ static void test_dup(void) { handle_t h1, h2; assert(_syscall_pipe(pipe, 0) >= 0); - if (!_syscall_fork(0, NULL)) { - _syscall_close(pipe[0]); + if (!fork()) { + close(pipe[0]); h1 = _syscall_dup(pipe[1], -1, 0); assert(h1 >= 0); @@ -132,7 +132,7 @@ static void test_dup(void) { _syscall_write(h1, "h1", 2, 0); _syscall_write(h2, "h2", 2, 0); - _syscall_close(pipe[1]); + close(pipe[1]); _syscall_write(h1, "h1", 2, 0); _syscall_write(h2, "h2", 2, 0); @@ -140,22 +140,22 @@ static void test_dup(void) { assert(_syscall_dup(h2, pipe[1], 0) == pipe[1]); assert(_syscall_dup(h1, pipe[1], 0) == pipe[1]); assert(_syscall_dup(h2, pipe[1], 0) == pipe[1]); - _syscall_close(h1); - _syscall_close(h2); + close(h1); + close(h2); assert(_syscall_dup(pipe[1], h2, 0) == h2); _syscall_write(h2, "h2", 2, 0); - _syscall_close(h2); + close(h2); assert(_syscall_dup(pipe[1], h1, 0) == h1); _syscall_write(h1, "h1", 2, 0); - _syscall_close(h1); + close(h1); _syscall_exit(0); } else { char buf[16]; size_t count = 0; - _syscall_close(pipe[1]); + close(pipe[1]); while (_syscall_read(pipe[0], buf, sizeof buf, 0) >= 0) count++; assert(count == 7); @@ -163,7 +163,7 @@ static void test_dup(void) { } - _syscall_close(pipe[0]); + close(pipe[0]); } static void test_malloc(void) { 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 diff --git a/src/user/tests/semaphore.c b/src/user/tests/semaphore.c index e5aacaa..836edf5 100644 --- a/src/user/tests/semaphore.c +++ b/src/user/tests/semaphore.c @@ -37,11 +37,11 @@ void test_semaphore(void) { handle_t pipe[2]; assert(_syscall_pipe(pipe, 0) >= 0); - if (!_syscall_fork(0, NULL)) { + if (!fork()) { sem1 = esem_new(0); sem2 = esem_new(0); assert(sem1 && sem2); - if (!_syscall_fork(0, NULL)) { + if (!fork()) { odd(pipe[1], sem1, sem2); _syscall_exit(69); } else { @@ -56,7 +56,7 @@ void test_semaphore(void) { sem1 = esem_new(0); sem2 = esem_new(0); assert(sem1 && sem2); - if (!_syscall_fork(0, NULL)) { + if (!fork()) { even(pipe[1], sem1, sem2); _syscall_exit(69); } else { @@ -69,7 +69,7 @@ void test_semaphore(void) { _syscall_exit(0); } else { - _syscall_close(pipe[1]); + close(pipe[1]); char buf[16]; size_t pos = 0; diff --git a/src/user/tests/stress.c b/src/user/tests/stress.c index 51b9c4e..5d29e87 100644 --- a/src/user/tests/stress.c +++ b/src/user/tests/stress.c @@ -5,7 +5,7 @@ #include <shared/syscalls.h> static void run_forked(void (*fn)()) { - if (!_syscall_fork(0, NULL)) { + if (!fork()) { fn(); _syscall_exit(0); } else { @@ -18,7 +18,7 @@ static void run_forked(void (*fn)()) { static void stress_fork(void) { for (size_t i = 0; i < 2048; i++) { - if (!_syscall_fork(0, NULL)) _syscall_exit(0); + if (!fork()) _syscall_exit(0); _syscall_await(); } } |