CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::UnitTestRunner Class Reference

The test runner (process-wide singleton). More...

#include <UnitTestFramework.h>

Public Member Functions

void registerTest (const char *name, UnitTestFunc func, const char *description="", const char *category="", bool inDefaultRun=true)
 Register a test with the runner.
void setVerbose (bool v)
 Enable/disable verbose diagnostics (unittest::detail output).
void setCompareFile (const char *path)
 Set a previous perf JSON file to compare metrics against.
void setOutputFile (const char *path)
 Set an explicit perf JSON output path (overrides the timestamped default).
void setOutputDir (const char *dir)
 Set the directory for the default (timestamped + latest) output files.
void setWriteJSON (bool v)
 Enable/disable writing the perf JSON file at all.
void setForkPerTest (bool v)
 Run each test in its own process (default: on where supported) so crashes/hangs are isolated.
bool hasTest (const char *name) const
std::vector< std::string > testNames () const
void listTests () const
 Print the registered tests (name, category, description) to stdout.
bool runAll ()
 Run every test marked inDefaultRun.
bool runOne (const char *name)
 Run a single named test in isolation.
void hookProgress (int percent, const char *action)
 Hook behind unittest::progress()/progressf() for the current test.
void hookMetric (const char *name, double value, const char *unit, bool higherIsBetter)
 Hook behind unittest::metric() for the current test.
void hookDetail (const char *text)
 Hook behind unittest::detail() for the current test.
void hookFail (const char *text)
 Hook behind unittest::fail() for the current test.
bool hookVerbose () const
 Hook behind unittest::verbose().

Static Public Member Functions

static UnitTestRunner & instance ()
 Access the singleton (created on first use).

Detailed Description

The test runner (process-wide singleton).

Holds the registry of tests, executes them (optionally each in a forked child process so a crash or hang cannot take down the suite), renders the console output, writes the perf JSON and computes compare-mode deltas.

Note
Thread-safe for the hook* callbacks via an internal mutex; registration and execution are expected from a single thread.

Definition at line 175 of file UnitTestFramework.h.

Member Function Documentation

◆ hasTest()

bool cmlabs::UnitTestRunner::hasTest ( const char * name) const
Returns
true if name is a registered test.

Definition at line 183 of file UnitTestFramework.cpp.

References stricmp.

Referenced by cmlabs::IsCMSDKTest().

◆ hookDetail()

void cmlabs::UnitTestRunner::hookDetail ( const char * text)

Hook behind unittest::detail() for the current test.

Definition at line 269 of file UnitTestFramework.cpp.

References UT_INDENT.

Referenced by cmlabs::unittest::detail().

◆ hookFail()

void cmlabs::UnitTestRunner::hookFail ( const char * text)

Hook behind unittest::fail() for the current test.

Definition at line 276 of file UnitTestFramework.cpp.

References UT_INDENT.

Referenced by cmlabs::unittest::fail().

◆ hookMetric()

void cmlabs::UnitTestRunner::hookMetric ( const char * name,
double value,
const char * unit,
bool higherIsBetter )

◆ hookProgress()

void cmlabs::UnitTestRunner::hookProgress ( int percent,
const char * action )

Hook behind unittest::progress()/progressf() for the current test.

Definition at line 214 of file UnitTestFramework.cpp.

References UT_NAME_WIDTH.

Referenced by cmlabs::unittest::progress(), and cmlabs::unittest::progressf().

◆ hookVerbose()

bool cmlabs::UnitTestRunner::hookVerbose ( ) const

Hook behind unittest::verbose().

Definition at line 212 of file UnitTestFramework.cpp.

Referenced by cmlabs::unittest::verbose().

◆ instance()

◆ listTests()

void cmlabs::UnitTestRunner::listTests ( ) const

Print the registered tests (name, category, description) to stdout.

Definition at line 196 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests(), and runOne().

◆ registerTest()

void cmlabs::UnitTestRunner::registerTest ( const char * name,
UnitTestFunc func,
const char * description = "",
const char * category = "",
bool inDefaultRun = true )

