diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index 1e9eefbba..0e8ea53c8 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -9,33 +9,91 @@ # provide "stub" versions of all calls in the OSAL public API. # +set(OSAL_PUBLIC_API_HEADERS + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-binsem.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-bsp.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-clock.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-common.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-constants.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-countsem.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-dir.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-error.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-file.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-filesys.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-heap.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-idmap.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-macros.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-module.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-mutex.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-network.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-printf.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-queue.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-select.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-shell.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-sockets.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-task.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-timebase.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-timer.h + ${OSAL_SOURCE_DIR}/src/os/inc/osapi-version.h +) + +# The following target rule contains the specific commands required +# to auto-generate the stub implementations from the headers +add_custom_target(generate_osapi_stubs + COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl + ${CMAKE_CURRENT_SOURCE_DIR} + ${OSAL_PUBLIC_API_HEADERS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM +) + + # NOTE: There is no separate public include directory for the stubs. # By definition, the stubs must implement the same public API that the # normal OSAL library implements. Therefore, only the standard OSAL # header files are used. add_library(ut_osapi_stubs STATIC utstub-helpers.c - osapi-utstub-binsem.c - osapi-utstub-clock.c - osapi-utstub-common.c - osapi-utstub-countsem.c - osapi-utstub-dir.c - osapi-utstub-errors.c - osapi-utstub-file.c - osapi-utstub-filesys.c - osapi-utstub-heap.c - osapi-utstub-idmap.c - osapi-utstub-module.c - osapi-utstub-mutex.c - osapi-utstub-network.c - osapi-utstub-printf.c - osapi-utstub-queue.c - osapi-utstub-select.c - osapi-utstub-sockets.c - osapi-utstub-task.c - osapi-utstub-time.c - osapi-utstub-timebase.c - osapi-utstub-version.c + osapi-binsem-stubs.c + osapi-binsem-hooks.c + osapi-clock-stubs.c + osapi-clock-hooks.c + osapi-common-stubs.c + osapi-countsem-stubs.c + osapi-countsem-hooks.c + osapi-dir-stubs.c + osapi-dir-hooks.c + osapi-error-stubs.c + osapi-error-hooks.c + osapi-file-stubs.c + osapi-file-hooks.c + osapi-filesys-stubs.c + osapi-filesys-hooks.c + osapi-heap-stubs.c + osapi-heap-hooks.c + osapi-idmap-stubs.c + osapi-idmap-hooks.c + osapi-module-stubs.c + osapi-module-hooks.c + osapi-mutex-stubs.c + osapi-mutex-hooks.c + osapi-network-stubs.c + osapi-network-hooks.c + osapi-printf-stubs.c + osapi-printf-hooks.c + osapi-queue-stubs.c + osapi-queue-hooks.c + osapi-select-stubs.c + osapi-sockets-stubs.c + osapi-sockets-hooks.c + osapi-task-stubs.c + osapi-task-hooks.c + osapi-timer-stubs.c + osapi-timer-hooks.c + osapi-timebase-stubs.c + osapi-timebase-hooks.c + osapi-version-stubs.c + osapi-version-hooks.c ) # Some of the internal API definitions in stubs are based on diff --git a/src/ut-stubs/osapi-binsem-hooks.c b/src/ut-stubs/osapi-binsem-hooks.c new file mode 100644 index 000000000..afdf6347e --- /dev/null +++ b/src/ut-stubs/osapi-binsem-hooks.c @@ -0,0 +1,114 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-binsem.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_BinSemCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_BinSemCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_BINSEM); + } + else + { + *sem_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_BinSemGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_BinSemGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_bin_sem_prop_t *bin_prop = UT_Hook_GetArgValueByName(Context, "bin_prop", OS_bin_sem_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetInfo), bin_prop, sizeof(*bin_prop)) < sizeof(*bin_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &bin_prop->creator); + strncpy(bin_prop->name, "Name", sizeof(bin_prop->name) - 1); + bin_prop->name[sizeof(bin_prop->name) - 1] = '\0'; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_BinSemDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_BinSemDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_BINSEM, sem_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_BinSemGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_BinSemGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_BINSEM, sem_id); + } +} diff --git a/src/ut-stubs/osapi-binsem-stubs.c b/src/ut-stubs/osapi-binsem-stubs.c new file mode 100644 index 000000000..21061a7b1 --- /dev/null +++ b/src/ut-stubs/osapi-binsem-stubs.c @@ -0,0 +1,167 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-binsem header + */ + +#include "osapi-binsem.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_BinSemCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_BinSemDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_BinSemGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_BinSemGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemCreate() + * ---------------------------------------------------- + */ +int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemCreate, int32); + + UT_GenStub_AddParam(OS_BinSemCreate, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_BinSemCreate, const char *, sem_name); + UT_GenStub_AddParam(OS_BinSemCreate, uint32, sem_initial_value); + UT_GenStub_AddParam(OS_BinSemCreate, uint32, options); + + UT_GenStub_Execute(OS_BinSemCreate, Basic, UT_DefaultHandler_OS_BinSemCreate); + + return UT_GenStub_GetReturnValue(OS_BinSemCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemDelete() + * ---------------------------------------------------- + */ +int32 OS_BinSemDelete(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemDelete, int32); + + UT_GenStub_AddParam(OS_BinSemDelete, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_BinSemDelete, Basic, UT_DefaultHandler_OS_BinSemDelete); + + return UT_GenStub_GetReturnValue(OS_BinSemDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemFlush() + * ---------------------------------------------------- + */ +int32 OS_BinSemFlush(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemFlush, int32); + + UT_GenStub_AddParam(OS_BinSemFlush, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_BinSemFlush, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemFlush, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemGetIdByName, int32); + + UT_GenStub_AddParam(OS_BinSemGetIdByName, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_BinSemGetIdByName, const char *, sem_name); + + UT_GenStub_Execute(OS_BinSemGetIdByName, Basic, UT_DefaultHandler_OS_BinSemGetIdByName); + + return UT_GenStub_GetReturnValue(OS_BinSemGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemGetInfo() + * ---------------------------------------------------- + */ +int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemGetInfo, int32); + + UT_GenStub_AddParam(OS_BinSemGetInfo, osal_id_t, sem_id); + UT_GenStub_AddParam(OS_BinSemGetInfo, OS_bin_sem_prop_t *, bin_prop); + + UT_GenStub_Execute(OS_BinSemGetInfo, Basic, UT_DefaultHandler_OS_BinSemGetInfo); + + return UT_GenStub_GetReturnValue(OS_BinSemGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemGive() + * ---------------------------------------------------- + */ +int32 OS_BinSemGive(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemGive, int32); + + UT_GenStub_AddParam(OS_BinSemGive, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_BinSemGive, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemGive, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemTake() + * ---------------------------------------------------- + */ +int32 OS_BinSemTake(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemTake, int32); + + UT_GenStub_AddParam(OS_BinSemTake, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_BinSemTake, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemTake, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemTimedWait() + * ---------------------------------------------------- + */ +int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemTimedWait, int32); + + UT_GenStub_AddParam(OS_BinSemTimedWait, osal_id_t, sem_id); + UT_GenStub_AddParam(OS_BinSemTimedWait, uint32, msecs); + + UT_GenStub_Execute(OS_BinSemTimedWait, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemTimedWait, int32); +} diff --git a/src/ut-stubs/osapi-utstub-clock.c b/src/ut-stubs/osapi-clock-hooks.c similarity index 57% rename from src/ut-stubs/osapi-utstub-clock.c rename to src/ut-stubs/osapi-clock-hooks.c index b13ce4798..1b607a8e4 100644 --- a/src/ut-stubs/osapi-utstub-clock.c +++ b/src/ut-stubs/osapi-clock-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,44 +33,42 @@ #include "osapi-clock.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -/***************************************************************************** - * - * Stub function for OS_GetLocalTime() - * - *****************************************************************************/ -int32 OS_GetLocalTime(OS_time_t *time_struct) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetLocalTime' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetLocalTime(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_Stub_RegisterContext(UT_KEY(OS_GetLocalTime), time_struct); + OS_time_t *time_struct = UT_Hook_GetArgValueByName(Context, "time_struct", OS_time_t *); + uint32 count = UT_GetStubCount(FuncKey); + int32 status; - int32 status; - uint32 count; - - status = UT_DEFAULT_IMPL(OS_GetLocalTime); + UT_Stub_GetInt32StatusCode(Context, &status); if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_GetLocalTime), time_struct, sizeof(*time_struct)) < sizeof(*time_struct)) { - count = UT_GetStubCount(UT_KEY(OS_GetLocalTime)); *time_struct = OS_TimeAssembleFromNanoseconds(1 + (count / 100), 10000000 * (count % 100)); } - return status; - } /* end OS_GetLocalTime */ -/***************************************************************************** - * - * Stub function for OS_SetLocalTime() - * - *****************************************************************************/ -int32 OS_SetLocalTime(const OS_time_t *time_struct) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SetLocalTime' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SetLocalTime(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_Stub_RegisterContext(UT_KEY(OS_SetLocalTime), time_struct); + const OS_time_t *time_struct = UT_Hook_GetArgValueByName(Context, "time_struct", const OS_time_t *); + int32 status; - int32 status; + UT_Stub_GetInt32StatusCode(Context, &status); - status = UT_DEFAULT_IMPL(OS_SetLocalTime); - - return status; + if (status == OS_SUCCESS) + { + UT_Stub_CopyFromLocal(UT_KEY(OS_SetLocalTime), time_struct, sizeof(*time_struct)); + } } /*end OS_SetLocalTime */ diff --git a/src/ut-stubs/osapi-clock-stubs.c b/src/ut-stubs/osapi-clock-stubs.c new file mode 100644 index 000000000..57bb3a6e7 --- /dev/null +++ b/src/ut-stubs/osapi-clock-stubs.c @@ -0,0 +1,63 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-clock header + */ + +#include "osapi-clock.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_GetLocalTime(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SetLocalTime(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetLocalTime() + * ---------------------------------------------------- + */ +int32 OS_GetLocalTime(OS_time_t *time_struct) +{ + UT_GenStub_SetupReturnBuffer(OS_GetLocalTime, int32); + + UT_GenStub_AddParam(OS_GetLocalTime, OS_time_t *, time_struct); + + UT_GenStub_Execute(OS_GetLocalTime, Basic, UT_DefaultHandler_OS_GetLocalTime); + + return UT_GenStub_GetReturnValue(OS_GetLocalTime, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SetLocalTime() + * ---------------------------------------------------- + */ +int32 OS_SetLocalTime(const OS_time_t *time_struct) +{ + UT_GenStub_SetupReturnBuffer(OS_SetLocalTime, int32); + + UT_GenStub_AddParam(OS_SetLocalTime, const OS_time_t *, time_struct); + + UT_GenStub_Execute(OS_SetLocalTime, Basic, UT_DefaultHandler_OS_SetLocalTime); + + return UT_GenStub_GetReturnValue(OS_SetLocalTime, int32); +} diff --git a/src/ut-stubs/osapi-common-stubs.c b/src/ut-stubs/osapi-common-stubs.c new file mode 100644 index 000000000..2c743f5ee --- /dev/null +++ b/src/ut-stubs/osapi-common-stubs.c @@ -0,0 +1,115 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-common header + */ + +#include "osapi-common.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_API_Init() + * ---------------------------------------------------- + */ +int32 OS_API_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_API_Init, int32); + + UT_GenStub_Execute(OS_API_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_API_Init, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_API_Teardown() + * ---------------------------------------------------- + */ +void OS_API_Teardown(void) +{ + + UT_GenStub_Execute(OS_API_Teardown, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ApplicationExit() + * ---------------------------------------------------- + */ +void OS_ApplicationExit(int32 Status) +{ + UT_GenStub_AddParam(OS_ApplicationExit, int32, Status); + + UT_GenStub_Execute(OS_ApplicationExit, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ApplicationShutdown() + * ---------------------------------------------------- + */ +void OS_ApplicationShutdown(uint8 flag) +{ + UT_GenStub_AddParam(OS_ApplicationShutdown, uint8, flag); + + UT_GenStub_Execute(OS_ApplicationShutdown, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DeleteAllObjects() + * ---------------------------------------------------- + */ +void OS_DeleteAllObjects(void) +{ + + UT_GenStub_Execute(OS_DeleteAllObjects, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_IdleLoop() + * ---------------------------------------------------- + */ +void OS_IdleLoop(void) +{ + + UT_GenStub_Execute(OS_IdleLoop, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_RegisterEventHandler() + * ---------------------------------------------------- + */ +int32 OS_RegisterEventHandler(OS_EventHandler_t handler) +{ + UT_GenStub_SetupReturnBuffer(OS_RegisterEventHandler, int32); + + UT_GenStub_AddParam(OS_RegisterEventHandler, OS_EventHandler_t, handler); + + UT_GenStub_Execute(OS_RegisterEventHandler, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_RegisterEventHandler, int32); +} diff --git a/src/ut-stubs/osapi-countsem-hooks.c b/src/ut-stubs/osapi-countsem-hooks.c new file mode 100644 index 000000000..970e9d247 --- /dev/null +++ b/src/ut-stubs/osapi-countsem-hooks.c @@ -0,0 +1,114 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-countsem.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_CountSemCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_CountSemCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM); + } + else + { + *sem_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_CountSemDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_CountSemDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_CountSemGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_CountSemGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_CountSemGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_CountSemGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_count_sem_prop_t *count_prop = UT_Hook_GetArgValueByName(Context, "count_prop", OS_count_sem_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetInfo), count_prop, sizeof(*count_prop)) < sizeof(*count_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &count_prop->creator); + strncpy(count_prop->name, "Name", sizeof(count_prop->name) - 1); + count_prop->name[sizeof(count_prop->name) - 1] = '\0'; + } +} diff --git a/src/ut-stubs/osapi-countsem-stubs.c b/src/ut-stubs/osapi-countsem-stubs.c new file mode 100644 index 000000000..4e1ca8aa0 --- /dev/null +++ b/src/ut-stubs/osapi-countsem-stubs.c @@ -0,0 +1,151 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-countsem header + */ + +#include "osapi-countsem.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_CountSemCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_CountSemDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_CountSemGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_CountSemGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemCreate() + * ---------------------------------------------------- + */ +int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemCreate, int32); + + UT_GenStub_AddParam(OS_CountSemCreate, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_CountSemCreate, const char *, sem_name); + UT_GenStub_AddParam(OS_CountSemCreate, uint32, sem_initial_value); + UT_GenStub_AddParam(OS_CountSemCreate, uint32, options); + + UT_GenStub_Execute(OS_CountSemCreate, Basic, UT_DefaultHandler_OS_CountSemCreate); + + return UT_GenStub_GetReturnValue(OS_CountSemCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemDelete() + * ---------------------------------------------------- + */ +int32 OS_CountSemDelete(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemDelete, int32); + + UT_GenStub_AddParam(OS_CountSemDelete, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_CountSemDelete, Basic, UT_DefaultHandler_OS_CountSemDelete); + + return UT_GenStub_GetReturnValue(OS_CountSemDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemGetIdByName, int32); + + UT_GenStub_AddParam(OS_CountSemGetIdByName, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_CountSemGetIdByName, const char *, sem_name); + + UT_GenStub_Execute(OS_CountSemGetIdByName, Basic, UT_DefaultHandler_OS_CountSemGetIdByName); + + return UT_GenStub_GetReturnValue(OS_CountSemGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemGetInfo() + * ---------------------------------------------------- + */ +int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemGetInfo, int32); + + UT_GenStub_AddParam(OS_CountSemGetInfo, osal_id_t, sem_id); + UT_GenStub_AddParam(OS_CountSemGetInfo, OS_count_sem_prop_t *, count_prop); + + UT_GenStub_Execute(OS_CountSemGetInfo, Basic, UT_DefaultHandler_OS_CountSemGetInfo); + + return UT_GenStub_GetReturnValue(OS_CountSemGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemGive() + * ---------------------------------------------------- + */ +int32 OS_CountSemGive(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemGive, int32); + + UT_GenStub_AddParam(OS_CountSemGive, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_CountSemGive, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemGive, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemTake() + * ---------------------------------------------------- + */ +int32 OS_CountSemTake(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemTake, int32); + + UT_GenStub_AddParam(OS_CountSemTake, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_CountSemTake, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemTake, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemTimedWait() + * ---------------------------------------------------- + */ +int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemTimedWait, int32); + + UT_GenStub_AddParam(OS_CountSemTimedWait, osal_id_t, sem_id); + UT_GenStub_AddParam(OS_CountSemTimedWait, uint32, msecs); + + UT_GenStub_Execute(OS_CountSemTimedWait, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemTimedWait, int32); +} diff --git a/src/ut-stubs/osapi-dir-hooks.c b/src/ut-stubs/osapi-dir-hooks.c new file mode 100644 index 000000000..1f5760c88 --- /dev/null +++ b/src/ut-stubs/osapi-dir-hooks.c @@ -0,0 +1,97 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-dir.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_DirectoryOpen' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_DirectoryOpen(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *dir_id = UT_Hook_GetArgValueByName(Context, "dir_id", osal_id_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS) + { + *dir_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_DIR); + } + else + { + *dir_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_DirectoryClose' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_DirectoryClose(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t dir_id = UT_Hook_GetArgValueByName(Context, "dir_id", osal_id_t); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_DIR, dir_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_DirectoryRead' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_DirectoryRead(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + os_dirent_t *dirent = UT_Hook_GetArgValueByName(Context, "dirent", os_dirent_t *); + int32 Status; + size_t CopySize; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS) + { + CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_DirectoryRead), dirent, sizeof(*dirent)); + if (CopySize < sizeof(*dirent)) + { + memset(dirent, 0, sizeof(*dirent)); + } + } +} diff --git a/src/ut-stubs/osapi-dir-stubs.c b/src/ut-stubs/osapi-dir-stubs.c new file mode 100644 index 000000000..8fe3004c5 --- /dev/null +++ b/src/ut-stubs/osapi-dir-stubs.c @@ -0,0 +1,131 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-dir header + */ + +#include "osapi-dir.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_DirectoryClose(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_DirectoryOpen(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_DirectoryRead(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirectoryClose() + * ---------------------------------------------------- + */ +int32 OS_DirectoryClose(osal_id_t dir_id) +{ + UT_GenStub_SetupReturnBuffer(OS_DirectoryClose, int32); + + UT_GenStub_AddParam(OS_DirectoryClose, osal_id_t, dir_id); + + UT_GenStub_Execute(OS_DirectoryClose, Basic, UT_DefaultHandler_OS_DirectoryClose); + + return UT_GenStub_GetReturnValue(OS_DirectoryClose, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirectoryOpen() + * ---------------------------------------------------- + */ +int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) +{ + UT_GenStub_SetupReturnBuffer(OS_DirectoryOpen, int32); + + UT_GenStub_AddParam(OS_DirectoryOpen, osal_id_t *, dir_id); + UT_GenStub_AddParam(OS_DirectoryOpen, const char *, path); + + UT_GenStub_Execute(OS_DirectoryOpen, Basic, UT_DefaultHandler_OS_DirectoryOpen); + + return UT_GenStub_GetReturnValue(OS_DirectoryOpen, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirectoryRead() + * ---------------------------------------------------- + */ +int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) +{ + UT_GenStub_SetupReturnBuffer(OS_DirectoryRead, int32); + + UT_GenStub_AddParam(OS_DirectoryRead, osal_id_t, dir_id); + UT_GenStub_AddParam(OS_DirectoryRead, os_dirent_t *, dirent); + + UT_GenStub_Execute(OS_DirectoryRead, Basic, UT_DefaultHandler_OS_DirectoryRead); + + return UT_GenStub_GetReturnValue(OS_DirectoryRead, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirectoryRewind() + * ---------------------------------------------------- + */ +int32 OS_DirectoryRewind(osal_id_t dir_id) +{ + UT_GenStub_SetupReturnBuffer(OS_DirectoryRewind, int32); + + UT_GenStub_AddParam(OS_DirectoryRewind, osal_id_t, dir_id); + + UT_GenStub_Execute(OS_DirectoryRewind, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirectoryRewind, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_mkdir() + * ---------------------------------------------------- + */ +int32 OS_mkdir(const char *path, uint32 access) +{ + UT_GenStub_SetupReturnBuffer(OS_mkdir, int32); + + UT_GenStub_AddParam(OS_mkdir, const char *, path); + UT_GenStub_AddParam(OS_mkdir, uint32, access); + + UT_GenStub_Execute(OS_mkdir, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_mkdir, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_rmdir() + * ---------------------------------------------------- + */ +int32 OS_rmdir(const char *path) +{ + UT_GenStub_SetupReturnBuffer(OS_rmdir, int32); + + UT_GenStub_AddParam(OS_rmdir, const char *, path); + + UT_GenStub_Execute(OS_rmdir, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_rmdir, int32); +} diff --git a/src/ut-stubs/osapi-utstub-errors.c b/src/ut-stubs/osapi-error-hooks.c similarity index 71% rename from src/ut-stubs/osapi-utstub-errors.c rename to src/ut-stubs/osapi-error-hooks.c index 151b44cc4..c36746876 100644 --- a/src/ut-stubs/osapi-utstub-errors.c +++ b/src/ut-stubs/osapi-error-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,19 +33,21 @@ #include "osapi-error.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetErrorName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetErrorName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_GetErrorName), error_num); - UT_Stub_RegisterContext(UT_KEY(OS_GetErrorName), err_name); + int32 error_num = UT_Hook_GetArgValueByName(Context, "error_num", int32); + os_err_name_t *err_name = UT_Hook_GetArgValueByName(Context, "err_name", os_err_name_t *); + int32 status; - int32 status; - - status = UT_DEFAULT_IMPL(OS_GetErrorName); + UT_Stub_GetInt32StatusCode(Context, &status); if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_GetErrorName), *err_name, sizeof(*err_name)) == 0) { snprintf(*err_name, sizeof(*err_name), "ut%d", (int)error_num); } - - return status; } diff --git a/src/ut-stubs/osapi-error-stubs.c b/src/ut-stubs/osapi-error-stubs.c new file mode 100644 index 000000000..c2245cf82 --- /dev/null +++ b/src/ut-stubs/osapi-error-stubs.c @@ -0,0 +1,47 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-error header + */ + +#include "osapi-error.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_GetErrorName(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetErrorName() + * ---------------------------------------------------- + */ +int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name) +{ + UT_GenStub_SetupReturnBuffer(OS_GetErrorName, int32); + + UT_GenStub_AddParam(OS_GetErrorName, int32, error_num); + UT_GenStub_AddParam(OS_GetErrorName, os_err_name_t *, err_name); + + UT_GenStub_Execute(OS_GetErrorName, Basic, UT_DefaultHandler_OS_GetErrorName); + + return UT_GenStub_GetReturnValue(OS_GetErrorName, int32); +} diff --git a/src/ut-stubs/osapi-file-hooks.c b/src/ut-stubs/osapi-file-hooks.c new file mode 100644 index 000000000..ac200dbcf --- /dev/null +++ b/src/ut-stubs/osapi-file-hooks.c @@ -0,0 +1,248 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-file.h" /* OSAL public API for this subsystem */ +#include "osapi-idmap.h" +#include "utstub-helpers.h" + +/***************************************************************************** + * + * Local Stub helper function for reading + * + *****************************************************************************/ +static void UT_GenericReadStub(UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + void * buffer = UT_Hook_GetArgValueByName(Context, "buffer", void *); + size_t nbytes = UT_Hook_GetArgValueByName(Context, "nbytes", size_t); + size_t CopySize; + int32 status; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + CopySize = UT_Stub_CopyToLocal(FuncKey, buffer, nbytes); + + /* If CopyToLocal returns zero, this probably means no buffer was supplied, + * in which case just generate fill data and pretend it was read. + */ + if (CopySize > 0) + { + status = CopySize; + } + else + { + memset(buffer, 0, nbytes); + status = nbytes; + } + } + else if (status > 0) + { + /* generate fill data for requested size */ + memset(buffer, 0, status); + } + + UT_Stub_SetReturnValue(FuncKey, status); +} + +/***************************************************************************** + * + * Local Stub helper function for writing + * + *****************************************************************************/ +static void UT_GenericWriteStub(UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + const void *buffer = UT_Hook_GetArgValueByName(Context, "buffer", const void *); + size_t nbytes = UT_Hook_GetArgValueByName(Context, "nbytes", size_t); + size_t CopySize; + int32 status; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + CopySize = UT_Stub_CopyFromLocal(FuncKey, buffer, nbytes); + + /* If CopyFromLocal returns zero, this probably means no buffer was supplied, + * in which case just throw out the data and pretend it was written. + */ + if (CopySize > 0) + { + status = CopySize; + } + else + { + status = nbytes; + } + } + + UT_Stub_SetReturnValue(FuncKey, status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_OpenCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_OpenCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *filedes = UT_Hook_GetArgValueByName(Context, "filedes", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *filedes = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); + } + else + { + *filedes = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_close' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_close(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t filedes = UT_Hook_GetArgValueByName(Context, "filedes", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_STREAM, filedes); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_read' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_read(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + UT_GenericReadStub(FuncKey, Context); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_write' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_write(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + UT_GenericWriteStub(FuncKey, Context); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimedRead' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimedRead(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + UT_GenericReadStub(FuncKey, Context); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimedWrite' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimedWrite(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + UT_GenericWriteStub(FuncKey, Context); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_stat' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_stat(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + os_fstat_t *filestats = UT_Hook_GetArgValueByName(Context, "filestats", os_fstat_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS) + { + UT_Stub_CopyToLocal(UT_KEY(OS_stat), filestats, sizeof(*filestats)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_lseek' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_lseek(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + int32 offset = UT_Hook_GetArgValueByName(Context, "offset", int32); + int32 Status; + + if (UT_Stub_GetInt32StatusCode(Context, &Status)) + { + /* Use the configured status code directly as the returned offset */ + offset = Status; + } + + UT_Stub_SetReturnValue(FuncKey, offset); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_FDGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_FDGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_file_prop_t *fd_prop = UT_Hook_GetArgValueByName(Context, "fd_prop", OS_file_prop_t *); + int32 status; + size_t CopySize; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + /* The user may supply specific entries to return */ + CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_FDGetInfo), fd_prop, sizeof(*fd_prop)); + if (CopySize < sizeof(*fd_prop)) + { + memset(fd_prop, 0, sizeof(*fd_prop)); + fd_prop->IsValid = true; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &fd_prop->User); + } + } +} diff --git a/src/ut-stubs/osapi-file-stubs.c b/src/ut-stubs/osapi-file-stubs.c new file mode 100644 index 000000000..4b0f30adf --- /dev/null +++ b/src/ut-stubs/osapi-file-stubs.c @@ -0,0 +1,329 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-file header + */ + +#include "osapi-file.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_FDGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_OpenCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimedRead(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimedWrite(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_close(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_lseek(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_read(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_stat(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_write(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CloseAllFiles() + * ---------------------------------------------------- + */ +int32 OS_CloseAllFiles(void) +{ + UT_GenStub_SetupReturnBuffer(OS_CloseAllFiles, int32); + + UT_GenStub_Execute(OS_CloseAllFiles, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CloseAllFiles, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CloseFileByName() + * ---------------------------------------------------- + */ +int32 OS_CloseFileByName(const char *Filename) +{ + UT_GenStub_SetupReturnBuffer(OS_CloseFileByName, int32); + + UT_GenStub_AddParam(OS_CloseFileByName, const char *, Filename); + + UT_GenStub_Execute(OS_CloseFileByName, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CloseFileByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FDGetInfo() + * ---------------------------------------------------- + */ +int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_FDGetInfo, int32); + + UT_GenStub_AddParam(OS_FDGetInfo, osal_id_t, filedes); + UT_GenStub_AddParam(OS_FDGetInfo, OS_file_prop_t *, fd_prop); + + UT_GenStub_Execute(OS_FDGetInfo, Basic, UT_DefaultHandler_OS_FDGetInfo); + + return UT_GenStub_GetReturnValue(OS_FDGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileOpenCheck() + * ---------------------------------------------------- + */ +int32 OS_FileOpenCheck(const char *Filename) +{ + UT_GenStub_SetupReturnBuffer(OS_FileOpenCheck, int32); + + UT_GenStub_AddParam(OS_FileOpenCheck, const char *, Filename); + + UT_GenStub_Execute(OS_FileOpenCheck, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileOpenCheck, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_OpenCreate() + * ---------------------------------------------------- + */ +int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) +{ + UT_GenStub_SetupReturnBuffer(OS_OpenCreate, int32); + + UT_GenStub_AddParam(OS_OpenCreate, osal_id_t *, filedes); + UT_GenStub_AddParam(OS_OpenCreate, const char *, path); + UT_GenStub_AddParam(OS_OpenCreate, int32, flags); + UT_GenStub_AddParam(OS_OpenCreate, int32, access); + + UT_GenStub_Execute(OS_OpenCreate, Basic, UT_DefaultHandler_OS_OpenCreate); + + return UT_GenStub_GetReturnValue(OS_OpenCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimedRead() + * ---------------------------------------------------- + */ +int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_TimedRead, int32); + + UT_GenStub_AddParam(OS_TimedRead, osal_id_t, filedes); + UT_GenStub_AddParam(OS_TimedRead, void *, buffer); + UT_GenStub_AddParam(OS_TimedRead, size_t, nbytes); + UT_GenStub_AddParam(OS_TimedRead, int32, timeout); + + UT_GenStub_Execute(OS_TimedRead, Basic, UT_DefaultHandler_OS_TimedRead); + + return UT_GenStub_GetReturnValue(OS_TimedRead, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimedWrite() + * ---------------------------------------------------- + */ +int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_TimedWrite, int32); + + UT_GenStub_AddParam(OS_TimedWrite, osal_id_t, filedes); + UT_GenStub_AddParam(OS_TimedWrite, const void *, buffer); + UT_GenStub_AddParam(OS_TimedWrite, size_t, nbytes); + UT_GenStub_AddParam(OS_TimedWrite, int32, timeout); + + UT_GenStub_Execute(OS_TimedWrite, Basic, UT_DefaultHandler_OS_TimedWrite); + + return UT_GenStub_GetReturnValue(OS_TimedWrite, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_chmod() + * ---------------------------------------------------- + */ +int32 OS_chmod(const char *path, uint32 access) +{ + UT_GenStub_SetupReturnBuffer(OS_chmod, int32); + + UT_GenStub_AddParam(OS_chmod, const char *, path); + UT_GenStub_AddParam(OS_chmod, uint32, access); + + UT_GenStub_Execute(OS_chmod, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_chmod, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_close() + * ---------------------------------------------------- + */ +int32 OS_close(osal_id_t filedes) +{ + UT_GenStub_SetupReturnBuffer(OS_close, int32); + + UT_GenStub_AddParam(OS_close, osal_id_t, filedes); + + UT_GenStub_Execute(OS_close, Basic, UT_DefaultHandler_OS_close); + + return UT_GenStub_GetReturnValue(OS_close, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_cp() + * ---------------------------------------------------- + */ +int32 OS_cp(const char *src, const char *dest) +{ + UT_GenStub_SetupReturnBuffer(OS_cp, int32); + + UT_GenStub_AddParam(OS_cp, const char *, src); + UT_GenStub_AddParam(OS_cp, const char *, dest); + + UT_GenStub_Execute(OS_cp, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_cp, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_lseek() + * ---------------------------------------------------- + */ +int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence) +{ + UT_GenStub_SetupReturnBuffer(OS_lseek, int32); + + UT_GenStub_AddParam(OS_lseek, osal_id_t, filedes); + UT_GenStub_AddParam(OS_lseek, int32, offset); + UT_GenStub_AddParam(OS_lseek, uint32, whence); + + UT_GenStub_Execute(OS_lseek, Basic, UT_DefaultHandler_OS_lseek); + + return UT_GenStub_GetReturnValue(OS_lseek, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_mv() + * ---------------------------------------------------- + */ +int32 OS_mv(const char *src, const char *dest) +{ + UT_GenStub_SetupReturnBuffer(OS_mv, int32); + + UT_GenStub_AddParam(OS_mv, const char *, src); + UT_GenStub_AddParam(OS_mv, const char *, dest); + + UT_GenStub_Execute(OS_mv, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_mv, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_read() + * ---------------------------------------------------- + */ +int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes) +{ + UT_GenStub_SetupReturnBuffer(OS_read, int32); + + UT_GenStub_AddParam(OS_read, osal_id_t, filedes); + UT_GenStub_AddParam(OS_read, void *, buffer); + UT_GenStub_AddParam(OS_read, size_t, nbytes); + + UT_GenStub_Execute(OS_read, Basic, UT_DefaultHandler_OS_read); + + return UT_GenStub_GetReturnValue(OS_read, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_remove() + * ---------------------------------------------------- + */ +int32 OS_remove(const char *path) +{ + UT_GenStub_SetupReturnBuffer(OS_remove, int32); + + UT_GenStub_AddParam(OS_remove, const char *, path); + + UT_GenStub_Execute(OS_remove, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_remove, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_rename() + * ---------------------------------------------------- + */ +int32 OS_rename(const char *old_filename, const char *new_filename) +{ + UT_GenStub_SetupReturnBuffer(OS_rename, int32); + + UT_GenStub_AddParam(OS_rename, const char *, old_filename); + UT_GenStub_AddParam(OS_rename, const char *, new_filename); + + UT_GenStub_Execute(OS_rename, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_rename, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_stat() + * ---------------------------------------------------- + */ +int32 OS_stat(const char *path, os_fstat_t *filestats) +{ + UT_GenStub_SetupReturnBuffer(OS_stat, int32); + + UT_GenStub_AddParam(OS_stat, const char *, path); + UT_GenStub_AddParam(OS_stat, os_fstat_t *, filestats); + + UT_GenStub_Execute(OS_stat, Basic, UT_DefaultHandler_OS_stat); + + return UT_GenStub_GetReturnValue(OS_stat, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_write() + * ---------------------------------------------------- + */ +int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes) +{ + UT_GenStub_SetupReturnBuffer(OS_write, int32); + + UT_GenStub_AddParam(OS_write, osal_id_t, filedes); + UT_GenStub_AddParam(OS_write, const void *, buffer); + UT_GenStub_AddParam(OS_write, size_t, nbytes); + + UT_GenStub_Execute(OS_write, Basic, UT_DefaultHandler_OS_write); + + return UT_GenStub_GetReturnValue(OS_write, int32); +} diff --git a/src/ut-stubs/osapi-filesys-hooks.c b/src/ut-stubs/osapi-filesys-hooks.c new file mode 100644 index 000000000..5c1b11aa1 --- /dev/null +++ b/src/ut-stubs/osapi-filesys-hooks.c @@ -0,0 +1,122 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-filesys.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_FileSysAddFixedMap' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_FileSysAddFixedMap(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *filesys_id = UT_Hook_GetArgValueByName(Context, "filesys_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *filesys_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_FILESYS); + } + else + { + *filesys_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_FileSysStatVolume' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_FileSysStatVolume(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_statvfs_t *statbuf = UT_Hook_GetArgValueByName(Context, "statbuf", OS_statvfs_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) + { + memset(statbuf, 0, sizeof(*statbuf)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_FS_GetPhysDriveName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_FS_GetPhysDriveName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + char * PhysDriveName = UT_Hook_GetArgValueByName(Context, "PhysDriveName", char *); + const char *MountPoint = UT_Hook_GetArgValueByName(Context, "MountPoint", const char *); + + strncpy(PhysDriveName, MountPoint, OS_FS_PHYS_NAME_LEN - 1); + PhysDriveName[OS_FS_PHYS_NAME_LEN - 1] = 0; +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetFsInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetFsInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + os_fsinfo_t *filesys_info = UT_Hook_GetArgValueByName(Context, "filesys_info", os_fsinfo_t *); + + memset(filesys_info, 0, sizeof(*filesys_info)); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TranslatePath' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TranslatePath(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + const char *VirtualPath = UT_Hook_GetArgValueByName(Context, "VirtualPath", const char *); + char * LocalPath = UT_Hook_GetArgValueByName(Context, "LocalPath", char *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && VirtualPath != NULL && LocalPath != NULL && + UT_Stub_CopyToLocal(UT_KEY(OS_TranslatePath), LocalPath, OS_MAX_LOCAL_PATH_LEN) == 0) + { + strncpy(LocalPath, VirtualPath, OS_MAX_LOCAL_PATH_LEN - 1); + LocalPath[OS_MAX_LOCAL_PATH_LEN - 1] = 0; + } +} diff --git a/src/ut-stubs/osapi-filesys-stubs.c b/src/ut-stubs/osapi-filesys-stubs.c new file mode 100644 index 000000000..a368a5f35 --- /dev/null +++ b/src/ut-stubs/osapi-filesys-stubs.c @@ -0,0 +1,225 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-filesys header + */ + +#include "osapi-filesys.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_FS_GetPhysDriveName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_FileSysAddFixedMap(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_FileSysStatVolume(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_GetFsInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TranslatePath(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FS_GetPhysDriveName() + * ---------------------------------------------------- + */ +int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) +{ + UT_GenStub_SetupReturnBuffer(OS_FS_GetPhysDriveName, int32); + + UT_GenStub_AddParam(OS_FS_GetPhysDriveName, char *, PhysDriveName); + UT_GenStub_AddParam(OS_FS_GetPhysDriveName, const char *, MountPoint); + + UT_GenStub_Execute(OS_FS_GetPhysDriveName, Basic, UT_DefaultHandler_OS_FS_GetPhysDriveName); + + return UT_GenStub_GetReturnValue(OS_FS_GetPhysDriveName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysAddFixedMap() + * ---------------------------------------------------- + */ +int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysAddFixedMap, int32); + + UT_GenStub_AddParam(OS_FileSysAddFixedMap, osal_id_t *, filesys_id); + UT_GenStub_AddParam(OS_FileSysAddFixedMap, const char *, phys_path); + UT_GenStub_AddParam(OS_FileSysAddFixedMap, const char *, virt_path); + + UT_GenStub_Execute(OS_FileSysAddFixedMap, Basic, UT_DefaultHandler_OS_FileSysAddFixedMap); + + return UT_GenStub_GetReturnValue(OS_FileSysAddFixedMap, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysStatVolume() + * ---------------------------------------------------- + */ +int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysStatVolume, int32); + + UT_GenStub_AddParam(OS_FileSysStatVolume, const char *, name); + UT_GenStub_AddParam(OS_FileSysStatVolume, OS_statvfs_t *, statbuf); + + UT_GenStub_Execute(OS_FileSysStatVolume, Basic, UT_DefaultHandler_OS_FileSysStatVolume); + + return UT_GenStub_GetReturnValue(OS_FileSysStatVolume, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetFsInfo() + * ---------------------------------------------------- + */ +int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) +{ + UT_GenStub_SetupReturnBuffer(OS_GetFsInfo, int32); + + UT_GenStub_AddParam(OS_GetFsInfo, os_fsinfo_t *, filesys_info); + + UT_GenStub_Execute(OS_GetFsInfo, Basic, UT_DefaultHandler_OS_GetFsInfo); + + return UT_GenStub_GetReturnValue(OS_GetFsInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TranslatePath() + * ---------------------------------------------------- + */ +int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) +{ + UT_GenStub_SetupReturnBuffer(OS_TranslatePath, int32); + + UT_GenStub_AddParam(OS_TranslatePath, const char *, VirtualPath); + UT_GenStub_AddParam(OS_TranslatePath, char *, LocalPath); + + UT_GenStub_Execute(OS_TranslatePath, Basic, UT_DefaultHandler_OS_TranslatePath); + + return UT_GenStub_GetReturnValue(OS_TranslatePath, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_chkfs() + * ---------------------------------------------------- + */ +int32 OS_chkfs(const char *name, bool repair) +{ + UT_GenStub_SetupReturnBuffer(OS_chkfs, int32); + + UT_GenStub_AddParam(OS_chkfs, const char *, name); + UT_GenStub_AddParam(OS_chkfs, bool, repair); + + UT_GenStub_Execute(OS_chkfs, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_chkfs, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_initfs() + * ---------------------------------------------------- + */ +int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) +{ + UT_GenStub_SetupReturnBuffer(OS_initfs, int32); + + UT_GenStub_AddParam(OS_initfs, char *, address); + UT_GenStub_AddParam(OS_initfs, const char *, devname); + UT_GenStub_AddParam(OS_initfs, const char *, volname); + UT_GenStub_AddParam(OS_initfs, size_t, blocksize); + UT_GenStub_AddParam(OS_initfs, osal_blockcount_t, numblocks); + + UT_GenStub_Execute(OS_initfs, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_initfs, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_mkfs() + * ---------------------------------------------------- + */ +int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) +{ + UT_GenStub_SetupReturnBuffer(OS_mkfs, int32); + + UT_GenStub_AddParam(OS_mkfs, char *, address); + UT_GenStub_AddParam(OS_mkfs, const char *, devname); + UT_GenStub_AddParam(OS_mkfs, const char *, volname); + UT_GenStub_AddParam(OS_mkfs, size_t, blocksize); + UT_GenStub_AddParam(OS_mkfs, osal_blockcount_t, numblocks); + + UT_GenStub_Execute(OS_mkfs, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_mkfs, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_mount() + * ---------------------------------------------------- + */ +int32 OS_mount(const char *devname, const char *mountpoint) +{ + UT_GenStub_SetupReturnBuffer(OS_mount, int32); + + UT_GenStub_AddParam(OS_mount, const char *, devname); + UT_GenStub_AddParam(OS_mount, const char *, mountpoint); + + UT_GenStub_Execute(OS_mount, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_mount, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_rmfs() + * ---------------------------------------------------- + */ +int32 OS_rmfs(const char *devname) +{ + UT_GenStub_SetupReturnBuffer(OS_rmfs, int32); + + UT_GenStub_AddParam(OS_rmfs, const char *, devname); + + UT_GenStub_Execute(OS_rmfs, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_rmfs, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_unmount() + * ---------------------------------------------------- + */ +int32 OS_unmount(const char *mountpoint) +{ + UT_GenStub_SetupReturnBuffer(OS_unmount, int32); + + UT_GenStub_AddParam(OS_unmount, const char *, mountpoint); + + UT_GenStub_Execute(OS_unmount, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_unmount, int32); +} diff --git a/src/ut-stubs/osapi-utstub-heap.c b/src/ut-stubs/osapi-heap-hooks.c similarity index 76% rename from src/ut-stubs/osapi-utstub-heap.c rename to src/ut-stubs/osapi-heap-hooks.c index bf3145f75..8b81750be 100644 --- a/src/ut-stubs/osapi-utstub-heap.c +++ b/src/ut-stubs/osapi-heap-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,18 +33,17 @@ #include "osapi-heap.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -/***************************************************************************** - * - * Stub function for OS_HeapGetInfo() - * - *****************************************************************************/ -int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_HeapGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_HeapGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_Stub_RegisterContext(UT_KEY(OS_HeapGetInfo), heap_prop); - - int32 status; + OS_heap_prop_t *heap_prop = UT_Hook_GetArgValueByName(Context, "heap_prop", OS_heap_prop_t *); + int32 status; - status = UT_DEFAULT_IMPL(OS_HeapGetInfo); + UT_Stub_GetInt32StatusCode(Context, &status); if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_HeapGetInfo), heap_prop, sizeof(*heap_prop)) < sizeof(*heap_prop)) @@ -56,6 +53,4 @@ int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop) heap_prop->free_blocks = OSAL_BLOCKCOUNT_C(6789); heap_prop->largest_free_block = OSAL_SIZE_C(100); } - - return status; } diff --git a/src/ut-stubs/osapi-heap-stubs.c b/src/ut-stubs/osapi-heap-stubs.c new file mode 100644 index 000000000..71f601850 --- /dev/null +++ b/src/ut-stubs/osapi-heap-stubs.c @@ -0,0 +1,46 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-heap header + */ + +#include "osapi-heap.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_HeapGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_HeapGetInfo() + * ---------------------------------------------------- + */ +int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_HeapGetInfo, int32); + + UT_GenStub_AddParam(OS_HeapGetInfo, OS_heap_prop_t *, heap_prop); + + UT_GenStub_Execute(OS_HeapGetInfo, Basic, UT_DefaultHandler_OS_HeapGetInfo); + + return UT_GenStub_GetReturnValue(OS_HeapGetInfo, int32); +} diff --git a/src/ut-stubs/osapi-idmap-hooks.c b/src/ut-stubs/osapi-idmap-hooks.c new file mode 100644 index 000000000..706789154 --- /dev/null +++ b/src/ut-stubs/osapi-idmap-hooks.c @@ -0,0 +1,195 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + * + * NOTE: The Object ID manipulation calls would not be called by applications. + * However stubs are still defined in order to support things such as + * coverage testing of the low-level implementation. This set of stubs + * is implemented separately here as it is only needed when coverage testing + * OSAL itself (not for coverage testing other units). + */ + +#include "osapi-idmap.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" +#include "os-shared-idmap.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdToArrayIndex' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdToArrayIndex(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t object_id = UT_Hook_GetArgValueByName(Context, "object_id", osal_id_t); + osal_index_t * ArrayIndex = UT_Hook_GetArgValueByName(Context, "ArrayIndex", osal_index_t *); + int32 Status; + osal_objtype_t checktype; + uint32 tempserial; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == 0 && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdToArrayIndex), ArrayIndex, sizeof(*ArrayIndex)) < sizeof(*ArrayIndex)) + { + /* this needs to output something valid or code will break */ + UT_ObjIdDecompose(object_id, &tempserial, &checktype); + *ArrayIndex = OSAL_INDEX_C(tempserial); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetResourceName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetResourceName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + char * buffer = UT_Hook_GetArgValueByName(Context, "buffer", char *); + size_t buffer_size = UT_Hook_GetArgValueByName(Context, "buffer_size", size_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + if (buffer_size > 0 && UT_Stub_CopyToLocal(UT_KEY(OS_GetResourceName), buffer, buffer_size) == 0) + { + /* return an empty string by default */ + buffer[0] = 0; + } + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ConvertToArrayIndex' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ConvertToArrayIndex(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t object_id = UT_Hook_GetArgValueByName(Context, "object_id", osal_id_t); + osal_index_t * ArrayIndex = UT_Hook_GetArgValueByName(Context, "ArrayIndex", osal_index_t *); + osal_objtype_t ObjType; + int32 status; + uint32 tempserial; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_ObjIdDecompose(object_id, &tempserial, &ObjType); + if (ObjType != OS_OBJECT_TYPE_UNDEFINED && ObjType < OS_OBJECT_TYPE_USER) + { + tempserial %= UT_MAXOBJS[ObjType]; + } + } + else + { + /* + * If set to fail, then set the output to something bizarre - if the code + * actually tries to use this, chances are it will segfault and be fixed + */ + tempserial = 0xDEADBEEFU; + } + + *ArrayIndex = OSAL_INDEX_C(tempserial); + +} /* end OS_ConvertToArrayIndex */ + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ForEachObjectOfType' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ForEachObjectOfType(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_ArgCallback_t callback_ptr = UT_Hook_GetArgValueByName(Context, "callback_ptr", OS_ArgCallback_t); + void * callback_arg = UT_Hook_GetArgValueByName(Context, "callback_arg", void *); + osal_id_t NextId; + size_t IdSize; + + while (1) + { + IdSize = UT_Stub_CopyToLocal(UT_KEY(OS_ForEachObjectOfType), &NextId, sizeof(NextId)); + if (IdSize < sizeof(NextId)) + { + break; + } + (*callback_ptr)(NextId, callback_arg); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ForEachObject' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ForEachObject(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_ArgCallback_t callback_ptr = UT_Hook_GetArgValueByName(Context, "callback_ptr", OS_ArgCallback_t); + void * callback_arg = UT_Hook_GetArgValueByName(Context, "callback_arg", void *); + osal_id_t NextId; + size_t IdSize; + + while (1) + { + IdSize = UT_Stub_CopyToLocal((UT_EntryKey_t)&OS_ForEachObject, &NextId, sizeof(NextId)); + if (IdSize < sizeof(NextId)) + { + break; + } + (*callback_ptr)(NextId, callback_arg); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_IdentifyObject' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_IdentifyObject(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t object_id = UT_Hook_GetArgValueByName(Context, "object_id", osal_id_t); + osal_objtype_t ObjType; + uint32 checkindx; + int32 status; + + if (UT_Stub_GetInt32StatusCode(Context, &status)) + { + /* Use the "status code" as the object type if it was set */ + ObjType = status; + } + else + { + /* output a type that will actually match the ID */ + UT_ObjIdDecompose(object_id, &checkindx, &ObjType); + } + + UT_Stub_SetReturnValue(FuncKey, ObjType); +} diff --git a/src/ut-stubs/osapi-idmap-stubs.c b/src/ut-stubs/osapi-idmap-stubs.c new file mode 100644 index 000000000..a55b7b8c0 --- /dev/null +++ b/src/ut-stubs/osapi-idmap-stubs.c @@ -0,0 +1,134 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-idmap header + */ + +#include "osapi-idmap.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_ConvertToArrayIndex(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ForEachObject(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ForEachObjectOfType(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_GetResourceName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_IdentifyObject(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdToArrayIndex(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ConvertToArrayIndex() + * ---------------------------------------------------- + */ +int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex) +{ + UT_GenStub_SetupReturnBuffer(OS_ConvertToArrayIndex, int32); + + UT_GenStub_AddParam(OS_ConvertToArrayIndex, osal_id_t, object_id); + UT_GenStub_AddParam(OS_ConvertToArrayIndex, osal_index_t *, ArrayIndex); + + UT_GenStub_Execute(OS_ConvertToArrayIndex, Basic, UT_DefaultHandler_OS_ConvertToArrayIndex); + + return UT_GenStub_GetReturnValue(OS_ConvertToArrayIndex, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ForEachObject() + * ---------------------------------------------------- + */ +void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg) +{ + UT_GenStub_AddParam(OS_ForEachObject, osal_id_t, creator_id); + UT_GenStub_AddParam(OS_ForEachObject, OS_ArgCallback_t, callback_ptr); + UT_GenStub_AddParam(OS_ForEachObject, void *, callback_arg); + + UT_GenStub_Execute(OS_ForEachObject, Basic, UT_DefaultHandler_OS_ForEachObject); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ForEachObjectOfType() + * ---------------------------------------------------- + */ +void OS_ForEachObjectOfType(osal_objtype_t objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, + void *callback_arg) +{ + UT_GenStub_AddParam(OS_ForEachObjectOfType, osal_objtype_t, objtype); + UT_GenStub_AddParam(OS_ForEachObjectOfType, osal_id_t, creator_id); + UT_GenStub_AddParam(OS_ForEachObjectOfType, OS_ArgCallback_t, callback_ptr); + UT_GenStub_AddParam(OS_ForEachObjectOfType, void *, callback_arg); + + UT_GenStub_Execute(OS_ForEachObjectOfType, Basic, UT_DefaultHandler_OS_ForEachObjectOfType); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetResourceName() + * ---------------------------------------------------- + */ +int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) +{ + UT_GenStub_SetupReturnBuffer(OS_GetResourceName, int32); + + UT_GenStub_AddParam(OS_GetResourceName, osal_id_t, object_id); + UT_GenStub_AddParam(OS_GetResourceName, char *, buffer); + UT_GenStub_AddParam(OS_GetResourceName, size_t, buffer_size); + + UT_GenStub_Execute(OS_GetResourceName, Basic, UT_DefaultHandler_OS_GetResourceName); + + return UT_GenStub_GetReturnValue(OS_GetResourceName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_IdentifyObject() + * ---------------------------------------------------- + */ +osal_objtype_t OS_IdentifyObject(osal_id_t object_id) +{ + UT_GenStub_SetupReturnBuffer(OS_IdentifyObject, osal_objtype_t); + + UT_GenStub_AddParam(OS_IdentifyObject, osal_id_t, object_id); + + UT_GenStub_Execute(OS_IdentifyObject, Basic, UT_DefaultHandler_OS_IdentifyObject); + + return UT_GenStub_GetReturnValue(OS_IdentifyObject, osal_objtype_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdToArrayIndex() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t object_id, osal_index_t *ArrayIndex) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdToArrayIndex, int32); + + UT_GenStub_AddParam(OS_ObjectIdToArrayIndex, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdToArrayIndex, osal_id_t, object_id); + UT_GenStub_AddParam(OS_ObjectIdToArrayIndex, osal_index_t *, ArrayIndex); + + UT_GenStub_Execute(OS_ObjectIdToArrayIndex, Basic, UT_DefaultHandler_OS_ObjectIdToArrayIndex); + + return UT_GenStub_GetReturnValue(OS_ObjectIdToArrayIndex, int32); +} diff --git a/src/ut-stubs/osapi-module-hooks.c b/src/ut-stubs/osapi-module-hooks.c new file mode 100644 index 000000000..f6065a0bf --- /dev/null +++ b/src/ut-stubs/osapi-module-hooks.c @@ -0,0 +1,173 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-module.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/*****************************************************************************/ +/** +** \brief dummy_function stub function +** +** \par Description +** This function is used by the OS API function, OS_SymbolLookup, which +** requires a valid function for which to report the address. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** Returns a user-defined status value. +** +******************************************************************************/ +int32 dummy_function(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(dummy_function); + + return status; +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ModuleLoad' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ModuleLoad(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *module_id = UT_Hook_GetArgValueByName(Context, "module_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *module_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MODULE); + } + else + { + *module_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ModuleUnload' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ModuleUnload(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t module_id = UT_Hook_GetArgValueByName(Context, "module_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MODULE, module_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ModuleInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ModuleInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_module_prop_t *module_info = UT_Hook_GetArgValueByName(Context, "module_info", OS_module_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ModuleInfo), module_info, sizeof(*module_info)) < sizeof(*module_info)) + { + memset(module_info, 0, sizeof(*module_info)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SymbolLookup' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SymbolLookup(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + cpuaddr *symbol_address = UT_Hook_GetArgValueByName(Context, "symbol_address", cpuaddr *); + int32 status; + + /* + * Register the context so a hook can do something with the parameters + */ + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status != OS_SUCCESS) + { + *symbol_address = 0xDEADBEEFU; + } + else if (UT_Stub_CopyToLocal(UT_KEY(OS_SymbolLookup), symbol_address, sizeof(*symbol_address)) < + sizeof(*symbol_address)) + { + /* return the dummy function when test didn't register anything else */ + *symbol_address = (cpuaddr)&dummy_function; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ModuleSymbolLookup' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ModuleSymbolLookup(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + cpuaddr *symbol_address = UT_Hook_GetArgValueByName(Context, "symbol_address", cpuaddr *); + int32 status; + + /* + * Register the context so a hook can do something with the parameters + */ + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status != OS_SUCCESS) + { + *symbol_address = 0xDEADBEEFU; + } + else if (UT_Stub_CopyToLocal(UT_KEY(OS_ModuleSymbolLookup), symbol_address, sizeof(*symbol_address)) < + sizeof(*symbol_address)) + { + /* return the dummy function when test didn't register anything else */ + *symbol_address = (cpuaddr)&dummy_function; + } +} diff --git a/src/ut-stubs/osapi-module-stubs.c b/src/ut-stubs/osapi-module-stubs.c new file mode 100644 index 000000000..99eef864c --- /dev/null +++ b/src/ut-stubs/osapi-module-stubs.c @@ -0,0 +1,138 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-module header + */ + +#include "osapi-module.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_ModuleInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ModuleLoad(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ModuleSymbolLookup(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ModuleUnload(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SymbolLookup(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleInfo() + * ---------------------------------------------------- + */ +int32 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_info) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleInfo, int32); + + UT_GenStub_AddParam(OS_ModuleInfo, osal_id_t, module_id); + UT_GenStub_AddParam(OS_ModuleInfo, OS_module_prop_t *, module_info); + + UT_GenStub_Execute(OS_ModuleInfo, Basic, UT_DefaultHandler_OS_ModuleInfo); + + return UT_GenStub_GetReturnValue(OS_ModuleInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleLoad() + * ---------------------------------------------------- + */ +int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleLoad, int32); + + UT_GenStub_AddParam(OS_ModuleLoad, osal_id_t *, module_id); + UT_GenStub_AddParam(OS_ModuleLoad, const char *, module_name); + UT_GenStub_AddParam(OS_ModuleLoad, const char *, filename); + UT_GenStub_AddParam(OS_ModuleLoad, uint32, flags); + + UT_GenStub_Execute(OS_ModuleLoad, Basic, UT_DefaultHandler_OS_ModuleLoad); + + return UT_GenStub_GetReturnValue(OS_ModuleLoad, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleSymbolLookup() + * ---------------------------------------------------- + */ +int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleSymbolLookup, int32); + + UT_GenStub_AddParam(OS_ModuleSymbolLookup, osal_id_t, module_id); + UT_GenStub_AddParam(OS_ModuleSymbolLookup, cpuaddr *, symbol_address); + UT_GenStub_AddParam(OS_ModuleSymbolLookup, const char *, symbol_name); + + UT_GenStub_Execute(OS_ModuleSymbolLookup, Basic, UT_DefaultHandler_OS_ModuleSymbolLookup); + + return UT_GenStub_GetReturnValue(OS_ModuleSymbolLookup, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleUnload() + * ---------------------------------------------------- + */ +int32 OS_ModuleUnload(osal_id_t module_id) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleUnload, int32); + + UT_GenStub_AddParam(OS_ModuleUnload, osal_id_t, module_id); + + UT_GenStub_Execute(OS_ModuleUnload, Basic, UT_DefaultHandler_OS_ModuleUnload); + + return UT_GenStub_GetReturnValue(OS_ModuleUnload, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SymbolLookup() + * ---------------------------------------------------- + */ +int32 OS_SymbolLookup(cpuaddr *symbol_address, const char *symbol_name) +{ + UT_GenStub_SetupReturnBuffer(OS_SymbolLookup, int32); + + UT_GenStub_AddParam(OS_SymbolLookup, cpuaddr *, symbol_address); + UT_GenStub_AddParam(OS_SymbolLookup, const char *, symbol_name); + + UT_GenStub_Execute(OS_SymbolLookup, Basic, UT_DefaultHandler_OS_SymbolLookup); + + return UT_GenStub_GetReturnValue(OS_SymbolLookup, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SymbolTableDump() + * ---------------------------------------------------- + */ +int32 OS_SymbolTableDump(const char *filename, size_t size_limit) +{ + UT_GenStub_SetupReturnBuffer(OS_SymbolTableDump, int32); + + UT_GenStub_AddParam(OS_SymbolTableDump, const char *, filename); + UT_GenStub_AddParam(OS_SymbolTableDump, size_t, size_limit); + + UT_GenStub_Execute(OS_SymbolTableDump, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SymbolTableDump, int32); +} diff --git a/src/ut-stubs/osapi-mutex-hooks.c b/src/ut-stubs/osapi-mutex-hooks.c new file mode 100644 index 000000000..32bdb6d92 --- /dev/null +++ b/src/ut-stubs/osapi-mutex-hooks.c @@ -0,0 +1,113 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-mutex.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_MutSemCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_MutSemCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MUTEX); + } + else + { + *sem_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_MutSemDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_MutSemDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MUTEX, sem_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_MutSemGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_MutSemGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sem_id = UT_Hook_GetArgValueByName(Context, "sem_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_MUTEX, sem_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_MutSemGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_MutSemGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_mut_sem_prop_t *mut_prop = UT_Hook_GetArgValueByName(Context, "mut_prop", OS_mut_sem_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetInfo), mut_prop, sizeof(*mut_prop)) < sizeof(*mut_prop)) + { + strncpy(mut_prop->name, "Name", sizeof(mut_prop->name) - 1); + mut_prop->name[sizeof(mut_prop->name) - 1] = '\0'; + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &mut_prop->creator); + } +} diff --git a/src/ut-stubs/osapi-mutex-stubs.c b/src/ut-stubs/osapi-mutex-stubs.c new file mode 100644 index 000000000..c0e9b31b2 --- /dev/null +++ b/src/ut-stubs/osapi-mutex-stubs.c @@ -0,0 +1,133 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-mutex header + */ + +#include "osapi-mutex.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_MutSemCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_MutSemDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_MutSemGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_MutSemGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemCreate() + * ---------------------------------------------------- + */ +int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemCreate, int32); + + UT_GenStub_AddParam(OS_MutSemCreate, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_MutSemCreate, const char *, sem_name); + UT_GenStub_AddParam(OS_MutSemCreate, uint32, options); + + UT_GenStub_Execute(OS_MutSemCreate, Basic, UT_DefaultHandler_OS_MutSemCreate); + + return UT_GenStub_GetReturnValue(OS_MutSemCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemDelete() + * ---------------------------------------------------- + */ +int32 OS_MutSemDelete(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemDelete, int32); + + UT_GenStub_AddParam(OS_MutSemDelete, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_MutSemDelete, Basic, UT_DefaultHandler_OS_MutSemDelete); + + return UT_GenStub_GetReturnValue(OS_MutSemDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemGetIdByName, int32); + + UT_GenStub_AddParam(OS_MutSemGetIdByName, osal_id_t *, sem_id); + UT_GenStub_AddParam(OS_MutSemGetIdByName, const char *, sem_name); + + UT_GenStub_Execute(OS_MutSemGetIdByName, Basic, UT_DefaultHandler_OS_MutSemGetIdByName); + + return UT_GenStub_GetReturnValue(OS_MutSemGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemGetInfo() + * ---------------------------------------------------- + */ +int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemGetInfo, int32); + + UT_GenStub_AddParam(OS_MutSemGetInfo, osal_id_t, sem_id); + UT_GenStub_AddParam(OS_MutSemGetInfo, OS_mut_sem_prop_t *, mut_prop); + + UT_GenStub_Execute(OS_MutSemGetInfo, Basic, UT_DefaultHandler_OS_MutSemGetInfo); + + return UT_GenStub_GetReturnValue(OS_MutSemGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemGive() + * ---------------------------------------------------- + */ +int32 OS_MutSemGive(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemGive, int32); + + UT_GenStub_AddParam(OS_MutSemGive, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_MutSemGive, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemGive, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemTake() + * ---------------------------------------------------- + */ +int32 OS_MutSemTake(osal_id_t sem_id) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemTake, int32); + + UT_GenStub_AddParam(OS_MutSemTake, osal_id_t, sem_id); + + UT_GenStub_Execute(OS_MutSemTake, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemTake, int32); +} diff --git a/src/ut-stubs/osapi-utstub-network.c b/src/ut-stubs/osapi-network-hooks.c similarity index 71% rename from src/ut-stubs/osapi-utstub-network.c rename to src/ut-stubs/osapi-network-hooks.c index 549ffb8bc..9be4d42ab 100644 --- a/src/ut-stubs/osapi-utstub-network.c +++ b/src/ut-stubs/osapi-network-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,16 +33,18 @@ #include "osapi-network.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -UT_DEFAULT_STUB(OS_NetworkAPI_Init, (void)) - -int32 OS_NetworkGetHostName(char *host_name, size_t name_len) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_NetworkGetHostName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_NetworkGetHostName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - UT_Stub_RegisterContext(UT_KEY(OS_NetworkGetHostName), host_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_NetworkGetHostName), name_len); + char * host_name = UT_Hook_GetArgValueByName(Context, "host_name", char *); + size_t name_len = UT_Hook_GetArgValueByName(Context, "name_len", size_t); + int32 status; - int32 status; - - status = UT_DEFAULT_IMPL(OS_NetworkGetHostName); + UT_Stub_GetInt32StatusCode(Context, &status); if (status == OS_SUCCESS && name_len > 0 && UT_Stub_CopyToLocal(UT_KEY(OS_NetworkGetHostName), host_name, name_len) == 0) @@ -52,16 +52,4 @@ int32 OS_NetworkGetHostName(char *host_name, size_t name_len) strncpy(host_name, "ut", name_len - 1); host_name[name_len - 1] = 0; } - - return status; } - -int32 OS_NetworkGetID(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL(OS_NetworkGetID); - - return status; - -} /* end OS_NetworkGetID */ diff --git a/src/ut-stubs/osapi-network-stubs.c b/src/ut-stubs/osapi-network-stubs.c new file mode 100644 index 000000000..0fb889cbb --- /dev/null +++ b/src/ut-stubs/osapi-network-stubs.c @@ -0,0 +1,61 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-network header + */ + +#include "osapi-network.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_NetworkGetHostName(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NetworkGetHostName() + * ---------------------------------------------------- + */ +int32 OS_NetworkGetHostName(char *host_name, size_t name_len) +{ + UT_GenStub_SetupReturnBuffer(OS_NetworkGetHostName, int32); + + UT_GenStub_AddParam(OS_NetworkGetHostName, char *, host_name); + UT_GenStub_AddParam(OS_NetworkGetHostName, size_t, name_len); + + UT_GenStub_Execute(OS_NetworkGetHostName, Basic, UT_DefaultHandler_OS_NetworkGetHostName); + + return UT_GenStub_GetReturnValue(OS_NetworkGetHostName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NetworkGetID() + * ---------------------------------------------------- + */ +int32 OS_NetworkGetID(void) +{ + UT_GenStub_SetupReturnBuffer(OS_NetworkGetID, int32); + + UT_GenStub_Execute(OS_NetworkGetID, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_NetworkGetID, int32); +} diff --git a/src/ut-stubs/osapi-utstub-printf.c b/src/ut-stubs/osapi-printf-hooks.c similarity index 55% rename from src/ut-stubs/osapi-utstub-printf.c rename to src/ut-stubs/osapi-printf-hooks.c index 52d162bcc..d876e42e7 100644 --- a/src/ut-stubs/osapi-utstub-printf.c +++ b/src/ut-stubs/osapi-printf-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,46 +33,26 @@ #include "osapi-printf.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -int32 OS_ConsoleAPI_Init(void) -{ - return UT_DEFAULT_IMPL(OS_ConsoleAPI_Init); -} - -/***************************************************************************** - * - * Stub function for OS_ConsoleWrite() - * - *****************************************************************************/ -int32 OS_ConsoleWrite(uint32 console_id, const char *Str) -{ - UT_Stub_RegisterContext(UT_KEY(OS_ConsoleWrite), Str); - return UT_DEFAULT_IMPL(OS_ConsoleWrite); -} - -/***************************************************************************** - * - * Stub function for OS_printf() - * - *****************************************************************************/ -void OS_printf(const char *string, ...) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_printf' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_printf(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, va_list va) { - UT_Stub_RegisterContext(UT_KEY(OS_printf), string); + const char *string = UT_Hook_GetArgValueByName(Context, "string", const char *); + size_t length = strlen(string); + char str[128]; + va_list va_debugcopy; + int32 status; - int32 status; - size_t length = strlen(string); - va_list va; - char str[128]; + UT_Stub_GetInt32StatusCode(Context, &status); - /* Output the message when in debug mode */ - va_start(va, string); - vsnprintf(str, sizeof(str), string, va); + va_copy(va_debugcopy, va); + /* Output the message when in debug mode (uses a copy of the va list) */ + vsnprintf(str, sizeof(str), string, va_debugcopy); UtDebug("OS_printf: %s", str); - va_end(va); - - /* Reset va list for next use */ - va_start(va, string); - - status = UT_DefaultStubImplWithArgs(__func__, UT_KEY(OS_printf), 0, va); + va_end(va_debugcopy); if (status >= 0) { @@ -104,26 +82,4 @@ void OS_printf(const char *string, ...) UT_Stub_CopyFromLocal(UT_KEY(OS_printf), "\n", 1); } } - - va_end(va); -} - -/***************************************************************************** - * - * Stub function for OS_printf_disable() - * - *****************************************************************************/ -void OS_printf_disable(void) -{ - UT_DEFAULT_IMPL(OS_printf_disable); -} - -/***************************************************************************** - * - * Stub function for OS_printf_enable() - * - *****************************************************************************/ -void OS_printf_enable(void) -{ - UT_DEFAULT_IMPL(OS_printf_enable); } diff --git a/src/ut-stubs/osapi-printf-stubs.c b/src/ut-stubs/osapi-printf-stubs.c new file mode 100644 index 000000000..fd5e3145d --- /dev/null +++ b/src/ut-stubs/osapi-printf-stubs.c @@ -0,0 +1,70 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-printf header + */ + +#include + +#include "osapi-printf.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_printf(void *, UT_EntryKey_t, const UT_StubContext_t *, va_list); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_printf() + * ---------------------------------------------------- + */ +void OS_printf(const char *string, ...) +{ + va_list UtStub_ArgList; + + UT_GenStub_AddParam(OS_printf, const char *, string); + + va_start(UtStub_ArgList, string); + UT_GenStub_Execute(OS_printf, Va, UT_DefaultHandler_OS_printf, UtStub_ArgList); + va_end(UtStub_ArgList); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_printf_disable() + * ---------------------------------------------------- + */ +void OS_printf_disable(void) +{ + + UT_GenStub_Execute(OS_printf_disable, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_printf_enable() + * ---------------------------------------------------- + */ +void OS_printf_enable(void) +{ + + UT_GenStub_Execute(OS_printf_enable, Basic, NULL); +} diff --git a/src/ut-stubs/osapi-queue-hooks.c b/src/ut-stubs/osapi-queue-hooks.c new file mode 100644 index 000000000..a7bc4a951 --- /dev/null +++ b/src/ut-stubs/osapi-queue-hooks.c @@ -0,0 +1,160 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-queue.h" /* OSAL public API for this subsystem */ +#include "osapi-idmap.h" +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueueCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueueCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *queue_id = UT_Hook_GetArgValueByName(Context, "queue_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *queue_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_QUEUE); + } + else + { + *queue_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueueDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueueDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t queue_id = UT_Hook_GetArgValueByName(Context, "queue_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_QUEUE, queue_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueueGet' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueueGet(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t queue_id = UT_Hook_GetArgValueByName(Context, "queue_id", osal_id_t); + void * data = UT_Hook_GetArgValueByName(Context, "data", void *); + size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + size_t * size_copied = UT_Hook_GetArgValueByName(Context, "size_copied", size_t *); + int32 status; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + *size_copied = UT_Stub_CopyToLocal((UT_EntryKey_t)OS_ObjectIdToInteger(queue_id), data, size); + if (*size_copied == 0) + { + status = OS_QUEUE_EMPTY; + } + + UT_Stub_SetReturnValue(FuncKey, status); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueuePut' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueuePut(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t queue_id = UT_Hook_GetArgValueByName(Context, "queue_id", osal_id_t); + const void *data = UT_Hook_GetArgValueByName(Context, "data", const void *); + size_t size = UT_Hook_GetArgValueByName(Context, "size", size_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_SetDataBuffer((UT_EntryKey_t)OS_ObjectIdToInteger(queue_id), (void *)data, size, true); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueueGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueueGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *queue_id = UT_Hook_GetArgValueByName(Context, "queue_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetIdByName), queue_id, sizeof(*queue_id)) < sizeof(*queue_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_QUEUE, queue_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_QueueGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_QueueGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_queue_prop_t *queue_prop = UT_Hook_GetArgValueByName(Context, "queue_prop", OS_queue_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetInfo), queue_prop, sizeof(*queue_prop)) < sizeof(*queue_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &queue_prop->creator); + strncpy(queue_prop->name, "Name", sizeof(queue_prop->name) - 1); + queue_prop->name[sizeof(queue_prop->name) - 1] = '\0'; + } +} diff --git a/src/ut-stubs/osapi-queue-stubs.c b/src/ut-stubs/osapi-queue-stubs.c new file mode 100644 index 000000000..cb8230fd9 --- /dev/null +++ b/src/ut-stubs/osapi-queue-stubs.c @@ -0,0 +1,145 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-queue header + */ + +#include "osapi-queue.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_QueueCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_QueueDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_QueueGet(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_QueueGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_QueueGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_QueuePut(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueCreate() + * ---------------------------------------------------- + */ +int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, + uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueCreate, int32); + + UT_GenStub_AddParam(OS_QueueCreate, osal_id_t *, queue_id); + UT_GenStub_AddParam(OS_QueueCreate, const char *, queue_name); + UT_GenStub_AddParam(OS_QueueCreate, osal_blockcount_t, queue_depth); + UT_GenStub_AddParam(OS_QueueCreate, size_t, data_size); + UT_GenStub_AddParam(OS_QueueCreate, uint32, flags); + + UT_GenStub_Execute(OS_QueueCreate, Basic, UT_DefaultHandler_OS_QueueCreate); + + return UT_GenStub_GetReturnValue(OS_QueueCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueDelete() + * ---------------------------------------------------- + */ +int32 OS_QueueDelete(osal_id_t queue_id) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueDelete, int32); + + UT_GenStub_AddParam(OS_QueueDelete, osal_id_t, queue_id); + + UT_GenStub_Execute(OS_QueueDelete, Basic, UT_DefaultHandler_OS_QueueDelete); + + return UT_GenStub_GetReturnValue(OS_QueueDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueGet() + * ---------------------------------------------------- + */ +int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueGet, int32); + + UT_GenStub_AddParam(OS_QueueGet, osal_id_t, queue_id); + UT_GenStub_AddParam(OS_QueueGet, void *, data); + UT_GenStub_AddParam(OS_QueueGet, size_t, size); + UT_GenStub_AddParam(OS_QueueGet, size_t *, size_copied); + UT_GenStub_AddParam(OS_QueueGet, int32, timeout); + + UT_GenStub_Execute(OS_QueueGet, Basic, UT_DefaultHandler_OS_QueueGet); + + return UT_GenStub_GetReturnValue(OS_QueueGet, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueGetIdByName, int32); + + UT_GenStub_AddParam(OS_QueueGetIdByName, osal_id_t *, queue_id); + UT_GenStub_AddParam(OS_QueueGetIdByName, const char *, queue_name); + + UT_GenStub_Execute(OS_QueueGetIdByName, Basic, UT_DefaultHandler_OS_QueueGetIdByName); + + return UT_GenStub_GetReturnValue(OS_QueueGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueGetInfo() + * ---------------------------------------------------- + */ +int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueGetInfo, int32); + + UT_GenStub_AddParam(OS_QueueGetInfo, osal_id_t, queue_id); + UT_GenStub_AddParam(OS_QueueGetInfo, OS_queue_prop_t *, queue_prop); + + UT_GenStub_Execute(OS_QueueGetInfo, Basic, UT_DefaultHandler_OS_QueueGetInfo); + + return UT_GenStub_GetReturnValue(OS_QueueGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueuePut() + * ---------------------------------------------------- + */ +int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_QueuePut, int32); + + UT_GenStub_AddParam(OS_QueuePut, osal_id_t, queue_id); + UT_GenStub_AddParam(OS_QueuePut, const void *, data); + UT_GenStub_AddParam(OS_QueuePut, size_t, size); + UT_GenStub_AddParam(OS_QueuePut, uint32, flags); + + UT_GenStub_Execute(OS_QueuePut, Basic, UT_DefaultHandler_OS_QueuePut); + + return UT_GenStub_GetReturnValue(OS_QueuePut, int32); +} diff --git a/src/ut-stubs/osapi-select-stubs.c b/src/ut-stubs/osapi-select-stubs.c new file mode 100644 index 000000000..9b9375965 --- /dev/null +++ b/src/ut-stubs/osapi-select-stubs.c @@ -0,0 +1,131 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-select header + */ + +#include "osapi-select.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectFdAdd() + * ---------------------------------------------------- + */ +int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectFdAdd, int32); + + UT_GenStub_AddParam(OS_SelectFdAdd, OS_FdSet *, Set); + UT_GenStub_AddParam(OS_SelectFdAdd, osal_id_t, objid); + + UT_GenStub_Execute(OS_SelectFdAdd, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectFdAdd, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectFdClear() + * ---------------------------------------------------- + */ +int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectFdClear, int32); + + UT_GenStub_AddParam(OS_SelectFdClear, OS_FdSet *, Set); + UT_GenStub_AddParam(OS_SelectFdClear, osal_id_t, objid); + + UT_GenStub_Execute(OS_SelectFdClear, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectFdClear, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectFdIsSet() + * ---------------------------------------------------- + */ +bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectFdIsSet, bool); + + UT_GenStub_AddParam(OS_SelectFdIsSet, OS_FdSet *, Set); + UT_GenStub_AddParam(OS_SelectFdIsSet, osal_id_t, objid); + + UT_GenStub_Execute(OS_SelectFdIsSet, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectFdIsSet, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectFdZero() + * ---------------------------------------------------- + */ +int32 OS_SelectFdZero(OS_FdSet *Set) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectFdZero, int32); + + UT_GenStub_AddParam(OS_SelectFdZero, OS_FdSet *, Set); + + UT_GenStub_Execute(OS_SelectFdZero, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectFdZero, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectMultiple() + * ---------------------------------------------------- + */ +int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectMultiple, int32); + + UT_GenStub_AddParam(OS_SelectMultiple, OS_FdSet *, ReadSet); + UT_GenStub_AddParam(OS_SelectMultiple, OS_FdSet *, WriteSet); + UT_GenStub_AddParam(OS_SelectMultiple, int32, msecs); + + UT_GenStub_Execute(OS_SelectMultiple, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectMultiple, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectSingle() + * ---------------------------------------------------- + */ +int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectSingle, int32); + + UT_GenStub_AddParam(OS_SelectSingle, osal_id_t, objid); + UT_GenStub_AddParam(OS_SelectSingle, uint32 *, StateFlags); + UT_GenStub_AddParam(OS_SelectSingle, int32, msecs); + + UT_GenStub_Execute(OS_SelectSingle, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectSingle, int32); +} diff --git a/src/ut-stubs/osapi-sockets-hooks.c b/src/ut-stubs/osapi-sockets-hooks.c new file mode 100644 index 000000000..b40926881 --- /dev/null +++ b/src/ut-stubs/osapi-sockets-hooks.c @@ -0,0 +1,242 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-sockets.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketOpen' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketOpen(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sock_id = UT_Hook_GetArgValueByName(Context, "sock_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *sock_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketRecvFrom' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketRecvFrom(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + void * buffer = UT_Hook_GetArgValueByName(Context, "buffer", void *); + size_t buflen = UT_Hook_GetArgValueByName(Context, "buflen", size_t); + int32 status; + size_t CopySize; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketRecvFrom), buffer, buflen); + + /* If CopyToLocal returns zero, this probably means no buffer was supplied, + * in which case just generate fill data and pretend it was read. + */ + if (CopySize > 0) + { + status = CopySize; + } + else + { + memset(buffer, 0, buflen); + status = buflen; + } + } + else if (status > 0) + { + /* generate fill data for requested size */ + memset(buffer, 0, status); + } + + UT_Stub_SetReturnValue(FuncKey, status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketSendTo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketSendTo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + const void *buffer = UT_Hook_GetArgValueByName(Context, "buffer", const void *); + size_t buflen = UT_Hook_GetArgValueByName(Context, "buflen", size_t); + int32 status; + size_t CopySize; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + CopySize = UT_Stub_CopyFromLocal(UT_KEY(OS_SocketSendTo), buffer, buflen); + + /* If CopyFromLocal returns zero, this probably means no buffer was supplied, + * in which case just throw out the data and pretend it was written. + */ + if (CopySize > 0) + { + status = CopySize; + } + else + { + status = buflen; + } + } + + UT_Stub_SetReturnValue(FuncKey, status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *sock_id = UT_Hook_GetArgValueByName(Context, "sock_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetIdByName), sock_id, sizeof(*sock_id)) < sizeof(*sock_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_STREAM, sock_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_socket_prop_t *sock_prop = UT_Hook_GetArgValueByName(Context, "sock_prop", OS_socket_prop_t *); + int32 status; + size_t CopySize; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + /* The user may supply specific entries to return */ + CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetInfo), sock_prop, sizeof(*sock_prop)); + if (CopySize < sizeof(*sock_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &sock_prop->creator); + strncpy(sock_prop->name, "ut", sizeof(sock_prop->name) - 1); + sock_prop->name[sizeof(sock_prop->name) - 1] = 0; + } + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketAddrInit' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketAddrInit(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_SockAddr_t *Addr = UT_Hook_GetArgValueByName(Context, "Addr", OS_SockAddr_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrInit), Addr, sizeof(*Addr)) < sizeof(*Addr)) + { + memset(Addr, 0, sizeof(*Addr)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketAddrToString' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketAddrToString(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + char * buffer = UT_Hook_GetArgValueByName(Context, "buffer", char *); + size_t buflen = UT_Hook_GetArgValueByName(Context, "buflen", size_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && buflen > 0 && UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrToString), buffer, buflen) == 0) + { + strncpy(buffer, "UT-addr", buflen - 1); + buffer[buflen - 1] = 0; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketAddrFromString' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketAddrFromString(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_SockAddr_t *Addr = UT_Hook_GetArgValueByName(Context, "Addr", OS_SockAddr_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrFromString), Addr, sizeof(*Addr)) < sizeof(*Addr)) + { + memset(Addr, 0, sizeof(*Addr)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_SocketAddrGetPort' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_SocketAddrGetPort(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + uint16 *PortNum = UT_Hook_GetArgValueByName(Context, "PortNum", uint16 *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrGetPort), PortNum, sizeof(*PortNum)) < sizeof(*PortNum)) + { + *PortNum = 0; + } +} diff --git a/src/ut-stubs/osapi-sockets-stubs.c b/src/ut-stubs/osapi-sockets-stubs.c new file mode 100644 index 000000000..c515f8bdb --- /dev/null +++ b/src/ut-stubs/osapi-sockets-stubs.c @@ -0,0 +1,269 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-sockets header + */ + +#include "osapi-sockets.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_SocketAddrFromString(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketAddrGetPort(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketAddrInit(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketAddrToString(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketOpen(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketRecvFrom(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_SocketSendTo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAccept() + * ---------------------------------------------------- + */ +int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAccept, int32); + + UT_GenStub_AddParam(OS_SocketAccept, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketAccept, osal_id_t *, connsock_id); + UT_GenStub_AddParam(OS_SocketAccept, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAccept, int32, timeout); + + UT_GenStub_Execute(OS_SocketAccept, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAccept, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrFromString() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrFromString, int32); + + UT_GenStub_AddParam(OS_SocketAddrFromString, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrFromString, const char *, string); + + UT_GenStub_Execute(OS_SocketAddrFromString, Basic, UT_DefaultHandler_OS_SocketAddrFromString); + + return UT_GenStub_GetReturnValue(OS_SocketAddrFromString, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrGetPort() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrGetPort, int32); + + UT_GenStub_AddParam(OS_SocketAddrGetPort, uint16 *, PortNum); + UT_GenStub_AddParam(OS_SocketAddrGetPort, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketAddrGetPort, Basic, UT_DefaultHandler_OS_SocketAddrGetPort); + + return UT_GenStub_GetReturnValue(OS_SocketAddrGetPort, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrInit() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrInit, int32); + + UT_GenStub_AddParam(OS_SocketAddrInit, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrInit, OS_SocketDomain_t, Domain); + + UT_GenStub_Execute(OS_SocketAddrInit, Basic, UT_DefaultHandler_OS_SocketAddrInit); + + return UT_GenStub_GetReturnValue(OS_SocketAddrInit, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrSetPort() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrSetPort, int32); + + UT_GenStub_AddParam(OS_SocketAddrSetPort, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrSetPort, uint16, PortNum); + + UT_GenStub_Execute(OS_SocketAddrSetPort, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrSetPort, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrToString() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrToString, int32); + + UT_GenStub_AddParam(OS_SocketAddrToString, char *, buffer); + UT_GenStub_AddParam(OS_SocketAddrToString, size_t, buflen); + UT_GenStub_AddParam(OS_SocketAddrToString, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketAddrToString, Basic, UT_DefaultHandler_OS_SocketAddrToString); + + return UT_GenStub_GetReturnValue(OS_SocketAddrToString, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketBind() + * ---------------------------------------------------- + */ +int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketBind, int32); + + UT_GenStub_AddParam(OS_SocketBind, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketBind, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketBind, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketBind, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketConnect() + * ---------------------------------------------------- + */ +int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketConnect, int32); + + UT_GenStub_AddParam(OS_SocketConnect, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketConnect, const OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketConnect, int32, timeout); + + UT_GenStub_Execute(OS_SocketConnect, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketConnect, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketGetIdByName, int32); + + UT_GenStub_AddParam(OS_SocketGetIdByName, osal_id_t *, sock_id); + UT_GenStub_AddParam(OS_SocketGetIdByName, const char *, sock_name); + + UT_GenStub_Execute(OS_SocketGetIdByName, Basic, UT_DefaultHandler_OS_SocketGetIdByName); + + return UT_GenStub_GetReturnValue(OS_SocketGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketGetInfo() + * ---------------------------------------------------- + */ +int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketGetInfo, int32); + + UT_GenStub_AddParam(OS_SocketGetInfo, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketGetInfo, OS_socket_prop_t *, sock_prop); + + UT_GenStub_Execute(OS_SocketGetInfo, Basic, UT_DefaultHandler_OS_SocketGetInfo); + + return UT_GenStub_GetReturnValue(OS_SocketGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketOpen() + * ---------------------------------------------------- + */ +int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketOpen, int32); + + UT_GenStub_AddParam(OS_SocketOpen, osal_id_t *, sock_id); + UT_GenStub_AddParam(OS_SocketOpen, OS_SocketDomain_t, Domain); + UT_GenStub_AddParam(OS_SocketOpen, OS_SocketType_t, Type); + + UT_GenStub_Execute(OS_SocketOpen, Basic, UT_DefaultHandler_OS_SocketOpen); + + return UT_GenStub_GetReturnValue(OS_SocketOpen, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketRecvFrom() + * ---------------------------------------------------- + */ +int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketRecvFrom, int32); + + UT_GenStub_AddParam(OS_SocketRecvFrom, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketRecvFrom, void *, buffer); + UT_GenStub_AddParam(OS_SocketRecvFrom, size_t, buflen); + UT_GenStub_AddParam(OS_SocketRecvFrom, OS_SockAddr_t *, RemoteAddr); + UT_GenStub_AddParam(OS_SocketRecvFrom, int32, timeout); + + UT_GenStub_Execute(OS_SocketRecvFrom, Basic, UT_DefaultHandler_OS_SocketRecvFrom); + + return UT_GenStub_GetReturnValue(OS_SocketRecvFrom, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketSendTo() + * ---------------------------------------------------- + */ +int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketSendTo, int32); + + UT_GenStub_AddParam(OS_SocketSendTo, osal_id_t, sock_id); + UT_GenStub_AddParam(OS_SocketSendTo, const void *, buffer); + UT_GenStub_AddParam(OS_SocketSendTo, size_t, buflen); + UT_GenStub_AddParam(OS_SocketSendTo, const OS_SockAddr_t *, RemoteAddr); + + UT_GenStub_Execute(OS_SocketSendTo, Basic, UT_DefaultHandler_OS_SocketSendTo); + + return UT_GenStub_GetReturnValue(OS_SocketSendTo, int32); +} diff --git a/src/ut-stubs/osapi-task-hooks.c b/src/ut-stubs/osapi-task-hooks.c new file mode 100644 index 000000000..1b5577dd7 --- /dev/null +++ b/src/ut-stubs/osapi-task-hooks.c @@ -0,0 +1,156 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-task.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *task_id = UT_Hook_GetArgValueByName(Context, "task_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *task_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TASK); + } + else + { + *task_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t task_id = UT_Hook_GetArgValueByName(Context, "task_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TASK, task_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskGetId' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskGetId(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t TaskId; + int32 status; + + /* Unless set otherwise this returns a task ID that correlates to table position 1. + * This is for historical reasons, many old test cases assume this is the default */ + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + status = 1; + } + UT_ObjIdCompose(status, OS_OBJECT_TYPE_OS_TASK, &TaskId); + + UT_Stub_SetReturnValue(FuncKey, TaskId); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *task_id = UT_Hook_GetArgValueByName(Context, "task_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetIdByName), task_id, sizeof(*task_id)) < sizeof(*task_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_task_prop_t *task_prop = UT_Hook_GetArgValueByName(Context, "task_prop", OS_task_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetInfo), task_prop, sizeof(*task_prop)) < sizeof(*task_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &task_prop->creator); + task_prop->stack_size = OSAL_SIZE_C(100); + task_prop->priority = OSAL_PRIORITY_C(150); + strncpy(task_prop->name, "UnitTest", sizeof(task_prop->name) - 1); + task_prop->name[sizeof(task_prop->name) - 1] = '\0'; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TaskFindIdBySystemData' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TaskFindIdBySystemData(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *task_id = UT_Hook_GetArgValueByName(Context, "task_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TaskFindIdBySystemData), task_id, sizeof(*task_id)) < sizeof(*task_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); + } +} diff --git a/src/ut-stubs/osapi-task-stubs.c b/src/ut-stubs/osapi-task-stubs.c new file mode 100644 index 000000000..22e46325a --- /dev/null +++ b/src/ut-stubs/osapi-task-stubs.c @@ -0,0 +1,200 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-task header + */ + +#include "osapi-task.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_TaskCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TaskDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TaskFindIdBySystemData(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TaskGetId(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TaskGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TaskGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskCreate() + * ---------------------------------------------------- + */ +int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, + osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskCreate, int32); + + UT_GenStub_AddParam(OS_TaskCreate, osal_id_t *, task_id); + UT_GenStub_AddParam(OS_TaskCreate, const char *, task_name); + UT_GenStub_AddParam(OS_TaskCreate, osal_task_entry, function_pointer); + UT_GenStub_AddParam(OS_TaskCreate, osal_stackptr_t, stack_pointer); + UT_GenStub_AddParam(OS_TaskCreate, size_t, stack_size); + UT_GenStub_AddParam(OS_TaskCreate, osal_priority_t, priority); + UT_GenStub_AddParam(OS_TaskCreate, uint32, flags); + + UT_GenStub_Execute(OS_TaskCreate, Basic, UT_DefaultHandler_OS_TaskCreate); + + return UT_GenStub_GetReturnValue(OS_TaskCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskDelay() + * ---------------------------------------------------- + */ +int32 OS_TaskDelay(uint32 millisecond) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskDelay, int32); + + UT_GenStub_AddParam(OS_TaskDelay, uint32, millisecond); + + UT_GenStub_Execute(OS_TaskDelay, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskDelay, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskDelete() + * ---------------------------------------------------- + */ +int32 OS_TaskDelete(osal_id_t task_id) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskDelete, int32); + + UT_GenStub_AddParam(OS_TaskDelete, osal_id_t, task_id); + + UT_GenStub_Execute(OS_TaskDelete, Basic, UT_DefaultHandler_OS_TaskDelete); + + return UT_GenStub_GetReturnValue(OS_TaskDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskExit() + * ---------------------------------------------------- + */ +void OS_TaskExit(void) +{ + + UT_GenStub_Execute(OS_TaskExit, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskFindIdBySystemData() + * ---------------------------------------------------- + */ +int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskFindIdBySystemData, int32); + + UT_GenStub_AddParam(OS_TaskFindIdBySystemData, osal_id_t *, task_id); + UT_GenStub_AddParam(OS_TaskFindIdBySystemData, const void *, sysdata); + UT_GenStub_AddParam(OS_TaskFindIdBySystemData, size_t, sysdata_size); + + UT_GenStub_Execute(OS_TaskFindIdBySystemData, Basic, UT_DefaultHandler_OS_TaskFindIdBySystemData); + + return UT_GenStub_GetReturnValue(OS_TaskFindIdBySystemData, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskGetId() + * ---------------------------------------------------- + */ +osal_id_t OS_TaskGetId(void) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskGetId, osal_id_t); + + UT_GenStub_Execute(OS_TaskGetId, Basic, UT_DefaultHandler_OS_TaskGetId); + + return UT_GenStub_GetReturnValue(OS_TaskGetId, osal_id_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskGetIdByName, int32); + + UT_GenStub_AddParam(OS_TaskGetIdByName, osal_id_t *, task_id); + UT_GenStub_AddParam(OS_TaskGetIdByName, const char *, task_name); + + UT_GenStub_Execute(OS_TaskGetIdByName, Basic, UT_DefaultHandler_OS_TaskGetIdByName); + + return UT_GenStub_GetReturnValue(OS_TaskGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskGetInfo() + * ---------------------------------------------------- + */ +int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskGetInfo, int32); + + UT_GenStub_AddParam(OS_TaskGetInfo, osal_id_t, task_id); + UT_GenStub_AddParam(OS_TaskGetInfo, OS_task_prop_t *, task_prop); + + UT_GenStub_Execute(OS_TaskGetInfo, Basic, UT_DefaultHandler_OS_TaskGetInfo); + + return UT_GenStub_GetReturnValue(OS_TaskGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskInstallDeleteHandler() + * ---------------------------------------------------- + */ +int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskInstallDeleteHandler, int32); + + UT_GenStub_AddParam(OS_TaskInstallDeleteHandler, osal_task_entry, function_pointer); + + UT_GenStub_Execute(OS_TaskInstallDeleteHandler, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskInstallDeleteHandler, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskSetPriority() + * ---------------------------------------------------- + */ +int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskSetPriority, int32); + + UT_GenStub_AddParam(OS_TaskSetPriority, osal_id_t, task_id); + UT_GenStub_AddParam(OS_TaskSetPriority, osal_priority_t, new_priority); + + UT_GenStub_Execute(OS_TaskSetPriority, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskSetPriority, int32); +} diff --git a/src/ut-stubs/osapi-timebase-hooks.c b/src/ut-stubs/osapi-timebase-hooks.c new file mode 100644 index 000000000..3d6e0fc3d --- /dev/null +++ b/src/ut-stubs/osapi-timebase-hooks.c @@ -0,0 +1,136 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-timebase.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimeBaseCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimeBaseCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *timebase_id = UT_Hook_GetArgValueByName(Context, "timebase_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *timebase_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE); + } + else + { + *timebase_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimeBaseDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimeBaseDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t timebase_id = UT_Hook_GetArgValueByName(Context, "timebase_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimeBaseGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimeBaseGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *timebase_id = UT_Hook_GetArgValueByName(Context, "timebase_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetIdByName), timebase_id, sizeof(*timebase_id)) < sizeof(*timebase_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimeBaseGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimeBaseGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_timebase_prop_t *timebase_prop = UT_Hook_GetArgValueByName(Context, "timebase_prop", OS_timebase_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetInfo), timebase_prop, sizeof(*timebase_prop)) < sizeof(*timebase_prop)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timebase_prop->creator); + strncpy(timebase_prop->name, "Name", sizeof(timebase_prop->name) - 1); + timebase_prop->name[sizeof(timebase_prop->name) - 1] = '\0'; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimeBaseGetFreeRun' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimeBaseGetFreeRun(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + uint32 *freerun_val = UT_Hook_GetArgValueByName(Context, "freerun_val", uint32 *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetFreeRun), freerun_val, sizeof(*freerun_val)) < sizeof(*freerun_val)) + { + /* + * Use the call count such that the value increases with each successive call. + */ + *freerun_val = UT_GetStubCount(FuncKey); + } +} diff --git a/src/ut-stubs/osapi-timebase-stubs.c b/src/ut-stubs/osapi-timebase-stubs.c new file mode 100644 index 000000000..c1e3439dc --- /dev/null +++ b/src/ut-stubs/osapi-timebase-stubs.c @@ -0,0 +1,137 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-timebase header + */ + +#include "osapi-timebase.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_TimeBaseCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimeBaseDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimeBaseGetFreeRun(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimeBaseGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimeBaseGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseCreate() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t al_sync) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseCreate, int32); + + UT_GenStub_AddParam(OS_TimeBaseCreate, osal_id_t *, timebase_id); + UT_GenStub_AddParam(OS_TimeBaseCreate, const char *, timebase_name); + UT_GenStub_AddParam(OS_TimeBaseCreate, OS_TimerSync_t, al_sync); + + UT_GenStub_Execute(OS_TimeBaseCreate, Basic, UT_DefaultHandler_OS_TimeBaseCreate); + + return UT_GenStub_GetReturnValue(OS_TimeBaseCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseDelete() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseDelete(osal_id_t timebase_id) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseDelete, int32); + + UT_GenStub_AddParam(OS_TimeBaseDelete, osal_id_t, timebase_id); + + UT_GenStub_Execute(OS_TimeBaseDelete, Basic, UT_DefaultHandler_OS_TimeBaseDelete); + + return UT_GenStub_GetReturnValue(OS_TimeBaseDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseGetFreeRun() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseGetFreeRun, int32); + + UT_GenStub_AddParam(OS_TimeBaseGetFreeRun, osal_id_t, timebase_id); + UT_GenStub_AddParam(OS_TimeBaseGetFreeRun, uint32 *, freerun_val); + + UT_GenStub_Execute(OS_TimeBaseGetFreeRun, Basic, UT_DefaultHandler_OS_TimeBaseGetFreeRun); + + return UT_GenStub_GetReturnValue(OS_TimeBaseGetFreeRun, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseGetIdByName, int32); + + UT_GenStub_AddParam(OS_TimeBaseGetIdByName, osal_id_t *, timebase_id); + UT_GenStub_AddParam(OS_TimeBaseGetIdByName, const char *, timebase_name); + + UT_GenStub_Execute(OS_TimeBaseGetIdByName, Basic, UT_DefaultHandler_OS_TimeBaseGetIdByName); + + return UT_GenStub_GetReturnValue(OS_TimeBaseGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseGetInfo() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseGetInfo, int32); + + UT_GenStub_AddParam(OS_TimeBaseGetInfo, osal_id_t, timebase_id); + UT_GenStub_AddParam(OS_TimeBaseGetInfo, OS_timebase_prop_t *, timebase_prop); + + UT_GenStub_Execute(OS_TimeBaseGetInfo, Basic, UT_DefaultHandler_OS_TimeBaseGetInfo); + + return UT_GenStub_GetReturnValue(OS_TimeBaseGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseSet() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseSet(osal_id_t timebase_id, uint32 start_time, uint32 interval_time) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseSet, int32); + + UT_GenStub_AddParam(OS_TimeBaseSet, osal_id_t, timebase_id); + UT_GenStub_AddParam(OS_TimeBaseSet, uint32, start_time); + UT_GenStub_AddParam(OS_TimeBaseSet, uint32, interval_time); + + UT_GenStub_Execute(OS_TimeBaseSet, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseSet, int32); +} diff --git a/src/ut-stubs/osapi-timer-hooks.c b/src/ut-stubs/osapi-timer-hooks.c new file mode 100644 index 000000000..1b5f74fa7 --- /dev/null +++ b/src/ut-stubs/osapi-timer-hooks.c @@ -0,0 +1,135 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file + * + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-timer.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimerAdd' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimerAdd(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *timer_id = UT_Hook_GetArgValueByName(Context, "timer_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); + } + else + { + *timer_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimerCreate' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimerCreate(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *timer_id = UT_Hook_GetArgValueByName(Context, "timer_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); + } + else + { + *timer_id = UT_STUB_FAKE_OBJECT_ID; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimerDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimerDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t timer_id = UT_Hook_GetArgValueByName(Context, "timer_id", osal_id_t); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS) + { + UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMECB, timer_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimerGetIdByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimerGetIdByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_id_t *timer_id = UT_Hook_GetArgValueByName(Context, "timer_id", osal_id_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetIdByName), timer_id, sizeof(*timer_id)) < sizeof(*timer_id)) + { + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMECB, timer_id); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_TimerGetInfo' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_TimerGetInfo(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_timer_prop_t *timer_prop = UT_Hook_GetArgValueByName(Context, "timer_prop", OS_timer_prop_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetInfo), timer_prop, sizeof(*timer_prop)) < sizeof(*timer_prop)) + { + memset(timer_prop, 0, sizeof(*timer_prop)); + UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timer_prop->creator); + } +} diff --git a/src/ut-stubs/osapi-timer-stubs.c b/src/ut-stubs/osapi-timer-stubs.c new file mode 100644 index 000000000..091e67971 --- /dev/null +++ b/src/ut-stubs/osapi-timer-stubs.c @@ -0,0 +1,143 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-timer header + */ + +#include "osapi-timer.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_TimerAdd(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimerCreate(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimerDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimerGetIdByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_TimerGetInfo(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerAdd() + * ---------------------------------------------------- + */ +int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_id, OS_ArgCallback_t callback_ptr, + void *callback_arg) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerAdd, int32); + + UT_GenStub_AddParam(OS_TimerAdd, osal_id_t *, timer_id); + UT_GenStub_AddParam(OS_TimerAdd, const char *, timer_name); + UT_GenStub_AddParam(OS_TimerAdd, osal_id_t, timebase_id); + UT_GenStub_AddParam(OS_TimerAdd, OS_ArgCallback_t, callback_ptr); + UT_GenStub_AddParam(OS_TimerAdd, void *, callback_arg); + + UT_GenStub_Execute(OS_TimerAdd, Basic, UT_DefaultHandler_OS_TimerAdd); + + return UT_GenStub_GetReturnValue(OS_TimerAdd, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerCreate() + * ---------------------------------------------------- + */ +int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_accuracy, + OS_TimerCallback_t callback_ptr) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerCreate, int32); + + UT_GenStub_AddParam(OS_TimerCreate, osal_id_t *, timer_id); + UT_GenStub_AddParam(OS_TimerCreate, const char *, timer_name); + UT_GenStub_AddParam(OS_TimerCreate, uint32 *, clock_accuracy); + UT_GenStub_AddParam(OS_TimerCreate, OS_TimerCallback_t, callback_ptr); + + UT_GenStub_Execute(OS_TimerCreate, Basic, UT_DefaultHandler_OS_TimerCreate); + + return UT_GenStub_GetReturnValue(OS_TimerCreate, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerDelete() + * ---------------------------------------------------- + */ +int32 OS_TimerDelete(osal_id_t timer_id) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerDelete, int32); + + UT_GenStub_AddParam(OS_TimerDelete, osal_id_t, timer_id); + + UT_GenStub_Execute(OS_TimerDelete, Basic, UT_DefaultHandler_OS_TimerDelete); + + return UT_GenStub_GetReturnValue(OS_TimerDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerGetIdByName() + * ---------------------------------------------------- + */ +int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerGetIdByName, int32); + + UT_GenStub_AddParam(OS_TimerGetIdByName, osal_id_t *, timer_id); + UT_GenStub_AddParam(OS_TimerGetIdByName, const char *, timer_name); + + UT_GenStub_Execute(OS_TimerGetIdByName, Basic, UT_DefaultHandler_OS_TimerGetIdByName); + + return UT_GenStub_GetReturnValue(OS_TimerGetIdByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerGetInfo() + * ---------------------------------------------------- + */ +int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerGetInfo, int32); + + UT_GenStub_AddParam(OS_TimerGetInfo, osal_id_t, timer_id); + UT_GenStub_AddParam(OS_TimerGetInfo, OS_timer_prop_t *, timer_prop); + + UT_GenStub_Execute(OS_TimerGetInfo, Basic, UT_DefaultHandler_OS_TimerGetInfo); + + return UT_GenStub_GetReturnValue(OS_TimerGetInfo, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerSet() + * ---------------------------------------------------- + */ +int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerSet, int32); + + UT_GenStub_AddParam(OS_TimerSet, osal_id_t, timer_id); + UT_GenStub_AddParam(OS_TimerSet, uint32, start_time); + UT_GenStub_AddParam(OS_TimerSet, uint32, interval_time); + + UT_GenStub_Execute(OS_TimerSet, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimerSet, int32); +} diff --git a/src/ut-stubs/osapi-utstub-binsem.c b/src/ut-stubs/osapi-utstub-binsem.c deleted file mode 100644 index f2f1c746e..000000000 --- a/src/ut-stubs/osapi-utstub-binsem.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-binsem.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_BinSemAPI_Init, (void)) - -/*****************************************************************************/ -/** -** \brief OS_BinSemTake stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemTake. The user can adjust the response by setting -** the value of UT_BinSemFail, causing it to return a failure -** indication (-1) on the first or second call to the function. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either -1 or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_BinSemTake(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTake), sem_id); - - int32 status = OS_SUCCESS; - - status = UT_DEFAULT_IMPL(OS_BinSemTake); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemFlush stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemFlush. The variable OSBinSemFlushRtn.value is set to the -** value passed to the function, reset_type, and the variable -** OSBinSemFlushRtn.count is incremented each time this function is -** called. The unit tests compare these values to expected results to -** verify proper system response. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_BinSemFlush(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemFlush), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemFlush); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemCreate stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemCreate. The user can adjust the response by setting the -** values in the OS_BinSemCreateRtn structure prior to this function -** being called. If the value OS_BinSemCreateRtn.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 -** OS_BinSemCreateRtn.value. Alternately, the user can cause the -** function to return a failure result, OS_ERROR, by setting the value -** of UT_OS_Fail to OS_SEMCREATE_FAIL prior to this function being -** called. OS_SUCCESS is returned otherwise. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either a user-defined status flag, OS_ERROR, or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) -{ - UT_Stub_RegisterContext(UT_KEY(OS_BinSemCreate), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_BinSemCreate), sem_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemCreate), sem_initial_value); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemCreate), options); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemCreate); - - if (status == OS_SUCCESS) - { - *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_BINSEM); - } - else - { - *sem_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemGive stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemGive. The user can adjust the response by setting the value -** of UT_BinSemFail prior to this function being called. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns the user-defined value UT_BinSemFail. -** -******************************************************************************/ -int32 OS_BinSemGive(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemGive), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemGive); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemGetInfo. It sets the binary semaphore structure variables -** to fixed values and returns OS_SUCCESS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemGetInfo), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetInfo), bin_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetInfo), bin_prop, sizeof(*bin_prop)) < sizeof(*bin_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &bin_prop->creator); - strncpy(bin_prop->name, "Name", sizeof(bin_prop->name) - 1); - bin_prop->name[sizeof(bin_prop->name) - 1] = '\0'; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemDelete stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemDelete. The user can adjust the response by setting -** the values in the BinSemDelRtn structure prior to this function -** being called. If the value BinSemDelRtn.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 BinSemDelRtn.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 OS_BinSemDelete(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemDelete), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_BINSEM, sem_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_BinSemTimedWait stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_BinSemTimedWait. The variable OSBinSemTimedWaitRtn.value is set -** to the value passed to the function, reset_type, and the variable -** OSBinSemTimedWaitRtn.count is incremented each time this function is -** called. The unit tests compare these values to expected results to -** verify proper system response. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_BinSemTimedWait(osal_id_t sem_id, uint32 msecs) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTimedWait), sem_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_BinSemTimedWait), msecs); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemTimedWait); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_BinSemGetIdByName() - * - *****************************************************************************/ -int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetIdByName), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_BinSemGetIdByName), sem_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_BinSemGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_BinSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_BINSEM, sem_id); - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-bsp.c b/src/ut-stubs/osapi-utstub-bsp.c deleted file mode 100644 index 126b5bb7f..000000000 --- a/src/ut-stubs/osapi-utstub-bsp.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi-utstub-bsp.c - * \author joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-bsp.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -/* - ********************************************************************************* - * PUBLIC API (application-callable functions) - ********************************************************************************* - */ - -/*---------------------------------------------------------------- - OS_BSP_GetArgC - See full description in header - ------------------------------------------------------------------*/ -uint32 OS_BSP_GetArgC(void) -{ - int32 status = UT_DEFAULT_IMPL(OS_BSP_GetArgC); - - return status; -} - -/*---------------------------------------------------------------- - OS_BSP_GetArgV - See full description in header - ------------------------------------------------------------------*/ -char *const *OS_BSP_GetArgV(void) -{ - void *buffer = NULL; - int32 status; - - status = UT_DEFAULT_IMPL(OS_BSP_GetArgV); - if (status == 0 && UT_Stub_CopyToLocal(UT_KEY(OS_BSP_GetArgV), &buffer, sizeof(buffer)) < sizeof(buffer)) - { - buffer = NULL; - } - return buffer; -} diff --git a/src/ut-stubs/osapi-utstub-common.c b/src/ut-stubs/osapi-utstub-common.c deleted file mode 100644 index bd121f640..000000000 --- a/src/ut-stubs/osapi-utstub-common.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-common.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -/***************************************************************************** - * - * Stub function for OS_API_Init() - * - *****************************************************************************/ -int32 OS_API_Init(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL(OS_API_Init); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_NotifyEvent() - * - *****************************************************************************/ -int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_NotifyEvent), event); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_NotifyEvent), object_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_NotifyEvent), data); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_NotifyEvent); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_RegisterEventHandler() - * - *****************************************************************************/ -int32 OS_RegisterEventHandler(OS_EventHandler_t handler) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_RegisterEventHandler), handler); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_RegisterEventHandler); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_ApplicationExit() - * - *****************************************************************************/ -void OS_ApplicationExit(int32 Status) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ApplicationExit), Status); - - /* just call the default so a hook can be attached */ - UT_DEFAULT_IMPL(OS_ApplicationExit); -} - -/***************************************************************************** - * - * Stub function for OS_CleanUpObject() - * - *****************************************************************************/ -void OS_CleanUpObject(uint32 object_id, void *arg) -{ - UT_Stub_RegisterContext(UT_KEY(OS_CleanUpObject), &object_id); - UT_Stub_RegisterContext(UT_KEY(OS_CleanUpObject), arg); - UT_DEFAULT_IMPL(OS_CleanUpObject); -} - -/***************************************************************************** - * - * Stub function for OS_DeleteAllObjects() - * - *****************************************************************************/ -void OS_DeleteAllObjects(void) -{ - UT_DEFAULT_IMPL(OS_DeleteAllObjects); -} - -/***************************************************************************** - * - * Stub function for OS_IdleLoop() - * - *****************************************************************************/ -void OS_IdleLoop(void) -{ - UT_DEFAULT_IMPL(OS_IdleLoop); -} - -/***************************************************************************** - * - * Stub function for OS_ApplicationShutdown() - * - *****************************************************************************/ -void OS_ApplicationShutdown(uint8 flag) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ApplicationShutdown), flag); - - UT_DEFAULT_IMPL(OS_ApplicationShutdown); -} diff --git a/src/ut-stubs/osapi-utstub-countsem.c b/src/ut-stubs/osapi-utstub-countsem.c deleted file mode 100644 index 31c7faaa7..000000000 --- a/src/ut-stubs/osapi-utstub-countsem.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-countsem.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_CountSemAPI_Init, (void)) - -/***************************************************************************** - * - * Stub function for OS_CountSemCreate() - * - *****************************************************************************/ -int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initial_value, uint32 options) -{ - UT_Stub_RegisterContext(UT_KEY(OS_CountSemCreate), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_CountSemCreate), sem_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemCreate), sem_initial_value); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemCreate), options); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemCreate); - - if (status == OS_SUCCESS) - { - *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM); - } - else - { - *sem_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_CountSemDelete stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_CountSemDelete. The user can adjust the response by setting -** the values in the CountSemDelRtn structure prior to this function -** being called. If the value CountSemDelRtn.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 CountSemDelRtn.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 OS_CountSemDelete(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemDelete), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_CountSemGive() function - * - *****************************************************************************/ -int32 OS_CountSemGive(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemGive), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemGive); - - return status; -} - -/***************************************************************************** - * - * Stub for OS_CountSemTake() function - * - *****************************************************************************/ -int32 OS_CountSemTake(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemTake), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemTake); - - return status; -} - -/***************************************************************************** - * - * Stub for OS_CountSemTimedWait() function - * - *****************************************************************************/ -int32 OS_CountSemTimedWait(osal_id_t sem_id, uint32 msecs) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemTimedWait), sem_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemTimedWait), msecs); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemTimedWait); - - return status; -} - -/***************************************************************************** - * - * Stub for OS_CountSemGetIdByName() function - * - *****************************************************************************/ -int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_CountSemGetIdByName), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_CountSemGetIdByName), sem_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_COUNTSEM, sem_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_CountSemGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_CountSemGetInfo. It sets the counting semaphore structure -** variables to fixed values and returns OS_SUCCESS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_CountSemGetInfo), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_CountSemGetInfo), count_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CountSemGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_CountSemGetInfo), count_prop, sizeof(*count_prop)) < sizeof(*count_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &count_prop->creator); - strncpy(count_prop->name, "Name", sizeof(count_prop->name) - 1); - count_prop->name[sizeof(count_prop->name) - 1] = '\0'; - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-dir.c b/src/ut-stubs/osapi-utstub-dir.c deleted file mode 100644 index 43ad38760..000000000 --- a/src/ut-stubs/osapi-utstub-dir.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-dir.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_DirAPI_Init, (void)) - -/***************************************************************************** - * - * Stub for OS_mkdir() function - * - *****************************************************************************/ -int32 OS_mkdir(const char *path, uint32 access) -{ - UT_Stub_RegisterContext(UT_KEY(OS_mkdir), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_mkdir), access); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_mkdir); - - return Status; -} - -/***************************************************************************** - * - * Stub for OS_rmdir() function - * - *****************************************************************************/ -int32 OS_rmdir(const char *path) -{ - UT_Stub_RegisterContext(UT_KEY(OS_rmdir), path); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_rmdir); - - return Status; -} - -/***************************************************************************** - * - * Stub for OS_DirectoryOpen() function - * - *****************************************************************************/ -int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path) -{ - UT_Stub_RegisterContext(UT_KEY(OS_DirectoryOpen), dir_id); - UT_Stub_RegisterContext(UT_KEY(OS_DirectoryOpen), path); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_DirectoryOpen); - - if (Status == OS_SUCCESS) - { - *dir_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_DIR); - } - else - { - *dir_id = UT_STUB_FAKE_OBJECT_ID; - } - - return Status; -} - -/***************************************************************************** - * - * Stub for OS_DirectoryClose() function - * - *****************************************************************************/ -int32 OS_DirectoryClose(osal_id_t dir_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_DirectoryClose), dir_id); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_DirectoryClose); - - if (Status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_DIR, dir_id); - } - - return Status; -} - -/***************************************************************************** - * - * Stub for OS_DirectoryRewind() function - * - *****************************************************************************/ -int32 OS_DirectoryRewind(osal_id_t dir_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_DirectoryRewind), dir_id); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_DirectoryRewind); - - return Status; -} - -/***************************************************************************** - * - * Stub for OS_DirectoryRead() function - * - *****************************************************************************/ -int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_DirectoryRead), dir_id); - UT_Stub_RegisterContext(UT_KEY(OS_DirectoryRead), dirent); - - int32 Status; - size_t CopySize; - - Status = UT_DEFAULT_IMPL(OS_DirectoryRead); - - if (Status == OS_SUCCESS) - { - CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_DirectoryRead), dirent, sizeof(*dirent)); - if (CopySize < sizeof(*dirent)) - { - memset(dirent, 0, sizeof(*dirent)); - } - } - - return Status; -} diff --git a/src/ut-stubs/osapi-utstub-file.c b/src/ut-stubs/osapi-utstub-file.c deleted file mode 100644 index 9fdc1f2c7..000000000 --- a/src/ut-stubs/osapi-utstub-file.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-file.h" /* OSAL public API for this subsystem */ -#include "osapi-idmap.h" -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_FileAPI_Init, (void)) - -/***************************************************************************** - * - * Local Stub helper function for reading - * - *****************************************************************************/ -static int32 UT_GenericReadStub(const char *fname, UT_EntryKey_t fkey, void *buffer, size_t bsize) -{ - int32 status; - size_t CopySize; - - status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF, NULL); - - if (status == 0x7FFFFFFF) - { - CopySize = UT_Stub_CopyToLocal(fkey, buffer, bsize); - - /* If CopyToLocal returns zero, this probably means no buffer was supplied, - * in which case just generate fill data and pretend it was read. - */ - if (CopySize > 0) - { - status = CopySize; - } - else - { - memset(buffer, 0, bsize); - status = bsize; - } - } - else if (status > 0) - { - /* generate fill data for requested size */ - memset(buffer, 0, status); - } - - return status; -} - -/***************************************************************************** - * - * Local Stub helper function for writing - * - *****************************************************************************/ -static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const void *buffer, size_t bsize) -{ - int32 status; - size_t CopySize; - - status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF, NULL); - - if (status == 0x7FFFFFFF) - { - CopySize = UT_Stub_CopyFromLocal(fkey, buffer, bsize); - - /* If CopyFromLocal returns zero, this probably means no buffer was supplied, - * in which case just throw out the data and pretend it was written. - */ - if (CopySize > 0) - { - status = CopySize; - } - else - { - status = bsize; - } - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_OpenCreate() - * - *****************************************************************************/ -int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) -{ - UT_Stub_RegisterContext(UT_KEY(OS_OpenCreate), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_OpenCreate), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_OpenCreate), flags); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_OpenCreate), access); - int32 status; - - status = UT_DEFAULT_IMPL(OS_OpenCreate); - if (status == OS_SUCCESS) - { - *filedes = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); - } - else - { - *filedes = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_close() - * - *****************************************************************************/ -int32 OS_close(osal_id_t filedes) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_close), filedes); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_close); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_STREAM, filedes); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_StreamRead() - * - *****************************************************************************/ -int32 OS_StreamRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) -{ - return UT_GenericReadStub(__func__, UT_KEY(OS_StreamRead), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_StreamWrite() - * - *****************************************************************************/ -int32 OS_StreamWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) -{ - return UT_GenericWriteStub(__func__, UT_KEY(OS_StreamWrite), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_read() - * - *****************************************************************************/ -int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_read), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_read), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_read), nbytes); - - return UT_GenericReadStub(__func__, UT_KEY(OS_read), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_write() - * - *****************************************************************************/ -int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_write), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_write), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_write), nbytes); - - return UT_GenericWriteStub(__func__, UT_KEY(OS_write), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_TimedRead() - * - *****************************************************************************/ -int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedRead), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_TimedRead), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedRead), nbytes); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedRead), timeout); - - return UT_GenericReadStub(__func__, UT_KEY(OS_TimedRead), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_TimedWrite() - * - *****************************************************************************/ -int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedWrite), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_TimedWrite), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedWrite), nbytes); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimedWrite), timeout); - - return UT_GenericWriteStub(__func__, UT_KEY(OS_TimedWrite), buffer, nbytes); -} - -/***************************************************************************** - * - * Stub function for OS_chmod() - * - *****************************************************************************/ -int32 OS_chmod(const char *path, uint32 access) -{ - UT_Stub_RegisterContext(UT_KEY(OS_chmod), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_chmod), access); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_chmod); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_stat() - * - *****************************************************************************/ -int32 OS_stat(const char *path, os_fstat_t *filestats) -{ - UT_Stub_RegisterContext(UT_KEY(OS_stat), path); - UT_Stub_RegisterContext(UT_KEY(OS_stat), filestats); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_stat); - - if (Status == OS_SUCCESS) - { - UT_Stub_CopyToLocal(UT_KEY(OS_stat), filestats, sizeof(*filestats)); - } - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_lseek() - * - *****************************************************************************/ -int32 OS_lseek(osal_id_t filedes, int32 offset, uint32 whence) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_lseek), filedes); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_lseek), offset); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_lseek), whence); - - int32 status; - - status = UT_DEFAULT_IMPL_RC(OS_lseek, offset); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_remove() - * - *****************************************************************************/ -int32 OS_remove(const char *path) -{ - UT_Stub_RegisterContext(UT_KEY(OS_remove), path); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_remove); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_rename() - * - *****************************************************************************/ -int32 OS_rename(const char *old_filename, const char *new_filename) -{ - UT_Stub_RegisterContext(UT_KEY(OS_rename), old_filename); - UT_Stub_RegisterContext(UT_KEY(OS_rename), new_filename); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_rename); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_cp() - * - *****************************************************************************/ -int32 OS_cp(const char *src, const char *dest) -{ - UT_Stub_RegisterContext(UT_KEY(OS_cp), src); - UT_Stub_RegisterContext(UT_KEY(OS_cp), dest); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_cp); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_mv() - * - *****************************************************************************/ -int32 OS_mv(const char *src, const char *dest) -{ - UT_Stub_RegisterContext(UT_KEY(OS_mv), src); - UT_Stub_RegisterContext(UT_KEY(OS_mv), dest); - - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_mv); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_FDGetInfo() - * - *****************************************************************************/ -int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_FDGetInfo), filedes); - UT_Stub_RegisterContext(UT_KEY(OS_FDGetInfo), fd_prop); - - int32 status; - size_t CopySize; - - status = UT_DEFAULT_IMPL(OS_FDGetInfo); - - if (status == OS_SUCCESS) - { - /* The user may supply specific entries to return */ - CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_FDGetInfo), fd_prop, sizeof(*fd_prop)); - if (CopySize < sizeof(*fd_prop)) - { - memset(fd_prop, 0, sizeof(*fd_prop)); - fd_prop->IsValid = true; - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &fd_prop->User); - } - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_FileOpenCheck() - * - *****************************************************************************/ -int32 OS_FileOpenCheck(const char *Filename) -{ - UT_Stub_RegisterContext(UT_KEY(OS_FileOpenCheck), Filename); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_FileOpenCheck); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_CloseFileByName() - * - *****************************************************************************/ -int32 OS_CloseFileByName(const char *Filename) -{ - UT_Stub_RegisterContext(UT_KEY(OS_CloseFileByName), Filename); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_CloseFileByName); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_CloseAllFiles() - * - *****************************************************************************/ -int32 OS_CloseAllFiles(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL(OS_CloseAllFiles); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_ShellOutputToFile() - * - *****************************************************************************/ -int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) -{ - UT_Stub_RegisterContext(UT_KEY(OS_ShellOutputToFile), Cmd); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ShellOutputToFile), filedes); - - int32 status; - - /* - * This allows a hook function to do something with the "Cmd" parameter - */ - - status = UT_DEFAULT_IMPL(OS_ShellOutputToFile); - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c deleted file mode 100644 index 38b3ebf5b..000000000 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-filesys.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_FileSysAPI_Init, (void)) - -/***************************************************************************** - * - * Stub function for OS_FileSysAddFixedMap() - * - *****************************************************************************/ -int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const char *virt_path) -{ - UT_Stub_RegisterContext(UT_KEY(OS_FileSysAddFixedMap), filesys_id); - UT_Stub_RegisterContext(UT_KEY(OS_FileSysAddFixedMap), phys_path); - UT_Stub_RegisterContext(UT_KEY(OS_FileSysAddFixedMap), virt_path); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_FileSysAddFixedMap); - - if (status == OS_SUCCESS) - { - *filesys_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_FILESYS); - } - else - { - *filesys_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_mkfs() - * - *****************************************************************************/ -int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) -{ - UT_Stub_RegisterContext(UT_KEY(OS_mkfs), address); - UT_Stub_RegisterContext(UT_KEY(OS_mkfs), devname); - UT_Stub_RegisterContext(UT_KEY(OS_mkfs), volname); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_mkfs), blocksize); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_mkfs), numblocks); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_mkfs); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_rmfs() - * - *****************************************************************************/ -int32 OS_rmfs(const char *devname) -{ - UT_Stub_RegisterContext(UT_KEY(OS_rmfs), devname); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_rmfs); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_initfs() - * - *****************************************************************************/ -int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks) -{ - UT_Stub_RegisterContext(UT_KEY(OS_initfs), address); - UT_Stub_RegisterContext(UT_KEY(OS_initfs), devname); - UT_Stub_RegisterContext(UT_KEY(OS_initfs), volname); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_initfs), blocksize); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_initfs), numblocks); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_initfs); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_mount() - * - *****************************************************************************/ -int32 OS_mount(const char *devname, const char *mountpoint) -{ - UT_Stub_RegisterContext(UT_KEY(OS_mount), devname); - UT_Stub_RegisterContext(UT_KEY(OS_mount), mountpoint); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_mount); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_unmount() - * - *****************************************************************************/ -int32 OS_unmount(const char *mountpoint) -{ - UT_Stub_RegisterContext(UT_KEY(OS_unmount), mountpoint); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_unmount); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_FileSysStatVolume() - * - *****************************************************************************/ -int32 OS_FileSysStatVolume(const char *name, OS_statvfs_t *statbuf) -{ - UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), name); - UT_Stub_RegisterContext(UT_KEY(OS_FileSysStatVolume), statbuf); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_FileSysStatVolume); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume), statbuf, sizeof(*statbuf)) < sizeof(*statbuf)) - { - memset(statbuf, 0, sizeof(*statbuf)); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_chkfs() - * - *****************************************************************************/ -int32 OS_chkfs(const char *name, bool repair) -{ - UT_Stub_RegisterContext(UT_KEY(OS_chkfs), name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_chkfs), repair); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_chkfs); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_FS_GetPhysDriveName() - * - *****************************************************************************/ -int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint) -{ - UT_Stub_RegisterContext(UT_KEY(OS_FS_GetPhysDriveName), PhysDriveName); - UT_Stub_RegisterContext(UT_KEY(OS_FS_GetPhysDriveName), MountPoint); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_FS_GetPhysDriveName); - strncpy(PhysDriveName, MountPoint, OS_FS_PHYS_NAME_LEN - 1); - PhysDriveName[OS_FS_PHYS_NAME_LEN - 1] = 0; - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_GetFsInfo() - * - *****************************************************************************/ -int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) -{ - UT_Stub_RegisterContext(UT_KEY(OS_GetFsInfo), filesys_info); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_GetFsInfo); - memset(filesys_info, 0, sizeof(*filesys_info)); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TranslatePath() - * - *****************************************************************************/ -int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TranslatePath), VirtualPath); - UT_Stub_RegisterContext(UT_KEY(OS_TranslatePath), LocalPath); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TranslatePath); - - if (status == OS_SUCCESS && VirtualPath != NULL && LocalPath != NULL && - UT_Stub_CopyToLocal(UT_KEY(OS_TranslatePath), LocalPath, OS_MAX_LOCAL_PATH_LEN) == 0) - { - strncpy(LocalPath, VirtualPath, OS_MAX_LOCAL_PATH_LEN - 1); - LocalPath[OS_MAX_LOCAL_PATH_LEN - 1] = 0; - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-idmap.c b/src/ut-stubs/osapi-utstub-idmap.c deleted file mode 100644 index 4521ba0e8..000000000 --- a/src/ut-stubs/osapi-utstub-idmap.c +++ /dev/null @@ -1,635 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi-utstub-idmap.c - * \author joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - * - * NOTE: The Object ID manipulation calls would not be called by applications. - * However stubs are still defined in order to support things such as - * coverage testing of the low-level implementation. This set of stubs - * is implemented separately here as it is only needed when coverage testing - * OSAL itself (not for coverage testing other units). - */ - -#include "osapi-idmap.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" -#include "os-shared-idmap.h" - -/* - * UT Helper function to create a fake object lock token - */ -static void UT_TokenCompose(uint32 lock_mode, uint32 indx, osal_objtype_t objtype, OS_object_token_t *token) -{ - token->lock_mode = lock_mode; - token->obj_type = objtype; - token->obj_idx = indx; - UT_ObjIdCompose(indx, objtype, &token->obj_id); -} - -UT_DEFAULT_STUB(OS_ObjectIdInit, (void)) - -/* Lock/Unlock for global tables */ -void OS_Lock_Global(OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_Lock_Global); -} -void OS_Unlock_Global(OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_Unlock_Global); -} - -/***************************************************************************** - * - * Stub function for OS_GetMaxForObjectType() - * - *****************************************************************************/ -uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) -{ - int32 max; - - if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) - { - max = OSAL_MAX_VALID_PER_TYPE; - } - else - { - max = 0; - } - - return UT_DEFAULT_IMPL_RC(OS_GetMaxForObjectType, max); -} - -/***************************************************************************** - * - * Stub function for OS_GetBaseForObjectType() - * - *****************************************************************************/ -uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) -{ - int32 base; - - if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) - { - base = OSAL_MAX_VALID_PER_TYPE * (idtype - 1); - } - else - { - base = 0; - } - - return UT_DEFAULT_IMPL_RC(OS_GetBaseForObjectType, base); -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdToArrayIndex() - * - *****************************************************************************/ -int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t id, osal_index_t *ArrayIndex) -{ - int32 Status; - osal_objtype_t checktype; - uint32 tempserial; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdToArrayIndex); - - if (Status == 0 && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdToArrayIndex), ArrayIndex, sizeof(*ArrayIndex)) < sizeof(*ArrayIndex)) - { - /* this needs to output something valid or code will break */ - UT_ObjIdDecompose(id, &tempserial, &checktype); - *ArrayIndex = OSAL_INDEX_C(tempserial); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdGlobalFromToken() - * - *****************************************************************************/ -OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) -{ - static OS_common_record_t fake_record; - int32 status; - OS_common_record_t * recptr = &fake_record; - - status = UT_DEFAULT_IMPL(OS_ObjectIdGlobalFromToken); - if (status == 0 && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGlobalFromToken), &recptr, sizeof(recptr)) < sizeof(recptr)) - { - /* This function should never return null */ - recptr = &fake_record; - } - - return recptr; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdFinalize() - * - *****************************************************************************/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdFinalizeNew, operation_status); - - /* need to actually write something to the output buffer */ - if (Status == OS_SUCCESS && token != NULL && outid != NULL && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdFinalizeNew), outid, sizeof(*outid)) < sizeof(*outid)) - { - *outid = token->obj_id; - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdFinalizeDelete() - * - *****************************************************************************/ -int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdFinalizeDelete, operation_status); - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdFindMatch() - * - *****************************************************************************/ -int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, - OS_object_token_t *token) -{ - int32 Status; - - /* by default this stub should return NAME_NOT_FOUND - * unless the test case has set up otherwise. To set - * up a success response, just register a buffer for - * the function - */ - Status = UT_DEFAULT_IMPL(OS_ObjectIdGetBySearch); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), token, sizeof(*token)) < sizeof(*token)) - { - UT_TokenCompose(lock_mode, 1, idtype, token); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdTransactionInit() - * - *****************************************************************************/ -int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdTransactionInit); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransactionInit), token, sizeof(*token)) < sizeof(*token)) - { - memset(&token, 0, sizeof(token)); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdTransactionCancel() - * - *****************************************************************************/ -void OS_ObjectIdTransactionCancel(OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_ObjectIdTransactionCancel); -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdFindByName() - * - *****************************************************************************/ -int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) -{ - int32 Status; - - /* by default this stub should return NAME_NOT_FOUND - * unless the test case has set up otherwise. To set - * up a success response, just register a buffer for - * the function - */ - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdFindByName, OS_ERR_NAME_NOT_FOUND); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdFindByName), object_id, sizeof(*object_id)) < sizeof(*object_id)) - { - UT_ObjIdCompose(1, idtype, object_id); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdGetByName() - * - *****************************************************************************/ -int32 OS_ObjectIdGetByName(OS_lock_mode_t lock_mode, osal_objtype_t idtype, const char *name, OS_object_token_t *token) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdGetByName); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), token, sizeof(*token)) < sizeof(*token)) - { - UT_TokenCompose(lock_mode, 1, idtype, token); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdGetById() - * - *****************************************************************************/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, osal_objtype_t idtype, osal_id_t id, OS_object_token_t *token) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdGetById); - - if (Status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetById), token, sizeof(*token)) < sizeof(*token)) - { - UT_TokenCompose(lock_mode, OS_ObjectIdToInteger(id) & 0xFFFF, idtype, token); - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdRelease() - * - *****************************************************************************/ -void OS_ObjectIdRelease(OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_ObjectIdRelease); -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdTransferToken() - * - *****************************************************************************/ -void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdTransferToken); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransferToken), token_to, sizeof(*token_to)) < sizeof(*token_to)) - { - /* just copy it if nothing specified */ - *token_to = *token_from; - } -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdGetNext() - * - *****************************************************************************/ -int32 OS_ObjectIdGetNext(osal_objtype_t idtype, uint32 *curr_index, OS_common_record_t **record) -{ - int32 Status; - uint32 local_id; - OS_common_record_t * local_record; - static OS_common_record_t fake_record; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdGetNext); - - if (Status == 0) - { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetNext), &local_id, sizeof(local_id)) < sizeof(local_id)) - { - local_id = UT_GetStubCount(UT_KEY(OS_ObjectIdGetNext)); - } - - if (local_id >= OSAL_MAX_VALID_PER_TYPE) - { - Status = OS_ERROR; - } - else - { - if (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetNext), &local_record, sizeof(local_record)) < - sizeof(local_record)) - { - memset(&fake_record, 0, sizeof(fake_record)); - UT_ObjIdCompose(local_id, idtype, &fake_record.active_id); - local_record = &fake_record; - } - - if (curr_index != NULL) - { - *curr_index = local_id; - } - - if (record != NULL) - { - *record = local_record; - } - } - } - - return Status; -} - -/***************************************************************************** - * - * Stub function for OS_ObjectIdAllocateNew() - * - *****************************************************************************/ -int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdAllocateNew); - - if (Status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdAllocateNew), token, sizeof(*token)) < sizeof(*token)) - { - UT_TokenCompose(OS_LOCK_MODE_GLOBAL, UT_GetStubCount(UT_KEY(OS_ObjectIdAllocateNew)), idtype, token); - } - - return Status; -} - -/*-------------------------------------------------------------------------------------- - Name: OS_GetResourceName - - Purpose: Stub function for OS_GetResourceName, returns either the test-supplied string - or an empty string. - - returns: status ----------------------------------------------------------------------------------------*/ -int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_GetResourceName), object_id); - UT_Stub_RegisterContext(UT_KEY(OS_GetResourceName), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_GetResourceName), buffer_size); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_GetResourceName); - - if (return_code == OS_SUCCESS) - { - if (buffer_size > 0 && UT_Stub_CopyToLocal(UT_KEY(OS_GetResourceName), buffer, buffer_size) == 0) - { - /* return an empty string by default */ - buffer[0] = 0; - } - } - - return return_code; -} - -/*-------------------------------------------------------------------------------------- - Name: OS_ConvertToArrayIndex - - Purpose: Converts any abstract ID into a number suitable for use as an array index. - This is necessary for code that breaks when IDs are converted - to nonzero ranges. Note that this does NOT verify the validity of the ID, - that is left to the caller. This is only the conversion logic. - - returns: status ----------------------------------------------------------------------------------------*/ -int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ConvertToArrayIndex), object_id); - UT_Stub_RegisterContext(UT_KEY(OS_ConvertToArrayIndex), ArrayIndex); - - int32 return_code; - uint32 tempserial; - - return_code = UT_DEFAULT_IMPL(OS_ConvertToArrayIndex); - - if (return_code == OS_SUCCESS) - { - osal_objtype_t ObjType; - UT_ObjIdDecompose(object_id, &tempserial, &ObjType); - if (ObjType != OS_OBJECT_TYPE_UNDEFINED && ObjType < OS_OBJECT_TYPE_USER) - { - tempserial %= UT_MAXOBJS[ObjType]; - } - } - else - { - /* - * If set to fail, then set the output to something bizarre - if the code - * actually tries to use this, chances are it will segfault and be fixed - */ - tempserial = 0xDEADBEEFU; - } - - *ArrayIndex = OSAL_INDEX_C(tempserial); - - return return_code; -} /* end OS_ConvertToArrayIndex */ - -/*-------------------------------------------------------------------------------------- - Name: OS_ForEachObjectOfType - - Purpose: Stub function for OS_ForEachObjectOfType - - returns: None ----------------------------------------------------------------------------------------*/ -void OS_ForEachObjectOfType(osal_objtype_t objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, - void *callback_arg) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObjectOfType), objtype); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObjectOfType), creator_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObjectOfType), callback_ptr); - UT_Stub_RegisterContext(UT_KEY(OS_ForEachObjectOfType), callback_arg); - - osal_id_t NextId; - size_t IdSize; - - /* Although this is "void", Invoke the default impl to log it and invoke any hooks */ - UT_DEFAULT_IMPL(OS_ForEachObjectOfType); - - while (1) - { - IdSize = UT_Stub_CopyToLocal(UT_KEY(OS_ForEachObjectOfType), &NextId, sizeof(NextId)); - if (IdSize < sizeof(NextId)) - { - break; - } - (*callback_ptr)(NextId, callback_arg); - } -} - -/*-------------------------------------------------------------------------------------- - Name: OS_ForEachOject - - Purpose: Loops through all defined OSAL objects and calls callback_ptr on each one - If creator_id is nonzero then only objects with matching creator id are processed. - - returns: None ----------------------------------------------------------------------------------------*/ -void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObject), creator_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ForEachObject), callback_ptr); - UT_Stub_RegisterContext(UT_KEY(OS_ForEachObject), callback_arg); - - osal_id_t NextId; - size_t IdSize; - - /* Although this is "void", Invoke the default impl to log it and invoke any hooks */ - UT_DEFAULT_IMPL(OS_ForEachObject); - - while (1) - { - IdSize = UT_Stub_CopyToLocal((UT_EntryKey_t)&OS_ForEachObject, &NextId, sizeof(NextId)); - if (IdSize < sizeof(NextId)) - { - break; - } - (*callback_ptr)(NextId, callback_arg); - } -} - -int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, - OS_object_iter_t *iter) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matchfunc); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), matcharg); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), objtype); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorInit), iter); - - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorInit, 1); - - if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), iter, sizeof(*iter)) < sizeof(*iter)) - { - memset(iter, 0, sizeof(*iter)); - Status = OS_SUCCESS; - } - - return Status; -} - -int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), objtype); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIterateActive), iter); - - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIterateActive, 1); - - if (Status == 1 && UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIterateActive), iter, sizeof(*iter)) < sizeof(*iter)) - { - memset(iter, 0, sizeof(*iter)); - Status = OS_SUCCESS; - } - - return Status; -} - -bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ObjectIdIteratorGetNext), iter); - - int32 Status; - - Status = UT_DEFAULT_IMPL_RC(OS_ObjectIdIteratorGetNext, -1); - - if (Status == -1) - { - /* if test case has registered something, return true, otherwise return false */ - Status = (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), &iter->token, sizeof(iter->token)) == - sizeof(iter->token)); - } - - return (bool)Status; -} - -void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) -{ - UT_DEFAULT_IMPL(OS_ObjectIdIteratorDestroy); -} - -int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)) -{ - int32 Status; - - Status = UT_DEFAULT_IMPL(OS_ObjectIdIteratorProcessEntry); - - return Status; -} - -/*--------------------------------------------------------------------------------------- - Name: OS_IdentifyObject - - Purpose: Given an arbitrary object ID, get the type of the object - - returns: The type of object that the ID represents ----------------------------------------------------------------------------------------*/ -osal_objtype_t OS_IdentifyObject(osal_id_t object_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_IdentifyObject), object_id); - - osal_objtype_t ObjType; - uint32 checkindx; - int32 DefaultType; - - UT_ObjIdDecompose(object_id, &checkindx, &ObjType); - - DefaultType = UT_DEFAULT_IMPL_RC(OS_IdentifyObject, ObjType); - - return DefaultType; -} diff --git a/src/ut-stubs/osapi-utstub-module.c b/src/ut-stubs/osapi-utstub-module.c deleted file mode 100644 index e62c85d2b..000000000 --- a/src/ut-stubs/osapi-utstub-module.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-module.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_ModuleAPI_Init, (void)) - -/*****************************************************************************/ -/** -** \brief dummy_function stub function -** -** \par Description -** This function is used by the OS API function, OS_SymbolLookup, which -** requires a valid function for which to report the address. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns a user-defined status value. -** -******************************************************************************/ -int32 dummy_function(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL_RC(dummy_function, 0); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_ModuleLoad stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_ModuleLoad. The user can adjust the response by setting -** the values in the ModuleLoadRtn structure prior to this function -** being called. If the value ModuleLoadRtn.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 ModuleLoadRtn.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 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *filename, uint32 flags) -{ - UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), module_id); - UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), module_name); - UT_Stub_RegisterContext(UT_KEY(OS_ModuleLoad), filename); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleLoad), flags); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_ModuleLoad); - - if (status == OS_SUCCESS) - { - *module_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MODULE); - } - else - { - *module_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_ModuleUnload stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_ModuleUnload. The user can adjust the response by setting -** the values in the ModuleUnloadRtn structure prior to this function -** being called. If the value ModuleUnloadRtn.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 ModuleUnloadRtn.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 OS_ModuleUnload(osal_id_t module_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleUnload), module_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_ModuleUnload); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MODULE, module_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_ModuleInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_ModuleInfo. The user can adjust the response by setting -** the values in the ModuleInfoRtn structure prior to this function -** being called. If the value ModuleInfoRtn.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 ModuleInfoRtn.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 OS_ModuleInfo(osal_id_t module_id, OS_module_prop_t *module_info) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleInfo), module_id); - UT_Stub_RegisterContext(UT_KEY(OS_ModuleInfo), module_info); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_ModuleInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_ModuleInfo), module_info, sizeof(*module_info)) < sizeof(*module_info)) - { - memset(module_info, 0, sizeof(*module_info)); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_SymbolLookup stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_SymbolLookup. The user can adjust the response by setting -** the values in the SymbolLookupRtn structure prior to this function -** being called. If the value SymbolLookupRtn.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 SymbolLookupRtn.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 OS_SymbolLookup(cpuaddr *symbol_address, const char *symbol_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SymbolLookup), symbol_address); - UT_Stub_RegisterContext(UT_KEY(OS_SymbolLookup), symbol_name); - - int32 status; - - /* - * Register the context so a hook can do something with the parameters - */ - - status = UT_DEFAULT_IMPL(OS_SymbolLookup); - - if (status != OS_SUCCESS) - { - *symbol_address = 0xDEADBEEFU; - } - else if (UT_Stub_CopyToLocal(UT_KEY(OS_SymbolLookup), symbol_address, sizeof(*symbol_address)) < - sizeof(*symbol_address)) - { - /* return the dummy function when test didn't register anything else */ - *symbol_address = (cpuaddr)&dummy_function; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SymbolTableDump() - * - *****************************************************************************/ -int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const char *symbol_name) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_ModuleSymbolLookup), module_id); - UT_Stub_RegisterContext(UT_KEY(OS_ModuleSymbolLookup), symbol_address); - UT_Stub_RegisterContext(UT_KEY(OS_ModuleSymbolLookup), symbol_name); - - int32 status; - - /* - * Register the context so a hook can do something with the parameters - */ - - status = UT_DEFAULT_IMPL(OS_ModuleSymbolLookup); - - if (status != OS_SUCCESS) - { - *symbol_address = 0xDEADBEEFU; - } - else if (UT_Stub_CopyToLocal(UT_KEY(OS_ModuleSymbolLookup), symbol_address, sizeof(*symbol_address)) < - sizeof(*symbol_address)) - { - /* return the dummy function when test didn't register anything else */ - *symbol_address = (cpuaddr)&dummy_function; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SymbolTableDump() - * - *****************************************************************************/ -int32 OS_SymbolTableDump(const char *filename, size_t size_limit) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SymbolTableDump), filename); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SymbolTableDump), size_limit); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SymbolTableDump); - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-mutex.c b/src/ut-stubs/osapi-utstub-mutex.c deleted file mode 100644 index 89912f6e6..000000000 --- a/src/ut-stubs/osapi-utstub-mutex.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi-utstub-mutex.c - * \author joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-mutex.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_MutexAPI_Init, (void)) - -/*****************************************************************************/ -/** -** \brief OS_MutSemCreate stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_MutSemCreate. The user can adjust the response by setting the -** values in the MutSemCreateRtn structure prior to this function being -** called. If the value MutSemCreateRtn.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 MutSemCreateRtn.value. -** Alternately, the user can cause the function to return a failure -** result, OS_ERROR, by setting the value of UT_OS_Fail to -** OS_MUTCREATE_FAIL prior to this function being called. OS_SUCCESS -** is returned otherwise. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either a user-defined status flag, OS_ERROR, or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_MutSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 options) -{ - UT_Stub_RegisterContext(UT_KEY(OS_MutSemCreate), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_MutSemCreate), sem_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_MutSemCreate), options); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemCreate); - - if (status == OS_SUCCESS) - { - *sem_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_MUTEX); - } - else - { - *sem_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_MutSemDelete stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_MutSemDelete. The user can adjust the response by setting -** the values in the MutSemDelRtn structure prior to this function -** being called. If the value MutSemDelRtn.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 MutSemDelRtn.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 OS_MutSemDelete(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_MutSemDelete), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_MUTEX, sem_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_MutSemGive stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_MutSemGive. The user can adjust the response by setting -** the values in the MutSemGiveRtn structure prior to this function -** being called. If the value MutSemGiveRtn.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 MutSemGiveRtn.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 OS_MutSemGive(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_MutSemGive), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemGive); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_MutSemTake stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_MutSemTake. The user can adjust the response by setting -** the values in the MutSemTakeRtn structure prior to this function -** being called. If the value MutSemTakeRtn.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 MutSemTakeRtn.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 OS_MutSemTake(osal_id_t sem_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_MutSemTake), sem_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemTake); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_MutSemGetIdByName() - * - *****************************************************************************/ -int32 OS_MutSemGetIdByName(osal_id_t *sem_id, const char *sem_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_MutSemGetIdByName), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_MutSemGetIdByName), sem_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetIdByName), sem_id, sizeof(*sem_id)) < sizeof(*sem_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_MUTEX, sem_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_MutSemGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_MutSemGetInfo. It sets the mutex semaphore structure variables -** to fixed values and returns OS_SUCCESS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_MutSemGetInfo(osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_MutSemGetInfo), sem_id); - UT_Stub_RegisterContext(UT_KEY(OS_MutSemGetInfo), mut_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_MutSemGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_MutSemGetInfo), mut_prop, sizeof(*mut_prop)) < sizeof(*mut_prop)) - { - strncpy(mut_prop->name, "Name", sizeof(mut_prop->name) - 1); - mut_prop->name[sizeof(mut_prop->name) - 1] = '\0'; - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &mut_prop->creator); - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-queue.c b/src/ut-stubs/osapi-utstub-queue.c deleted file mode 100644 index faa7fe675..000000000 --- a/src/ut-stubs/osapi-utstub-queue.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-queue.h" /* OSAL public API for this subsystem */ -#include "osapi-idmap.h" -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_QueueAPI_Init, (void)) - -/*****************************************************************************/ -/** -** \brief OS_QueueCreate stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_QueueCreate. The user can adjust the response by setting -** the values in the QueueCreateRtn structure prior to this function -** being called. If the value QueueCreateRtn.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 QueueCreateRtn.value. -** Otherwise the return value is dependent on success or failure in -** creating the queue. -** -** \par Assumptions, External Events, and Notes: -** 1. Similar to the real call, doesn't care about creator or do any -** mutex locking\n -** 2. Emulates socket queue, without use of sockets -** -** \returns -** Returns either a user-defined status flag, OS_INVALID_POINTER, -** OS_ERR_NAME_TOO_LONG, OS_ERR_NO_FREE_IDS, OS_ERR_NAME_TAKEN, -** or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, - uint32 flags) -{ - UT_Stub_RegisterContext(UT_KEY(OS_QueueCreate), queue_id); - UT_Stub_RegisterContext(UT_KEY(OS_QueueCreate), queue_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueCreate), queue_depth); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueCreate), data_size); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueCreate), flags); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueueCreate); - - if (status == OS_SUCCESS) - { - *queue_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_QUEUE); - } - else - { - *queue_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_QueueDelete stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_QueueDelete. The user can adjust the response by setting -** the values in the QueueDelRtn structure prior to this function -** being called. If the value QueueDelRtn.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 QueueDelRtn.value. -** Otherwise the return value is dependent on success or failure in -** deleting the queue. -** -** \par Assumptions, External Events, and Notes: -** 1. Similar to real code without mutex locking\n -** 2. Emulates socket queue, without use of sockets -** -** \returns -** Returns either a user-defined status flag, OS_ERR_INVALID_ID, -** OS_ERROR, or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_QueueDelete(osal_id_t queue_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueDelete), queue_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueueDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_QUEUE, queue_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_QueueGet stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_QueueGet. The user can adjust the response by setting -** the values in the QueueGetRtn structure prior to this function -** being called. If the value QueueGetRtn.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 QueueGetRtn.value. -** Otherwise the return value is dependent on success or failure in -** getting the queue. -** -** \par Assumptions, External Events, and Notes: -** 1. Works similar to real function; note that pend on empty queue -** doesn't block\n -** 2. Emulates socket queue, without use of sockets -** -** \returns -** Returns either a user-defined status flag, OS_ERR_INVALID_ID, -** OS_INVALID_POINTER, OS_QUEUE_EMPTY, OS_QUEUE_INVALID_SIZE, -** or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueGet), queue_id); - UT_Stub_RegisterContext(UT_KEY(OS_QueueGet), data); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueGet), size); - UT_Stub_RegisterContext(UT_KEY(OS_QueueGet), size_copied); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueGet), timeout); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueueGet); - - if (status == OS_SUCCESS) - { - *size_copied = UT_Stub_CopyToLocal((UT_EntryKey_t)OS_ObjectIdToInteger(queue_id), data, size); - if (*size_copied == 0) - { - status = OS_QUEUE_EMPTY; - } - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_QueuePut stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_QueuePut. The user can adjust the response by setting -** the values in the QueuePutRtn structure prior to this function -** being called. If the value QueuePutRtn.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 QueuePutRtn.value. -** Otherwise the return value is dependent on success or failure in -** putting the queue. -** -** \par Assumptions, External Events, and Notes: -** 1. Same as real function\n -** 2. Emulates socket queue, without use of sockets -** -** \returns -** Returns either a user-defined status flag, OS_ERR_INVALID_ID, -** OS_INVALID_POINTER, OS_QUEUE_FULL, or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueuePut), queue_id); - UT_Stub_RegisterContext(UT_KEY(OS_QueuePut), data); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueuePut), size); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueuePut), flags); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueuePut); - - if (status == OS_SUCCESS) - { - UT_SetDataBuffer((UT_EntryKey_t)OS_ObjectIdToInteger(queue_id), (void *)data, size, true); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_QueueGetIdByName() - * - *****************************************************************************/ -int32 OS_QueueGetIdByName(osal_id_t *queue_id, const char *queue_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_QueueGetIdByName), queue_id); - UT_Stub_RegisterContext(UT_KEY(OS_QueueGetIdByName), queue_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueueGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetIdByName), queue_id, sizeof(*queue_id)) < sizeof(*queue_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_QUEUE, queue_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_QueueGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_QueueGetInfo. It sets the queue structure variables to fixed -** values and returns OS_SUCCESS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_QueueGetInfo(osal_id_t queue_id, OS_queue_prop_t *queue_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_QueueGetInfo), queue_id); - UT_Stub_RegisterContext(UT_KEY(OS_QueueGetInfo), queue_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_QueueGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_QueueGetInfo), queue_prop, sizeof(*queue_prop)) < sizeof(*queue_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &queue_prop->creator); - strncpy(queue_prop->name, "Name", sizeof(queue_prop->name) - 1); - queue_prop->name[sizeof(queue_prop->name) - 1] = '\0'; - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-select.c b/src/ut-stubs/osapi-utstub-select.c deleted file mode 100644 index eca0b48cd..000000000 --- a/src/ut-stubs/osapi-utstub-select.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi-utstub-select.c - * \author joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-select.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -/***************************************************************************** - * - * Stub function for OS_SelectSingle() - * - *****************************************************************************/ -int32 OS_SelectSingle(osal_id_t objid, uint32 *StateFlags, int32 msecs) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle), objid); - UT_Stub_RegisterContext(UT_KEY(OS_SelectSingle), StateFlags); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle), msecs); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectSingle); - - return return_code; -} - -/***************************************************************************** - * - * Stub function for OS_SelectMultiple() - * - *****************************************************************************/ -int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SelectMultiple), ReadSet); - UT_Stub_RegisterContext(UT_KEY(OS_SelectMultiple), WriteSet); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple), msecs); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectMultiple); - - return return_code; -} - -/***************************************************************************** - * - * Stub function for OS_SelectFdZero() - * - *****************************************************************************/ -int32 OS_SelectFdZero(OS_FdSet *Set) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SelectFdZero), Set); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectFdZero); - - return return_code; -} - -/***************************************************************************** - * - * Stub function for OS_SelectFdAdd() - * - *****************************************************************************/ -int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SelectFdAdd), Set); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectFdAdd), objid); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectFdAdd); - - return return_code; -} - -/***************************************************************************** - * - * Stub function for OS_SelectFdClear() - * - *****************************************************************************/ -int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SelectFdClear), Set); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectFdClear), objid); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectFdClear); - - return return_code; -} - -/***************************************************************************** - * - * Stub function for OS_SelectFdIsSet() - * - *****************************************************************************/ -bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SelectFdIsSet), Set); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectFdIsSet), objid); - - int32 return_code; - - return_code = UT_DEFAULT_IMPL(OS_SelectFdIsSet); - - return (return_code == 0); -} diff --git a/src/ut-stubs/osapi-utstub-sockets.c b/src/ut-stubs/osapi-utstub-sockets.c deleted file mode 100644 index 5a211c846..000000000 --- a/src/ut-stubs/osapi-utstub-sockets.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi-utstub-sockets.c - * \author joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-sockets.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_SocketAPI_Init, (void)) - -/***************************************************************************** - * - * Stub function for OS_SocketOpen() - * - *****************************************************************************/ -int32 OS_SocketOpen(osal_id_t *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t Type) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketOpen), sock_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketOpen), Domain); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketOpen), Type); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketOpen); - - if (status == OS_SUCCESS) - { - *sock_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketBind() - * - *****************************************************************************/ -int32 OS_SocketBind(osal_id_t sock_id, const OS_SockAddr_t *Addr) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketBind), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketBind), Addr); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketBind); - - return status; -} -/***************************************************************************** - * - * Stub function for OS_SocketAccept() - * - *****************************************************************************/ -int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *Addr, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAccept), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketAccept), connsock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketAccept), Addr); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAccept), timeout); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAccept); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketConnect() - * - *****************************************************************************/ -int32 OS_SocketConnect(osal_id_t sock_id, const OS_SockAddr_t *Addr, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketConnect), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketConnect), Addr); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketConnect), timeout); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketConnect); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketRecvFrom() - * - *****************************************************************************/ -int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketRecvFrom), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketRecvFrom), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketRecvFrom), buflen); - UT_Stub_RegisterContext(UT_KEY(OS_SocketRecvFrom), RemoteAddr); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketRecvFrom), timeout); - - int32 status; - size_t CopySize; - - status = UT_DEFAULT_IMPL(OS_SocketRecvFrom); - - if (status == 0x7FFFFFFF) - { - CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketRecvFrom), buffer, buflen); - - /* If CopyToLocal returns zero, this probably means no buffer was supplied, - * in which case just generate fill data and pretend it was read. - */ - if (CopySize > 0) - { - status = CopySize; - } - else - { - memset(buffer, 0, buflen); - status = buflen; - } - } - else if (status > 0) - { - /* generate fill data for requested size */ - memset(buffer, 0, status); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketSendTo() - * - *****************************************************************************/ -int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketSendTo), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketSendTo), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketSendTo), buflen); - UT_Stub_RegisterContext(UT_KEY(OS_SocketSendTo), RemoteAddr); - - int32 status; - size_t CopySize; - - status = UT_DEFAULT_IMPL_RC(OS_SocketSendTo, 0x7FFFFFFF); - - if (status == 0x7FFFFFFF) - { - CopySize = UT_Stub_CopyFromLocal(UT_KEY(OS_SocketSendTo), buffer, buflen); - - /* If CopyFromLocal returns zero, this probably means no buffer was supplied, - * in which case just throw out the data and pretend it was written. - */ - if (CopySize > 0) - { - status = CopySize; - } - else - { - status = buflen; - } - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketGetIdByName() - * - *****************************************************************************/ -int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketGetIdByName), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketGetIdByName), sock_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetIdByName), sock_id, sizeof(*sock_id)) < sizeof(*sock_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_STREAM, sock_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_SocketGetInfo(,sock_id) - * - *****************************************************************************/ -int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketGetInfo), sock_id); - UT_Stub_RegisterContext(UT_KEY(OS_SocketGetInfo), sock_prop); - - int32 status; - size_t CopySize; - - status = UT_DEFAULT_IMPL(OS_SocketGetInfo); - - if (status == OS_SUCCESS) - { - /* The user may supply specific entries to return */ - CopySize = UT_Stub_CopyToLocal(UT_KEY(OS_SocketGetInfo), sock_prop, sizeof(*sock_prop)); - if (CopySize < sizeof(*sock_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &sock_prop->creator); - strncpy(sock_prop->name, "ut", sizeof(sock_prop->name) - 1); - sock_prop->name[sizeof(sock_prop->name) - 1] = 0; - } - } - - return status; -} - -int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrInit), Addr); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAddrInit), Domain); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAddrInit); - - if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrInit), Addr, sizeof(*Addr)) < sizeof(*Addr)) - { - memset(Addr, 0, sizeof(*Addr)); - } - - return status; -} - -int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrToString), buffer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAddrToString), buflen); - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrToString), Addr); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAddrToString); - - if (status == OS_SUCCESS && buflen > 0 && UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrToString), buffer, buflen) == 0) - { - strncpy(buffer, "UT-addr", buflen - 1); - buffer[buflen - 1] = 0; - } - - return status; -} - -int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrFromString), Addr); - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrFromString), string); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAddrFromString); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrFromString), Addr, sizeof(*Addr)) < sizeof(*Addr)) - { - memset(Addr, 0, sizeof(*Addr)); - } - - return status; -} - -int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrGetPort), PortNum); - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrGetPort), Addr); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAddrGetPort); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_SocketAddrGetPort), PortNum, sizeof(*PortNum)) < sizeof(*PortNum)) - { - *PortNum = 0; - } - - return status; -} - -int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum) -{ - UT_Stub_RegisterContext(UT_KEY(OS_SocketAddrSetPort), Addr); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SocketAddrSetPort), PortNum); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_SocketAddrSetPort); - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-task.c b/src/ut-stubs/osapi-utstub-task.c deleted file mode 100644 index 5bd42d0d6..000000000 --- a/src/ut-stubs/osapi-utstub-task.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-task.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_TaskAPI_Init, (void)) - -/*****************************************************************************/ -/** -** \brief OS_TaskCreate stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskCreate. The user can adjust the response by setting the value -** of UT_OS_Fail prior to this function being called. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either OS_SUCCESS or OS_ERROR. -** -******************************************************************************/ -int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, - osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TaskCreate), task_id); - UT_Stub_RegisterContext(UT_KEY(OS_TaskCreate), task_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), function_pointer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), stack_pointer); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), stack_size); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), priority); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskCreate), flags); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskCreate); - - if (status == OS_SUCCESS) - { - *task_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TASK); - } - else - { - *task_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TaskDelete stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskDelete. The user can adjust the response by -** setting the value of UT_OS_Fail prior to this function being called. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either OS_SUCCESS or OS_ERROR. -** -******************************************************************************/ -int32 OS_TaskDelete(osal_id_t task_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskDelete), task_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TASK, task_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TaskExit stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskExit. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** This function does not return a value. -** -******************************************************************************/ -void OS_TaskExit() -{ - /* Although this has no retcode, invoke the hooks provided in the default impl. - * NOTE: historically CFE UT checks for a "1" output via its sideband methods. */ - UT_DEFAULT_IMPL_RC(OS_TaskExit, 1); -} - -/*****************************************************************************/ -/** -** \brief OS_TaskDelay stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskDelay. The user can adjust the response by setting the value -** of UT_OS_Fail prior to this function being called. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either OS_SUCCESS or OS_ERROR. -** -******************************************************************************/ -int32 OS_TaskDelay(uint32 millisecond) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskDelay), millisecond); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskDelay); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TaskSetPriority() - * - *****************************************************************************/ -int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskSetPriority), task_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskSetPriority), new_priority); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskSetPriority); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TaskGetId stub function -** -** \par Description -** This function is used as a placeholder for the OS API function -** OS_TaskGetId. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns 1 unless an override value is configured. -** -******************************************************************************/ -osal_id_t OS_TaskGetId(void) -{ - osal_id_t TaskId; - int32 status; - - status = UT_DEFAULT_IMPL_RC(OS_TaskGetId, 1); - UT_ObjIdCompose(status, OS_OBJECT_TYPE_OS_TASK, &TaskId); - - return TaskId; -} - -/***************************************************************************** - * - * Stub function for OS_TaskGetIdByName() - * - *****************************************************************************/ -int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TaskGetIdByName), task_id); - UT_Stub_RegisterContext(UT_KEY(OS_TaskGetIdByName), task_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetIdByName), task_id, sizeof(*task_id)) < sizeof(*task_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TaskGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskGetInfo. If the input structure, task_prop, is null, it -** returns OS_INVALID_POINTER. Otherwise it sets the task structure -** variables to fixed values and returns OS_SUCCESS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either OS_INVALID_POINTER or OS_SUCCESS. -** -******************************************************************************/ -int32 OS_TaskGetInfo(osal_id_t task_id, OS_task_prop_t *task_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskGetInfo), task_id); - UT_Stub_RegisterContext(UT_KEY(OS_TaskGetInfo), task_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TaskGetInfo), task_prop, sizeof(*task_prop)) < sizeof(*task_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &task_prop->creator); - task_prop->stack_size = OSAL_SIZE_C(100); - task_prop->priority = OSAL_PRIORITY_C(150); - strncpy(task_prop->name, "UnitTest", sizeof(task_prop->name) - 1); - task_prop->name[sizeof(task_prop->name) - 1] = '\0'; - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TaskGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskFindIdBySystemData. -** -** \returns -** The return value instructed by the test case setup -** -******************************************************************************/ -int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t sysdata_size) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TaskFindIdBySystemData), task_id); - UT_Stub_RegisterContext(UT_KEY(OS_TaskFindIdBySystemData), sysdata); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskFindIdBySystemData), sysdata_size); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskFindIdBySystemData); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TaskFindIdBySystemData), task_id, sizeof(*task_id)) < sizeof(*task_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, task_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TaskInstallDeleteHandler() - * - *****************************************************************************/ -int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TaskInstallDeleteHandler), function_pointer); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskInstallDeleteHandler); - - return (status); -} - -/***************************************************************************** - * - * Stub function for OS_TaskEntryPoint() - * - * This is an internal function but it needs a stub in order to test - * the low level implementation that uses the shared layer. - * - *****************************************************************************/ -void OS_TaskEntryPoint(osal_id_t task_id) -{ - UT_DEFAULT_IMPL(OS_TaskEntryPoint); -} diff --git a/src/ut-stubs/osapi-utstub-time.c b/src/ut-stubs/osapi-utstub-time.c deleted file mode 100644 index e8478332a..000000000 --- a/src/ut-stubs/osapi-utstub-time.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-timer.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_TimerCbAPI_Init, (void)) - -/***************************************************************************** - * - * Stub function for OS_TimerAdd() - * - *****************************************************************************/ -int32 OS_TimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_t timebase_id, OS_ArgCallback_t callback_ptr, - void *callback_arg) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TimerAdd), timer_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimerAdd), timer_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerAdd), timebase_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerAdd), callback_ptr); - UT_Stub_RegisterContext(UT_KEY(OS_TimerAdd), callback_arg); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerAdd); - - if (status == OS_SUCCESS) - { - *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); - } - else - { - *timer_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TimerCreate() - * - *****************************************************************************/ -int32 OS_TimerCreate(osal_id_t *timer_id, const char *timer_name, uint32 *clock_accuracy, - OS_TimerCallback_t callback_ptr) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TimerCreate), timer_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimerCreate), timer_name); - UT_Stub_RegisterContext(UT_KEY(OS_TimerCreate), clock_accuracy); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerCreate), callback_ptr); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerCreate); - - if (status == OS_SUCCESS) - { - *timer_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMECB); - } - else - { - *timer_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TimerSet() - * - *****************************************************************************/ -int32 OS_TimerSet(osal_id_t timer_id, uint32 start_time, uint32 interval_time) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerSet), timer_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerSet), start_time); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerSet), interval_time); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerSet); - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TimerDelete stub function -** -** \par Description -** This function is used as a placeholder for the OS API function -** OS_TimerDelete. It always returns OS_ERR_INVALID_ID. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_ERR_INVALID_ID. -** -******************************************************************************/ -int32 OS_TimerDelete(osal_id_t timer_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerDelete), timer_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMECB, timer_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_TimerGetIdByName() - * - *****************************************************************************/ -int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TimerGetIdByName), timer_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimerGetIdByName), timer_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetIdByName), timer_id, sizeof(*timer_id)) < sizeof(*timer_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMECB, timer_id); - } - - return status; -} - -/*****************************************************************************/ -/** -** \brief OS_TimerGetInfo stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TimerGetInfo. The user can adjust the response by setting -** the values in the OSTimerGetInfoRtn structure prior to this function -** being called. If the value OSTimerGetInfoRtn.count is greater than -** zero then the counter is decremented and the timer creator value is -** set to the user-defined value OSTimerGetInfoRtn.value. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns OS_SUCCESS. -** -******************************************************************************/ -int32 OS_TimerGetInfo(osal_id_t timer_id, OS_timer_prop_t *timer_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimerGetInfo), timer_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimerGetInfo), timer_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimerGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TimerGetInfo), timer_prop, sizeof(*timer_prop)) < sizeof(*timer_prop)) - { - memset(timer_prop, 0, sizeof(*timer_prop)); - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timer_prop->creator); - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-timebase.c b/src/ut-stubs/osapi-utstub-timebase.c deleted file mode 100644 index b439eb1e0..000000000 --- a/src/ut-stubs/osapi-utstub-timebase.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 United States Government as represented by - * the Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file osapi_stubs.c - * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov - * - * Stub implementations for the functions defined in the OSAL API - * - * The stub implementation can be used for unit testing applications built - * on top of OSAL. The stubs do not do any real function, but allow - * the return code to be crafted such that error paths in the application - * can be executed. - */ - -#include "osapi-timebase.h" /* OSAL public API for this subsystem */ -#include "utstub-helpers.h" - -UT_DEFAULT_STUB(OS_TimeBaseAPI_Init, (void)) - -/***************************************************************************** - * - * Stub for OS_TimeBaseCreate() function - * - *****************************************************************************/ -int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t external_sync) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseCreate), timebase_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseCreate), timebase_name); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseCreate), external_sync); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseCreate); - - if (status == OS_SUCCESS) - { - *timebase_id = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE); - } - else - { - *timebase_id = UT_STUB_FAKE_OBJECT_ID; - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBaseSet() function - * - *****************************************************************************/ -int32 OS_TimeBaseSet(osal_id_t timebase_id, uint32 start_time, uint32 interval_time) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseSet), timebase_id); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseSet), start_time); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseSet), interval_time); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseSet); - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBaseDelete() function - * - *****************************************************************************/ -int32 OS_TimeBaseDelete(osal_id_t timebase_id) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseDelete), timebase_id); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseDelete); - - if (status == OS_SUCCESS) - { - UT_DeleteStubObjId(OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBaseGetIdByName() function - * - *****************************************************************************/ -int32 OS_TimeBaseGetIdByName(osal_id_t *timebase_id, const char *timebase_name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseGetIdByName), timebase_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseGetIdByName), timebase_name); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseGetIdByName); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetIdByName), timebase_id, sizeof(*timebase_id)) < sizeof(*timebase_id)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TIMEBASE, timebase_id); - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBaseGetInfo() function - * - *****************************************************************************/ -int32 OS_TimeBaseGetInfo(osal_id_t timebase_id, OS_timebase_prop_t *timebase_prop) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseGetInfo), timebase_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseGetInfo), timebase_prop); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseGetInfo); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetInfo), timebase_prop, sizeof(*timebase_prop)) < sizeof(*timebase_prop)) - { - UT_ObjIdCompose(1, OS_OBJECT_TYPE_OS_TASK, &timebase_prop->creator); - strncpy(timebase_prop->name, "Name", sizeof(timebase_prop->name) - 1); - timebase_prop->name[sizeof(timebase_prop->name) - 1] = '\0'; - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBaseGetFreeRun() function - * - *****************************************************************************/ -int32 OS_TimeBaseGetFreeRun(osal_id_t timebase_id, uint32 *freerun_val) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_TimeBaseGetFreeRun), timebase_id); - UT_Stub_RegisterContext(UT_KEY(OS_TimeBaseGetFreeRun), freerun_val); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_TimeBaseGetFreeRun); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_TimeBaseGetFreeRun), freerun_val, sizeof(*freerun_val)) < sizeof(*freerun_val)) - { - int32 tempcount; - int32 temprc; - - /* - * Use the call count such that the value increases with each successive call. - * If that doesn't work then just return a constant nonzero value. - */ - if (UT_GetStubRetcodeAndCount(UT_KEY(OS_TimeBaseGetFreeRun), &temprc, &tempcount)) - { - *freerun_val = tempcount; - } - else - { - *freerun_val = 1; - } - } - - return status; -} - -/***************************************************************************** - * - * Stub for OS_TimeBase_CallbackThread() function - * - *****************************************************************************/ -void OS_TimeBase_CallbackThread(uint32 timebase_id) -{ - UT_DEFAULT_IMPL(OS_TimeBase_CallbackThread); -} - -/***************************************************************************** - * - * Stub for OS_Milli2Ticks() function - * - *****************************************************************************/ -int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_Milli2Ticks), milli_seconds); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_Milli2Ticks), ticks); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_Milli2Ticks); - - if (status >= 0) - { - UT_Stub_CopyToLocal(UT_KEY(OS_Milli2Ticks), (uint8 *)ticks, sizeof(*ticks)); - } - - return status; -} diff --git a/src/ut-stubs/osapi-utstub-version.c b/src/ut-stubs/osapi-version-hooks.c similarity index 52% rename from src/ut-stubs/osapi-utstub-version.c rename to src/ut-stubs/osapi-version-hooks.c index c52c49435..a1201872c 100644 --- a/src/ut-stubs/osapi-utstub-version.c +++ b/src/ut-stubs/osapi-version-hooks.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API * @@ -35,15 +33,12 @@ #include "osapi-version.h" /* OSAL public API for this subsystem */ #include "utstub-helpers.h" -/*---------------------------------------------------------------- - * - * Function: OS_GetVersionString - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -const char *OS_GetVersionString(void) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetVersionString' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetVersionString(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { static const char DEFAULT[] = "UT"; void * Buffer; @@ -59,18 +54,15 @@ const char *OS_GetVersionString(void) RetVal = Buffer; } - return RetVal; + UT_Stub_SetReturnValue(FuncKey, RetVal); } -/*---------------------------------------------------------------- - * - * Function: OS_GetVersionCodeName - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -const char *OS_GetVersionCodeName(void) +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetVersionCodeName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetVersionCodeName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { static const char DEFAULT[] = "UT"; void * Buffer; @@ -86,36 +78,5 @@ const char *OS_GetVersionCodeName(void) RetVal = Buffer; } - return RetVal; -} - -/*---------------------------------------------------------------- - * - * Function: OS_GetVersionNumber - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -void OS_GetVersionNumber(uint8 VersionNumbers[4]) -{ - UT_Stub_RegisterContext(UT_KEY(OS_GetVersionNumber), VersionNumbers); - UT_DEFAULT_IMPL(VersionNumbers); -} - -/*---------------------------------------------------------------- - * - * Function: OS_GetBuildNumber - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -uint32 OS_GetBuildNumber(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL(OS_GetBuildNumber); - - return status; + UT_Stub_SetReturnValue(FuncKey, RetVal); } diff --git a/src/ut-stubs/osapi-version-stubs.c b/src/ut-stubs/osapi-version-stubs.c new file mode 100644 index 000000000..c9c0d80b6 --- /dev/null +++ b/src/ut-stubs/osapi-version-stubs.c @@ -0,0 +1,84 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in osapi-version header + */ + +#include "osapi-version.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_GetVersionCodeName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_GetVersionString(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetBuildNumber() + * ---------------------------------------------------- + */ +uint32 OS_GetBuildNumber(void) +{ + UT_GenStub_SetupReturnBuffer(OS_GetBuildNumber, uint32); + + UT_GenStub_Execute(OS_GetBuildNumber, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_GetBuildNumber, uint32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetVersionCodeName() + * ---------------------------------------------------- + */ +const char *OS_GetVersionCodeName(void) +{ + UT_GenStub_SetupReturnBuffer(OS_GetVersionCodeName, const char *); + + UT_GenStub_Execute(OS_GetVersionCodeName, Basic, UT_DefaultHandler_OS_GetVersionCodeName); + + return UT_GenStub_GetReturnValue(OS_GetVersionCodeName, const char *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetVersionNumber() + * ---------------------------------------------------- + */ +void OS_GetVersionNumber(uint8 VersionNumbers[4]) +{ + + UT_GenStub_Execute(OS_GetVersionNumber, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetVersionString() + * ---------------------------------------------------- + */ +const char *OS_GetVersionString(void) +{ + UT_GenStub_SetupReturnBuffer(OS_GetVersionString, const char *); + + UT_GenStub_Execute(OS_GetVersionString, Basic, UT_DefaultHandler_OS_GetVersionString); + + return UT_GenStub_GetReturnValue(OS_GetVersionString, const char *); +} diff --git a/src/ut-stubs/utstub-helpers.c b/src/ut-stubs/utstub-helpers.c index 4050b2726..53b74cbc9 100644 --- a/src/ut-stubs/utstub-helpers.c +++ b/src/ut-stubs/utstub-helpers.c @@ -19,10 +19,8 @@ */ /** - * \file osapi_stubs.c + * \file * - * Created on: Feb 25, 2015 - * Author: joseph.p.hickey@nasa.gov * * Stub implementations for the functions defined in the OSAL API *