CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
UnitTestFramework.h File Reference

Small, dependency-free unit test harness used by all CMSDK object tests. More...

#include "Standard.h"
#include "Types.h"
#include "Utils.h"
#include <string>
#include <vector>
#include <map>
Include dependency graph for UnitTestFramework.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cmlabs::UnitTestMetric
 One recorded performance metric of a test run. More...
struct  cmlabs::UnitTestRecord
 Registration and result record for a single unit test. More...
class  cmlabs::UnitTestRunner
 The test runner (process-wide singleton). More...

Namespaces

namespace  cmlabs
namespace  cmlabs::unittest
 API used by the body of a unit test.

Typedefs

typedef bool(* cmlabs::UnitTestFunc) ()
 Signature every unit test uses.

Functions

void cmlabs::unittest::progress (int percent, const char *action)
 Report progress with a short description of the current action.
void cmlabs::unittest::progressf (int percent, const char *fmt,...)
 printf-style variant of progress().
void cmlabs::unittest::metric (const char *name, double value, const char *unit="", bool higherIsBetter=true)
 Record a performance metric.
void cmlabs::unittest::detail (const char *fmt,...)
 Verbose-only indented diagnostic line (shown only when verbose=1).
void cmlabs::unittest::fail (const char *fmt,...)
 Set an explanatory reason shown on the FAIL line.
bool cmlabs::unittest::verbose ()

Detailed Description

Small, dependency-free unit test harness used by all CMSDK object tests.

A self-contained (no external libraries) harness that gives every CMSDK object's unit test consistent output, performance recording and comparison against previous runs.

A test is any function bool Func() that:

  • calls unittest::progress(pct, action) to drive the live progress line
  • calls unittest::metric(name, value, unit) to record/print performance
  • calls unittest::detail(fmt, ...) for verbose-only diagnostics
  • returns true on success, false on failure (optionally unittest::fail() first to set a reason)

Tests are registered with the runner (see RegisterAllCMSDKTests in UnitTest_CMSDK.cpp) and driven by Psyclone:

Psyclone test=cmsdk run all tests
Psyclone test=<objectname> run a single test in isolation
Psyclone test=cmsdk compare=<oldfile> show deltas vs a previous run
Psyclone test=cmsdk verbose=1 show verbose diagnostics
Psyclone test=cmsdk out=<file> override perf JSON output path

Definition in file UnitTestFramework.h.