Source
stdlib/tests/time_test.cpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
#include "time.hpp"5
#include <gtest/gtest.h>7
namespace t = cheatah::time;9
TEST(CheatahTime, MonotonicClocksAdvanceAcrossSleep) {10
const double m0 = t::monotonic();11
const long long p0 = t::perf_counter_ns();12
t::sleep(0.01); // 10 ms13
EXPECT_GE(t::monotonic() - m0, 0.005); // at least ~5 ms elapsed14
EXPECT_GT(t::perf_counter_ns() - p0, 0);15
EXPECT_GT(t::monotonic_ns(), 0);16
}18
TEST(CheatahTime, WallClockIsRecent) {19
EXPECT_GT(t::time(), 1.6e9); // after ~2020-0920
EXPECT_GT(t::time_ns(), 0);21
}23
TEST(CheatahTime, ProcessTimeNonNegative) {24
EXPECT_GE(t::process_time(), 0.0);25
}27
TEST(CheatahTime, PerfCounterAdvances) {28
const double a = t::perf_counter();29
t::sleep(0.005);30
EXPECT_GE(t::perf_counter(), a);31
EXPECT_GE(t::perf_counter_ns(), 0);32
}