-
Notifications
You must be signed in to change notification settings - Fork 203
/
ut_sb_stubs.c
1126 lines (940 loc) · 32.7 KB
/
ut_sb_stubs.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
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-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.
*/
/*
** File: ut_sb_stubs.c
**
** Purpose:
** Unit test stubs for Software Bus routines
**
** Notes:
** Minimal work is done, only what is required for unit testing
**
*/
/*
** Includes
*/
#include <string.h>
#include "cfe.h"
#include "private/cfe_private.h"
#include "utstubs.h"
typedef struct
{
CFE_SB_MsgId_t MsgId;
uint32 UserLength;
uint32 TotalLength;
uint16 CommandCode;
CFE_TIME_SysTime_t TimeStamp;
} CFE_SB_StubMsg_MetaData_t;
/*
** Global variables
**
** NOTE: CFE_SB_Default_Qos is an oddball in that it is directly referenced by the code
** in other applications. Therefore the UT stub has to instantiate this in order to get
** any dependent code to link.
*/
CFE_SB_Qos_t CFE_SB_Default_Qos;
static CFE_SB_StubMsg_MetaData_t* CFE_SB_StubMsg_GetMetaData(const CFE_SB_Msg_t *MsgPtr)
{
CFE_SB_StubMsg_MetaData_t* MetaPtr;
CFE_SB_StubMsg_MetaData_t DefaultMeta;
uint32 MetaSize;
UT_EntryKey_t MsgKey = (UT_EntryKey_t)MsgPtr;
UT_GetDataBuffer(MsgKey, (void**)&MetaPtr, &MetaSize, NULL);
if (MetaPtr == NULL || MetaSize != sizeof(DefaultMeta))
{
memset(&DefaultMeta, 0, sizeof(DefaultMeta));
DefaultMeta.MsgId = CFE_SB_INVALID_MSG_ID;
UT_ResetState(MsgKey);
UT_SetDataBuffer(MsgKey, &DefaultMeta, sizeof(DefaultMeta), true);
/* Because "allocate copy" is true above, this gets a pointer to the copy */
UT_GetDataBuffer(MsgKey, (void**)&MetaPtr, &MetaSize, NULL);
}
return MetaPtr;
}
/*
** Functions
*/
/*****************************************************************************/
/**
** \brief CFE_SB_EarlyInit stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_EarlyInit. It always returns CFE_SUCCESS when called.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_EarlyInit(void)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_EarlyInit);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_TaskMain stub function
**
** \par Description
** This function is used as a placeholder for the cFE SB function
** CFE_SB_TaskMain.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_SB_TaskMain(void)
{
UT_DEFAULT_IMPL(CFE_SB_TaskMain);
}
/*****************************************************************************/
/**
** \brief CFE_SB_CreatePipe stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_CreatePipe. The user can adjust the response by setting
** the values in the SB_CreatePipeRtn structure prior to this function
** being called. If the value SB_CreatePipeRtn.count is greater than
** zero then the counter is decremented; if it then equals zero the
** return value is set to the user-defined value SB_CreatePipeRtn.value.
** CFE_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_CreatePipe(CFE_SB_PipeId_t *PipeIdPtr, uint16 Depth,
const char *PipeName)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_CreatePipe), PipeIdPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_CreatePipe), Depth);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_CreatePipe), PipeName);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_CreatePipe);
if (status >= 0)
{
UT_Stub_CopyToLocal(UT_KEY(CFE_SB_CreatePipe), (uint8*)PipeIdPtr, sizeof(*PipeIdPtr));
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_DeletePipe stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_DeletePipe.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_DeletePipe(CFE_SB_PipeId_t PipeId)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_DeletePipe), PipeId);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_DeletePipe);
if (status >= 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_DeletePipe), &PipeId, sizeof(PipeId));
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_GetPipeName stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_GetPipeName. The user must set the value of UT_pipename prior
** to this function being called. The function uses UT_pipename for the
** retrieved pipe name and returns CFE_SUCCESS.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_GetPipeName(char *PipeNameBuf, size_t PipeNameSize, CFE_SB_PipeId_t PipeId)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetPipeName), PipeNameBuf);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetPipeName), PipeNameSize);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetPipeName), PipeId);
uint32 UserBuffSize;
uint32 BuffPosition;
const char *NameBuff;
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_GetPipeName);
if (status >= 0 && PipeNameSize > 0)
{
UT_GetDataBuffer(UT_KEY(CFE_SB_GetPipeName), (void**)&NameBuff, &UserBuffSize, &BuffPosition);
if (NameBuff == NULL || UserBuffSize == 0)
{
NameBuff = "UT";
UserBuffSize = 2;
}
if (UserBuffSize < PipeNameSize)
{
BuffPosition = UserBuffSize;
}
else
{
BuffPosition = PipeNameSize - 1;
}
strncpy(PipeNameBuf, NameBuff, BuffPosition);
PipeNameBuf[BuffPosition] = 0;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_GetPipeIdByName stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_GetPipeIdByName. The user can adjust the response by setting
** the value of UT_pipename prior to this function being called, then
** choosing specific values for the pipe name (PipeName) used
** when calling this function. The Pipe ID returned is
** dependent on the pipe name provided. If pipe name
** doesn't match the expected values the function returns an error
** code. CFE_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either CFE_SB_BAD_ARGUMENT or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_GetPipeIdByName(CFE_SB_PipeId_t *PipeIdPtr, const char *PipeName)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetPipeIdByName), PipeIdPtr);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetPipeIdByName), PipeName);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_GetPipeIdByName);
if (status >= 0)
{
/* TODO: add GetPipeName */
if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetPipeIdByName), (uint8*)PipeIdPtr, sizeof(*PipeIdPtr)) == sizeof(*PipeIdPtr))
{
status = CFE_SUCCESS;
}
else
{
status = CFE_SB_BAD_ARGUMENT;
*PipeIdPtr = 0;
}
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_GetCmdCode stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_GetCmdCode.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either the function code from command secondary header or 0.
**
******************************************************************************/
uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetCmdCode), MsgPtr);
int32 status;
uint16 cmdcode = 0;
status = UT_DEFAULT_IMPL(CFE_SB_GetCmdCode);
if (status != 0)
{
cmdcode = status;
}
else
{
cmdcode = CFE_SB_StubMsg_GetMetaData(MsgPtr)->CommandCode;
}
return cmdcode;
}
/*****************************************************************************/
/**
** \brief CFE_SB_GetMsgId stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_GetMsgId.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns the entire stream ID from the primary header.
**
******************************************************************************/
CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetMsgId), MsgPtr);
CFE_SB_MsgId_t Result;
UT_DEFAULT_IMPL(CFE_SB_GetMsgId);
if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetMsgId), &Result, sizeof(Result)) < sizeof(Result))
{
Result = CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId;
}
return Result;
}
/*****************************************************************************/
/**
** \brief CFE_SB_InitMsg stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_InitMsg.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_SB_InitMsg(void *MsgPtr,
CFE_SB_MsgId_t MsgId,
uint16 Length,
bool Clear)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_InitMsg), MsgPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_InitMsg), MsgId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_InitMsg), Length);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_InitMsg), Clear);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_InitMsg);
if (status >= 0)
{
CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId = MsgId;
CFE_SB_StubMsg_GetMetaData(MsgPtr)->TotalLength = Length;
UT_Stub_CopyToLocal(UT_KEY(CFE_SB_InitMsg), (uint8*)MsgPtr, Length);
}
}
/*****************************************************************************/
/**
** \brief CFE_SB_RcvMsg stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_RcvMsg. By default it will return the TIMEOUT error response,
** unless the test setup sequence has indicated otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns CFE_SUCCESS on the first call, then -1 on the second.
**
******************************************************************************/
int32 CFE_SB_RcvMsg(CFE_SB_MsgPtr_t *BufPtr,
CFE_SB_PipeId_t PipeId,
int32 TimeOut)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_RcvMsg), BufPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_RcvMsg), PipeId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_RcvMsg), TimeOut);
int32 status;
static union
{
CFE_SB_Msg_t Msg;
uint8 Ext[CFE_MISSION_SB_MAX_SB_MSG_SIZE];
} Buffer;
status = UT_DEFAULT_IMPL(CFE_SB_RcvMsg);
if (status >= 0)
{
if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_RcvMsg), (uint8*)BufPtr, sizeof(*BufPtr)) < sizeof(*BufPtr))
{
memset(&Buffer, 0, sizeof(Buffer));
*BufPtr = &Buffer.Msg;
}
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_SendMsg stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SendMsg. The user can adjust the response by setting
** the values in the SBSendMsgRtn structure prior to this function
** being called. If the value SBSendMsgRtn.count is greater than
** zero then the counter is decremented; if it then equals zero the
** return value is set to the user-defined value SBSendMsgRtn.value.
** CFE_SUCCESS is returned otherwise. Only EVS and TIME messages are
** handled directly by this function; other messages are passed to the
** unit test function, UT_ProcessSBMsg, for any further action.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
/* Only doing subset of total messages;
** NOTE: Currently does EVS, TIME
*/
int32 CFE_SB_SendMsg(CFE_SB_Msg_t *MsgPtr)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_SendMsg), MsgPtr);
int32 status = CFE_SUCCESS;
/*
* Create a context entry so a hook function
* could do something useful with the message
*/
status = UT_DEFAULT_IMPL(CFE_SB_SendMsg);
if (status >= 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SendMsg), &MsgPtr, sizeof(MsgPtr));
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_SetCmdCode stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SetCmdCode.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either CFE_SB_WRONG_MSG_TYPE or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CmdCode)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetCmdCode), MsgPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetCmdCode), CmdCode);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SetCmdCode);
if (status == 0)
{
CFE_SB_StubMsg_GetMetaData(MsgPtr)->CommandCode = CmdCode;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_SetMsgId stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SetMsgId.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr, CFE_SB_MsgId_t MsgId)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetMsgId), MsgPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetMsgId), MsgId);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SetMsgId);
if (status == 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetMsgId), &MsgId, sizeof(MsgId));
CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId = MsgId;
}
}
/*****************************************************************************/
/**
** \brief CFE_SB_SetMsgTime stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SetMsgTime. It always returns CFE_SUCCESS.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t Time)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetMsgTime), MsgPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetMsgTime), Time);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SetMsgTime);
if (status == 0)
{
CFE_SB_StubMsg_GetMetaData(MsgPtr)->TimeStamp = Time;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_SubscribeEx stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SubscribeEx. The user can adjust the response by setting
** the values in the SB_SubscribeExRtn structure prior to this function
** being called. If the value SB_SubscribeExRtn.count is greater than
** zero then the counter is decremented; if it then equals zero the
** return value is set to the user-defined value
** SB_SubscribeExRtn.value. CFE_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_SubscribeEx(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId,
CFE_SB_Qos_t Quality, uint16 MsgLim)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeEx), MsgId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeEx), PipeId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeEx), Quality);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeEx), MsgLim);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SubscribeEx);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_Subscribe stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_Subscribe. The user can adjust the response by setting
** the values in the SB_SubscribeRtn structure prior to this function
** being called. If the value SB_SubscribeRtn.count is greater than
** zero then the counter is decremented; if it then equals zero the
** return value is set to the user-defined value SB_SubscribeRtn.value.
** CFE_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_Subscribe(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_Subscribe), MsgId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_Subscribe), PipeId);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_Subscribe);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_SubscribeLocal stub function
**
** \par Description
** This function is used to mimic the response of the cFE SB function
** CFE_SB_SubscribeLocal. The user can adjust the response by setting
** the values in the SB_SubscribeLocalRtn structure prior to this
** function being called. If the value SB_SubscribeLocalRtn.count is
** greater than zero then the counter is decremented; if it then equals
** zero the return value is set to the user-defined value
** SB_SubscribeLocalRtn.value. CFE_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or CFE_SUCCESS.
**
******************************************************************************/
int32 CFE_SB_SubscribeLocal(CFE_SB_MsgId_t MsgId,
CFE_SB_PipeId_t PipeId,
uint16 MsgLim)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeLocal), MsgId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeLocal), PipeId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SubscribeLocal), MsgLim);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SubscribeLocal);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_SB_TimeStampMsg stub function
**
** \par Description
** This function is used as a placeholder for the cFE SB function
** CFE_SB_TimeStampMsg.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_SB_TimeStampMsg(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_TimeStampMsg), MsgPtr);
UT_DEFAULT_IMPL(CFE_SB_TimeStampMsg);
UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_TimeStampMsg), &MsgPtr, sizeof(MsgPtr));
}
/*****************************************************************************/
/**
** \brief CFE_SB_GetTotalMsgLength stub function
**
** \par Description
** This function is used as a placeholder for the cFE SB function
** CFE_SB_GetTotalMsgLength. It returns the user-defined value,
** UT_SB_TotalMsgLen.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns a user-defined status value, UT_SB_TotalMsgLen.
**
******************************************************************************/
uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetTotalMsgLength), MsgPtr);
int32 status;
uint16 result;
status = UT_DEFAULT_IMPL_RC(CFE_SB_GetTotalMsgLength,-1);
if (status >= 0)
{
result = status;
}
else
{
result = CFE_SB_StubMsg_GetMetaData(MsgPtr)->TotalLength;
}
return result;
}
/*****************************************************************************/
/**
** \brief CFE_SB_CleanUpApp stub function
**
** \par Description
** This function is used as a placeholder for the cFE SB function
** CFE_SB_CleanUpApp.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
int32 CFE_SB_CleanUpApp(uint32 AppId)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_CleanUpApp);
return status;
}
/******************************************************************************
** Function: CFE_SB_MessageStringGet()
**
** See function prototype for full description
**
*/
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, uint32 DestMaxSize, uint32 SourceMaxSize)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_MessageStringGet), DestStringPtr);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_MessageStringGet), SourceStringPtr);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_MessageStringGet), DefaultString);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_MessageStringGet), DestMaxSize);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_MessageStringGet), SourceMaxSize);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_MessageStringGet);
if (status == 0)
{
if (DestMaxSize == 0)
{
status = CFE_SB_BAD_ARGUMENT;
}
else
{
/*
* Check if should use the default, which is if
* the source string has zero length (first char is NUL).
*/
if (DefaultString != NULL && (SourceMaxSize == 0 || *SourceStringPtr == 0))
{
SourceStringPtr = DefaultString;
SourceMaxSize = DestMaxSize;
}
/* For the UT implementation, just call strncpy() */
strncpy(DestStringPtr, SourceStringPtr, DestMaxSize - 1);
DestStringPtr[DestMaxSize - 1] = 0;
status = strlen(DestStringPtr);
}
}
return status;
}
/******************************************************************************
** Function: CFE_SB_MessageStringSet()
**
** See function prototype for full description
**
*/
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, uint32 DestMaxSize, uint32 SourceMaxSize)
{
UT_Stub_RegisterContext(UT_KEY(CFE_SB_MessageStringSet), DestStringPtr);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_MessageStringSet), SourceStringPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_MessageStringSet), DestMaxSize);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_MessageStringSet), SourceMaxSize);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_MessageStringSet);
if (status == 0)
{
if (DestMaxSize == 0)
{
status = CFE_SB_BAD_ARGUMENT;
}
else
{
/* For the UT implementation, just call strncpy() */
strncpy(DestStringPtr, SourceStringPtr, DestMaxSize);
if (DestStringPtr[DestMaxSize - 1] != 0)
{
status = DestMaxSize;
}
else
{
status = strlen(DestStringPtr);
}
}
}
return status;
}
int32 CFE_SB_Unsubscribe(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeId)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_Unsubscribe), MsgId);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_Unsubscribe), PipeId);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_Unsubscribe);
return status;
}
/******************************************************************************
** Function: CFE_SB_GetMsgTime()
**
** Purpose:
** Get the time field from a message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** Time field from message or
** Time value of zero for msgs that do not have a Time field in header
*/
CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetMsgTime), MsgPtr);
CFE_TIME_SysTime_t TimeFromMsg;
UT_DEFAULT_IMPL(CFE_SB_GetMsgTime);
if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetMsgTime), &TimeFromMsg, sizeof(CFE_TIME_SysTime_t)) != sizeof(CFE_TIME_SysTime_t))
{
TimeFromMsg = CFE_SB_StubMsg_GetMetaData(MsgPtr)->TimeStamp;
}
return TimeFromMsg;
}/* end CFE_SB_GetMsgTime */
bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_ValidateChecksum), MsgPtr);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_ValidateChecksum);
return (bool) status;
}
void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetUserData), MsgPtr);
uint8 *BytePtr;
void *Result;
uint16 HdrSize;
UT_DEFAULT_IMPL(CFE_SB_GetUserData);
if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetUserData), &Result, sizeof(Result)) != sizeof(Result))
{
BytePtr = (uint8 *)MsgPtr;
if ((MsgPtr->Byte[0] & 0x10) != 0)
{
HdrSize = CFE_SB_CMD_HDR_SIZE;
}
else
{
HdrSize = CFE_SB_TLM_HDR_SIZE;
}
Result = (BytePtr + HdrSize);
}
return Result;
}
void CFE_SB_SetTotalMsgLength (CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetTotalMsgLength), MsgPtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_SetTotalMsgLength), TotalLength);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_SetTotalMsgLength);
if (status == 0)
{
UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetTotalMsgLength), &TotalLength, sizeof(TotalLength));
CFE_SB_StubMsg_GetMetaData(MsgPtr)->TotalLength = TotalLength;
}
}
uint32 CFE_SB_GetPktType(CFE_SB_MsgId_t MsgId)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetPktType), MsgId);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_GetPktType);
return status;
}
void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GenerateChecksum), MsgPtr);
UT_DEFAULT_IMPL(CFE_SB_GenerateChecksum);
}
uint16 CFE_SB_GetChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetChecksum), MsgPtr);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_GetChecksum);
return status;
}
int32 CFE_SB_GetPipeOpts(CFE_SB_PipeId_t PipeId, uint8 *OptPtr)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_SB_GetPipeOpts), PipeId);
UT_Stub_RegisterContext(UT_KEY(CFE_SB_GetPipeOpts), OptPtr);
int32 status;
status = UT_DEFAULT_IMPL(CFE_SB_GetPipeOpts);
return status;