17 header->command = command;
75 const uint16 command = 7;
76 const uint64 from = 0x1122334455667788ULL;
77 const uint64 to = 0x99AABBCCDDEEFF00ULL;
82 if (msg.
getFrom() != from) {
unittest::fail(
"ControlMessage test: getFrom mismatch\n");
return false; }
83 if (msg.
getTo() != to) {
unittest::fail(
"ControlMessage test: getTo mismatch\n");
return false; }
95 if (!msg.
setStatus(0xBEEF)) {
unittest::fail(
"ControlMessage test: setStatus returned false\n");
return false; }
96 if (msg.
getStatus() != 0xBEEF) {
unittest::fail(
"ControlMessage test: getStatus mismatch after setStatus\n");
return false; }
98 if (msg.
getStatus() != 0) {
unittest::fail(
"ControlMessage test: getStatus mismatch after setStatus(0)\n");
return false; }
104 const char payload[] = {
'C',
'M',
'D',
'A',
'T',
'A' };
105 const uint32 payloadSize =
sizeof(payload);
110 unittest::fail(
"ControlMessage test: payload getSize mismatch\n");
return false;
114 if (memcmp(stored, payload, payloadSize) != 0) {
115 unittest::fail(
"ControlMessage test: payload bytes not stored correctly\n");
return false;
122 const char payload[] = { 0x01, 0x02, 0x03, 0x04 };
123 const uint32 payloadSize =
sizeof(payload);
124 ControlMessage orig(99, 0xAAAA, 0xBBBB, (
char*)payload, payloadSize);
129 if (wrapped.
getCommand() != 99) {
unittest::fail(
"ControlMessage test: wrapped getCommand mismatch\n");
return false; }
130 if (wrapped.
getFrom() != 0xAAAA) {
unittest::fail(
"ControlMessage test: wrapped getFrom mismatch\n");
return false; }
131 if (wrapped.
getTo() != 0xBBBB) {
unittest::fail(
"ControlMessage test: wrapped getTo mismatch\n");
return false; }
132 if (wrapped.
getStatus() != 0x1234) {
unittest::fail(
"ControlMessage test: wrapped getStatus mismatch\n");
return false; }
134 unittest::fail(
"ControlMessage test: wrapped getSize mismatch\n");
return false;
137 unittest::fail(
"ControlMessage test: wrapped payload mismatch\n");
return false;
146 if (bad.
getSize() != 0) {
unittest::fail(
"ControlMessage test: NULL getSize != 0\n");
return false; }
148 if (bad.
getTime() != 0) {
unittest::fail(
"ControlMessage test: NULL getTime != 0\n");
return false; }
149 if (bad.
getFrom() != 0) {
unittest::fail(
"ControlMessage test: NULL getFrom != 0\n");
return false; }
150 if (bad.
getTo() != 0) {
unittest::fail(
"ControlMessage test: NULL getTo != 0\n");
return false; }
159 const char payload[] = {
'p',
'e',
'r',
'f' };
162 for (
int i = 0; i < N; i++) {
163 ControlMessage m((uint16)i, (uint64)i, (uint64)(i + 1), (
char*)payload,
sizeof(payload));
168 unittest::metric(
"construct_throughput", (
double)N / us * 1e6,
"msg/s",
true);
169 unittest::detail(
"constructed %d control messages, command checksum %llu", N, acc);
178 "Control message construction, status, payload, raw-buffer round-trip",
"core");
Lightweight internal control/command message used by the Psyclone runtime.
#define VerObj(data)
Extract and verify the cid of a binary object block in one step.
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
Small, dependency-free unit test harness used by all CMSDK object tests.
~ControlMessage()
Destructor.
char * data
The flat message block (ControlMessageHeader + payload); see class notes on ownership.
static bool UnitTest()
Run the built-in self test.
bool setStatus(uint16 status)
Set the status/result code.
ControlMessage(uint16 command, uint64 from, uint64 to, char *data=NULL, uint32 dataSize=0)
Create a new control message.
static UnitTestRunner & instance()
Access the singleton (created on first use).
void registerTest(const char *name, UnitTestFunc func, const char *description="", const char *category="", bool inDefaultRun=true)
Register a test with the runner.
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
void fail(const char *fmt,...)
Set an explanatory reason shown on the FAIL line.
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.
void Register_ControlMessage_Tests()