-
Notifications
You must be signed in to change notification settings - Fork 46
/
cf_cmd_tests.c
4474 lines (3479 loc) · 169 KB
/
cf_cmd_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
/************************************************************************
* 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_cmd.h"
#include "cf_events.h"
#include "cf_test_alt_handler.h"
/*
* In order to properly instantiate buffers to pass to functions that
* accept a CFE_SB_Buffer_t, a union must be used to align the
* data.
*/
typedef union
{
CF_UnionArgsCmd_t ua;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_unionargs_buf_t;
typedef union
{
CF_SetParamCmd_t sp;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_set_param_args_buf_t;
typedef union
{
CF_GetParamCmd_t gp;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_get_param_args_buf_t;
typedef union
{
CF_TxFileCmd_t tf;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_tx_file_buf_t;
typedef union
{
CF_PlaybackDirCmd_t pd;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_playback_dir_buf_t;
typedef union
{
CF_TransactionCmd_t xact;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_transaction_buf_t;
typedef union
{
CF_WriteQueueCmd_t wq;
CFE_SB_Buffer_t buf;
} CF_UT_cmd_write_q_buf_t;
/*******************************************************************************
**
** cf_cmd_tests Setup and Teardown
**
*******************************************************************************/
void cf_cmd_tests_Setup(void)
{
cf_tests_Setup();
}
void cf_cmd_tests_Teardown(void)
{
cf_tests_Teardown();
}
/*******************************************************************************
**
** cf_cmd_tests specific Any functions NOTE:Some of these may be better as global
**
*******************************************************************************/
CF_CFDP_Class_t Any_cfdp_class_t(void)
{
return (CF_CFDP_Class_t)AnyCoinFlip();
}
CF_EntityId_t Any_CF_EntityId_t(void)
{
return (CF_EntityId_t)Any_uint8();
}
/* uint8 used for Any_cf_channel likely there will never be that many channels */
uint8 Any_cf_channel(void)
{
return Any_uint8_LessThan(CF_NUM_CHANNELS);
}
/* uint8 used for Any_cf_polldir likely there will never be that many polldirs */
uint8 Any_cf_polldir(void)
{
return Any_uint8_LessThan(CF_MAX_POLLING_DIR_PER_CHAN);
}
/* bool_arg_t_barg should only be 0 or 1 (Boolean) */
uint8 Any_bool_arg_t_barg(void)
{
return AnyCoinFlip();
}
uint8 Any_queue_Except_q_pend(void)
{
/* q_pend = 0, q_active = 1, q_history = 2, q_all = 3 */
return (rand() % 2) + 1; /* 0-2, + 1 -> 1-3 */
}
CF_TransactionSeq_t Any_CF_TransactionSeq_t(void)
{
return (CF_TransactionSeq_t)Any_uint32();
}
/*******************************************************************************
**
** cf_cmd_tests dummy test functions
**
*******************************************************************************/
typedef struct
{
CF_Transaction_t *t;
void * context;
} Dummy_CF_TsnChanAction_fn_t_context_t;
int Dummy_chan_action_fn_t(uint8 chan_num, void *context)
{
/* This one does not need to save its context, just call default so count works */
return UT_DEFAULT_IMPL(Dummy_chan_action_fn_t);
}
void Dummy_CF_TsnChanAction_fn_t(CF_Transaction_t *t, void *context)
{
Dummy_CF_TsnChanAction_fn_t_context_t *ctxt =
UT_CF_GetContextBuffer(UT_KEY(Dummy_CF_TsnChanAction_fn_t), Dummy_CF_TsnChanAction_fn_t_context_t);
if (ctxt)
{
ctxt->t = t;
ctxt->context = context;
}
UT_DEFAULT_IMPL(Dummy_CF_TsnChanAction_fn_t);
}
/*******************************************************************************
**
** CF_CmdNoop tests
**
*******************************************************************************/
void Test_CF_CmdNoop_SendNoopEventAndAcceptCommand(void)
{
/* Arrange */
CFE_SB_Buffer_t *arg_msg = NULL;
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdNoop(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_NOOP);
/* Assert to show counter incremented */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}
/*******************************************************************************
**
** CF_CmdReset tests
**
*******************************************************************************/
void Test_CF_CmdReset_tests_WhenCommandByteIsEqTo_5_SendEventAndRejectCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = 5; /* 5 is size of 'names' */
uint16 initial_hk_err_counter = Any_uint16();
CF_AppData.hk.counters.err = initial_hk_err_counter;
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_RESET_INVALID);
/* Assert incremented counter */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF);
}
void Test_CF_CmdReset_tests_WhenCommandByteIsGreaterThan_5_SendEventAndRejectCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = Any_uint8_GreaterThan(5); /* 5 is size of 'names' */
uint16 initial_hk_err_counter = Any_uint16();
CF_AppData.hk.counters.err = initial_hk_err_counter;
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_RESET_INVALID);
/* Assert incremented counter */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF);
}
void Test_CF_CmdReset_tests_WhenCommandByteIs_command_AndResetHkCmdAndErrCountSendEvent(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = CF_Reset_command;
CF_AppData.hk.counters.cmd = Any_uint16_Except(0);
CF_AppData.hk.counters.err = Any_uint16_Except(0);
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_RESET);
UtAssert_ZERO(CF_AppData.hk.counters.cmd);
UtAssert_ZERO(CF_AppData.hk.counters.err);
}
void Test_CF_CmdReset_tests_WhenCommandByteIs_fault_ResetAllHkFaultCountSendEventAndAcceptCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
int i = 0;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = CF_Reset_fault;
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.fault.file_open = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_read = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_seek = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_write = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_rename = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.directory_read = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.crc_mismatch = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_size_mismatch = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.nak_limit = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.ack_limit = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.inactivity_timer = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.spare = Any_uint16_Except(0);
}
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_RESET);
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_open);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_read);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_seek);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_write);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_rename);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.directory_read);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.crc_mismatch);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.file_size_mismatch);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.nak_limit);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.ack_limit);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.inactivity_timer);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.fault.spare);
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.fault, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.fault),
"fault channel %d was completely cleared to 0", i);
}
/* Assert to show counter incremented */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}
void Test_CF_CmdReset_tests_WhenCommandByteIs_up_AndResetAllHkRecvCountSendEventAndAcceptCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
int i = 0;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = CF_Reset_up;
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.recv.file_data_bytes = Any_uint64_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.pdu = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.error = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.spurious = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.dropped = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.nak_segment_requests = Any_uint32_Except(0);
}
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_RESET);
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.file_data_bytes);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.pdu);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.error);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.spurious);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.pdu);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.recv.nak_segment_requests);
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.recv, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.recv),
"recv channel %d was completely cleared to 0", i);
}
/* Assert to show counter incremented */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}
void Test_CF_CmdReset_tests_SWhenCommandByteIs_down_AndResetAllHkSentCountendEventAcceptCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
uint8 i = 0;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = CF_Reset_down;
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.sent.file_data_bytes = Any_uint64_Except(0);
CF_AppData.hk.channel_hk[i].counters.sent.nak_segment_requests = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.sent.pdu = Any_uint32_Except(0);
}
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_RESET);
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.sent.file_data_bytes);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.sent.nak_segment_requests);
UtAssert_ZERO(CF_AppData.hk.channel_hk[i].counters.sent.pdu);
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.sent, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.sent),
"sent channel %d was completely cleared to 0", i);
}
/* Assert to show counter incremented */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}
void Test_CF_CmdReset_tests_WhenCommandByteIs_all_AndResetAllMemValuesSendEvent(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
int i = 0;
memset(&utbuf, 0, sizeof(utbuf));
dummy_msg->data.byte[0] = CF_Reset_all;
CF_AppData.hk.counters.cmd = Any_uint16_Except(0);
CF_AppData.hk.counters.err = Any_uint16_Except(0);
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.fault.file_open = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_read = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_seek = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_write = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_rename = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.directory_read = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.crc_mismatch = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.file_size_mismatch = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.nak_limit = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.ack_limit = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.inactivity_timer = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.fault.spare = Any_uint16_Except(0);
}
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.recv.file_data_bytes = Any_uint64_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.pdu = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.error = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.spurious = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.dropped = Any_uint16_Except(0);
CF_AppData.hk.channel_hk[i].counters.recv.nak_segment_requests = Any_uint32_Except(0);
}
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
CF_AppData.hk.channel_hk[i].counters.sent.file_data_bytes = Any_uint64_Except(0);
CF_AppData.hk.channel_hk[i].counters.sent.nak_segment_requests = Any_uint32_Except(0);
CF_AppData.hk.channel_hk[i].counters.sent.pdu = Any_uint32_Except(0);
}
/* Act */
CF_CmdReset(arg_msg);
/* Assert */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_RESET);
UtAssert_ZERO(CF_AppData.hk.counters.cmd);
UtAssert_ZERO(CF_AppData.hk.counters.err);
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.fault, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.fault),
"fault channel %d was completely cleared to 0", i);
}
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.recv, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.recv),
"recv channel %d was completely cleared to 0", i);
}
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
UtAssert_MemCmpValue(&CF_AppData.hk.channel_hk[i].counters.sent, 0,
sizeof(&CF_AppData.hk.channel_hk[i].counters.sent),
"sent channel %d was completely cleared to 0", i);
}
}
/*******************************************************************************
**
** CF_CmdTxFile tests
**
*******************************************************************************/
void Test_CF_CmdTxFile(void)
{
/* Test case for:
* void CF_CmdTxFile(CFE_SB_Buffer_t *msg);
*/
CF_UT_cmd_tx_file_buf_t utbuf;
CF_TxFileCmd_t * msg = &utbuf.tf;
memset(&CF_AppData.hk.counters, 0, sizeof(CF_AppData.hk.counters));
/* nominal, all zero should pass checks, just calls CF_CFDP_TxFile */
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_1;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_TX_FILE);
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_2;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 2);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_TX_FILE);
/* out of range arguments: bad class */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = 10;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = -10;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);
/* out of range arguments: bad channel */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->chan_num = CF_NUM_CHANNELS;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);
/* out of range arguments: bad keep */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->keep = 15;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);
/* CF_CFDP_TxFile fails*/
UT_CF_ResetEventCapture();
UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_TxFile), -1);
memset(msg, 0, sizeof(*msg));
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_TX_FILE);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 5);
}
/*******************************************************************************
**
** CF_CmdPlaybackDir tests
**
*******************************************************************************/
void Test_CF_CmdPlaybackDir(void)
{
/* Test case for:
* void CF_CmdPlaybackDir(CFE_SB_Buffer_t *msg);
*/
CF_UT_cmd_playback_dir_buf_t utbuf;
CF_PlaybackDirCmd_t * msg = &utbuf.pd;
memset(&CF_AppData.hk.counters, 0, sizeof(CF_AppData.hk.counters));
/* nominal, all zero should pass checks, just calls CF_CFDP_PlaybackDir */
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_1;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1);
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_2;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 2);
/* out of range arguments: bad class */
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = 10;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = -10;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);
/* out of range arguments: bad channel */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->chan_num = CF_NUM_CHANNELS;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);
/* out of range arguments: bad keep */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->keep = 15;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);
/* CF_CFDP_PlaybackDir fails*/
UT_CF_ResetEventCapture();
UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_PlaybackDir), -1);
memset(msg, 0, sizeof(*msg));
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_PLAYBACK_DIR);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 5);
}
/*******************************************************************************
**
** CF_DoChanAction tests
**
*******************************************************************************/
void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenAny_fn_returns_1_Return_1(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
uint8 random_fn_call = Any_uint8_LessThan(CF_NUM_CHANNELS) + 1;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = CF_ALL_CHANNELS;
UT_SetDeferredRetcode(UT_KEY(Dummy_chan_action_fn_t), random_fn_call, 1);
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, CF_NUM_CHANNELS);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_True(local_result == 1, "CF_DoChanAction returned %d and should be 1 (an fn returned 1)", local_result);
}
void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenAll_fn_return_1_Return_1(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = CF_ALL_CHANNELS;
UT_SetDefaultReturnValue(UT_KEY(Dummy_chan_action_fn_t), 1);
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, CF_NUM_CHANNELS);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_True(local_result == 1, "CF_DoChanAction returned %d and should be 1 (an fn returned 1)", local_result);
}
void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenNo_fn_returns_0_Return_0(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = CF_ALL_CHANNELS;
UT_SetDefaultReturnValue(UT_KEY(Dummy_chan_action_fn_t), 0);
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, CF_NUM_CHANNELS);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_True(local_result == 0, "CF_DoChanAction returned %d and should be 0 (all fn returned 0)", local_result);
}
void Test_CF_DoChanAction_WhenChannel_fn_ActionReturns_1_Return_1(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = Any_cf_channel();
UT_SetDefaultReturnValue(UT_KEY(Dummy_chan_action_fn_t), 1);
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_True(local_result == 1, "CF_DoChanAction returned %d and should be 1 (fn returned 1)", local_result);
}
void Test_CF_DoChanAction_WhenChannel_fn_ActionReturns_0_Return_1(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = Any_cf_channel();
UT_SetDefaultReturnValue(UT_KEY(Dummy_chan_action_fn_t), 0);
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_True(local_result == 0, "CF_DoChanAction returned %d and should be 0 (fn returned 0)", local_result);
}
void Test_CF_DoChanAction_WhenChanNumberEq_CF_NUM_CHANNELS_Return_neg1_And_SendEvent_(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
arg_cmd->data.byte[0] = CF_NUM_CHANNELS;
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_CHAN_PARAM);
UtAssert_True(local_result == -1,
"CF_DoChanAction returned %d and should be -1 (cmd->data.byte[0] >= CF_NUM_CHANNELS)", local_result);
}
void Test_CF_DoChanAction_WhenBadChannelNumber_Return_neg1_And_SendEvent(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * arg_cmd = &utbuf.ua;
const char * arg_errstr = "CANNOT TEST SENT TO SEND EVENT";
CF_ChanActionFn_t arg_fn = &Dummy_chan_action_fn_t;
int dummy_context;
void * arg_context = &dummy_context;
int local_result;
memset(&utbuf, 0, sizeof(utbuf));
/* force CF_ALL_CHANNELS to not be a selection possibility */
arg_cmd->data.byte[0] = CF_ALL_CHANNELS;
int catastrophe_count = 0;
while (arg_cmd->data.byte[0] == CF_ALL_CHANNELS)
{
if (catastrophe_count == 10) /* 10 is arbitrary */
{
UtAssert_Message(UTASSERT_CASETYPE_ABORT, __FILE__, __LINE__,
"CANNOT make arg_cmd->data.byte[0] != CF_ALL_CHANNELS in 10 tries");
}
arg_cmd->data.byte[0] = Any_uint8_GreaterThan_or_EqualTo(CF_NUM_CHANNELS);
++catastrophe_count;
}
/* Act */
local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context);
UT_GetStubCount(UT_KEY(Dummy_chan_action_fn_t));
UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
/* Assert */
UtAssert_STUB_COUNT(Dummy_chan_action_fn_t, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_CHAN_PARAM);
UtAssert_True(local_result == -1,
"CF_DoChanAction returned %d and should be -1 (cmd->data.byte[0] >= CF_NUM_CHANNELS)", local_result);
}
/*******************************************************************************
**
** CF_DoFreezeThaw tests
**
*******************************************************************************/
void Test_CF_DoFreezeThaw_Set_frozen_ToGiven_context_barg_AndReturn_0(void)
{
/* Arrange */
uint8 arg_chan_num = Any_cf_channel();
CF_ChanAction_BoolArg_t dummy_context;
const CF_ChanAction_BoolArg_t *arg_context;
int local_result;
dummy_context.barg = Any_bool_arg_t_barg();
arg_context = &dummy_context;
/* set frozen to opposite to ensure change was done - not required for test,
* but it is helpful for verification that the function did the change */
CF_AppData.hk.channel_hk[arg_chan_num].frozen = !dummy_context.barg;
/* Act */
local_result = CF_DoFreezeThaw(arg_chan_num, arg_context);
/* Assert */
UtAssert_True(CF_AppData.hk.channel_hk[arg_chan_num].frozen == dummy_context.barg,
"CF_DoFreezeThaw set frozen to %d and should be %d (context->barg))",
CF_AppData.hk.channel_hk[arg_chan_num].frozen, dummy_context.barg);
UtAssert_True(local_result == 0, "CF_DoFreezeThaw returned %d and should be 0 (only returns 0)", local_result);
}
/**************************************************************************
**
** CF_CmdFreeze tests
**
*******************************************************************************/
void Test_CF_CmdFreeze_Set_frozen_To_1_AndAcceptCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
/* Arrange unstubbable: CF_DoFreezeThaw via CF_DoChanAction */
uint8 dummy_chan_num = Any_cf_channel();
memset(&utbuf, 0, sizeof(utbuf));
/* Arrange unstubbable: CF_DoChanAction */
dummy_msg->data.byte[0] = dummy_chan_num;
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdFreeze(arg_msg);
/* Assert */
/* Assert for CF_DoFreezeThaw */
UtAssert_True(CF_AppData.hk.channel_hk[dummy_chan_num].frozen == 1,
"CF_DoFreezeThaw set frozen to %d and should be 1 (freeze = 1))",
CF_AppData.hk.channel_hk[dummy_chan_num].frozen);
UtAssert_True(CF_AppData.hk.counters.cmd == (uint16)(initial_hk_cmd_counter + 1),
"CF_AppData.hk.counters.cmd is %d and should be 1 more than %d", CF_AppData.hk.counters.cmd,
initial_hk_cmd_counter);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_FREEZE);
}
void Test_CF_CmdFreeze_Set_frozen_To_1_AndRejectCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
/* Arrange unstubbable: CF_DoFreezeThaw via CF_DoChanAction */
memset(&utbuf, 0, sizeof(utbuf));
/* Arrange unstubbable: CF_DoChanAction */
dummy_msg->data.byte[0] = CF_NUM_CHANNELS + 1;
CF_AppData.hk.counters.cmd = 0;
/* Act */
CF_CmdFreeze(arg_msg);
/* Assert */
/* Assert for incremented counter */
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_FREEZE);
}
/*******************************************************************************
**
** CF_CmdThaw tests
**
*******************************************************************************/
void Test_CF_CmdThaw_Set_frozen_To_0_AndAcceptCommand(void)
{
/* Arrange */
CF_UT_cmd_unionargs_buf_t utbuf;
CF_UnionArgsCmd_t * dummy_msg = &utbuf.ua;
CFE_SB_Buffer_t * arg_msg = &utbuf.buf;
/* Arrange unstubbable: CF_DoFreezeThaw via CF_DoChanAction */
uint8 dummy_chan_num = Any_cf_channel();
memset(&utbuf, 0, sizeof(utbuf));
/* Arrange unstubbable: CF_DoChanAction */
dummy_msg->data.byte[0] = dummy_chan_num;
uint16 initial_hk_cmd_counter = Any_uint16();
CF_AppData.hk.counters.cmd = initial_hk_cmd_counter;
/* Act */
CF_CmdThaw(arg_msg);
/* Assert */
/* Assert for CF_DoFreezeThaw */
UtAssert_True(CF_AppData.hk.channel_hk[dummy_chan_num].frozen == 0,
"CF_DoFreezeThaw set frozen to %d and should be 0 (thaw = 0))",
CF_AppData.hk.channel_hk[dummy_chan_num].frozen);
UtAssert_True(CF_AppData.hk.counters.cmd == (uint16)(initial_hk_cmd_counter + 1),
"CF_AppData.hk.counters.cmd is %d and should be 1 more than %d", CF_AppData.hk.counters.cmd,
initial_hk_cmd_counter);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_THAW);
}