diff options
Diffstat (limited to 'src/cmd/tests/kernel')
-rw-r--r-- | src/cmd/tests/kernel/miscsyscall.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cmd/tests/kernel/miscsyscall.c b/src/cmd/tests/kernel/miscsyscall.c index 1317720..883fcee 100644 --- a/src/cmd/tests/kernel/miscsyscall.c +++ b/src/cmd/tests/kernel/miscsyscall.c @@ -326,6 +326,40 @@ static void test_getnull(void) { close(h2); } +static void test_dup_ro(void) { + char buf[2]; + + /* runs two times, trying to close either the original handle or the dup'd + * one. */ + for (int i = 0; i < 2; i++) { + hid_t h = _sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_RW); + test(0 <= h); + hid_t h2 = _sys_dup(h, 0, DUP_SEARCH | DUP_RDONLY); + test(0 <= h2); + + test(_sys_write(h, "hi", 2, 0, 0) == 2); + test(_sys_write(h2, "no", 2, 0, 0) == -EACCES); + + test(_sys_read(h, buf, 2, 0) == 2); + test(memcmp(buf, "hi", 2) == 0); + test(_sys_read(h2, buf, 2, 0) == 2); + test(memcmp(buf, "hi", 2) == 0); + + if (i == 0) { + _sys_close(h); + test(_sys_read(h2, buf, 2, 0) == 2); + test(memcmp(buf, "hi", 2) == 0); + _sys_close(h2); + } else { + _sys_close(h2); + test(_sys_write(h, "ay", 2, 0, 0) == 2); + test(_sys_read(h, buf, 2, 0) == 2); + test(memcmp(buf, "ay", 2) == 0); + _sys_close(h); + } + } +} + void r_k_miscsyscall(void) { run_test(test_await); run_test(test_await2); @@ -338,4 +372,5 @@ void r_k_miscsyscall(void) { run_test(test_badopen); run_test(test_timer); run_test(test_getnull); + run_test(test_dup_ro); } |