diff options
author | dzwdz | 2023-01-25 20:16:22 +0100 |
---|---|---|
committer | dzwdz | 2023-01-25 20:16:22 +0100 |
commit | 17bfb0ef0a48330b1d54e61fe3c30d83528d2d90 (patch) | |
tree | b3d4aed1f408edcb17fe5c86fccaeacaa2a5a48a /src/user/app/tests/kernel/miscsyscall.c | |
parent | 2ad6ee8ed15d1bf898645a16dbc06991a3c1425e (diff) |
style: typedef structs, shorter namespaces
I've wanted to do this for a while, and since I've just had a relatively
large refactor commit (pcpy), this is as good of a time as any.
Typedefing structs was mostly inspired by Plan 9's coding style. It makes
some lines of code much shorter at basically no expense.
Everything related to userland kept old-style struct definitions, so as not
to force that style onto other people.
I also considered changing SCREAMING_ENUM_FIELDS to NicerLookingCamelcase,
but I didn't, just in case that'd be confusing.
Diffstat (limited to 'src/user/app/tests/kernel/miscsyscall.c')
-rw-r--r-- | src/user/app/tests/kernel/miscsyscall.c | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/src/user/app/tests/kernel/miscsyscall.c b/src/user/app/tests/kernel/miscsyscall.c index 58a9afb..c90560e 100644 --- a/src/user/app/tests/kernel/miscsyscall.c +++ b/src/user/app/tests/kernel/miscsyscall.c @@ -17,7 +17,7 @@ static void test_await(void) { if (!fork()) exit(i); - while ((ret = _syscall_await()) != ~0) { + while ((ret = _sys_await()) != ~0) { test(0 <= ret && ret < 16); counts[ret]++; } @@ -30,114 +30,114 @@ static void test_await2(void) { /* hangs on failure */ if (!fork()) { if (!fork()) { - for (;;) _syscall_sleep(1000000000); + for (;;) _sys_sleep(1000000000); } else { exit(123); } } - test(_syscall_await() == 123); - test(_syscall_await() == ~0); /* don't wait for tombstone */ - _syscall_filicide(); + test(_sys_await() == 123); + test(_sys_await() == ~0); /* don't wait for tombstone */ + _sys_filicide(); } static void test_pipe(void) { const char *pipe_msgs[2] = {"hello", "world"}; - handle_t ends[2]; + hid_t ends[2]; char buf[16]; /* test regular reads / writes */ - test(_syscall_pipe(ends, 0) >= 0); + test(_sys_pipe(ends, 0) >= 0); if (!fork()) { /* those repeated asserts ensure that you can't read/write to the wrong ends */ - test(_syscall_read(ends[1], buf, 16, 0) < 0); - test(_syscall_write(ends[0], buf, 16, 0, 0) < 0); + test(_sys_read(ends[1], buf, 16, 0) < 0); + test(_sys_write(ends[0], buf, 16, 0, 0) < 0); - test(5 == _syscall_write(ends[1], pipe_msgs[0], 5, -1, 0)); + test(5 == _sys_write(ends[1], pipe_msgs[0], 5, -1, 0)); - test(_syscall_read(ends[1], buf, 16, 0) < 0); - test(_syscall_write(ends[0], buf, 16, 0, 0) < 0); + test(_sys_read(ends[1], buf, 16, 0) < 0); + test(_sys_write(ends[0], buf, 16, 0, 0) < 0); - test(5 == _syscall_write(ends[1], pipe_msgs[1], 5, -1, 0)); + test(5 == _sys_write(ends[1], pipe_msgs[1], 5, -1, 0)); exit(0); } else { - test(_syscall_read(ends[1], buf, 16, 0) < 0); - test(_syscall_write(ends[0], buf, 16, 0, 0) < 0); + test(_sys_read(ends[1], buf, 16, 0) < 0); + test(_sys_write(ends[0], buf, 16, 0, 0) < 0); - test(5 == _syscall_read(ends[0], buf, 16, 0)); + test(5 == _sys_read(ends[0], buf, 16, 0)); test(!memcmp(buf, pipe_msgs[0], 5)); - test(_syscall_read(ends[1], buf, 16, 0) < 0); - test(_syscall_write(ends[0], buf, 16, 0, 0) < 0); + test(_sys_read(ends[1], buf, 16, 0) < 0); + test(_sys_write(ends[0], buf, 16, 0, 0) < 0); - test(5 == _syscall_read(ends[0], buf, 16, 0)); + test(5 == _sys_read(ends[0], buf, 16, 0)); test(!memcmp(buf, pipe_msgs[1], 5)); - _syscall_await(); + _sys_await(); } close(ends[0]); close(ends[1]); /* writing to pipes with one end closed */ - test(_syscall_pipe(ends, 0) >= 0); + test(_sys_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { if (!fork()) { close(ends[1]); - test(_syscall_read(ends[0], buf, 16, 0) < 0); + test(_sys_read(ends[0], buf, 16, 0) < 0); exit(0); } } close(ends[1]); for (int i = 0; i < 16; i++) - _syscall_await(); + _sys_await(); close(ends[0]); - test(_syscall_pipe(ends, 0) >= 0); + test(_sys_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { if (!fork()) { close(ends[0]); - test(_syscall_write(ends[1], buf, 16, 0, 0) < 0); + test(_sys_write(ends[1], buf, 16, 0, 0) < 0); exit(0); } } close(ends[0]); for (int i = 0; i < 16; i++) - _syscall_await(); + _sys_await(); close(ends[1]); /* queueing */ - test(_syscall_pipe(ends, 0) >= 0); + test(_sys_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { if (!fork()) { - test(_syscall_write(ends[1], pipe_msgs[0], 5, -1, 0) == 5); + test(_sys_write(ends[1], pipe_msgs[0], 5, -1, 0) == 5); exit(0); } } close(ends[1]); for (int i = 0; i < 16; i++) { - test(_syscall_read(ends[0], buf, sizeof buf, 0) == 5); - _syscall_await(); + test(_sys_read(ends[0], buf, sizeof buf, 0) == 5); + _sys_await(); } - test(_syscall_read(ends[0], buf, sizeof buf, 0) < 0); + test(_sys_read(ends[0], buf, sizeof buf, 0) < 0); close(ends[0]); - test(_syscall_pipe(ends, 0) >= 0); + test(_sys_pipe(ends, 0) >= 0); for (int i = 0; i < 16; i++) { if (!fork()) { memset(buf, 0, sizeof buf); - test(_syscall_read(ends[0], buf, 5, -1) == 5); + test(_sys_read(ends[0], buf, 5, -1) == 5); test(!memcmp(buf, pipe_msgs[1], 5)); exit(0); } } close(ends[0]); for (int i = 0; i < 16; i++) { - test(_syscall_write(ends[1], pipe_msgs[1], 5, -1, 0) == 5); - _syscall_await(); + test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) == 5); + _sys_await(); } - test(_syscall_write(ends[1], pipe_msgs[1], 5, -1, 0) < 0); + test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) < 0); close(ends[1]); @@ -147,65 +147,65 @@ static void test_pipe(void) { static void test_memflag(void) { void *page = (void*)0x77777000; - _syscall_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page + _sys_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page memset(page, 77, 4096); // write to it - _syscall_memflag(page, 4096, 0); // free it + _sys_memflag(page, 4096, 0); // free it if (!fork()) { memset(page, 11, 4096); // should segfault exit(0); } else { - test(_syscall_await() != 0); // test if the process crashed + test(_sys_await() != 0); // test if the process crashed } char *pages[4]; for (size_t i = 0; i < 4; i++) { - pages[i] = _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE); - test(pages[i] == _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE | MEMFLAG_PRESENT)); + pages[i] = _sys_memflag(NULL, 4096, MEMFLAG_FINDFREE); + test(pages[i] == _sys_memflag(NULL, 4096, MEMFLAG_FINDFREE | MEMFLAG_PRESENT)); if (i > 0) test(pages[i] != pages[i-1]); *pages[i] = 0x77; } for (size_t i = 0; i < 4; i++) - _syscall_memflag(pages, 4096, MEMFLAG_PRESENT); + _sys_memflag(pages, 4096, MEMFLAG_PRESENT); } static void test_dup(void) { - handle_t pipe[2]; - handle_t h1, h2; - test(_syscall_pipe(pipe, 0) >= 0); + hid_t pipe[2]; + hid_t h1, h2; + test(_sys_pipe(pipe, 0) >= 0); if (!fork()) { close(pipe[0]); - h1 = _syscall_dup(pipe[1], -1, 0); + h1 = _sys_dup(pipe[1], -1, 0); test(h1 >= 0); test(h1 != pipe[1]); - h2 = _syscall_dup(h1, -1, 0); + h2 = _sys_dup(h1, -1, 0); test(h2 >= 0); test(h2 != pipe[1] && h2 != h1); - _syscall_write(pipe[1], "og", 2, 0, 0); - _syscall_write(h1, "h1", 2, 0, 0); - _syscall_write(h2, "h2", 2, 0, 0); + _sys_write(pipe[1], "og", 2, 0, 0); + _sys_write(h1, "h1", 2, 0, 0); + _sys_write(h2, "h2", 2, 0, 0); close(pipe[1]); - _syscall_write(h1, "h1", 2, 0, 0); - _syscall_write(h2, "h2", 2, 0, 0); + _sys_write(h1, "h1", 2, 0, 0); + _sys_write(h2, "h2", 2, 0, 0); - test(_syscall_dup(h1, pipe[1], 0) == pipe[1]); - test(_syscall_dup(h2, pipe[1], 0) == pipe[1]); - test(_syscall_dup(h1, pipe[1], 0) == pipe[1]); - test(_syscall_dup(h2, pipe[1], 0) == pipe[1]); + test(_sys_dup(h1, pipe[1], 0) == pipe[1]); + test(_sys_dup(h2, pipe[1], 0) == pipe[1]); + test(_sys_dup(h1, pipe[1], 0) == pipe[1]); + test(_sys_dup(h2, pipe[1], 0) == pipe[1]); close(h1); close(h2); - test(_syscall_dup(pipe[1], h2, 0) == h2); - _syscall_write(h2, "h2", 2, 0, 0); + test(_sys_dup(pipe[1], h2, 0) == h2); + _sys_write(h2, "h2", 2, 0, 0); close(h2); - test(_syscall_dup(pipe[1], h1, 0) == h1); - _syscall_write(h1, "h1", 2, 0, 0); + test(_sys_dup(pipe[1], h1, 0) == h1); + _sys_write(h1, "h1", 2, 0, 0); close(h1); exit(0); @@ -213,10 +213,10 @@ static void test_dup(void) { char buf[16]; size_t count = 0; close(pipe[1]); - while (_syscall_read(pipe[0], buf, sizeof buf, 0) >= 0) + while (_sys_read(pipe[0], buf, sizeof buf, 0) >= 0) count++; test(count == 7); - _syscall_await(); + _sys_await(); } @@ -226,47 +226,47 @@ static void test_dup(void) { static void test_execbuf(void) { if (!fork()) { uint64_t buf[] = { - EXECBUF_SYSCALL, _SYSCALL_EXIT, 123, 0, 0, 0, 0, + EXECBUF_SYSCALL, _SYS_EXIT, 123, 0, 0, 0, 0, }; - _syscall_execbuf(buf, sizeof buf); + _sys_execbuf(buf, sizeof buf); test_fail(); } else { - test(_syscall_await() == 123); + test(_sys_await() == 123); } } static void test_sleep(void) { - handle_t reader; + hid_t reader; FILE *writer; if (!forkpipe(&writer, &reader)) { if (!fork()) { if (!fork()) { - _syscall_sleep(100); + _sys_sleep(100); fprintf(writer, "1"); - _syscall_sleep(200); + _sys_sleep(200); fprintf(writer, "3"); - _syscall_sleep(200); + _sys_sleep(200); fprintf(writer, "5"); - _syscall_exit(0); + _sys_exit(0); } if (!fork()) { fprintf(writer, "0"); - _syscall_sleep(200); + _sys_sleep(200); fprintf(writer, "2"); - _syscall_sleep(200); + _sys_sleep(200); fprintf(writer, "4"); /* get killed while asleep * a peaceful death, i suppose. */ - for (;;) _syscall_sleep(1000000000); + for (;;) _sys_sleep(1000000000); } - _syscall_await(); - _syscall_filicide(); - _syscall_exit(0); + _sys_await(); + _sys_filicide(); + _sys_exit(0); } /* this part checks if, after killing an asleep process, * other processes can still wake up */ - _syscall_sleep(600); + _sys_sleep(600); fprintf(writer, "6"); exit(0); } else { @@ -275,7 +275,7 @@ static void test_sleep(void) { size_t pos = 0; for (;;) { char buf[128]; - long ret = _syscall_read(reader, buf, sizeof buf, 0); + long ret = _sys_read(reader, buf, sizeof buf, 0); if (ret < 0) break; test(pos + ret <= target); test(memcmp(buf, expected + pos, ret) == 0); @@ -286,8 +286,8 @@ static void test_sleep(void) { } static void test_badopen(void) { - test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE) >= 0); - test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL); + test(_sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE) >= 0); + test(_sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL); } void r_k_miscsyscall(void) { |