diff options
author | dzwdz | 2023-09-18 16:20:52 +0200 |
---|---|---|
committer | dzwdz | 2023-09-18 16:20:52 +0200 |
commit | 14fd2aecd074fb93bb509df0c1cedd1f1055a4a6 (patch) | |
tree | 10ecb45967748a6b65558074f22c8cdf52ee74ae /src/cmd/tests/kernel/miscsyscall.c | |
parent | 730a929fffbaaaeb20529962654049fe26dd5dde (diff) |
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.
Diffstat (limited to 'src/cmd/tests/kernel/miscsyscall.c')
-rw-r--r-- | src/cmd/tests/kernel/miscsyscall.c | 18 |
1 files changed, 18 insertions, 0 deletions
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); } |