Go to the documentation of this file. 1 #ifndef TEST_OUTPUT_TEST_H
2 #define TEST_OUTPUT_TEST_H
5 #include <initializer_list>
13 #include "../src/re.h"
14 #include "benchmark/benchmark.h"
16 #define CONCAT2(x, y) x##y
17 #define CONCAT(x, y) CONCAT2(x, y)
19 #define ADD_CASES(...) int CONCAT(dummy, __LINE__) = ::AddCases(__VA_ARGS__)
21 #define SET_SUBSTITUTIONS(...) \
22 int CONCAT(dummy, __LINE__) = ::SetSubstitutions(__VA_ARGS__)
37 std::shared_ptr<benchmark::Regex>
regex;
58 std::initializer_list<std::pair<std::string, std::string>> il);
75 #define CHECK_BENCHMARK_RESULTS(bm_name_pattern, checker_function) \
76 size_t CONCAT(dummy, __LINE__) = AddChecker(bm_name_pattern, checker_function)
90 std::map< std::string, std::string >
values;
116 if(
it ==
values.end())
return nullptr;
123 T GetAs(
const char* entry_name)
const;
129 double dval = GetAs< double >(entry_name);
130 T tval =
static_cast< T >(dval);
137 auto *sv =
Get(entry_name);
138 CHECK(sv !=
nullptr && !sv->empty());
139 std::stringstream ss;
151 #define _CHECK_RESULT_VALUE(entry, getfn, var_type, var_name, relationship, value) \
152 CONCAT(CHECK_, relationship) \
153 (entry.getfn< var_type >(var_name), (value)) << "\n" \
154 << __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
155 << __FILE__ << ":" << __LINE__ << ": " \
156 << "expected (" << #var_type << ")" << (var_name) \
157 << "=" << (entry).getfn< var_type >(var_name) \
158 << " to be " #relationship " to " << (value) << "\n"
162 #define _CHECK_FLOAT_RESULT_VALUE(entry, getfn, var_type, var_name, relationship, value, eps_factor) \
163 CONCAT(CHECK_FLOAT_, relationship) \
164 (entry.getfn< var_type >(var_name), (value), (eps_factor) * (value)) << "\n" \
165 << __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
166 << __FILE__ << ":" << __LINE__ << ": " \
167 << "expected (" << #var_type << ")" << (var_name) \
168 << "=" << (entry).getfn< var_type >(var_name) \
169 << " to be " #relationship " to " << (value) << "\n" \
170 << __FILE__ << ":" << __LINE__ << ": " \
171 << "with tolerance of " << (eps_factor) * (value) \
172 << " (" << (eps_factor)*100. << "%), " \
173 << "but delta was " << ((entry).getfn< var_type >(var_name) - (value)) \
174 << " (" << (((entry).getfn< var_type >(var_name) - (value)) \
176 ((value) > 1.e-5 || value < -1.e-5 ? value : 1.e-5)*100.) \
179 #define CHECK_RESULT_VALUE(entry, var_type, var_name, relationship, value) \
180 _CHECK_RESULT_VALUE(entry, GetAs, var_type, var_name, relationship, value)
182 #define CHECK_COUNTER_VALUE(entry, var_type, var_name, relationship, value) \
183 _CHECK_RESULT_VALUE(entry, GetCounterAs, var_type, var_name, relationship, value)
185 #define CHECK_FLOAT_RESULT_VALUE(entry, var_name, relationship, value, eps_factor) \
186 _CHECK_FLOAT_RESULT_VALUE(entry, GetAs, double, var_name, relationship, value, eps_factor)
188 #define CHECK_FLOAT_COUNTER_VALUE(entry, var_name, relationship, value, eps_factor) \
189 _CHECK_FLOAT_RESULT_VALUE(entry, GetCounterAs, double, var_name, relationship, value, eps_factor)
197 const char*
const dec_re =
"[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?";
201 #endif // TEST_OUTPUT_TEST_H
double DurationCPUTime() const
size_t AddChecker(const char *bm_name_pattern, ResultsCheckFn fn)
std::function< void(Results const &)> ResultsCheckFn
std::string substituted_regex
T GetCounterAs(const char *entry_name) const
TestCase(std::string re, int rule=MR_Default)
#define T(upbtypeconst, upbtype, ctype, default_value)
std::map< std::string, std::string > values
std::shared_ptr< benchmark::Regex > regex
T GetAs(const char *entry_name) const
void RunOutputTests(int argc, char *argv[])
double DurationRealTime() const
int SetSubstitutions(std::initializer_list< std::pair< std::string, std::string >> il)
std::function< void(Results const &) > ResultsCheckFn
int AddCases(TestCaseID ID, std::initializer_list< TestCase > il)
Results(const std::string &n)
double GetTime(BenchmarkTime which) const
const std::string * Get(const char *entry_name) const
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:36