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

API used by the body of a unit test. More...

Functions

void progress (int percent, const char *action)
 Report progress with a short description of the current action.
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 fail (const char *fmt,...)
 Set an explanatory reason shown on the FAIL line.
bool verbose ()
static std::string ut_vformat (const char *fmt, va_list args)

Detailed Description

API used by the body of a unit test.

These free functions operate on the test the runner is currently executing (dispatched via UnitTestRunner's hook* methods).

Function Documentation

◆ detail()

◆ fail()

void cmlabs::unittest::fail ( const char * fmt,
... )

◆ metric()

void cmlabs::unittest::metric ( const char * name,
double value,
const char * unit = "",
bool higherIsBetter = true )

Record a performance metric.

Parameters
nameMetric name (unique within the test).
valueMeasured value.
unitUnit label, e.g. "msg/s" or "us".
higherIsBetterWhether a larger value is an improvement (e.g. throughput) or a smaller one is (e.g. latency) - used only to label the delta direction in compare mode. Printed as an indented subline under the test's PASS line and written to the performance JSON file. In compare mode the previous value and the %-change are appended.

Definition at line 819 of file UnitTestFramework.cpp.

References cmlabs::UnitTestRunner::hookMetric(), and cmlabs::UnitTestRunner::instance().

Referenced by cmlabs::Base64_UnitTest(), cmlabs::Hash_UnitTest(), cmlabs::html::HTML_UnitTest(), cmlabs::MathClasses_UnitTest(), cmlabs::NetworkProtocols_UnitTest(), cmlabs::Observations_UnitTest(), cmlabs::ProcessMemory::PerfTest(), cmlabs::PsyTime_UnitTest(), cmlabs::Test_RequestClient(), cmlabs::Bitmap::UnitTest(), cmlabs::ControlMessage::UnitTest(), cmlabs::MemoryManager::UnitTest(), cmlabs::MemoryRequestServer::UnitTest(), cmlabs::MessageIndex::UnitTest(), cmlabs::MovingAverage::UnitTest(), cmlabs::NetworkManager::UnitTest(), cmlabs::ProcessMemory::UnitTest(), cmlabs::RequestGateway::UnitTest(), cmlabs::RequestQueue::UnitTest(), cmlabs::RESTParser::UnitTest(), cmlabs::TemporalMemory::UnitTest(), cmlabs::ThreadManager::UnitTest(), cmlabs::TriggerSpec::UnitTest(), cmlabs::VantagePoints::UnitTest(), cmlabs::utils::UnitTest_Timer(), and cmlabs::NetworkManager::UnitTestHTTP().

◆ progress()

void cmlabs::unittest::progress ( int percent,
const char * action )

Report progress with a short description of the current action.

Parameters
percentProgress 0..100.
actionShort description of the current phase. On a terminal this redraws a single overwriting line; when output is not a terminal (piped/redirected) it is suppressed so logs stay clean.

Definition at line 807 of file UnitTestFramework.cpp.

References cmlabs::UnitTestRunner::hookProgress(), and cmlabs::UnitTestRunner::instance().

Referenced by cmlabs::Base64_UnitTest(), cmlabs::Hash_UnitTest(), cmlabs::html::HTML_UnitTest(), cmlabs::MathClasses_UnitTest(), cmlabs::NetworkProtocols_UnitTest(), cmlabs::Observations_UnitTest(), cmlabs::ProcessMemory::PerfTest(), cmlabs::PsyTime_UnitTest(), cmlabs::MemoryManager::ShmUnitTest(), cmlabs::Test_RequestClient(), cmlabs::Bitmap::UnitTest(), cmlabs::ComponentData::UnitTest(), cmlabs::ComponentMemory::UnitTest(), cmlabs::ControlMessage::UnitTest(), cmlabs::DataMessage::UnitTest(), cmlabs::MemoryManager::UnitTest(), cmlabs::MemoryRequestServer::UnitTest(), cmlabs::MessageIndex::UnitTest(), cmlabs::MovingAverage::UnitTest(), cmlabs::NetworkManager::UnitTest(), cmlabs::ProcessMemory::UnitTest(), cmlabs::RequestGateway::UnitTest(), cmlabs::RequestQueue::UnitTest(), cmlabs::RESTParser::UnitTest(), cmlabs::Stats::UnitTest(), cmlabs::TemporalMemory::UnitTest(), cmlabs::ThreadManager::UnitTest(), cmlabs::TriggerSpec::UnitTest(), cmlabs::VantagePoints::UnitTest(), cmlabs::utils::UnitTest_Timer(), cmlabs::utils::UnitTest_Utils(), cmlabs::NetworkManager::UnitTestDelayedConnect(), cmlabs::NetworkManager::UnitTestHTTP(), and cmlabs::NetworkManager::WebsocketTest().

◆ progressf()

void cmlabs::unittest::progressf ( int percent,
const char * fmt,
... )

printf-style variant of progress().

See also
progress()

Definition at line 811 of file UnitTestFramework.cpp.

References cmlabs::UnitTestRunner::hookProgress(), cmlabs::UnitTestRunner::instance(), and ut_vformat().

◆ ut_vformat()

std::string cmlabs::unittest::ut_vformat ( const char * fmt,
va_list args )
static

Definition at line 799 of file UnitTestFramework.cpp.

References cmlabs::utils::StringFormatVA().

Referenced by detail(), fail(), and progressf().

◆ verbose()

bool cmlabs::unittest::verbose ( )
Returns
true when verbose diagnostics are enabled.

Definition at line 840 of file UnitTestFramework.cpp.

References cmlabs::UnitTestRunner::hookVerbose(), and cmlabs::UnitTestRunner::instance().