79#if !defined(_UNITTESTFRAMEWORK_H_)
80#define _UNITTESTFRAMEWORK_H_
109 void progress(
int percent,
const char* action);
111 void progressf(
int percent,
const char* fmt, ...);
123 void metric(
const char* name,
double value,
const char* unit =
"",
bool higherIsBetter =
true);
126 void detail(
const char* fmt, ...);
130 void fail(
const char* fmt, ...);
175class UnitTestRunner {
187 const char* description =
"",
const char* category =
"",
188 bool inDefaultRun =
true);
204 bool hasTest(
const char* name)
const;
206 std::vector<std::string>
testNames()
const;
215 bool runOne(
const char* name);
220 void hookMetric(
const char* name,
double value,
const char* unit,
bool higherIsBetter);
232 bool runRecords(std::vector<UnitTestRecord*>& records);
240 void clearProgressLine();
246 void writeResults(
const std::vector<UnitTestRecord*>& records,
247 uint64 totalUs,
int passed,
int failed);
249 void loadComparison();
251 bool comparisonValue(
const std::string& key,
double& out)
const;
253 static std::string timestampForFilename(uint64 t);
255 std::vector<UnitTestRecord> tests;
263 std::string progressPath;
266 std::string compareFile;
267 std::string outputFile;
268 std::string outputDir;
271 std::map<std::string, double> compareMetrics;
Platform/compiler detection and base portability macros for all of CMSDK.
Core fixed-width scalar typedefs and the PsyType / PsyContext hierarchical identifiers.
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
std::vector< std::string > testNames() const
void hookDetail(const char *text)
Hook behind unittest::detail() for the current test.
void setForkPerTest(bool v)
Run each test in its own process (default: on where supported) so crashes/hangs are isolated.
void setWriteJSON(bool v)
Enable/disable writing the perf JSON file at all.
void listTests() const
Print the registered tests (name, category, description) to stdout.
void hookProgress(int percent, const char *action)
Hook behind unittest::progress()/progressf() for the current test.
void setOutputFile(const char *path)
Set an explicit perf JSON output path (overrides the timestamped default).
bool hasTest(const char *name) const
void hookMetric(const char *name, double value, const char *unit, bool higherIsBetter)
Hook behind unittest::metric() for the current test.
static UnitTestRunner & instance()
Access the singleton (created on first use).
void setVerbose(bool v)
Enable/disable verbose diagnostics (unittest::detail output).
bool hookVerbose() const
Hook behind unittest::verbose().
void setCompareFile(const char *path)
Set a previous perf JSON file to compare metrics against.
bool runAll()
Run every test marked inDefaultRun.
void registerTest(const char *name, UnitTestFunc func, const char *description="", const char *category="", bool inDefaultRun=true)
Register a test with the runner.
bool runOne(const char *name)
Run a single named test in isolation.
void setOutputDir(const char *dir)
Set the directory for the default (timestamped + latest) output files.
void hookFail(const char *text)
Hook behind unittest::fail() for the current test.
Recursive mutual-exclusion lock, optionally named for cross-process use.
bool(* UnitTestFunc)()
Signature every unit test uses.
API used by the body of a unit test.
void fail(const char *fmt,...)
Set an explanatory reason shown on the FAIL line.
void progressf(int percent, const char *fmt,...)
printf-style variant of progress().
void metric(const char *name, double value, const char *unit="", bool higherIsBetter=true)
Record a performance metric.
void detail(const char *fmt,...)
Verbose-only indented diagnostic line (shown only when verbose=1).
void progress(int percent, const char *action)
Report progress with a short description of the current action.
One recorded performance metric of a test run.
bool higherIsBetter
Delta-direction hint for compare mode.
std::string unit
Unit label (e.g.
double value
Measured value.
std::string name
Metric name (unique within the test).
Registration and result record for a single unit test.
UnitTestFunc func
The test function itself.
UnitTestRecord()
Default: unregistered, not run, in the default suite.
bool passed
Outcome (only meaningful when ran).
std::vector< UnitTestMetric > metrics
Metrics recorded via unittest::metric().
std::string failReason
Reason set by the test via unittest::fail() (printed immediately).
bool inDefaultRun
Included when running the whole suite (test=cmsdk).
std::string description
One-line human description.
std::string name
Canonical name, used by test=<name>.
std::string endNote
Framework outcome note (timed out / crashed / no test function).
std::string category
Grouping label (e.g.
uint64 durationUs
Wall-clock duration in microseconds.
bool ran
True once the runner attempted this test.