cheatah
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>
7namespace t = cheatah::time;
9TEST(CheatahTime, MonotonicClocksAdvanceAcrossSleep) {
10 const double m0 = t::monotonic();
11 const long long p0 = t::perf_counter_ns();
12 t::sleep(0.01); // 10 ms
13 EXPECT_GE(t::monotonic() - m0, 0.005); // at least ~5 ms elapsed
14 EXPECT_GT(t::perf_counter_ns() - p0, 0);
15 EXPECT_GT(t::monotonic_ns(), 0);
18TEST(CheatahTime, WallClockIsRecent) {
19 EXPECT_GT(t::time(), 1.6e9); // after ~2020-09
20 EXPECT_GT(t::time_ns(), 0);
23TEST(CheatahTime, ProcessTimeNonNegative) {
24 EXPECT_GE(t::process_time(), 0.0);
27TEST(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);