Go to the documentation of this file. 1 #ifndef TEST_OUTPUT_TEST_H
2 #define TEST_OUTPUT_TEST_H
6 #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);
82 #define CHECK_BENCHMARK_RESULTS(bm_name_pattern, checker_function) \
83 size_t CONCAT(dummy, __LINE__) = AddChecker(bm_name_pattern, checker_function)
96 std::map<std::string, std::string>
values;
124 if (
it ==
values.end())
return nullptr;
131 T GetAs(
const char* entry_name)
const;
137 double dval = GetAs<double>(entry_name);
138 T tval =
static_cast<T>(dval);
145 auto* sv =
Get(entry_name);
146 BM_CHECK(sv !=
nullptr && !sv->empty());
147 std::stringstream ss;
161 #define CHECK_RESULT_VALUE_IMPL(entry, getfn, var_type, var_name, relationship, value) \
162 CONCAT(BM_CHECK_, relationship) \
163 (entry.getfn< var_type >(var_name), (value)) << "\n" \
164 << __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
165 << __FILE__ << ":" << __LINE__ << ": " \
166 << "expected (" << #var_type << ")" << (var_name) \
167 << "=" << (entry).getfn< var_type >(var_name) \
168 << " to be " #relationship " to " << (value) << "\n"
172 #define CHECK_FLOAT_RESULT_VALUE_IMPL(entry, getfn, var_type, var_name, relationship, value, eps_factor) \
173 CONCAT(BM_CHECK_FLOAT_, relationship) \
174 (entry.getfn< var_type >(var_name), (value), (eps_factor) * (value)) << "\n" \
175 << __FILE__ << ":" << __LINE__ << ": " << (entry).name << ":\n" \
176 << __FILE__ << ":" << __LINE__ << ": " \
177 << "expected (" << #var_type << ")" << (var_name) \
178 << "=" << (entry).getfn< var_type >(var_name) \
179 << " to be " #relationship " to " << (value) << "\n" \
180 << __FILE__ << ":" << __LINE__ << ": " \
181 << "with tolerance of " << (eps_factor) * (value) \
182 << " (" << (eps_factor)*100. << "%), " \
183 << "but delta was " << ((entry).getfn< var_type >(var_name) - (value)) \
184 << " (" << (((entry).getfn< var_type >(var_name) - (value)) \
186 ((value) > 1.e-5 || value < -1.e-5 ? value : 1.e-5)*100.) \
189 #define CHECK_RESULT_VALUE(entry, var_type, var_name, relationship, value) \
190 CHECK_RESULT_VALUE_IMPL(entry, GetAs, var_type, var_name, relationship, value)
192 #define CHECK_COUNTER_VALUE(entry, var_type, var_name, relationship, value) \
193 CHECK_RESULT_VALUE_IMPL(entry, GetCounterAs, var_type, var_name, relationship, value)
195 #define CHECK_FLOAT_RESULT_VALUE(entry, var_name, relationship, value, eps_factor) \
196 CHECK_FLOAT_RESULT_VALUE_IMPL(entry, GetAs, double, var_name, relationship, value, eps_factor)
198 #define CHECK_FLOAT_COUNTER_VALUE(entry, var_name, relationship, value, eps_factor) \
199 CHECK_FLOAT_RESULT_VALUE_IMPL(entry, GetCounterAs, double, var_name, relationship, value, eps_factor)
209 const char*
const dec_re =
"[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?";
213 #endif // TEST_OUTPUT_TEST_H
std::string GetFileReporterOutput(int argc, char *argv[])
double DurationCPUTime() const
std::function< void(Results const &)> ResultsCheckFn
std::string substituted_regex
T GetCounterAs(const char *entry_name) const
int SubstrCnt(const std::string &haystack, const std::string &pat)
TestCase(std::string re, int rule=MR_Default)
#define T(upbtypeconst, upbtype, ctype, default_value)
double NumIterations() const
int SetSubstitutions(std::initializer_list< std::pair< std::string, std::string >> il)
std::map< std::string, std::string > values
std::shared_ptr< benchmark::Regex > regex
T GetAs(const char *entry_name) const
int AddCases(TestCaseID ID, std::initializer_list< TestCase > il)
size_t AddChecker(const char *bm_name_pattern, ResultsCheckFn fn)
void RunOutputTests(int argc, char *argv[])
double DurationRealTime() const
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