commit 44cae1e90820948ffbf91b4c7d11732f1363fb1d
parent ce1d933f78707515470d4a36071256b67647ddda
Author: Kirill Primak <vyivel@eclair.cafe>
Date: Mon, 24 Oct 2022 08:45:16 +0300
rt/test: fix timespec diff calculation
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
Diffstat:
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/rt/+test/+freebsd.ha b/rt/+test/+freebsd.ha
@@ -11,6 +11,11 @@ fn time_start() void = {
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 / 10000z);
+ let sec_diff = end.tv_sec - start.tv_sec;
+ let nsec_diff = end.tv_nsec - start.tv_nsec;
+ if (nsec_diff < 0) {
+ nsec_diff += 1000000000;
+ sec_diff -= 1;
+ };
+ return (sec_diff: size, nsec_diff: size / 1000000z);
};
diff --git a/rt/+test/+linux.ha b/rt/+test/+linux.ha
@@ -12,6 +12,11 @@ fn time_start() void = {
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 / 10000z);
+ let sec_diff = end.tv_sec - start.tv_sec;
+ let nsec_diff = end.tv_nsec - start.tv_nsec;
+ if (nsec_diff < 0) {
+ nsec_diff += 1000000000;
+ sec_diff -= 1;
+ };
+ return (sec_diff: size, nsec_diff: size / 1000000z);
};