-
Notifications
You must be signed in to change notification settings - Fork 56
/
ut_psp_stubs.c
748 lines (661 loc) · 21.7 KB
/
ut_psp_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
/*
** 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:https://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_bsp_stubs.c
**
** Purpose:
** Unit test stubs for BSP routines
**
** Notes:
** Minimal work is done, only what is required for unit testing
**
*/
/*
** Includes
*/
#include "cfe_psp.h"
#include "utstubs.h"
#include <string.h>
#include <target_config.h>
Target_PspConfigData GLOBAL_PSP_CONFIGDATA = { 0 };
Target_CfeConfigData GLOBAL_CFE_CONFIGDATA = { 0 };
/**
* Instantiation of global system-wide configuration struct
* This contains build info plus pointers to the PSP and CFE
* configuration structures. Everything will be linked together
* in the final executable.
*/
Target_ConfigData GLOBAL_CONFIGDATA =
{
.MissionVersion = "MissionUnitTest",
.CfeVersion = "CfeUnitTest",
.OsalVersion = "OsalUnitTest",
.Config = "MissionConfig",
.Date = "MissionBuildDate",
.User = "MissionBuildUser",
.Default_CpuName = "UnitTestCpu",
.Default_CpuId = 1,
.Default_SpacecraftId = 0x42,
.CfeConfig = &GLOBAL_CFE_CONFIGDATA,
.PspConfig = &GLOBAL_PSP_CONFIGDATA
};
/*
** Functions
*/
/*****************************************************************************/
/**
** \brief CFE_PSP_Panic stub function
**
** \par Description
** This function is used to mimic the response of the OS API function
** CFE_PSP_Panic. The variable PSPPanicRtn.value is set equal to the
** input variable ErrorCode and the variable PSPPanicRtn.count is
** incremented each time this function is called. The unit tests
** compare these values to expected results to verify proper system
** response.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_Panic(int32 ErrorCode)
{
UT_DEFAULT_IMPL(CFE_PSP_Panic);
UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Panic), (uint8*)&ErrorCode, sizeof(ErrorCode));
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetProcessorId stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetProcessorId. It is set to return a fixed value for the
** unit tests.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns 0.
**
******************************************************************************/
uint32 CFE_PSP_GetProcessorId(void)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_GetProcessorId);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetSpacecraftId stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetSpacecraftId. It is set to return a fixed value for the
** unit tests.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns 0.
**
******************************************************************************/
uint32 CFE_PSP_GetSpacecraftId(void)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_GetSpacecraftId);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetProcessorName stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetProcessorName. It is set to return a fixed value for the
** unit tests.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns Default_CpuName or passed in address from buffer
**
******************************************************************************/
const char *CFE_PSP_GetProcessorName(void)
{
int32 status;
const char *ptr = GLOBAL_CONFIGDATA.Default_CpuName;
status = UT_DEFAULT_IMPL(CFE_PSP_GetProcessorName);
if (status >= 0)
{
UT_Stub_CopyToLocal(UT_KEY(CFE_PSP_GetProcessorName), &ptr, sizeof(ptr));
}
return ptr;
}
/*****************************************************************************/
/**
v** \brief CFE_PSP_GetTime stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetTime. The LocalTime structure is set to the user-defined
** values in BSP_Time.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_GetTime(OS_time_t *LocalTime)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_GetTime);
if (status >= 0)
{
if (UT_Stub_CopyToLocal(UT_KEY(CFE_PSP_GetTime), (uint8*)LocalTime, sizeof(*LocalTime)) < sizeof(*LocalTime))
{
LocalTime->seconds = 100;
LocalTime->microsecs = 200;
}
}
}
/*****************************************************************************/
/**
** \brief CFE_PSP_WriteToCDS stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_WriteToCDS. The user can adjust the response by setting
** the values in the BSPWriteCDSRtn structure prior to this function
** being called. If the value BSPWriteCDSRtn.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 BSPWriteCDSRtn.value.
** Otherwise, the value of the user-defined variable UT_BSP_Fail
** determines the status returned by the function.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either OS_SUCCESS, OS_ERROR, or a user-defined value.
**
******************************************************************************/
int32 CFE_PSP_WriteToCDS(const void *PtrToDataToWrite,
uint32 CDSOffset,
uint32 NumBytes)
{
uint8 *BufPtr;
size_t CdsSize;
size_t Position;
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_WriteToCDS);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_WriteToCDS), (void**)&BufPtr, &CdsSize, &Position);
if (BufPtr != NULL && (CDSOffset + NumBytes) <= CdsSize)
{
memcpy(BufPtr + CDSOffset, PtrToDataToWrite, NumBytes);
}
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_ReadFromCDS stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_ReadFromCDS. The user can adjust the response by setting
** the values in the BSPReadCDSRtn structure prior to this function
** being called. If the value BSPReadCDSRtn.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 BSPReadCDSRtn.value.
** Otherwise, the value of the user-defined variable UT_BSP_Fail
** determines the status returned by the function.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either OS_SUCCESS, OS_ERROR, or a user-defined value.
**
******************************************************************************/
int32 CFE_PSP_ReadFromCDS(void *PtrToDataToRead,
uint32 CDSOffset,
uint32 NumBytes)
{
uint8 *BufPtr;
size_t CdsSize;
size_t Position;
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_ReadFromCDS);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_ReadFromCDS), (void**)&BufPtr, &CdsSize, &Position);
if (BufPtr != NULL && (CDSOffset + NumBytes) <= CdsSize)
{
memcpy(PtrToDataToRead, BufPtr + CDSOffset, NumBytes);
}
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetCDSSize stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_GetCDSSize. The user can adjust the response by
** setting the value of UT_BSP_Fail prior to this function being called.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either OS_SUCCESS or OS_ERROR.
**
******************************************************************************/
int32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS)
{
int32 status;
size_t TempSize;
status = UT_DEFAULT_IMPL(CFE_PSP_GetCDSSize);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetCDSSize), NULL, &TempSize, NULL);
*SizeOfCDS = TempSize;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetVolatileDiskMem stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_GetVolatileDiskMem. The user can adjust the response by
** setting the value of UT_BSP_Fail prior to this function being called.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either OS_SUCCESS or OS_ERROR.
**
******************************************************************************/
int32 CFE_PSP_GetVolatileDiskMem(cpuaddr *PtrToVolDisk, uint32 *SizeOfVolDisk)
{
int32 status;
size_t TempSize;
void *TempAddr;
status = UT_DEFAULT_IMPL(CFE_PSP_GetVolatileDiskMem);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVolatileDiskMem), &TempAddr, &TempSize, NULL);
*PtrToVolDisk = (cpuaddr)TempAddr;
*SizeOfVolDisk = TempSize;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_Restart stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_Restart. The variable PSPRestartRtn.value is set to the
** value passed to the function, reset_type, and the variable
** PSPRestartRtn.count is incremented each time this function is called.
** The unit tests compare these values to expected results to verify
** proper system response.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_Restart(uint32 reset_type)
{
UT_DEFAULT_IMPL(CFE_PSP_Restart);
UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8*)&reset_type, sizeof(reset_type));
}
/*****************************************************************************/
/**
** \brief CFE_PSP_Get_Timebase stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_Get_Timebase.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32* Tbl)
{
*Tbu = 0;
*Tbl = 0;
UT_Stub_RegisterContext(UT_KEY(CFE_PSP_Get_Timebase), Tbu);
UT_Stub_RegisterContext(UT_KEY(CFE_PSP_Get_Timebase), Tbl);
UT_DEFAULT_IMPL(CFE_PSP_Get_Timebase);
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetResetArea stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetResetArea. It returns the user-defined value,
** UT_StatusBSP.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns a user-defined status value, UT_StatusBSP.
**
******************************************************************************/
int32 CFE_PSP_GetResetArea(cpuaddr *PtrToResetArea, uint32 *SizeOfResetArea)
{
int32 status;
size_t TempSize;
void *TempAddr;
status = UT_DEFAULT_IMPL(CFE_PSP_GetResetArea);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetResetArea), &TempAddr, &TempSize, NULL);
*PtrToResetArea = (cpuaddr)TempAddr;
*SizeOfResetArea = TempSize;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_AttachExceptions stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_AttachExceptions.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_AttachExceptions(void)
{
UT_DEFAULT_IMPL(CFE_PSP_AttachExceptions);
}
/*****************************************************************************/
/**
** \brief CFE_PSP_SetDefaultExceptionEnvironment stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_SetDefaultExceptionEnvironment.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
******************************************************************************/
void CFE_PSP_SetDefaultExceptionEnvironment(void)
{
UT_DEFAULT_IMPL(CFE_PSP_SetDefaultExceptionEnvironment);
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetTimerTicksPerSecond stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetTimerTicksPerSecond. It is set to return a fixed value
** for the unit tests.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns 2000.
**
******************************************************************************/
uint32 CFE_PSP_GetTimerTicksPerSecond(void)
{
int32 status;
status = UT_DEFAULT_IMPL_RC(CFE_PSP_GetTimerTicksPerSecond, 2000);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetTimerLow32Rollover stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_GetTimerLow32Rollover. It is set to return a fixed value
** for the unit tests.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns 1000000.
**
******************************************************************************/
uint32 CFE_PSP_GetTimerLow32Rollover(void)
{
int32 status;
status = UT_DEFAULT_IMPL_RC(CFE_PSP_GetTimerLow32Rollover, 100000);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_GetCFETextSegmentInfo stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_GetCFETextSegmentInfo. The user can adjust the response by
** setting the values in the BSPGetCFETextRtn structure prior to this
** function being called. If the value BSPGetCFETextRtn.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
** BSPGetCFETextRtn.value. OS_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_GetCFETextSegmentInfo(cpuaddr *PtrToCFESegment,
uint32 *SizeOfCFESegment)
{
static uint32 LocalTextSegment;
int32 status;
void *TempAddr;
size_t TempSize;
status = UT_DEFAULT_IMPL(CFE_PSP_GetCFETextSegmentInfo);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_PSP_GetCFETextSegmentInfo), &TempAddr, &TempSize, NULL);
if (*PtrToCFESegment == 0)
{
/* Backup -- Set the pointer and size to anything */
*PtrToCFESegment = (cpuaddr)&LocalTextSegment;
*SizeOfCFESegment = sizeof(LocalTextSegment);
}
else
{
*PtrToCFESegment = (cpuaddr)TempAddr;
*SizeOfCFESegment = TempSize;
}
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_MemRead8 stub function
**
** \par Description
** This function is used as a placeholder for the PSP function
** CFE_PSP_MemRead8. It sets the Data variable to a fixed value and
** always returns OS_SUCCESS.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_MemRead8(cpuaddr Address, uint8 *Data)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_MemRead8);
if (status >= 0)
{
*Data = 0x01;
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_MemValidateRange stub function
**
** \par Description
** This function is used to mimic the response of the PSP function
** CFE_PSP_MemValidateRange. The user can adjust the response by
** setting the values in the PSPMemValRangeRtn structure prior to this
** function being called. If the value PSPMemValRangeRtn.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
** PSPMemValRangeRtn.value. OS_SUCCESS is returned otherwise.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns either a user-defined status flag or OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_MemValidateRange);
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_MemCpy stub function
**
** \par Description
** This function is used to mimic the response of the OS API function
** CFE_PSP_MemCpy. It always returns OS_SUCCESS.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_MemCpy(void *dst, const void *src, uint32 size)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_MemCpy);
if (status >= 0)
{
/* this is not actually a stub; it actually has to _do_ the intended function */
memcpy(dst, src, size);
}
return status;
}
/*****************************************************************************/
/**
** \brief CFE_PSP_MemSet stub function
**
** \par Description
** This function is used to mimic the response of the OS API function
** CFE_PSP_MemSet. It always returns OS_SUCCESS.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** Returns OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_MemSet(void *dst, uint8 value , uint32 size)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_MemSet);
if (status >= 0)
{
/* this is not actually a stub; it actually has to _do_ the intended function */
memset(dst, (int)value, (size_t)size);
}
return status;
}
uint32 CFE_PSP_Exception_GetCount(void)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_Exception_GetCount);
return status;
}
int32 CFE_PSP_Exception_GetSummary(uint32 *ContextLogId, osal_id_t *TaskId, char *ReasonBuf, uint32 ReasonSize)
{
int32 status;
*ContextLogId = 0;
*TaskId = OS_OBJECT_ID_UNDEFINED;
*ReasonBuf = 0;
/* allow the testcase to easily set the taskID output, anything more involved needs a hook */
status = UT_DEFAULT_IMPL_ARGS(CFE_PSP_Exception_GetSummary, ContextLogId, TaskId, ReasonBuf, ReasonSize);
if (status == 0 && !OS_ObjectIdDefined(*TaskId))
{
UT_Stub_CopyToLocal(UT_KEY(CFE_PSP_Exception_GetSummary), TaskId, sizeof(*TaskId));
}
return status;
}
int32 CFE_PSP_Exception_CopyContext(uint32 ContextLogId, void *ContextBuf, uint32 ContextSize)
{
int32 status;
status = UT_DEFAULT_IMPL(CFE_PSP_Exception_CopyContext);
if (status == 0)
{
status = UT_Stub_CopyToLocal(UT_KEY(CFE_PSP_Exception_CopyContext), ContextBuf, ContextSize);
}
return status;
}