From e6c5f5d3ce502bc0e88d6039384a0fae4698685f Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 2 Aug 2024 16:13:25 -0400 Subject: [PATCH] Reorg of PSP stubs --- .../src/PCS_arch_ppc_vxPpcLib_stubs.c | 105 +++ .../ut-stubs/src/PCS_bsdnet_stubs.c | 83 ++ .../ut-stubs/src/PCS_cacheLib_stubs.c | 43 + .../ut-stubs/src/PCS_cfe_configdata_stubs.c | 63 ++ .../ut-stubs/src/PCS_dosFsLib_stubs.c | 44 + .../ut-stubs/src/PCS_drv_hdisk_ataDrv_stubs.c | 45 + .../ut-stubs/src/PCS_errnoLib_stubs.c | 40 + .../ut-stubs/src/PCS_excLib_stubs.c | 39 + .../ut-stubs/src/PCS_fppLib_stubs.c | 38 + .../ut-stubs/src/PCS_moduleLib_stubs.c | 59 ++ .../ut-stubs/src/PCS_ramDrv_stubs.c | 46 + .../ut-stubs/src/PCS_rebootLib_stubs.c | 38 + .../ut-stubs/src/PCS_spyLibP_stubs.c | 66 ++ .../ut-stubs/src/PCS_spyLib_stubs.c | 38 + .../ut-stubs/src/PCS_stdio_stubs.c | 218 +++++ .../ut-stubs/src/PCS_stdlib_stubs.c | 111 +++ .../ut-stubs/src/PCS_string_stubs.c | 233 +++++ .../ut-stubs/src/PCS_sysLib_stubs.c | 134 +++ .../ut-stubs/src/PCS_taskLib_stubs.c | 343 ++++++++ .../ut-stubs/src/PCS_unistd_stubs.c | 201 +++++ .../ut-stubs/src/PCS_xbdBlkDev_stubs.c | 60 ++ ut-stubs/CMakeLists.txt | 2 + ut-stubs/src/cfe_psp_cache_api_handlers.c | 42 + ut-stubs/src/cfe_psp_cds_api_handlers.c | 154 ++++ .../src/cfe_psp_eepromaccess_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_error_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_exception_api_handlers.c | 356 ++++++++ ut-stubs/src/cfe_psp_globaldata_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_id_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_memaccess_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_memrange_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_port_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_ssr_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_timertick_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_version_api_handlers.c | 831 ++++++++++++++++++ ut-stubs/src/cfe_psp_watchdog_api_handlers.c | 831 ++++++++++++++++++ 37 files changed, 12573 insertions(+) create mode 100644 unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_cacheLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_cfe_configdata_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_dosFsLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_drv_hdisk_ataDrv_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_errnoLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_excLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_fppLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_ramDrv_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_rebootLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_spyLibP_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_spyLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_string_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c create mode 100644 unit-test-coverage/ut-stubs/src/PCS_xbdBlkDev_stubs.c create mode 100644 ut-stubs/src/cfe_psp_cache_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_cds_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_eepromaccess_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_error_handlers.c create mode 100644 ut-stubs/src/cfe_psp_exception_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_globaldata_handlers.c create mode 100644 ut-stubs/src/cfe_psp_handlers.c create mode 100644 ut-stubs/src/cfe_psp_id_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_memaccess_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_memrange_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_port_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_ssr_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_timertick_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_version_api_handlers.c create mode 100644 ut-stubs/src/cfe_psp_watchdog_api_handlers.c 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 new file mode 100644 index 00000000..dac8d644 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_arch_ppc_vxPpcLib_stubs.c @@ -0,0 +1,105 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_arch_ppc_vxPpcLib header + */ + +#include "PCS_arch_ppc_vxPpcLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxDecGet() + * ---------------------------------------------------- + */ +uint32_t PCS_vxDecGet(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_vxDecGet, uint32_t); + + UT_GenStub_Execute(PCS_vxDecGet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_vxDecGet, uint32_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxFpscrGet() + * ---------------------------------------------------- + */ +uint32_t PCS_vxFpscrGet(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_vxFpscrGet, uint32_t); + + UT_GenStub_Execute(PCS_vxFpscrGet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_vxFpscrGet, uint32_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxFpscrSet() + * ---------------------------------------------------- + */ +void PCS_vxFpscrSet(uint32_t) +{ + UT_GenStub_AddParam(PCS_vxFpscrSet, , uint32_t); + + UT_GenStub_Execute(PCS_vxFpscrSet, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxMsrGet() + * ---------------------------------------------------- + */ +uint32_t PCS_vxMsrGet(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_vxMsrGet, uint32_t); + + UT_GenStub_Execute(PCS_vxMsrGet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_vxMsrGet, uint32_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxMsrSet() + * ---------------------------------------------------- + */ +void PCS_vxMsrSet(uint32_t) +{ + UT_GenStub_AddParam(PCS_vxMsrSet, , uint32_t); + + UT_GenStub_Execute(PCS_vxMsrSet, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vxTimeBaseGet() + * ---------------------------------------------------- + */ +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); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c new file mode 100644 index 00000000..3c39909f --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_bsdnet_stubs.c @@ -0,0 +1,83 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_bsdnet header + */ + +#include "PCS_bsdnet.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_bsdnet_do_dhcp_failsafe() + * ---------------------------------------------------- + */ +void PCS_rtems_bsdnet_do_dhcp_failsafe(void) +{ + + UT_GenStub_Execute(PCS_rtems_bsdnet_do_dhcp_failsafe, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_bsdnet_initialize_network() + * ---------------------------------------------------- + */ +int PCS_rtems_bsdnet_initialize_network(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_bsdnet_initialize_network, int); + + UT_GenStub_Execute(PCS_rtems_bsdnet_initialize_network, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_bsdnet_initialize_network, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_fxp_attach() + * ---------------------------------------------------- + */ +int PCS_rtems_fxp_attach(struct PCS_rtems_bsdnet_ifconfig *, int) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_fxp_attach, int); + + UT_GenStub_AddParam(PCS_rtems_fxp_attach, , int); + + UT_GenStub_Execute(PCS_rtems_fxp_attach, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_fxp_attach, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rtems_status_text() + * ---------------------------------------------------- + */ +const char *PCS_rtems_status_text(PCS_rtems_status_code) +{ + UT_GenStub_SetupReturnBuffer(PCS_rtems_status_text, const char *); + + UT_GenStub_AddParam(PCS_rtems_status_text, , PCS_rtems_status_code); + + UT_GenStub_Execute(PCS_rtems_status_text, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rtems_status_text, const char *); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_cacheLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_cacheLib_stubs.c new file mode 100644 index 00000000..2023f390 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_cacheLib_stubs.c @@ -0,0 +1,43 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_cacheLib header + */ + +#include "PCS_cacheLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_cacheTextUpdate() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_cacheTextUpdate(void *adrs, size_t bytes) +{ + UT_GenStub_SetupReturnBuffer(PCS_cacheTextUpdate, PCS_STATUS); + + UT_GenStub_AddParam(PCS_cacheTextUpdate, void *, adrs); + UT_GenStub_AddParam(PCS_cacheTextUpdate, size_t, bytes); + + UT_GenStub_Execute(PCS_cacheTextUpdate, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_cacheTextUpdate, PCS_STATUS); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_cfe_configdata_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_cfe_configdata_stubs.c new file mode 100644 index 00000000..3cabcef7 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_cfe_configdata_stubs.c @@ -0,0 +1,63 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_cfe_configdata header + */ + +#include "PCS_cfe_configdata.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_System1HzISR() + * ---------------------------------------------------- + */ +void PCS_System1HzISR(void) +{ + + UT_GenStub_Execute(PCS_System1HzISR, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_SystemMain() + * ---------------------------------------------------- + */ +void PCS_SystemMain(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const char *StartFilePath) +{ + UT_GenStub_AddParam(PCS_SystemMain, uint32, StartType); + UT_GenStub_AddParam(PCS_SystemMain, uint32, StartSubtype); + UT_GenStub_AddParam(PCS_SystemMain, uint32, ModeId); + UT_GenStub_AddParam(PCS_SystemMain, const char *, StartFilePath); + + UT_GenStub_Execute(PCS_SystemMain, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_SystemNotify() + * ---------------------------------------------------- + */ +void PCS_SystemNotify(void) +{ + + UT_GenStub_Execute(PCS_SystemNotify, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_dosFsLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_dosFsLib_stubs.c new file mode 100644 index 00000000..6e720e4c --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_dosFsLib_stubs.c @@ -0,0 +1,44 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_dosFsLib header + */ + +#include "PCS_dosFsLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_dosFsVolFormat() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_dosFsVolFormat(char *path, int opt, PCS_FUNCPTR pPromptFunc) +{ + UT_GenStub_SetupReturnBuffer(PCS_dosFsVolFormat, PCS_STATUS); + + UT_GenStub_AddParam(PCS_dosFsVolFormat, char *, path); + UT_GenStub_AddParam(PCS_dosFsVolFormat, int, opt); + UT_GenStub_AddParam(PCS_dosFsVolFormat, PCS_FUNCPTR, pPromptFunc); + + UT_GenStub_Execute(PCS_dosFsVolFormat, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_dosFsVolFormat, PCS_STATUS); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_drv_hdisk_ataDrv_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_drv_hdisk_ataDrv_stubs.c new file mode 100644 index 00000000..b185f8f3 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_drv_hdisk_ataDrv_stubs.c @@ -0,0 +1,45 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_drv_hdisk_ataDrv header + */ + +#include "PCS_drv_hdisk_ataDrv.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_ataXbdDevCreate() + * ---------------------------------------------------- + */ +PCS_device_t PCS_ataXbdDevCreate(int ctrl, int drive, unsigned int nBlks, unsigned int offset, const char *) +{ + UT_GenStub_SetupReturnBuffer(PCS_ataXbdDevCreate, PCS_device_t); + + UT_GenStub_AddParam(PCS_ataXbdDevCreate, int, ctrl); + UT_GenStub_AddParam(PCS_ataXbdDevCreate, int, drive); + UT_GenStub_AddParam(PCS_ataXbdDevCreate, unsigned int, nBlks); + UT_GenStub_AddParam(PCS_ataXbdDevCreate, unsigned int, offset); + + UT_GenStub_Execute(PCS_ataXbdDevCreate, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_ataXbdDevCreate, PCS_device_t); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_errnoLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_errnoLib_stubs.c new file mode 100644 index 00000000..ae9091ec --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_errnoLib_stubs.c @@ -0,0 +1,40 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_errnoLib header + */ + +#include "PCS_errnoLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_errnoGet() + * ---------------------------------------------------- + */ +int PCS_errnoGet(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_errnoGet, int); + + UT_GenStub_Execute(PCS_errnoGet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_errnoGet, int); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_excLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_excLib_stubs.c new file mode 100644 index 00000000..2dd5405d --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_excLib_stubs.c @@ -0,0 +1,39 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_excLib header + */ + +#include "PCS_excLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_excHookAdd() + * ---------------------------------------------------- + */ +void PCS_excHookAdd(void (*Hook)(PCS_TASK_ID, int, void *)) +{ +UT_GenStub_AddParam(PCS_excHookAdd, void (*Hook)(, PCS_TASK_ID); +UT_GenStub_AddParam(PCS_excHookAdd, , int); + +UT_GenStub_Execute(PCS_excHookAdd, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_fppLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_fppLib_stubs.c new file mode 100644 index 00000000..9e67c81c --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_fppLib_stubs.c @@ -0,0 +1,38 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_fppLib header + */ + +#include "PCS_fppLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_fppSave() + * ---------------------------------------------------- + */ +void PCS_fppSave(PCS_FP_CONTEXT *fpc) +{ + UT_GenStub_AddParam(PCS_fppSave, PCS_FP_CONTEXT *, fpc); + + UT_GenStub_Execute(PCS_fppSave, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c new file mode 100644 index 00000000..f4980ebd --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_moduleLib_stubs.c @@ -0,0 +1,59 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_moduleLib header + */ + +#include "PCS_moduleLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_moduleFindByName() + * ---------------------------------------------------- + */ +PCS_MODULE_ID PCS_moduleFindByName(const char *moduleName) +{ + UT_GenStub_SetupReturnBuffer(PCS_moduleFindByName, PCS_MODULE_ID); + + UT_GenStub_AddParam(PCS_moduleFindByName, const char *, moduleName); + + UT_GenStub_Execute(PCS_moduleFindByName, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_moduleFindByName, PCS_MODULE_ID); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_moduleInfoGet() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_moduleInfoGet(PCS_MODULE_ID moduleId, PCS_MODULE_INFO *pModuleInfo) +{ + UT_GenStub_SetupReturnBuffer(PCS_moduleInfoGet, PCS_STATUS); + + 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); + + return UT_GenStub_GetReturnValue(PCS_moduleInfoGet, PCS_STATUS); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_ramDrv_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_ramDrv_stubs.c new file mode 100644 index 00000000..d6701bc0 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_ramDrv_stubs.c @@ -0,0 +1,46 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_ramDrv header + */ + +#include "PCS_ramDrv.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_ramDevCreate() + * ---------------------------------------------------- + */ +PCS_BLK_DEV *PCS_ramDevCreate(char *ramAddr, int bytesPerSec, int secPerTrack, int nSectors, int secOffset) +{ + UT_GenStub_SetupReturnBuffer(PCS_ramDevCreate, PCS_BLK_DEV *); + + UT_GenStub_AddParam(PCS_ramDevCreate, char *, ramAddr); + UT_GenStub_AddParam(PCS_ramDevCreate, int, bytesPerSec); + UT_GenStub_AddParam(PCS_ramDevCreate, int, secPerTrack); + UT_GenStub_AddParam(PCS_ramDevCreate, int, nSectors); + UT_GenStub_AddParam(PCS_ramDevCreate, int, secOffset); + + UT_GenStub_Execute(PCS_ramDevCreate, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_ramDevCreate, PCS_BLK_DEV *); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_rebootLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_rebootLib_stubs.c new file mode 100644 index 00000000..55eaac85 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_rebootLib_stubs.c @@ -0,0 +1,38 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_rebootLib header + */ + +#include "PCS_rebootLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_reboot() + * ---------------------------------------------------- + */ +void PCS_reboot(int) +{ + UT_GenStub_AddParam(PCS_reboot, , int); + + UT_GenStub_Execute(PCS_reboot, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_spyLibP_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_spyLibP_stubs.c new file mode 100644 index 00000000..bd911111 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_spyLibP_stubs.c @@ -0,0 +1,66 @@ +/************************************************************************ + * 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. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_spyLibP header + */ + +#include "PCS_spyLibP.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_spyClkStartCommon() + * ---------------------------------------------------- + */ +int PCS_spyClkStartCommon(int intsPerSec, PCS_FUNCPTR print) +{ + UT_GenStub_SetupReturnBuffer(PCS_spyClkStartCommon, int); + + 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, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_spyClkStopCommon() + * ---------------------------------------------------- + */ +void PCS_spyClkStopCommon(void) +{ + + UT_GenStub_Execute(PCS_spyClkStopCommon, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_spyReportCommon() + * ---------------------------------------------------- + */ +void PCS_spyReportCommon(PCS_FUNCPTR print) +{ + UT_GenStub_AddParam(PCS_spyReportCommon, PCS_FUNCPTR, print); + + UT_GenStub_Execute(PCS_spyReportCommon, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_spyLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_spyLib_stubs.c new file mode 100644 index 00000000..9fa7fa0b --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_spyLib_stubs.c @@ -0,0 +1,38 @@ +/************************************************************************ + * 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. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in PCS_spyLib header + */ + +#include "PCS_spyLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_spyLibInit() + * ---------------------------------------------------- + */ +void PCS_spyLibInit(int maxTasks) +{ + UT_GenStub_AddParam(PCS_spyLibInit, int, maxTasks); + + UT_GenStub_Execute(PCS_spyLibInit, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c new file mode 100644 index 00000000..18366c19 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_stdio_stubs.c @@ -0,0 +1,218 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_stdio header + */ + +#include + +#include "PCS_stdio.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_fclose() + * ---------------------------------------------------- + */ +int PCS_fclose(PCS_FILE *stream) +{ + UT_GenStub_SetupReturnBuffer(PCS_fclose, int); + + UT_GenStub_AddParam(PCS_fclose, PCS_FILE *, stream); + + UT_GenStub_Execute(PCS_fclose, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_fclose, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_fgets() + * ---------------------------------------------------- + */ +char *PCS_fgets(char *s, int n, PCS_FILE *stream) +{ + UT_GenStub_SetupReturnBuffer(PCS_fgets, char *); + + UT_GenStub_AddParam(PCS_fgets, char *, s); + UT_GenStub_AddParam(PCS_fgets, int, n); + UT_GenStub_AddParam(PCS_fgets, PCS_FILE *, stream); + + UT_GenStub_Execute(PCS_fgets, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_fgets, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_fopen() + * ---------------------------------------------------- + */ +PCS_FILE *PCS_fopen(const char *filename, const char *modes) +{ + UT_GenStub_SetupReturnBuffer(PCS_fopen, PCS_FILE *); + + UT_GenStub_AddParam(PCS_fopen, const char *, filename); + UT_GenStub_AddParam(PCS_fopen, const char *, modes); + + UT_GenStub_Execute(PCS_fopen, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_fopen, PCS_FILE *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_fputs() + * ---------------------------------------------------- + */ +int PCS_fputs(const char *s, PCS_FILE *stream) +{ + UT_GenStub_SetupReturnBuffer(PCS_fputs, int); + + UT_GenStub_AddParam(PCS_fputs, const char *, s); + UT_GenStub_AddParam(PCS_fputs, PCS_FILE *, stream); + + UT_GenStub_Execute(PCS_fputs, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_fputs, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_perror() + * ---------------------------------------------------- + */ +void PCS_perror(const char *str) +{ + UT_GenStub_AddParam(PCS_perror, const char *, str); + + UT_GenStub_Execute(PCS_perror, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_printf() + * ---------------------------------------------------- + */ +int PCS_printf(const char *format, ...) +{ + va_list UtStub_ArgList; + + UT_GenStub_SetupReturnBuffer(PCS_printf, int); + + UT_GenStub_AddParam(PCS_printf, const char *, format); + + va_start(UtStub_ArgList, format); + UT_GenStub_Execute(PCS_printf, Va, NULL, UtStub_ArgList); + va_end(UtStub_ArgList); + + return UT_GenStub_GetReturnValue(PCS_printf, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_putchar() + * ---------------------------------------------------- + */ +int PCS_putchar(int c) +{ + UT_GenStub_SetupReturnBuffer(PCS_putchar, int); + + UT_GenStub_AddParam(PCS_putchar, int, c); + + UT_GenStub_Execute(PCS_putchar, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_putchar, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_remove() + * ---------------------------------------------------- + */ +int PCS_remove(const char *filename) +{ + UT_GenStub_SetupReturnBuffer(PCS_remove, int); + + UT_GenStub_AddParam(PCS_remove, const char *, filename); + + UT_GenStub_Execute(PCS_remove, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_remove, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rename() + * ---------------------------------------------------- + */ +int PCS_rename(const char *old, const char *nw) +{ + UT_GenStub_SetupReturnBuffer(PCS_rename, int); + + UT_GenStub_AddParam(PCS_rename, const char *, old); + UT_GenStub_AddParam(PCS_rename, const char *, nw); + + UT_GenStub_Execute(PCS_rename, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rename, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_snprintf() + * ---------------------------------------------------- + */ +int PCS_snprintf(char *s, size_t maxlen, const char *format, ...) +{ + va_list UtStub_ArgList; + + UT_GenStub_SetupReturnBuffer(PCS_snprintf, int); + + UT_GenStub_AddParam(PCS_snprintf, char *, s); + UT_GenStub_AddParam(PCS_snprintf, size_t, maxlen); + UT_GenStub_AddParam(PCS_snprintf, const char *, format); + + va_start(UtStub_ArgList, format); + UT_GenStub_Execute(PCS_snprintf, Va, NULL, UtStub_ArgList); + va_end(UtStub_ArgList); + + return UT_GenStub_GetReturnValue(PCS_snprintf, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_vsnprintf() + * ---------------------------------------------------- + */ +int PCS_vsnprintf(char *s, size_t maxlen, const char *format, PCS_va_list arg) +{ + UT_GenStub_SetupReturnBuffer(PCS_vsnprintf, int); + + UT_GenStub_AddParam(PCS_vsnprintf, char *, s); + UT_GenStub_AddParam(PCS_vsnprintf, size_t, maxlen); + UT_GenStub_AddParam(PCS_vsnprintf, const char *, format); + UT_GenStub_AddParam(PCS_vsnprintf, PCS_va_list, arg); + + UT_GenStub_Execute(PCS_vsnprintf, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_vsnprintf, int); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c new file mode 100644 index 00000000..096e624f --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_stdlib_stubs.c @@ -0,0 +1,111 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_stdlib header + */ + +#include "PCS_stdlib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_abort() + * ---------------------------------------------------- + */ +void PCS_abort(void) +{ + + UT_GenStub_Execute(PCS_abort, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_exit() + * ---------------------------------------------------- + */ +void PCS_exit(int status) +{ + UT_GenStub_AddParam(PCS_exit, int, status); + + UT_GenStub_Execute(PCS_exit, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_free() + * ---------------------------------------------------- + */ +void PCS_free(void *ptr) +{ + UT_GenStub_AddParam(PCS_free, void *, ptr); + + UT_GenStub_Execute(PCS_free, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_malloc() + * ---------------------------------------------------- + */ +void *PCS_malloc(size_t sz) +{ + UT_GenStub_SetupReturnBuffer(PCS_malloc, void *); + + UT_GenStub_AddParam(PCS_malloc, size_t, sz); + + UT_GenStub_Execute(PCS_malloc, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_malloc, void *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strtoul() + * ---------------------------------------------------- + */ +unsigned long int PCS_strtoul(const char *nptr, char **endptr, int base) +{ + UT_GenStub_SetupReturnBuffer(PCS_strtoul, unsigned long int); + + UT_GenStub_AddParam(PCS_strtoul, const char *, nptr); + UT_GenStub_AddParam(PCS_strtoul, char **, endptr); + UT_GenStub_AddParam(PCS_strtoul, int, base); + + UT_GenStub_Execute(PCS_strtoul, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strtoul, unsigned long int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_system() + * ---------------------------------------------------- + */ +int PCS_system(const char *command) +{ + UT_GenStub_SetupReturnBuffer(PCS_system, int); + + UT_GenStub_AddParam(PCS_system, const char *, command); + + UT_GenStub_Execute(PCS_system, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_system, int); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c new file mode 100644 index 00000000..12d80b0d --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_string_stubs.c @@ -0,0 +1,233 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_string header + */ + +#include "PCS_string.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_memcpy() + * ---------------------------------------------------- + */ +void *PCS_memcpy(void *dest, const void *src, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_memcpy, void *); + + UT_GenStub_AddParam(PCS_memcpy, void *, dest); + UT_GenStub_AddParam(PCS_memcpy, const void *, src); + UT_GenStub_AddParam(PCS_memcpy, size_t, n); + + UT_GenStub_Execute(PCS_memcpy, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_memcpy, void *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_memset() + * ---------------------------------------------------- + */ +void *PCS_memset(void *s, int c, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_memset, void *); + + UT_GenStub_AddParam(PCS_memset, void *, s); + UT_GenStub_AddParam(PCS_memset, int, c); + UT_GenStub_AddParam(PCS_memset, size_t, n); + + UT_GenStub_Execute(PCS_memset, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_memset, void *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strcat() + * ---------------------------------------------------- + */ +char *PCS_strcat(char *dest, const char *src) +{ + UT_GenStub_SetupReturnBuffer(PCS_strcat, char *); + + UT_GenStub_AddParam(PCS_strcat, char *, dest); + UT_GenStub_AddParam(PCS_strcat, const char *, src); + + UT_GenStub_Execute(PCS_strcat, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strcat, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strchr() + * ---------------------------------------------------- + */ +char *PCS_strchr(const char *s, int c) +{ + UT_GenStub_SetupReturnBuffer(PCS_strchr, char *); + + UT_GenStub_AddParam(PCS_strchr, const char *, s); + UT_GenStub_AddParam(PCS_strchr, int, c); + + UT_GenStub_Execute(PCS_strchr, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strchr, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strcmp() + * ---------------------------------------------------- + */ +int PCS_strcmp(const char *s1, const char *s2) +{ + UT_GenStub_SetupReturnBuffer(PCS_strcmp, int); + + UT_GenStub_AddParam(PCS_strcmp, const char *, s1); + UT_GenStub_AddParam(PCS_strcmp, const char *, s2); + + UT_GenStub_Execute(PCS_strcmp, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strcmp, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strcpy() + * ---------------------------------------------------- + */ +char *PCS_strcpy(char *dest, const char *src) +{ + UT_GenStub_SetupReturnBuffer(PCS_strcpy, char *); + + UT_GenStub_AddParam(PCS_strcpy, char *, dest); + UT_GenStub_AddParam(PCS_strcpy, const char *, src); + + UT_GenStub_Execute(PCS_strcpy, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strcpy, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strerror() + * ---------------------------------------------------- + */ +char *PCS_strerror(int errnum) +{ + UT_GenStub_SetupReturnBuffer(PCS_strerror, char *); + + UT_GenStub_AddParam(PCS_strerror, int, errnum); + + UT_GenStub_Execute(PCS_strerror, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strerror, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strlen() + * ---------------------------------------------------- + */ +size_t PCS_strlen(const char *s) +{ + UT_GenStub_SetupReturnBuffer(PCS_strlen, size_t); + + UT_GenStub_AddParam(PCS_strlen, const char *, s); + + UT_GenStub_Execute(PCS_strlen, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strlen, size_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strncat() + * ---------------------------------------------------- + */ +char *PCS_strncat(char *dest, const char *src, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_strncat, char *); + + UT_GenStub_AddParam(PCS_strncat, char *, dest); + UT_GenStub_AddParam(PCS_strncat, const char *, src); + UT_GenStub_AddParam(PCS_strncat, size_t, n); + + UT_GenStub_Execute(PCS_strncat, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strncat, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strncmp() + * ---------------------------------------------------- + */ +int PCS_strncmp(const char *s1, const char *s2, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_strncmp, int); + + UT_GenStub_AddParam(PCS_strncmp, const char *, s1); + UT_GenStub_AddParam(PCS_strncmp, const char *, s2); + UT_GenStub_AddParam(PCS_strncmp, size_t, n); + + UT_GenStub_Execute(PCS_strncmp, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strncmp, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strncpy() + * ---------------------------------------------------- + */ +char *PCS_strncpy(char *dest, const char *src, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_strncpy, char *); + + UT_GenStub_AddParam(PCS_strncpy, char *, dest); + UT_GenStub_AddParam(PCS_strncpy, const char *, src); + UT_GenStub_AddParam(PCS_strncpy, size_t, n); + + UT_GenStub_Execute(PCS_strncpy, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strncpy, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_strrchr() + * ---------------------------------------------------- + */ +char *PCS_strrchr(const char *s, int c) +{ + UT_GenStub_SetupReturnBuffer(PCS_strrchr, char *); + + UT_GenStub_AddParam(PCS_strrchr, const char *, s); + UT_GenStub_AddParam(PCS_strrchr, int, c); + + UT_GenStub_Execute(PCS_strrchr, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_strrchr, char *); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c new file mode 100644 index 00000000..eb4a4ab1 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_sysLib_stubs.c @@ -0,0 +1,134 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_sysLib header + */ + +#include "PCS_sysLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_GetWrsKernelTextEnd() + * ---------------------------------------------------- + */ +unsigned int PCS_GetWrsKernelTextEnd(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_GetWrsKernelTextEnd, unsigned int); + + UT_GenStub_Execute(PCS_GetWrsKernelTextEnd, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_GetWrsKernelTextEnd, unsigned int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_GetWrsKernelTextStart() + * ---------------------------------------------------- + */ +unsigned int PCS_GetWrsKernelTextStart(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_GetWrsKernelTextStart, unsigned int); + + UT_GenStub_Execute(PCS_GetWrsKernelTextStart, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_GetWrsKernelTextStart, unsigned int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_PciOutByte() + * ---------------------------------------------------- + */ +void PCS_PciOutByte(uint32_t address, uint8_t data) +{ + UT_GenStub_AddParam(PCS_PciOutByte, uint32_t, address); + UT_GenStub_AddParam(PCS_PciOutByte, uint8_t, data); + + UT_GenStub_Execute(PCS_PciOutByte, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_PciOutLong() + * ---------------------------------------------------- + */ +void PCS_PciOutLong(uint32_t address, uint32_t data) +{ + UT_GenStub_AddParam(PCS_PciOutLong, uint32_t, address); + UT_GenStub_AddParam(PCS_PciOutLong, uint32_t, data); + + UT_GenStub_Execute(PCS_PciOutLong, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_sysClkRateGet() + * ---------------------------------------------------- + */ +int PCS_sysClkRateGet(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_sysClkRateGet, int); + + UT_GenStub_Execute(PCS_sysClkRateGet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_sysClkRateGet, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_sysMemTop() + * ---------------------------------------------------- + */ +char *PCS_sysMemTop(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_sysMemTop, char *); + + UT_GenStub_Execute(PCS_sysMemTop, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_sysMemTop, char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_sysPciRead32() + * ---------------------------------------------------- + */ +void PCS_sysPciRead32(uint32_t address, uint32_t *data) +{ + UT_GenStub_AddParam(PCS_sysPciRead32, uint32_t, address); + UT_GenStub_AddParam(PCS_sysPciRead32, uint32_t *, data); + + UT_GenStub_Execute(PCS_sysPciRead32, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_sysPciWrite32() + * ---------------------------------------------------- + */ +void PCS_sysPciWrite32(uint32_t address, uint32_t data) +{ + UT_GenStub_AddParam(PCS_sysPciWrite32, uint32_t, address); + UT_GenStub_AddParam(PCS_sysPciWrite32, uint32_t, data); + + UT_GenStub_Execute(PCS_sysPciWrite32, Basic, NULL); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c new file mode 100644 index 00000000..f6725825 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_taskLib_stubs.c @@ -0,0 +1,343 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_taskLib header + */ + +#include "PCS_taskLib.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskActivate() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskActivate(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskActivate, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskActivate, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskActivate, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskActivate, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskDelay() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskDelay(int ticks) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskDelay, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskDelay, int, ticks); + + UT_GenStub_Execute(PCS_taskDelay, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskDelay, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskDelete() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskDelete(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskDelete, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskDelete, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskDelete, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskDelete, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskDeleteForce() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskDeleteForce(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskDeleteForce, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskDeleteForce, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskDeleteForce, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskDeleteForce, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskExit() + * ---------------------------------------------------- + */ +void PCS_taskExit(int code) +{ + UT_GenStub_AddParam(PCS_taskExit, int, code); + + UT_GenStub_Execute(PCS_taskExit, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskGetInfo() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskGetInfo(PCS_TASK_ID task_id, PCS_TASK_DESC *desc) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskGetInfo, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskGetInfo, PCS_TASK_ID, task_id); + UT_GenStub_AddParam(PCS_taskGetInfo, PCS_TASK_DESC *, desc); + + UT_GenStub_Execute(PCS_taskGetInfo, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskGetInfo, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskIdDefault() + * ---------------------------------------------------- + */ +PCS_TASK_ID PCS_taskIdDefault(PCS_TASK_ID task_id) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskIdDefault, PCS_TASK_ID); + + UT_GenStub_AddParam(PCS_taskIdDefault, PCS_TASK_ID, task_id); + + UT_GenStub_Execute(PCS_taskIdDefault, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskIdDefault, PCS_TASK_ID); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskIdSelf() + * ---------------------------------------------------- + */ +PCS_TASK_ID PCS_taskIdSelf(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskIdSelf, PCS_TASK_ID); + + UT_GenStub_Execute(PCS_taskIdSelf, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskIdSelf, PCS_TASK_ID); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskInit() + * ---------------------------------------------------- + */ +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) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskInit, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskInit, PCS_WIND_TCB *, pTcb); + UT_GenStub_AddParam(PCS_taskInit, char *, name); + UT_GenStub_AddParam(PCS_taskInit, int, priority); + UT_GenStub_AddParam(PCS_taskInit, int, options); + UT_GenStub_AddParam(PCS_taskInit, char *, pStackBase); + UT_GenStub_AddParam(PCS_taskInit, int, stackSize); + UT_GenStub_AddParam(PCS_taskInit, PCS_FUNCPTR, entryPt); + UT_GenStub_AddParam(PCS_taskInit, int, arg1); + UT_GenStub_AddParam(PCS_taskInit, int, arg2); + UT_GenStub_AddParam(PCS_taskInit, int, arg3); + UT_GenStub_AddParam(PCS_taskInit, int, arg4); + UT_GenStub_AddParam(PCS_taskInit, int, arg5); + UT_GenStub_AddParam(PCS_taskInit, int, arg6); + UT_GenStub_AddParam(PCS_taskInit, int, arg7); + UT_GenStub_AddParam(PCS_taskInit, int, arg8); + UT_GenStub_AddParam(PCS_taskInit, int, arg9); + UT_GenStub_AddParam(PCS_taskInit, int, arg10); + + UT_GenStub_Execute(PCS_taskInit, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskInit, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskIsReady() + * ---------------------------------------------------- + */ +PCS_BOOL PCS_taskIsReady(PCS_TASK_ID task_id) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskIsReady, PCS_BOOL); + + UT_GenStub_AddParam(PCS_taskIsReady, PCS_TASK_ID, task_id); + + UT_GenStub_Execute(PCS_taskIsReady, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskIsReady, PCS_BOOL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskIsSuspended() + * ---------------------------------------------------- + */ +PCS_BOOL PCS_taskIsSuspended(PCS_TASK_ID task_id) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskIsSuspended, PCS_BOOL); + + UT_GenStub_AddParam(PCS_taskIsSuspended, PCS_TASK_ID, task_id); + + UT_GenStub_Execute(PCS_taskIsSuspended, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskIsSuspended, PCS_BOOL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskName() + * ---------------------------------------------------- + */ +const char *PCS_taskName(PCS_TASK_ID task_id) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskName, const char *); + + UT_GenStub_AddParam(PCS_taskName, PCS_TASK_ID, task_id); + + UT_GenStub_Execute(PCS_taskName, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskName, const char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskNameToId() + * ---------------------------------------------------- + */ +PCS_TASK_ID PCS_taskNameToId(const char *name) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskNameToId, PCS_TASK_ID); + + UT_GenStub_AddParam(PCS_taskNameToId, const char *, name); + + UT_GenStub_Execute(PCS_taskNameToId, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskNameToId, PCS_TASK_ID); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskPrioritySet() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskPrioritySet(PCS_TASK_ID tid, int newPriority) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskPrioritySet, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskPrioritySet, PCS_TASK_ID, tid); + UT_GenStub_AddParam(PCS_taskPrioritySet, int, newPriority); + + UT_GenStub_Execute(PCS_taskPrioritySet, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskPrioritySet, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskResume() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskResume(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskResume, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskResume, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskResume, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskResume, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskSpawn() + * ---------------------------------------------------- + */ +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) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskSpawn, PCS_TASK_ID); + + UT_GenStub_AddParam(PCS_taskSpawn, char *, name); + UT_GenStub_AddParam(PCS_taskSpawn, int, priority); + UT_GenStub_AddParam(PCS_taskSpawn, int, options); + UT_GenStub_AddParam(PCS_taskSpawn, int, stackSize); + UT_GenStub_AddParam(PCS_taskSpawn, PCS_FUNCPTR, entryPt); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg1); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg2); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg3); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg4); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg5); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg6); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg7); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg8); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg9); + UT_GenStub_AddParam(PCS_taskSpawn, int, arg10); + + UT_GenStub_Execute(PCS_taskSpawn, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskSpawn, PCS_TASK_ID); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskSuspend() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_taskSuspend(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskSuspend, PCS_STATUS); + + UT_GenStub_AddParam(PCS_taskSuspend, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskSuspend, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskSuspend, PCS_STATUS); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_taskTcb() + * ---------------------------------------------------- + */ +PCS_WIND_TCB *PCS_taskTcb(PCS_TASK_ID tid) +{ + UT_GenStub_SetupReturnBuffer(PCS_taskTcb, PCS_WIND_TCB *); + + UT_GenStub_AddParam(PCS_taskTcb, PCS_TASK_ID, tid); + + UT_GenStub_Execute(PCS_taskTcb, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_taskTcb, PCS_WIND_TCB *); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c new file mode 100644 index 00000000..8927c896 --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_unistd_stubs.c @@ -0,0 +1,201 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_unistd header + */ + +#include "PCS_unistd.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_close() + * ---------------------------------------------------- + */ +int PCS_close(int fd) +{ + UT_GenStub_SetupReturnBuffer(PCS_close, int); + + UT_GenStub_AddParam(PCS_close, int, fd); + + UT_GenStub_Execute(PCS_close, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_close, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_getegid() + * ---------------------------------------------------- + */ +PCS_gid_t PCS_getegid(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_getegid, PCS_gid_t); + + UT_GenStub_Execute(PCS_getegid, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_getegid, PCS_gid_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_geteuid() + * ---------------------------------------------------- + */ +PCS_uid_t PCS_geteuid(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_geteuid, PCS_uid_t); + + UT_GenStub_Execute(PCS_geteuid, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_geteuid, PCS_uid_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_gethostid() + * ---------------------------------------------------- + */ +long int PCS_gethostid(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_gethostid, long int); + + UT_GenStub_Execute(PCS_gethostid, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_gethostid, long int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_gethostname() + * ---------------------------------------------------- + */ +int PCS_gethostname(char *name, size_t len) +{ + UT_GenStub_SetupReturnBuffer(PCS_gethostname, int); + + UT_GenStub_AddParam(PCS_gethostname, char *, name); + UT_GenStub_AddParam(PCS_gethostname, size_t, len); + + UT_GenStub_Execute(PCS_gethostname, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_gethostname, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_getpid() + * ---------------------------------------------------- + */ +PCS_pid_t PCS_getpid(void) +{ + UT_GenStub_SetupReturnBuffer(PCS_getpid, PCS_pid_t); + + UT_GenStub_Execute(PCS_getpid, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_getpid, PCS_pid_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_lseek() + * ---------------------------------------------------- + */ +PCS_off_t PCS_lseek(int fd, PCS_off_t offset, int whence) +{ + UT_GenStub_SetupReturnBuffer(PCS_lseek, PCS_off_t); + + UT_GenStub_AddParam(PCS_lseek, int, fd); + UT_GenStub_AddParam(PCS_lseek, PCS_off_t, offset); + UT_GenStub_AddParam(PCS_lseek, int, whence); + + UT_GenStub_Execute(PCS_lseek, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_lseek, PCS_off_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_read() + * ---------------------------------------------------- + */ +PCS_ssize_t PCS_read(int fd, void *buf, size_t nbytes) +{ + UT_GenStub_SetupReturnBuffer(PCS_read, PCS_ssize_t); + + UT_GenStub_AddParam(PCS_read, int, fd); + UT_GenStub_AddParam(PCS_read, void *, buf); + UT_GenStub_AddParam(PCS_read, size_t, nbytes); + + UT_GenStub_Execute(PCS_read, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_read, PCS_ssize_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_rmdir() + * ---------------------------------------------------- + */ +int PCS_rmdir(const char *path) +{ + UT_GenStub_SetupReturnBuffer(PCS_rmdir, int); + + UT_GenStub_AddParam(PCS_rmdir, const char *, path); + + UT_GenStub_Execute(PCS_rmdir, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_rmdir, int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_sysconf() + * ---------------------------------------------------- + */ +long int PCS_sysconf(int name) +{ + UT_GenStub_SetupReturnBuffer(PCS_sysconf, long int); + + UT_GenStub_AddParam(PCS_sysconf, int, name); + + UT_GenStub_Execute(PCS_sysconf, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_sysconf, long int); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_write() + * ---------------------------------------------------- + */ +PCS_ssize_t PCS_write(int fd, const void *buf, size_t n) +{ + UT_GenStub_SetupReturnBuffer(PCS_write, PCS_ssize_t); + + UT_GenStub_AddParam(PCS_write, int, fd); + UT_GenStub_AddParam(PCS_write, const void *, buf); + UT_GenStub_AddParam(PCS_write, size_t, n); + + UT_GenStub_Execute(PCS_write, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_write, PCS_ssize_t); +} diff --git a/unit-test-coverage/ut-stubs/src/PCS_xbdBlkDev_stubs.c b/unit-test-coverage/ut-stubs/src/PCS_xbdBlkDev_stubs.c new file mode 100644 index 00000000..75dc467a --- /dev/null +++ b/unit-test-coverage/ut-stubs/src/PCS_xbdBlkDev_stubs.c @@ -0,0 +1,60 @@ +/************************************************************************ + * 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 + * + * Auto-Generated stub implementations for functions defined in PCS_xbdBlkDev header + */ + +#include "PCS_xbdBlkDev.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_xbdBlkDevCreateSync() + * ---------------------------------------------------- + */ +PCS_device_t PCS_xbdBlkDevCreateSync(PCS_BLK_DEV *bd, const char *name) +{ + UT_GenStub_SetupReturnBuffer(PCS_xbdBlkDevCreateSync, PCS_device_t); + + UT_GenStub_AddParam(PCS_xbdBlkDevCreateSync, PCS_BLK_DEV *, bd); + UT_GenStub_AddParam(PCS_xbdBlkDevCreateSync, const char *, name); + + UT_GenStub_Execute(PCS_xbdBlkDevCreateSync, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_xbdBlkDevCreateSync, PCS_device_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for PCS_xbdBlkDevDelete() + * ---------------------------------------------------- + */ +PCS_STATUS PCS_xbdBlkDevDelete(PCS_device_t dev, PCS_BLK_DEV **ppbd) +{ + UT_GenStub_SetupReturnBuffer(PCS_xbdBlkDevDelete, PCS_STATUS); + + UT_GenStub_AddParam(PCS_xbdBlkDevDelete, PCS_device_t, dev); + UT_GenStub_AddParam(PCS_xbdBlkDevDelete, PCS_BLK_DEV **, ppbd); + + UT_GenStub_Execute(PCS_xbdBlkDevDelete, Basic, NULL); + + return UT_GenStub_GetReturnValue(PCS_xbdBlkDevDelete, PCS_STATUS); +} diff --git a/ut-stubs/CMakeLists.txt b/ut-stubs/CMakeLists.txt index 6dd8700e..6cc170c0 100644 --- a/ut-stubs/CMakeLists.txt +++ b/ut-stubs/CMakeLists.txt @@ -4,7 +4,9 @@ add_library(ut_psp_api_stubs + src/cfe_psp_cache_api_handlers.c src/cfe_psp_cache_api_stubs.c + src/cfe_psp_cds_api_handlers.c src/cfe_psp_cds_api_stubs.c src/cfe_psp_eepromaccess_api_stubs.c src/cfe_psp_error_stubs.c diff --git a/ut-stubs/src/cfe_psp_cache_api_handlers.c b/ut-stubs/src/cfe_psp_cache_api_handlers.c new file mode 100644 index 00000000..398c147c --- /dev/null +++ b/ut-stubs/src/cfe_psp_cache_api_handlers.c @@ -0,0 +1,42 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +/* +** Functions +*/ diff --git a/ut-stubs/src/cfe_psp_cds_api_handlers.c b/ut-stubs/src/cfe_psp_cds_api_handlers.c new file mode 100644 index 00000000..0cfc4970 --- /dev/null +++ b/ut-stubs/src/cfe_psp_cds_api_handlers.c @@ -0,0 +1,154 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + + +/* +** Functions +*/ + + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either OS_SUCCESS, OS_ERROR, or a user-defined value. +** +******************************************************************************/ +void UT_DefaultHandler_CFE_PSP_WriteToCDS(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_WriteToCDS(const void *PtrToDataToWrite, uint32 CDSOffset, uint32 NumBytes) */ + const void *PtrToDataToWrite = UT_Hook_GetArgValueByName(Context, "PtrToDataToWrite", const void *); + uint32 CDSOffset = UT_Hook_GetArgValueByName(Context, "CDSOffset", uint32 ); + uint32 NumBytes = UT_Hook_GetArgValueByName(Context, "NumBytes", uint32 ); + + uint8 *BufPtr; + size_t CdsSize; + size_t Position; + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + 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); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_ReadFromCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_ReadFromCDS. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either OS_SUCCESS, OS_ERROR, or a user-defined value. +** +******************************************************************************/ +void UT_DefaultHandler_CFE_PSP_ReadFromCDS(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_ReadFromCDS(void *PtrToDataToRead, uint32 CDSOffset, uint32 NumBytes) */ + void *PtrToDataToRead = UT_Hook_GetArgValueByName(Context, "PtrToDataToRead", void *); + uint32 CDSOffset = UT_Hook_GetArgValueByName(Context, "CDSOffset", uint32 ); + uint32 NumBytes = UT_Hook_GetArgValueByName(Context, "NumBytes", uint32 ); + + uint8 *BufPtr; + size_t CdsSize; + size_t Position; + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + 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); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_GetCDSSize stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetCDSSize. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either OS_SUCCESS or OS_ERROR. +** +******************************************************************************/ +void UT_DefaultHandler_CFE_PSP_GetCDSSize(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + /* int32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS) */ + uint32 *SizeOfCDS = UT_Hook_GetArgValueByName(Context, "SizeOfCDS", uint32 *); + + int32 status; + size_t TempSize; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetCDSSize), NULL, &TempSize, NULL); + *SizeOfCDS = TempSize; + } +} diff --git a/ut-stubs/src/cfe_psp_eepromaccess_api_handlers.c b/ut-stubs/src/cfe_psp_eepromaccess_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_eepromaccess_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_error_handlers.c b/ut-stubs/src/cfe_psp_error_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_error_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_exception_api_handlers.c b/ut-stubs/src/cfe_psp_exception_api_handlers.c new file mode 100644 index 00000000..a1089a47 --- /dev/null +++ b/ut-stubs/src/cfe_psp_exception_api_handlers.c @@ -0,0 +1,356 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + + +/* +** 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. +** +** \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_GetVolatileDiskMem stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetVolatileDiskMem. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + + +/*****************************************************************************/ +/** +** \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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_globaldata_handlers.c b/ut-stubs/src/cfe_psp_globaldata_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_globaldata_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_handlers.c b/ut-stubs/src/cfe_psp_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_id_api_handlers.c b/ut-stubs/src/cfe_psp_id_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_id_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} 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..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_memaccess_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_memrange_api_handlers.c b/ut-stubs/src/cfe_psp_memrange_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_memrange_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_port_api_handlers.c b/ut-stubs/src/cfe_psp_port_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_port_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_ssr_api_handlers.c b/ut-stubs/src/cfe_psp_ssr_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_ssr_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_timertick_api_handlers.c b/ut-stubs/src/cfe_psp_timertick_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_timertick_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_version_api_handlers.c b/ut-stubs/src/cfe_psp_version_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_version_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +} diff --git a/ut-stubs/src/cfe_psp_watchdog_api_handlers.c b/ut-stubs/src/cfe_psp_watchdog_api_handlers.c new file mode 100644 index 00000000..2e65ea2b --- /dev/null +++ b/ut-stubs/src/cfe_psp_watchdog_api_handlers.c @@ -0,0 +1,831 @@ +/************************************************************************ + * 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 + +#include "target_config.h" + +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}; + +/* +** 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. +** +** \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; +} + +/*****************************************************************************/ +/** +** \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 = OS_TimeAssembleFromNanoseconds(100, 200000); + } + } +} + +/*****************************************************************************/ +/** +** \brief CFE_PSP_WriteToCDS stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_WriteToCDS. +** +** \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. +** +** \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. +** +** \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. +** +** \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. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** This function does not return a value. +** +******************************************************************************/ +void CFE_PSP_Restart(uint32 resetType) +{ + UT_DEFAULT_IMPL(CFE_PSP_Restart); + UT_Stub_CopyFromLocal(UT_KEY(CFE_PSP_Restart), (uint8 *)&resetType, sizeof(resetType)); +} + +/*****************************************************************************/ +/** +** \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 (TempAddr == NULL) + { + /* 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_GetKernelTextSegmentInfo stub function +** +** \par Description +** This function is used to mimic the response of the PSP function +** CFE_PSP_GetKernelTextSegmentInfo. The user can adjust the response by +** setting the values in the BSPGetCFETextRtn structure prior to this +** function being called. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns either a user-defined status flag or OS_SUCCESS. +** +******************************************************************************/ +int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment) +{ + static uint32 LocalTextSegment; + int32 status; + void * TempAddr; + size_t TempSize; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetKernelTextSegmentInfo); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetKernelTextSegmentInfo), &TempAddr, &TempSize, NULL); + if (TempAddr == NULL) + { + /* Backup -- Set the pointer and size to anything */ + *PtrToKernelSegment = (cpuaddr)&LocalTextSegment; + *SizeOfKernelSegment = sizeof(LocalTextSegment); + } + else + { + *PtrToKernelSegment = (cpuaddr)TempAddr; + *SizeOfKernelSegment = 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, size_t 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 *dest, const void *src, uint32 n) +{ + 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(dest, src, n); + } + + 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 *dest, uint8 value, uint32 n) +{ + 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(dest, (int)value, (size_t)n); + } + + 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; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *CFE_PSP_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void * Buffer; + const char * RetVal; + + UT_GetDataBuffer(UT_KEY(CFE_PSP_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void CFE_PSP_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_PSP_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 CFE_PSP_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_PSP_GetBuildNumber); + + return status; +}