diff options
Diffstat (limited to 'src/cmd/tests')
-rw-r--r-- | src/cmd/tests/kernel/time.c | 49 | ||||
-rw-r--r-- | src/cmd/tests/tests.c | 1 | ||||
-rw-r--r-- | src/cmd/tests/tests.h | 1 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/cmd/tests/kernel/time.c b/src/cmd/tests/kernel/time.c new file mode 100644 index 0000000..476a90a --- /dev/null +++ b/src/cmd/tests/kernel/time.c @@ -0,0 +1,49 @@ +#include "../tests.h" +#include <camellia.h> + +static void +test_settime(void) { + uint64_t ns = 1000000000; + uint64_t base = 1337 * ns; + union { + uint64_t t; + char buf[8]; + } u; + + hid_t h = camellia_open("/dev/bintime", OPEN_RW); + + /* check if time is reasonable */ + test(h >= 0); + test(_sys_read(h, u.buf, 8, 0) == 8); + test(0 < u.t); + test(u.t < ns); /* this should've taken less than a second */ + + /* try changing the time */ + u.t = base; + test(_sys_write(h, u.buf, 8, 0, 0) == 8); + + /* did we succeed? */ + u.t = 0; + test(_sys_read(h, u.buf, 8, 0) == 8); + test(base < u.t); + test(u.t < base + ns); + + /* clone the handle */ + hid_t h2 = _sys_dup(h, 0, DUP_SEARCH | DUP_RDONLY); + test(h2 >= 0); + + /* i shouldn't be able to write to it */ + u.t = 0; + test(_sys_write(h2, u.buf, 8, 0, 0) == -EACCES); + + /* but reads should be fine */ + test(_sys_read(h2, u.buf, 8, 0) == 8); + test(base < u.t); + test(u.t < base + ns); +} + +void +r_k_time(void) +{ + run_test(test_settime); +} diff --git a/src/cmd/tests/tests.c b/src/cmd/tests/tests.c index 2b7ba01..2b66b43 100644 --- a/src/cmd/tests/tests.c +++ b/src/cmd/tests/tests.c @@ -54,6 +54,7 @@ int main(void) { r_k_misc(); r_k_path(); r_k_threads(); + r_k_time(); r_libc_esemaphore(); r_libc_setjmp(); r_libc_string(); diff --git a/src/cmd/tests/tests.h b/src/cmd/tests/tests.h index bbf5309..f562d27 100644 --- a/src/cmd/tests/tests.h +++ b/src/cmd/tests/tests.h @@ -13,6 +13,7 @@ void r_k_misc(void); void r_k_miscsyscall(void); void r_k_path(void); void r_k_threads(void); +void r_k_time(void); void r_libc_esemaphore(void); void r_libc_setjmp(void); void r_libc_string(void); |