-
Notifications
You must be signed in to change notification settings - Fork 0
/
sb_sendrecv_test.c
607 lines (504 loc) · 31.9 KB
/
sb_sendrecv_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/**
* @file
*
* Functional test of SB transmit/receive APIs
* CFE_SB_TransmitMsg - Transmit a message.
* CFE_SB_ReceiveBuffer - Receive a message from a software bus pipe.
* CFE_SB_AllocateMessageBuffer - Get a buffer pointer to use for "zero copy" SB sends.
* CFE_SB_ReleaseMessageBuffer - Release an unused "zero copy" buffer pointer.
* CFE_SB_TransmitBuffer - Transmit a buffer.
*/
#include "cfe_test.h"
#include "cfe_msgids.h"
#include "cfe_test_msgids.h"
#define CFE_FT_STRINGBUF_SIZE 12
/* A simple command message */
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader;
uint64 CmdPayload;
} CFE_FT_TestCmdMessage_t;
/* A simple telemetry message */
typedef struct
{
CFE_MSG_TelemetryHeader_t TelemetryHeader;
uint64 TlmPayload;
} CFE_FT_TestTlmMessage_t;
/* A message intended to be (overall) larger than the CFE_MISSION_SB_MAX_SB_MSG_SIZE */
typedef union
{
CFE_MSG_Message_t Hdr;
CFE_MSG_CommandHeader_t CmdHeader;
CFE_MSG_TelemetryHeader_t TlmHeader;
uint8 MaxSize[CFE_MISSION_SB_MAX_SB_MSG_SIZE + 16];
char StringBuffer[CFE_FT_STRINGBUF_SIZE];
} CFE_FT_TestBigMessage_t;
/*
* This test procedure should be agnostic to specific MID values, but it should
* not overlap/interfere with real MIDs used by other apps.
*/
static const CFE_SB_MsgId_t CFE_FT_CMD_MSGID = CFE_SB_MSGID_WRAP_VALUE(CFE_TEST_CMD_MID);
static const CFE_SB_MsgId_t CFE_FT_TLM_MSGID = CFE_SB_MSGID_WRAP_VALUE(CFE_TEST_HK_TLM_MID);
static CFE_FT_TestBigMessage_t CFE_FT_BigMsg;
void TestBasicTransmitRecv(void)
{
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_FT_TestCmdMessage_t CmdMsg;
CFE_FT_TestTlmMessage_t TlmMsg;
CFE_SB_MsgId_t MsgId;
CFE_MSG_SequenceCount_t Seq1, Seq2;
CFE_SB_Buffer_t * MsgBuf;
const CFE_FT_TestCmdMessage_t *CmdPtr;
const CFE_FT_TestTlmMessage_t *TlmPtr;
memset(&CmdMsg, 0, sizeof(CmdMsg));
memset(&TlmMsg, 0, sizeof(TlmMsg));
UtPrintf("Testing: CFE_SB_TransmitMsg");
/* Setup, create a pipe and subscribe (one cmd, one tlm) */
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 5, "TestPipe1"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId2, 5, "TestPipe2"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId1, CFE_SB_DEFAULT_QOS, 3), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_TLM_MSGID, PipeId2, CFE_SB_DEFAULT_QOS, 3), CFE_SUCCESS);
/* Initialize the message content */
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(CmdMsg.CommandHeader), CFE_FT_CMD_MSGID, sizeof(CmdMsg)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(TlmMsg.TelemetryHeader), CFE_FT_TLM_MSGID, sizeof(TlmMsg)), CFE_SUCCESS);
CFE_MSG_SetSequenceCount(CFE_MSG_PTR(CmdMsg.CommandHeader), 11);
CFE_MSG_SetSequenceCount(CFE_MSG_PTR(TlmMsg.TelemetryHeader), 21);
/* Sending with sequence update should ignore the sequence in the msg struct */
CmdMsg.CmdPayload = 0x0c0ffee;
TlmMsg.TlmPayload = 0x0d00d1e;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(TlmMsg.TelemetryHeader), true), CFE_SUCCESS);
CmdMsg.CmdPayload = 0x1c0ffee;
TlmMsg.TlmPayload = 0x1d00d1e;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(TlmMsg.TelemetryHeader), true), CFE_SUCCESS);
/* Sending without sequence update should use the sequence in the msg struct */
CmdMsg.CmdPayload = 0x2c0ffee;
TlmMsg.TlmPayload = 0x2d00d1e;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), false), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(TlmMsg.TelemetryHeader), false), CFE_SUCCESS);
/* Sending again should trigger MsgLimit errors on the pipe, however the call still returns CFE_SUCCESS */
CmdMsg.CmdPayload = 0x3c0ffee;
TlmMsg.TlmPayload = 0x3d00d1e;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(TlmMsg.TelemetryHeader), true), CFE_SUCCESS);
/* Attempt to send a msg which does not have a valid msgid */
memset(&CFE_FT_BigMsg, 0xFF, sizeof(CFE_FT_BigMsg));
CFE_MSG_SetSize(&CFE_FT_BigMsg.Hdr, sizeof(CFE_MSG_Message_t) + 4);
CFE_Assert_STATUS_STORE(CFE_SB_TransmitMsg(&CFE_FT_BigMsg.Hdr, true));
if (!CFE_Assert_STATUS_MAY_BE(CFE_SUCCESS))
{
CFE_Assert_STATUS_MUST_BE(CFE_SB_BAD_ARGUMENT);
}
/* Attempt to send a msg which is too big */
CFE_MSG_SetSize(&CFE_FT_BigMsg.Hdr, sizeof(CFE_FT_BigMsg));
CFE_MSG_SetMsgId(&CFE_FT_BigMsg.Hdr, CFE_FT_CMD_MSGID);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(&CFE_FT_BigMsg.Hdr, true), CFE_SB_MSG_TOO_BIG);
/* Attempt to send a msg which is NULL */
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(NULL, true), CFE_SB_BAD_ARGUMENT);
UtPrintf("Testing: CFE_SB_ReceiveBuffer");
/* off nominal / bad arguments */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, CFE_SB_INVALID_PIPE, 100), CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(NULL, PipeId1, 100), CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, -100), CFE_SB_BAD_ARGUMENT);
/*
* Note, the CFE_SB_TransmitMsg now adheres to the "IsOrigination" flag.
* Thus, the sequence numbers should come back with the value from the Route (1-2)
* rather than the value the message was filled with initially.
*
* Note this also utilizes the CFE_SB_PEND_FOREVER flag - if working correctly,
* there should be a message in the queue, so it should not block.
*/
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x0c0ffee);
UtAssert_UINT32_EQ(Seq1, 1);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x1c0ffee);
UtAssert_UINT32_EQ(Seq1, 2);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x2c0ffee);
UtAssert_UINT32_EQ(Seq1, 11);
/* Final should not be in the pipe, should have been rejected due to MsgLim */
/* Must not use CFE_SB_PEND_FOREVER here, as this will cause the test to block */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SB_TIME_OUT);
/*
* For TLM, the CFE_SB_TransmitMsg obeys the "IncrementSequence" flag.
* Thus, first message gets the reference point, next message should be one more.
*/
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_TLM_MSGID);
TlmPtr = (const CFE_FT_TestTlmMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(TlmPtr->TlmPayload, 0x0d00d1e);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq2), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_TLM_MSGID);
TlmPtr = (const CFE_FT_TestTlmMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(TlmPtr->TlmPayload, 0x1d00d1e);
UtAssert_UINT32_EQ(Seq2, CFE_MSG_GetNextSequenceCount(Seq1));
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq2), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_TLM_MSGID);
TlmPtr = (const CFE_FT_TestTlmMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(TlmPtr->TlmPayload, 0x2d00d1e);
UtAssert_UINT32_EQ(Seq2, 21);
/* Final should not be in the pipe, should have been rejected due to MsgLim */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, 100), CFE_SB_TIME_OUT);
/* Cleanup */
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId2), CFE_SUCCESS);
}
/*
* Test distribution/broadcasting features (MsgLimit/PipeDepth enforcement, etc)
*
* Important to verify that although some receive pipes may have errors/limits, it should not affect
* the transmit side nor should it affect delivery to pipes that do not have limit errors.
*/
void TestMsgBroadcast(void)
{
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId3 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId4 = CFE_SB_INVALID_PIPE;
CFE_FT_TestCmdMessage_t CmdMsg;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_SB_Buffer_t * MsgBuf1;
CFE_SB_Buffer_t * MsgBuf2;
CFE_SB_Buffer_t * MsgBuf3;
CFE_SB_Buffer_t * MsgBuf4;
const CFE_FT_TestCmdMessage_t *CmdPtr;
memset(&CmdMsg, 0, sizeof(CmdMsg));
UtPrintf("Testing: MsgLimit enforcement");
/* Setup - subscribe same MsgId to multiple different pipes with different limits */
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 3, "TestPipe1"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId2, 3, "TestPipe2"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId3, 3, "TestPipe3"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId4, 5, "TestPipe4"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId1, CFE_SB_DEFAULT_QOS, 1), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId2, CFE_SB_DEFAULT_QOS, 2), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId3, CFE_SB_DEFAULT_QOS, 4), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId4, CFE_SB_DEFAULT_QOS, 6), CFE_SUCCESS);
/* Initialize the message content */
UtAssert_INT32_EQ(CFE_MSG_Init(CFE_MSG_PTR(CmdMsg.CommandHeader), CFE_FT_CMD_MSGID, sizeof(CmdMsg)), CFE_SUCCESS);
/* Make unique content in each message. Sending should always be successful. */
CmdMsg.CmdPayload = 0xbabb1e00;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
CmdMsg.CmdPayload = 0xbabb1e01;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
CmdMsg.CmdPayload = 0xbabb1e02;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
CmdMsg.CmdPayload = 0xbabb1e03;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
/* Now receive 1st message from Pipes, actual msg should appear on all (no limit violations here) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* All pipes should have gotten the same actual buffer */
UtAssert_ADDRESS_EQ(MsgBuf1, MsgBuf2);
UtAssert_ADDRESS_EQ(MsgBuf1, MsgBuf3);
UtAssert_ADDRESS_EQ(MsgBuf1, MsgBuf4);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf1->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf1;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e00);
/* Now receive 2nd message from Pipes, should not appear on PipeId 1 due to MsgLimit */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* All pipes should have gotten the same actual buffer */
UtAssert_ADDRESS_EQ(MsgBuf2, MsgBuf3);
UtAssert_ADDRESS_EQ(MsgBuf2, MsgBuf4);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf2->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf2;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e01);
/* Now receive 3rd message from Pipes, should not appear on PipeId 1 or 2 due to MsgLimit */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* All pipes should have gotten the same actual buffer */
UtAssert_ADDRESS_EQ(MsgBuf3, MsgBuf4);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf3->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf3;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e02);
/* Now receive 4th message from Pipes, should only appear on PipeId4 due PipeDepth limit on 3 */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf4->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf4;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e03);
UtPrintf("Testing: Unsubscribe single pipe");
/* Now unsubscribe only one of the pipes, and confirm no messages delivered to that pipe */
UtAssert_INT32_EQ(CFE_SB_Unsubscribe(CFE_FT_CMD_MSGID, PipeId2), CFE_SUCCESS);
/* Send two more messages */
CmdMsg.CmdPayload = 0xbabb1e04;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
CmdMsg.CmdPayload = 0xbabb1e05;
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdMsg.CommandHeader), true), CFE_SUCCESS);
/* poll all pipes again, message should appear on all except PipeId2 (Unsubscribed) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* All pipes should have gotten the same actual buffer */
UtAssert_ADDRESS_EQ(MsgBuf1, MsgBuf3);
UtAssert_ADDRESS_EQ(MsgBuf1, MsgBuf4);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf1->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf1;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e04);
/* poll all pipes again, message should appear on all except PipeId1 (MsgLim) or PipeId2 (Unsubscribed) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SUCCESS);
/* All pipes should have gotten the same actual buffer */
UtAssert_ADDRESS_EQ(MsgBuf3, MsgBuf4);
/* Confirm content */
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf3->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf3;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0xbabb1e05);
/* poll all pipes again, all should be empty now */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf1, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf2, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf3, PipeId3, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf4, PipeId4, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
/* Cleanup */
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId2), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId3), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId4), CFE_SUCCESS);
}
/* This is a variant of the message transmit API that does not copy */
void TestZeroCopyTransmitRecv(void)
{
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_SB_Buffer_t * CmdBuf;
CFE_SB_Buffer_t * TlmBuf;
CFE_SB_Buffer_t * MsgBuf;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_SequenceCount_t SeqCmd1;
CFE_MSG_SequenceCount_t SeqTlm1;
CFE_MSG_SequenceCount_t SeqCmd2;
CFE_MSG_SequenceCount_t SeqTlm2;
/* Setup, create a pipe and subscribe (one cmd, one tlm) */
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 5, "TestPipe1"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId2, 5, "TestPipe2"), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_CMD_MSGID, PipeId1, CFE_SB_DEFAULT_QOS, 3), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_SubscribeEx(CFE_FT_TLM_MSGID, PipeId2, CFE_SB_DEFAULT_QOS, 3), CFE_SUCCESS);
UtPrintf("Testing: CFE_SB_AllocateMessageBuffer");
/* Confirm bad size rejection */
UtAssert_NULL(CFE_SB_AllocateMessageBuffer(CFE_MISSION_SB_MAX_SB_MSG_SIZE + 1));
/* Nominal */
UtAssert_NOT_NULL(CmdBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestCmdMessage_t)));
UtAssert_NOT_NULL(TlmBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestTlmMessage_t)));
UtPrintf("Testing: CFE_SB_ReleaseMessageBuffer");
/* allocate a buffer but then discard it without sending */
UtAssert_NOT_NULL(MsgBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_MSG_Message_t) + 4));
UtAssert_INT32_EQ(CFE_SB_ReleaseMessageBuffer(MsgBuf), CFE_SUCCESS);
/* Attempt to double-release, should fail validation */
UtAssert_INT32_EQ(CFE_SB_ReleaseMessageBuffer(MsgBuf), CFE_SB_BUFFER_INVALID);
/* Other bad input checking */
UtAssert_INT32_EQ(CFE_SB_ReleaseMessageBuffer(NULL), CFE_SB_BAD_ARGUMENT);
UtPrintf("Testing: CFE_SB_TransmitBuffer");
/* Initialize the message content */
UtAssert_INT32_EQ(CFE_MSG_Init(&CmdBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_FT_TestCmdMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_Init(&TlmBuf->Msg, CFE_FT_TLM_MSGID, sizeof(CFE_FT_TestTlmMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(TlmBuf, true), CFE_SUCCESS);
/* Attempt to send a buffer which has been released */
UtAssert_NOT_NULL(MsgBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_MSG_Message_t) + 4));
UtAssert_INT32_EQ(CFE_MSG_Init(&MsgBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_MSG_Message_t) + 4), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReleaseMessageBuffer(MsgBuf), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(MsgBuf, true), CFE_SB_BUFFER_INVALID);
/* Attempt to send a NULL buffer */
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(NULL, true), CFE_SB_BAD_ARGUMENT);
UtPrintf("Testing: CFE_SB_ReceiveBuffer");
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
UtAssert_ADDRESS_EQ(MsgBuf, CmdBuf); /* should be the same actual buffer (not a copy) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_TLM_MSGID);
UtAssert_ADDRESS_EQ(MsgBuf, TlmBuf); /* should be the same actual buffer (not a copy) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
/* Attempt to send a msg of maximum size */
UtAssert_NOT_NULL(CmdBuf = CFE_SB_AllocateMessageBuffer(CFE_MISSION_SB_MAX_SB_MSG_SIZE));
/* First initialize to indicate its even bigger than the max (should fail to transmit) */
UtAssert_INT32_EQ(CFE_MSG_Init(&CmdBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_FT_BigMsg)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, true), CFE_SB_MSG_TOO_BIG);
/* reducing size should make it work */
UtAssert_INT32_EQ(CFE_MSG_SetSize(&CmdBuf->Msg, CFE_MISSION_SB_MAX_SB_MSG_SIZE), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_ADDRESS_EQ(MsgBuf, CmdBuf); /* should be the same actual buffer (not a copy) */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SB_NO_MESSAGE);
UtPrintf("Testing: CFE_SB_TransmitBuffer sequence number updates");
/* Send a set of messages with and without sequence number update flag */
UtAssert_NOT_NULL(CmdBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestCmdMessage_t)));
UtAssert_NOT_NULL(TlmBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestTlmMessage_t)));
UtAssert_INT32_EQ(CFE_MSG_Init(&CmdBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_FT_TestCmdMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_Init(&TlmBuf->Msg, CFE_FT_TLM_MSGID, sizeof(CFE_FT_TestTlmMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&CmdBuf->Msg, 1234), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&TlmBuf->Msg, 5678), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(TlmBuf, true), CFE_SUCCESS);
/* Receive and get initial sequence count */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqCmd1), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqCmd1, 6); /* NOTE: commands now honor "Update" flag */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqTlm1), CFE_SUCCESS);
/* Send a second message also with increment = true and confirm value */
UtAssert_NOT_NULL(CmdBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestCmdMessage_t)));
UtAssert_NOT_NULL(TlmBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestTlmMessage_t)));
UtAssert_INT32_EQ(CFE_MSG_Init(&CmdBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_FT_TestCmdMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_Init(&TlmBuf->Msg, CFE_FT_TLM_MSGID, sizeof(CFE_FT_TestTlmMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&CmdBuf->Msg, 1234), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&TlmBuf->Msg, 5678), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, true), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(TlmBuf, true), CFE_SUCCESS);
/* Receive and get current sequence count */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqCmd2), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqCmd2, 7); /* NOTE: commands now honor "Update" flag */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqTlm2), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqTlm2, CFE_MSG_GetNextSequenceCount(SeqTlm1)); /* should be +1 from the previous */
/* Send a third message also with increment = false and confirm value */
UtAssert_NOT_NULL(CmdBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestCmdMessage_t)));
UtAssert_NOT_NULL(TlmBuf = CFE_SB_AllocateMessageBuffer(sizeof(CFE_FT_TestTlmMessage_t)));
UtAssert_INT32_EQ(CFE_MSG_Init(&CmdBuf->Msg, CFE_FT_CMD_MSGID, sizeof(CFE_FT_TestCmdMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_Init(&TlmBuf->Msg, CFE_FT_TLM_MSGID, sizeof(CFE_FT_TestTlmMessage_t)), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&CmdBuf->Msg, 1234), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_SetSequenceCount(&TlmBuf->Msg, 5678), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(CmdBuf, false), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_TransmitBuffer(TlmBuf, false), CFE_SUCCESS);
/* Receive and get sequence count, should NOT be incremented from previous */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqCmd1), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqCmd1, 1234); /* should match initialized value */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqTlm1), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqTlm1, 5678); /* should match initialized value */
/* Cleanup */
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId2), CFE_SUCCESS);
}
void TestMiscMessageUtils(void)
{
char TestString[CFE_FT_STRINGBUF_SIZE + 4];
const char RefString1[] = "abc";
const char RefString2[] = "defg";
memset(&CFE_FT_BigMsg, 'x', sizeof(CFE_FT_BigMsg));
memset(TestString, 'y', sizeof(TestString));
/* nominal CFE_SB_MessageStringGet */
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, CFE_FT_BigMsg.StringBuffer, RefString1, sizeof(TestString),
sizeof(CFE_FT_BigMsg.StringBuffer)),
CFE_FT_STRINGBUF_SIZE);
/* The result should be null terminated, even if the input was not */
UtAssert_ZERO(TestString[CFE_FT_STRINGBUF_SIZE]);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), CFE_FT_BigMsg.StringBuffer,
sizeof(CFE_FT_BigMsg.StringBuffer));
/* No default */
memset(&CFE_FT_BigMsg, 'w', sizeof(CFE_FT_BigMsg));
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, CFE_FT_BigMsg.StringBuffer, NULL, sizeof(TestString),
sizeof(CFE_FT_BigMsg.StringBuffer)),
CFE_FT_STRINGBUF_SIZE);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), CFE_FT_BigMsg.StringBuffer,
sizeof(CFE_FT_BigMsg.StringBuffer));
UtAssert_ZERO(TestString[CFE_FT_STRINGBUF_SIZE]);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), CFE_FT_BigMsg.StringBuffer,
sizeof(CFE_FT_BigMsg.StringBuffer));
/* Check if the input is empty */
memset(&CFE_FT_BigMsg, 0, sizeof(CFE_FT_BigMsg));
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, CFE_FT_BigMsg.StringBuffer, RefString1, sizeof(TestString),
sizeof(CFE_FT_BigMsg.StringBuffer)),
sizeof(RefString1) - 1);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), RefString1, sizeof(RefString1));
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, NULL, RefString2, sizeof(TestString), 0),
sizeof(RefString2) - 1);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), RefString2, sizeof(RefString2));
/* Neither source nor default */
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, NULL, NULL, sizeof(TestString), 0), CFE_SUCCESS);
UtAssert_STRINGBUF_EQ(TestString, sizeof(TestString), "", 1);
/* bad inputs */
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(NULL, CFE_FT_BigMsg.StringBuffer, RefString1, sizeof(TestString),
sizeof(CFE_FT_BigMsg.StringBuffer)),
CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_SB_MessageStringGet(TestString, CFE_FT_BigMsg.StringBuffer, RefString1, 0,
sizeof(CFE_FT_BigMsg.StringBuffer)),
CFE_SB_BAD_ARGUMENT);
/* nominal CFE_SB_MessageStringSet */
memset(TestString, 'z', sizeof(TestString));
UtAssert_INT32_EQ(CFE_SB_MessageStringSet(CFE_FT_BigMsg.StringBuffer, TestString,
sizeof(CFE_FT_BigMsg.StringBuffer), sizeof(TestString)),
CFE_FT_STRINGBUF_SIZE);
UtAssert_STRINGBUF_EQ(TestString, CFE_FT_STRINGBUF_SIZE, CFE_FT_BigMsg.StringBuffer, CFE_FT_STRINGBUF_SIZE);
/* The result should NOT be null terminated (fixed size msg string does not need it) */
UtAssert_INT32_EQ(CFE_FT_BigMsg.StringBuffer[sizeof(CFE_FT_BigMsg.StringBuffer) - 1], 'z');
/* Should not have overwritten anything beyond the fixed buffer */
UtAssert_ZERO(CFE_FT_BigMsg.MaxSize[sizeof(CFE_FT_BigMsg.StringBuffer)]);
/* bad inputs */
UtAssert_INT32_EQ(CFE_SB_MessageStringSet(NULL, TestString, sizeof(CFE_FT_BigMsg.StringBuffer), sizeof(TestString)),
CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_SB_MessageStringSet(CFE_FT_BigMsg.StringBuffer, NULL, sizeof(CFE_FT_BigMsg.StringBuffer),
sizeof(TestString)),
CFE_SB_BAD_ARGUMENT);
}
void SBSendRecvTestSetup(void)
{
UtTest_Add(TestBasicTransmitRecv, NULL, NULL, "Test Basic Transmit/Receive");
UtTest_Add(TestZeroCopyTransmitRecv, NULL, NULL, "Test Zero Copy Transmit/Receive");
UtTest_Add(TestMsgBroadcast, NULL, NULL, "Test Msg Broadcast");
UtTest_Add(TestMiscMessageUtils, NULL, NULL, "Test Miscellaneous Message Utility APIs");
}