-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_cfdp_tests.c
10198 lines (8199 loc) · 473 KB
/
cf_cfdp_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
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
/* cf testing includes */
#include "cf_test_utils.h"
/* undefs/redefs for stubbing before source inclusion */
#undef cfdp_set_uint8
#define cfdp_set_uint8(dst, src) (dst) = (src)
#undef cfdp_set_uint16
#define cfdp_set_uint16(dst, src) (dst) = (src)
#undef cfdp_get_uint16
#define cfdp_get_uint16(dst, src) (dst) = (src)
#undef cfdp_ldst_uint16
#define cfdp_ldst_uint16(dst, src) (dst) = (src)
#undef cfdp_get_uint32
#define cfdp_get_uint32(dst, src) (dst) = (src)
#undef cfdp_ldst_uint32
#define cfdp_ldst_uint32(dst, src) (dst) = (src)
/* stub redefines for unit testing */
#undef FGV
#define FGV Stub_FGV
int32 Stub_FGV(uint8 source, CF_FIELD_FIELD name);
#undef cf_dequeue_transaction
#define cf_dequeue_transaction Stub_cf_dequeue_transaction
void cf_dequeue_transaction(transaction_t *t);
#undef CF_CList_InsertBack_Ex
#define CF_CList_InsertBack_Ex Stub_CF_CList_InsertBack_Ex
void Stub_CF_CList_InsertBack_Ex(channel_t *c, cf_queue_index_t index, clist_node node);
#include "cf_cfdp.c"
#include "cf_cfdp_pdu.h"
/* cf_cfdp_tests globals */
extern type_of_context_CF_CList_Traverse_t type_of_context_CF_CList_Traverse;
/*******************************************************************************
**
** cf_cfdp_tests local utility functions
**
*******************************************************************************/
uint8 Any_cf_queue_index_t_Except(uint8 exception)
{
uint8 num_checks = 0;
const uint8 max_checks = 10;
uint8 random_val = exception;
while (random_val == exception)
{
random_val = rand() % CF_Q_NUM;
if (num_checks >= max_checks)
{
UtPrintf("Any_cf_queue_index_t_Except unable to get valid number in %u checks\n", num_checks);
UtAssert_Abort("Any_cf_queue_index_t_Except failed");
}
else
{
++num_checks;
}
}
return random_val;
}
/* uint8 selected for ease of use */
uint8 Any_cfdp_state_t(void)
{
uint8 random_val = rand() % CFDP_INVALID;
return random_val;
}
uint8 Any_cfdp_state_t_ExceptThese(uint8 exceptions[], uint8 num_exceptions)
{
uint8 i = 0;
uint8 num_checks = 0;
const uint8 max_checks = 10;
uint8 random_val = Any_cfdp_state_t();
while (i < num_exceptions)
{
if (random_val == exceptions[i])
{
random_val = Any_cfdp_state_t();
i = 0;
if (num_checks >= max_checks)
{
UtPrintf("Any_cfdp_state_t_ExceptThese unable to get valid number in %u checks\n", num_checks);
UtAssert_Abort("Any_cfdp_state_t_ExceptThese failed");
}
else
{
++num_checks;
}
}
else
{
++i;
}
}
return random_val;
}
file_directive_t Any_file_directive_t_Except(file_directive_t exception)
{
uint8 num_tries = 0;
uint8 max_tries = 10;
file_directive_t rand_val = rand() % PDU_INVALID_MAX;
while (rand_val == exception)
{
if (++num_tries > max_tries)
{
UtPrintf("Unable to achieve different random value within %u tries.", max_tries);
assert(ERROR_RETRIEVING_ANY_VALUE);
}
rand_val = rand() % PDU_INVALID_MAX;
}
return rand_val;
}
direction_t Any_direction_t(void)
{
return (direction_t)Any_uint8_LessThan(CF_DIR_NUM);
}
cfdp_class_t Any_cfdp_class_t(void)
{
if (AnyCoinFlip())
{
return CLASS_1;
}
else
{
return CLASS_2;
}
}
void Handler_int_ForcedReturnArray(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
int forced_return;
uint8 array_location = UT_GetStubCount(FuncKey) - 1;
memcpy(&forced_return, ((uint8 *)UserObj + array_location * sizeof(forced_return)), sizeof(forced_return));
UT_Stub_SetReturnValue(FuncKey, forced_return);
}
void Handler_size_t_ForcedReturnOnly(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
size_t forced_return;
memcpy(&forced_return, UserObj, sizeof(forced_return));
UT_Stub_SetReturnValue(FuncKey, forced_return);
}
uint8 callNumberToSet_notNULL_for_CF_CFDP_S1_Tx_args_c_cur = 0;
void Handler_CF_CFDP_S1_Tx_notNull_cur_AtSetCallNumber(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
CF_CFDP_CycleTx_args_t *args = (CF_CFDP_CycleTx_args_t *)UserObj;
if (UT_GetStubCount(FuncKey) >= callNumberToSet_notNULL_for_CF_CFDP_S1_Tx_args_c_cur)
{
args->c->cur = CF_AppData.engine.transactions; /* args->c->cur = CF_AppData.engine.transactions is used to set
to an arbitrary transaction that exists */
}
}
void Handler_CF_CFDP_S1_Tx_notCF_Q_TXA_q_index(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
transaction_t *t = *((transaction_t **)((uint8 *)UserObj + sizeof(void *)));
if (UT_GetStubCount(FuncKey) > 1)
{
t->flags.all.q_index = CF_Q_NUM;
}
}
void Handler_CF_CList_Traverse_Set_ran_one_To_1(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
CF_CFDP_CycleTx_args_t *stub_context = UT_Hook_GetArgValueByName(Context, "context", CF_CFDP_CycleTx_args_t *);
stub_context->ran_one = 1;
}
void Handler_CF_CList_Traverse_SecondCallSet_ran_one_To_1(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
if (UT_GetStubCount(FuncKey) == 2)
{
Handler_CF_CList_Traverse_Set_ran_one_To_1(UserObj, FuncKey, Context);
}
}
void *Dummy_tick_args_t_fn(transaction_t *t, int *cont)
{
UT_GenStub_Execute(Dummy_tick_args_t_fn, Basic, NULL);
return NULL;
}
void Handler_Dummy_tick_args_t_fn_Set_cur_notNULL(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
transaction_t **cur = (transaction_t **)UserObj;
*cur = CF_AppData.engine.transactions; /* *cur = CF_AppData.engine.transactions is used to set to an arbitrary
transaction that exists */
}
void Handler_CF_CList_Traverse_Sets_args_early_exit_To_1(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
tick_args_t *args = UT_Hook_GetArgValueByName(Context, "context", tick_args_t *);
args->early_exit = 1;
}
void Handler_CF_CList_Traverse_Sets_args_cont_To_1_UntilGivenCount(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
tick_args_t *args = UT_Hook_GetArgValueByName(Context, "context", tick_args_t *);
uint32 *stop_count = (uint32 *)UserObj;
if (UT_GetStubCount(FuncKey) >= *stop_count)
{
args->cont = 0;
}
else
{
args->cont = 1;
}
}
void Handler_OS_DirectoryClose_ReportOnly(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
/* Handler_OS_DirectoryClose_ReportOnly does nothing, written to override OS_DirectoryClose follow-on behavior that
* causes failures and is not required for unit testing */
}
void Handler_OS_DirectoryRead_Set_dirent_FileName_ToGivenString(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
os_dirent_t *dirent = UT_Hook_GetArgValueByName(Context, "dirent", os_dirent_t *);
memcpy(dirent->FileName, UserObj, OS_MAX_FILE_NAME);
}
/* int32 selected only for ease of Stub use */
int32 Stub_FGV(uint8 source, CF_FIELD_FIELD name)
{
UT_GenStub_SetupReturnBuffer(Stub_FGV, int32);
UT_GenStub_AddParam(Stub_FGV, uint8, source);
UT_GenStub_AddParam(Stub_FGV, CF_FIELD_FIELD, name);
UT_GenStub_Execute(Stub_FGV, Basic, NULL);
return UT_GenStub_GetReturnValue(Stub_FGV, int32);
}
void Handler_CF_Timer_InitRelSec_Change_t_state_To_CFDP_IDLE(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
((transaction_t *)UserObj)->state = CFDP_IDLE;
}
void handler_CFE_SB_AllocateMessageBuffer_ReturnForced_CFE_SB_Buffer(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
UT_Stub_SetReturnValue(FuncKey, UserObj);
}
void Stub_cf_dequeue_transaction(transaction_t *t)
{
UT_GenStub_AddParam(Stub_cf_dequeue_transaction, transaction_t *, t);
UT_GenStub_Execute(Stub_cf_dequeue_transaction, Basic, NULL);
}
void handler_CF_CList_InsertBack_Ex_Record_indexes(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
cf_queue_index_t index = UT_Hook_GetArgValueByName(Context, "index", cf_queue_index_t);
*(((cf_queue_index_t *)UserObj) + (UT_GetStubCount(FuncKey) - 1)) = index;
}
void Stub_CF_CList_InsertBack_Ex(channel_t *c, cf_queue_index_t index, clist_node node)
{
UT_GenStub_AddParam(Stub_CF_CList_InsertBack_Ex, channel_t *, c);
UT_GenStub_AddParam(Stub_CF_CList_InsertBack_Ex, cf_queue_index_t, index);
UT_GenStub_AddParam(Stub_CF_CList_InsertBack_Ex, clist_node, node);
UT_GenStub_Execute(Stub_CF_CList_InsertBack_Ex, Basic, NULL);
}
void handler_OS_remove_Report_path(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
*((char **)UserObj) = UT_Hook_GetArgValueByName(Context, "path", char *);
}
/* end cf_cfdp_tests local utility functions */
/*******************************************************************************
**
** cf_cfdp_tests Setup and Teardown
**
*******************************************************************************/
void cf_cfdp_tests_Setup(void)
{
cf_tests_Setup();
} /* end cf_cfdp_tests_Setup */
void cf_cfdp_tests_Teardown(void)
{
cf_tests_Teardown();
} /* end cf_cfdp_tests_Teardown */
/* end cf_cfdp_tests Setup and Teardown */
/*******************************************************************************
**
** CF_CFDP_ArmAckTimer tests (simple) - full coverage
**
*******************************************************************************/
void Test_CF_CFDP_ArmAckTimer_Call_CF_Timer_InitRelSec_WithCorrectParamsAndArmsTimer(void)
{
/* Arrange */
transaction_t dummy_t;
transaction_t *arg_t = &dummy_t;
cf_config_table_t dummy_config_table;
CF_Timer_InitRelSec_context_t context_CF_Timer_InitRelSec;
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->ack_timer_s = Any_uint32();
arg_t->flags.all.ack_timer_armed = 0; /* not required but helps show assert */
UT_SetDataBuffer(UT_KEY(CF_Timer_InitRelSec), &context_CF_Timer_InitRelSec, sizeof(context_CF_Timer_InitRelSec),
false);
/* Act */
CF_CFDP_ArmAckTimer(arg_t);
/* Assert */
UtAssert_STUB_COUNT(CF_Timer_InitRelSec, 1);
UtAssert_ADDRESS_EQ(context_CF_Timer_InitRelSec.t, &arg_t->ack_timer);
UtAssert_True(context_CF_Timer_InitRelSec.rel_sec == CF_AppData.config_table->ack_timer_s,
"CF_Timer_InitRelSec received rel_sec %u and should be %u (CF_AppData.config_table->ack_timer_s)",
context_CF_Timer_InitRelSec.rel_sec, CF_AppData.config_table->ack_timer_s);
UtAssert_True(arg_t->flags.all.ack_timer_armed == 1,
"CF_CFDP_ArmAckTimer set ack_timer_armed to %u and should be 1", arg_t->flags.all.ack_timer_armed);
} /* end Test_CF_CFDP_ArmAckTimer_Call_CF_Timer_InitRelSec_WithCorrectParamsAndArmsTimer */
/* end CF_CFDP_ArmAckTimer tests */
/*******************************************************************************
**
** CF_CFDP_GetClass tests (simple) - full coverage - 1 coverage JIRA issue
**
*******************************************************************************/
void Test_CF_CFDP_GetClass_AssertsBecause_q_index_IsEqTo_CF_Q_FREE(void)
{
/* Arrange */
// transaction_t dummy_ti;
// transaction_t* arg_ti = &dummy_ti;
// arg_ti->flags.all.q_index = CF_Q_FREE;
// /* Act */
// //CF_CFDP_GetClass(arg_ti);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_GetClass_AssertsBecause_q_index_IsEqTo_CF_Q_FREE */
void Test_CF_CFDP_GetClass_WhenNeitherStateIsSet_Return_CLASS_1(void)
{
/* Arrange */
uint8 excepted_states[2] = {CFDP_S2, CFDP_R2};
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
cfdp_class_t local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = Any_cfdp_state_t_ExceptThese(excepted_states, sizeof(excepted_states) / sizeof(excepted_states[0]));
/* Act */
local_result = CF_CFDP_GetClass(arg_ti);
/* Assert */
UtAssert_True(local_result == CLASS_1, "CF_CFDP_GetClass returned %u and should be %u (CLASS_1)", local_result,
CLASS_1);
} /* end Test_CF_CFDP_GetClass_WhenNeitherStateIsSet_Return_CLASS_1 */
void Test_CF_CFDP_GetClass_WhenStateIs_CFDP_S2_Return_CLASS_1(void)
{
/* Arrange */
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
cfdp_class_t local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = CFDP_S2;
/* Act */
local_result = CF_CFDP_GetClass(arg_ti);
/* Assert */
UtAssert_True(local_result == CLASS_2, "CF_CFDP_GetClass returned %u and should be %u (CLASS_2)", local_result,
CLASS_2);
} /* end Test_CF_CFDP_GetClass_WhenStateIs_CFDP_S2_Return_CLASS_1 */
void Test_CF_CFDP_GetClass_WhenStateIs_CFDP_R2_Return_CLASS_1(void)
{
/* Arrange */
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
cfdp_class_t local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = CFDP_R2;
/* Act */
local_result = CF_CFDP_GetClass(arg_ti);
/* Assert */
UtAssert_True(local_result == CLASS_2, "CF_CFDP_GetClass returned %u and should be %u (CLASS_2)", local_result,
CLASS_2);
} /* end Test_CF_CFDP_GetClass_WhenStateIs_CFDP_R2_Return_CLASS_1 */
/* end CF_CFDP_GetClass tests */
/*******************************************************************************
**
** CF_CFDP_IsSender tests (simple) - full coverage - 1 coverage JIRA issue
**
*******************************************************************************/
void Test_CF_CFDP_IsSender_AssertsBecause_q_index_IsEqTo_CF_Q_FREE(void)
{
// /* Arrange */
// transaction_t dummy_ti;
// transaction_t* arg_ti = &dummy_ti;
// arg_ti->flags.all.q_index = CF_Q_FREE;
// /* Act */
// CF_CFDP_IsSender(arg_ti);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_IsSender_AssertsBecause_q_index_IsEqTo_CF_Q_FREE */
void Test_CF_CFDP_IsSender_WhenNeitherStateIsSetReturn_0_MeaningReciever(void)
{
/* Arrange */
uint8 excepted_states[2] = {CFDP_S1, CFDP_S2};
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
int local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = Any_cfdp_state_t_ExceptThese(excepted_states, sizeof(excepted_states) / sizeof(excepted_states[0]));
/* Act */
local_result = CF_CFDP_IsSender(arg_ti);
/* Assert */
UtAssert_True(local_result == 0, "CF_CFDP_GetClass returned %u and should be 0 (receiver)", local_result);
} /* end Test_CF_CFDP_IsSender_WhenNeitherStateIsSetReturn_0_MeaningReciever */
void Test_CF_CFDP_IsSender_WhenStateIs_CFDP_S1_Return_1_MeaningSender(void)
{
/* Arrange */
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
int local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = CFDP_S1;
/* Act */
local_result = CF_CFDP_IsSender(arg_ti);
/* Assert */
UtAssert_True(local_result == 1, "CF_CFDP_GetClass returned %u and should be 1 (sender)", local_result);
} /* end Test_CF_CFDP_IsSender_WhenStateIs_CFDP_S1_Return_1_MeaningSender */
void Test_CF_CFDP_IsSender_WhenStateIs_CFDP_S2_Return_1_MeaningSender(void)
{
/* Arrange */
transaction_t dummy_ti;
transaction_t *arg_ti = &dummy_ti;
int local_result;
arg_ti->flags.all.q_index = Any_cf_queue_index_t_Except(CF_Q_FREE);
arg_ti->state = CFDP_S2;
/* Act */
local_result = CF_CFDP_IsSender(arg_ti);
/* Assert */
UtAssert_True(local_result == 1, "CF_CFDP_GetClass returned %u and should be 1 (sender)", local_result);
} /* end Test_CF_CFDP_IsSender_WhenStateIs_CFDP_S2_Return_1_MeaningSender */
/* end CF_CFDP_IsSender tests */
/*******************************************************************************
**
** CF_CFDP_ArmInactTimer tests (simple) - full coverage
**
*******************************************************************************/
void Test_CF_CFDP_ArmInactTimer_Call_CF_Timer_InitRelSec_WithCorrectParams(void)
{
/* Arrange */
transaction_t dummy_t;
transaction_t *arg_t = &dummy_t;
cf_config_table_t dummy_config_table;
CF_Timer_InitRelSec_context_t context_CF_Timer_InitRelSec;
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->inactivity_timer_s = Any_uint32();
UT_SetDataBuffer(UT_KEY(CF_Timer_InitRelSec), &context_CF_Timer_InitRelSec, sizeof(context_CF_Timer_InitRelSec),
false);
/* Act */
CF_CFDP_ArmInactTimer(arg_t);
/* Assert */
UtAssert_STUB_COUNT(CF_Timer_InitRelSec, 1);
UtAssert_ADDRESS_EQ(context_CF_Timer_InitRelSec.t, &arg_t->inactivity_timer);
UtAssert_True(context_CF_Timer_InitRelSec.rel_sec == CF_AppData.config_table->inactivity_timer_s,
"CF_Timer_InitRelSec received rel_sec %u and should be %u (CF_AppData.config_table->ack_timer_s)",
context_CF_Timer_InitRelSec.rel_sec, CF_AppData.config_table->inactivity_timer_s);
} /* end Test_CF_CFDP_ArmInactTimer_Call_CF_Timer_InitRelSec_WithCorrectParams */
/* end CF_CFDP_ArmInactTimer tests */
/*******************************************************************************
**
** CF_CFDP_DispatchRecv tests (small) - full coverage - 1 coverage JIRA issue - [unstubbables: CF_CFDP_RecvIdle,
*CF_CFDP_R1_Recv, CF_CFDP_S1_Recv, CF_CFDP_R2_Recv, CF_CFDP_S2_Recv, CF_CFDP_RecvDrop, CF_CFDP_ArmInactTimer]
** NOTE: unstubbables for CF_CFDP_DispatchRecv tests are wrong, most of these calls are stubbable
**
*******************************************************************************/
void Test_CF_CFDP_DispatchRecv_AssertsBecause_t_state_EqTo_CFDP_INVALID(void)
{
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_INVALID;
// /* Act */
// CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->state<CFDP_INVALID");
} /* end Test_CF_CFDP_DispatchRecv_AssertsBecause_t_state_EqTo_CFDP_INVALID */
/* TODO: Test_CF_CFDP_DispatchRecv_AssertsBecause_t_state_GreaterThan_CFDP_INVALID not required but desired */
// void Test_CF_CFDP_DispatchRecv_AssertsBecause_t_state_GreaterThan_CFDP_INVALID(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = Any_uint8_GreaterThan(CFDP_INVALID);
// /* Act */
// //CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->state<CFDP_INVALID");
// } /* end Test_CF_CFDP_DispatchRecv_AssertsBecause_t_state_GreaterThan_CFDP_INVALID */
// TODO: CF_CFDP_DispatchRecv tests really should check all the possible states, but only 1 is necessary for coverage
// void Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_RecvIdle_BecauseStateEq_CFDP_IDLE(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_IDLE;
// /* Act */
// //CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_Failed("Deep Setup - uses CF_CFDP_RecvIdle, CF_CFDP_ArmInactTimer");
// } /* end Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_RecvIdle_BecauseStateEq_CFDP_IDLE */
// void Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_R1_Recv_BecauseStateEq_CFDP_R1(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_R1;
// /* Act */
// //CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_Failed("Deep Setup - uses CF_CFDP_R1_Recv, CF_CFDP_ArmInactTimer");
// } /* end Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_R1_Recv_BecauseStateEq_CFDP_R1 */
// void Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_S1_Recv_BecauseStateEq_CFDP_S1(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_S1;
// /* Act */
// //CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_Failed("Deep Setup - uses CF_CFDP_S1_Recv, CF_CFDP_ArmInactTimer");
// } /* end Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_S1_Recv_BecauseStateEq_CFDP_S1 */
// void Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_R2_Recv_BecauseStateEq_CFDP_R2(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_R2;
// /* Act */
// //CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_Failed("Deep Setup - uses CF_CFDP_R2_Recv, CF_CFDP_ArmInactTimer");
// } /* end Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_R2_Recv_BecauseStateEq_CFDP_R2 */
// void Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_S2_Recv_BecauseStateEq_CFDP_S2(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_S2;
// /* Act */
// // CF_CFDP_DispatchRecv(arg_t);
// /* Assert */
// UtAssert_Failed("Deep Setup - uses CF_CFDP_S2_Recv, CF_CFDP_ArmInactTimer");
// } /* end Test_CF_CFDP_DispatchRecv_Calls_CF_CFDP_S2_Recv_BecauseStateEq_CFDP_S2 */
void Test_CF_CFDP_DispatchRecv_WhenStateEq_CFDP_DROP_Call_CF_CFDP_RecvDrop(void)
{
/* Arrange */
transaction_t dummy_t;
transaction_t *arg_t = &dummy_t;
uint16 initial_recv_dropped = Any_uint16();
arg_t->state = CFDP_DROP;
CF_AppData.hk.channel_hk[arg_t->chan_num].counters.recv.dropped = initial_recv_dropped;
/* Arrange for CF_CFDP_ArmInactTimer */
cf_config_table_t dummy_config_table;
CF_AppData.config_table = &dummy_config_table;
/* Act */
CF_CFDP_DispatchRecv(arg_t);
/* Assert */
UtAssert_True(CF_AppData.hk.channel_hk[arg_t->chan_num].counters.recv.dropped == (uint16)(initial_recv_dropped + 1),
"CF_AppData recv.dropped is %u and should be 1 more than %u (value before call)",
CF_AppData.hk.channel_hk[arg_t->chan_num].counters.recv.dropped, initial_recv_dropped);
/* Assert for CF_CFDP_ArmInactTimer */
UtAssert_STUB_COUNT(CF_Timer_InitRelSec, 1);
} /* end Test_CF_CFDP_DispatchRecv_WhenStateEq_CFDP_DROP_Call_CF_CFDP_RecvDrop */
/* end CF_CFDP_DispatchRecv tests */
/*******************************************************************************
**
** CF_CFDP_DispatchTx tests (small) - full coverage - 2 coverage JIRA issue
**
*******************************************************************************/
void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_INVALID(void)
{
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_INVALID;
// /* Act */
// CF_CFDP_DispatchTx(arg_t);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->state<CFDP_INVALID");
} /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_INVALID */
/* TODO: Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_GreaterThanOrEqTo_CFDP_INVALID desired but not required */
// void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_GreaterThanOrEqTo_CFDP_INVALID(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = Any_uint8_GreaterThan(CFDP_INVALID);
// /* Act */
// //CF_CFDP_DispatchTx(arg_t);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
// } /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_GreaterThanOrEqTo_CFDP_INVALID */
void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_IDLE(void)
{
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_IDLE;
// /* Act */
// CF_CFDP_DispatchTx(arg_t);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_IDLE */
/* TODO: Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R1 desired but not required */
// void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R1(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_R1;
// /* Act */
// //CF_CFDP_DispatchTx(arg_t);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
// } /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R1 */
/* TODO: Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R2 desired but not required */
// void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R2(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_R2;
// /* Act */
// //CF_CFDP_DispatchTx(arg_t);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
// } /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_R2 */
/* TODO: Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_DROP desired but not required */
// void Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_DROP(void)
// {
// /* Arrange */
// transaction_t dummy_t;
// transaction_t* arg_t = &dummy_t;
// arg_t->state = CFDP_DROP;
// /* Act */
// //CF_CFDP_DispatchTx(arg_t);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
// } /* end Test_CF_CFDP_DispatchTx_AssertsBecause_t_state_EqTo_CFDP_DROP */
void Test_CF_CFDP_DispatchTx_When_t_state_EqTo_CFDP_S1_Call_CF_CFDP_S1_Tx(void)
{
/* Arrange */
transaction_t dummy_t;
transaction_t *arg_t = &dummy_t;
transaction_t *context_CF_CFDP_S1_Tx;
arg_t->state = CFDP_S1;
UT_SetDataBuffer(UT_KEY(CF_CFDP_S1_Tx), &context_CF_CFDP_S1_Tx, sizeof(context_CF_CFDP_S1_Tx), false);
/* Act */
CF_CFDP_DispatchTx(arg_t);
/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_S1_Tx, 1);
UtAssert_ADDRESS_EQ(context_CF_CFDP_S1_Tx, arg_t);
} /* end Test_CF_CFDP_DispatchTx_When_t_state_EqTo_CFDP_S1_Call_CF_CFDP_S1_Tx */
void Test_CF_CFDP_DispatchTx_Call_When_t_state_EqTo_CFDP_S2_CF_CFDP_S1_Tx(void)
{
/* Arrange */
transaction_t dummy_t;
transaction_t *arg_t = &dummy_t;
transaction_t *context_CF_CFDP_S2_Tx;
arg_t->state = CFDP_S2;
UT_SetDataBuffer(UT_KEY(CF_CFDP_S2_Tx), &context_CF_CFDP_S2_Tx, sizeof(context_CF_CFDP_S2_Tx), false);
/* Act */
CF_CFDP_DispatchTx(arg_t);
/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_S2_Tx, 1);
UtAssert_ADDRESS_EQ(context_CF_CFDP_S2_Tx, arg_t);
} /* end Test_CF_CFDP_DispatchTx_Call_When_t_state_EqTo_CFDP_S2_CF_CFDP_S1_Tx */
/* end CF_CFDP_DispatchTx tests */
/*******************************************************************************
**
** CF_CFDP_FindUnusedChunks tests (small) - full coverage - 2 coverage JIRA issue
**
*******************************************************************************/
void Test_CF_CFDP_FindUnusedChunks_AssertsBecause_dir_IsEq_CF_DIR_NUM(void)
{
/* Arrange */
// channel_t dummy_c;
// channel_t* arg_c = &dummy_c;
// direction_t arg_dir = CF_DIR_NUM;
/* Act */
// CF_CFDP_FindUnusedChunks(arg_c, arg_dir);
/* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_FindUnusedChunks_AssertsBecause_dir_IsEq_CF_DIR_NUM */
/* TODO: Test_CF_CFDP_FindUnusedChunks_AssertsBecause_dir_IsGreaterThan_CF_DIR_NUM desired but not required */
// void Test_CF_CFDP_FindUnusedChunks_AssertsBecause_dir_IsGreaterThan_CF_DIR_NUM(void)
// {
// /* Arrange */
// // channel_t dummy_c;
// // channel_t* arg_c = &dummy_c;
// // direction_t arg_dir = Any_uint8_GreaterThan(CF_DIR_NUM);
// /* Act */
// //CF_CFDP_FindUnusedChunks(arg_c, arg_dir);
// /* Assert */
// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
// } /* end Test_CF_CFDP_FindUnusedChunks_AssertsBecause_dir_IsGreaterThan_CF_DIR_NUM */
void Test_CF_CFDP_FindUnusedChunks_AssertsBecause_c_cs_dir_IsNull(void)
{
/* Arrange */
// channel_t dummy_c;
// channel_t* arg_c = &dummy_c;
// direction_t arg_dir = Any_direction_t();
// arg_c->cs[arg_dir] = NULL;
/* Act */
// CF_CFDP_FindUnusedChunks(arg_c, arg_dir);
/* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_FindUnusedChunks_AssertsBecause_c_cs_dir_IsNull */
void Test_CF_CFDP_FindUnusedChunks_Success(void)
{
/* Arrange */
channel_t dummy_c;
channel_t *arg_c = &dummy_c;
direction_t arg_dir = Any_direction_t();
chunks_wrapper_t dummy_expected_result;
chunks_wrapper_t *expected_result = &dummy_expected_result;
chunks_wrapper_t *local_result;
clist_node forced_return_CF_CList_Pop;
CF_CList_Pop_context_t context_CF_CList_Pop;
forced_return_CF_CList_Pop = &expected_result->cl_node;
arg_c->cs[arg_dir] = (clist_node)&forced_return_CF_CList_Pop;
context_CF_CList_Pop.forced_return = forced_return_CF_CList_Pop;
UT_SetDataBuffer(UT_KEY(CF_CList_Pop), &context_CF_CList_Pop, sizeof(context_CF_CList_Pop), false);
/* Act */
local_result = CF_CFDP_FindUnusedChunks(arg_c, arg_dir);
/* Assert */
UtAssert_ADDRESS_EQ(local_result, expected_result);
UtAssert_STUB_COUNT(CF_CList_Pop, 1);
UtAssert_ADDRESS_EQ(context_CF_CList_Pop.head, &arg_c->cs[arg_dir]);
} /* end Test_CF_CFDP_FindUnusedChunks_Success */
/* end CF_CFDP_FindUnusedChunks tests */
/*******************************************************************************
**
** CF_CFDP_FindUnusedTransaction tests (large) - full coverage - 3 coverage JIRA issue - [unstubbables:
*CF_CList_Remove_Ex]
**
*******************************************************************************/
void Test_CF_CFDP_FindUnusedTransaction_AssertsBecause_c_IsNull(void)
{
// /* Arrange */
// channel_t* arg_c;
// /* Act */
// CF_CFDP_FindUnusedTransaction(arg_c);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_FindUnusedTransaction_WhenNoFreeTransactionsAreAvailableReturn_NULL */
void Test_CF_CFDP_FindUnusedTransaction_AssertsBecause_q_size_CF_Q_HIST_IsNotLessThan_CF_NUM_HISTORIES_PER_CHANNEL(void)
{
// /* Arrange */
// channel_t* arg_c;
// /* Act */
// CF_CFDP_FindUnusedTransaction(arg_c);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_FindUnusedTransaction_AssertsBecause_q_size_CF_Q_HIST_IsNotLessThan_CF_NUM_HISTORIES_PER_CHANNEL
*/
void Test_CF_CFDP_FindUnusedTransaction_AssertsBecause_c_qs_CF_Q_HIST_IsNull(void)
{
// /* Arrange */
// channel_t* arg_c;
// /* Act */
// CF_CFDP_FindUnusedTransaction(arg_c);
// /* Assert */
UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert");
} /* end Test_CF_CFDP_FindUnusedTransaction_AssertsBecause_c_qs_CF_Q_HIST_IsNull */
void Test_CF_CFDP_FindUnusedTransaction_WhenNoFreeTransactionsAreAvailableReturn_NULL(void)
{
/* Arrange */
channel_t dummy_c;
channel_t *arg_c = &dummy_c;
transaction_t *local_result;
arg_c->qs[CF_Q_FREE] = NULL; /* No free transactions */
/* Act */
local_result = CF_CFDP_FindUnusedTransaction(arg_c);
/* Assert */
UtAssert_ADDRESS_EQ(local_result, NULL);
} /* end Test_CF_CFDP_FindUnusedTransaction_WhenNoFreeTransactionsAreAvailableReturn_NULL */
void Test_CF_CFDP_FindUnusedTransaction_WhenNoFreeHistoryReturnExpected_t(void)
{
/* Arrange */
channel_t *arg_c;
clist_node dummy_n;
history_t dummy_history;
transaction_t dummy_expected_t;
uint8 dummy_channel = Any_uint8_LessThan(CF_NUM_CHANNELS);
transaction_t *expected_t = &dummy_expected_t;
transaction_t *local_result;
CF_CList_Remove_context_t context_CF_CList_Remove;
dummy_n = &expected_t->cl_node;
arg_c = &CF_AppData.engine.channels[dummy_channel];
arg_c->qs[CF_Q_FREE] = dummy_n; /* No free transactions */
arg_c->qs[CF_Q_HIST] = &dummy_history.cl_node;
/* Arrange unstubbable: CF_CList_Remove_Ex */