-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsleep_for.test.cc
53 lines (41 loc) · 1.2 KB
/
sleep_for.test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/thread/sleep_for.hh"
#include "snn-core/unittest.hh"
#include "snn-core/time/duration.formatter.hh"
#include "snn-core/time/stopwatch.hh"
#include "snn-core/time/unit.hh"
namespace snn::app
{
namespace
{
bool example()
{
time::stopwatch stopwatch;
constexpr time::duration how_long = time::milliseconds{50}.duration().value();
thread::sleep_for(how_long).or_throw();
fmt::print("Slept for: {}\n", stopwatch.duration());
return true;
}
bool test_sleep_for()
{
time::stopwatch stopwatch;
for (loop::count lc{2}; lc--;)
{
thread::sleep_for(time::milliseconds{2}.duration().value()).or_throw();
const i64 ns = stopwatch.nanoseconds();
snn_require(ns >= 2'000'000 && ns < 2'900'000);
stopwatch.reset();
}
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_require(app::example());
snn_require(app::test_sleep_for());
}
}