-
Notifications
You must be signed in to change notification settings - Fork 207
/
ut_support.c
794 lines (690 loc) · 21.1 KB
/
ut_support.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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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://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: ut_support.c
**
** Purpose:
** Unit test stubs
**
** Notes:
** Minimal work is done, only what is required for unit testing
**
*/
/*
** Includes
*/
#include "ut_support.h"
#include <string.h>
/*
** Global variables
*/
uint8 UT_Endianess;
static char UT_appname[80];
static char UT_subsys[5];
static uint32 UT_AppID;
static uint32 UT_LastCDSSize = 0;
typedef union
{
long long int AlignLong;
long double AlignDbl;
void *AlignPtr;
char Content[128 * 1024];
} UT_Buffer_t;
static UT_Buffer_t UT_CFE_ES_MemoryPool;
static UT_Buffer_t UT_CDS_Data;
static UT_Buffer_t UT_SyslogBuffer;
static UT_Buffer_t UT_PrintfBuffer;
static union
{
UT_Buffer_t Buff;
CFE_ES_ResetData_t ResetData;
} UT_CFE_ES_ResetData;
static uint16 UT_SendEventHistory[UT_EVENT_HISTORY_SIZE];
static uint16 UT_SendTimedEventHistory[UT_EVENT_HISTORY_SIZE];
static uint16 UT_SendEventAppIDHistory[UT_EVENT_HISTORY_SIZE * 10];
extern int32 dummy_function(void);
/*
** Functions
*/
/*
** Initialize unit test
*/
void UT_Init(const char *subsys)
{
int8 i;
/* Copy the application name for later use */
strncpy(UT_subsys, subsys, sizeof(UT_subsys)-1);
UT_subsys[sizeof(UT_subsys)-1] = 0;
snprintf(UT_appname, 80, "ut_cfe_%s", subsys);
/* Convert to upper case */
for (i = 0; i < strlen(UT_subsys); ++i)
{
if (UT_subsys[i] >= 'a' && UT_subsys[i] <= 'z')
{
UT_subsys[i] = (UT_subsys[i] - 'a') + 'A';
}
}
UT_InitData();
/*
* NOTE: There are some UT cases in TBL that are dependent on
* the endianness of the local CPU. This "endian check" exists
* to provide hints to the test code.
*
* All endian-specific code should be replaced with endian-neutral
* code in future versions. This check will be removed in a future
* version once that is complete. No new test code should use this.
*/
int32 EndianCheck = 0x01020304;
if ((*(char *) &EndianCheck) == 0x04)
{
UT_Endianess = UT_LITTLE_ENDIAN;
}
else
{
UT_Endianess = UT_BIG_ENDIAN;
}
}
/*
** Initialize unit test variables
*/
void UT_InitData(void)
{
/*
* Purge all entries in the entire stub table
*/
UT_ResetState(0);
/*
* Set up entries to capture Events and Syslog writes
* These are frequently needed by many tests
*/
UT_SyslogBuffer.AlignLong = 0;
UT_SetDataBuffer(UT_KEY(CFE_ES_WriteToSysLog), &UT_SyslogBuffer, sizeof(UT_SyslogBuffer), false);
UT_PrintfBuffer.AlignLong = 0;
UT_SetDataBuffer(UT_KEY(OS_printf), &UT_PrintfBuffer, sizeof(UT_PrintfBuffer), false);
/*
* Set up the CFE_ES reset area
*/
UT_SetDataBuffer(UT_KEY(CFE_PSP_GetResetArea), &UT_CFE_ES_ResetData, sizeof(UT_CFE_ES_ResetData), false);
/*
* Set up the CDS area
*/
UT_SetCDSSize(UT_LastCDSSize);
/*
* Set up for the CFE_SB_RcvMsg() call.
*
* The existing test cases assume that this will return success once,
* followed by a timeout response followed by a different error.
*
* Specific test cases may provide an actual message buffer to return for
* the first call, or they may override this default behavior entirely.
*
* The default behavior of the CFE_SB_RcvMsg stub is to return success with a zero-ed out
* buffer returned to the caller.
*/
UT_SetDeferredRetcode(UT_KEY(CFE_SB_RcvMsg), 2, CFE_SB_TIME_OUT);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_RcvMsg), 3, -1);
/*
* Set up CFE_ES_GetAppName() and friends
* This should return the UT_appname
*/
UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppName), (uint8*)UT_appname, sizeof(UT_appname), false);
UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppID), (uint8*)&UT_AppID, sizeof(UT_AppID), false);
/*
* Reset the OSAL stubs to the default state
*/
OS_API_Init();
UT_ClearEventHistory();
UT_ResetPoolBufferIndex();
}
void UT_ResetCDS(void)
{
memset(&UT_CDS_Data, 0, sizeof(UT_CDS_Data));
}
/*
** Reset pool buffer index
*/
void UT_ResetPoolBufferIndex(void)
{
/*
* Initialize the buffer which ES mempool will allocate from
* Set the whole memory space to a pattern.
*/
UT_ResetState(UT_KEY(CFE_ES_GetPoolBuf));
UT_SetDataBuffer(UT_KEY(CFE_ES_GetPoolBuf), &UT_CFE_ES_MemoryPool, sizeof(UT_CFE_ES_MemoryPool), false);
}
/*
** Output a text string
*/
void UT_Text(const char *text)
{
UtPrintf("%s\n", text);
}
/*
** Output single test's pass/fail status
*/
void UT_Report(const char *file, uint32 line, bool test, const char *fun_name,
const char *info)
{
UtAssertEx(test, UtAssert_GetContext(), file, line, "%s - %s", fun_name,
info);
}
/*
** Calls the specified "task pipe" function
**
** This first sets up the various stubs according to the test case,
** then invokes the pipe function.
*/
void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_MsgPtr_t), CFE_SB_MsgPtr_t Msg, uint32 MsgSize,
UT_TaskPipeDispatchId_t DispatchId)
{
/*
* set the fields within the buffer itself.
* a lot of the CFE code requires this as it uses
* macros (not stubs) to read this info direct from
* the buffer.
*/
CFE_SB_SetTotalMsgLength(Msg, MsgSize);
CFE_SB_SetMsgId(Msg, DispatchId.MsgId);
CFE_SB_SetCmdCode(Msg, DispatchId.CommandCode);
/*
* Finally, call the actual task pipe requested.
*/
TaskPipeFunc(Msg);
}
int32 UT_SoftwareBusSnapshotHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
{
UT_SoftwareBusSnapshot_Entry_t *Snapshot = UserObj;
const CFE_SB_Msg_t *MsgPtr;
if (Context->ArgCount > 0)
{
MsgPtr = Context->ArgPtr[0];
}
else
{
MsgPtr = NULL;
}
if (MsgPtr != NULL && Snapshot != NULL &&
CFE_SB_MsgId_Equal(Snapshot->MsgId, CFE_SB_GetMsgId((CFE_SB_MsgPtr_t)MsgPtr)))
{
++Snapshot->Count;
if (Snapshot->SnapshotSize > 0 && Snapshot->SnapshotBuffer != NULL)
{
memcpy(Snapshot->SnapshotBuffer, &MsgPtr->Byte[Snapshot->SnapshotOffset],
Snapshot->SnapshotSize);
}
}
return StubRetcode;
}
/*
** Set the application ID returned by unit test stubs
*/
void UT_SetAppID(int32 AppID_in)
{
UT_AppID = AppID_in;
}
/*
** Set the return code of CFE_PSP_GetResetArea and the data validation
** signature
*/
void UT_SetStatusBSPResetArea(int32 status, uint32 Signature, uint32 ClockSignal)
{
UT_CFE_ES_ResetData.ResetData.TimeResetVars.Signature = Signature;
UT_CFE_ES_ResetData.ResetData.TimeResetVars.ClockSignal = ClockSignal;
if (status != 0)
{
UT_SetForceFail(UT_KEY(CFE_PSP_GetResetArea), status);
}
else
{
UT_ClearForceFail(UT_KEY(CFE_PSP_GetResetArea));
}
}
/*
** Set the contents of the buffer to read
*/
void UT_SetReadBuffer(void *Buff, int NumBytes)
{
UT_SetDataBuffer(UT_KEY(OS_read), Buff, NumBytes, true);
}
/*
** Set the contents of the header to read
*/
void UT_SetReadHeader(void *Hdr, int NumBytes)
{
UT_SetDataBuffer(UT_KEY(CFE_FS_ReadHeader), Hdr, NumBytes, true);
}
/*
** Set the dummy function return code
*/
void UT_SetDummyFuncRtn(int Return)
{
UT_SetForceFail(UT_KEY(dummy_function), Return);
}
/*
** Set the size of the ES reset area
*/
void UT_SetSizeofESResetArea(int32 Size)
{
UT_ResetState(UT_KEY(CFE_PSP_GetResetArea));
if (Size > 0)
{
if (Size > sizeof(UT_CFE_ES_ResetData))
{
UtAssert_Abort("Reset area size too large");
Size = sizeof(UT_CFE_ES_ResetData);
}
UT_SetDataBuffer(UT_KEY(CFE_PSP_GetResetArea), &UT_CFE_ES_ResetData, Size, false);
}
}
/*
** Set the CDS size returned by the BSP
*/
uint8* UT_SetCDSSize(int32 Size)
{
UT_ResetState(UT_KEY(CFE_PSP_GetCDSSize));
UT_ResetState(UT_KEY(CFE_PSP_ReadFromCDS));
UT_ResetState(UT_KEY(CFE_PSP_WriteToCDS));
if (Size <= 0)
{
UT_LastCDSSize = 0;
return NULL;
}
if (Size > sizeof(UT_CDS_Data))
{
UtAssert_Abort("Size of CDS too large");
Size = sizeof(UT_CDS_Data);
}
UT_SetDataBuffer(UT_KEY(CFE_PSP_GetCDSSize), &UT_CDS_Data, Size, false);
UT_SetDataBuffer(UT_KEY(CFE_PSP_ReadFromCDS), &UT_CDS_Data, Size, false);
UT_SetDataBuffer(UT_KEY(CFE_PSP_WriteToCDS), &UT_CDS_Data, Size, false);
UT_LastCDSSize = Size;
return (uint8*)UT_CDS_Data.Content;
}
/*
** Set BSP time
*/
void UT_SetBSP_Time(uint32 seconds, uint32 microsecs)
{
OS_time_t BSP_Time;
BSP_Time.seconds = seconds;
BSP_Time.microsecs = microsecs;
UT_SetDataBuffer(UT_KEY(CFE_PSP_GetTime), &BSP_Time, sizeof(BSP_Time), true);
}
void UT_ClearEventHistory(void)
{
UT_ResetState(UT_KEY(CFE_EVS_SendEvent));
UT_ResetState(UT_KEY(CFE_EVS_SendEventWithAppID));
UT_ResetState(UT_KEY(CFE_EVS_SendTimedEvent));
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), UT_SendEventHistory, sizeof(UT_SendEventHistory), false);
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendTimedEvent), UT_SendTimedEventHistory, sizeof(UT_SendTimedEventHistory), false);
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEventWithAppID), UT_SendEventAppIDHistory, sizeof(UT_SendEventAppIDHistory), false);
}
static bool UT_CheckEventHistoryFromFunc(UT_EntryKey_t Func, uint16 EventIDToSearchFor)
{
bool Result = false;
uint32 Position;
uint32 MaxSize;
uint16 *EvBuf;
UT_GetDataBuffer(Func, (void**)&EvBuf, &MaxSize, &Position);
if (EvBuf != NULL && MaxSize > 0)
{
while (Position > 0)
{
if (*EvBuf == EventIDToSearchFor)
{
Result = true;
break;
}
++EvBuf;
--Position;
}
}
return Result;
}
/*
** Search the event history for a specified event ID
*/
bool UT_EventIsInHistory(uint16 EventIDToSearchFor)
{
return (UT_CheckEventHistoryFromFunc(UT_KEY(CFE_EVS_SendEvent),EventIDToSearchFor) ||
UT_CheckEventHistoryFromFunc(UT_KEY(CFE_EVS_SendEventWithAppID),EventIDToSearchFor) ||
UT_CheckEventHistoryFromFunc(UT_KEY(CFE_EVS_SendTimedEvent),EventIDToSearchFor));
}
/*
** Return number of events issued
*/
uint16 UT_GetNumEventsSent(void)
{
uint16 Total = 0;
uint32 Position;
uint32 MaxSize;
void *EvBuf;
UT_GetDataBuffer(UT_KEY(CFE_EVS_SendEvent), &EvBuf, &MaxSize, &Position);
Total += Position / sizeof(uint16);
UT_GetDataBuffer(UT_KEY(CFE_EVS_SendEventWithAppID), &EvBuf, &MaxSize, &Position);
Total += Position / sizeof(uint16);
UT_GetDataBuffer(UT_KEY(CFE_EVS_SendTimedEvent), &EvBuf, &MaxSize, &Position);
Total += Position / sizeof(uint16);
return Total;
}
/*
** Display the contents of a packet
*/
void UT_DisplayPkt(CFE_SB_MsgPtr_t ptr, uint32 size)
{
uint8 *BytePtr = (uint8 *) ptr;
uint32 i;
uint32 BufSize = UT_MAX_MESSAGE_LENGTH;
char DisplayMsg[UT_MAX_MESSAGE_LENGTH];
char *msgPtr = DisplayMsg;
DisplayMsg[0] = '\0';
for (i = 0; i < size && BufSize > 3; i++)
{
snprintf(msgPtr, BufSize, "%02x ", *BytePtr);
msgPtr += 3;
BufSize -= 3;
++BytePtr;
}
UT_Text(DisplayMsg);
}
/*
** Return the actual packet length
*/
int16 UT_GetActualPktLenField(CFE_SB_MsgPtr_t MsgPtr)
{
return ( ( MsgPtr->CCSDS.Pri.Length[0] << 8) + MsgPtr->CCSDS.Pri.Length[1] );
}
/*
** Return the actual command code
*/
uint8 UT_GetActualCmdCodeField(CFE_SB_MsgPtr_t MsgPtr)
{
/*
* This function is used to "go around" the structure field
* definitions and access macro definitions, to look for the
* bits of the function code in the exact spot where we are
* expecting to find them.
*
* The CCSDS Command Function Code is defined as living in
* the first byte of the command secondary header (mask 0x7F)
* NOTE: this definition is endian agnostic
*
* CCSDS version 1 - cmd sec header is offset 6 bytes
* CCSDS Version 2 - cmd sec header is offset 10 bytes
*/
uint8 Index; /* Field index (in BYTES) */
uint8 *w = (uint8 *)MsgPtr;
#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
Index = 6;
#else
Index = 10;
#endif
return (w[Index] & 0x7F);
}
CFE_ES_ResetData_t *UT_GetResetDataPtr(void)
{
return &UT_CFE_ES_ResetData.ResetData;
}
/*
** Compare two strings using printf-style conversion specifiers.
**
** Determines if the TestStr could have been an output from a printf-style call
** using FormatStr. Common conversions specifiers in FormatStr are recognized:
** %c, %d, %f, %F, %g, %G, %i, %u, %s, %p, %x, %X, and %%
**
** To keep it simple this just skips over the conversion specifier entirely,
** it does not validate whether the content of the string could have come from
** that conversion specifier or not. In essence any conversion specifier is
** treated as a wildcard that matches any string.
**
** HOWEVER - this could be enhanced in the future, if necessary, to actually
** perform that validation by e.g. passing the string to "sscanf()" or similar
** and checking if the reverse conversion was successful.
**
** NOTE this logic is not foolproof - particularly where %s is in use, as the
** content of the string could alias the next part of the format string.
** This does not seem to be an issue for the strings generated by CFE.
**
** But on the upside this concession avoids a far more complicated issue of
** needing a fully-fledged implementation of printf in the OS_printf stub.
*/
static int UT_StrCmpFormatStr(const char *FormatStr, const char *TestStr, uint32 FormatLength, uint32 TestLength)
{
const char *ChunkStart;
const char *ChunkEnd;
const char *TestStart;
int WildCard;
int MatchGood;
size_t ChunkLen;
/* Step through each character in both strings */
ChunkStart = FormatStr;
TestStart = TestStr;
WildCard = 1;
MatchGood = 1;
while (FormatLength > 0)
{
if (*ChunkStart == '%')
{
/* At a Conversion specifier - Find the END of it */
do
{
--FormatLength;
++ChunkStart;
}
while (FormatLength > 0 && strchr("%cdfFgGiuspxX ",*ChunkStart) == NULL);
if (FormatLength == 0)
{
/* Invalid format string */
MatchGood = 0;
break;
}
if (*ChunkStart != '%')
{
WildCard = 1;
++ChunkStart;
--FormatLength;
}
else if (TestLength > 0 && *TestStart == '%')
{
MatchGood = 1;
++TestStart;
--TestLength;
}
else
{
/* Insufficient length on TestString */
MatchGood = 0;
break;
}
}
else
{
/* Matchable content - Find the NEXT conversion specifier in the format string */
MatchGood = 0;
ChunkEnd = memchr(ChunkStart, '%', FormatLength);
if (ChunkEnd != NULL)
{
ChunkLen = ChunkEnd - ChunkStart;
}
else
{
ChunkLen = FormatLength;
}
while (TestLength >= ChunkLen)
{
if (memcmp(ChunkStart, TestStart, ChunkLen) == 0)
{
MatchGood = 1;
break;
}
if (!WildCard)
{
break;
}
++TestStart;
--TestLength;
}
if (!MatchGood)
{
break;
}
WildCard = 0;
ChunkStart += ChunkLen;
TestStart += ChunkLen;
TestLength -= ChunkLen;
FormatLength -= ChunkLen;
}
}
return MatchGood;
}
/*
* A string comparison function that will match exact strings only
* (Printf style conversion strings are compared literally)
*/
static int UT_StrCmpExact(const char *RefStr, const char *TestStr, uint32 RefLength, uint32 TestLength)
{
return (RefLength == TestLength && memcmp(RefStr, TestStr, RefLength) == 0);
}
static uint32 UT_GetMessageCount(const char *Msg, UT_Buffer_t *Buf,
int (*Comparator)(const char *, const char *, uint32, uint32))
{
uint32 Count = 0;
uint32 MsgLen = strlen(Msg);
char *Start = Buf->Content;
char *End;
while (MsgLen > 0 && Msg[MsgLen-1] == '\n')
{
--MsgLen;
}
while(1)
{
End = strchr(Start, '\n');
if (End == NULL)
{
End = Start + strlen(Start);
}
if (Start == End)
{
break;
}
if (Comparator(Msg, Start, MsgLen, End - Start))
{
++Count;
}
if (*End == 0)
{
break;
}
Start = End + 1;
}
return Count;
}
uint32 UT_SyslogIsInHistory(const char *LogMsgToSearchFor)
{
return UT_GetMessageCount(LogMsgToSearchFor, &UT_SyslogBuffer, UT_StrCmpExact);
}
uint32 UT_PrintfIsInHistory(const char *MsgToSearchFor)
{
return UT_GetMessageCount(MsgToSearchFor, &UT_PrintfBuffer, UT_StrCmpFormatStr);
}
void UT_AddSubTest(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *GroupName, const char *TestName)
{
char CompleteTestName[128];
const char *GroupPtr;
const char *TestPtr;
/* Remove any common prefix between the two names.
* They are often function names that all start with "Test_XXX"
* and this repetitive information just becomes clutter.
*/
GroupPtr = GroupName;
TestPtr = TestName;
while (*GroupPtr != 0 && *GroupPtr == *TestPtr)
{
++GroupPtr;
++TestPtr;
}
/*
* Only break at an underscore(_) to avoid weird effects
*/
while(TestPtr > TestName && *TestPtr != '_')
{
--TestPtr;
}
if (*TestPtr == '_')
{
++TestPtr;
}
/*
* Remove a remaining "Test_" prefix on the group name.
* Again just to remove common repetitive content
*/
GroupPtr = GroupName;
if (strncmp(GroupPtr, "Test_", 5) == 0)
{
GroupPtr += 5;
}
(void)snprintf(CompleteTestName, sizeof(CompleteTestName), "%s.%s", GroupPtr, TestPtr);
/*
* Note that UtTest_Add() does not copy the string - it retains the passed-in pointer.
* Therefore it must be duplicated.
*
* This isn't an issue on Linux as the memory is freed when the process exits, but
* might be an issue on VxWorks.
*/
UtTest_Add(Test, Setup, Teardown, strdup(CompleteTestName));
}
void UT_SETUP_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
UtAssertEx(FnRet == CFE_SUCCESS, UTASSERT_CASETYPE_TSF, FileName, LineNum, "%s - Setup - %s returned %ld",
TestName, FnName, (long int)FnRet);
}
void UT_ASSERT_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
UtAssertEx(FnRet == CFE_SUCCESS, UtAssert_GetContext(), FileName, LineNum, "%s - %s returned %ld, expected CFE_SUCCESS",
TestName, FnName, (long int)FnRet);
}
void UT_ASSERT_EQ_impl(const char *FileName, int LineNum,
const char *FnName, int32 FnRet, const char *ExpName, int32 Exp)
{
UtAssertEx(FnRet == Exp, UtAssert_GetContext(), FileName, LineNum, "%s - value %ld, expected %s[%ld]",
FnName, (long)FnRet, ExpName, (long)Exp);
}
void UT_ASSERT_TRUE_impl(const char *FileName, int LineNum, const char *TestName,
const char *ExpName, bool Exp)
{
UtAssertEx(Exp, UtAssert_GetContext(), FileName, LineNum, "%s - %s",
TestName, ExpName);
}
void UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int32 CntExp)
{
int32 CntSent = UT_GetNumEventsSent();
UtAssertEx(CntSent == CntExp, UtAssert_GetContext(), FileName, LineNum, "%s - event count (sent %ld, expected %ld)",
TestName, (long int)CntSent, (long int)CntExp);
}
void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
{
UtAssertEx(UT_EventIsInHistory(EvtId), UtAssert_GetContext(), FileName, LineNum, "%s - sent event %s [%ld]",
TestName, EvtName, (long int)EvtId);
}
void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
UtAssertEx(FnRet == CFE_SUCCESS, UTASSERT_CASETYPE_TTF, FileName, LineNum, "%s - Teardown failed (%s returned %ld)",
TestName, FnName, (long int)FnRet);
}