-
Notifications
You must be signed in to change notification settings - Fork 204
/
es_UT.c
5723 lines (4884 loc) · 273 KB
/
es_UT.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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************
* 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://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:
** es_UT.c
**
** Purpose:
** Executive Services unit test
**
** References:
** 1. cFE Application Developers Guide
** 2. unit test standard 092503
** 3. C Coding Standard 102904
**
** Notes:
** 1. This is unit test code only, not for use in flight
**
*/
/*
** Includes
*/
#include "es_UT.h"
#include "target_config.h"
#include "cfe_config.h"
#define ES_UT_CDS_BLOCK_SIZE 16
/*
* A size which meets the minimum CDS size
* requirements for the implementation, but
* not much larger.
*/
#define ES_UT_CDS_SMALL_TEST_SIZE (56 * 1024)
/*
* A size which has room for actual allocations
*/
#define ES_UT_CDS_LARGE_TEST_SIZE (128 * 1024)
extern CFE_ES_Global_t CFE_ES_Global;
int32 dummy_function(void);
/*
** Global variables
*/
/*
* Pointer to reset data that will be re-configured/preserved across calls to ES_ResetUnitTest()
*/
static CFE_ES_ResetData_t *ES_UT_PersistentResetData = NULL;
/* Buffers to support memory pool testing */
typedef union
{
CFE_ES_PoolAlign_t Align; /* make aligned */
uint8 Data[300];
} CFE_ES_GMP_DirectBuffer_t;
typedef struct
{
CFE_ES_GenPoolBD_t BD;
CFE_ES_PoolAlign_t Align; /* make aligned */
uint8 Spare; /* make unaligned */
uint8 Data[(sizeof(CFE_ES_GenPoolBD_t) * 4) + 157]; /* oddball size */
} CFE_ES_GMP_IndirectBuffer_t;
CFE_ES_GMP_DirectBuffer_t UT_MemPoolDirectBuffer;
CFE_ES_GMP_IndirectBuffer_t UT_MemPoolIndirectBuffer;
/* Create a startup script buffer for a maximum of 5 lines * 80 chars/line */
char StartupScript[MAX_STARTUP_SCRIPT];
/* Normal dispatching registers the MsgID+CC in order to follow a
* certain path through a series of switch statements */
#define ES_UT_MID_DISPATCH(intf) \
.Method = UT_TaskPipeDispatchMethod_MSG_ID_CC, .MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_ES_##intf##_MID)
#define ES_UT_MSG_DISPATCH(intf, cmd) ES_UT_MID_DISPATCH(intf), UT_TPD_SETSIZE(CFE_ES_##cmd)
#define ES_UT_CC_DISPATCH(intf, cc, cmd) ES_UT_MSG_DISPATCH(intf, cmd), UT_TPD_SETCC(cc)
#define ES_UT_ERROR_DISPATCH(intf, cc, err) ES_UT_MID_DISPATCH(intf), UT_TPD_SETCC(cc), UT_TPD_SETERR(err)
/* NOTE: Automatic formatting of this table tends to make it harder to read. */
/* clang-format off */
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_NOOP_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_NOOP_CC, NoopCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_RESET_COUNTERS_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_RESET_COUNTERS_CC, ResetCountersCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_RESTART_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_RESTART_CC, RestartCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_START_APP_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_START_APP_CC, StartAppCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_STOP_APP_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_STOP_APP_CC, StopAppCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_RESTART_APP_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_RESTART_APP_CC, RestartAppCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_RELOAD_APP_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_RELOAD_APP_CC, ReloadAppCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_QUERY_ONE_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_QUERY_ONE_CC, QueryOneCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_QUERY_ALL_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_QUERY_ALL_CC, QueryAllCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_QUERY_ALL_TASKS_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_QUERY_ALL_TASKS_CC, QueryAllTasksCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_CLEAR_SYS_LOG_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_CLEAR_SYS_LOG_CC, ClearSysLogCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_WRITE_SYS_LOG_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_WRITE_SYS_LOG_CC, WriteSysLogCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_OVER_WRITE_SYS_LOG_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_OVER_WRITE_SYS_LOG_CC, OverWriteSysLogCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_CLEAR_ER_LOG_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_CLEAR_ER_LOG_CC, ClearERLogCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_WRITE_ER_LOG_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_WRITE_ER_LOG_CC, WriteERLogCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_START_PERF_DATA_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_START_PERF_DATA_CC, StartPerfDataCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_STOP_PERF_DATA_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_STOP_PERF_DATA_CC, StopPerfDataCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_SET_PERF_FILTER_MASK_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_SET_PERF_FILTER_MASK_CC, SetPerfFilterMaskCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_SET_PERF_TRIGGER_MASK_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_SET_PERF_TRIGGER_MASK_CC, SetPerfTriggerMaskCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_RESET_PR_COUNT_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_RESET_PR_COUNT_CC, ResetPRCountCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_SET_MAX_PR_COUNT_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_SET_MAX_PR_COUNT_CC, SetMaxPRCountCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_DELETE_CDS_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_DELETE_CDS_CC, DeleteCDSCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_SEND_MEM_POOL_STATS_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_SEND_MEM_POOL_STATS_CC, SendMemPoolStatsCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC =
{ ES_UT_CC_DISPATCH(CMD, CFE_ES_DUMP_CDS_REGISTRY_CC, DumpCDSRegistryCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_SEND_HK =
{ ES_UT_MSG_DISPATCH(SEND_HK, SendHkCmd) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_INVALID_LENGTH =
{ ES_UT_ERROR_DISPATCH(CMD, 0, CFE_STATUS_WRONG_MSG_LENGTH) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_INVALID_CC =
{ ES_UT_ERROR_DISPATCH(CMD, -1, CFE_STATUS_BAD_COMMAND_CODE) };
/* clang-format on */
/*
** Functions
*/
CFE_ResourceId_t ES_UT_MakeAppIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up AppID values in a manner similar to FSW.
* Real apps should never do this. */
return CFE_ResourceId_FromInteger(ArrayIdx + CFE_ES_APPID_BASE);
}
CFE_ResourceId_t ES_UT_MakeTaskIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up TaskID values in a manner similar to FSW.
* Real apps should never do this. */
uint32 Base;
/* The base to use depends on whether STRICT mode is enabled or not */
#ifndef CFE_RESOURCEID_STRICT //_MODE
Base = CFE_ES_TASKID_BASE;
#else
Base = 0x40010000; /* note this is NOT the same as the normal OSAL task ID base */
#endif
return CFE_ResourceId_FromInteger(ArrayIdx + Base);
}
CFE_ResourceId_t ES_UT_MakeLibIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up LibID values in a manner similar to FSW.
* Real apps should never do this. */
return CFE_ResourceId_FromInteger(ArrayIdx + CFE_ES_LIBID_BASE);
}
CFE_ResourceId_t ES_UT_MakeCounterIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up CounterID values in a manner similar to FSW.
* Real apps should never do this. */
return CFE_ResourceId_FromInteger(ArrayIdx + CFE_ES_COUNTID_BASE);
}
CFE_ResourceId_t ES_UT_MakePoolIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up PoolID values in a manner similar to FSW.
* Real apps should never do this. */
return CFE_ResourceId_FromInteger(ArrayIdx + CFE_ES_POOLID_BASE);
}
CFE_ResourceId_t ES_UT_MakeCDSIdForIndex(uint32 ArrayIdx)
{
/* UT hack - make up CDSID values in a manner similar to FSW.
* Real apps should never do this. */
return CFE_ResourceId_FromInteger(ArrayIdx + CFE_ES_CDSBLOCKID_BASE);
}
/*
* A local stub that can serve as the user function for testing ES tasks
*/
void ES_UT_TaskFunction(void)
{
UT_DEFAULT_IMPL(ES_UT_TaskFunction);
}
/* Local function to test CFE_ES_SysLog_vsnprintf */
void ES_UT_SysLog_snprintf(char *Buffer, size_t BufferSize, const char *SpecStringPtr, ...)
{
va_list ap;
va_start(ap, SpecStringPtr);
CFE_ES_SysLog_vsnprintf(Buffer, BufferSize, SpecStringPtr, ap);
va_end(ap);
}
void ES_UT_FillBuffer(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
char * PrintBuffer = UT_Hook_GetArgValueByName(Context, "PrintBuffer", char *);
uint32 Size = *((uint32 *)UserObj);
memset(PrintBuffer, ' ', Size - 1);
PrintBuffer[Size - 1] = 0;
}
/*
* Helper function to assemble basic bits of info into the "CFE_ES_ModuleLoadParams_t" struct
*/
void ES_UT_SetupModuleLoadParams(CFE_ES_ModuleLoadParams_t *Params, const char *FileName, const char *EntryName)
{
char Empty = 0;
if (FileName == NULL)
{
FileName = &Empty;
}
if (EntryName == NULL)
{
EntryName = &Empty;
}
strncpy(Params->FileName, FileName, sizeof(Params->FileName));
strncpy(Params->InitSymbolName, EntryName, sizeof(Params->InitSymbolName));
}
/*
* Helper function to assemble basic bits of info into the "CFE_ES_AppStartParams_t" struct
*/
void ES_UT_SetupAppStartParams(CFE_ES_AppStartParams_t *Params, const char *FileName, const char *EntryName,
size_t StackSize, CFE_ES_TaskPriority_Atom_t Priority,
CFE_ES_ExceptionAction_Enum_t ExceptionAction)
{
ES_UT_SetupModuleLoadParams(&Params->BasicInfo, FileName, EntryName);
Params->MainTaskInfo.StackSize = StackSize;
Params->MainTaskInfo.Priority = Priority;
Params->ExceptionAction = ExceptionAction;
}
/*
* Helper function to setup a single app ID in the given state, along with
* a main task ID. A pointer to the App and Task record is output so the
* record can be modified
*/
void ES_UT_SetupSingleAppId(CFE_ES_AppType_Enum_t AppType, CFE_ES_AppState_Enum_t AppState, const char *AppName,
CFE_ES_AppRecord_t **OutAppRec, CFE_ES_TaskRecord_t **OutTaskRec)
{
osal_id_t UtOsalId = OS_OBJECT_ID_UNDEFINED;
CFE_ResourceId_t UtTaskId;
CFE_ResourceId_t UtAppId;
CFE_ES_AppRecord_t * LocalAppPtr;
CFE_ES_TaskRecord_t *LocalTaskPtr;
OS_TaskCreate(&UtOsalId, "UT", NULL, OSAL_TASK_STACK_ALLOCATE, 0, 0, 0);
UtTaskId = CFE_RESOURCEID_UNWRAP(CFE_ES_TaskId_FromOSAL(UtOsalId));
UtAppId = CFE_ES_Global.LastAppId;
CFE_ES_Global.LastAppId = CFE_ResourceId_FromInteger(CFE_ResourceId_ToInteger(UtAppId) + 1);
LocalTaskPtr = CFE_ES_LocateTaskRecordByID(CFE_ES_TASKID_C(UtTaskId));
LocalAppPtr = CFE_ES_LocateAppRecordByID(CFE_ES_APPID_C(UtAppId));
CFE_ES_TaskRecordSetUsed(LocalTaskPtr, UtTaskId);
CFE_ES_AppRecordSetUsed(LocalAppPtr, UtAppId);
LocalTaskPtr->AppId = CFE_ES_AppRecordGetID(LocalAppPtr);
LocalAppPtr->MainTaskId = CFE_ES_TaskRecordGetID(LocalTaskPtr);
LocalAppPtr->AppState = AppState;
LocalAppPtr->Type = AppType;
if (AppName)
{
strncpy(LocalAppPtr->AppName, AppName, sizeof(LocalAppPtr->AppName) - 1);
LocalAppPtr->AppName[sizeof(LocalAppPtr->AppName) - 1] = 0;
strncpy(LocalTaskPtr->TaskName, AppName, sizeof(LocalTaskPtr->TaskName) - 1);
LocalTaskPtr->TaskName[sizeof(LocalTaskPtr->TaskName) - 1] = 0;
}
if (OutAppRec)
{
*OutAppRec = LocalAppPtr;
}
if (OutTaskRec)
{
*OutTaskRec = LocalTaskPtr;
}
if (AppType == CFE_ES_AppType_CORE)
{
++CFE_ES_Global.RegisteredCoreApps;
}
if (AppType == CFE_ES_AppType_EXTERNAL)
{
++CFE_ES_Global.RegisteredExternalApps;
OS_ModuleLoad(&UtOsalId, NULL, NULL, 0);
LocalAppPtr->LoadStatus.ModuleId = UtOsalId;
}
++CFE_ES_Global.RegisteredTasks;
}
/*
* Helper function to setup a child task ID associated with the given
* app record. A pointer to the Task record is output so the record
* can be modified
*/
void ES_UT_SetupChildTaskId(const CFE_ES_AppRecord_t *ParentApp, const char *TaskName, CFE_ES_TaskRecord_t **OutTaskRec)
{
osal_id_t UtOsalId = OS_OBJECT_ID_UNDEFINED;
CFE_ES_TaskId_t UtTaskId;
CFE_ES_AppId_t UtAppId;
CFE_ES_TaskRecord_t *LocalTaskPtr;
UtAppId = CFE_ES_AppRecordGetID(ParentApp);
OS_TaskCreate(&UtOsalId, "C", NULL, OSAL_TASK_STACK_ALLOCATE, 0, 0, 0);
UtTaskId = CFE_ES_TaskId_FromOSAL(UtOsalId);
LocalTaskPtr = CFE_ES_LocateTaskRecordByID(UtTaskId);
CFE_ES_TaskRecordSetUsed(LocalTaskPtr, CFE_RESOURCEID_UNWRAP(UtTaskId));
LocalTaskPtr->AppId = UtAppId;
if (TaskName)
{
strncpy(LocalTaskPtr->TaskName, TaskName, sizeof(LocalTaskPtr->TaskName) - 1);
LocalTaskPtr->TaskName[sizeof(LocalTaskPtr->TaskName) - 1] = 0;
}
if (OutTaskRec)
{
*OutTaskRec = LocalTaskPtr;
}
++CFE_ES_Global.RegisteredTasks;
}
/*
* Helper function to setup a single Lib ID. A pointer to the Lib
* record is output so the record can be modified
*/
void ES_UT_SetupSingleLibId(const char *LibName, CFE_ES_LibRecord_t **OutLibRec)
{
CFE_ResourceId_t UtLibId;
CFE_ES_LibRecord_t *LocalLibPtr;
UtLibId = CFE_ES_Global.LastLibId;
CFE_ES_Global.LastLibId = CFE_ResourceId_FromInteger(CFE_ResourceId_ToInteger(UtLibId) + 1);
LocalLibPtr = CFE_ES_LocateLibRecordByID(CFE_ES_LIBID_C(UtLibId));
CFE_ES_LibRecordSetUsed(LocalLibPtr, UtLibId);
if (LibName)
{
strncpy(LocalLibPtr->LibName, LibName, sizeof(LocalLibPtr->LibName) - 1);
LocalLibPtr->LibName[sizeof(LocalLibPtr->LibName) - 1] = 0;
}
if (OutLibRec)
{
*OutLibRec = LocalLibPtr;
}
++CFE_ES_Global.RegisteredLibs;
}
int32 ES_UT_PoolDirectRetrieve(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, CFE_ES_GenPoolBD_t **BdPtr)
{
*BdPtr = (CFE_ES_GenPoolBD_t *)((void *)&UT_MemPoolDirectBuffer.Data[Offset]);
return CFE_SUCCESS;
}
int32 ES_UT_PoolDirectCommit(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, const CFE_ES_GenPoolBD_t *BdPtr)
{
return CFE_SUCCESS;
}
int32 ES_UT_PoolIndirectRetrieve(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, CFE_ES_GenPoolBD_t **BdPtr)
{
memcpy(&UT_MemPoolIndirectBuffer.BD, &UT_MemPoolIndirectBuffer.Data[Offset], sizeof(CFE_ES_GenPoolBD_t));
*BdPtr = &UT_MemPoolIndirectBuffer.BD;
return CFE_SUCCESS;
}
int32 ES_UT_PoolIndirectCommit(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, const CFE_ES_GenPoolBD_t *BdPtr)
{
memcpy(&UT_MemPoolIndirectBuffer.Data[Offset], BdPtr, sizeof(CFE_ES_GenPoolBD_t));
return CFE_SUCCESS;
}
int32 ES_UT_CDSPoolRetrieve(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, CFE_ES_GenPoolBD_t **BdPtr)
{
static CFE_ES_GenPoolBD_t BdBuf;
*BdPtr = &BdBuf;
return CFE_PSP_ReadFromCDS(&BdBuf, Offset, sizeof(BdBuf));
}
int32 ES_UT_CDSPoolCommit(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, const CFE_ES_GenPoolBD_t *BdPtr)
{
return CFE_PSP_WriteToCDS(BdPtr, Offset, sizeof(*BdPtr));
}
/* Commit failure routine for pool coverage testing */
int32 ES_UT_PoolCommitFail(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, const CFE_ES_GenPoolBD_t *BdPtr)
{
return CFE_ES_CDS_ACCESS_ERROR;
}
/* Retrieve failure routine for pool coverage testing */
int32 ES_UT_PoolRetrieveFail(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t Offset, CFE_ES_GenPoolBD_t **BdPtr)
{
return CFE_ES_CDS_ACCESS_ERROR;
}
void ES_UT_SetupMemPoolId(CFE_ES_MemPoolRecord_t **OutPoolRecPtr)
{
CFE_ResourceId_t UtPoolID;
CFE_ES_MemPoolRecord_t *LocalPoolRecPtr;
UtPoolID = CFE_ES_Global.LastMemPoolId;
CFE_ES_Global.LastMemPoolId = CFE_ResourceId_FromInteger(CFE_ResourceId_ToInteger(UtPoolID) + 1);
LocalPoolRecPtr = CFE_ES_LocateMemPoolRecordByID(CFE_ES_MEMHANDLE_C(UtPoolID));
/* in order to validate the size must be nonzero */
LocalPoolRecPtr->Pool.PoolTotalSize = sizeof(UT_MemPoolDirectBuffer.Data);
LocalPoolRecPtr->Pool.PoolMaxOffset = sizeof(UT_MemPoolDirectBuffer.Data);
LocalPoolRecPtr->Pool.Buckets[0].BlockSize = 16;
LocalPoolRecPtr->Pool.NumBuckets = 1;
LocalPoolRecPtr->Pool.Retrieve = ES_UT_PoolDirectRetrieve;
LocalPoolRecPtr->Pool.Commit = ES_UT_PoolDirectCommit;
LocalPoolRecPtr->BaseAddr = (cpuaddr)UT_MemPoolDirectBuffer.Data;
OS_MutSemCreate(&LocalPoolRecPtr->MutexId, NULL, 0);
CFE_ES_MemPoolRecordSetUsed(LocalPoolRecPtr, UtPoolID);
if (OutPoolRecPtr)
{
*OutPoolRecPtr = LocalPoolRecPtr;
}
}
void ES_UT_SetupCDSGlobal(uint32 CDS_Size)
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
UT_SetCDSSize(CDS_Size);
if (CDS_Size > CDS_RESERVED_MIN_SIZE)
{
OS_MutSemCreate(&CDS->GenMutex, "UT", 0);
CDS->TotalSize = CDS_Size;
CDS->DataSize = CDS->TotalSize;
CDS->DataSize -= CDS_RESERVED_MIN_SIZE;
CFE_ES_InitCDSSignatures();
CFE_ES_CreateCDSPool(CDS->DataSize, CDS_POOL_OFFSET);
CFE_ES_InitCDSRegistry();
CFE_ES_Global.CDSIsAvailable = true;
}
}
void ES_UT_SetupSingleCDSRegistry(const char *CDSName, size_t BlockSize, bool IsTable, CFE_ES_CDS_RegRec_t **OutRegRec)
{
CFE_ES_CDS_RegRec_t *LocalRegRecPtr;
CFE_ResourceId_t UtCDSID;
CFE_ES_GenPoolBD_t LocalBD;
size_t UT_CDS_BufferSize;
/* first time this is done, set up the global */
if (!CFE_ES_Global.CDSIsAvailable)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetCDSSize), NULL, &UT_CDS_BufferSize, NULL);
if (UT_CDS_BufferSize > (2 * CFE_ES_CDS_SIGNATURE_LEN))
{
/* Use the CDS buffer from ut_support.c if it was configured */
CFE_ES_Global.CDSVars.Pool.PoolMaxOffset = UT_CDS_BufferSize - CFE_ES_CDS_SIGNATURE_LEN;
CFE_ES_Global.CDSVars.Pool.Retrieve = ES_UT_CDSPoolRetrieve;
CFE_ES_Global.CDSVars.Pool.Commit = ES_UT_CDSPoolCommit;
}
else
{
CFE_ES_Global.CDSVars.Pool.PoolMaxOffset = sizeof(UT_MemPoolIndirectBuffer.Data);
CFE_ES_Global.CDSVars.Pool.Retrieve = ES_UT_PoolIndirectRetrieve;
CFE_ES_Global.CDSVars.Pool.Commit = ES_UT_PoolIndirectCommit;
}
CFE_ES_Global.CDSVars.Pool.Buckets[0].BlockSize = ES_UT_CDS_BLOCK_SIZE;
CFE_ES_Global.CDSVars.Pool.NumBuckets = 1;
CFE_ES_Global.CDSVars.Pool.TailPosition = CFE_ES_CDS_SIGNATURE_LEN;
CFE_ES_Global.CDSVars.Pool.PoolTotalSize =
CFE_ES_Global.CDSVars.Pool.PoolMaxOffset - CFE_ES_Global.CDSVars.Pool.TailPosition;
CFE_ES_Global.CDSIsAvailable = true;
}
UtCDSID = CFE_ES_Global.CDSVars.LastCDSBlockId;
CFE_ES_Global.CDSVars.LastCDSBlockId = CFE_ResourceId_FromInteger(CFE_ResourceId_ToInteger(UtCDSID) + 1);
LocalRegRecPtr = CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHANDLE_C(UtCDSID));
if (CDSName != NULL)
{
strncpy(LocalRegRecPtr->Name, CDSName, sizeof(LocalRegRecPtr->Name) - 1);
LocalRegRecPtr->Name[sizeof(LocalRegRecPtr->Name) - 1] = 0;
}
else
{
LocalRegRecPtr->Name[0] = 0;
}
LocalRegRecPtr->Table = IsTable;
LocalRegRecPtr->BlockOffset = CFE_ES_Global.CDSVars.Pool.TailPosition + sizeof(LocalBD);
LocalRegRecPtr->BlockSize = BlockSize;
LocalBD.CheckBits = CFE_ES_CHECK_PATTERN;
LocalBD.Allocated = CFE_ES_MEMORY_ALLOCATED + 1;
LocalBD.ActualSize = BlockSize;
LocalBD.NextOffset = 0;
CFE_ES_Global.CDSVars.Pool.Commit(&CFE_ES_Global.CDSVars.Pool, CFE_ES_Global.CDSVars.Pool.TailPosition, &LocalBD);
CFE_ES_Global.CDSVars.Pool.TailPosition = LocalRegRecPtr->BlockOffset + LocalRegRecPtr->BlockSize;
CFE_ES_CDSBlockRecordSetUsed(LocalRegRecPtr, UtCDSID);
if (OutRegRec)
{
*OutRegRec = LocalRegRecPtr;
}
}
int32 ES_UT_SetupOSCleanupHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
{
osal_id_t ObjList[8];
/* On the first call, Use the stub functions to generate one object of
* each type
*/
if (CallCount == 0)
{
/* Initialize to avoid static analysis warnings */
memset(ObjList, 0, sizeof(ObjList));
OS_TaskCreate(&ObjList[0], NULL, NULL, OSAL_TASK_STACK_ALLOCATE, 0, 0, 0);
OS_QueueCreate(&ObjList[1], NULL, 0, 0, 0);
OS_MutSemCreate(&ObjList[2], NULL, 0);
OS_BinSemCreate(&ObjList[3], NULL, 0, 0);
OS_CountSemCreate(&ObjList[4], NULL, 0, 0);
OS_TimerCreate(&ObjList[5], NULL, NULL, NULL);
OS_OpenCreate(&ObjList[6], NULL, 0, 0);
OS_ModuleLoad(&ObjList[7], NULL, NULL, 0);
UT_SetDataBuffer((UT_EntryKey_t)&OS_ForEachObject, ObjList, sizeof(ObjList), true);
}
return StubRetcode;
}
static void ES_UT_SetupForOSCleanup(void)
{
UT_SetHookFunction(UT_KEY(OS_ForEachObject), ES_UT_SetupOSCleanupHook, NULL);
}
typedef struct
{
uint32 AppType;
uint32 AppState;
} ES_UT_SetAppStateHook_t;
static int32 ES_UT_SetAppStateHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
{
ES_UT_SetAppStateHook_t *StateHook = UserObj;
uint32 i;
CFE_ES_AppRecord_t * AppRecPtr;
AppRecPtr = CFE_ES_Global.AppTable;
for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; ++i)
{
if (CFE_ES_AppRecordIsUsed(AppRecPtr))
{
/* If no filter object supplied, set all apps to RUNNING */
if (StateHook == NULL)
{
AppRecPtr->AppState = CFE_ES_AppState_RUNNING;
}
else if (StateHook->AppType == 0 || AppRecPtr->Type == StateHook->AppType)
{
AppRecPtr->AppState = StateHook->AppState;
}
}
++AppRecPtr;
}
return StubRetcode;
}
void UtTest_Setup(void)
{
UT_Init("es");
UtPrintf("cFE ES Unit Test Output File\n\n");
UT_ADD_TEST(TestInit);
UT_ADD_TEST(TestStartupErrorPaths);
UT_ADD_TEST(TestResourceID);
UT_ADD_TEST(TestApps);
UT_ADD_TEST(TestLibs);
UT_ADD_TEST(TestERLog);
UT_ADD_TEST(TestTask);
UT_ADD_TEST(TestPerf);
UT_ADD_TEST(TestAPI);
UT_ADD_TEST(TestGenericCounterAPI);
UT_ADD_TEST(TestCDS);
UT_ADD_TEST(TestGenericPool);
UT_ADD_TEST(TestCDSMempool);
UT_ADD_TEST(TestESMempool);
UT_ADD_TEST(TestSysLog);
UT_ADD_TEST(TestBackground);
UT_ADD_TEST(TestStatusToString);
}
/*
** Reset variable values prior to a test
*/
void ES_ResetUnitTest(void)
{
UT_InitData();
memset(&CFE_ES_Global, 0, sizeof(CFE_ES_Global));
/*
** Initialize the Last Id
*/
CFE_ES_Global.LastAppId = CFE_ResourceId_FromInteger(CFE_ES_APPID_BASE);
CFE_ES_Global.LastLibId = CFE_ResourceId_FromInteger(CFE_ES_LIBID_BASE);
CFE_ES_Global.LastCounterId = CFE_ResourceId_FromInteger(CFE_ES_COUNTID_BASE);
CFE_ES_Global.LastMemPoolId = CFE_ResourceId_FromInteger(CFE_ES_POOLID_BASE);
CFE_ES_Global.CDSVars.LastCDSBlockId = CFE_ResourceId_FromInteger(CFE_ES_CDSBLOCKID_BASE);
/*
* (Re-)Initialize the reset data pointer
* This was formerly a separate global, but now part of CFE_ES_Global.
*
* Some unit tests assume/rely on it preserving its value across tests,
* so it must be re-initialized here every time CFE_ES_Global is reset.
*/
CFE_ES_Global.ResetDataPtr = ES_UT_PersistentResetData;
} /* end ES_ResetUnitTest() */
void TestInit(void)
{
UtPrintf("Begin Test Init");
UT_SetCDSSize(128 * 1024);
UT_SetSizeofESResetArea(sizeof(CFE_ES_ResetData_t));
/* Set up the reset area */
UT_SetStatusBSPResetArea(OS_SUCCESS, CFE_TIME_RESET_SIGNATURE, CFE_TIME_ToneSignalSelect_PRIMARY);
/* Set up the startup script for reading */
strncpy(StartupScript,
"CFE_LIB, /cf/apps/tst_lib.bundle, TST_LIB_Init, TST_LIB, 0, 0, 0x0, 1; "
"CFE_APP, /cf/apps/ci.bundle, CI_task_main, CI_APP, 70, 4096, 0x0, 1; "
"CFE_APP, /cf/apps/sch.bundle, SCH_TaskMain, SCH_APP, 120, 4096, 0x0, 1; "
"CFE_APP, /cf/apps/to.bundle, TO_task_main, TO_APP, 74, 4096, 0x0, 1; !",
sizeof(StartupScript) - 1);
StartupScript[sizeof(StartupScript) - 1] = '\0';
UT_SetReadBuffer(StartupScript, strlen(StartupScript));
/* Go through ES_Main and cover normal paths */
UT_SetDummyFuncRtn(OS_SUCCESS);
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL);
CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1, "ut_startup");
UtAssert_STUB_COUNT(CFE_PSP_Panic, 0);
}
void TestStartupErrorPaths(void)
{
int j;
ES_UT_SetAppStateHook_t StateHook;
uint32 PanicStatus;
uint32 ResetType;
OS_statvfs_t StatBuf;
CFE_ES_TaskRecord_t * TaskRecPtr;
CFE_ES_AppRecord_t * AppRecPtr;
void * TempBuff;
UtPrintf("Begin Test Startup Error Paths");
/*
* Get the reference to the reset area and save it so it will be preserved
* across calls to ES_ResetUnitTest(). This is required since now the pointer
* is part of CFE_ES_Global which is zeroed out as part of test reset. Formerly
* this was a separate global which was not cleared with the other globals.
*/
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetResetArea), &TempBuff, NULL, NULL);
ES_UT_PersistentResetData = TempBuff;
/* Set up the startup script for reading */
strncpy(StartupScript,
"CFE_LIB, /cf/apps/tst_lib.bundle, TST_LIB_Init, TST_LIB, 0, 0, 0x0, 1; "
"CFE_APP, /cf/apps/ci.bundle, CI_task_main, CI_APP, 70, 4096, 0x0, 1; "
"CFE_APP, /cf/apps/sch.bundle, SCH_TaskMain, SCH_APP, 120, 4096, 0x0, 1; "
"CFE_APP, /cf/apps/to.bundle, TO_task_main, TO_APP, 74, 4096, 0x0, 1; !",
sizeof(StartupScript) - 1);
StartupScript[sizeof(StartupScript) - 1] = '\0';
/* Perform ES main startup with a mutex creation failure */
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_MutSemCreate), OS_ERROR);
UT_SetReadBuffer(StartupScript, strlen(StartupScript));
UT_SetDataBuffer(UT_KEY(CFE_PSP_Panic), &PanicStatus, sizeof(PanicStatus), false);
CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, 1, 1, "ut_startup");
UtAssert_STUB_COUNT(CFE_PSP_Panic, 1);
UtAssert_UINT32_EQ(PanicStatus, CFE_PSP_PANIC_STARTUP_SEM);
/* Perform ES main startup with an ES Perf Data mutex creation failure */
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_MutSemCreate), 2, OS_ERROR);
UT_SetDataBuffer(UT_KEY(CFE_PSP_Panic), &PanicStatus, sizeof(PanicStatus), false);
CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, 1, 1, "ut_startup");
UtAssert_UINT32_EQ(PanicStatus, CFE_PSP_PANIC_STARTUP_SEM);
UtAssert_UINT32_EQ(UT_GetStubCount(UT_KEY(CFE_PSP_Panic)), 1);
/* Perform ES main startup with an ES Shared Data mutex creation failure */
ES_ResetUnitTest();
UT_SetDummyFuncRtn(OS_SUCCESS);
UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR);
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL);
CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, 1, 1, "ut_startup");
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_CANNOT_OPEN_ES_APP_STARTUP]);
/* Perform ES main startup with a startup sync failure */
ES_ResetUnitTest();
StateHook.AppState = CFE_ES_AppState_RUNNING;
StateHook.AppType =
CFE_ES_AppType_CORE; /* by only setting core apps, it will appear as if external apps did not start */
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, &StateHook);
UT_SetReadBuffer(StartupScript, strlen(StartupScript));
CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, 1, 1, "ut_startup");
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_STARTUP_SYNC_FAIL_1]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_STARTUP_SYNC_FAIL_2]);
/* Perform a power on reset with a hardware special sub-type */
ES_ResetUnitTest();
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_POWERON, CFE_PSP_RST_SUBTYPE_HW_SPECIAL_COMMAND, 1);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_POR_HW_SPECIAL]);
/* Perform a processor reset with a hardware special sub-type */
ES_ResetUnitTest();
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_HW_SPECIAL_COMMAND, 1);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_PROC_RESET_MAX_HW_SPECIAL]);
/* Perform a power on reset with an "other cause" sub-type */
ES_ResetUnitTest();
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_POWERON, -1, 1);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_POR_OTHER]);
/* Perform the maximum number of processor resets */
ES_ResetUnitTest();
CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount = 0;
CFE_ES_Global.ResetDataPtr->ResetVars.ES_CausedReset = false;
for (j = 0; j < CFE_PLATFORM_ES_MAX_PROCESSOR_RESETS; j++)
{
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1);
}
UtAssert_UINT32_EQ(CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount, CFE_PLATFORM_ES_MAX_PROCESSOR_RESETS);
/* Attempt another processor reset after the maximum have occurred */
ES_ResetUnitTest();
UT_SetDataBuffer(UT_KEY(CFE_PSP_Restart), &ResetType, sizeof(ResetType), false);
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1);
UtAssert_UINT32_EQ(CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount,
CFE_PLATFORM_ES_MAX_PROCESSOR_RESETS + 1);
UtAssert_UINT32_EQ(ResetType, CFE_PSP_RST_TYPE_POWERON);
UtAssert_STUB_COUNT(CFE_PSP_Restart, 1);
/* Perform a power on reset with a hardware special sub-type */
ES_ResetUnitTest();
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_HW_SPECIAL_COMMAND, 1);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_POR_MAX_HW_SPECIAL]);
/* Perform a processor reset with a reset area failure */
ES_ResetUnitTest();
UT_SetStatusBSPResetArea(OS_ERROR, 0, CFE_TIME_ToneSignalSelect_PRIMARY);
UT_SetDataBuffer(UT_KEY(CFE_PSP_Panic), &PanicStatus, sizeof(PanicStatus), false);
CFE_ES_Global.ResetDataPtr->ResetVars.ES_CausedReset = true;
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1);
UtAssert_UINT32_EQ(PanicStatus, CFE_PSP_PANIC_MEMORY_ALLOC);
UtAssert_STUB_COUNT(CFE_PSP_Panic, 1);
/* Perform a processor reset triggered by ES */
/* Added for coverage, as the "panic" case will should not cover this one */
ES_ResetUnitTest();
CFE_ES_Global.ResetDataPtr->ResetVars.ES_CausedReset = true;
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1);
UtAssert_STUB_COUNT(CFE_PSP_Panic, 0);
/* Perform a processor reset with the size of the reset area too small */
ES_ResetUnitTest();
UT_SetSizeofESResetArea(0);
UT_SetDataBuffer(UT_KEY(CFE_PSP_Panic), &PanicStatus, sizeof(PanicStatus), false);
UT_SetStatusBSPResetArea(OS_SUCCESS, 0, CFE_TIME_ToneSignalSelect_PRIMARY);
CFE_ES_SetupResetVariables(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PSP_RST_SUBTYPE_POWER_CYCLE, 1);
UtAssert_UINT32_EQ(PanicStatus, CFE_PSP_PANIC_MEMORY_ALLOC);
UtAssert_STUB_COUNT(CFE_PSP_Panic, 1);
/* Test initialization of the file systems specifying a power on reset
* following a failure to create the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mkfs), OS_ERROR);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_POWERON);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_CREATE_VOLATILE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_MOUNT_VOLATILE]);
/* prepare the StatBuf to reflect a RAM disk that is 99% full */
StatBuf.block_size = 1024;
StatBuf.total_blocks = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS;
StatBuf.blocks_free = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS / 100;
/* Test initialization of the file systems specifying a processor reset
* following a failure to reformat the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_mkfs), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_CREATE_VOLATILE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INIT_VOLATILE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_MOUNT_VOLATILE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_REFORMAT_VOLATILE]);
/* Verify requirement to report formatting */
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_FORMAT_VOLATILE]);
/* Test initialization of the file systems specifying a processor reset
* following failure to get the volatile disk memory
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(CFE_PSP_GetVolatileDiskMem), CFE_PSP_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]);
/* Test initialization of the file systems specifying a processor reset
* following a failure to remove the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_rmfs), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_REMOVE_VOLATILE]);
/* Test initialization of the file systems specifying a processor reset
* following a failure to unmount the RAM volume
*/
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_unmount), 1, -1);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_UNMOUNT_VOLATILE]);
/* Test successful initialization of the file systems */
ES_ResetUnitTest();
CFE_ES_InitializeFileSystems(4564564);
UtAssert_STUB_COUNT(CFE_PSP_Panic, 0);
/* Test initialization of the file systems specifying a processor reset
* following a failure to remount the RAM volume
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR);
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_MOUNT_VOLATILE]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_REMOUNT_VOLATILE]);
/* Test initialization of the file systems with an error determining the
* number of blocks that are free on the volume
*/
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_FileSysStatVolume), 1, -1);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_DETERMINE_BLOCKS]);
/* File system init with free space (no reformat) */
ES_ResetUnitTest();
StatBuf.blocks_free = StatBuf.total_blocks;
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UtAssert_STUB_COUNT(OS_unmount, 0);
StatBuf.blocks_free = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS / 100;
/* File system init with no blocks */
ES_ResetUnitTest();
StatBuf.total_blocks = 0;
UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false);
CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR);
UtAssert_STUB_COUNT(CFE_PSP_Panic, 1);
StatBuf.total_blocks = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS;
/* Test reading the object table where a record used error occurs */
ES_ResetUnitTest();
TaskRecPtr = CFE_ES_Global.TaskTable;
for (j = 0; j < OS_MAX_TASKS; j++)
{
/* Mark all entries as "used" to ensure that the log message gets
* output
*/
CFE_ES_TaskRecordSetUsed(TaskRecPtr, ES_UT_MakeTaskIdForIndex(j));
++TaskRecPtr;
}
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL);
CFE_ES_CreateObjects();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_RECORD_USED]);
/* Test reading the object table where an error occurs when
* calling a function
*/
ES_ResetUnitTest();
TaskRecPtr = CFE_ES_Global.TaskTable;
for (j = 0; j < OS_MAX_TASKS; j++)
{
/* Mark all entries as "used" to ensure that the log message gets
* output
*/
CFE_ES_TaskRecordSetUsed(TaskRecPtr, ES_UT_MakeAppIdForIndex(j));
++TaskRecPtr;
}
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_EarlyInit), 1, -1);
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL);
CFE_ES_CreateObjects();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_RECORD_USED]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_EARLYINIT]);
/* Test reading the object table where an error occurs when
* creating a core app
*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_TaskCreate), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_BinSemCreate), OS_ERROR);
UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL);
CFE_ES_CreateObjects();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_CORE_APP_CREATE]);
/* Test reading the object table where all app slots are taken */
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(CFE_ResourceId_FindNext), OS_ERROR);
CFE_ES_CreateObjects();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]);
/* Test reading the object table with a NULL function pointer */
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(CFE_ResourceId_FindNext), OS_ERROR);
CFE_ES_ObjectTable[1].ObjectType = CFE_ES_FUNCTION_CALL;
CFE_ES_CreateObjects();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]);
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_FUNCTION_POINTER]);