Register a test with the runner.

Parameters
nameCanonical test name (used by test=<name>); duplicates are ignored.
funcThe test function.
descriptionOne-line human description.
categoryGrouping label shown in listings.
inDefaultRunInclude in the full-suite run (test=cmsdk).

Definition at line 153 of file UnitTestFramework.cpp.

References cmlabs::UnitTestRecord::category, cmlabs::UnitTestRecord::description, cmlabs::UnitTestRecord::func, cmlabs::UnitTestRecord::inDefaultRun, and cmlabs::UnitTestRecord::name.

Referenced by cmlabs::Register_Base64_Tests(), cmlabs::Register_Bitmap_Tests(), cmlabs::Register_ComponentData_Tests(), cmlabs::Register_ComponentMemory_Tests(), cmlabs::Register_ControlMessage_Tests(), cmlabs::Register_DataMessage_Tests(), cmlabs::Register_Hash_Tests(), cmlabs::Register_HTML_Tests(), cmlabs::Register_MathClasses_Tests(), cmlabs::Register_MemoryManager_Tests(), cmlabs::Register_MemoryRequestServer_Tests(), cmlabs::Register_MessageIndex_Tests(), cmlabs::Register_MovingAverage_Tests(), cmlabs::Register_NetworkManager_Tests(), cmlabs::Register_NetworkProtocols_Tests(), cmlabs::Register_Observations_Tests(), cmlabs::Register_ProcessMemory_Tests(), cmlabs::Register_PsyTime_Tests(), cmlabs::Register_RequestClient_Tests(), cmlabs::Register_RequestGateway_Tests(), cmlabs::Register_RESTParser_Tests(), cmlabs::Register_Stats_Tests(), cmlabs::Register_Subscriptions_Tests(), cmlabs::Register_TemporalMemory_Tests(), cmlabs::Register_ThreadManager_Tests(), cmlabs::Register_Utils_Tests(), and cmlabs::Register_VantagePoints_Tests().

◆ runAll()

bool cmlabs::UnitTestRunner::runAll ( )

Run every test marked inDefaultRun.

Returns
true only if every test that ran passed.

Definition at line 576 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ runOne()

bool cmlabs::UnitTestRunner::runOne ( const char * name)

Run a single named test in isolation.

Returns
true only if it passed.

Definition at line 594 of file UnitTestFramework.cpp.

References listTests(), cmlabs::UnitTestRecord::name, and stricmp.

Referenced by cmlabs::RunCMSDKTests().

◆ setCompareFile()

void cmlabs::UnitTestRunner::setCompareFile ( const char * path)

Set a previous perf JSON file to compare metrics against.

Definition at line 177 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ setForkPerTest()

void cmlabs::UnitTestRunner::setForkPerTest ( bool v)

Run each test in its own process (default: on where supported) so crashes/hangs are isolated.

Definition at line 181 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ setOutputDir()

void cmlabs::UnitTestRunner::setOutputDir ( const char * dir)

Set the directory for the default (timestamped + latest) output files.

Definition at line 179 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ setOutputFile()

void cmlabs::UnitTestRunner::setOutputFile ( const char * path)

Set an explicit perf JSON output path (overrides the timestamped default).

Definition at line 178 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ setVerbose()

void cmlabs::UnitTestRunner::setVerbose ( bool v)

Enable/disable verbose diagnostics (unittest::detail output).

Definition at line 176 of file UnitTestFramework.cpp.

Referenced by cmlabs::RunCMSDKTests().

◆ setWriteJSON()

void cmlabs::UnitTestRunner::setWriteJSON ( bool v)

Enable/disable writing the perf JSON file at all.

Definition at line 180 of file UnitTestFramework.cpp.

◆ testNames()

std::vector< std::string > cmlabs::UnitTestRunner::testNames ( ) const
Returns
the names of all registered tests.

Definition at line 190 of file UnitTestFramework.cpp.


The documentation for this class was generated from the following files: