diff --git a/fsw/modules/eeprom_direct/cfe_psp_eeprom_direct.c b/fsw/modules/eeprom_direct/cfe_psp_eeprom_direct.c index 5a3740ec..22a925d8 100644 --- a/fsw/modules/eeprom_direct/cfe_psp_eeprom_direct.c +++ b/fsw/modules/eeprom_direct/cfe_psp_eeprom_direct.c @@ -82,7 +82,7 @@ int32 CFE_PSP_EepromWrite16(cpuaddr MemoryAddress, uint16 uint16Value) { uint32 write32; uint32 temp32; - uint32 aligned_address; + cpuaddr aligned_address; /* ** check 16 bit alignment , check the 1st lsb @@ -160,7 +160,7 @@ int32 CFE_PSP_EepromWrite16(cpuaddr MemoryAddress, uint16 uint16Value) *-----------------------------------------------------------------*/ int32 CFE_PSP_EepromWrite8(cpuaddr MemoryAddress, uint8 ByteValue) { - uint32 aligned_address; + cpuaddr aligned_address; uint16 write16, temp16; temp16 = ByteValue; diff --git a/unit-test-coverage/ut-stubs/CMakeLists.txt b/unit-test-coverage/ut-stubs/CMakeLists.txt index e0ca0431..54d7e12a 100644 --- a/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -36,23 +36,10 @@ # the OCS functions that are actually used. # add_library(ut_psp_libc_stubs STATIC EXCLUDE_FROM_ALL - src/libc-stdio-stubs.c - src/libc-stdlib-stubs.c - src/libc-string-stubs.c - src/vxworks-ataDrv-stubs.c - src/vxworks-cacheLib-stubs.c - src/vxworks-moduleLib-stubs.c - src/vxworks-taskLib-stubs.c - src/vxworks-excLib-stubs.c - src/vxworks-fppLib-stubs.c - src/vxworks-mcpx750-stubs.c - src/vxworks-rebootLib-stubs.c - src/vxworks-sysLib-stubs.c - src/vxworks-vxLib-stubs.c - src/vxworks-spyLib-stubs.c - src/vxworks-spyLibP-stubs.c - src/rtems-bsdnet-stubs.c + src/cfe-configdata-stubs.c + src/PCS_arch_ppc_vxPpcLib_handlers.c src/PCS_arch_ppc_vxPpcLib_stubs.c + src/PCS_bsdnet_handlers.c src/PCS_bsdnet_stubs.c src/PCS_cacheLib_stubs.c src/PCS_cfe_configdata_stubs.c @@ -61,20 +48,28 @@ add_library(ut_psp_libc_stubs STATIC EXCLUDE_FROM_ALL src/PCS_errnoLib_stubs.c src/PCS_excLib_stubs.c src/PCS_fppLib_stubs.c + src/PCS_moduleLib_handlers.c src/PCS_moduleLib_stubs.c src/PCS_ramDrv_stubs.c src/PCS_rebootLib_stubs.c src/PCS_spyLibP_stubs.c src/PCS_spyLib_stubs.c + src/PCS_stdio_handlers.c src/PCS_stdio_stubs.c + src/PCS_stdlib_handlers.c src/PCS_stdlib_stubs.c + src/PCS_string_handlers.c src/PCS_string_stubs.c + src/PCS_sysLib_handlers.c src/PCS_sysLib_stubs.c src/PCS_sys_mman_stubs.c src/PCS_sys_stat_stubs.c + src/PCS_taskLib_handlers.c src/PCS_taskLib_stubs.c src/PCS_unistd_stubs.c - src/PCS_xbdBlkDev_stubs.c) + src/PCS_xbdBlkDev_stubs.c + src/vxworks-mcpx750-stubs.c +) target_include_directories(ut_libc_stubs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc diff --git a/unit-test-coverage/ut-stubs/src/vxworks-ataDrv-stubs.c b/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_handlers.c similarity index 66% rename from unit-test-coverage/ut-stubs/src/vxworks-ataDrv-stubs.c rename to unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_handlers.c index 4ee30038..2cee627b 100644 --- a/unit-test-coverage/ut-stubs/src/vxworks-ataDrv-stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_handlers.c @@ -16,14 +16,23 @@ * limitations under the License. ************************************************************************/ -/* PSP coverage stub replacement for ataDrv.h */ +/* PSP coverage stub replacement for vxLib.h */ #include #include #include "utstubs.h" -#include "PCS_drv_hdisk_ataDrv.h" +#include "PCS_vxLib.h" +#include "PCS_arch_ppc_vxPpcLib.h" -PCS_device_t PCS_ataXbdDevCreate(int ctrl, int drive, unsigned int nBlks, unsigned int offset, const char *name) +void UT_DefaultHandler_PCS_vxTimeBaseGet(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - return UT_DEFAULT_IMPL(PCS_ataXbdDevCreate); + /* void PCS_vxTimeBaseGet(uint32_t *u, uint32_t *l) */ + uint32_t *u = UT_Hook_GetArgValueByName(Context, "u", uint32 *); + uint32_t *l = UT_Hook_GetArgValueByName(Context, "l", uint32 *); + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + *u = 0; + *l = 0; + } } diff --git a/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c index 50636374..ba3a3769 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c @@ -25,6 +25,8 @@ #include "PCS_arch_ppc_vxPpcLib.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_vxTimeBaseGet(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_vxDecGet() @@ -101,5 +103,5 @@ void PCS_vxTimeBaseGet(uint32_t *u, uint32_t *l) UT_GenStub_AddParam(PCS_vxTimeBaseGet, uint32_t *, u); UT_GenStub_AddParam(PCS_vxTimeBaseGet, uint32_t *, l); - UT_GenStub_Execute(PCS_vxTimeBaseGet, Basic, NULL); + UT_GenStub_Execute(PCS_vxTimeBaseGet, Basic, UT_DefaultHandler_PCS_vxTimeBaseGet); } diff --git a/unit-test-coverage/ut-stubs/src/rtems-bsdnet-stubs.c b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_handlers.c similarity index 69% rename from unit-test-coverage/ut-stubs/src/rtems-bsdnet-stubs.c rename to unit-test-coverage/ut-stubs/src/PCS_bsdnet_handlers.c index 57499c4f..98ca6fff 100644 --- a/unit-test-coverage/ut-stubs/src/rtems-bsdnet-stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_handlers.c @@ -23,31 +23,17 @@ #include "PCS_bsdnet.h" #include "PCS_rtems.h" -void PCS_rtems_bsdnet_do_dhcp_failsafe(void) -{ - UT_DEFAULT_IMPL(PCS_rtems_bsdnet_do_dhcp_failsafe); -} - -const char *PCS_rtems_status_text(PCS_rtems_status_code code) +void UT_DefaultHandler_PCS_rtems_status_text(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { + /* const char *PCS_rtems_status_text(PCS_rtems_status_code code) */ const char *ReturnCode = NULL; int32 Status; - Status = UT_DEFAULT_IMPL(PCS_rtems_status_text); - if (Status == 0) + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status >= 0 && + UT_Stub_CopyToLocal(UT_KEY(PCS_rtems_status_text), &ReturnCode, sizeof(ReturnCode)) == sizeof(ReturnCode)) { - UT_Stub_CopyToLocal(UT_KEY(PCS_rtems_status_text), &ReturnCode, sizeof(ReturnCode)); + UT_Stub_SetReturnValue(FuncKey, ReturnCode); } - - return ReturnCode; } - -int PCS_rtems_bsdnet_initialize_network(void) -{ - return UT_DEFAULT_IMPL(PCS_rtems_bsdnet_initialize_network); -} - -int PCS_rtems_fxp_attach(struct PCS_rtems_bsdnet_ifconfig *config, int attaching) -{ - return UT_DEFAULT_IMPL(PCS_rtems_fxp_attach); -} \ No newline at end of file diff --git a/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c index c152a5c0..81f259d0 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c @@ -25,6 +25,8 @@ #include "PCS_bsdnet.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_rtems_status_text(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_rtems_bsdnet_do_dhcp_failsafe() @@ -78,7 +80,7 @@ const char *PCS_rtems_status_text(PCS_rtems_status_code sc) UT_GenStub_AddParam(PCS_rtems_status_text, PCS_rtems_status_code, sc); - UT_GenStub_Execute(PCS_rtems_status_text, Basic, NULL); + UT_GenStub_Execute(PCS_rtems_status_text, Basic, UT_DefaultHandler_PCS_rtems_status_text); return UT_GenStub_GetReturnValue(PCS_rtems_status_text, const char *); } diff --git a/unit-test-coverage/ut-stubs/src/vxworks-moduleLib-stubs.c b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_handlers.c similarity index 64% rename from unit-test-coverage/ut-stubs/src/vxworks-moduleLib-stubs.c rename to unit-test-coverage/ut-stubs/src/PCS_moduleLib_handlers.c index a3cfccf3..e4de1451 100644 --- a/unit-test-coverage/ut-stubs/src/vxworks-moduleLib-stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_handlers.c @@ -23,32 +23,34 @@ #include "PCS_moduleLib.h" -PCS_MODULE_ID PCS_moduleFindByName(const char *moduleName) +void UT_DefaultHandler_PCS_moduleFindByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { + /* PCS_MODULE_ID PCS_moduleFindByName(const char *moduleName) */ PCS_MODULE_ID retval; int32 Status; retval = NULL; - Status = UT_DEFAULT_IMPL(PCS_moduleFindByName); - if (Status == 0) + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status >= 0 && UT_Stub_CopyToLocal(FuncKey, &retval, sizeof(retval)) == sizeof(retval)) { - UT_Stub_CopyToLocal(UT_KEY(PCS_moduleFindByName), &retval, sizeof(retval)); + UT_Stub_SetReturnValue(FuncKey, retval); } - - return retval; } -PCS_STATUS PCS_moduleInfoGet(PCS_MODULE_ID moduleId, PCS_MODULE_INFO *pModuleInfo) +void UT_DefaultHandler_PCS_moduleInfoGet(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { + /* PCS_STATUS PCS_moduleInfoGet(PCS_MODULE_ID moduleId, PCS_MODULE_INFO *pModuleInfo) */ + PCS_MODULE_INFO *pModuleInfo = UT_Hook_GetArgValueByName(Context, "pModuleInfo", PCS_MODULE_INFO *); + int32 Status; - Status = UT_DEFAULT_IMPL(PCS_moduleInfoGet); + UT_Stub_GetInt32StatusCode(Context, &Status); - if (Status == 0 && + if (Status >= 0 && UT_Stub_CopyToLocal(UT_KEY(PCS_moduleInfoGet), pModuleInfo, sizeof(*pModuleInfo)) < sizeof(*pModuleInfo)) { memset(pModuleInfo, 0, sizeof(*pModuleInfo)); } - - return Status; } diff --git a/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c index f4980ebd..0df0bbb9 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c @@ -25,6 +25,9 @@ #include "PCS_moduleLib.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_moduleFindByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_moduleInfoGet(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_moduleFindByName() @@ -36,7 +39,7 @@ PCS_MODULE_ID PCS_moduleFindByName(const char *moduleName) UT_GenStub_AddParam(PCS_moduleFindByName, const char *, moduleName); - UT_GenStub_Execute(PCS_moduleFindByName, Basic, NULL); + UT_GenStub_Execute(PCS_moduleFindByName, Basic, UT_DefaultHandler_PCS_moduleFindByName); return UT_GenStub_GetReturnValue(PCS_moduleFindByName, PCS_MODULE_ID); } @@ -53,7 +56,7 @@ PCS_STATUS PCS_moduleInfoGet(PCS_MODULE_ID moduleId, PCS_MODULE_INFO *pModuleInf UT_GenStub_AddParam(PCS_moduleInfoGet, PCS_MODULE_ID, moduleId); UT_GenStub_AddParam(PCS_moduleInfoGet, PCS_MODULE_INFO *, pModuleInfo); - UT_GenStub_Execute(PCS_moduleInfoGet, Basic, NULL); + UT_GenStub_Execute(PCS_moduleInfoGet, Basic, UT_DefaultHandler_PCS_moduleInfoGet); return UT_GenStub_GetReturnValue(PCS_moduleInfoGet, PCS_STATUS); } diff --git a/unit-test-coverage/ut-stubs/src/PCS_stdio_handlers.c b/unit-test-coverage/ut-stubs/src/PCS_stdio_handlers.c new file mode 100644 index 00000000..7826f6dd --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_stdio_handlers.c @@ -0,0 +1,142 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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. + ************************************************************************/ + +/* PSP coverage stub replacement for stdio.h */ +#include +#include +#include +#include "utstubs.h" + +#include "PCS_stdio.h" + +struct PCS_FILE +{ + int f; +}; + +#define PCS_STDIO_MAX_SIZE 0x01000000 + +void UT_DefaultHandler_PCS_fgets(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_fgets(char *s, int n, PCS_FILE *stream) */ + char *s = UT_Hook_GetArgValueByName(Context, "s", char *); + int n = UT_Hook_GetArgValueByName(Context, "n", int); + + int32 Status; + uint32 CopySize; + void * DataBufferPtr; + + Status = 0; + UT_GetDataBuffer(FuncKey, &DataBufferPtr, NULL, NULL); + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (DataBufferPtr != NULL) + { + if (Status > n) + { + CopySize = n; + } + else + { + CopySize = Status; + } + + CopySize = UT_Stub_CopyToLocal(UT_KEY(PCS_fgets), s, CopySize); + } + else + { + CopySize = 0; + } + + if (n < Status) + { + Status = n; + } + + if (UT_GetStubCount(UT_KEY(PCS_fgets) < 4) && Status > 0 && CopySize < Status) + { + memset(&s[CopySize], 'x', Status - CopySize); + CopySize = Status; + } + + if (CopySize <= 0) + { + s = NULL; + } + else + { + s[CopySize - 1] = 0; + } + + UT_Stub_SetReturnValue(FuncKey, s); +} + +void UT_DefaultHandler_PCS_fopen(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* PCS_FILE *PCS_fopen(const char *filename, const char *modes) */ + PCS_FILE * retval; + static PCS_FILE FOPEN_FP = {0}; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = &FOPEN_FP; + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_snprintf(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, + va_list ArgList) +{ + /* int PCS_snprintf(char *s, size_t maxlen, const char *format, ...) */ + char * s = UT_Hook_GetArgValueByName(Context, "s", char *); + size_t maxlen = UT_Hook_GetArgValueByName(Context, "maxlen", size_t); + const char *format = UT_Hook_GetArgValueByName(Context, "format", const char *); + + int retval; + + /* need to actually _do_ the snprintf */ + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = vsnprintf(s, maxlen, format, ArgList); + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_vsnprintf(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int PCS_vsnprintf(char *s, size_t maxlen, const char *format, PCS_va_list arg) */ + char * s = UT_Hook_GetArgValueByName(Context, "s", char *); + size_t maxlen = UT_Hook_GetArgValueByName(Context, "maxlen", size_t); + const char *format = UT_Hook_GetArgValueByName(Context, "format", const char *); + + int retval = 0; + + /* need to actually _do_ something here - + * cannot do the real vsnprintf because we lost the args. */ + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = snprintf(s, maxlen, "%s", format); + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +static PCS_FILE LOCAL_FP[3] = {{10}, {11}, {12}}; + +PCS_FILE *PCS_stdin = &LOCAL_FP[0]; +PCS_FILE *PCS_stdout = &LOCAL_FP[1]; +PCS_FILE *PCS_stderr = &LOCAL_FP[2]; diff --git a/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c index 18366c19..0d5e8af1 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c @@ -27,6 +27,11 @@ #include "PCS_stdio.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_fgets(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_fopen(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_snprintf(void *, UT_EntryKey_t, const UT_StubContext_t *, va_list); +void UT_DefaultHandler_PCS_vsnprintf(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_fclose() @@ -56,7 +61,7 @@ char *PCS_fgets(char *s, int n, PCS_FILE *stream) UT_GenStub_AddParam(PCS_fgets, int, n); UT_GenStub_AddParam(PCS_fgets, PCS_FILE *, stream); - UT_GenStub_Execute(PCS_fgets, Basic, NULL); + UT_GenStub_Execute(PCS_fgets, Basic, UT_DefaultHandler_PCS_fgets); return UT_GenStub_GetReturnValue(PCS_fgets, char *); } @@ -73,7 +78,7 @@ PCS_FILE *PCS_fopen(const char *filename, const char *modes) UT_GenStub_AddParam(PCS_fopen, const char *, filename); UT_GenStub_AddParam(PCS_fopen, const char *, modes); - UT_GenStub_Execute(PCS_fopen, Basic, NULL); + UT_GenStub_Execute(PCS_fopen, Basic, UT_DefaultHandler_PCS_fopen); return UT_GenStub_GetReturnValue(PCS_fopen, PCS_FILE *); } @@ -192,7 +197,7 @@ int PCS_snprintf(char *s, size_t maxlen, const char *format, ...) UT_GenStub_AddParam(PCS_snprintf, const char *, format); va_start(UtStub_ArgList, format); - UT_GenStub_Execute(PCS_snprintf, Va, NULL, UtStub_ArgList); + UT_GenStub_Execute(PCS_snprintf, Va, UT_DefaultHandler_PCS_snprintf, UtStub_ArgList); va_end(UtStub_ArgList); return UT_GenStub_GetReturnValue(PCS_snprintf, int); @@ -212,7 +217,7 @@ int PCS_vsnprintf(char *s, size_t maxlen, const char *format, PCS_va_list arg) UT_GenStub_AddParam(PCS_vsnprintf, const char *, format); UT_GenStub_AddParam(PCS_vsnprintf, PCS_va_list, arg); - UT_GenStub_Execute(PCS_vsnprintf, Basic, NULL); + UT_GenStub_Execute(PCS_vsnprintf, Basic, UT_DefaultHandler_PCS_vsnprintf); return UT_GenStub_GetReturnValue(PCS_vsnprintf, int); } diff --git a/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c b/unit-test-coverage/ut-stubs/src/PCS_stdlib_handlers.c similarity index 64% rename from unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c rename to unit-test-coverage/ut-stubs/src/PCS_stdlib_handlers.c index 1dc56700..381b0b4b 100644 --- a/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_stdlib_handlers.c @@ -44,51 +44,28 @@ struct MPOOL_REC uint32 Size; }; -void PCS_exit(int c) +void UT_DefaultHandler_PCS_strtoul(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_DEFAULT_IMPL(PCS_exit); + /* unsigned long int PCS_strtoul(const char *nptr, char **endptr, int base) */ + const char *nptr = UT_Hook_GetArgValueByName(Context, "nptr", const char *); + char ** endptr = UT_Hook_GetArgValueByName(Context, "endptr", char **); + int base = UT_Hook_GetArgValueByName(Context, "base", int); - /* - * This call is never supposed to return, but this stub will. - * The application therefore must handle a return from exit() - * - * TBD: IT would be nice if this could use a setjmp-like - * method to avoid returning here. - */ -} + unsigned long Result; -void PCS_abort(void) -{ - UT_DEFAULT_IMPL(PCS_abort); -} - -unsigned long int PCS_strtoul(const char *nptr, char **endptr, int base) -{ - int32 Status; - unsigned long Result = 0; - - Status = UT_DEFAULT_IMPL_RC(PCS_strtoul, -1); - - if (Status < 0) + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) { /* do the real op */ Result = strtoul(nptr, endptr, base); + UT_Stub_SetReturnValue(FuncKey, Result); } - else - { - Result = Status; - } - - return Result; } -int PCS_system(const char *command) +void UT_DefaultHandler_PCS_malloc(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - return UT_DEFAULT_IMPL(PCS_system); -} + /* void *PCS_malloc(size_t sz) */ + size_t sz = UT_Hook_GetArgValueByName(Context, "sz", size_t); -void *PCS_malloc(size_t sz) -{ int32 Status; void * PoolPtr; cpuaddr PoolStart; @@ -97,10 +74,12 @@ void *PCS_malloc(size_t sz) size_t NextSize; size_t PoolSize; uint32 CallCnt; + void * BlockPtr; struct MPOOL_REC *Rec; - Rec = NULL; - CallCnt = UT_GetStubCount(UT_KEY(PCS_malloc)); + Rec = NULL; + BlockPtr = NULL; + CallCnt = UT_GetStubCount(UT_KEY(PCS_malloc)); UT_GetDataBuffer(UT_KEY(PCS_malloc), &PoolPtr, &PoolSize, NULL); if (PoolPtr != NULL) @@ -128,41 +107,45 @@ void *PCS_malloc(size_t sz) } } - Status = UT_DEFAULT_IMPL(PCS_malloc); - - if (Status != 0 || Rec == NULL) - { - return NULL; - } + UT_Stub_GetInt32StatusCode(Context, &Status); - NextSize = Rec->Size + sz + MPOOL_ALIGN; - if (NextSize > PoolSize) + if (Status == 0 && Rec != NULL) { - /* - * This indicates that the application is trying to allocate - * a block larger than the pool. It typically means that the - * emulated heap size is too small, so it is prudent to generate - * a message. - */ - UtAssert_Failed("PCS_malloc() heap has been exhausted"); - return NULL; - } + NextSize = Rec->Size + sz + MPOOL_ALIGN; + if (NextSize > PoolSize) + { + /* + * This indicates that the application is trying to allocate + * a block larger than the pool. It typically means that the + * emulated heap size is too small, so it is prudent to generate + * a message. + */ + UtAssert_Failed("PCS_malloc() heap has been exhausted"); + } + else + { + NextSize = (NextSize + MPOOL_ALIGN - 1) & ~((size_t)MPOOL_ALIGN - 1); + NextBlock = Rec->BlockAddr + MPOOL_ALIGN; + Rec->BlockAddr += NextSize; + Rec->Size += NextSize; - NextSize = (NextSize + MPOOL_ALIGN - 1) & ~((size_t)MPOOL_ALIGN - 1); - NextBlock = Rec->BlockAddr + MPOOL_ALIGN; - Rec->BlockAddr += NextSize; - Rec->Size += NextSize; + Rec = (struct MPOOL_REC *)(NextBlock - sizeof(struct MPOOL_REC)); + Rec->BlockAddr = NextBlock; + Rec->Magic = MPOOL_BLOCK_SIGNATURE; + Rec->Size = sz; - Rec = (struct MPOOL_REC *)(NextBlock - sizeof(struct MPOOL_REC)); - Rec->BlockAddr = NextBlock; - Rec->Magic = MPOOL_BLOCK_SIGNATURE; - Rec->Size = sz; + BlockPtr = (void *)NextBlock; + } - return (void *)NextBlock; + UT_Stub_SetReturnValue(FuncKey, BlockPtr); + } } -void PCS_free(void *ptr) +void UT_DefaultHandler_PCS_free(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { + /* void PCS_free(void *ptr) */ + void *ptr = UT_Hook_GetArgValueByName(Context, "ptr", void *); + int32 Status; cpuaddr BlockAddr; void * PoolPtr; @@ -173,9 +156,11 @@ void PCS_free(void *ptr) * If there is a data buffer associated with free() then this * will sanity-check that the block being freed came from that heap. */ + PoolPtr = NULL; + PoolSize = 0; UT_GetDataBuffer(UT_KEY(PCS_free), &PoolPtr, &PoolSize, NULL); - Status = UT_DEFAULT_IMPL(PCS_free); + UT_Stub_GetInt32StatusCode(Context, &Status); if (Status == 0 && PoolPtr != NULL) { BlockAddr = (cpuaddr)ptr; diff --git a/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c index 096e624f..79e78b20 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c @@ -25,6 +25,10 @@ #include "PCS_stdlib.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_free(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_malloc(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strtoul(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_abort() @@ -57,7 +61,7 @@ void PCS_free(void *ptr) { UT_GenStub_AddParam(PCS_free, void *, ptr); - UT_GenStub_Execute(PCS_free, Basic, NULL); + UT_GenStub_Execute(PCS_free, Basic, UT_DefaultHandler_PCS_free); } /* @@ -71,7 +75,7 @@ void *PCS_malloc(size_t sz) UT_GenStub_AddParam(PCS_malloc, size_t, sz); - UT_GenStub_Execute(PCS_malloc, Basic, NULL); + UT_GenStub_Execute(PCS_malloc, Basic, UT_DefaultHandler_PCS_malloc); return UT_GenStub_GetReturnValue(PCS_malloc, void *); } @@ -89,7 +93,7 @@ unsigned long int PCS_strtoul(const char *nptr, char **endptr, int base) UT_GenStub_AddParam(PCS_strtoul, char **, endptr); UT_GenStub_AddParam(PCS_strtoul, int, base); - UT_GenStub_Execute(PCS_strtoul, Basic, NULL); + UT_GenStub_Execute(PCS_strtoul, Basic, UT_DefaultHandler_PCS_strtoul); return UT_GenStub_GetReturnValue(PCS_strtoul, unsigned long int); } diff --git a/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c b/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c new file mode 100644 index 00000000..da6fcfdb --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_string_handlers.c @@ -0,0 +1,228 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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. + ************************************************************************/ + +/* PSP coverage stub replacement for string.h */ +#include +#include +#include +#include "utstubs.h" + +#include "PCS_string.h" + +/* + * NOTE: Normal behavior of this particular set of C library routines is important. + * + * Case in point - if code relies on something like memset() to clear memory, but that + * memory is not cleared, then behavior of the code thereafter is undefined. Thus, most + * of the handlers here need to implement the real call by default. + */ + +void UT_DefaultHandler_PCS_memset(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* void *PCS_memset(void *s, int c, size_t n) */ + void * s = UT_Hook_GetArgValueByName(Context, "s", void *); + int c = UT_Hook_GetArgValueByName(Context, "c", int); + size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t); + + void *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = memset(s, c, n); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_memcpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* void *PCS_memcpy(void *dest, const void *src, size_t n) */ + void * dest = UT_Hook_GetArgValueByName(Context, "dest", void *); + const void *src = UT_Hook_GetArgValueByName(Context, "src", const void *); + size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t); + + void *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = memcpy(dest, src, n); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strchr(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strchr(const char *s, int c) */ + const char *s = UT_Hook_GetArgValueByName(Context, "s", const char *); + int c = UT_Hook_GetArgValueByName(Context, "c", int); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strchr(s, c); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strrchr(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strrchr(const char *s, int c) */ + const char *s = UT_Hook_GetArgValueByName(Context, "s", const char *); + int c = UT_Hook_GetArgValueByName(Context, "c", int); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strrchr(s, c); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strlen(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* size_t PCS_strlen(const char *s) */ + const char *s = UT_Hook_GetArgValueByName(Context, "s", const char *); + + size_t Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strlen(s); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strcat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strcat(char *dest, const char *src) */ + void * dest = UT_Hook_GetArgValueByName(Context, "dest", void *); + const void *src = UT_Hook_GetArgValueByName(Context, "src", const void *); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strcat(dest, src); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strncat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strncat(char *dest, const char *src, size_t size) */ + void * dest = UT_Hook_GetArgValueByName(Context, "dest", void *); + const void *src = UT_Hook_GetArgValueByName(Context, "src", const void *); + size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strncat(dest, src, size); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strncmp(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int PCS_strncmp(const char *s1, const char *s2, size_t n) */ + const char *s1 = UT_Hook_GetArgValueByName(Context, "s1", const char *); + const char *s2 = UT_Hook_GetArgValueByName(Context, "s2", const char *); + size_t n = UT_Hook_GetArgValueByName(Context, "n", size_t); + + int Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strncmp(s1, s2, n); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strcmp(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int PCS_strcmp(const char *s1, const char *s2) */ + const char *s1 = UT_Hook_GetArgValueByName(Context, "s1", const char *); + const char *s2 = UT_Hook_GetArgValueByName(Context, "s2", const char *); + + int Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strcmp(s1, s2); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strcpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strcpy(char *dst, const char *src) */ + char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *); + const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strcpy(dst, src); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strncpy(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strncpy(char *dst, const char *src, size_t size) */ + char * dst = UT_Hook_GetArgValueByName(Context, "dst", char *); + const char *src = UT_Hook_GetArgValueByName(Context, "src", const char *); + size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + + char *Result; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform the real operation */ + Result = strncpy(dst, src, size); + UT_Stub_SetReturnValue(FuncKey, Result); + } +} + +void UT_DefaultHandler_PCS_strerror(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* char *PCS_strerror(int errnum) */ + int errnum = UT_Hook_GetArgValueByName(Context, "errnum", int); + + static char str[16]; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + /* Perform a substitute operation */ + snprintf(str, sizeof(str), "UT_ERR_%d", errnum); + UT_Stub_SetReturnValue(FuncKey, str); + } +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c index 12d80b0d..03cb943d 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c @@ -25,6 +25,19 @@ #include "PCS_string.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_memcpy(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_memset(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strcat(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strchr(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strcmp(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strcpy(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strerror(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strlen(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strncat(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strncmp(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strncpy(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_strrchr(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_memcpy() @@ -38,7 +51,7 @@ void *PCS_memcpy(void *dest, const void *src, size_t n) UT_GenStub_AddParam(PCS_memcpy, const void *, src); UT_GenStub_AddParam(PCS_memcpy, size_t, n); - UT_GenStub_Execute(PCS_memcpy, Basic, NULL); + UT_GenStub_Execute(PCS_memcpy, Basic, UT_DefaultHandler_PCS_memcpy); return UT_GenStub_GetReturnValue(PCS_memcpy, void *); } @@ -56,7 +69,7 @@ void *PCS_memset(void *s, int c, size_t n) UT_GenStub_AddParam(PCS_memset, int, c); UT_GenStub_AddParam(PCS_memset, size_t, n); - UT_GenStub_Execute(PCS_memset, Basic, NULL); + UT_GenStub_Execute(PCS_memset, Basic, UT_DefaultHandler_PCS_memset); return UT_GenStub_GetReturnValue(PCS_memset, void *); } @@ -73,7 +86,7 @@ char *PCS_strcat(char *dest, const char *src) UT_GenStub_AddParam(PCS_strcat, char *, dest); UT_GenStub_AddParam(PCS_strcat, const char *, src); - UT_GenStub_Execute(PCS_strcat, Basic, NULL); + UT_GenStub_Execute(PCS_strcat, Basic, UT_DefaultHandler_PCS_strcat); return UT_GenStub_GetReturnValue(PCS_strcat, char *); } @@ -90,7 +103,7 @@ char *PCS_strchr(const char *s, int c) UT_GenStub_AddParam(PCS_strchr, const char *, s); UT_GenStub_AddParam(PCS_strchr, int, c); - UT_GenStub_Execute(PCS_strchr, Basic, NULL); + UT_GenStub_Execute(PCS_strchr, Basic, UT_DefaultHandler_PCS_strchr); return UT_GenStub_GetReturnValue(PCS_strchr, char *); } @@ -107,7 +120,7 @@ int PCS_strcmp(const char *s1, const char *s2) UT_GenStub_AddParam(PCS_strcmp, const char *, s1); UT_GenStub_AddParam(PCS_strcmp, const char *, s2); - UT_GenStub_Execute(PCS_strcmp, Basic, NULL); + UT_GenStub_Execute(PCS_strcmp, Basic, UT_DefaultHandler_PCS_strcmp); return UT_GenStub_GetReturnValue(PCS_strcmp, int); } @@ -124,7 +137,7 @@ char *PCS_strcpy(char *dest, const char *src) UT_GenStub_AddParam(PCS_strcpy, char *, dest); UT_GenStub_AddParam(PCS_strcpy, const char *, src); - UT_GenStub_Execute(PCS_strcpy, Basic, NULL); + UT_GenStub_Execute(PCS_strcpy, Basic, UT_DefaultHandler_PCS_strcpy); return UT_GenStub_GetReturnValue(PCS_strcpy, char *); } @@ -140,7 +153,7 @@ char *PCS_strerror(int errnum) UT_GenStub_AddParam(PCS_strerror, int, errnum); - UT_GenStub_Execute(PCS_strerror, Basic, NULL); + UT_GenStub_Execute(PCS_strerror, Basic, UT_DefaultHandler_PCS_strerror); return UT_GenStub_GetReturnValue(PCS_strerror, char *); } @@ -156,7 +169,7 @@ size_t PCS_strlen(const char *s) UT_GenStub_AddParam(PCS_strlen, const char *, s); - UT_GenStub_Execute(PCS_strlen, Basic, NULL); + UT_GenStub_Execute(PCS_strlen, Basic, UT_DefaultHandler_PCS_strlen); return UT_GenStub_GetReturnValue(PCS_strlen, size_t); } @@ -174,7 +187,7 @@ char *PCS_strncat(char *dest, const char *src, size_t n) UT_GenStub_AddParam(PCS_strncat, const char *, src); UT_GenStub_AddParam(PCS_strncat, size_t, n); - UT_GenStub_Execute(PCS_strncat, Basic, NULL); + UT_GenStub_Execute(PCS_strncat, Basic, UT_DefaultHandler_PCS_strncat); return UT_GenStub_GetReturnValue(PCS_strncat, char *); } @@ -192,7 +205,7 @@ int PCS_strncmp(const char *s1, const char *s2, size_t n) UT_GenStub_AddParam(PCS_strncmp, const char *, s2); UT_GenStub_AddParam(PCS_strncmp, size_t, n); - UT_GenStub_Execute(PCS_strncmp, Basic, NULL); + UT_GenStub_Execute(PCS_strncmp, Basic, UT_DefaultHandler_PCS_strncmp); return UT_GenStub_GetReturnValue(PCS_strncmp, int); } @@ -210,7 +223,7 @@ char *PCS_strncpy(char *dest, const char *src, size_t n) UT_GenStub_AddParam(PCS_strncpy, const char *, src); UT_GenStub_AddParam(PCS_strncpy, size_t, n); - UT_GenStub_Execute(PCS_strncpy, Basic, NULL); + UT_GenStub_Execute(PCS_strncpy, Basic, UT_DefaultHandler_PCS_strncpy); return UT_GenStub_GetReturnValue(PCS_strncpy, char *); } @@ -227,7 +240,7 @@ char *PCS_strrchr(const char *s, int c) UT_GenStub_AddParam(PCS_strrchr, const char *, s); UT_GenStub_AddParam(PCS_strrchr, int, c); - UT_GenStub_Execute(PCS_strrchr, Basic, NULL); + UT_GenStub_Execute(PCS_strrchr, Basic, UT_DefaultHandler_PCS_strrchr); return UT_GenStub_GetReturnValue(PCS_strrchr, char *); } diff --git a/unit-test-coverage/ut-stubs/src/vxworks-sysLib-stubs.c b/unit-test-coverage/ut-stubs/src/PCS_sysLib_handlers.c similarity index 62% rename from unit-test-coverage/ut-stubs/src/vxworks-sysLib-stubs.c rename to unit-test-coverage/ut-stubs/src/PCS_sysLib_handlers.c index 07f9cbab..7dd311eb 100644 --- a/unit-test-coverage/ut-stubs/src/vxworks-sysLib-stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_sysLib_handlers.c @@ -23,52 +23,31 @@ #include "PCS_sysLib.h" -int PCS_sysClkRateGet(void) +void UT_DefaultHandler_PCS_sysClkRateGet(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - return UT_DEFAULT_IMPL_RC(PCS_sysClkRateGet, 10000); + /* int PCS_sysClkRateGet(void) */ + int DefaultValue = 10000; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + UT_Stub_SetReturnValue(FuncKey, DefaultValue); + } } -char *PCS_sysMemTop(void) +void UT_DefaultHandler_PCS_sysMemTop(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { + /* char *PCS_sysMemTop(void) */ int32 Status; char *BufPtr; BufPtr = NULL; - Status = UT_DEFAULT_IMPL(PCS_sysMemTop); + UT_Stub_GetInt32StatusCode(Context, &Status); if (Status == 0) { UT_GetDataBuffer(UT_KEY(PCS_sysMemTop), (void **)&BufPtr, NULL, NULL); + if (BufPtr != NULL) + { + UT_Stub_SetReturnValue(FuncKey, BufPtr); + } } - - return BufPtr; -} - -void PCS_PciOutByte(uint32_t address, uint8_t data) -{ - UT_DEFAULT_IMPL(PCS_PciOutByte); -} - -void PCS_PciOutLong(uint32_t address, uint32_t data) -{ - UT_DEFAULT_IMPL(PCS_PciOutLong); -} - -void PCS_sysPciWrite32(uint32_t address, uint32_t data) -{ - UT_DEFAULT_IMPL(PCS_sysPciWrite32); -} - -void PCS_sysPciRead32(uint32_t address, uint32_t *data) -{ - UT_DEFAULT_IMPL(PCS_sysPciRead32); -} - -unsigned int PCS_GetWrsKernelTextStart(void) -{ - return UT_DEFAULT_IMPL(PCS_GetWrsKernelTextStart); -} - -unsigned int PCS_GetWrsKernelTextEnd(void) -{ - return UT_DEFAULT_IMPL(PCS_GetWrsKernelTextEnd); } diff --git a/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c index eb4a4ab1..781e3fd1 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c @@ -25,6 +25,9 @@ #include "PCS_sysLib.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_sysClkRateGet(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_sysMemTop(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_GetWrsKernelTextEnd() @@ -88,7 +91,7 @@ int PCS_sysClkRateGet(void) { UT_GenStub_SetupReturnBuffer(PCS_sysClkRateGet, int); - UT_GenStub_Execute(PCS_sysClkRateGet, Basic, NULL); + UT_GenStub_Execute(PCS_sysClkRateGet, Basic, UT_DefaultHandler_PCS_sysClkRateGet); return UT_GenStub_GetReturnValue(PCS_sysClkRateGet, int); } @@ -102,7 +105,7 @@ char *PCS_sysMemTop(void) { UT_GenStub_SetupReturnBuffer(PCS_sysMemTop, char *); - UT_GenStub_Execute(PCS_sysMemTop, Basic, NULL); + UT_GenStub_Execute(PCS_sysMemTop, Basic, UT_DefaultHandler_PCS_sysMemTop); return UT_GenStub_GetReturnValue(PCS_sysMemTop, char *); } diff --git a/unit-test-coverage/ut-stubs/src/PCS_taskLib_handlers.c b/unit-test-coverage/ut-stubs/src/PCS_taskLib_handlers.c new file mode 100644 index 00000000..d913f20f --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_taskLib_handlers.c @@ -0,0 +1,103 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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. + ************************************************************************/ + +/* PSP coverage stub replacement for taskLib.h */ +#include +#include +#include "utstubs.h" + +#include "PCS_taskLib.h" +#include "PCS_errnoLib.h" + +static PCS_WIND_TCB PCS_LOCAL_TASK = {0}; + +void UT_DefaultHandler_PCS_taskName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* const char *PCS_taskName(PCS_TASK_ID task_id) */ + + const char *retval; + + retval = NULL; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL) && + UT_Stub_CopyToLocal(FuncKey, &retval, sizeof(retval)) == sizeof(retval)) + { + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_taskIdSelf(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* PCS_TASK_ID PCS_taskIdSelf(void) */ + PCS_TASK_ID retval; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = &PCS_LOCAL_TASK; + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_taskNameToId(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* PCS_TASK_ID PCS_taskNameToId(const char *name) */ + PCS_TASK_ID retval; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = &PCS_LOCAL_TASK; + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_taskSpawn(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* PCS_TASK_ID PCS_taskSpawn(char *name, int priority, int options, int stackSize, PCS_FUNCPTR entryPt, int arg1, + int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) */ + PCS_TASK_ID retval; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + retval = &PCS_LOCAL_TASK; + UT_Stub_SetReturnValue(FuncKey, retval); + } +} + +void UT_DefaultHandler_PCS_taskTcb(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* PCS_WIND_TCB *PCS_taskTcb(PCS_TASK_ID tid) */ + PCS_TASK_ID tid = UT_Hook_GetArgValueByName(Context, "tid", PCS_TASK_ID); + + PCS_WIND_TCB *LocalTcb; + + if (!UT_Stub_GetInt32StatusCode(Context, NULL)) + { + if (UT_Stub_CopyToLocal(UT_KEY(PCS_taskTcb), &LocalTcb, sizeof(LocalTcb)) < sizeof(LocalTcb)) + { + /* + * On VxWorks the TASK_ID is defined as a direct type cast + * of the TCB address. This is actually documented + * in the API and application code that works with TCBs + * certainly will depend on this being the case. + */ + LocalTcb = (PCS_WIND_TCB *)tid; + } + + UT_Stub_SetReturnValue(FuncKey, LocalTcb); + } +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c index f6725825..6951c83c 100644 --- a/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c +++ b/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c @@ -25,6 +25,12 @@ #include "PCS_taskLib.h" #include "utgenstub.h" +void UT_DefaultHandler_PCS_taskIdSelf(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_taskName(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_taskNameToId(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_taskSpawn(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_PCS_taskTcb(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for PCS_taskActivate() @@ -143,7 +149,7 @@ PCS_TASK_ID PCS_taskIdSelf(void) { UT_GenStub_SetupReturnBuffer(PCS_taskIdSelf, PCS_TASK_ID); - UT_GenStub_Execute(PCS_taskIdSelf, Basic, NULL); + UT_GenStub_Execute(PCS_taskIdSelf, Basic, UT_DefaultHandler_PCS_taskIdSelf); return UT_GenStub_GetReturnValue(PCS_taskIdSelf, PCS_TASK_ID); } @@ -225,7 +231,7 @@ const char *PCS_taskName(PCS_TASK_ID task_id) UT_GenStub_AddParam(PCS_taskName, PCS_TASK_ID, task_id); - UT_GenStub_Execute(PCS_taskName, Basic, NULL); + UT_GenStub_Execute(PCS_taskName, Basic, UT_DefaultHandler_PCS_taskName); return UT_GenStub_GetReturnValue(PCS_taskName, const char *); } @@ -241,7 +247,7 @@ PCS_TASK_ID PCS_taskNameToId(const char *name) UT_GenStub_AddParam(PCS_taskNameToId, const char *, name); - UT_GenStub_Execute(PCS_taskNameToId, Basic, NULL); + UT_GenStub_Execute(PCS_taskNameToId, Basic, UT_DefaultHandler_PCS_taskNameToId); return UT_GenStub_GetReturnValue(PCS_taskNameToId, PCS_TASK_ID); } @@ -305,7 +311,7 @@ PCS_TASK_ID PCS_taskSpawn(char *name, int priority, int options, int stackSize, UT_GenStub_AddParam(PCS_taskSpawn, int, arg9); UT_GenStub_AddParam(PCS_taskSpawn, int, arg10); - UT_GenStub_Execute(PCS_taskSpawn, Basic, NULL); + UT_GenStub_Execute(PCS_taskSpawn, Basic, UT_DefaultHandler_PCS_taskSpawn); return UT_GenStub_GetReturnValue(PCS_taskSpawn, PCS_TASK_ID); } @@ -337,7 +343,7 @@ PCS_WIND_TCB *PCS_taskTcb(PCS_TASK_ID tid) UT_GenStub_AddParam(PCS_taskTcb, PCS_TASK_ID, tid); - UT_GenStub_Execute(PCS_taskTcb, Basic, NULL); + UT_GenStub_Execute(PCS_taskTcb, Basic, UT_DefaultHandler_PCS_taskTcb); return UT_GenStub_GetReturnValue(PCS_taskTcb, PCS_WIND_TCB *); } diff --git a/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c b/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c deleted file mode 100644 index d5f43c3b..00000000 --- a/unit-test-coverage/ut-stubs/src/libc-stdio-stubs.c +++ /dev/null @@ -1,206 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for stdio.h */ -#include -#include -#include -#include "utstubs.h" - -#include "PCS_stdio.h" - -struct PCS_FILE -{ - int f; -}; - -#define PCS_STDIO_MAX_SIZE 0x01000000 - -int PCS_fclose(PCS_FILE *stream) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_fclose); - - return Status; -} - -char *PCS_fgets(char *s, int n, PCS_FILE *stream) -{ - int32 Status; - uint32 CopySize; - - Status = UT_DEFAULT_IMPL_RC(PCS_fgets, PCS_STDIO_MAX_SIZE); - - if (Status > 0) - { - if (Status > n) - { - CopySize = n; - } - else - { - CopySize = Status; - } - - CopySize = UT_Stub_CopyToLocal(UT_KEY(PCS_fgets), s, CopySize); - - if (CopySize != 0) - { - Status = CopySize; - } - else if (Status <= n) - { - memset(s, 'x', Status); - } - else if (UT_GetStubCount(UT_KEY(PCS_fgets) < 4)) - { - memset(s, 'x', n); - Status = n; - } - else - { - Status = 0; - } - } - - if (Status <= 0) - { - return NULL; - } - - return s; -} - -PCS_FILE *PCS_fopen(const char *filename, const char *modes) -{ - int32 Status; - PCS_FILE * retval; - static PCS_FILE FOPEN_FP = {0}; - - Status = UT_DEFAULT_IMPL(PCS_fopen); - - if (Status == 0) - { - retval = &FOPEN_FP; - } - else - { - retval = NULL; - } - - return retval; -} - -int PCS_fputs(const char *s, PCS_FILE *stream) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_fputs); - - return Status; -} - -int PCS_putchar(int c) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_putchar); - - return Status; -} - -int PCS_remove(const char *filename) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_remove); - - return Status; -} - -int PCS_rename(const char *old, const char *nw) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_rename); - - return Status; -} - -int PCS_snprintf(char *s, size_t maxlen, const char *format, ...) -{ - int32 Status; - int actual = 0; - va_list ap; - - Status = UT_DEFAULT_IMPL(PCS_snprintf); - - /* need to actually _do_ the snprintf */ - if (Status >= 0) - { - va_start(ap, format); - actual = vsnprintf(s, maxlen, format, ap); - va_end(ap); - } - - if (Status != 0) - { - actual = Status; - } - - return actual; -} - -int PCS_vsnprintf(char *s, size_t maxlen, const char *format, PCS_va_list arg) -{ - int32 Status; - int actual = 0; - - Status = UT_DEFAULT_IMPL(PCS_vsnprintf); - - /* need to actually _do_ something here - - * cannot do the real vsnprintf because we lost the args. */ - if (Status >= 0) - { - actual = snprintf(s, maxlen, "%s", format); - } - - if (Status != 0) - { - actual = Status; - } - - return actual; -} - -int PCS_printf(const char *format, ...) -{ - return UT_DEFAULT_IMPL(PCS_printf); -} - -void PCS_perror(const char * str) -{ - /* No implmentation */ -} - -static PCS_FILE LOCAL_FP[3] = {{10}, {11}, {12}}; - -PCS_FILE *PCS_stdin = &LOCAL_FP[0]; -PCS_FILE *PCS_stdout = &LOCAL_FP[1]; -PCS_FILE *PCS_stderr = &LOCAL_FP[2]; diff --git a/unit-test-coverage/ut-stubs/src/libc-string-stubs.c b/unit-test-coverage/ut-stubs/src/libc-string-stubs.c deleted file mode 100644 index adb92ed0..00000000 --- a/unit-test-coverage/ut-stubs/src/libc-string-stubs.c +++ /dev/null @@ -1,205 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for string.h */ -#include -#include -#include -#include "utstubs.h" - -#include "PCS_string.h" - -void *PCS_memset(void *s, int c, size_t n) -{ - int32 Status; - void *Result; - - Status = UT_DEFAULT_IMPL(PCS_memset); - - if (Status == 0) - { - Result = memset(s, c, n); - } - else - { - Result = NULL; - } - - return Result; -} - -void *PCS_memcpy(void *dest, const void *src, size_t n) -{ - int32 Status; - void *Result; - - Status = UT_DEFAULT_IMPL(PCS_memcpy); - - if (Status == 0) - { - Result = memcpy(dest, src, n); - } - else - { - Result = NULL; - } - - return Result; -} - -char *PCS_strchr(const char *s, int c) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strchr); - - if (Status == 0) - { - /* "nominal" response */ - return strchr(s, c); - } - if (Status < 0) - { - return (char *)0; - } - - return (char *)&s[Status - 1]; -} - -char *PCS_strrchr(const char *s, int c) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strrchr); - - if (Status == 0) - { - /* "nominal" response */ - return strrchr(s, c); - } - if (Status < 0) - { - return (char *)0; - } - - return (char *)&s[Status - 1]; -} - -size_t PCS_strlen(const char *s) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(PCS_strlen, strlen(s)); - - return Status; -} - -char *PCS_strcat(char *dest, const char *src) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strcat); - - if (Status == 0) - { - /* "nominal" response */ - return strcat(dest, src); - } - - return (char *)0; -} - -char *PCS_strncat(char *dest, const char *src, size_t size) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strncat); - - if (Status == 0) - { - /* "nominal" response */ - return strncat(dest, src, size); - } - - return (char *)0; -} - -int PCS_strncmp(const char *s1, const char *s2, size_t size) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(PCS_strncmp, strncmp(s1, s2, size)); - - return Status; -} - -int PCS_strcmp(const char *s1, const char *s2) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(PCS_strcmp, strcmp(s1, s2)); - - return Status; -} - -char *PCS_strcpy(char *dst, const char *src) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strcpy); - - if (Status == 0) - { - /* "nominal" response */ - return strcpy(dst, src); - } - - return (char *)0; -} - -char *PCS_strncpy(char *dst, const char *src, size_t size) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strncpy); - - if (Status == 0) - { - /* "nominal" response */ - return strncpy(dst, src, size); - } - - return (char *)0; -} - -char *PCS_strerror(int errnum) -{ - static char str[16]; - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_strerror); - - if (Status != 0) - { - return NULL; - } - - /* "nominal" response */ - snprintf(str, sizeof(str), "UT_ERR_%d", errnum); - return str; -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-cacheLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-cacheLib-stubs.c deleted file mode 100644 index 2fab1476..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-cacheLib-stubs.c +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for cacheLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_cacheLib.h" - -PCS_STATUS PCS_cacheTextUpdate(void *adrs, size_t bytes) -{ - return UT_DEFAULT_IMPL(PCS_cacheTextUpdate); -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-excLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-excLib-stubs.c deleted file mode 100644 index 5a717de6..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-excLib-stubs.c +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for excLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_excLib.h" - -void PCS_excHookAdd(void (*Hook)(PCS_TASK_ID, int, void *)) -{ - UT_DEFAULT_IMPL(PCS_excHookAdd); -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-fppLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-fppLib-stubs.c deleted file mode 100644 index 1a60c7b9..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-fppLib-stubs.c +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for fppLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_fppLib.h" - -void PCS_fppSave(PCS_FP_CONTEXT *fpc) -{ - UT_DEFAULT_IMPL(PCS_fppSave); -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-rebootLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-rebootLib-stubs.c deleted file mode 100644 index c85d039f..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-rebootLib-stubs.c +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for rebootLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_rebootLib.h" - -void PCS_reboot(int boottype) -{ - UT_DEFAULT_IMPL(PCS_reboot); -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-spyLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-spyLib-stubs.c deleted file mode 100644 index ef22cbb2..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-spyLib-stubs.c +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2023 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. - ************************************************************************/ - -/* PSP coverage stub replacement for spyLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_spyLib.h" - - -void PCS_spyLibInit(int maxTasks) -{ - /* Not Implment */ -} - diff --git a/unit-test-coverage/ut-stubs/src/vxworks-spyLibP-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-spyLibP-stubs.c deleted file mode 100644 index ed226f47..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-spyLibP-stubs.c +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2023 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. - ************************************************************************/ - -/* PSP coverage stub replacement for spyLibP.h */ -#include -#include -#include "utstubs.h" -#include "utgenstub.h" - -#include "PCS_spyLibP.h" - -void PCS_spyReportCommon(PCS_FUNCPTR print) -{ - /* Not Implement*/ -} - -void PCS_spyClkStopCommon(void) -{ - /* Not Implement */ -} - -int PCS_spyClkStartCommon(int intsPerSec, PCS_FUNCPTR print) -{ - - UT_GenStub_SetupReturnBuffer(PCS_spyClkStartCommon, int32); - - UT_GenStub_AddParam(PCS_spyClkStartCommon, int, intsPerSec); - UT_GenStub_AddParam(PCS_spyClkStartCommon, PCS_FUNCPTR, print); - - UT_GenStub_Execute(PCS_spyClkStartCommon, Basic, NULL); - - return UT_GenStub_GetReturnValue(PCS_spyClkStartCommon, int32);; -} - diff --git a/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c deleted file mode 100644 index 7d433954..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-taskLib-stubs.c +++ /dev/null @@ -1,159 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for taskLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_taskLib.h" -#include "PCS_errnoLib.h" - -static PCS_WIND_TCB PCS_LOCAL_TASK = {0}; - -const char *PCS_taskName(PCS_TASK_ID task_id) -{ - const char *retval; - int32 Status; - - retval = NULL; - Status = UT_DEFAULT_IMPL(PCS_taskName); - if (Status == 0) - { - UT_Stub_CopyToLocal(UT_KEY(PCS_taskName), &retval, sizeof(retval)); - } - - return retval; -} - -void PCS_taskExit(int code) -{ - UT_DEFAULT_IMPL(PCS_taskExit); -} - -PCS_TASK_ID PCS_taskIdSelf(void) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_taskIdSelf); - if (Status != 0) - { - return (PCS_TASK_ID)PCS_ERROR; - } - - return &PCS_LOCAL_TASK; -} - -PCS_TASK_ID PCS_taskNameToId(const char *name) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_taskNameToId); - if (Status != 0) - { - return (PCS_TASK_ID)PCS_ERROR; - } - - return &PCS_LOCAL_TASK; -} - -PCS_STATUS PCS_taskDelay(int ticks) -{ - return UT_DEFAULT_IMPL(PCS_taskDelay); -} - -PCS_STATUS PCS_taskDelete(PCS_TASK_ID tid) -{ - return UT_DEFAULT_IMPL(PCS_taskDelete); -} - -PCS_STATUS PCS_taskDeleteForce(PCS_TASK_ID tid) -{ - return UT_DEFAULT_IMPL(PCS_taskDeleteForce); -} - -PCS_STATUS PCS_taskSuspend(PCS_TASK_ID tid) -{ - return UT_DEFAULT_IMPL(PCS_taskSuspend); -} - -PCS_STATUS PCS_taskResume(PCS_TASK_ID tid) -{ - return UT_DEFAULT_IMPL(PCS_taskResume); -} - -PCS_STATUS PCS_taskPrioritySet(PCS_TASK_ID tid, int newPriority) -{ - return UT_DEFAULT_IMPL(PCS_taskPrioritySet); -} - -PCS_STATUS PCS_taskInit(PCS_WIND_TCB *pTcb, char *name, int priority, int options, char *pStackBase, int stackSize, - PCS_FUNCPTR entryPt, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, - int arg8, int arg9, int arg10) -{ - return UT_DEFAULT_IMPL(PCS_taskInit); -} - -PCS_TASK_ID PCS_taskSpawn(char *name, int priority, int options, int stackSize, PCS_FUNCPTR entryPt, int arg1, int arg2, - int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) - -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_taskSpawn); - if (Status != 0) - { - return (PCS_TASK_ID)PCS_ERROR; - } - - return &PCS_LOCAL_TASK; -} - -PCS_STATUS PCS_taskActivate(PCS_TASK_ID tid) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(PCS_taskActivate); - - return Status; -} - -PCS_WIND_TCB *PCS_taskTcb(PCS_TASK_ID tid) -{ - int32 Status; - PCS_WIND_TCB *LocalTcb; - - Status = UT_DEFAULT_IMPL(PCS_taskTcb); - if (Status != 0) - { - return NULL; - } - - if (UT_Stub_CopyToLocal(UT_KEY(PCS_taskTcb), &LocalTcb, sizeof(LocalTcb)) < sizeof(LocalTcb)) - { - /* - * On VxWorks the TASK_ID is defined as a direct type cast - * of the TCB address. This is actually documented - * in the API and application code that works with TCBs - * certainly will depend on this being the case. - */ - LocalTcb = (PCS_WIND_TCB *)tid; - } - - return LocalTcb; -} diff --git a/unit-test-coverage/ut-stubs/src/vxworks-vxLib-stubs.c b/unit-test-coverage/ut-stubs/src/vxworks-vxLib-stubs.c deleted file mode 100644 index ac73b908..00000000 --- a/unit-test-coverage/ut-stubs/src/vxworks-vxLib-stubs.c +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” - * - * Copyright (c) 2020 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. - ************************************************************************/ - -/* PSP coverage stub replacement for vxLib.h */ -#include -#include -#include "utstubs.h" - -#include "PCS_vxLib.h" -#include "PCS_arch_ppc_vxPpcLib.h" - -void PCS_vxTimeBaseGet(uint32_t *u, uint32_t *l) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(PCS_vxTimeBaseGet), u); - UT_Stub_RegisterContextGenericArg(UT_KEY(PCS_vxTimeBaseGet), l); - *u = 0; - *l = 0; - UT_DEFAULT_IMPL(PCS_vxTimeBaseGet); -} - -void PCS_vxMsrSet(uint32_t val) -{ - UT_DEFAULT_IMPL(PCS_vxMsrSet); -} - -uint32_t PCS_vxMsrGet(void) -{ - return UT_DEFAULT_IMPL(PCS_vxMsrGet); -} - -void PCS_vxFpscrSet(uint32_t val) -{ - UT_DEFAULT_IMPL(PCS_vxFpscrSet); -} - -uint32_t PCS_vxFpscrGet(void) -{ - return UT_DEFAULT_IMPL(PCS_vxFpscrGet); -} - -uint32_t PCS_vxDecGet(void) -{ - return UT_DEFAULT_IMPL(PCS_vxDecGet); -} diff --git a/ut-stubs/CMakeLists.txt b/ut-stubs/CMakeLists.txt index 67d69f50..0157c9a5 100644 --- a/ut-stubs/CMakeLists.txt +++ b/ut-stubs/CMakeLists.txt @@ -14,6 +14,7 @@ add_library(ut_psp_api_stubs src/cfe_psp_globaldata_stubs.c src/cfe_psp_id_api_handlers.c src/cfe_psp_id_api_stubs.c + src/cfe_psp_memaccess_api_handlers.c src/cfe_psp_memaccess_api_stubs.c src/cfe_psp_memory_stubs.c src/cfe_psp_memrange_api_handlers.c diff --git a/ut-stubs/src/cfe_psp_memaccess_api_handlers.c b/ut-stubs/src/cfe_psp_memaccess_api_handlers.c new file mode 100644 index 00000000..d2f741f6 --- /dev/null +++ b/ut-stubs/src/cfe_psp_memaccess_api_handlers.c @@ -0,0 +1,88 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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_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 + +/* +** Functions +*/ + +void UT_DefaultHandler_CFE_PSP_MemRead8(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_MemRead8(cpuaddr MemoryAddress, uint8 *ByteValue) */ + uint8 *outptr = UT_Hook_GetArgValueByName(Context, "ByteValue", uint8 *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + if (Status == CFE_PSP_SUCCESS && outptr != NULL) + { + if (UT_Stub_CopyToLocal(FuncKey, outptr, sizeof(*outptr)) != sizeof(*outptr)) + { + *outptr = 1; + } + } +} + +void UT_DefaultHandler_CFE_PSP_MemRead16(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_MemRead16(cpuaddr MemoryAddress, uint16 *uint16Value) */ + uint16 *outptr = UT_Hook_GetArgValueByName(Context, "uint16Value", uint16 *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + if (Status == CFE_PSP_SUCCESS && outptr != NULL) + { + if (UT_Stub_CopyToLocal(FuncKey, outptr, sizeof(*outptr)) != sizeof(*outptr)) + { + *outptr = 0; + } + } +} + +void UT_DefaultHandler_CFE_PSP_MemRead32(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_MemRead32(cpuaddr MemoryAddress, uint32 *uint32Value) */ + uint32 *outptr = UT_Hook_GetArgValueByName(Context, "uint32Value", uint32 *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + if (Status == CFE_PSP_SUCCESS && outptr != NULL) + { + if (UT_Stub_CopyToLocal(FuncKey, outptr, sizeof(*outptr)) != sizeof(*outptr)) + { + *outptr = 0; + } + } +} diff --git a/ut-stubs/src/cfe_psp_memaccess_api_stubs.c b/ut-stubs/src/cfe_psp_memaccess_api_stubs.c index a19c44fe..d103f951 100644 --- a/ut-stubs/src/cfe_psp_memaccess_api_stubs.c +++ b/ut-stubs/src/cfe_psp_memaccess_api_stubs.c @@ -25,6 +25,10 @@ #include "cfe_psp_memaccess_api.h" #include "utgenstub.h" +void UT_DefaultHandler_CFE_PSP_MemRead16(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_CFE_PSP_MemRead32(void *, UT_EntryKey_t, const UT_StubContext_t *); +void UT_DefaultHandler_CFE_PSP_MemRead8(void *, UT_EntryKey_t, const UT_StubContext_t *); + /* * ---------------------------------------------------- * Generated stub function for CFE_PSP_MemCpy() @@ -55,7 +59,7 @@ int32 CFE_PSP_MemRead16(cpuaddr MemoryAddress, uint16 *uint16Value) UT_GenStub_AddParam(CFE_PSP_MemRead16, cpuaddr, MemoryAddress); UT_GenStub_AddParam(CFE_PSP_MemRead16, uint16 *, uint16Value); - UT_GenStub_Execute(CFE_PSP_MemRead16, Basic, NULL); + UT_GenStub_Execute(CFE_PSP_MemRead16, Basic, UT_DefaultHandler_CFE_PSP_MemRead16); return UT_GenStub_GetReturnValue(CFE_PSP_MemRead16, int32); } @@ -72,7 +76,7 @@ int32 CFE_PSP_MemRead32(cpuaddr MemoryAddress, uint32 *uint32Value) UT_GenStub_AddParam(CFE_PSP_MemRead32, cpuaddr, MemoryAddress); UT_GenStub_AddParam(CFE_PSP_MemRead32, uint32 *, uint32Value); - UT_GenStub_Execute(CFE_PSP_MemRead32, Basic, NULL); + UT_GenStub_Execute(CFE_PSP_MemRead32, Basic, UT_DefaultHandler_CFE_PSP_MemRead32); return UT_GenStub_GetReturnValue(CFE_PSP_MemRead32, int32); } @@ -89,7 +93,7 @@ int32 CFE_PSP_MemRead8(cpuaddr MemoryAddress, uint8 *ByteValue) UT_GenStub_AddParam(CFE_PSP_MemRead8, cpuaddr, MemoryAddress); UT_GenStub_AddParam(CFE_PSP_MemRead8, uint8 *, ByteValue); - UT_GenStub_Execute(CFE_PSP_MemRead8, Basic, NULL); + UT_GenStub_Execute(CFE_PSP_MemRead8, Basic, UT_DefaultHandler_CFE_PSP_MemRead8); return UT_GenStub_GetReturnValue(CFE_PSP_MemRead8, int32); }