]> Git Repo - VerusCoin.git/blame - src/gtest/test_metrics.cpp
Build fix
[VerusCoin.git] / src / gtest / test_metrics.cpp
CommitLineData
000499ae
JG
1#include <gtest/gtest.h>
2
3#include "metrics.h"
6c1df957 4#include "utiltest.h"
000499ae
JG
5#include "utiltime.h"
6
7
601f00f6
JG
8TEST(Metrics, AtomicTimer) {
9 AtomicTimer t;
10 SetMockTime(100);
11
12 EXPECT_FALSE(t.running());
13
14 t.start();
15 EXPECT_TRUE(t.running());
16
17 t.start();
18 EXPECT_TRUE(t.running());
19
20 t.stop();
21 EXPECT_TRUE(t.running());
22
23 t.stop();
24 EXPECT_FALSE(t.running());
25
26 // Additional calls to stop() are ignored.
27 t.stop();
28 EXPECT_FALSE(t.running());
29
30 t.start();
31 EXPECT_TRUE(t.running());
32
33 AtomicCounter c;
34 EXPECT_EQ(0, t.rate(c));
35
36 c.increment();
37 EXPECT_EQ(0, t.rate(c));
38
39 SetMockTime(101);
40 EXPECT_EQ(1, t.rate(c));
41
42 c.decrement();
43 EXPECT_EQ(0, t.rate(c));
44
45 SetMockTime(102);
46 EXPECT_EQ(0, t.rate(c));
47
48 c.increment();
49 EXPECT_EQ(0.5, t.rate(c));
50
51 t.stop();
52 EXPECT_FALSE(t.running());
53 EXPECT_EQ(0.5, t.rate(c));
54}
55
000499ae
JG
56TEST(Metrics, GetLocalSolPS) {
57 SetMockTime(100);
5c0d105b 58 miningTimer.start();
000499ae
JG
59
60 // No time has passed
61 EXPECT_EQ(0, GetLocalSolPS());
62
63 // Increment time
64 SetMockTime(101);
65 EXPECT_EQ(0, GetLocalSolPS());
66
67 // Increment solutions
68 solutionTargetChecks.increment();
69 EXPECT_EQ(1, GetLocalSolPS());
70
71 // Increment time
72 SetMockTime(102);
73 EXPECT_EQ(0.5, GetLocalSolPS());
74
75 // Increment solutions
76 solutionTargetChecks.increment();
77 solutionTargetChecks.increment();
78 EXPECT_EQ(1.5, GetLocalSolPS());
5c0d105b
JG
79
80 // Stop timing
81 miningTimer.stop();
82 EXPECT_EQ(1.5, GetLocalSolPS());
83
84 // Increment time
85 SetMockTime(103);
86 EXPECT_EQ(1.5, GetLocalSolPS());
87
88 // Start timing again
89 miningTimer.start();
90 EXPECT_EQ(1.5, GetLocalSolPS());
91
92 // Increment time
93 SetMockTime(104);
94 EXPECT_EQ(1, GetLocalSolPS());
000499ae 95}
047aec1e 96
6c1df957
EOW
97TEST(Metrics, EstimateNetHeight) {
98 auto params = RegtestActivateBlossom(false, 200);
99 int64_t blockTimes[400];
100 for (int i = 0; i < 400; i++) {
101 blockTimes[i] = i ? blockTimes[i - 1] + params.PoWTargetSpacing(i) : 0;
102 }
103 SetMockTime(blockTimes[399]);
104 for (int i = 0; i < 400; i++) {
105 // Check that we are within 1 of the correct height
106 EXPECT_LT(std::abs(399 - EstimateNetHeight(params, i, blockTimes[i])), 2);
107 }
108 RegtestDeactivateBlossom();
047aec1e 109}
This page took 0.138173 seconds and 4 git commands to generate.