/
performancetimer_test.cpp
45 lines (36 loc) · 1.53 KB
/
performancetimer_test.cpp
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
#include <gtest/gtest.h>
#include <ctime>
#include "util/performancetimer.h"
TEST(PerformanceTimerTest, ElapsedIsMonotonic) {
ASSERT_TRUE(PerformanceTimer::debugEnsureClockIsMonotonic());
}
// This test was added because of an signed/unsigned underflow bug that
// affected Windows and (presumably) Symbian.
// See https://github.com/mixxxdj/mixxx/issues/7397
TEST(PerformanceTimerTest, DifferenceCanBeNegative) {
PerformanceTimer early;
early.start();
std::time_t start = time(0);
while (1) {
// use the standard clock to make sure we don't run forever
double seconds = difftime(time(0), start);
PerformanceTimer late;
late.start();
mixxx::Duration difference = early.difference(late);
// If the high-res clock hasn't ticked yet, the difference should be 0.
// If it has ticked, then the difference better be negative.
ASSERT_LE(difference.toIntegerNanos(), 0);
if (difference < mixxx::Duration::fromNanos(0)) {
break; // test passed
}
if (seconds > 0.9) {
// The standard clock ticked, but difference is still zero.
// Assume that there is no high-resolution clock on this system.
ASSERT_EQ(0, difference.toIntegerNanos());
// It would be nice if gtest printed this, but it currently doesn't.
// https://code.google.com/p/googletest/wiki/AdvancedGuide
SUCCEED() << "inconclusive: no high-resolution timer on this system?";
break;
}
}
}