hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3d2397091e86b3c242377804c0bc137ad2fa66d5
parent 3fd55fd1e44451fe438ccfd4951d21a7e50dfebe
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 15 Feb 2021 14:13:04 -0500

rt+test: add ellapsed time to test results

Diffstat:
Mrt/+linux/syscalls.ha | 9+++++++++
Mrt/+linux/types.ha | 13+++++++++++++
Art/+test/+linux.ha | 13+++++++++++++
Mrt/+test/start.ha | 8+++++++-
4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -177,3 +177,12 @@ export fn getrandom(buf: *void, bufln: size, flags: uint) (size | errno) = { n: u64 => n: size, }; }; + +// TODO: Implement me with VDSO +export fn clock_gettime(clock_id: int, tp: *timespec) (void | errno) = { + return match (wrap_return(syscall2(SYS_clock_gettime, + clock_id: u64, tp: uintptr: u64))) { + err: errno => err, + u64 => void, + }; +}; diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -204,3 +204,16 @@ export type f_owner_ex = struct { _type: int, pid: int, }; + +export def CLOCK_REALTIME: int = 0; +export def CLOCK_MONOTONIC: int = 1; +export def CLOCK_PROCESS_CPUTIME_ID: int = 2; +export def CLOCK_THREAD_CPUTIME_ID: int = 3; +export def CLOCK_MONOTONIC_RAW: int = 4; +export def CLOCK_REALTIME_COARSE: int = 5; +export def CLOCK_MONOTONIC_COARSE: int = 6; +export def CLOCK_BOOTTIME: int = 7; +export def CLOCK_REALTIME_ALARM: int = 8; +export def CLOCK_BOOTTIME_ALARM: int = 9; +export def CLOCK_SGI_CYCLE: int = 10; +export def CLOCK_TAI: int = 11; diff --git a/rt/+test/+linux.ha b/rt/+test/+linux.ha @@ -0,0 +1,13 @@ +let start: timespec = timespec { ... }; + +fn time_start() void = { + clock_gettime(CLOCK_MONOTONIC, &start) as void; +}; + +// Returns ellapsed time as (seconds, milliseconds) +fn time_stop() (size, size) = { + let end: timespec = timespec { ... }; + clock_gettime(CLOCK_MONOTONIC, &end) as void; + return ((end.tv_sec - start.tv_sec): size, + (end.tv_nsec - start.tv_nsec): size / 100000z); +}; diff --git a/rt/+test/start.ha b/rt/+test/start.ha @@ -33,6 +33,7 @@ export fn start_ha() void = { print("Running "); print(ztos(ntest)); print(" tests:\n\n"); + time_start(); for (let i = 0z; i < ntest; i += 1) { print(test_start[i].name); dots(maxname - len(test_start[i].name) + 3); @@ -49,6 +50,7 @@ export fn start_ha() void = { npass += 1; print("OK\n"); }; + let end = time_stop(); if (nfail != 0) { print("\n"); @@ -72,7 +74,11 @@ export fn start_ha() void = { print(ztos(nfail)); print(" failed; "); print(ztos(ntest)); - print(" tests completed.\n"); + print(" tests completed in "); + print(ztos(end.0)); + print("."); + print(ztos(end.1)); + print("s\n"); const nfini = (&fini_end: uintptr - &fini_start: uintptr): size / size(*fn() void);