GCC Code Coverage Report
Directory: . Exec Total Coverage
File: test/unit/util/stats_black.cpp Lines: 43 43 100.0 %
Date: 2021-09-07 Branches: 112 304 36.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Andres Noetzli, Gereon Kremer
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Black box testing of cvc5::Stat and associated classes.
14
 */
15
16
#include <fcntl.h>
17
18
#include <ctime>
19
#include <sstream>
20
#include <string>
21
#include <thread>
22
23
#include "lib/clock_gettime.h"
24
#include "proof/proof_rule.h"
25
#include "test.h"
26
#include "util/statistics_registry.h"
27
#include "util/statistics_stats.h"
28
29
namespace cvc5 {
30
31
20
std::ostream& operator<<(std::ostream& os, const StatisticBaseValue* sbv)
32
{
33
20
  return os << *sbv;
34
}
35
20
bool operator==(const StatisticBaseValue* sbv, const std::string& s)
36
{
37
40
  std::stringstream ss;
38
20
  ss << sbv;
39
40
  return ss.str() == s;
40
}
41
42
namespace test {
43
44
4
class TestUtilBlackStats : public TestInternal
45
{
46
};
47
48
10
TEST_F(TestUtilBlackStats, stats)
49
{
50
#ifdef CVC5_STATISTICS_ON
51
4
  StatisticsRegistry reg(false);
52
4
  std::string empty, bar = "bar", baz = "baz";
53
54
2
  AverageStat avg = reg.registerAverage("avg");
55
2
  avg << 1.0 << 2.0;
56
57
2
  HistogramStat<int64_t> histInt = reg.registerHistogram<int64_t>("hist-int");
58
2
  histInt << 15 << 16 << 15 << 14 << 16;
59
60
  HistogramStat<PfRule> histPfRule =
61
2
      reg.registerHistogram<PfRule>("hist-pfrule");
62
2
  histPfRule << PfRule::ASSUME << PfRule::SCOPE << PfRule::ASSUME;
63
64
2
  IntStat intstat = reg.registerInt("int");
65
2
  intstat = 5;
66
2
  intstat++;
67
68
  ReferenceStat<std::string> refStr =
69
4
      reg.registerReference<std::string>("strref1", empty);
70
  ReferenceStat<std::string> refStr2 =
71
4
      reg.registerReference<std::string>("strref2", bar);
72
73
2
  TimerStat timer = reg.registerTimer("timer");
74
  {
75
4
    CodeTimer ct(timer);
76
2
    std::this_thread::sleep_for(std::chrono::milliseconds(50));
77
  }
78
79
2
  ValueStat<std::string> valStr = reg.registerValue("backed", baz);
80
2
  valStr.set("barz");
81
2
  ValueStat<double> valD1 = reg.registerValue("backedDouble", 16.5);
82
2
  valD1.set(3.5);
83
2
  ValueStat<double> valD2 = reg.registerValue("backedNegDouble", -16.5);
84
2
  valD2.set(-3.5);
85
2
  ValueStat<double> valD3 = reg.registerValue("backedDoubleNoDec", 2.0);
86
2
  valD3.set(17);
87
88
2
  ASSERT_EQ(reg.get("avg"), std::string("1.5"));
89
2
  ASSERT_EQ(reg.get("hist-int"), std::string("{ 14: 1, 15: 2, 16: 2 }"));
90
2
  ASSERT_EQ(reg.get("hist-pfrule"), std::string("{ ASSUME: 2, SCOPE: 1 }"));
91
2
  ASSERT_EQ(reg.get("int"), std::string("6"));
92
2
  ASSERT_EQ(reg.get("strref1"), std::string(""));
93
2
  ASSERT_EQ(reg.get("strref2"), std::string("bar"));
94
2
  ASSERT_EQ(reg.get("backed"), std::string("barz"));
95
2
  ASSERT_EQ(reg.get("backedDouble"), std::string("3.5"));
96
2
  ASSERT_EQ(reg.get("backedNegDouble"), std::string("-3.5"));
97
2
  ASSERT_EQ(reg.get("backedDoubleNoDec"), std::string("17"));
98
#endif
99
}
100
}  // namespace test
101
6
}  // namespace cvc5