-
Notifications
You must be signed in to change notification settings - Fork 203
/
tbl_UT.c
3943 lines (3389 loc) · 172 KB
/
tbl_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:
** tbl_UT.c
**
** Purpose:
** Table 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 "tbl_UT.h"
#include "cfe_core_resourceid_basevalues.h"
/*
** External global variables
*/
extern CFE_TBL_Global_t CFE_TBL_Global;
/*
** Global variables
*/
CFE_TBL_Handle_t App1TblHandle1;
CFE_TBL_Handle_t App1TblHandle2;
CFE_TBL_Handle_t App2TblHandle1;
CFE_TBL_Handle_t App2TblHandle2;
CFE_TBL_Handle_t ArrayOfHandles[2];
#define UT_TBL_APPID_1 CFE_ES_APPID_C(CFE_ResourceId_FromInteger(CFE_ES_APPID_BASE + 1))
#define UT_TBL_APPID_2 CFE_ES_APPID_C(CFE_ResourceId_FromInteger(CFE_ES_APPID_BASE + 2))
#define UT_TBL_APPID_3 CFE_ES_APPID_C(CFE_ResourceId_FromInteger(CFE_ES_APPID_BASE + 3))
#define UT_TBL_APPID_10 CFE_ES_APPID_C(CFE_ResourceId_FromInteger(CFE_ES_APPID_BASE + 10))
/* Set up buffer to provide to CFE_ES_GetPoolBuf handler */
#define UT_TBL_LOAD_BUFFER_SIZE \
(CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS * (CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE + sizeof(CFE_ES_PoolAlign_t)))
static union
{
CFE_ES_PoolAlign_t Align;
uint8 Bytes[UT_TBL_LOAD_BUFFER_SIZE];
} UT_TBL_LoadBuffer;
void * Tbl1Ptr = NULL;
void * Tbl2Ptr = NULL;
void **ArrayOfPtrsToTblPtrs[2];
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_MSG_HK = {.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_SEND_HK_MID)};
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_CMD_NOOP_CC = {.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_CMD_MID),
.CommandCode = CFE_TBL_NOOP_CC};
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_CMD_RESET_COUNTERS_CC = {
.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_CMD_MID), .CommandCode = CFE_TBL_RESET_COUNTERS_CC};
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_INVALID_MID = {.MsgId = CFE_SB_MSGID_RESERVED, .CommandCode = 0};
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_CMD_INVALID_CC = {
.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_CMD_MID), .CommandCode = 0x7F};
CFE_TBL_RegistryRec_t Original[CFE_PLATFORM_TBL_MAX_NUM_TABLES];
/*
* UT helper routines
*/
void UT_TBL_SetupHeader(CFE_TBL_File_Hdr_t *TblFileHeader, size_t Offset, size_t NumBytes)
{
TblFileHeader->Offset = Offset;
TblFileHeader->NumBytes = NumBytes;
if (UT_Endianess == UT_LITTLE_ENDIAN)
{
CFE_TBL_ByteSwapUint32(&TblFileHeader->Offset);
CFE_TBL_ByteSwapUint32(&TblFileHeader->NumBytes);
}
}
/*
** Functions
*/
void UtTest_Setup(void)
{
/* Initialize unit test */
UT_Init("tbl");
UtPrintf("cFE TBL Unit Test Output File\n\n");
UT_InitializeTableRegistryNames();
/* cfe_tbl_task.c functions */
UT_ADD_TEST(Test_CFE_TBL_TaskInit);
UT_ADD_TEST(Test_CFE_TBL_InitData);
UT_ADD_TEST(Test_CFE_TBL_SearchCmdHndlrTbl);
/* cfe_tbl_task_cmds.c functions */
/* This should be done first (it initializes working data structures) */
UT_ADD_TEST(Test_CFE_TBL_DeleteCDSCmd);
UT_ADD_TEST(Test_CFE_TBL_TlmRegCmd);
UT_ADD_TEST(Test_CFE_TBL_AbortLoadCmd);
UT_ADD_TEST(Test_CFE_TBL_ActivateCmd);
UT_ADD_TEST(Test_CFE_TBL_DumpToFile);
UT_ADD_TEST(Test_CFE_TBL_ResetCmd);
UT_ADD_TEST(Test_CFE_TBL_ValidateCmd);
UT_ADD_TEST(Test_CFE_TBL_NoopCmd);
UT_ADD_TEST(Test_CFE_TBL_GetTblRegData);
UT_ADD_TEST(Test_CFE_TBL_GetHkData);
UT_ADD_TEST(Test_CFE_TBL_DumpRegCmd);
UT_ADD_TEST(Test_CFE_TBL_DumpCmd);
UT_ADD_TEST(Test_CFE_TBL_LoadCmd);
UT_ADD_TEST(Test_CFE_TBL_HousekeepingCmd);
/* cfe_tbl_api.c and cfe_tbl_internal.c functions */
UT_ADD_TEST(Test_CFE_TBL_ApiInit);
UT_ADD_TEST(Test_CFE_TBL_Register);
UT_ADD_TEST(Test_CFE_TBL_Share);
UT_ADD_TEST(Test_CFE_TBL_Unregister);
UT_ADD_TEST(Test_CFE_TBL_NotifyByMessage);
UT_ADD_TEST(Test_CFE_TBL_Load);
UT_ADD_TEST(Test_CFE_TBL_GetAddress);
UT_ADD_TEST(Test_CFE_TBL_ReleaseAddress);
UT_ADD_TEST(Test_CFE_TBL_GetAddresses);
UT_ADD_TEST(Test_CFE_TBL_ReleaseAddresses);
UT_ADD_TEST(Test_CFE_TBL_Validate);
UT_ADD_TEST(Test_CFE_TBL_Manage);
UT_ADD_TEST(Test_CFE_TBL_DumpToBuffer);
UT_ADD_TEST(Test_CFE_TBL_Update);
UT_ADD_TEST(Test_CFE_TBL_GetStatus);
UT_ADD_TEST(Test_CFE_TBL_GetInfo);
UT_ADD_TEST(Test_CFE_TBL_TblMod);
/* Miscellaneous cfe_tbl_internal.c tests */
UT_ADD_TEST(Test_CFE_TBL_Internal);
}
/*
** Fill the whole table registry with known table names and set an owner ID
*/
void UT_InitializeTableRegistryNames()
{
int i;
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_TABLES; i++)
{
snprintf(CFE_TBL_Global.Registry[i].Name, CFE_TBL_MAX_FULL_NAME_LEN, "%d", i);
CFE_TBL_Global.Registry[i].OwnerAppId = UT_TBL_APPID_2;
}
}
/*
** Initialize table registry values
*/
void UT_ResetTableRegistry(void)
{
int32 i = 0;
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_TABLES; i++)
{
CFE_TBL_InitRegistryRecord(&CFE_TBL_Global.Registry[i]);
}
/* Initialize the table access descriptors */
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_HANDLES; i++)
{
CFE_TBL_Global.Handles[i].AppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.Handles[i].RegIndex = 0;
CFE_TBL_Global.Handles[i].PrevLink = CFE_TBL_END_OF_LIST;
CFE_TBL_Global.Handles[i].NextLink = CFE_TBL_END_OF_LIST;
CFE_TBL_Global.Handles[i].UsedFlag = false;
CFE_TBL_Global.Handles[i].LockFlag = false;
CFE_TBL_Global.Handles[i].Updated = false;
CFE_TBL_Global.Handles[i].BufferIndex = 0;
}
/* Initialize the table validation results records */
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_VALIDATIONS; i++)
{
CFE_TBL_Global.ValidationResults[i].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.ValidationResults[i].CrcOfTable = 0;
CFE_TBL_Global.ValidationResults[i].Result = 0;
CFE_TBL_Global.ValidationResults[i].ActiveBuffer = false;
CFE_TBL_Global.ValidationResults[i].TableName[0] = '\0';
}
/* Initialize the dump-only table dump control blocks */
for (i = 0; i < CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS; i++)
{
CFE_TBL_Global.DumpControlBlocks[i].State = CFE_TBL_DUMP_FREE;
CFE_TBL_Global.DumpControlBlocks[i].DumpBufferPtr = NULL;
CFE_TBL_Global.DumpControlBlocks[i].Size = 0;
CFE_TBL_Global.DumpControlBlocks[i].TableName[0] = '\0';
/* Free all shared buffers */
CFE_TBL_Global.LoadBuffs[i].Taken = false;
}
CFE_TBL_Global.ValidationCounter = 0;
CFE_TBL_Global.HkTlmTblRegIndex = CFE_TBL_NOT_FOUND;
CFE_TBL_Global.LastTblUpdated = CFE_TBL_NOT_FOUND;
}
/*
** Tests to cover table task initialization functions
*/
void Test_CFE_TBL_TaskInit(void)
{
uint32 ExitCode;
union
{
CFE_TBL_NoopCmd_t NoopCmd;
CFE_TBL_SendHkCmd_t SendHkCmd;
CFE_TBL_ResetCountersCmd_t ResetCountersCmd;
CFE_MSG_Message_t Msg;
} CmdBuf;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;
UtPrintf("Begin Test Task Init");
memset(&CmdBuf, 0, sizeof(CmdBuf));
/* Test successful table services main entry point execution */
UT_InitData();
ExitCode = 0;
UT_SetDataBuffer(UT_KEY(CFE_ES_ExitApp), &ExitCode, sizeof(ExitCode), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
UtAssert_VOIDCALL(CFE_TBL_TaskMain());
UtAssert_INT32_EQ(ExitCode, CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR);
UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1);
/* Main task initialization failure */
UT_InitData();
ExitCode = 0;
UT_SetDataBuffer(UT_KEY(CFE_ES_ExitApp), &ExitCode, sizeof(ExitCode), false);
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, -1);
UtAssert_VOIDCALL(CFE_TBL_TaskMain());
UtAssert_INT32_EQ(ExitCode, CFE_ES_RunStatus_CORE_APP_INIT_ERROR);
/* Since stub doesn't actually cause an exit, will get called twice */
UtAssert_STUB_COUNT(CFE_ES_ExitApp, 2);
/* Test successful table services core application initialization */
UT_InitData();
CFE_UtAssert_SUCCESS(CFE_TBL_TaskInit());
/* Test table services core application initialization response to a pipe
* creation failure
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_CreatePipe), 1, -2);
UtAssert_INT32_EQ(CFE_TBL_TaskInit(), -2);
/* Test table services core application initialization response to a
* housekeeping request subscription error
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 1, -3);
UtAssert_INT32_EQ(CFE_TBL_TaskInit(), -3);
/* Test table services core application initialization response to a
* ground command subscription error
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 2, -4);
UtAssert_INT32_EQ(CFE_TBL_TaskInit(), -4);
/* Test table services core application initialization response to a
* send initialization event error
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_SendEvent), 1, -5);
UtAssert_INT32_EQ(CFE_TBL_TaskInit(), -5);
/* Test table services core application initialization response to an
* EVS register failure
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, -6);
UtAssert_INT32_EQ(CFE_TBL_TaskInit(), -6);
/* Test command pipe messages handler response to a valid command */
UT_InitData();
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.NoopCmd), UT_TPID_CFE_TBL_CMD_NOOP_CC);
CFE_UtAssert_EVENTSENT(CFE_TBL_NOOP_INF_EID);
/* Test command pipe messages handler response to an invalid
* message length
*/
UT_InitData();
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.NoopCmd) - 1, UT_TPID_CFE_TBL_CMD_NOOP_CC);
CFE_UtAssert_EVENTSENT(CFE_TBL_LEN_ERR_EID);
/* Test command pipe messages handler response to an invalid
* command code
*/
UT_InitData();
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.NoopCmd), UT_TPID_CFE_TBL_CMD_INVALID_CC);
CFE_UtAssert_EVENTSENT(CFE_TBL_CC1_ERR_EID);
/* Test command pipe messages handler response to other errors */
UT_InitData();
CFE_TBL_Global.CommandCounter = 0;
CFE_TBL_Global.CommandErrorCounter = 0;
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.NoopCmd), UT_TPID_CFE_TBL_INVALID_MID);
CFE_UtAssert_EVENTSENT(CFE_TBL_MID_ERR_EID);
UtAssert_ZERO(CFE_TBL_Global.CommandCounter);
UtAssert_ZERO(CFE_TBL_Global.CommandErrorCounter);
/* Test command pipe messages handler response to "message type" message */
UT_InitData();
CFE_TBL_Global.CommandCounter = 0;
CFE_TBL_Global.CommandErrorCounter = 0;
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.SendHkCmd), UT_TPID_CFE_TBL_MSG_HK);
UtAssert_ZERO(CFE_TBL_Global.CommandCounter);
UtAssert_ZERO(CFE_TBL_Global.CommandErrorCounter);
/* Test command pipe messages handler response to "command type" message */
UT_InitData();
UT_CallTaskPipe(CFE_TBL_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.ResetCountersCmd),
UT_TPID_CFE_TBL_CMD_RESET_COUNTERS_CC);
CFE_UtAssert_EVENTSENT(CFE_TBL_RESET_INF_EID);
UtAssert_ZERO(CFE_TBL_Global.CommandCounter);
UtAssert_ZERO(CFE_TBL_Global.CommandErrorCounter);
}
/*
** Test table service application data initialization
*/
void Test_CFE_TBL_InitData(void)
{
UtPrintf("Begin Test Init Data");
/* This function has only one possible path with no return code */
UT_InitData();
CFE_TBL_InitData();
UtAssert_STUB_COUNT(CFE_MSG_Init, 3);
}
/*
** Test command handler table message ID (or command code) search function
*/
void Test_CFE_TBL_SearchCmdHndlrTbl(void)
{
uint16 CmdCode;
CFE_SB_MsgId_t MsgID;
UtPrintf("Begin Test Search Command Handler Table");
/* Test successfully finding a matching message ID and command code */
UT_InitData();
MsgID = CFE_SB_ValueToMsgId(CFE_TBL_CMD_MID);
CmdCode = CFE_TBL_NOOP_CC;
UtAssert_INT32_EQ(CFE_TBL_SearchCmdHndlrTbl(MsgID, CmdCode), 1);
/* Test using a message that is not a command message with specific
* command code
*/
UT_InitData();
MsgID = CFE_SB_ValueToMsgId(CFE_TBL_SEND_HK_MID);
UtAssert_INT32_EQ(CFE_TBL_SearchCmdHndlrTbl(MsgID, CmdCode), 0);
/* Test with a message ID that matches but the command code does
* not match
*/
UT_InitData();
MsgID = CFE_SB_ValueToMsgId(CFE_TBL_CMD_MID);
CmdCode = 0xffff;
UtAssert_INT32_EQ(CFE_TBL_SearchCmdHndlrTbl(MsgID, CmdCode), CFE_TBL_BAD_CMD_CODE);
/* Test with a message ID that does not match */
UT_InitData();
MsgID = CFE_SB_INVALID_MSG_ID;
UtAssert_INT32_EQ(CFE_TBL_SearchCmdHndlrTbl(MsgID, CmdCode), CFE_TBL_BAD_MSG_ID);
}
/*
** Test the delete critical table's CDS command message
*/
void Test_CFE_TBL_DeleteCDSCmd(void)
{
int j, k;
CFE_TBL_DeleteCDSCmd_t DelCDSCmd;
UtPrintf("Begin Test Delete CDS Command");
/* Test successfully finding the table name in the table registry */
UT_InitData();
strncpy(DelCDSCmd.Payload.TableName, "0", sizeof(DelCDSCmd.Payload.TableName) - 1);
DelCDSCmd.Payload.TableName[sizeof(DelCDSCmd.Payload.TableName) - 1] = '\0';
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test failure to find table in the critical table registry */
UT_InitData();
k = CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES + CFE_PLATFORM_TBL_MAX_NUM_TABLES;
for (j = CFE_PLATFORM_TBL_MAX_NUM_TABLES; j < k; j++)
{
snprintf(CFE_TBL_Global.CritReg[j - CFE_PLATFORM_TBL_MAX_NUM_TABLES].Name, CFE_TBL_MAX_FULL_NAME_LEN, "%d", j);
}
strncpy(DelCDSCmd.Payload.TableName, "-1", sizeof(DelCDSCmd.Payload.TableName) - 1);
DelCDSCmd.Payload.TableName[sizeof(DelCDSCmd.Payload.TableName) - 1] = '\0';
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test finding the table in the critical table registry, but CDS is not
* tagged as a table
*/
UT_InitData();
snprintf(DelCDSCmd.Payload.TableName, sizeof(DelCDSCmd.Payload.TableName), "%d",
CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES + CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_ES_CDS_WRONG_TYPE_ERR);
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test deletion when CDS owning application is still active */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_ES_CDS_OWNER_ACTIVE_ERR);
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test deletion where the table cannot be located in the CDS registry */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_ES_ERR_NAME_NOT_FOUND);
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test deletion error while deleting table from the CDS */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_SUCCESS - 1);
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_ERR_CTR);
/* Test successful removal of the table from the CDS */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TBL_DeleteCDSCmd(&DelCDSCmd), CFE_TBL_INC_CMD_CTR);
}
/*
** Test the processing telemetry table registry command message function
*/
void Test_CFE_TBL_TlmRegCmd(void)
{
CFE_TBL_SendRegistryCmd_t TlmRegCmd;
UtPrintf("Begin Test Telemetry Registry Command");
/* Test when table name does exist */
UT_InitData();
/* Registry[0].Name used because it is confirmed to be a registered
* table name
*/
strncpy(TlmRegCmd.Payload.TableName, CFE_TBL_Global.Registry[0].Name, sizeof(TlmRegCmd.Payload.TableName) - 1);
TlmRegCmd.Payload.TableName[sizeof(TlmRegCmd.Payload.TableName) - 1] = '\0';
UtAssert_INT32_EQ(CFE_TBL_SendRegistryCmd(&TlmRegCmd), CFE_TBL_INC_CMD_CTR);
/* Test when table name does not exist */
UT_InitData();
snprintf(TlmRegCmd.Payload.TableName, sizeof(TlmRegCmd.Payload.TableName), "%d",
CFE_PLATFORM_TBL_MAX_NUM_TABLES + 1);
UtAssert_INT32_EQ(CFE_TBL_SendRegistryCmd(&TlmRegCmd), CFE_TBL_INC_ERR_CTR);
}
/*
** Test the processing abort load command message function
*/
void Test_CFE_TBL_AbortLoadCmd(void)
{
int load = (int)CFE_TBL_Global.Registry[0].LoadInProgress;
CFE_TBL_AbortLoadCmd_t AbortLdCmd;
UtPrintf("Begin Test Abort Load Command");
/* Test when table name does exist and a table load is in progress */
UT_InitData();
/* Entering the if statement with a table name that has to be in
* the registry
*/
strncpy(AbortLdCmd.Payload.TableName, CFE_TBL_Global.Registry[0].Name, sizeof(AbortLdCmd.Payload.TableName) - 1);
AbortLdCmd.Payload.TableName[sizeof(AbortLdCmd.Payload.TableName) - 1] = '\0';
CFE_TBL_Global.Registry[0].LoadInProgress = 1;
UtAssert_INT32_EQ(CFE_TBL_AbortLoadCmd(&AbortLdCmd), CFE_TBL_INC_CMD_CTR);
/* Test when table name does exist but no table load is in progress */
UT_InitData();
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS;
UtAssert_INT32_EQ(CFE_TBL_AbortLoadCmd(&AbortLdCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table name does exist, a table load is in progress, and the
* table is dump only
*/
UT_InitData();
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
CFE_TBL_Global.Registry[0].DumpOnly = true;
UtAssert_INT32_EQ(CFE_TBL_AbortLoadCmd(&AbortLdCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table name not found in the registry */
UT_InitData();
snprintf(AbortLdCmd.Payload.TableName, sizeof(AbortLdCmd.Payload.TableName), "%d",
CFE_PLATFORM_TBL_MAX_NUM_TABLES + 1);
UtAssert_INT32_EQ(CFE_TBL_AbortLoadCmd(&AbortLdCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table is double buffered */
UT_InitData();
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
CFE_TBL_Global.LoadBuffs[0].Taken = true;
CFE_TBL_AbortLoad(&CFE_TBL_Global.Registry[0]);
UtAssert_BOOL_TRUE(CFE_TBL_Global.LoadBuffs[0].Taken);
/* Restore values for subsequent tests */
CFE_TBL_Global.Registry[0].LoadInProgress = load;
CFE_TBL_Global.LoadBuffs[0].Taken = false;
}
/*
** Test the activate table command message function
*/
void Test_CFE_TBL_ActivateCmd(void)
{
int load = (int)CFE_TBL_Global.Registry[0].LoadInProgress;
uint8 dump = CFE_TBL_Global.Registry[0].DumpOnly;
CFE_TBL_ActivateCmd_t ActivateCmd;
UtPrintf("Begin Test Activate Command");
/* Enter the if statement with a table name that is in the registry */
strncpy(ActivateCmd.Payload.TableName, CFE_TBL_Global.Registry[0].Name, sizeof(ActivateCmd.Payload.TableName) - 1);
ActivateCmd.Payload.TableName[sizeof(ActivateCmd.Payload.TableName) - 1] = '\0';
/* Test when table name exists, but attempts to activate a dump-only
* table
*/
UT_InitData();
CFE_TBL_Global.Registry[0].DumpOnly = true;
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table name exists, the table is not a dump-only, a load is in
* progress, and the table is double-buffered
*/
UT_InitData();
CFE_TBL_Global.Registry[0].DumpOnly = false;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table name exists, the table is not a dump-only, a load is in
* progress, the table isn't double-buffered, and ValidationStatus = true
*/
UT_InitData();
CFE_TBL_Global.Registry[0].DoubleBuffered = false;
CFE_TBL_Global.LoadBuffs[CFE_TBL_Global.Registry[0].LoadInProgress].Validated = true;
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_CMD_CTR);
/* Test when table name exists, the table is not a dump-only, no load is in
* progress, and no notification message should be sent
*/
UT_InitData();
CFE_TBL_Global.Registry[0].NotifyByMsg = false;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS;
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_ERR_CTR);
/* Test when table name exists, the table is not a dump-only, no load in in
* progress, and a notification message should be sent
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_TransmitMsg), 1, CFE_SB_INTERNAL_ERR);
CFE_TBL_Global.Registry[0].NotifyByMsg = true;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_CMD_CTR);
/* Test when the table name doesn't exist */
UT_InitData();
snprintf(ActivateCmd.Payload.TableName, sizeof(ActivateCmd.Payload.TableName), "%d",
CFE_PLATFORM_TBL_MAX_NUM_TABLES + 1);
UtAssert_INT32_EQ(CFE_TBL_ActivateCmd(&ActivateCmd), CFE_TBL_INC_ERR_CTR);
/* Restore original values */
CFE_TBL_Global.Registry[0].LoadInProgress = load;
CFE_TBL_Global.Registry[0].DumpOnly = dump;
}
/*
** Test the write table data to a file function
*/
void Test_CFE_TBL_DumpToFile(void)
{
uint32 TblSizeInBytes = 9;
UtPrintf("Begin Test Dump to File");
/* Test with an error creating the dump file */
UT_InitData();
UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR);
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_ERR_CTR);
/* Test with an error writing the cFE file header */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_FS_WriteHeader), 1, sizeof(CFE_FS_Header_t) - 1);
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_ERR_CTR);
/* Test with an error writing the table file header */
UT_InitData();
/* Set the count for the FSWriteHdrRtn return code variable to a large
* enough value to pass through every time
*/
UT_SetDeferredRetcode(UT_KEY(CFE_FS_WriteHeader), 6, sizeof(CFE_FS_Header_t));
UT_SetDeferredRetcode(UT_KEY(OS_write), 1, sizeof(CFE_TBL_File_Hdr_t) - 1);
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_ERR_CTR);
/* Test with an error writing the table to a file */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(OS_write), 2, TblSizeInBytes - 1);
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_ERR_CTR);
/* Test successful file creation and data dumped */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(OS_OpenCreate), 1, OS_ERROR);
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_CMD_CTR);
/* Test where file already exists so data is overwritten */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_DumpToFile("filename", "tablename", "dumpaddress", TblSizeInBytes), CFE_TBL_INC_CMD_CTR);
}
/*
** Test the processing reset counters command message function
*/
void Test_CFE_TBL_ResetCmd(void)
{
UtPrintf("Begin Test Reset Command");
/* Test run through function (there are no additional paths) */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_ResetCountersCmd(NULL), CFE_TBL_DONT_INC_CTR);
}
/*
** Test the validate table command message function
*/
void Test_CFE_TBL_ValidateCmd(void)
{
int i;
uint8 Buff;
uint8 * BuffPtr = &Buff;
CFE_TBL_ValidateCmd_t ValidateCmd;
CFE_TBL_CallbackFuncPtr_t ValFuncPtr = (CFE_TBL_CallbackFuncPtr_t)((unsigned long)&UT_InitializeTableRegistryNames);
UtPrintf("Begin Test Validate Command");
/* Test when table name is not found in the registry */
UT_InitData();
snprintf(ValidateCmd.Payload.TableName, sizeof(ValidateCmd.Payload.TableName), "%d",
CFE_PLATFORM_TBL_MAX_NUM_TABLES + 1);
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_ERR_CTR);
/* Test where the active buffer has data, but too many table validations
* have been requested
*/
UT_InitData();
strncpy(ValidateCmd.Payload.TableName, CFE_TBL_Global.Registry[0].Name, sizeof(ValidateCmd.Payload.TableName) - 1);
ValidateCmd.Payload.TableName[sizeof(ValidateCmd.Payload.TableName) - 1] = '\0';
ValidateCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_ACTIVE;
CFE_TBL_Global.Registry[0].Buffers[CFE_TBL_Global.Registry[0].ActiveBufferIndex].BufferPtr = BuffPtr;
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_VALIDATIONS; i++)
{
CFE_TBL_Global.ValidationResults[i].State = CFE_TBL_VALIDATION_PENDING;
}
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_ERR_CTR);
/* Test where the active buffer has data, but there is no validation
* function pointer
*/
UT_InitData();
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].ValidationFuncPtr = NULL;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
/* Test where the active buffer has data, the validation function pointer
* exists, and the active table flag is set
*/
UT_InitData();
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].ValidationFuncPtr = ValFuncPtr;
ValidateCmd.Payload.ActiveTableFlag = true;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
/* Test with the buffer inactive, the table is double-buffered, and the
* validation function pointer exists
*/
UT_InitData();
ValidateCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_INACTIVE;
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
CFE_TBL_Global.Registry[0].Buffers[1 - CFE_TBL_Global.Registry[0].ActiveBufferIndex].BufferPtr = BuffPtr;
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].ValidationFuncPtr = ValFuncPtr;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
/* Test with the buffer inactive, the table is single-buffered with a
* load in progress, the validation function pointer exists, and no
* notification message should be sent
*/
UT_InitData();
CFE_TBL_Global.Registry[0].NotifyByMsg = false;
CFE_TBL_Global.Registry[0].DoubleBuffered = false;
CFE_TBL_Global.LoadBuffs[CFE_TBL_Global.Registry[0].LoadInProgress].BufferPtr = BuffPtr;
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
/* Test with the buffer inactive, the table is single-buffered with a
* load in progress, the validation function pointer exists, and a
* notification message should be sent
*/
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_TransmitMsg), 1, CFE_SB_INTERNAL_ERR);
CFE_TBL_Global.Registry[0].NotifyByMsg = true;
CFE_TBL_Global.Registry[0].DoubleBuffered = false;
CFE_TBL_Global.LoadBuffs[CFE_TBL_Global.Registry[0].LoadInProgress].BufferPtr = BuffPtr;
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
/* Test where no inactive buffer is present (single-buffered table without
* load in progress)
*/
UT_InitData();
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_ERR_CTR);
/* Test with an illegal buffer */
UT_InitData();
ValidateCmd.Payload.ActiveTableFlag = 0xffff;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_ERR_CTR);
}
/*
** Test the processing no-operation command message function
*/
void Test_CFE_TBL_NoopCmd(void)
{
UtPrintf("Begin Test No-Op Command");
/* Test run through function (there are no additional paths) */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_NoopCmd(NULL), CFE_TBL_INC_CMD_CTR);
}
/*
** Test the function which converts table registry entries for tables into
** messages
*/
void Test_CFE_TBL_GetTblRegData(void)
{
UtPrintf("Begin Test Get Table Registry Command");
/* Test using a double buffered table */
UT_InitData();
CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr = CFE_ES_MEMADDRESS_C(0);
CFE_TBL_Global.Registry[CFE_TBL_Global.HkTlmTblRegIndex].DoubleBuffered = true;
CFE_TBL_GetTblRegData();
UtAssert_NOT_NULL(CFE_ES_MEMADDRESS_TO_PTR(CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr));
/* Test using a single buffered table and the buffer is inactive */
UT_InitData();
CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr = CFE_ES_MEMADDRESS_C(0);
CFE_TBL_Global.Registry[CFE_TBL_Global.HkTlmTblRegIndex].DoubleBuffered = false;
CFE_TBL_Global.Registry[CFE_TBL_Global.HkTlmTblRegIndex].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
CFE_TBL_GetTblRegData();
UtAssert_NOT_NULL(CFE_ES_MEMADDRESS_TO_PTR(CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr));
/* Test with no inactive buffer */
UT_InitData();
CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr = CFE_ES_MEMADDRESS_C(0);
CFE_TBL_Global.Registry[CFE_TBL_Global.HkTlmTblRegIndex].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS;
CFE_TBL_GetTblRegData();
UtAssert_NULL(CFE_ES_MEMADDRESS_TO_PTR(CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr));
}
/*
** Test the function that collects data and stores it in the housekeeping
** message
*/
void Test_CFE_TBL_GetHkData(void)
{
int i;
int32 NumLoadPendingIndex = CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1;
int32 FreeSharedBuffIndex = CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS - 1;
int32 ValTableIndex = CFE_PLATFORM_TBL_MAX_NUM_VALIDATIONS - 1;
CFE_ES_AppId_t AppID;
/* Get the AppID being used for UT */
CFE_ES_GetAppID(&AppID);
UtPrintf("Begin Test Get Housekeeping Data");
for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_TABLES; i++)
{
CFE_TBL_Global.Registry[i].LoadPending = false;
}
/* Test raising the count of load pending tables */
UT_InitData();
CFE_TBL_Global.Registry[NumLoadPendingIndex].LoadPending = true;
CFE_TBL_Global.Registry[NumLoadPendingIndex].OwnerAppId = AppID;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.HkPacket.Payload.NumLoadPending, 1);
/* Test lowering the count of free shared buffers */
UT_InitData();
CFE_TBL_Global.LoadBuffs[FreeSharedBuffIndex].Taken = true;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.HkPacket.Payload.NumFreeSharedBufs, CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS - 1);
/* Test making a ValPtr with result = CFE_SUCCESS */
UT_InitData();
CFE_TBL_Global.SuccessValCounter = 0;
CFE_TBL_Global.ValidationResults[ValTableIndex].State = CFE_TBL_VALIDATION_PERFORMED;
CFE_TBL_Global.ValidationResults[ValTableIndex].Result = CFE_SUCCESS;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.SuccessValCounter, 1);
/* Test making a ValPtr without result = CFE_SUCCESS */
UT_InitData();
CFE_TBL_Global.FailedValCounter = 0;
CFE_TBL_Global.ValidationResults[ValTableIndex].State = CFE_TBL_VALIDATION_PERFORMED;
CFE_TBL_Global.ValidationResults[ValTableIndex].Result = CFE_SUCCESS - 1;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.FailedValCounter, 1);
/* Test with an invalid registry entry */
UT_InitData();
CFE_TBL_Global.Registry[CFE_TBL_Global.LastTblUpdated].OwnerAppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds = 19283;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds, 19283);
/* Test with invalid last valid table updated out of range (low) */
UT_InitData();
CFE_TBL_Global.LastTblUpdated = -1;
CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds = 12345;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds, 12345);
/* Test with invalid last valid table updated out of range (high) */
UT_InitData();
CFE_TBL_Global.LastTblUpdated = CFE_PLATFORM_TBL_MAX_NUM_TABLES;
CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds = 54321;
CFE_TBL_GetHkData();
UtAssert_UINT32_EQ(CFE_TBL_Global.HkPacket.Payload.LastUpdateTime.Seconds, 54321);
}
/*
** Test the function that processes dump table registration to file
** command message
*/
void Test_CFE_TBL_DumpRegCmd(void)
{
int q;
CFE_TBL_DumpRegistryCmd_t DumpRegCmd;
CFE_ES_AppId_t AppID;
size_t LocalSize;
void * LocalBuf;
/* Get the AppID being used for UT */
CFE_ES_GetAppID(&AppID);
UtPrintf("Begin Test Dump Register Command");
for (q = 0; q < CFE_PLATFORM_TBL_MAX_NUM_TABLES; q++)
{
CFE_TBL_Global.Registry[q].HeadOfAccessList = CFE_TBL_END_OF_LIST;
}
/* Test command using the default dump file name (nominal path) */
UT_InitData();
UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpIsPending), false);
strncpy(DumpRegCmd.Payload.DumpFilename, "X", sizeof(DumpRegCmd.Payload.DumpFilename) - 1);
DumpRegCmd.Payload.DumpFilename[sizeof(DumpRegCmd.Payload.DumpFilename) - 1] = '\0';
UtAssert_INT32_EQ(CFE_TBL_DumpRegistryCmd(&DumpRegCmd), CFE_TBL_INC_CMD_CTR);
/* Test command with a bad file name */
UT_SetDeferredRetcode(UT_KEY(CFE_FS_ParseInputFileNameEx), 1, CFE_FS_INVALID_PATH);
UtAssert_INT32_EQ(CFE_TBL_DumpRegistryCmd(&DumpRegCmd), CFE_TBL_INC_ERR_CTR);
UT_ResetState(UT_KEY(CFE_FS_ParseInputFileNameEx));
/* Test command with the dump file already pending (max requests pending) */
UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpIsPending), true);
UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpRequest), CFE_STATUS_REQUEST_ALREADY_PENDING);
UtAssert_INT32_EQ(CFE_TBL_DumpRegistryCmd(&DumpRegCmd), CFE_TBL_INC_ERR_CTR);
UT_ResetState(UT_KEY(CFE_FS_BackgroundFileDumpRequest));
/* Test command with the dump file already pending (local) */
UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpIsPending), false);
UT_SetDefaultReturnValue(UT_KEY(CFE_FS_BackgroundFileDumpRequest), CFE_STATUS_REQUEST_ALREADY_PENDING);
UtAssert_INT32_EQ(CFE_TBL_DumpRegistryCmd(&DumpRegCmd), CFE_TBL_INC_ERR_CTR);
/* Check event generators */
UT_ClearEventHistory();
CFE_TBL_Global.RegDumpState.FileExisted = true;
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_COMPLETE, CFE_SUCCESS, 10, 0,
1000);
CFE_UtAssert_EVENTSENT(CFE_TBL_OVERWRITE_REG_DUMP_INF_EID);
UT_ClearEventHistory();
CFE_TBL_Global.RegDumpState.FileExisted = false;
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_COMPLETE, CFE_SUCCESS, 10, 0,
1000);
CFE_UtAssert_EVENTSENT(CFE_TBL_WRITE_REG_DUMP_INF_EID);
UT_ClearEventHistory();
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_RECORD_WRITE_ERROR,
CFE_SUCCESS, 10, 10, 1000);
CFE_UtAssert_EVENTSENT(CFE_TBL_WRITE_TBL_REG_ERR_EID);
UT_ClearEventHistory();
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_HEADER_WRITE_ERROR,
CFE_SUCCESS, 10, 10, 1000);
CFE_UtAssert_EVENTSENT(CFE_TBL_WRITE_CFE_HDR_ERR_EID);
UT_ClearEventHistory();
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_CREATE_ERROR, OS_ERROR, 10, 0,
0);
CFE_UtAssert_EVENTSENT(CFE_TBL_CREATING_DUMP_FILE_ERR_EID);
UT_ClearEventHistory();
CFE_TBL_DumpRegistryEventHandler(&CFE_TBL_Global.RegDumpState, CFE_FS_FileWriteEvent_UNDEFINED, OS_ERROR, 0, 0, 0);
CFE_UtAssert_EVENTCOUNT(0);
/* Test where the table is owned, the file doesn't already exist, and the
* table is successfully dumped
*/
UT_InitData();
CFE_TBL_Global.Registry[0].OwnerAppId = AppID;
CFE_TBL_Global.Registry[0].HeadOfAccessList = CFE_TBL_END_OF_LIST;
CFE_TBL_Global.Registry[1].OwnerAppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
LocalBuf = NULL;
LocalSize = 0;
UtAssert_BOOL_FALSE(CFE_TBL_DumpRegistryGetter(&CFE_TBL_Global.RegDumpState, 0, &LocalBuf, &LocalSize));
UtAssert_NOT_NULL(LocalBuf);
UtAssert_NONZERO(LocalSize);
/* Same but not double buffered */
UT_InitData();
CFE_TBL_Global.Registry[0].OwnerAppId = AppID;
CFE_TBL_Global.Registry[0].HeadOfAccessList = CFE_TBL_END_OF_LIST;
CFE_TBL_Global.Registry[1].OwnerAppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1;
CFE_TBL_Global.Registry[0].DoubleBuffered = false;
LocalBuf = NULL;
LocalSize = 0;
UtAssert_BOOL_FALSE(CFE_TBL_DumpRegistryGetter(&CFE_TBL_Global.RegDumpState, 0, &LocalBuf, &LocalSize));
UtAssert_NOT_NULL(LocalBuf);
UtAssert_NONZERO(LocalSize);
/* Hit last entry, no load in progress */
CFE_TBL_Global.Registry[CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1].OwnerAppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.Registry[CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1].HeadOfAccessList = 2;
CFE_TBL_Global.Registry[CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS;
CFE_TBL_Global.Handles[2].NextLink = CFE_TBL_END_OF_LIST;
LocalBuf = NULL;
LocalSize = 0;
UtAssert_BOOL_TRUE(CFE_TBL_DumpRegistryGetter(&CFE_TBL_Global.RegDumpState, CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1,
&LocalBuf, &LocalSize));
UtAssert_NOT_NULL(LocalBuf);
UtAssert_NONZERO(LocalSize);
/* Test with record numb beyond EOF (should be ignored, return null) */
UtAssert_BOOL_TRUE(CFE_TBL_DumpRegistryGetter(&CFE_TBL_Global.RegDumpState, CFE_PLATFORM_TBL_MAX_NUM_TABLES + 1,
&LocalBuf, &LocalSize));
UtAssert_NULL(LocalBuf);
UtAssert_ZERO(LocalSize);
/* Test empty registry */
CFE_TBL_Global.Registry[0].OwnerAppId = CFE_TBL_NOT_OWNED;
CFE_TBL_Global.Registry[0].HeadOfAccessList = CFE_TBL_END_OF_LIST;
LocalBuf = NULL;