From 14fd2aecd074fb93bb509df0c1cedd1f1055a4a6 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 18 Sep 2023 16:20:52 +0200 Subject: kernel: implement _sys_time() After some consideration this seems like the most fitting way to handle timekeeping. Directly, the syscall is only useful for keeping time within a single process, but it is meant to be used for e.g. NTP clients, which will provide the real time through the VFS. --- src/cmd/tests/kernel/miscsyscall.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/cmd/tests') diff --git a/src/cmd/tests/kernel/miscsyscall.c b/src/cmd/tests/kernel/miscsyscall.c index 7c61392..3cf3f2e 100644 --- a/src/cmd/tests/kernel/miscsyscall.c +++ b/src/cmd/tests/kernel/miscsyscall.c @@ -287,6 +287,23 @@ static void test_badopen(void) { test(_sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL); } +static void test_timer(void) { + uint64_t start = _sys_time(0); + test(start == 0); + _sys_sleep(10); + uint64_t delay = _sys_time(0) - start; + test(delay >= 10 * 1000000); + if (!fork()) { + uint64_t start = _sys_time(0); + test(start == 0); + _sys_sleep(10); + uint64_t delay = _sys_time(0) - start; + test(delay >= 10 * 1000000); + } else { + _sys_await(); + } +} + void r_k_miscsyscall(void) { run_test(test_await); run_test(test_await2); @@ -297,4 +314,5 @@ void r_k_miscsyscall(void) { run_test(test_execbuf); run_test(test_sleep); run_test(test_badopen); + run_test(test_timer); } -- cgit v1.2.3