-
Notifications
You must be signed in to change notification settings - Fork 46
/
cf_app_tests.c
877 lines (691 loc) · 32.4 KB
/
cf_app_tests.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
/************************************************************************
* NASA Docket No. GSC-18,447-1, and identified as “CFS CFDP (CF)
* Application version 3.0.0”
*
* Copyright (c) 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.
************************************************************************/
/* cf testing includes */
#include "cf_test_utils.h"
#include "cf_events.h"
#include "cf_app.h"
#include "cf_cmd.h"
/*******************************************************************************
**
** cf_app_tests Setup and Teardown
**
*******************************************************************************/
void cf_app_tests_Setup(void)
{
cf_tests_Setup();
} /* end cf_app_tests_Setup */
void CF_App_Tests_Teardown(void)
{
cf_tests_Teardown();
} /* end CF_App_Tests_Teardown */
/* end cf_app_tests Setup and Teardown */
/*******************************************************************************
**
** cf_app_tests helpers
**
*******************************************************************************/
/* NOTE: UT_UpdatedDefaultHandler_CFE_SB_ReceiveBuffer is an update to the provided version that can be made to
* correctly mimic the behavior needed.
* In this case, values not equal to CFE_SUCCESS should return NULL. Provided CFE_SB stub as of caelum-rc3 tag does
* not provide this ability
* see https://github.com/nasa/cFE/issues/1617 (closed as wontfix label)
*/
void UT_UpdatedDefaultHandler_CFE_SB_ReceiveBuffer(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
CFE_SB_Buffer_t **BufPtr = UT_Hook_GetArgValueByName(Context, "BufPtr", CFE_SB_Buffer_t **);
UT_Stub_CopyToLocal(UT_KEY(CFE_SB_ReceiveBuffer), BufPtr, sizeof(*BufPtr));
}
/* end cf_app_tests helpers */
/*******************************************************************************
**
** CF_HkCmd tests - full coverage
**
*******************************************************************************/
void Test_CF_HkCmd(void)
{
/* Act */
CF_HkCmd();
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_SetMsgTime, 1);
UtAssert_STUB_COUNT(CFE_SB_TransmitMsg, 1);
UtAssert_STUB_COUNT(CFE_TIME_GetTime, 1);
}
/* end CF_HkCmd tests */
/*******************************************************************************
**
** CF_CheckTables tests - full coverage
**
*******************************************************************************/
void Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled(void)
{
/* Arrange */
CF_AppData.engine.enabled = 1;
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 0);
} /* end Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled */
void Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent(void)
{
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), CFE_STATUS_EXTERNAL_RESOURCE_FAIL);
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
} /* end Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent */
void Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent(void)
{
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), CFE_STATUS_EXTERNAL_RESOURCE_FAIL);
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 1);
UtAssert_STUB_COUNT(CFE_TBL_Manage, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
} /* end Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent */
void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent(void)
{
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_STATUS_EXTERNAL_RESOURCE_FAIL);
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 1);
UtAssert_STUB_COUNT(CFE_TBL_Manage, 1);
UtAssert_STUB_COUNT(CFE_TBL_GetAddress, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
} /* end Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent */
void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS(void)
{
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 1);
UtAssert_STUB_COUNT(CFE_TBL_Manage, 1);
UtAssert_STUB_COUNT(CFE_TBL_GetAddress, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
} /* end Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS */
void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED(void)
{
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED);
/* Act */
CF_CheckTables();
/* Assert */
UtAssert_STUB_COUNT(CFE_TBL_ReleaseAddress, 1);
UtAssert_STUB_COUNT(CFE_TBL_Manage, 1);
UtAssert_STUB_COUNT(CFE_TBL_GetAddress, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
} /* end Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED */
/* end CF_CheckTables tests */
/*******************************************************************************
**
** CF_ValidateConfigTable tests - full coverage
**
*******************************************************************************/
/* CF_ValidateConfigTable tests specific items */
/* CF_ValidateConfigTable tests specific global variables */
CF_ConfigTable_t dummy_table;
/* CF_ValidateConfigTable tests specific functions */
void cf_config_table_tests_set_dummy_table_to_nominal(void)
{
// all values for dummy_table.ticks_per_second nominal except 0
dummy_table.ticks_per_second = Any_uint32_Except(0);
// all values (except 0) & 3ff == 0 are nominal (1024 byte aligned)
dummy_table.rx_crc_calc_bytes_per_wakeup = Any_uint32_Except(0) << 10;
// all values less than sizeof(CF_CFDP_PduFileDataContent_t) are nominal
dummy_table.outgoing_file_chunk_size = Any_uint16_LessThan(sizeof(CF_CFDP_PduFileDataContent_t));
} /* end cf_config_table_tests_set_dummy_table_to_nominal */
void Setup_cf_config_table_tests(void)
{
cf_app_tests_Setup();
cf_config_table_tests_set_dummy_table_to_nominal();
} /* end Setup_cf_config_table_tests */
/* end CF_ValidateConfigTable tests specific items */
void Test_CF_ValidateConfigTable_FailBecauseTableTicksPerSecondIs0(void)
{
/* Arrange */
CF_ConfigTable_t *arg_table = &dummy_table;
int32 result;
arg_table->ticks_per_second = 0;
/* Act */
result = CF_ValidateConfigTable(arg_table);
/* Assert */
UtAssert_INT32_EQ(result, -1);
} /* end Test_CF_ValidateConfigTable_FailBecauseTableTicksPerSecondIs0 */
void Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIs0(void)
{
/* Arrange */
CF_ConfigTable_t *arg_table = &dummy_table;
int32 result;
arg_table->ticks_per_second = 1;
arg_table->rx_crc_calc_bytes_per_wakeup = 0;
/* Act */
result = CF_ValidateConfigTable(arg_table);
/* Assert */
UtAssert_INT32_EQ(result, -2);
} /* end Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIs0 */
void Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIsNot1024ByteAligned(void)
{
/* Arrange */
CF_ConfigTable_t *arg_table = &dummy_table;
int32 result;
arg_table->ticks_per_second = 1;
arg_table->rx_crc_calc_bytes_per_wakeup =
(Any_uint32() << 10) +
(Any_uint32_LessThan_or_EqualTo(0x3FE) +
1); /* Any_uint32_LessThan_or_EqualTo(0x3FE) + 1 is 0x001 to 0x3FF, forcing no 1024 byte alignment */
/* Act */
result = CF_ValidateConfigTable(arg_table);
/* Assert */
UtAssert_INT32_EQ(result, -2);
} /* end Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIsNot1024ByteAligned */
void Test_CF_ValidateConfigTable_FailBecauseOutgoingFileChunkSmallerThanDataArray(void)
{
/* Arrange */
CF_ConfigTable_t *arg_table = &dummy_table;
int32 result;
// outgoing_file_chunk_size set to greater than sizeof(CF_CFDP_PduFileDataContent_t)
arg_table->ticks_per_second = 1;
arg_table->rx_crc_calc_bytes_per_wakeup = 0x0400; /* 1024 aligned */
arg_table->outgoing_file_chunk_size = sizeof(CF_CFDP_PduFileDataContent_t) + 1;
/* Act */
result = CF_ValidateConfigTable(arg_table);
/* Assert */
UtAssert_INT32_EQ(result, -3);
} /* end Test_CF_ValidateConfigTable_FailBecauseOutgoingFileChunkSmallerThanDataArray */
void Test_CF_ValidateConfigTable_Success(void)
{
/* Arange */
CF_ConfigTable_t *arg_table = &dummy_table;
int32 result;
arg_table->ticks_per_second = 1;
arg_table->rx_crc_calc_bytes_per_wakeup = 0x0400; /* 1024 aligned */
arg_table->outgoing_file_chunk_size = sizeof(CF_CFDP_PduFileDataContent_t);
/* Act */
result = CF_ValidateConfigTable(arg_table);
/* Assert */
UtAssert_INT32_EQ(result, CFE_SUCCESS);
} /* end Test_CF_ValidateConfigTable_Success */
/* end CF_ValidateConfigTable tests */
/*******************************************************************************
**
** CF_TableInit tests - full coverage
**
*******************************************************************************/
void Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess(void)
{
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_REG);
} /* end Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess */
void Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess(void)
{
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_LOAD);
} /* end Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess */
void Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess(void)
{
int32 result = -1;
/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_MANAGE);
} /* end Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess */
void Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess(void)
{
int32 result = -1;
/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_GETADDR);
} /* end Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess */
void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoNotSendEvent(void)
{
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), CFE_SUCCESS);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
} /* end Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoNotSendEvent */
void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_SuccessAndDoNotSendEvent(void)
{
/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED);
/* Act */
UtAssert_INT32_EQ(CF_TableInit(), CFE_SUCCESS);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
} /* end Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_SuccessAndDoNotSendEvent */
/* end CF_TableInit tests */
/*******************************************************************************
**
** CF_Init tests - full coverage
**
*******************************************************************************/
void Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void)
{
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1);
} /* end Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */
void Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void)
{
/* Arrange */
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_CreatePipe), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1);
} /* end Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */
void Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void)
{
/* Arrange */
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_Subscribe), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1);
UtAssert_STUB_COUNT(CFE_SB_Subscribe, 1);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1);
} /* end Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */
/* NOTE: multi call test for CFE_SB_Subscribe would be helpful but not necessary for coverage */
void Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus(void)
{
/* Arrange */
int32 result = -1;
/* Arrange unstubbable: CF_TableInit */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1);
UtAssert_STUB_COUNT(CFE_SB_Subscribe, 3);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
} /* end Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus */
void Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus(void)
{
/* Arrange */
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_InitEngine), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1);
UtAssert_STUB_COUNT(CFE_SB_Subscribe, 3);
UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 1);
} /* end Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus */
void Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void)
{
/* Arrange */
int32 result = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_SendEvent), result);
/* Act */
UtAssert_INT32_EQ(CF_Init(), result);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_EVS_Register, 1);
UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1);
UtAssert_STUB_COUNT(CFE_SB_Subscribe, 3);
// UtAssert_STUB_COUNT(CF_TableInit, 1);
UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
} /* end Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */
void Test_CF_Init_Success(void)
{
/* Act */
UtAssert_INT32_EQ(CF_Init(), CFE_SUCCESS);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
} /* end Test_CF_Init_Success */
/* end CF_Init tests */
/*******************************************************************************
**
** CF_WakeUp tests
**
*******************************************************************************/
void Test_CF_WakeUp(void)
{
/* Arrange */
/* No Arrange Required */
/* Act */
CF_WakeUp();
/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_CycleEngine, 1);
} /* end Test_CF_WakeUp */
/*******************************************************************************
**
** CF_ProcessMsg tests
**
*******************************************************************************/
void Test_CF_ProcessMsg_ProcessGroundCommand(void)
{
/* Arrange */
CFE_SB_Buffer_t sbbuf;
CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_CMD_MID);
memset(&sbbuf, 0, sizeof(sbbuf));
/* CFE_MSG_GetMsgId uses return by ref */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
/* Act */
CF_ProcessMsg(&sbbuf);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1);
UtAssert_STUB_COUNT(CF_ProcessGroundCommand, 1);
} /* end Test_CF_ProcessMsg_ProcessGroundCommand */
void Test_CF_ProcessMsg_WakeUp(void)
{
/* Arrange */
CFE_SB_Buffer_t sbbuf;
CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_WAKE_UP_MID);
memset(&sbbuf, 0, sizeof(sbbuf));
/* CFE_MSG_GetMsgId uses return by ref */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
/* Act */
CF_ProcessMsg(&sbbuf);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1);
UtAssert_STUB_COUNT(CF_CFDP_CycleEngine, 1);
} /* end Test_CF_ProcessMsg_WakeUp */
void Test_CF_ProcessMsg_SendHk(void)
{
CFE_SB_Buffer_t sbbuf;
CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_SEND_HK_MID);
memset(&sbbuf, 0, sizeof(sbbuf));
/* CFE_MSG_GetMsgId uses return by ref */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
/* Act */
CF_ProcessMsg(&sbbuf);
/* Assert */
UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_STUB_COUNT(CFE_MSG_SetMsgTime, 1); /* Confirms CF_HkCmd path was taken */
} /* end Test_CF_ProcessMsg_SendHk */
void Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath(void)
{
/* Arrange */
CFE_SB_MsgId_t forced_MsgID = CFE_SB_INVALID_MSG_ID;
CFE_SB_Buffer_t *arg_msg = NULL;
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
/* Act */
CF_ProcessMsg(arg_msg);
/* Assert */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_INIT_CMD_LENGTH);
} /* end Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath */
/* end CF_ProcessMsg tests */
/*******************************************************************************
**
** CF_AppMain tests
**
*******************************************************************************/
void Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_ERROR(
void)
{
/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false);
UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), -1);
/* Act */
CF_AppMain();
/* Assert */
UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 2);
UtAssert_STUB_COUNT(CFE_ES_RunLoop, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_UINT32_EQ(CF_AppData.run_status, CFE_ES_RunStatus_APP_ERROR);
} /* end Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_ERROR
*/
void Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases(void)
{
CFE_SB_Buffer_t sbbuf;
CFE_SB_Buffer_t *sbbufptr = NULL;
uint16 events[2] = {0};
memset(&sbbuf, 0, sizeof(sbbuf));
/* Run loop once */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false);
/* Capture events */
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);
/* Unit under test does not use the buffer in this case */
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, -1);
/* Act */
UtAssert_VOIDCALL(CF_AppMain());
/* Assert */
UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 4);
UtAssert_STUB_COUNT(CFE_ES_RunLoop, 2);
UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1);
/* Event from CF_Init and CF_AppMain */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(events[1], CF_EID_ERR_INIT_MSG_RECV);
/* Reset, return CFE_SUCCESS from CFE_SB_ReceiveBuffer and buffer NULL */
UT_ResetState(UT_KEY(CFE_EVS_SendEvent));
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UtAssert_VOIDCALL(CF_AppMain());
/* Event from CF_Init and CF_AppMain */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(events[1], CF_EID_ERR_INIT_MSG_RECV);
/* Reset, return non-error codes and non-NULL buffer */
UT_ResetState(UT_KEY(CFE_EVS_SendEvent));
UT_ResetState(UT_KEY(CFE_ES_RunLoop));
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);
sbbufptr = &sbbuf;
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_TIME_OUT);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_NO_MESSAGE);
UtAssert_VOIDCALL(CF_AppMain());
/* Event from CF_Init */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_STUB_COUNT(CFE_ES_RunLoop, 3);
}
void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg(void)
{
/* Arrange */
CFE_SB_MsgId_t forced_MsgID = CFE_SB_INVALID_MSG_ID;
CFE_SB_Buffer_t fake_msg;
CFE_SB_Buffer_t *dummy_msg = &fake_msg;
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false);
/* Actual data not used, just address is needed */
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &dummy_msg, sizeof(dummy_msg), false);
/* Arrange unstubbable: CF_ProcessMsg, invalid ID */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
/* Act */
CF_AppMain();
/* Assert */
UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 4);
UtAssert_STUB_COUNT(CFE_ES_RunLoop, 2);
UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1);
/* Assert for CF_Init call and CF_ProcessMsg */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
/* Assert for CF_ProcessMsg */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);
} /* end Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg */
/* end CF_AppMain tests */
/*******************************************************************************
**
** cf_app_tests UtTest_Add groups
**
*******************************************************************************/
void add_CF_HkCmd_tests(void)
{
UtTest_Add(Test_CF_HkCmd, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_HkCmd");
}
void add_CF_CheckTables_tests(void)
{
UtTest_Add(Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled");
UtTest_Add(Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent,
Setup_cf_config_table_tests, CF_App_Tests_Teardown,
"Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent");
UtTest_Add(Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent");
UtTest_Add(
Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent,
Setup_cf_config_table_tests, CF_App_Tests_Teardown,
"Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent");
UtTest_Add(Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS");
UtTest_Add(Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED");
} /* end add_CF_CheckTables_tests */
void add_CF_ValidateConfigTable_tests(void)
{
UtTest_Add(Test_CF_ValidateConfigTable_FailBecauseTableTicksPerSecondIs0, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_ValidateConfigTable_FailBecauseTableTicksPerSecondIs0");
UtTest_Add(Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIs0, Setup_cf_config_table_tests,
CF_App_Tests_Teardown, "Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIs0");
UtTest_Add(Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIsNot1024ByteAligned,
Setup_cf_config_table_tests, CF_App_Tests_Teardown,
"Test_CF_ValidateConfigTable_FailBecauseCalcBytesPerWakeupIsNot1024ByteAligned");
UtTest_Add(Test_CF_ValidateConfigTable_FailBecauseOutgoingFileChunkSmallerThanDataArray,
Setup_cf_config_table_tests, CF_App_Tests_Teardown,
"Test_CF_ValidateConfigTable_FailBecauseOutgoingFileChunkSmallerThanDataArray");
UtTest_Add(Test_CF_ValidateConfigTable_Success, Setup_cf_config_table_tests, CF_App_Tests_Teardown,
"Test_CF_ValidateConfigTable_Success");
} /* end add_CF_ValidateConfigTable_tests */
void add_CF_TableInit_tests(void)
{
UtTest_Add(Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess, cf_app_tests_Setup,
CF_App_Tests_Teardown, "Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess");
UtTest_Add(Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess, cf_app_tests_Setup,
CF_App_Tests_Teardown, "Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess");
UtTest_Add(Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess, cf_app_tests_Setup,
CF_App_Tests_Teardown, "Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess");
UtTest_Add(Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess, cf_app_tests_Setup,
CF_App_Tests_Teardown, "Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess");
UtTest_Add(Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoNotSendEvent,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoNotSendEvent");
UtTest_Add(Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_SuccessAndDoNotSendEvent,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_SuccessAndDoNotSendEvent");
} /* end add_CF_TableInit_tests */
void add_CF_Init_tests(void)
{
UtTest_Add(
Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus");
UtTest_Add(
Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus");
UtTest_Add(
Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus");
UtTest_Add(Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus, cf_app_tests_Setup,
CF_App_Tests_Teardown, "Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus");
UtTest_Add(Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus, cf_app_tests_Setup,
CF_App_Tests_Teardown,
"Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus");
UtTest_Add(
Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus");
UtTest_Add(Test_CF_Init_Success, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_Init_Success");
} /* end add_CF_Init_tests */
void add_CF_WakeUp_tests(void)
{
UtTest_Add(Test_CF_WakeUp, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_WakeUp");
} /* end add_CF_WakeUp_tests */
void add_CF_ProcessMsg_tests(void)
{
UtTest_Add(Test_CF_ProcessMsg_ProcessGroundCommand, cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_ProcessMsg_ProcessGroundCommand");
UtTest_Add(Test_CF_ProcessMsg_WakeUp, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_ProcessMsg_WakeUp");
UtTest_Add(Test_CF_ProcessMsg_SendHk, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_ProcessMsg_SendHk");
UtTest_Add(Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath, cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath");
} /* end add_CF_ProcessMsg_tests */
void add_CF_AppMain_tests(void)
{
UtTest_Add(
Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_ERROR,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_"
"ERROR");
UtTest_Add(Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases, cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases");
UtTest_Add(
Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg,
cf_app_tests_Setup, CF_App_Tests_Teardown,
"Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg");
} /* end add_CF_AppMain_tests */
/* end cf_app_tests UtTest_Add groups */
/*******************************************************************************
**
** cf_app_tests test UtTest_Setup
**
*******************************************************************************/
void UtTest_Setup(void)
{
TestUtil_InitializeRandomSeed();
add_CF_HkCmd_tests();
add_CF_CheckTables_tests();
add_CF_ValidateConfigTable_tests();
add_CF_TableInit_tests();
add_CF_Init_tests();
add_CF_WakeUp_tests();
add_CF_ProcessMsg_tests();
add_CF_AppMain_tests();
}
/* end cf_app_tests.c */