From ccf9215f0ac65a2bba333759f75897923a0b770a Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 12 Apr 2021 11:01:38 -0400 Subject: [PATCH 01/12] Fix #957, move async console option Puts the "async" option into the shared layer instead of the impl layer. This allows both options to be coverage tested and also allows a bit more of the logic to be common instead of duplicated in the 3 implementations. This also adds back an osconfig option to allow the user to elect this mode at configuration time. --- default_config.cmake | 25 +++++++++++++++++++ osconfig.h.in | 1 + src/os/posix/inc/os-impl-console.h | 1 - src/os/posix/src/os-impl-console.c | 22 ++++++---------- src/os/rtems/inc/os-impl-console.h | 1 - src/os/rtems/src/os-impl-console.c | 25 +++++++------------ src/os/shared/inc/os-shared-printf.h | 9 +++---- src/os/shared/src/osapi-printf.c | 22 +++++++++++++++- src/os/vxworks/inc/os-impl-console.h | 1 - src/os/vxworks/src/os-impl-console.c | 20 +++++---------- .../shared/src/coveragetest-printf.c | 23 ++++++++++++----- .../vxworks/adaptors/inc/ut-adaptor-console.h | 5 ---- .../vxworks/adaptors/src/ut-adaptor-console.c | 5 ---- .../vxworks/src/coveragetest-console.c | 18 +++++++------ 14 files changed, 101 insertions(+), 77 deletions(-) diff --git a/default_config.cmake b/default_config.cmake index f71dafbc5..2ba2c0d1d 100644 --- a/default_config.cmake +++ b/default_config.cmake @@ -180,6 +180,31 @@ set(OSAL_CONFIG_DEBUG_PRINTF FALSE CACHE BOOL "Controls inclusion of OS_DEBUG statements in the code" ) +# +# OS_CONFIG_CONSOLE_ASYNC +# ---------------------------------- +# +# Controls whether the console device writes (OS_printf) will be deferred +# to a separate utility task or handled directly by the calling task. +# +# If set FALSE, the utility task WILL NOT be spawned, and all OS_printf() +# calls will be synchronously written to the console device. +# +# If set TRUE, an extra utility task WILL be spawned, and the data from +# all OS_printf() calls will be written to an output queue which is then +# transferred to the console device by the utility task. +# +# When this is TRUE (default), it may improve real time performance by not +# requiring the caller to delay on a potentially slow console device output. +# +# However decoupling in this manner requires creation of an extra task and +# stack to handle the output, and a side effect is that the OS_printf() output +# can become decoupled from the event/task where it actually occurred, or +# messages might appear in a different order than they originally occurred. +# +set(OSAL_CONFIG_CONSOLE_ASYNC TRUE + CACHE BOOL "Controls spawning of a separate utility task for OS_printf" +) ############################################# # Resource Limits for the OS API diff --git a/osconfig.h.in b/osconfig.h.in index a7f947b18..fc1710b2d 100644 --- a/osconfig.h.in +++ b/osconfig.h.in @@ -44,6 +44,7 @@ #cmakedefine OSAL_CONFIG_INCLUDE_SHELL #cmakedefine OSAL_CONFIG_DEBUG_PRINTF #cmakedefine OSAL_CONFIG_DEBUG_PERMISSIVE_MODE +#cmakedefine OSAL_CONFIG_CONSOLE_ASYNC #cmakedefine OSAL_CONFIG_BUGCHECK_DISABLE #cmakedefine OSAL_CONFIG_BUGCHECK_STRICT diff --git a/src/os/posix/inc/os-impl-console.h b/src/os/posix/inc/os-impl-console.h index ac0140053..73faaedb6 100644 --- a/src/os/posix/inc/os-impl-console.h +++ b/src/os/posix/inc/os-impl-console.h @@ -36,7 +36,6 @@ /* Console device */ typedef struct { - bool is_async; sem_t data_sem; } OS_impl_console_internal_record_t; diff --git a/src/os/posix/src/os-impl-console.c b/src/os/posix/src/os-impl-console.c index 672770fc7..0dff3e863 100644 --- a/src/os/posix/src/os-impl-console.c +++ b/src/os/posix/src/os-impl-console.c @@ -68,16 +68,9 @@ void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); - if (local->is_async) - { - /* post the sem for the utility task to run */ - sem_post(&local->data_sem); - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(token); - } + /* post the sem for the utility task to run */ + sem_post(&local->data_sem); + } /* end OS_ConsoleWakeup_Impl */ /*---------------------------------------------------------------- @@ -121,18 +114,19 @@ static void *OS_ConsoleTask_Entry(void *arg) int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { OS_impl_console_internal_record_t *local; + OS_console_internal_record_t * console; pthread_t consoletask; int32 return_code; OS_VoidPtrValueWrapper_t local_arg = {0}; - local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); if (token->obj_idx == 0) { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; + return_code = OS_SUCCESS; - if (local->is_async) + if (console->IsAsync) { if (sem_init(&local->data_sem, 0, 0) < 0) { diff --git a/src/os/rtems/inc/os-impl-console.h b/src/os/rtems/inc/os-impl-console.h index b015783a9..1ad387fa3 100644 --- a/src/os/rtems/inc/os-impl-console.h +++ b/src/os/rtems/inc/os-impl-console.h @@ -36,7 +36,6 @@ /* Console device */ typedef struct { - bool is_async; sem_t data_sem; } OS_impl_console_internal_record_t; diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c index 7aa2622e3..08e83c9b3 100644 --- a/src/os/rtems/src/os-impl-console.c +++ b/src/os/rtems/src/os-impl-console.c @@ -67,7 +67,6 @@ /* Console device */ typedef struct { - bool is_async; rtems_id data_sem; int out_fd; } OS_impl_console_internal_record_t; @@ -93,16 +92,9 @@ void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); - if (local->is_async) - { - /* post the sem for the utility task to run */ - rtems_semaphore_release(local->data_sem); - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(token); - } + /* post the sem for the utility task to run */ + rtems_semaphore_release(local->data_sem); + } /* end OS_ConsoleWakeup_Impl */ /*---------------------------------------------------------------- @@ -143,20 +135,21 @@ static void OS_ConsoleTask_Entry(rtems_task_argument arg) int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) { OS_impl_console_internal_record_t *local; + OS_console_internal_record_t * console; int32 return_code; rtems_name r_name; rtems_id r_task_id; rtems_status_code status; - local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); + console = OS_OBJECT_TABLE_GET(OS_console_table, *token); if (OS_ObjectIndexFromToken(token) == 0) { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; - local->out_fd = OSAL_CONSOLE_FILENO; + return_code = OS_SUCCESS; + local->out_fd = OSAL_CONSOLE_FILENO; - if (local->is_async) + if (console->IsAsync) { OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); /* diff --git a/src/os/shared/inc/os-shared-printf.h b/src/os/shared/inc/os-shared-printf.h index b1cce4fcc..e221016ae 100644 --- a/src/os/shared/inc/os-shared-printf.h +++ b/src/os/shared/inc/os-shared-printf.h @@ -50,6 +50,7 @@ typedef struct volatile size_t ReadPos; /**< Offset of next byte to read */ volatile size_t WritePos; /**< Offset of next byte to write */ uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ + bool IsAsync; } OS_console_internal_record_t; @@ -89,17 +90,15 @@ int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); void OS_ConsoleOutput_Impl(const OS_object_token_t *token); /*---------------------------------------------------------------- - Function: OS_ConsoleOutput_Impl + Function: OS_ConsoleWakeup_Impl Purpose: Console output data notification This is a notification API that is invoked whenever there is new data available in the console output buffer. - For a synchronous console service, this may call - OS_ConsoleWrite_Impl() directly. For an async console - service, this should wakeup the actual console servicing - thread. + It is only used of the console is configured for async operation, + and it should wakeup the actual console servicing thread. ------------------------------------------------------------------*/ void OS_ConsoleWakeup_Impl(const OS_object_token_t *token); diff --git a/src/os/shared/src/osapi-printf.c b/src/os/shared/src/osapi-printf.c index a21f55b36..677fc8c3c 100644 --- a/src/os/shared/src/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -56,6 +56,16 @@ #include "os-shared-idmap.h" #include "os-shared-printf.h" +/* + * The choice of whether to run a separate utility task + * comes from osal compile-time config + */ +#ifdef OSAL_CONFIG_CONSOLE_ASYNC +#define OS_CONSOLE_IS_ASYNC true +#else +#define OS_CONSOLE_IS_ASYNC false +#endif + /* reserve buffer memory for the printf console device */ static char OS_printf_buffer_mem[(sizeof(OS_PRINTF_CONSOLE_NAME) + OS_BUFFER_SIZE) * OS_BUFFER_MSG_DEPTH]; @@ -99,6 +109,7 @@ int32 OS_ConsoleAPI_Init(void) */ console->BufBase = OS_printf_buffer_mem; console->BufSize = sizeof(OS_printf_buffer_mem); + console->IsAsync = OS_CONSOLE_IS_ASYNC; return_code = OS_ConsoleCreate_Impl(&token); @@ -234,7 +245,16 @@ int32 OS_ConsoleWrite(osal_id_t console_id, const char *Str) * This is done while still locked, so it can support * either a synchronous or asynchronous implementation. */ - OS_ConsoleWakeup_Impl(&token); + if (console->IsAsync) + { + /* post the sem for the utility task to run */ + OS_ConsoleWakeup_Impl(&token); + } + else + { + /* output directly */ + OS_ConsoleOutput_Impl(&token); + } OS_ObjectIdRelease(&token); } diff --git a/src/os/vxworks/inc/os-impl-console.h b/src/os/vxworks/inc/os-impl-console.h index f87c9203f..862225646 100644 --- a/src/os/vxworks/inc/os-impl-console.h +++ b/src/os/vxworks/inc/os-impl-console.h @@ -37,7 +37,6 @@ typedef struct { VX_COUNTING_SEMAPHORE(cmem); - bool is_async; SEM_ID datasem; TASK_ID taskid; } OS_impl_console_internal_record_t; diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c index 9fc250814..bc5dd1664 100644 --- a/src/os/vxworks/src/os-impl-console.c +++ b/src/os/vxworks/src/os-impl-console.c @@ -74,19 +74,12 @@ void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) local = OS_OBJECT_TABLE_GET(OS_impl_console_table, *token); - if (local->is_async) + /* post the sem for the utility task to run */ + if (semGive(local->datasem) == ERROR) { - /* post the sem for the utility task to run */ - if (semGive(local->datasem) == ERROR) - { - OS_DEBUG("semGive() - vxWorks errno %d\n", errno); - } - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(token); + OS_DEBUG("semGive() - vxWorks errno %d\n", errno); } + } /* end OS_ConsoleWakeup_Impl */ /*---------------------------------------------------------------- @@ -142,10 +135,9 @@ int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) if (OS_ObjectIndexFromToken(token) == 0) { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; + return_code = OS_SUCCESS; - if (local->is_async) + if (console->IsAsync) { OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index e27780d1d..6592cd941 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -64,7 +64,6 @@ void Test_OS_printf(void) * void OS_printf_disable(void); * void OS_printf_enable(void); */ - uint32 CallCount = 0; /* catch case where OS_printf called before init */ OS_SharedGlobalVars.PrintfConsoleId = OS_OBJECT_ID_UNDEFINED; @@ -80,17 +79,29 @@ void Test_OS_printf(void) UtAssert_True(OS_console_table[0].WritePos == 0, "WritePos (%lu) >= 0", (unsigned long)OS_console_table[0].WritePos); - /* normal case */ + /* normal case - sync mode */ + OS_console_table[0].IsAsync = false; OS_printf_enable(); - OS_printf("UnitTest3"); - CallCount = UT_GetStubCount(UT_KEY(OS_ConsoleWakeup_Impl)); - UtAssert_True(CallCount == 1, "OS_ConsoleWakeup_Impl() call count (%lu) == 1", (unsigned long)CallCount); - UtAssert_True(OS_console_table[0].WritePos >= 9, "WritePos (%lu) >= 9", + OS_printf("UnitTest3s"); + UtAssert_STUB_COUNT(OS_ConsoleWakeup_Impl, 0); + UtAssert_STUB_COUNT(OS_ConsoleOutput_Impl, 1); + UtAssert_True(OS_console_table[0].WritePos >= 10, "WritePos (%lu) >= 10", + (unsigned long)OS_console_table[0].WritePos); + + /* normal case - async mode */ + OS_console_table[0].IsAsync = true; + OS_console_table[0].WritePos = 0; + OS_printf("UnitTest3a"); + UtAssert_STUB_COUNT(OS_ConsoleWakeup_Impl, 1); + UtAssert_STUB_COUNT(OS_ConsoleOutput_Impl, 1); + UtAssert_True(OS_console_table[0].WritePos >= 10, "WritePos (%lu) >= 10", (unsigned long)OS_console_table[0].WritePos); /* print a long string that does not fit in the 16-char buffer */ OS_printf_enable(); OS_printf("UnitTest4BufferLengthExceeded"); + UtAssert_True(OS_console_table[0].OverflowEvents == 1, "OverflowEvents (%lu) == 1", + (unsigned long)OS_console_table[0].OverflowEvents); /* test writing with a non-empty console name */ strncpy(OS_console_table[0].device_name, "ut", sizeof(OS_console_table[0].device_name) - 1); diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h index 73890d11b..83a1b47b1 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h @@ -39,9 +39,4 @@ extern size_t const UT_Ref_OS_impl_console_table_SIZE; */ extern void UT_ConsoleTest_TaskEntry(int arg); -/** - * Force the "is_async" field to a given state for coverage testing - */ -extern void UT_ConsoleTest_SetConsoleAsync(osal_index_t local_id, bool is_async); - #endif /* UT_ADAPTOR_CONSOLE_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c index c69adb7ee..8909b537b 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c @@ -39,8 +39,3 @@ void UT_ConsoleTest_TaskEntry(int arg) { OS_VxWorks_ConsoleTask_Entry(arg); } - -void UT_ConsoleTest_SetConsoleAsync(osal_index_t local_id, bool is_async) -{ - OS_impl_console_table[local_id].is_async = is_async; -} diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-console.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c index 1865b4afa..0746f74fc 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-console.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -43,18 +43,13 @@ void Test_OS_ConsoleWakeup_Impl(void) */ OS_object_token_t token = UT_TOKEN_0; - /* no return code - check for coverage */ - UT_ConsoleTest_SetConsoleAsync(0, true); + /* this just gives the sem, only called in async mode */ OS_ConsoleWakeup_Impl(&token); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode"); + /* Failure only causes a debug message to be generated, no error handling here */ UT_SetDefaultReturnValue(UT_KEY(OCS_semGive), -1); OS_ConsoleWakeup_Impl(&token); - - UT_ConsoleTest_SetConsoleAsync(0, false); - OS_console_table[0].WritePos = 1; - OS_ConsoleWakeup_Impl(&token); - UtAssert_True(UT_GetStubCount(UT_KEY(OS_ConsoleOutput_Impl)) == 1, "OS_ConsoleOutput_Impl() called in sync mode"); } void Test_OS_ConsoleCreate_Impl(void) @@ -63,8 +58,15 @@ void Test_OS_ConsoleCreate_Impl(void) memset(&token, 0, sizeof(token)); + /* Verify coverage when configured for sync mode */ + OS_console_table[0].IsAsync = false; + OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SUCCESS); + UtAssert_STUB_COUNT(OCS_taskSpawn, 0); /* Task _was not_ spawned */ + + /* Verify coverage when configured for async mode */ + OS_console_table[0].IsAsync = true; OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SUCCESS); - UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskSpawn)) == 1, "taskSpawn() called"); + UtAssert_STUB_COUNT(OCS_taskSpawn, 1); /* Task _was_ spawned */ UT_SetDefaultReturnValue(UT_KEY(OCS_semCInitialize), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_ConsoleCreate_Impl(&token), OS_SEM_FAILURE); From ed5c3a9fe01b992b5e69c29925361e5a016bd63e Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 9 Apr 2021 18:10:10 +0000 Subject: [PATCH 02/12] Fix #419, Add makefile to simplify local build --- .gitignore | 3 +- Makefile.sample | 152 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 Makefile.sample diff --git a/.gitignore b/.gitignore index 9f5386bd0..dd5959f69 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build/inc/ +build +Makefile diff --git a/Makefile.sample b/Makefile.sample new file mode 100644 index 000000000..a49cd2093 --- /dev/null +++ b/Makefile.sample @@ -0,0 +1,152 @@ +# +# Operating System Abstraction Layer CMake / GNU make wrapper +# +# ABOUT THIS MAKEFILE: +# It is a GNU-make wrapper that calls the CMake tools appropriately +# so that setting up a new build is fast and easy with no need to +# learn the CMake commands. It also makes it easier to integrate +# the build with IDE tools such as Eclipse by providing a default +# makefile that has the common targets such as all/clean/etc. +# +# Use of this file is optional. +# +# For _ALL_ targets defined in this file the build tree location may +# be specified via the "O" variable (i.e. make O= all). +# If not specified then the "build" subdirectory will be assumed. +# +# This wrapper defines the following major targets: +# prep -- Runs CMake to create a new or re-configure an existing build tree +# Note that multiple build trees can exist from a single source +# Other control options may be passed to CMake via +# make variables depending on the mission build scripts. These will be +# cached in the build tree so they do not need to be set again thereafter. +# +# all -- Build all targets in the CMake build tree +# +# install -- Copy all files to the installation tree and run packaging scripts +# The "DESTDIR" and "INSTALLPREFIX" environment variables control where the +# files are copied +# +# clean -- Clean all targets in the CMake build tree, but not the build tree itself. +# +# distclean -- Entirely remove the build directory specified by "O" +# Note that after this the "prep" step must be run again in order to build. +# Use caution with this as it does an rm -rf - don't set O to your home dir! +# +# test -- Run all unit tests defined in the build on the host. This will not +# work if the BSPTYPE selection is not compatible with the host. +# In that case it is up to the user to copy the executables to the target +# and run them. +# +# lcov -- Runs the "lcov" tool on the build tree to collect all code coverage +# analysis data and build the reports. Code coverage data may be created by +# the "make test" target above. +# + +# Establish default values for critical variables. Any of these may be overridden +# on the command line or via the make environment configuration in an IDE +O ?= build +BSPTYPE ?= generic-linux +BUILDTYPE ?= debug +INSTALLPREFIX ?= /exe +DESTDIR ?= $(O) + +# The "DESTDIR" variable is a bit more complicated because it should be an absolute +# path for CMake, but we want to accept either absolute or relative paths. So if +# the path does NOT start with "/", prepend it with the current directory. +ifeq ($(filter /%, $(DESTDIR)),) +DESTDIR := $(CURDIR)/$(DESTDIR) +endif + +# The "LOCALTGTS" defines the top-level targets that are implemented in this makefile +# Any other target may also be given, in that case it will simply be passed through. +LOCALTGTS := prep all clean install distclean test lcov +OTHERTGTS := $(filter-out $(LOCALTGTS),$(MAKECMDGOALS)) + +# As this makefile does not build any real files, treat everything as a PHONY target +# This ensures that the rule gets executed even if a file by that name does exist +.PHONY: $(LOCALTGTS) $(OTHERTGTS) + +# If the target name appears to be a directory (ends in /), do a make all in that directory +DIRTGTS := $(filter %/,$(OTHERTGTS)) +ifneq ($(DIRTGTS),) +$(DIRTGTS): + $(MAKE) -C $(O)/$(patsubst $(O)/%,%,$(@)) all +endif + +# For any other goal that is not one of the known local targets, pass it to the build +# as there might be a target by that name. For example, this is useful for rebuilding +# single unit test executable files while debugging from the IDE +FILETGTS := $(filter-out $(DIRTGTS),$(OTHERTGTS)) +ifneq ($(FILETGTS),) +$(FILETGTS): + $(MAKE) -C $(O) $(@) +endif + +# The "prep" step requires extra options that are specified via enviroment variables. +# Certain special ones should be passed via cache (-D) options to CMake. +# These are only needed for the "prep" target but they are computed globally anyway. +# +# Note this simple makefile just builds for one target, could trivally manage +# multiple targets by changing build directory. More complex target +# list examples are provide by cFE.. +PREP_OPTS := -DOSAL_SYSTEM_BSPTYPE=$(BSPTYPE) -DINSTALL_TARGET_LIST=. + +ifneq ($(INSTALLPREFIX),) +PREP_OPTS += -DCMAKE_INSTALL_PREFIX=$(INSTALLPREFIX) +endif + +ifneq ($(VERBOSE),) +PREP_OPTS += --trace +endif + +ifneq ($(OMIT_DEPRECATED),) +PREP_OPTS += -DOSAL_OMIT_DEPRECATED=$(OMIT_DEPRECATED) +endif + +ifneq ($(BUILDTYPE),) +PREP_OPTS += -DCMAKE_BUILD_TYPE=$(BUILDTYPE) +endif + +ifneq ($(ENABLE_UNIT_TESTS),) +PREP_OPTS += -DENABLE_UNIT_TESTS=$(ENABLE_UNIT_TESTS) +endif + +ifneq ($(PERMISSIVE_MODE),) +PREP_OPTS += -DOSAL_CONFIG_DEBUG_PERMISSIVE_MODE=$(PERMISSIVE_MODE) +endif + +all: + $(MAKE) --no-print-directory -C "$(O)" all + +install: + $(MAKE) --no-print-directory -C "$(O)" DESTDIR="${DESTDIR}" install + +prep $(O)/.prep: + mkdir -p "$(O)" + (cd "$(O)" && cmake $(PREP_OPTS) "$(CURDIR)") + echo "$(PREP_OPTS)" > "$(O)/.prep" + +clean: + $(MAKE) --no-print-directory -C "$(O)" clean + +distclean: + rm -rf "$(O)" + +# Grab lcov baseline before running tests +test: + lcov --capture --initial --directory $(O) --output-file $(O)/coverage_base.info + $(MAKE) --no-print-directory -C "$(O)" test + +lcov: + lcov --capture --rc lcov_branch_coverage=1 --directory $(O) --output-file $(O)/coverage_test.info + lcov --rc lcov_branch_coverage=1 --add-tracefile $(O)/coverage_base.info --add-tracefile $(O)/coverage_test.info --output-file $(O)/coverage_total.info + genhtml $(O)/coverage_total.info --branch-coverage --output-directory $(O)/lcov + @/bin/echo -e "\n\nCoverage Report Link: file:$(CURDIR)/$(O)/lcov/index.html\n" + + +# Make all the commands that use the build tree depend on a flag file +# that is used to indicate the prep step has been done. This way +# the prep step does not need to be done explicitly by the user +# as long as the default options are sufficient. +$(filter-out prep distclean,$(LOCALTGTS)): $(O)/.prep From 497881b3395658d2cf739827bf086d3b5286557b Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 9 Apr 2021 18:10:59 +0000 Subject: [PATCH 03/12] Fix #729, Add local and bundle unit test action with coverage verification --- .github/workflows/codeql-build.yml | 13 +++------ .github/workflows/local_unit_test.yml | 41 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/local_unit_test.yml diff --git a/.github/workflows/codeql-build.yml b/.github/workflows/codeql-build.yml index 46f0ee81f..7d458fbb5 100644 --- a/.github/workflows/codeql-build.yml +++ b/.github/workflows/codeql-build.yml @@ -17,7 +17,6 @@ jobs: timeout-minutes: 15 steps: - # Checks out a copy of your repository on the ubuntu-latest machine - name: Checkout bundle uses: actions/checkout@v2 with: @@ -38,21 +37,17 @@ jobs: languages: c queries: +security-extended, security-and-quality - # Setup the build system - name: Set up for build run: | cp ./cfe/cmake/Makefile.sample Makefile cp -r ./cfe/cmake/sample_defs sample_defs make prep - # Build the code - name: Build - run: | - make osal - make native/default_cpu1/osal/tests/ - make native/default_cpu1/osal/unit-test-coverage/ - make native/default_cpu1/osal/unit-tests/ - make native/default_cpu1/osal/ut-stubs/ + run: make -j native/default_cpu1/osal/ + + - name: Run tests + run: (cd build/native/default_cpu1/osal && make test) - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/local_unit_test.yml b/.github/workflows/local_unit_test.yml new file mode 100644 index 000000000..17da300b9 --- /dev/null +++ b/.github/workflows/local_unit_test.yml @@ -0,0 +1,41 @@ +name: "Local Unit Test" + +on: + push: + pull_request: + +jobs: + + Local-Unit-Test: + runs-on: ubuntu-18.04 + timeout-minutes: 15 + + steps: + - name: Install coverage tools + run: sudo apt-get install lcov -y + + - name: Checkout submodule + uses: actions/checkout@v2 + + - name: Set up for build + run: | + cp Makefile.sample Makefile + make ENABLE_UNIT_TESTS=true PERMISSIVE_MODE=true prep + + - name: Build the code + run: make -j + + # Baseline lcov and run all tests + - name: Test + run: make test + + - name: Calculate coverage + run: make lcov | tee lcov_out.txt + + - name: Confirm 100% line coverage + run: | + if [[ `grep -A 3 "Overall coverage rate" lcov_out.txt | grep lines` != *"100.0%"* ]]; then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "Lacks 100.0% line unit test coverage" + exit -1 + fi From c2736b3168840111cc969b8585c2e4aa501677c4 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 9 Apr 2021 19:06:09 +0000 Subject: [PATCH 04/12] Fix #954, Additional coverage for OS_SocketAccept_Impl --- .../portable/src/coveragetest-bsd-sockets.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c index 95f570dd8..be2912a34 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c @@ -242,6 +242,24 @@ void Test_OS_SocketAccept_Impl(void) /* Success case */ OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); + + /* Failure in fcntl() GETFL */ + UT_PortablePosixIOTest_ResetImpl(conn_token.obj_idx); + UT_ResetState(UT_KEY(OCS_fcntl)); + UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); + UtAssert_STUB_COUNT(OCS_fcntl, 1); + UtAssert_True(!UT_PortablePosixIOTest_Get_Selectable(conn_token.obj_idx), + "Socket not selectable without O_NONBLOCK flag"); + + /* Failure in fcntl() SETFL */ + UT_PortablePosixIOTest_ResetImpl(conn_token.obj_idx); + UT_ResetState(UT_KEY(OCS_fcntl)); + UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 2, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); + UtAssert_STUB_COUNT(OCS_fcntl, 2); + UtAssert_True(!UT_PortablePosixIOTest_Get_Selectable(conn_token.obj_idx), + "Socket not selectable without O_NONBLOCK flag"); } void Test_OS_SocketRecvFrom_Impl(void) From 838a7eba78e9cecbda1909ea31a1c6062b53a340 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 15 Apr 2021 23:20:07 -0400 Subject: [PATCH 05/12] Fix #832, add "handler" feature to utassert stub API Adds the concept of a "handler" function to UT assert. A handler is basically the custom logic that exists between the hook function and the return to the stub caller. In current UT stubs, this is hard coded, and it generally comprises setting output parameters and translating return values as needed. This concept adds the basic plumbing to allow the handler to be configured just like a hook function already does. The difference is that the handler is directly responsible for setting all outputs. This also includes a script to auto-generate stub functions that match this pattern. Given an API header file, the script extracts the declarations, and generates a source file with stub definitions that rely on a separate handler to deal with the needed outputs. Note this initial commit only adds the basic framework. It does not change any existing stubs or tests, and is fully backward compatible, as it is a new feature and it is a no-op unless actually configured/used by the stub or test case. Follow on commits will update the stubs to use this pattern. --- ut_assert/inc/utgenstub.h | 81 ++++++ ut_assert/inc/utstubs.h | 228 +++++++++++++++- ut_assert/scripts/generate_stubs.pl | 405 ++++++++++++++++++++++++++++ ut_assert/src/utstubs.c | 305 +++++++++++++++++---- 4 files changed, 970 insertions(+), 49 deletions(-) create mode 100644 ut_assert/inc/utgenstub.h create mode 100755 ut_assert/scripts/generate_stubs.pl diff --git a/ut_assert/inc/utgenstub.h b/ut_assert/inc/utgenstub.h new file mode 100644 index 000000000..97dcea067 --- /dev/null +++ b/ut_assert/inc/utgenstub.h @@ -0,0 +1,81 @@ +/* + * 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 + * + * Provides a set of macros to facilitate generating stub code + * + * These macros are primarily used in the code generated by the "generate_stubs.pl" script + */ + +#ifndef UTGENSTUB_H +#define UTGENSTUB_H + +#include "common_types.h" +#include "utstubs.h" + +/** + * Helper macro to set up a return buffer in a generated stub + * + * Registers a buffer that the hook/handler can fill. This works + * with any return data type, not just int32. + * + * \param FuncName The name of the function + * \param ReturnType The type of return value + */ +#define UT_GenStub_SetupReturnBuffer(FuncName, ReturnType) \ + UT_Stub_RegisterReturnType(UT_KEY(FuncName), sizeof(ReturnType)) + +/** + * Helper macro to get the return value from the handler + * + * Gets the value exported from the hook/handler + * + * \param FuncName The name of the function + * \param ReturnType The type of return value + */ +#define UT_GenStub_GetReturnValue(FuncName, ReturnType) \ + (*(ReturnType *)UT_Stub_GetReturnValuePtr(UT_KEY(FuncName), sizeof(ReturnType))) + +/** + * Helper macro to add a local parameter to the current context + * + * This makes the parameter accessible from hook/handler functions + * + * \param FuncName The name of the function + * \param ParamType The type of the parameter + * \param ParamName The name of the parameter + */ +#define UT_GenStub_AddParam(FuncName, ParamType, ParamName) \ + UT_Stub_RegisterContextWithMetaData(UT_KEY(FuncName), #ParamName, UT_STUBCONTEXT_ARG_TYPE_INDIRECT, &(ParamName), \ + sizeof(ParamType)) + +/** + * Helper macro to execute the actual stub handler + * + * Additional arguments are passed through + * + * \param FuncName The name of the function + * \param Type The type of handler to execute (Va or Basic) + */ +#define UT_GenStub_Execute(FuncName, Type, ...) UT_Execute##Type##Handler(UT_KEY(FuncName), #FuncName, __VA_ARGS__); + +#endif /* UTGENSTUB_H */ diff --git a/ut_assert/inc/utstubs.h b/ut_assert/inc/utstubs.h index aa5c37b2a..ed593b208 100644 --- a/ut_assert/inc/utstubs.h +++ b/ut_assert/inc/utstubs.h @@ -87,18 +87,59 @@ typedef struct */ typedef struct { + int32 Int32StatusCode; + bool Int32StatusIsSet; uint32 ArgCount; const void * ArgPtr[UT_STUBCONTEXT_MAXSIZE]; UT_StubArgMetaData_t Meta[UT_STUBCONTEXT_MAXSIZE]; } UT_StubContext_t; /** - * Function pointer for user-specified hooks/stub callbacks + * Function pointer for user-specified hook callbacks + * + * Hook functions provide a user-specified supplement to the handler + * function. They are invoked prior to the actual stub handler, and can + * perform any additional test-specific logic necessary. + * + * \sa UT_HandlerFunc_t */ typedef int32 (*UT_HookFunc_t)(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); + +/** + * Function pointer for user-specified variable-argument callbacks + * + * \copydoc UT_HookFunc_t + */ typedef int32 (*UT_VaHookFunc_t)(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context, va_list va); +/** + * Function pointer for user-specified stub handlers + * + * Handler functions are the final logic associated with a stub + * + * Handlers must perform the role of generating the actual + * return code to be sent to the caller, and must also output + * any required output parameters. + * + * \note Stubs should no longer have any "assumed" logic. Any + * additional outputs or return code translation is now + * dealt with only in the handler function. + * + * \param[inout] UserObj Opaque object from original registration + * \param[in] FuncKey UT key of function currently being handled + * \param[in] Context Context information for current handler + */ +typedef void (*UT_HandlerFunc_t)(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context); + +/** + * Function pointer for user-specified variable-argument stub handlers + * + * \copydoc UT_HandlerFunc_t + * \param[in] va Variable argument list from initial stub call + */ +typedef void (*UT_VaHandlerFunc_t)(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, va_list va); + /************************************************************** * Functions for use within test code implementation **************************************************************/ @@ -201,17 +242,40 @@ void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey); * The callback may optionally pass back context data, depending on the stub * implementation. * + * In UT assert, hook functions supplement the handler functions, and will + * be called prior to the handler to add additional logic. This facility should + * be used in cases where the default handling logic is acceptable, but needs some + * extensions or additional work performed at the time the stub is invoked, such + * as setting a state variable in the parent test program. + * + * * \param FuncKey The stub function to add the hook to. * \param HookFunc User defined hook function. Set NULL to delete/clear an entry. * \param UserObj Arbitrary user data object to pass to the hook function */ void UT_SetHookFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *UserObj); +/** + * Set a Handler function for a particular call + * + * This allows the user to completely replace the handler for a given function. + * + * The handler assumes all responsibility for the final behavior of the stub, + * including translating return values, and any outputs/side effects the stub + * function should have. The default handler for the stub is NOT used. + * + * \param FuncKey The stub function to add the hook to. + * \param HandlerFunc User defined hook function. Set NULL to delete/clear an entry. + * \param UserObj Arbitrary user data object to pass to the hook function + */ +void UT_SetHandlerFunction(UT_EntryKey_t FuncKey, UT_HandlerFunc_t HandlerFunc, void *UserObj); + /** * Set a variable-argument Hook function for a particular call * - * Identical to the normal hook function except that it includes a va_list argument - * such that the entire set of args from the original call can be passed to the hook. + * Identical to UT_SetHookFunction() except that it includes a va_list argument + * such that it can be used with a variable-argument stub function. + * * This can be important for printf-like stubs where correctness might depend on the * contents of the arguments but the types of arguments aren't known. * @@ -219,12 +283,32 @@ void UT_SetHookFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *Use * available on those systems. Tests should use the generic (non-va) hook function * unless the arguments are truly necessary. * + * \sa UT_SetHookFunction + * * \param FuncKey The stub function to add the hook to. * \param HookFunc User defined hook function. Set NULL to delete/clear an entry. * \param UserObj Arbitrary user data object to pass to the hook function */ void UT_SetVaHookFunction(UT_EntryKey_t FuncKey, UT_VaHookFunc_t HookFunc, void *UserObj); +/** + * Set a variable-argument Handler function for a particular call + * + * This allows the user to completely replace the handler for a given function. + * + * The handler assumes all responsibility for the final behavior of the stub, + * including translating return values, and any outputs/side effects the stub + * function should have. The default handler for the stub is NOT used. + * + * This is identical to UT_SetHandlerFunction() but the function includes a va_list + * argument to allow use with variadic functions. + * + * \param FuncKey The stub function to add the hook to. + * \param HandlerFunc User defined hook function. Set NULL to delete/clear an entry. + * \param UserObj Arbitrary user data object to pass to the hook function + */ +void UT_SetVaHandlerFunction(UT_EntryKey_t FuncKey, UT_VaHandlerFunc_t HandlerFunc, void *UserObj); + /** * Get a count for the number of times a stub was invoked, at its most recent return value * @@ -349,6 +433,100 @@ size_t UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, siz UT_Stub_RegisterContextWithMetaData(FuncKey, #Parameter, UT_STUBCONTEXT_ARG_TYPE_INDIRECT, &Parameter, \ sizeof(Parameter)) +/** + * Set a stub return value from the handler function + * + * This sets/copies the specified value to the buffer that will be + * returned from the original stub call back to the caller. This + * provides the actual return value and it will override/replace + * any assumed or default return value. + * + * The passed-in buffer should be a pointer to the same data type + * that the stub returns. Any type mismatch is considered an error. + * + * The handler function must call this routine for any stub which + * returns a data type other than int32. + * + * @note If there is no handler function or the handler does not call + * this routine to set a return value, the implementation will use the + * "Int32StatusCode" value as a return if the size matches sizeof(int32). + * + * \param FuncKey The stub function associated with the buffer + * \param BufferPtr Pointer to the local return value + * \param BufferSize Size of the local return value + */ +void UT_Stub_SetReturnValue(UT_EntryKey_t FuncKey, const void *BufferPtr, size_t BufferSize); + +/** + * Creates a buffer to hold the return value for the stub + * + * \param FuncKey The stub function associated with the buffer + * \param ReturnSize Size of the return value + */ +void UT_Stub_RegisterReturnType(UT_EntryKey_t FuncKey, size_t ReturnSize); + +/** + * Obtains direct pointer to buffer for stub return value + * + * This is a helper routine and not intended to be invoked directly + * by handler/hook routines. Use UT_Stub_CopyToReturnValue() to + * set the return value from a local variable. + * + * \sa UT_Stub_CopyToReturnValue() + * + * \param FuncKey The stub function associated with the buffer + * \param ReturnSize Size of the return value + */ +void *UT_Stub_GetReturnValuePtr(UT_EntryKey_t FuncKey, size_t ReturnSize); + +/** + * Exports a value from a hook/handler and stages it to be returned to the caller. + * + * This is the preferred alternative to using "int32" type returns, since not all + * functions return int32 status codes. This method works with any return type. + * + * \param FuncKey The stub function associated with the buffer + * \param ReturnPtr Pointer to return value data + * \param ReturnSize Size of the return value data + */ +void UT_Stub_CopyToReturnValue(UT_EntryKey_t FuncKey, const void *ReturnPtr, size_t ReturnSize); + +/** + * Macro to simplify use of the UT_Stub_CopyToReturnValue() in a hook/handler context. + * This returns the value stored in the specified variable + * + * \param FuncKey The stub function identifier + * \param ReturnValue The value to return + */ +#define UT_Stub_SetReturnValue(FuncKey, ReturnValue) \ + UT_Stub_CopyToReturnValue(FuncKey, &ReturnValue, sizeof(ReturnValue)) + +/** + * Checks if the int32 status code is set, and optionally gets its value + * + * The UT framework is optimized to handle functions that return an int32 status + * code, as this is a very common pattern in CFE, OSAL, and related applications. + * + * In the context of a hook or handler function, this retrieves the value of an + * int32 status code configured by the test case, either via the "deferred" or + * the fixed/forced status code APIs, or generated by a previous hook function. + * + * This returns whether or not a status code was explicitly set by the test case. + * If no status code was set, the value will be set to a default (0). + * + * \param[in] Context The context object that was passed to the hook + * \param[out] StatusCodeBuffer If non-NULL, this will be set to the actual status code value + * If status code was not unset, this will be set to the default code value + * + * \returns true if code was explicitly set, false if it is not set (and has default value) + * + * \note The return value allows a hook/handler function to differentiate between a default + * status code value that was explicitly set vs. implicitly set. That is, if the test case + * explicitly sets a status code of "0", this will return "true", even if the default value + * is also "0". + */ +bool UT_Stub_GetInt32StatusCode(const UT_StubContext_t *Context, int32 *StatusCodeBuffer); + /** * Registers a single context element for the hook callback * @@ -402,7 +580,10 @@ const void *UT_Hook_GetArgPtr(const UT_StubContext_t *ContextPtr, const char *Na * Checks first for a deferred retcode, then for a constant retcode, and a default (0) if neither is present. * Optionally also prints a debug level status message to show that the function was called. * - * If a hook function is registered, then it is called using the supplied va_list of arguments. + * If a hook function is registered, then it will be called with the stub context + * + * Finally, the handler function will be invoked, if one is associated with the stub. The handler + * assumes final responsibility for any output parameters or return values. * * \param FunctionName The printable name of the actual function called, for the debug message. If * NULL then no debug message will be generated. @@ -410,6 +591,26 @@ const void *UT_Hook_GetArgPtr(const UT_StubContext_t *ContextPtr, const char *Na */ int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey, int32 DefaultRc, va_list va); +/** + * Handles a stub call for a variadic function + * + * Implements the complete sequence of a stub for a "bare" stub function (i.e. a stub that has no + * built-in/assumed logic). This is the preferred stub architecture as it allows a complete override + * of any and all output behavior / side effects by the test program. + * + * The DefaultHandler will be invoked unless the parent program has registered a replacement handler. + * + * \note The "generate_stubs.pl" tool can be used to auto-generate bare stub functions that are + * compatible with this pattern. + * + * \sa UT_DefaultStubImplWithArgs() + * + * \param FuncKey The key of the stub being executed + * \param FunctionName The printable name of the actual function called, for the debug message. + */ +void UT_ExecuteVaHandler(UT_EntryKey_t FuncKey, const char *FunctionName, UT_VaHandlerFunc_t DefaultHandler, + va_list VaList); + /** * Default implementation for a stub function that should be useful for most cases. * @@ -422,6 +623,25 @@ int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey */ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 DefaultRc, ...); +/** + * Handles a stub call for a normal (non-variadic) function + * + * Implements the complete sequence of a stub for a "bare" stub function (i.e. a stub that has no + * built-in/assumed logic). This is the preferred stub architecture as it allows a complete override + * of any and all output behavior / side effects by the test program. + * + * The DefaultHandler will be invoked unless the parent program has registered a replacement handler. + * + * \note The "generate_stubs.pl" tool can be used to auto-generate bare stub functions that are + * compatible with this pattern. + * + * \sa UT_DefaultStubImplWithArgs() + * + * \param FuncKey The key of the stub being executed + * \param FunctionName The printable name of the actual function called, for the debug message. + */ +void UT_ExecuteBasicHandler(UT_EntryKey_t FuncKey, const char *FunctionName, UT_HandlerFunc_t DefaultHandler); + /** * Macro to simplify usage of the UT_DefaultStubImpl() function * diff --git a/ut_assert/scripts/generate_stubs.pl b/ut_assert/scripts/generate_stubs.pl new file mode 100755 index 000000000..03e3574b1 --- /dev/null +++ b/ut_assert/scripts/generate_stubs.pl @@ -0,0 +1,405 @@ +#!/usr/bin/perl + +# +# 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. +# + +# +# Stub function generator script +# ------------------------------ +# +# PURPOSE: +# Given a set of public API C header files, this generates a matching set of +# stub functions to be used with coverage testing. Generating the stub functions +# in this manner ensures the argument and return types are consistent between +# the stub and the declaration. +# +# USAGE: +# generate_stubs.pl ... +# +# The script will scan each header file given on the command line, and search them +# for C function prototypes. Each prototype will then be used to define a matching stub +# implementation in the output stub directory. A .c file will be created with the same +# basename as the .h file containing stub versions of the functions defined in that header. +# +# File boilerplate info (i.e. first block comment) is preserved between input and output file +# such that this should be able to work with any subsystem without altering the legal info +# in the file header. +# +# By default the stubs are rendered with a default handler following the pattern: +# UT_DefaultHandler_${STUBNAME} +# +# By default the stubs are written to a file with the same basename and a "-stubs" suffix. +# +# This script will check corresponding hook file (via the hook-suffix option) for the presence +# of a handler. A reference to the handler will only be generated in the stub if it exists. +# This is a convenience option to avoid rendering references to handlers that do not exist, +# while still allowing the set to grow over time. + +# +# Options: +# +# --no-handler: a NULL default handler will be rendered for all stubs +# --all-handler: a non-NULL default handler will be rendered for all stubs +# (note the result will fail to link unless handler is actually implemented) +# --filter: a perl regex expression to apply on function names (e.g. /_Impl$/) +# --stub-suffix: a suffix to use for the generated file names ("stubs" by default) +# --hook-suffix: a suffix to use for the generated file names ("hooks" by default) +# + +use strict; +use warnings; + +my $publicapi = {}; + +# a list of functions that this should NOT generate a stub for. +# In particular these are the "real thing" even in a coverage environment +my $ignorelist = { + OS_Application_Run => 1, + OS_Application_Startup => 1, + CompileTimeAssert => 1 # asserts can sometimes look like prototypes +}; + +my %options = ( + "stub-suffix" => 'stubs', + "hook-suffix" => 'hooks' +); + +my @hdrlist = grep(/\S/, map { + if (s/^--//) { + if (s/=(.*)$//) { + $options{$_} = $1; + } else { + $options{$_} = 1; + } + $_ = ""; + } + $_; +} @ARGV); + +# currently the output dir is the first positional arg, shift it out. +# could make this an option if needed +my $stubpath = shift (@hdrlist); + +unless (defined $stubpath && -d $stubpath) { + die "Usage: $0 ...\n"; +} + +foreach my $hdr (@hdrlist) +{ + next unless open(HDR, "$hdr") || die "Cannot open: $hdr for reading\n"; + + my $fileapi = {}; + my @lines = (); + my $file = ""; + my $file_boilerplate; + my $file_variadic; + + # All header files start with some legal boilerplate comments + # Take the first one and save it, so it can be put into the output. + while() + { + if (!$file_boilerplate && !/\S/) { + # at first blank line, consider it the end of boilerplate code + $file_boilerplate = join('', @lines); + @lines = (); + } else { + # Normal code processing + # if line has continuation (\) at end, remove the newline too, + # so it will be in a single "line" in the result. + chomp if (s/\\$//); + } + push(@lines, $_); + } + close(HDR); + + # combine all content into a single string + # this eases processing of multi-line constructs + $file = join('', @lines); + + # take out comments + $file =~ s/\/\*(.*?)\*\///msg; + + # take out preprocessor lines + $file =~ s/^\s*\#.*?$//msg; + + # take out all content inside braces {} + # this is done in a loop to handle nested braces + while ($file) + { + last unless ($file =~ s/\{[^{}]*\}/;/gsm); + } + + # split on semicolons, and eliminate blank lines + # now each array entry should be some sort of C declaration + @lines = grep(/\S/, split(/;/, $file)); + + # trim leading/trailing whitespace on each declaration + s/^\s+|\s+$//g foreach (@lines); + + # Now Find function prototypes + foreach (@lines) { + next if (/typedef/); # ignore typedefs + next if (/static inline/); # ignore + + + # discard "extern" qualifier + # (but other qualifiers like "const" are OK and should be preserved, as + # it is part of return type). + s/extern//; + + # The following macros are defined in OSAL common_types.h as function attributes + # They may appear on other function declarations, and should be ignored here. + s/_EXTENSION_//; + s/OS_USED//; + s/OS_PRINTF\(.*?\)//; + + # scrub whitespace for consistency - multiple spaces become single space + # and trim leading/trailing spaces again + s/^\s+//; + s/\s+$//; + s/\s+/ /g; + + # snapshot the original line + my $rt = $_; + + # filter for lines that meet general pattern: + # ( ); + # + # Note this is a regex match and does not attempt to handle all + # possible C tokens/grammar, but because of coding standards and formatting + # the input shouldn't be too obscure (i.e. the code should not have + # old-style C argument lists, trigraphs, etc). + # + # Because return types may be qualified (i.e. not just a single token/word and + # also may be a pointer, this focuses on only the function name and argument + # list parts. Function names in C are limited to alphanumeric chars w/underscore. + next unless ($rt =~ s/([A-Za-z0-9_]+) ?\((.*?)\)$//); + + my $fn = $1; # function name + my $argstr = $2; # arguments as a comma-separated string (C-style) + my @argnames = (); # arguments names as a list (to be filled later) + my %argtypes = (); # arguments types as a hash (to be filled later) + my $func_variadic; + + # trim whitespace again on the components + # note the leftover text in "rt" constitutes the return type. + $argstr =~ s/^\s+|\s+$//g; + $rt =~ s/^\s+|\s+$//g; + + # skip the rest if its part of the ignore list + next if ($ignorelist->{$fn}); + + # apply the filter + if (defined $options{filter}) { + local $_ = $fn; + next unless eval $options{filter}; + } + + # Show it on console for debug + print ("Identified API: $rt $fn($argstr)\n"); + + # recognize "void" return type as undefined + $rt = undef if ($rt eq "void"); + + # split argument list string by commas (,) to get each argument + # this also needs to recognize a single "void" - should result in empty list + if ($argstr ne "void") { + my @argtemp = split(/\s*,\s*/, $argstr); + foreach my $arg (@argtemp) { + my $argtype = $arg; + if ($argtype =~ s/([A-Za-z0-9_]+)$//) { + push(@argnames, $1); + $argtypes{$1} = $argtype; + } elsif ($argtype eq "...") { # variadic function + $func_variadic = 1; + $file_variadic = 1; + } + } + } + + # save the API details in a hash, keyed by function name, as follows: + # decl => full declaration in its original form (mostly) + # rt => return type + # argnames => list of argument names + # argtypes => list of argument types + $fileapi->{$fn} = { decl => $_, rt => $rt, argnames => \@argnames, argtypes => \%argtypes, variadic => $func_variadic }; + + } + + # If file API is not empty (i.e. some prototypes were found) then add it + # to the public API structure based on the filename + if (%{$fileapi}) { + my @filenameparts = split(/\//, $hdr); + my $basename = pop(@filenameparts); + + $basename =~ s/\..*$//; # trim filename extension + $publicapi->{$basename} = { boilerplate => $file_boilerplate, variadic => $file_variadic, api => $fileapi }; + } + +} + +# Now generate a stub function for all items in API +# This creates a source file per header file, with a stubs suffix. +foreach my $basename (sort keys %{$publicapi}) { + + my $fileapi = $publicapi->{$basename}->{api}; + my $boilerplate = $publicapi->{$basename}->{boilerplate}; + my @functions = sort keys %{$fileapi}; + + # file names are not consistent WRT use of - or _ chars. + # if file name uses -, then use -, otherwise use _. + my $refname = "$stubpath/$basename"; + if ($basename =~ /-/) { + $refname .= '-'; + } else { + $refname .= '_'; + } + my $stubfile = $refname . $options{"stub-suffix"} . '.c'; + my $hookfile = $refname . $options{"hook-suffix"} . '.c'; + + my $handler_func = {}; + my $handler_prefix = "UT_DefaultHandler_"; + + if ($options{"all-handler"}) { + foreach my $funcname (@functions) { + $handler_func->{$funcname} = $handler_prefix.$funcname; + } + } elsif (!$options{"no-handler"}) { + if (open(HOOK, $hookfile)) { + while () { + if (/void\s+$handler_prefix(\S+)\s*\(/) { + $handler_func->{$1} = $handler_prefix.$1; + } + } + close(HOOK); + } + } + + # Now actually write the output stub source file + # NOTE: no need to be too fussy about whitespace and formatting here + # as the output file will be passed to clang-fomat at the end. + open(OUT, ">$stubfile") || die "Cannot open $stubfile for writing"; + + print OUT $boilerplate . "\n"; + print OUT "/**\n"; + print OUT " * \@file\n"; + print OUT " *\n"; + print OUT " * Auto-Generated stub implementations for functions defined in $basename header\n"; + print OUT " */\n\n"; + + # if the file uses any variadic functions, then stdarg.h will be needed. + if ($publicapi->{$basename}->{variadic}) { + print OUT "#include \n\n"; + } + + print OUT "#include \"$basename.h\"\n"; + print OUT "#include \"utgenstub.h\"\n\n"; + + unless ($options{"no-handler"}) { + foreach my $funcname (@functions) { + + next unless ($handler_func->{$funcname}); + + my $args = "void *, UT_EntryKey_t, const UT_StubContext_t *"; + if ($fileapi->{$funcname}->{variadic}) { + $args .= ", va_list"; + } + print OUT "extern void ".$handler_func->{$funcname}."($args);\n"; + } + } + + print OUT "\n"; + + foreach my $funcname (@functions) { + + print OUT "/*\n"; + print OUT " * ----------------------------------------------------\n"; + print OUT " * Generated stub function for $funcname()\n"; + print OUT " * ----------------------------------------------------\n"; + print OUT " */\n"; + + # create local vars for ease of access + my $rt = $fileapi->{$funcname}->{rt}; + my $decl = $fileapi->{$funcname}->{decl}; + my $variadic = $fileapi->{$funcname}->{variadic}; + my @argnames = @{$fileapi->{$funcname}->{argnames}}; + my %argtypes = %{$fileapi->{$funcname}->{argtypes}}; + my @handler_args = (); + + print OUT "$decl\n"; + print OUT "{\n"; + + if ($variadic) { + print OUT "va_list UtStub_ArgList;\n\n"; + } + + if ($rt) { + print OUT "UT_GenStub_SetupReturnBuffer($funcname, $rt);\n\n"; + } + + foreach my $arg (@argnames) { + print OUT "UT_GenStub_AddParam($funcname, $argtypes{$arg}, $arg);\n"; + } + + print OUT "\n"; + + push(@handler_args, $funcname); + + if ($variadic) { + push(@handler_args, "Va"); + } else { + push(@handler_args, "Basic"); + } + + if ($handler_func->{$funcname}) { + push(@handler_args, $handler_func->{$funcname}); + } else { + push(@handler_args, 'NULL'); + } + + # Variadic stub functions have a different handler that includes a va_list + if ($variadic) { + push(@handler_args, "UtStub_ArgList"); + print OUT "va_start(UtStub_ArgList, $argnames[$#argnames]);\n"; + } + + print OUT "UT_GenStub_Execute(" . join(', ',@handler_args) . ");\n"; + + if ($variadic) { + print OUT "va_end(UtStub_ArgList);\n"; + } + + print OUT "\n"; + + if ($rt) { + print OUT "return UT_GenStub_GetReturnValue($funcname, $rt);\n"; + } + + print OUT "}\n\n"; + } + + close(OUT); + + # invoke clang-format on the output, so it will have consistent whitespace + system("clang-format -style=file -i \'$stubfile\'") == 0 || die "Unable to call clang-format\n"; + + print "Generated $stubfile\n"; +} + diff --git a/ut_assert/src/utstubs.c b/ut_assert/src/utstubs.c index c270f4505..2d67be29c 100644 --- a/ut_assert/src/utstubs.c +++ b/ut_assert/src/utstubs.c @@ -56,9 +56,11 @@ typedef enum UT_ENTRYTYPE_FORCE_FAIL, /**< Always return a designated code from stub */ UT_ENTRYTYPE_DEFERRED_RC, /**< Return a designated code from stub after "N" calls */ UT_ENTRYTYPE_DATA_BUFFER, /**< Storage for data buffers to simulate read/write or queue ops */ - UT_ENTRYTYPE_CALLBACK_HOOK, /**< Pointer to a custom callback/hook function */ + UT_ENTRYTYPE_CALLBACK_HOOK, /**< A custom callback/hook function to be invoked prior to handler */ UT_ENTRYTYPE_CALLBACK_CONTEXT, /**< Context data for callback/hook function */ UT_ENTRYTYPE_CALL_ONCE, /**< Records a "call once" directive */ + UT_ENTRYTYPE_FINAL_HANDLER, /**< The final handler for the stub */ + UT_ENTRYTYPE_RETURN_BUFFER, /**< Storage for return value from stub */ } UT_EntryType_t; typedef struct @@ -76,9 +78,11 @@ typedef struct typedef union { - void * Addr; - UT_HookFunc_t Simple; - UT_VaHookFunc_t Va; + void * Addr; + UT_HookFunc_t SimpleHook; + UT_VaHookFunc_t VaHook; + UT_HandlerFunc_t SimpleHandler; + UT_VaHandlerFunc_t VaHandler; } UT_HookFuncPtr_t; typedef struct @@ -118,8 +122,8 @@ static uint32 UT_MaxStubSearchLen = 0; static void UT_ClearStubEntry(UT_StubTableEntry_t *StubPtr) { /* Be sure to call free() on any malloc'ed buffers before clearing */ - if (StubPtr->EntryType == UT_ENTRYTYPE_DATA_BUFFER && StubPtr->Data.Buff.BasePtr != NULL && - (StubPtr->ModeFlags & UT_MODEFLAG_ALLOC_BUF) != 0) + if ((StubPtr->EntryType == UT_ENTRYTYPE_DATA_BUFFER || StubPtr->EntryType == UT_ENTRYTYPE_RETURN_BUFFER) && + StubPtr->Data.Buff.BasePtr != NULL && (StubPtr->ModeFlags & UT_MODEFLAG_ALLOC_BUF) != 0) { free(StubPtr->Data.Buff.BasePtr); } @@ -404,6 +408,83 @@ bool UT_Stub_CheckDefaultReturnValue(UT_EntryKey_t FuncKey, int32 *Value) return (Result); } +void UT_Stub_RegisterReturnType(UT_EntryKey_t FuncKey, size_t ReturnSize) +{ + UT_StubTableEntry_t *StubPtr; + + if (ReturnSize > 0) + { + /* Check for existing buffer and re-use if same size (should be!) */ + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_RETURN_BUFFER); + if (StubPtr != NULL) + { + if (StubPtr->Data.Buff.TotalSize != ReturnSize) + { + UT_ClearStubEntry(StubPtr); + StubPtr = NULL; + } + else + { + StubPtr->Data.Buff.Position = 0; + } + } + + if (StubPtr == NULL) + { + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_UNUSED); + if (StubPtr == NULL) + { + UtAssert_Abort("Cannot set return buffer - UT_MAX_FUNC_STUBS too low?"); + } + else + { + StubPtr->FuncKey = FuncKey; + StubPtr->EntryType = UT_ENTRYTYPE_RETURN_BUFFER; + StubPtr->Data.Buff.BasePtr = malloc(ReturnSize); + if (StubPtr->Data.Buff.BasePtr == NULL) + { + UtAssert_Abort("Cannot allocate data buffer - malloc() failed!"); + } + else + { + memset(StubPtr->Data.Buff.BasePtr, 0, ReturnSize); + StubPtr->ModeFlags |= UT_MODEFLAG_ALLOC_BUF; + } + + StubPtr->Data.Buff.TotalSize = ReturnSize; + StubPtr->Data.Buff.Position = 0; + } + } + } +} + +void *UT_Stub_GetReturnValuePtr(UT_EntryKey_t FuncKey, size_t ReturnSize) +{ + UT_StubTableEntry_t *StubPtr; + void * ReturnPtr; + + ReturnPtr = NULL; + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_RETURN_BUFFER); + + /* Sanity check on the size */ + if (StubPtr != NULL && StubPtr->Data.Buff.TotalSize == ReturnSize) + { + ReturnPtr = StubPtr->Data.Buff.BasePtr; + } + else + { + /* This shouldn't happen, it means the stub tried to use a + * return buffer that does not exist or does not match size. + * + * It is most likely caused by a mismatch/incompatibility between + * stub and handler. Aborting now is better than segfaulting later, + * as the errored call should still be on the stack trace */ + UtAssert_Abort("Return buffer invalid"); + } + + return ReturnPtr; +} + void UT_SetDataBuffer(UT_EntryKey_t FuncKey, void *DataBuffer, size_t BufferSize, bool AllocateCopy) { UT_StubTableEntry_t *StubPtr; @@ -549,7 +630,8 @@ size_t UT_Stub_CopyFromLocal(UT_EntryKey_t FuncKey, const void *LocalBuffer, siz /* * Helper function used by UT_SetHookFunction() and UT_SetVaHookFunction() */ -static void UT_DoSetHookFunction(UT_EntryKey_t FuncKey, UT_HookFuncPtr_t Value, void *UserObj, bool IsVarg) +static void UT_DoSetHookFunction(UT_EntryKey_t FuncKey, UT_EntryType_t EntryType, UT_HookFuncPtr_t Value, void *UserObj, + bool IsVarg) { UT_StubTableEntry_t *StubPtr; @@ -557,7 +639,7 @@ static void UT_DoSetHookFunction(UT_EntryKey_t FuncKey, UT_HookFuncPtr_t Value, * First find an existing hook entry for the function. * In case one is already set we do not duplicate */ - StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_CALLBACK_HOOK); + StubPtr = UT_GetStubEntry(FuncKey, EntryType); if (StubPtr == NULL && Value.Addr != NULL) { /* Creating force fail entry - repeat search and grab any unused slot */ @@ -577,7 +659,7 @@ static void UT_DoSetHookFunction(UT_EntryKey_t FuncKey, UT_HookFuncPtr_t Value, { /* Caller wants to set the entry */ StubPtr->FuncKey = FuncKey; - StubPtr->EntryType = UT_ENTRYTYPE_CALLBACK_HOOK; + StubPtr->EntryType = EntryType; StubPtr->Data.Cb.CallbackArg = UserObj; StubPtr->Data.Cb.Ptr = Value; StubPtr->Data.Cb.IsVarg = IsVarg; @@ -588,18 +670,36 @@ void UT_SetHookFunction(UT_EntryKey_t FuncKey, UT_HookFunc_t HookFunc, void *Use { UT_HookFuncPtr_t Value; - Value.Simple = HookFunc; + Value.SimpleHook = HookFunc; - UT_DoSetHookFunction(FuncKey, Value, UserObj, false); + UT_DoSetHookFunction(FuncKey, UT_ENTRYTYPE_CALLBACK_HOOK, Value, UserObj, false); } void UT_SetVaHookFunction(UT_EntryKey_t FuncKey, UT_VaHookFunc_t HookFunc, void *UserObj) { UT_HookFuncPtr_t Value; - Value.Va = HookFunc; + Value.VaHook = HookFunc; - UT_DoSetHookFunction(FuncKey, Value, UserObj, true); + UT_DoSetHookFunction(FuncKey, UT_ENTRYTYPE_CALLBACK_HOOK, Value, UserObj, true); +} + +void UT_SetHandlerFunction(UT_EntryKey_t FuncKey, UT_HandlerFunc_t HandlerFunc, void *UserObj) +{ + UT_HookFuncPtr_t Value; + + Value.SimpleHandler = HandlerFunc; + + UT_DoSetHookFunction(FuncKey, UT_ENTRYTYPE_FINAL_HANDLER, Value, UserObj, false); +} + +void UT_SetVaHandlerFunction(UT_EntryKey_t FuncKey, UT_VaHandlerFunc_t HandlerFunc, void *UserObj) +{ + UT_HookFuncPtr_t Value; + + Value.VaHandler = HandlerFunc; + + UT_DoSetHookFunction(FuncKey, UT_ENTRYTYPE_FINAL_HANDLER, Value, UserObj, true); } const void *UT_Hook_GetArgPtr(const UT_StubContext_t *ContextPtr, const char *Name, size_t ExpectedTypeSize) @@ -736,31 +836,85 @@ void UT_Stub_RegisterContextWithMetaData(UT_EntryKey_t FuncKey, const char *Name } } +bool UT_Stub_GetInt32StatusCode(const UT_StubContext_t *Context, int32 *StatusCodeBuffer) +{ + if (StatusCodeBuffer != NULL) + { + *StatusCodeBuffer = Context->Int32StatusCode; + } + + return Context->Int32StatusIsSet; +} + +void UT_Stub_CopyToReturnValue(UT_EntryKey_t FuncKey, const void *BufferPtr, size_t BufferSize) +{ + UT_StubTableEntry_t *StubPtr; + + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_RETURN_BUFFER); + if (StubPtr != NULL) + { + /* If the size does not match, there is a bug */ + if (StubPtr->Data.Buff.TotalSize != BufferSize) + { + UtAssert_Abort("Size mismatch in setting return value"); + } + else + { + memcpy(StubPtr->Data.Buff.BasePtr, BufferPtr, BufferSize); + StubPtr->Data.Buff.Position = BufferSize; + } + } +} + /** * Default implementation for a stub function that should be useful for most cases. * Checks first for a deferred retcode, then for a constant retcode, and a default if neither is present. * Prints a debug level status message to show that the function was called. */ -int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey, int32 DefaultRc, va_list va) +int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey, int32 DefaultRc, va_list ArgList) { - int32 Retcode; - const char * RetcodeString; - UT_StubTableEntry_t * StubPtr; - UT_StubTableEntry_t * ContextTblPtr; - const UT_StubContext_t *ContextPtr; - uint32 Counter; + const char * RetcodeString; + UT_StubTableEntry_t *StubPtr; + UT_StubTableEntry_t *ContextTblPtr; + UT_StubContext_t LocalContext; + uint32 Counter; + va_list ArgListCopy; - if (!UT_Stub_CheckDeferredRetcode(FuncKey, &Retcode)) + /* + * In this implementation a context is _always_ needed. + * + * First see if the stub has an already-registered context. Any non-trivial stub + * should already have registered some arguments and/or a return code buffer. + * + * To handle an old-style/incomplete stub function or simple void/void stubs that + * do not have any arguments, a blank entry can be created on the fly. + */ + ContextTblPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_CALLBACK_CONTEXT); + if (ContextTblPtr != NULL) { - if (!UT_Stub_CheckDefaultReturnValue(FuncKey, &Retcode)) - { - Retcode = DefaultRc; - } + LocalContext = ContextTblPtr->Data.Context; + + /* Always clear the context entry -- the next call will have a different one */ + UT_ClearStubEntry(ContextTblPtr); + } + else + { + memset(&LocalContext, 0, sizeof(LocalContext)); + } + + LocalContext.Int32StatusIsSet = UT_Stub_CheckDeferredRetcode(FuncKey, &LocalContext.Int32StatusCode); + if (!LocalContext.Int32StatusIsSet) + { + LocalContext.Int32StatusIsSet = UT_Stub_CheckDefaultReturnValue(FuncKey, &LocalContext.Int32StatusCode); + } + if (!LocalContext.Int32StatusIsSet) + { + LocalContext.Int32StatusCode = DefaultRc; } if (FunctionName != NULL) { - if (Retcode == DefaultRc) + if (!LocalContext.Int32StatusIsSet) { RetcodeString = "DEFAULT"; } @@ -770,7 +924,7 @@ int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey RetcodeString = "*SPECIAL*"; } - UtDebug("%s called (%s,%d)", FunctionName, RetcodeString, (int)Retcode); + UtDebug("%s called (%s,%d)", FunctionName, RetcodeString, (int)LocalContext.Int32StatusCode); } Counter = 0; @@ -791,42 +945,80 @@ int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey StubPtr->FuncKey = FuncKey; Counter = StubPtr->Data.Rc.Count; ++StubPtr->Data.Rc.Count; - StubPtr->Data.Rc.Value = Retcode; + StubPtr->Data.Rc.Value = LocalContext.Int32StatusCode; } - /* Handle a user-requested callback hook. - * First see if the stub has a registered context. - */ - ContextTblPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_CALLBACK_CONTEXT); - if (ContextTblPtr == NULL) - { - ContextPtr = NULL; - } - else + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_CALLBACK_HOOK); + if (StubPtr != NULL) { - ContextPtr = &ContextTblPtr->Data.Context; + if (StubPtr->Data.Cb.IsVarg) + { + va_copy(ArgListCopy, ArgList); + LocalContext.Int32StatusCode = StubPtr->Data.Cb.Ptr.VaHook( + StubPtr->Data.Cb.CallbackArg, LocalContext.Int32StatusCode, Counter, &LocalContext, ArgListCopy); + va_end(ArgListCopy); + } + else + { + LocalContext.Int32StatusCode = StubPtr->Data.Cb.Ptr.SimpleHook( + StubPtr->Data.Cb.CallbackArg, LocalContext.Int32StatusCode, Counter, &LocalContext); + } + + LocalContext.Int32StatusIsSet = true; } - StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_CALLBACK_HOOK); + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FINAL_HANDLER); if (StubPtr != NULL) { if (StubPtr->Data.Cb.IsVarg) { - Retcode = (*StubPtr->Data.Cb.Ptr.Va)(StubPtr->Data.Cb.CallbackArg, Retcode, Counter, ContextPtr, va); + StubPtr->Data.Cb.Ptr.VaHandler(StubPtr->Data.Cb.CallbackArg, FuncKey, &LocalContext, ArgList); } else { - Retcode = (*StubPtr->Data.Cb.Ptr.Simple)(StubPtr->Data.Cb.CallbackArg, Retcode, Counter, ContextPtr); + StubPtr->Data.Cb.Ptr.SimpleHandler(StubPtr->Data.Cb.CallbackArg, FuncKey, &LocalContext); } } - /* Always clear the context entry -- the next call will have a different one */ - if (ContextTblPtr != NULL) + /* + * Handle propagation of return code. + * + * "old style" stubs will translate the int32 return value from this function. + * - Return Buffer will always be unset with these stubs + * - This should continue to work with no special handling. + * + * "new style" stubs will provide a return value buffer via UT_ENTRYTYPE_RETURN_BUFFER in the context. + * - In this pattern the int32 return value of this function is _IGNORED_ by the calling stub. + * - The only way to return a value to the caller is via the buffer. + * - If the handler did _not_ populate the return value, then attempt to translate the local + * Retcode here to the return value buffer. This eases the transition, as the vast majority + * of functions do return an int32, this can be the automatic case. + */ + StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_RETURN_BUFFER); + if (StubPtr != NULL && StubPtr->Data.Buff.Position == 0) { - UT_ClearStubEntry(ContextTblPtr); + /* + * This means that the stub expects the hook to fill the provided return buffer, but the hook did not + * actually call UT_Stub_SetReturnValue() to fill that buffer. To mimic the old behavior where the hook + * return code was "passed through", attempt to copy the value now. This works because for the majority + * of functions, the return type is actually int32, so it is compatible. + * + * But if the size is different, then this shouldn't be done, and generate a failure message + * to indicate the test case or stub/hook needs to be fixed. + */ + if (StubPtr->Data.Buff.TotalSize == sizeof(LocalContext.Int32StatusCode)) + { + memcpy(StubPtr->Data.Buff.BasePtr, &LocalContext.Int32StatusCode, sizeof(LocalContext.Int32StatusCode)); + } + else + { + /* cannot copy - generate a "failure" message to indicate the problem */ + UtAssert_Failed("Stub %s w/return size=%lu, value cannot be auto-translated from int32", FunctionName, + (unsigned long)StubPtr->Data.Buff.TotalSize); + } } - return Retcode; + return LocalContext.Int32StatusCode; } /** @@ -844,3 +1036,26 @@ int32 UT_DefaultStubImpl(const char *FunctionName, UT_EntryKey_t FuncKey, int32 return Retcode; } + +void UT_ExecuteBasicHandler(UT_EntryKey_t FuncKey, const char *FunctionName, UT_HandlerFunc_t DefaultHook) +{ + /* Check if the test case registered a hook, and use the default if not */ + if (UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FINAL_HANDLER) == NULL && DefaultHook != NULL) + { + UT_SetHandlerFunction(FuncKey, DefaultHook, NULL); + } + + UT_DefaultStubImpl(FunctionName, FuncKey, 0, NULL); +} + +void UT_ExecuteVaHandler(UT_EntryKey_t FuncKey, const char *FunctionName, UT_VaHandlerFunc_t DefaultHook, + va_list VaList) +{ + /* Check if the test case registered a hook, and use the default if not */ + if (UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FINAL_HANDLER) == NULL && DefaultHook != NULL) + { + UT_SetVaHandlerFunction(FuncKey, DefaultHook, NULL); + } + + UT_DefaultStubImplWithArgs(FunctionName, FuncKey, 0, VaList); +} From 7194f1d0659d1bb17c5654f4e73bd220c45b4563 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 15 Apr 2021 23:37:48 -0400 Subject: [PATCH 06/12] Fix #832, improve scriptability of shared layer APIs To imporove scriptability of generating the shared layer stubs, makes two minor adjustments: - adds a typedef for the callback in OS_ObjectIdIteratorProcessEntry. This avoids the complex syntax of function pointer argument, which is hard to read but also harder to parse in a script, too. - Splits the "os-shared-printf.h" header into two parts, adding a new header file "os-shared-console.h". This is because OS_ConsoleOutput_Impl is implemented in a separate unit in the source, and this allows a better relationship between stub files and header files. --- src/os/shared/inc/os-shared-console.h | 94 +++++++++++++++++++++++++++ src/os/shared/inc/os-shared-idmap.h | 9 ++- src/os/shared/inc/os-shared-printf.h | 57 +--------------- 3 files changed, 103 insertions(+), 57 deletions(-) create mode 100644 src/os/shared/inc/os-shared-console.h diff --git a/src/os/shared/inc/os-shared-console.h b/src/os/shared/inc/os-shared-console.h new file mode 100644 index 000000000..b13762844 --- /dev/null +++ b/src/os/shared/inc/os-shared-console.h @@ -0,0 +1,94 @@ +/* + * 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 + * + * \ingroup shared + * + * Table implementation and calls related to the console buffer. + * + * This is a simple ring buffer that decouples + * the OS_printf() call from actual console output. + * + * The implementation layer may optionally spawn a + * "utility task" or equivalent to forward data, or + * it may process data immediately. + */ + +#ifndef OS_SHARED_CONSOLE_H +#define OS_SHARED_CONSOLE_H + +#include "osapi-printf.h" +#include "os-shared-printf.h" +#include "os-shared-globaldefs.h" + +/** + * The generic console data record + */ +typedef struct +{ + char device_name[OS_MAX_API_NAME]; + + char * BufBase; /**< Start of the buffer memory */ + size_t BufSize; /**< Total size of the buffer */ + volatile size_t ReadPos; /**< Offset of next byte to read */ + volatile size_t WritePos; /**< Offset of next byte to write */ + uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ + +} OS_console_internal_record_t; + +extern OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; + +/**************************************************************************************** + CONSOLE / DEBUG API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_ConsoleAPI_Init + + Purpose: Initialize the OS-independent layer for console service + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_ConsoleAPI_Init(void); + +/*---------------------------------------------------------------- + Function: OS_ConsoleCreate_Impl + + Purpose: Prepare a console device for use + For Async devices, this sets up the background writer task + ------------------------------------------------------------------*/ +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); + +/*---------------------------------------------------------------- + Function: OS_ConsoleWakeup_Impl + + Purpose: Console output data notification + + This is a notification API that is invoked whenever there + is new data available in the console output buffer. + + It is only used of the console is configured for async operation, + and it should wakeup the actual console servicing thread. + ------------------------------------------------------------------*/ +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token); + +#endif /* OS_SHARED_CONSOLE_H */ diff --git a/src/os/shared/inc/os-shared-idmap.h b/src/os/shared/inc/os-shared-idmap.h index 111d4e8ff..0e86a4cda 100644 --- a/src/os/shared/inc/os-shared-idmap.h +++ b/src/os/shared/inc/os-shared-idmap.h @@ -103,6 +103,13 @@ struct OS_object_token */ typedef bool (*OS_ObjectMatchFunc_t)(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj); +/* + * A function to serve as callback with object ID iterators + * + * This is the prototype of callback functions for use with OS_ObjectIdIteratorProcessEntry() + */ +typedef int32 (*OS_ObjectIdIteratorProcessFunc_t)(osal_id_t, void *); + /* * State object associated with an object iterator */ @@ -533,7 +540,7 @@ static inline const OS_object_token_t *OS_ObjectIdIteratorRef(OS_object_iter_t * Returns: None ------------------------------------------------------------------*/ -int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, int32 (*func)(osal_id_t, void *)); +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, OS_ObjectIdIteratorProcessFunc_t func); /* * Internal helper functions diff --git a/src/os/shared/inc/os-shared-printf.h b/src/os/shared/inc/os-shared-printf.h index b1cce4fcc..a54e80d43 100644 --- a/src/os/shared/inc/os-shared-printf.h +++ b/src/os/shared/inc/os-shared-printf.h @@ -29,53 +29,13 @@ #define OS_SHARED_PRINTF_H #include "osapi-printf.h" +#include "os-shared-console.h" #include "os-shared-globaldefs.h" -/* - * Variables related to the console buffer. - * This is a simple ring buffer that decouples - * the OS_printf() call from actual console output. - * - * The implementation layer may optionally spawn a - * "utility task" or equivalent to forward data, or - * it may process data immediately. - */ - -typedef struct -{ - char device_name[OS_MAX_API_NAME]; - - char * BufBase; /**< Start of the buffer memory */ - size_t BufSize; /**< Total size of the buffer */ - volatile size_t ReadPos; /**< Offset of next byte to read */ - volatile size_t WritePos; /**< Offset of next byte to write */ - uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ - -} OS_console_internal_record_t; - -extern OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; - /**************************************************************************************** CONSOLE / DEBUG API LOW-LEVEL IMPLEMENTATION FUNCTIONS ****************************************************************************************/ -/*--------------------------------------------------------------------------------------- - Name: OS_ConsoleAPI_Init - - Purpose: Initialize the OS-independent layer for console service - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_ConsoleAPI_Init(void); - -/*---------------------------------------------------------------- - Function: OS_ConsoleCreate_Impl - - Purpose: Prepare a console device for use - For Async devices, this sets up the background writer task - ------------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); - /*---------------------------------------------------------------- Function: OS_ConsoleOutput_Impl @@ -88,19 +48,4 @@ int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token); ------------------------------------------------------------------*/ void OS_ConsoleOutput_Impl(const OS_object_token_t *token); -/*---------------------------------------------------------------- - Function: OS_ConsoleOutput_Impl - - Purpose: Console output data notification - - This is a notification API that is invoked whenever there - is new data available in the console output buffer. - - For a synchronous console service, this may call - OS_ConsoleWrite_Impl() directly. For an async console - service, this should wakeup the actual console servicing - thread. - ------------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(const OS_object_token_t *token); - #endif /* OS_SHARED_PRINTF_H */ From 05e78377dc3794c8ac78d4d06e43c448c4424fd4 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 16 Apr 2021 08:57:48 -0400 Subject: [PATCH 07/12] Fix #832, replace public API stubs with generated versions The "built-in" logic from existing stubs is converted to a handler function and moved to a different source file. The generated stub references this function if it exists and uses it as a default handler, so the default behavior is not changed. In this pattern the stubs in this directory are strictly limited to the same public APIs that are defined in header files under src/os/inc. This has the side effect of removing some internal stubs required for coverage test. Those stubs will be reinstated in the coverage specific stubs where other internal functions are. --- src/ut-stubs/CMakeLists.txt | 100 ++- src/ut-stubs/osapi-binsem-hooks.c | 114 ++++ src/ut-stubs/osapi-binsem-stubs.c | 167 +++++ src/ut-stubs/osapi-bsp-stubs.c | 68 ++ ...api-utstub-clock.c => osapi-clock-hooks.c} | 52 +- src/ut-stubs/osapi-clock-stubs.c | 63 ++ src/ut-stubs/osapi-common-stubs.c | 115 ++++ src/ut-stubs/osapi-countsem-hooks.c | 114 ++++ src/ut-stubs/osapi-countsem-stubs.c | 151 +++++ src/ut-stubs/osapi-dir-hooks.c | 97 +++ src/ut-stubs/osapi-dir-stubs.c | 131 ++++ ...pi-utstub-errors.c => osapi-error-hooks.c} | 22 +- src/ut-stubs/osapi-error-stubs.c | 47 ++ src/ut-stubs/osapi-file-hooks.c | 248 +++++++ src/ut-stubs/osapi-file-stubs.c | 329 +++++++++ src/ut-stubs/osapi-filesys-hooks.c | 122 ++++ src/ut-stubs/osapi-filesys-stubs.c | 225 +++++++ ...osapi-utstub-heap.c => osapi-heap-hooks.c} | 25 +- src/ut-stubs/osapi-heap-stubs.c | 46 ++ src/ut-stubs/osapi-idmap-hooks.c | 195 ++++++ src/ut-stubs/osapi-idmap-stubs.c | 134 ++++ src/ut-stubs/osapi-module-hooks.c | 173 +++++ src/ut-stubs/osapi-module-stubs.c | 138 ++++ src/ut-stubs/osapi-mutex-hooks.c | 113 ++++ src/ut-stubs/osapi-mutex-stubs.c | 133 ++++ ...utstub-network.c => osapi-network-hooks.c} | 34 +- src/ut-stubs/osapi-network-stubs.c | 61 ++ ...i-utstub-printf.c => osapi-printf-hooks.c} | 78 +-- src/ut-stubs/osapi-printf-stubs.c | 70 ++ src/ut-stubs/osapi-queue-hooks.c | 160 +++++ src/ut-stubs/osapi-queue-stubs.c | 145 ++++ src/ut-stubs/osapi-select-stubs.c | 131 ++++ src/ut-stubs/osapi-shell-stubs.c | 45 ++ src/ut-stubs/osapi-sockets-hooks.c | 242 +++++++ src/ut-stubs/osapi-sockets-stubs.c | 269 ++++++++ src/ut-stubs/osapi-task-hooks.c | 156 +++++ src/ut-stubs/osapi-task-stubs.c | 200 ++++++ src/ut-stubs/osapi-timebase-hooks.c | 136 ++++ src/ut-stubs/osapi-timebase-stubs.c | 137 ++++ src/ut-stubs/osapi-timer-hooks.c | 135 ++++ src/ut-stubs/osapi-timer-stubs.c | 143 ++++ src/ut-stubs/osapi-utstub-binsem.c | 295 -------- src/ut-stubs/osapi-utstub-bsp.c | 68 -- src/ut-stubs/osapi-utstub-common.c | 141 ---- src/ut-stubs/osapi-utstub-countsem.c | 210 ------ src/ut-stubs/osapi-utstub-dir.c | 161 ----- src/ut-stubs/osapi-utstub-file.c | 454 ------------- src/ut-stubs/osapi-utstub-filesys.c | 254 ------- src/ut-stubs/osapi-utstub-idmap.c | 635 ------------------ src/ut-stubs/osapi-utstub-module.c | 276 -------- src/ut-stubs/osapi-utstub-mutex.c | 238 ------- src/ut-stubs/osapi-utstub-queue.c | 278 -------- src/ut-stubs/osapi-utstub-select.c | 137 ---- src/ut-stubs/osapi-utstub-sockets.c | 330 --------- src/ut-stubs/osapi-utstub-task.c | 327 --------- src/ut-stubs/osapi-utstub-time.c | 207 ------ src/ut-stubs/osapi-utstub-timebase.c | 221 ------ ...utstub-version.c => osapi-version-hooks.c} | 69 +- src/ut-stubs/osapi-version-stubs.c | 84 +++ src/ut-stubs/utstub-helpers.c | 4 +- 60 files changed, 5205 insertions(+), 4448 deletions(-) create mode 100644 src/ut-stubs/osapi-binsem-hooks.c create mode 100644 src/ut-stubs/osapi-binsem-stubs.c create mode 100644 src/ut-stubs/osapi-bsp-stubs.c rename src/ut-stubs/{osapi-utstub-clock.c => osapi-clock-hooks.c} (57%) create mode 100644 src/ut-stubs/osapi-clock-stubs.c create mode 100644 src/ut-stubs/osapi-common-stubs.c create mode 100644 src/ut-stubs/osapi-countsem-hooks.c create mode 100644 src/ut-stubs/osapi-countsem-stubs.c create mode 100644 src/ut-stubs/osapi-dir-hooks.c create mode 100644 src/ut-stubs/osapi-dir-stubs.c rename src/ut-stubs/{osapi-utstub-errors.c => osapi-error-hooks.c} (71%) create mode 100644 src/ut-stubs/osapi-error-stubs.c create mode 100644 src/ut-stubs/osapi-file-hooks.c create mode 100644 src/ut-stubs/osapi-file-stubs.c create mode 100644 src/ut-stubs/osapi-filesys-hooks.c create mode 100644 src/ut-stubs/osapi-filesys-stubs.c rename src/ut-stubs/{osapi-utstub-heap.c => osapi-heap-hooks.c} (76%) create mode 100644 src/ut-stubs/osapi-heap-stubs.c create mode 100644 src/ut-stubs/osapi-idmap-hooks.c create mode 100644 src/ut-stubs/osapi-idmap-stubs.c create mode 100644 src/ut-stubs/osapi-module-hooks.c create mode 100644 src/ut-stubs/osapi-module-stubs.c create mode 100644 src/ut-stubs/osapi-mutex-hooks.c create mode 100644 src/ut-stubs/osapi-mutex-stubs.c rename src/ut-stubs/{osapi-utstub-network.c => osapi-network-hooks.c} (71%) create mode 100644 src/ut-stubs/osapi-network-stubs.c rename src/ut-stubs/{osapi-utstub-printf.c => osapi-printf-hooks.c} (55%) create mode 100644 src/ut-stubs/osapi-printf-stubs.c create mode 100644 src/ut-stubs/osapi-queue-hooks.c create mode 100644 src/ut-stubs/osapi-queue-stubs.c create mode 100644 src/ut-stubs/osapi-select-stubs.c create mode 100644 src/ut-stubs/osapi-shell-stubs.c create mode 100644 src/ut-stubs/osapi-sockets-hooks.c create mode 100644 src/ut-stubs/osapi-sockets-stubs.c create mode 100644 src/ut-stubs/osapi-task-hooks.c create mode 100644 src/ut-stubs/osapi-task-stubs.c create mode 100644 src/ut-stubs/osapi-timebase-hooks.c create mode 100644 src/ut-stubs/osapi-timebase-stubs.c create mode 100644 src/ut-stubs/osapi-timer-hooks.c create mode 100644 src/ut-stubs/osapi-timer-stubs.c delete mode 100644 src/ut-stubs/osapi-utstub-binsem.c delete mode 100644 src/ut-stubs/osapi-utstub-bsp.c delete mode 100644 src/ut-stubs/osapi-utstub-common.c delete mode 100644 src/ut-stubs/osapi-utstub-countsem.c delete mode 100644 src/ut-stubs/osapi-utstub-dir.c delete mode 100644 src/ut-stubs/osapi-utstub-file.c delete mode 100644 src/ut-stubs/osapi-utstub-filesys.c delete mode 100644 src/ut-stubs/osapi-utstub-idmap.c delete mode 100644 src/ut-stubs/osapi-utstub-module.c delete mode 100644 src/ut-stubs/osapi-utstub-mutex.c delete mode 100644 src/ut-stubs/osapi-utstub-queue.c delete mode 100644 src/ut-stubs/osapi-utstub-select.c delete mode 100644 src/ut-stubs/osapi-utstub-sockets.c delete mode 100644 src/ut-stubs/osapi-utstub-task.c delete mode 100644 src/ut-stubs/osapi-utstub-time.c delete mode 100644 src/ut-stubs/osapi-utstub-timebase.c rename src/ut-stubs/{osapi-utstub-version.c => osapi-version-hooks.c} (52%) create mode 100644 src/ut-stubs/osapi-version-stubs.c 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-bsp-stubs.c b/src/ut-stubs/osapi-bsp-stubs.c new file mode 100644 index 000000000..6e8347327 --- /dev/null +++ b/src/ut-stubs/osapi-bsp-stubs.c @@ -0,0 +1,68 @@ +/* + * 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-bsp header + */ + +#include "osapi-bsp.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BSP_GetArgC() + * ---------------------------------------------------- + */ +uint32 OS_BSP_GetArgC(void) +{ + UT_GenStub_SetupReturnBuffer(OS_BSP_GetArgC, uint32); + + UT_GenStub_Execute(OS_BSP_GetArgC, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BSP_GetArgC, uint32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BSP_GetArgV() + * ---------------------------------------------------- + */ +char *const *OS_BSP_GetArgV(void) +{ + UT_GenStub_SetupReturnBuffer(OS_BSP_GetArgV, char *const *); + + UT_GenStub_Execute(OS_BSP_GetArgV, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BSP_GetArgV, char *const *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BSP_SetExitCode() + * ---------------------------------------------------- + */ +void OS_BSP_SetExitCode(int32 code) +{ + UT_GenStub_AddParam(OS_BSP_SetExitCode, int32, code); + + UT_GenStub_Execute(OS_BSP_SetExitCode, Basic, NULL); +} 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-shell-stubs.c b/src/ut-stubs/osapi-shell-stubs.c new file mode 100644 index 000000000..2b8c23edc --- /dev/null +++ b/src/ut-stubs/osapi-shell-stubs.c @@ -0,0 +1,45 @@ +/* + * 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-shell header + */ + +#include "osapi-shell.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ShellOutputToFile() + * ---------------------------------------------------- + */ +int32 OS_ShellOutputToFile(const char *Cmd, osal_id_t filedes) +{ + UT_GenStub_SetupReturnBuffer(OS_ShellOutputToFile, int32); + + UT_GenStub_AddParam(OS_ShellOutputToFile, const char *, Cmd); + UT_GenStub_AddParam(OS_ShellOutputToFile, osal_id_t, filedes); + + UT_GenStub_Execute(OS_ShellOutputToFile, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ShellOutputToFile, 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 697e26afd..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_mode) -{ - 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_mode); - 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_mode) -{ - UT_Stub_RegisterContext(UT_KEY(OS_chmod), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_chmod), access_mode); - - 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 * From e9f344b755d7a9ee18fa7f3498fd36c5911856cc Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 16 Apr 2021 09:12:34 -0400 Subject: [PATCH 08/12] Fix #832, update coverage test to use generated stubs Update the coverage-specific (shared layer internal) stubs to use generated stubs. --- src/unit-test-coverage/shared/CMakeLists.txt | 2 + .../ut-stubs/CMakeLists.txt | 195 +++++-- .../src/os-shared-binsem-impl-stubs.c | 144 +++++ .../src/os-shared-binsem-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-clock-impl-stubs.c | 60 +++ ...-stubs.c => os-shared-common-impl-stubs.c} | 38 +- .../src/os-shared-common-init-stubs.c | 44 ++ .../ut-stubs/src/os-shared-common-stubs.c | 46 ++ .../src/os-shared-console-impl-stubs.c | 56 ++ ...stubs.c => os-shared-console-init-stubs.c} | 32 +- .../src/os-shared-countsem-impl-stubs.c | 128 +++++ .../src/os-shared-countsem-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-dir-impl-stubs.c | 127 +++++ ...mpl-stubs.c => os-shared-dir-init-stubs.c} | 33 +- .../ut-stubs/src/os-shared-file-impl-hooks.c | 71 +++ .../ut-stubs/src/os-shared-file-impl-stubs.c | 206 +++++++ ...ug-stubs.c => os-shared-file-init-stubs.c} | 29 +- .../ut-stubs/src/os-shared-file-stubs.c | 45 ++ ...stubs.c => os-shared-filesys-impl-hooks.c} | 39 +- .../src/os-shared-filesys-impl-stubs.c | 144 +++++ .../src/os-shared-filesys-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-filesys-stubs.c | 86 +++ .../ut-stubs/src/os-shared-globaldefs-stubs.c | 49 ++ .../ut-stubs/src/os-shared-heap-impl-stubs.c | 44 ++ .../ut-stubs/src/os-shared-idmap-hooks.c | 402 ++++++++++++++ .../ut-stubs/src/os-shared-idmap-impl-stubs.c | 65 +++ .../ut-stubs/src/os-shared-idmap-stubs.c | 509 ++++++++++++++++++ .../src/os-shared-module-impl-stubs.c | 130 +++++ .../src/os-shared-module-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-module-stubs.c | 62 +++ .../ut-stubs/src/os-shared-mutex-impl-stubs.c | 110 ++++ .../ut-stubs/src/os-shared-mutex-init-stubs.c | 42 ++ .../src/os-shared-network-impl-hooks.c | 53 ++ .../src/os-shared-network-impl-stubs.c | 63 +++ .../src/os-shared-network-init-stubs.c | 42 ++ ...-stubs.c => os-shared-printf-impl-stubs.c} | 23 +- .../ut-stubs/src/os-shared-queue-impl-stubs.c | 117 ++++ .../ut-stubs/src/os-shared-queue-init-stubs.c | 42 ++ .../src/os-shared-select-impl-stubs.c | 64 +++ .../ut-stubs/src/os-shared-shell-impl-stubs.c | 45 ++ .../src/os-shared-sockets-impl-stubs.c | 243 +++++++++ .../src/os-shared-sockets-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-sockets-stubs.c | 42 ++ .../ut-stubs/src/os-shared-task-impl-stubs.c | 219 ++++++++ .../ut-stubs/src/os-shared-task-init-stubs.c | 42 ++ ...ap-impl-stubs.c => os-shared-task-stubs.c} | 26 +- .../ut-stubs/src/os-shared-time-init-stubs.c | 42 ++ .../src/os-shared-timebase-impl-stubs.c | 119 ++++ .../src/os-shared-timebase-init-stubs.c | 42 ++ .../ut-stubs/src/os-shared-timebase-stubs.c | 57 ++ .../ut-stubs/src/osapi-binsem-impl-stubs.c | 47 -- .../ut-stubs/src/osapi-countsem-impl-stubs.c | 46 -- .../ut-stubs/src/osapi-file-impl-stubs.c | 88 --- .../ut-stubs/src/osapi-loader-impl-stubs.c | 45 -- .../ut-stubs/src/osapi-mutex-impl-stubs.c | 45 -- .../ut-stubs/src/osapi-network-impl-stubs.c | 67 --- .../ut-stubs/src/osapi-queue-impl-stubs.c | 46 -- .../ut-stubs/src/osapi-select-impl-stubs.c | 52 -- ... => osapi-shared-error-impl-table-stubs.c} | 0 ...ubs.c => osapi-shared-idmap-table-stubs.c} | 0 .../ut-stubs/src/osapi-task-impl-stubs.c | 73 --- .../ut-stubs/src/osapi-timer-impl-stubs.c | 59 -- src/unit-test-coverage/vxworks/CMakeLists.txt | 2 + src/ut-stubs/osapi-file-stubs.c | 8 +- 64 files changed, 4278 insertions(+), 729 deletions(-) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-binsem-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-binsem-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-clock-impl-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-common-impl-stubs.c => os-shared-common-impl-stubs.c} (61%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-common-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-common-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-console-impl-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-idmap-impl-stubs.c => os-shared-console-init-stubs.c} (60%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-countsem-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-countsem-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-dir-impl-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-console-impl-stubs.c => os-shared-dir-init-stubs.c} (62%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-shared-debug-stubs.c => os-shared-file-init-stubs.c} (61%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-file-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-filesys-impl-stubs.c => os-shared-filesys-impl-hooks.c} (54%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-filesys-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-filesys-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-globaldefs-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-heap-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-idmap-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-module-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-module-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-mutex-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-mutex-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-network-init-stubs.c rename src/unit-test-coverage/ut-stubs/src/{portable-console-bsp-impl-stubs.c => os-shared-printf-impl-stubs.c} (68%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-queue-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-queue-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-select-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-shell-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-sockets-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-sockets-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-task-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-task-init-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-heap-impl-stubs.c => os-shared-task-stubs.c} (63%) create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-time-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-timebase-impl-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-timebase-init-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/os-shared-timebase-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c rename src/unit-test-coverage/ut-stubs/src/{osapi-error-impl-stubs.c => osapi-shared-error-impl-table-stubs.c} (100%) rename src/unit-test-coverage/ut-stubs/src/{osapi-shared-idmap-stubs.c => osapi-shared-idmap-table-stubs.c} (100%) delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c delete mode 100644 src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index defe74c08..7c51940aa 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -30,7 +30,9 @@ set(SHARED_COVERAGE_LINK_LIST os-shared-coverage-support ut-adaptor-shared ut_osapi_impl_stubs + ut_osapi_init_stubs ut_osapi_shared_stubs + ut_osapi_table_stubs ut_osapi_stubs ut_libc_stubs ) diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index ba4714dbb..82efb42b3 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -2,7 +2,7 @@ # Stub libraries for coverage testing # ---------------------------------------- -# This provides suitable "stub" implementations of every +# This provides suitable "stub" implementations of every # function call used internally by the various OSAL modules # for which there is not a stub already defined. # @@ -13,27 +13,27 @@ # i.e. memset, strcmp, etc - these should be relevant for all # supported operating systems as they are standard C # - Stub versions of internal "shared" OSAL implementation functions -# i.e. everything declared in the internal API. These are needed by +# i.e. everything declared in the internal API. These are needed by # any coverage test referencing on the shared/ng OSAL layer. # # The "ut_libc_stubs" target provides stub versions of C library calls. # They are prefixed with "OCS_" and target code must be recompiled to # call the OCS_ version of the syscall instead of the regular syscall. -# This is because in some circumstances for these calls the stub actually -# needs to invoke the real version or else weird things happen. +# This is because in some circumstances for these calls the stub actually +# needs to invoke the real version or else weird things happen. # This library includes stubs from all supported operating systems. This # is generally OK as we do not use any actual OS system headers # -# These files are generally organized to match whatever header file +# These files are generally organized to match whatever header file # defines the function. For instance, POSIX defines the "mqueue.h" # header file which in turn provides mq_open, mq_close, etc. So -# the OCS_mq_open, OCS_mq_close declarations are in overrides/mqueue.h, and +# the OCS_mq_open, OCS_mq_close declarations are in overrides/mqueue.h, and # the respective implementation is in posix-mqueue-stubs.c. # -# This keeps things relatively organized, and by keeping the source files +# This keeps things relatively organized, and by keeping the source files # relatively small and targeted like this the linker should only pull in -# the OCS functions that are actually used. +# the OCS functions that are actually used. # add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/arpa-inet-stubs.c @@ -74,49 +74,163 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/vxworks-taskLib-stubs.c src/vxworks-taskVarLib-stubs.c src/vxworks-xbdBlkDev-stubs.c) - -target_include_directories(ut_libc_stubs PUBLIC + +target_include_directories(ut_libc_stubs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc ) - - -# The "ut_osapi_impl_stubs" provides stub functions for internal -# OSAL calls used by or implemented by the shared layer. These -# are not public API calls. This is only compiled if used. + +# About the generated UT stub sources +# +# The interface between "shared" (upper) and "impl" (lower) layers presents a few +# complexities for stubs, because the os/shared/inc headers define prototypes for +# functions that are both referenced from upper and implemented in lower level, as +# well as some functions that are referenced from lower and implemented in upper. +# +# it is important _NOT_ to mix these into the same stub units, even if they are +# declared in the same header file, or else link-time errors are likely to occur. +# +# However, this is eased to some degree because of the naming conventions. All +# functions that are intended to be implemented in the lower layer have an "_Impl" +# suffix on their name. +# +# The stubs are generated in three sets +# impl-stubs : for all "Impl" routines, normally implemented in lower layer. No handlers. +# init-stubs : for all "Init" routines, normally implemented in upper layer. No handlers. +# stubs : for everything else, normally implemented in upper layer. Has handlers. +# +set(OSAL_SHARED_IMPL_HEADERS + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-binsem.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-clock.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-common.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-console.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-countsem.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-dir.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-errors.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-file.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-filesys.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-globaldefs.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-heap.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-idmap.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-module.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-mutex.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-network.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-printf.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-queue.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-select.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-shell.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-sockets.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-task.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-timebase.h + ${OSAL_SOURCE_DIR}/src/os/shared/inc/os-shared-time.h +) + +# The following target rule contains the specific commands required +# to auto-generate the stub implementations from the headers +add_custom_target(generate_osal_coverage_stubs + COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl + --filter=/_Impl$/ + --stub-suffix=impl-stubs + --hook-suffix=impl-hooks + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${OSAL_SHARED_IMPL_HEADERS} + COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl + --filter=/_Init$/ + --stub-suffix=init-stubs + --hook-suffix=init-hooks + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${OSAL_SHARED_IMPL_HEADERS} + COMMAND ${UT_ASSERT_SOURCE_DIR}/scripts/generate_stubs.pl + --filter=!/_Init$|_Impl$/ + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${OSAL_SHARED_IMPL_HEADERS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM +) + +# The "ut_osapi_impl_stubs" provides stub functions for the +# implementation-specific function calls that are declared under os/shared/inc +# header directory. These are the functions that all end in an "_Impl" suffix, +# and are not public API calls. This is only compiled if used. add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL - src/osapi-binsem-impl-stubs.c - src/osapi-common-impl-stubs.c - src/osapi-console-impl-stubs.c - src/osapi-countsem-impl-stubs.c - src/osapi-error-impl-stubs.c - src/osapi-file-impl-stubs.c - src/osapi-filesys-impl-stubs.c - src/osapi-heap-impl-stubs.c - src/osapi-idmap-impl-stubs.c - src/osapi-loader-impl-stubs.c - src/osapi-mutex-impl-stubs.c - src/osapi-network-impl-stubs.c - src/osapi-queue-impl-stubs.c - src/osapi-select-impl-stubs.c - src/osapi-shared-common-stubs.c - src/osapi-shared-debug-stubs.c - src/osapi-shared-idmap-stubs.c - src/osapi-task-impl-stubs.c - src/osapi-timer-impl-stubs.c - src/portable-console-bsp-impl-stubs.c + src/os-shared-binsem-impl-stubs.c + src/os-shared-clock-impl-stubs.c + src/os-shared-common-impl-stubs.c + src/os-shared-console-impl-stubs.c + src/os-shared-countsem-impl-stubs.c + src/os-shared-dir-impl-stubs.c + src/os-shared-file-impl-hooks.c + src/os-shared-file-impl-stubs.c + src/os-shared-filesys-impl-hooks.c + src/os-shared-filesys-impl-stubs.c + src/os-shared-heap-impl-stubs.c + src/os-shared-idmap-impl-stubs.c + src/os-shared-module-impl-stubs.c + src/os-shared-mutex-impl-stubs.c + src/os-shared-network-impl-hooks.c + src/os-shared-network-impl-stubs.c + src/os-shared-printf-impl-stubs.c + src/os-shared-queue-impl-stubs.c + src/os-shared-select-impl-stubs.c + src/os-shared-shell-impl-stubs.c + src/os-shared-sockets-impl-stubs.c + src/os-shared-task-impl-stubs.c + src/os-shared-timebase-impl-stubs.c ) -# The "ut_osapi_shared_stubs" provides stub objects for shared -# objects used by the implementation layer. These -# are not public. This is only compiled if used. +# The "ut_osapi_init_stubs" provides stub functions for the +# initialization function calls that are declared under os/shared/inc +# header directory. These are the functions that all end in an "_Init" suffix, +# and are not public API calls. This is only compiled if used. +add_library(ut_osapi_init_stubs STATIC EXCLUDE_FROM_ALL + src/os-shared-binsem-init-stubs.c + src/os-shared-common-init-stubs.c + src/os-shared-console-init-stubs.c + src/os-shared-countsem-init-stubs.c + src/os-shared-dir-init-stubs.c + src/os-shared-file-init-stubs.c + src/os-shared-filesys-init-stubs.c + src/os-shared-module-init-stubs.c + src/os-shared-mutex-init-stubs.c + src/os-shared-network-init-stubs.c + src/os-shared-queue-init-stubs.c + src/os-shared-sockets-init-stubs.c + src/os-shared-task-init-stubs.c + src/os-shared-timebase-init-stubs.c + src/os-shared-time-init-stubs.c +) + +# The "ut_osapi_shared_stubs" provides stub functions for the +# all other function calls that are declared under os/shared/inc +# header directory. These are the non-public functions that do +# NOT end in either _Init or _Impl suffix, and are normally +# implemented in the shared (upper) layer. +# Unlike the others, these stubs have default handler/hook functions. add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL - src/osapi-shared-common-stubs.c - src/osapi-shared-idmap-stubs.c + src/os-shared-common-stubs.c + src/os-shared-file-stubs.c + src/os-shared-filesys-stubs.c + src/os-shared-globaldefs-stubs.c + src/os-shared-idmap-hooks.c + src/os-shared-idmap-stubs.c + src/os-shared-module-stubs.c + src/os-shared-sockets-stubs.c + src/os-shared-task-stubs.c + src/os-shared-timebase-stubs.c +) + + +# The "ut_osapi_table_stubs" provides stub objects for shared +# table objects used by the implementation layer. These +# are not public. This is only compiled if used. +add_library(ut_osapi_table_stubs STATIC EXCLUDE_FROM_ALL src/osapi-shared-binsem-table-stubs.c src/osapi-shared-console-table-stubs.c + src/osapi-shared-common-stubs.c src/osapi-shared-countsem-table-stubs.c + src/osapi-shared-error-impl-table-stubs.c src/osapi-shared-dir-table-stubs.c src/osapi-shared-filesys-table-stubs.c + src/osapi-shared-idmap-table-stubs.c src/osapi-shared-module-table-stubs.c src/osapi-shared-mutex-table-stubs.c src/osapi-shared-queue-table-stubs.c @@ -124,7 +238,6 @@ add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL src/osapi-shared-task-table-stubs.c src/osapi-shared-timebase-table-stubs.c src/osapi-shared-timecb-table-stubs.c - src/osapi-shared-debug-stubs.c ) add_library(ut_bsp_impl_stubs STATIC EXCLUDE_FROM_ALL diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-impl-stubs.c new file mode 100644 index 000000000..1db968593 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-impl-stubs.c @@ -0,0 +1,144 @@ +/* + * 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 os-shared-binsem header + */ + +#include "os-shared-binsem.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemCreate_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_BinSemCreate_Impl, uint32, sem_initial_value); + UT_GenStub_AddParam(OS_BinSemCreate_Impl, uint32, options); + + UT_GenStub_Execute(OS_BinSemCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemDelete_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_BinSemDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemFlush_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemFlush_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemFlush_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemFlush_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_BinSemFlush_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemFlush_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemGetInfo_Impl(const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_BinSemGetInfo_Impl, OS_bin_sem_prop_t *, bin_prop); + + UT_GenStub_Execute(OS_BinSemGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemGive_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemGive_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemGive_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemGive_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_BinSemGive_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemGive_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemTake_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemTake_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemTake_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemTake_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_BinSemTake_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemTake_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemTimedWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_BinSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemTimedWait_Impl, int32); + + UT_GenStub_AddParam(OS_BinSemTimedWait_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_BinSemTimedWait_Impl, uint32, msecs); + + UT_GenStub_Execute(OS_BinSemTimedWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemTimedWait_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-init-stubs.c new file mode 100644 index 000000000..9e43aa906 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-binsem-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-binsem header + */ + +#include "os-shared-binsem.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BinSemAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_BinSemAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_BinSemAPI_Init, int32); + + UT_GenStub_Execute(OS_BinSemAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BinSemAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-clock-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-clock-impl-stubs.c new file mode 100644 index 000000000..98e028211 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-clock-impl-stubs.c @@ -0,0 +1,60 @@ +/* + * 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 os-shared-clock header + */ + +#include "os-shared-clock.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetLocalTime_Impl() + * ---------------------------------------------------- + */ +int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) +{ + UT_GenStub_SetupReturnBuffer(OS_GetLocalTime_Impl, int32); + + UT_GenStub_AddParam(OS_GetLocalTime_Impl, OS_time_t *, time_struct); + + UT_GenStub_Execute(OS_GetLocalTime_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_GetLocalTime_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SetLocalTime_Impl() + * ---------------------------------------------------- + */ +int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) +{ + UT_GenStub_SetupReturnBuffer(OS_SetLocalTime_Impl, int32); + + UT_GenStub_AddParam(OS_SetLocalTime_Impl, const OS_time_t *, time_struct); + + UT_GenStub_Execute(OS_SetLocalTime_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SetLocalTime_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-common-impl-stubs.c similarity index 61% rename from src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-common-impl-stubs.c index 07edfa887..bc9591309 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-common-impl-stubs.c @@ -19,34 +19,32 @@ */ /** - * \file osapi-common-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-common header */ -#include -#include -#include -#include - -#include "utstubs.h" - #include "os-shared-common.h" +#include "utgenstub.h" -UT_DEFAULT_STUB(OS_API_Impl_Init, (osal_objtype_t idtype)) - -void OS_IdleLoop_Impl(void) -{ - UT_DEFAULT_IMPL(OS_IdleLoop_Impl); -} - +/* + * ---------------------------------------------------- + * Generated stub function for OS_ApplicationShutdown_Impl() + * ---------------------------------------------------- + */ void OS_ApplicationShutdown_Impl(void) { - UT_DEFAULT_IMPL(OS_ApplicationShutdown_Impl); + + UT_GenStub_Execute(OS_ApplicationShutdown_Impl, Basic, NULL); } -void OS_WaitForStateChange_Impl(osal_objtype_t objtype, uint32 attempts) +/* + * ---------------------------------------------------- + * Generated stub function for OS_IdleLoop_Impl() + * ---------------------------------------------------- + */ +void OS_IdleLoop_Impl(void) { - UT_DEFAULT_IMPL(OS_WaitForStateChange_Impl); + + UT_GenStub_Execute(OS_IdleLoop_Impl, Basic, NULL); } diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-common-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-common-init-stubs.c new file mode 100644 index 000000000..c8746a6d3 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-common-init-stubs.c @@ -0,0 +1,44 @@ +/* + * 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 os-shared-common header + */ + +#include "os-shared-common.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_API_Impl_Init() + * ---------------------------------------------------- + */ +int32 OS_API_Impl_Init(osal_objtype_t idtype) +{ + UT_GenStub_SetupReturnBuffer(OS_API_Impl_Init, int32); + + UT_GenStub_AddParam(OS_API_Impl_Init, osal_objtype_t, idtype); + + UT_GenStub_Execute(OS_API_Impl_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_API_Impl_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-common-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-common-stubs.c new file mode 100644 index 000000000..488d67cc7 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-common-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 os-shared-common header + */ + +#include "os-shared-common.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NotifyEvent() + * ---------------------------------------------------- + */ +int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) +{ + UT_GenStub_SetupReturnBuffer(OS_NotifyEvent, int32); + + UT_GenStub_AddParam(OS_NotifyEvent, OS_Event_t, event); + UT_GenStub_AddParam(OS_NotifyEvent, osal_id_t, object_id); + UT_GenStub_AddParam(OS_NotifyEvent, void *, data); + + UT_GenStub_Execute(OS_NotifyEvent, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_NotifyEvent, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-console-impl-stubs.c new file mode 100644 index 000000000..0767427b6 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-console-impl-stubs.c @@ -0,0 +1,56 @@ +/* + * 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 os-shared-console header + */ + +#include "os-shared-console.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ConsoleCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ConsoleCreate_Impl, int32); + + UT_GenStub_AddParam(OS_ConsoleCreate_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ConsoleCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ConsoleCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ConsoleWakeup_Impl() + * ---------------------------------------------------- + */ +void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_ConsoleWakeup_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ConsoleWakeup_Impl, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-console-init-stubs.c similarity index 60% rename from src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-console-init-stubs.c index 7bff71d1e..d1253c95a 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-console-init-stubs.c @@ -19,30 +19,24 @@ */ /** - * \file osapi-idmap-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-console header */ -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-idmap.h" +#include "os-shared-console.h" +#include "utgenstub.h" /* - * Table locking and unlocking for global objects can be done at the shared code - * layer but the actual implementation is OS-specific + * ---------------------------------------------------- + * Generated stub function for OS_ConsoleAPI_Init() + * ---------------------------------------------------- */ -void OS_Lock_Global_Impl(osal_objtype_t idtype) -{ - UT_DEFAULT_IMPL(OS_Lock_Global_Impl); -} -void OS_Unlock_Global_Impl(osal_objtype_t idtype) +int32 OS_ConsoleAPI_Init(void) { - UT_DEFAULT_IMPL(OS_Unlock_Global_Impl); + UT_GenStub_SetupReturnBuffer(OS_ConsoleAPI_Init, int32); + + UT_GenStub_Execute(OS_ConsoleAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ConsoleAPI_Init, int32); } diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-impl-stubs.c new file mode 100644 index 000000000..7a5672c9d --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-impl-stubs.c @@ -0,0 +1,128 @@ +/* + * 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 os-shared-countsem header + */ + +#include "os-shared-countsem.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemCreate_Impl(const OS_object_token_t *token, uint32 sem_initial_value, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemCreate_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CountSemCreate_Impl, uint32, sem_initial_value); + UT_GenStub_AddParam(OS_CountSemCreate_Impl, uint32, options); + + UT_GenStub_Execute(OS_CountSemCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemDelete_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CountSemDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemGetInfo_Impl(const OS_object_token_t *token, OS_count_sem_prop_t *count_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CountSemGetInfo_Impl, OS_count_sem_prop_t *, count_prop); + + UT_GenStub_Execute(OS_CountSemGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemGive_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemGive_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemGive_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemGive_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CountSemGive_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemGive_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemTake_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemTake_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemTake_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemTake_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_CountSemTake_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemTake_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemTimedWait_Impl() + * ---------------------------------------------------- + */ +int32 OS_CountSemTimedWait_Impl(const OS_object_token_t *token, uint32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemTimedWait_Impl, int32); + + UT_GenStub_AddParam(OS_CountSemTimedWait_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CountSemTimedWait_Impl, uint32, msecs); + + UT_GenStub_Execute(OS_CountSemTimedWait_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemTimedWait_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-init-stubs.c new file mode 100644 index 000000000..29b52291f --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-countsem-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-countsem header + */ + +#include "os-shared-countsem.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CountSemAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_CountSemAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_CountSemAPI_Init, int32); + + UT_GenStub_Execute(OS_CountSemAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_CountSemAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-dir-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-dir-impl-stubs.c new file mode 100644 index 000000000..b0f83640b --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-dir-impl-stubs.c @@ -0,0 +1,127 @@ +/* + * 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 os-shared-dir header + */ + +#include "os-shared-dir.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirClose_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirClose_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_DirClose_Impl, int32); + + UT_GenStub_AddParam(OS_DirClose_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_DirClose_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirClose_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirCreate_Impl(const char *local_path, uint32 access) +{ + UT_GenStub_SetupReturnBuffer(OS_DirCreate_Impl, int32); + + UT_GenStub_AddParam(OS_DirCreate_Impl, const char *, local_path); + UT_GenStub_AddParam(OS_DirCreate_Impl, uint32, access); + + UT_GenStub_Execute(OS_DirCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirOpen_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirOpen_Impl(const OS_object_token_t *token, const char *local_path) +{ + UT_GenStub_SetupReturnBuffer(OS_DirOpen_Impl, int32); + + UT_GenStub_AddParam(OS_DirOpen_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_DirOpen_Impl, const char *, local_path); + + UT_GenStub_Execute(OS_DirOpen_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirOpen_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirRead_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirRead_Impl(const OS_object_token_t *token, os_dirent_t *dirent) +{ + UT_GenStub_SetupReturnBuffer(OS_DirRead_Impl, int32); + + UT_GenStub_AddParam(OS_DirRead_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_DirRead_Impl, os_dirent_t *, dirent); + + UT_GenStub_Execute(OS_DirRead_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirRead_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirRemove_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirRemove_Impl(const char *local_path) +{ + UT_GenStub_SetupReturnBuffer(OS_DirRemove_Impl, int32); + + UT_GenStub_AddParam(OS_DirRemove_Impl, const char *, local_path); + + UT_GenStub_Execute(OS_DirRemove_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirRemove_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DirRewind_Impl() + * ---------------------------------------------------- + */ +int32 OS_DirRewind_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_DirRewind_Impl, int32); + + UT_GenStub_AddParam(OS_DirRewind_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_DirRewind_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirRewind_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-dir-init-stubs.c similarity index 62% rename from src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-dir-init-stubs.c index 99dc96511..358408013 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-dir-init-stubs.c @@ -19,29 +19,24 @@ */ /** - * \file osapi-console-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-dir header */ -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-printf.h" +#include "os-shared-dir.h" +#include "utgenstub.h" /* -** Console output API (printf) -*/ -void OS_ConsoleWakeup_Impl(const OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_ConsoleWakeup_Impl); -} -int32 OS_ConsoleCreate_Impl(const OS_object_token_t *token) + * ---------------------------------------------------- + * Generated stub function for OS_DirAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_DirAPI_Init(void) { - return UT_DEFAULT_IMPL(OS_ConsoleCreate_Impl); + UT_GenStub_SetupReturnBuffer(OS_DirAPI_Init, int32); + + UT_GenStub_Execute(OS_DirAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_DirAPI_Init, int32); } diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c new file mode 100644 index 000000000..ec4f1cd23 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-hooks.c @@ -0,0 +1,71 @@ +/* + * 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. + */ + +#include "osapi-file.h" /* OSAL public API for this subsystem */ +#include "os-shared-file.h" +#include "utstubs.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GenericRead_Impl' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GenericRead_Impl(void *UserObj, 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); + int32 status; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + status = UT_Stub_CopyToLocal(UT_KEY(OS_GenericRead_Impl), buffer, nbytes); + UT_Stub_SetReturnValue(FuncKey, status); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GenericWrite_Impl' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GenericWrite_Impl(void *UserObj, 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); + int32 status; + + if (!UT_Stub_GetInt32StatusCode(Context, &status)) + { + status = UT_Stub_CopyFromLocal(UT_KEY(OS_GenericWrite_Impl), buffer, nbytes); + UT_Stub_SetReturnValue(FuncKey, status); + } +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c new file mode 100644 index 000000000..b239a625a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-file-impl-stubs.c @@ -0,0 +1,206 @@ +/* + * 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 os-shared-file header + */ + +#include "os-shared-file.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_GenericRead_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_GenericWrite_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileChmod_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileChmod_Impl(const char *local_path, uint32 access_mode) +{ + UT_GenStub_SetupReturnBuffer(OS_FileChmod_Impl, int32); + + UT_GenStub_AddParam(OS_FileChmod_Impl, const char *, local_path); + UT_GenStub_AddParam(OS_FileChmod_Impl, uint32, access_mode); + + UT_GenStub_Execute(OS_FileChmod_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileChmod_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileOpen_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileOpen_Impl(const OS_object_token_t *token, const char *local_path, int32 flags, int32 access_mode) +{ + UT_GenStub_SetupReturnBuffer(OS_FileOpen_Impl, int32); + + UT_GenStub_AddParam(OS_FileOpen_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_FileOpen_Impl, const char *, local_path); + UT_GenStub_AddParam(OS_FileOpen_Impl, int32, flags); + UT_GenStub_AddParam(OS_FileOpen_Impl, int32, access_mode); + + UT_GenStub_Execute(OS_FileOpen_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileOpen_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileRemove_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileRemove_Impl(const char *local_path) +{ + UT_GenStub_SetupReturnBuffer(OS_FileRemove_Impl, int32); + + UT_GenStub_AddParam(OS_FileRemove_Impl, const char *, local_path); + + UT_GenStub_Execute(OS_FileRemove_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileRemove_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileRename_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileRename_Impl(const char *old_path, const char *new_path) +{ + UT_GenStub_SetupReturnBuffer(OS_FileRename_Impl, int32); + + UT_GenStub_AddParam(OS_FileRename_Impl, const char *, old_path); + UT_GenStub_AddParam(OS_FileRename_Impl, const char *, new_path); + + UT_GenStub_Execute(OS_FileRename_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileRename_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileStat_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *filestat) +{ + UT_GenStub_SetupReturnBuffer(OS_FileStat_Impl, int32); + + UT_GenStub_AddParam(OS_FileStat_Impl, const char *, local_path); + UT_GenStub_AddParam(OS_FileStat_Impl, os_fstat_t *, filestat); + + UT_GenStub_Execute(OS_FileStat_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileStat_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GenericClose_Impl() + * ---------------------------------------------------- + */ +int32 OS_GenericClose_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_GenericClose_Impl, int32); + + UT_GenStub_AddParam(OS_GenericClose_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_GenericClose_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_GenericClose_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GenericRead_Impl() + * ---------------------------------------------------- + */ +int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_GenericRead_Impl, int32); + + UT_GenStub_AddParam(OS_GenericRead_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_GenericRead_Impl, void *, buffer); + UT_GenStub_AddParam(OS_GenericRead_Impl, size_t, nbytes); + UT_GenStub_AddParam(OS_GenericRead_Impl, int32, timeout); + + UT_GenStub_Execute(OS_GenericRead_Impl, Basic, UT_DefaultHandler_OS_GenericRead_Impl); + + return UT_GenStub_GetReturnValue(OS_GenericRead_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GenericSeek_Impl() + * ---------------------------------------------------- + */ +int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 whence) +{ + UT_GenStub_SetupReturnBuffer(OS_GenericSeek_Impl, int32); + + UT_GenStub_AddParam(OS_GenericSeek_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_GenericSeek_Impl, int32, offset); + UT_GenStub_AddParam(OS_GenericSeek_Impl, uint32, whence); + + UT_GenStub_Execute(OS_GenericSeek_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_GenericSeek_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GenericWrite_Impl() + * ---------------------------------------------------- + */ +int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_GenericWrite_Impl, int32); + + UT_GenStub_AddParam(OS_GenericWrite_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_GenericWrite_Impl, const void *, buffer); + UT_GenStub_AddParam(OS_GenericWrite_Impl, size_t, nbytes); + UT_GenStub_AddParam(OS_GenericWrite_Impl, int32, timeout); + + UT_GenStub_Execute(OS_GenericWrite_Impl, Basic, UT_DefaultHandler_OS_GenericWrite_Impl); + + return UT_GenStub_GetReturnValue(OS_GenericWrite_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ShellOutputToFile_Impl() + * ---------------------------------------------------- + */ +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) +{ + UT_GenStub_SetupReturnBuffer(OS_ShellOutputToFile_Impl, int32); + + UT_GenStub_AddParam(OS_ShellOutputToFile_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ShellOutputToFile_Impl, const char *, Cmd); + + UT_GenStub_Execute(OS_ShellOutputToFile_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ShellOutputToFile_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-init-stubs.c similarity index 61% rename from src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-file-init-stubs.c index d2973e5de..0e9c6e08b 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-file-init-stubs.c @@ -19,17 +19,24 @@ */ /** - * \file osapi-shared-debug-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-file header */ -#include "os-shared-globaldefs.h" -/***************************************************************************** - * - * Stub function for OS_DebugPrintf() - * This is only relevant when building OSAL with OSAL_CONFIG_DEBUG_PRINTF enabled - * - *****************************************************************************/ -void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *Format, ...) {} +#include "os-shared-file.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_FileAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_FileAPI_Init, int32); + + UT_GenStub_Execute(OS_FileAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-file-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-file-stubs.c new file mode 100644 index 000000000..d5dfa49a0 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-file-stubs.c @@ -0,0 +1,45 @@ +/* + * 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 os-shared-file header + */ + +#include "os-shared-file.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileIteratorClose() + * ---------------------------------------------------- + */ +int32 OS_FileIteratorClose(osal_id_t filedes, void *arg) +{ + UT_GenStub_SetupReturnBuffer(OS_FileIteratorClose, int32); + + UT_GenStub_AddParam(OS_FileIteratorClose, osal_id_t, filedes); + UT_GenStub_AddParam(OS_FileIteratorClose, void *, arg); + + UT_GenStub_Execute(OS_FileIteratorClose, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileIteratorClose, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-hooks.c similarity index 54% rename from src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-hooks.c index 0dd5577e0..b49982cf7 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-hooks.c @@ -19,39 +19,36 @@ */ /** - * \file osapi-filesys-impl-stubs.c - * \ingroup ut-stubs + * \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. */ -#include -#include -#include -#include - -#include "utstubs.h" +#include "osapi-filesys.h" /* OSAL public API for this subsystem */ #include "os-shared-filesys.h" +#include "utstubs.h" /* - * File system abstraction layer + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_FileSysStatVolume_Impl' stub + * ----------------------------------------------------------------- */ -UT_DEFAULT_STUB(OS_FileSysStartVolume_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_FileSysStopVolume_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_FileSysFormatVolume_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_FileSysCheckVolume_Impl, (const OS_object_token_t *token, bool repair)) -UT_DEFAULT_STUB(OS_FileSysMountVolume_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_FileSysUnmountVolume_Impl, (const OS_object_token_t *token)) - -int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) +void UT_DefaultHandler_OS_FileSysStatVolume_Impl(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - int32 Status = UT_DEFAULT_IMPL(OS_FileSysStatVolume_Impl); + OS_statvfs_t *result = UT_Hook_GetArgValueByName(Context, "result", OS_statvfs_t *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); - if (Status == OS_SUCCESS && + if (status == OS_SUCCESS && UT_Stub_CopyToLocal(UT_KEY(OS_FileSysStatVolume_Impl), result, sizeof(*result)) < sizeof(*result)) { memset(result, 0, sizeof(*result)); } - - return Status; } diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c new file mode 100644 index 000000000..90be32598 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-impl-stubs.c @@ -0,0 +1,144 @@ +/* + * 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 os-shared-filesys header + */ + +#include "os-shared-filesys.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_FileSysStatVolume_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysCheckVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysCheckVolume_Impl(const OS_object_token_t *token, bool repair) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysCheckVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysCheckVolume_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_FileSysCheckVolume_Impl, bool, repair); + + UT_GenStub_Execute(OS_FileSysCheckVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysCheckVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysFormatVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysFormatVolume_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysFormatVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysFormatVolume_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_FileSysFormatVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysFormatVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysMountVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysMountVolume_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysMountVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysMountVolume_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_FileSysMountVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysMountVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysStartVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysStartVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysStartVolume_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_FileSysStartVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysStartVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysStatVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysStatVolume_Impl(const OS_object_token_t *token, OS_statvfs_t *result) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysStatVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysStatVolume_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_FileSysStatVolume_Impl, OS_statvfs_t *, result); + + UT_GenStub_Execute(OS_FileSysStatVolume_Impl, Basic, UT_DefaultHandler_OS_FileSysStatVolume_Impl); + + return UT_GenStub_GetReturnValue(OS_FileSysStatVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysStopVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysStopVolume_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysStopVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysStopVolume_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_FileSysStopVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysStopVolume_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysUnmountVolume_Impl() + * ---------------------------------------------------- + */ +int32 OS_FileSysUnmountVolume_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysUnmountVolume_Impl, int32); + + UT_GenStub_AddParam(OS_FileSysUnmountVolume_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_FileSysUnmountVolume_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysUnmountVolume_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-init-stubs.c new file mode 100644 index 000000000..7841b6e5b --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-filesys header + */ + +#include "os-shared-filesys.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_FileSysAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysAPI_Init, int32); + + UT_GenStub_Execute(OS_FileSysAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-stubs.c new file mode 100644 index 000000000..17fe72be0 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-filesys-stubs.c @@ -0,0 +1,86 @@ +/* + * 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 os-shared-filesys header + */ + +#include "os-shared-filesys.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSysFilterFree() + * ---------------------------------------------------- + */ +bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSysFilterFree, bool); + + UT_GenStub_AddParam(OS_FileSysFilterFree, void *, ref); + UT_GenStub_AddParam(OS_FileSysFilterFree, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_FileSysFilterFree, const OS_common_record_t *, obj); + + UT_GenStub_Execute(OS_FileSysFilterFree, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSysFilterFree, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSys_FindVirtMountPoint() + * ---------------------------------------------------- + */ +bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSys_FindVirtMountPoint, bool); + + UT_GenStub_AddParam(OS_FileSys_FindVirtMountPoint, void *, ref); + UT_GenStub_AddParam(OS_FileSys_FindVirtMountPoint, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_FileSys_FindVirtMountPoint, const OS_common_record_t *, obj); + + UT_GenStub_Execute(OS_FileSys_FindVirtMountPoint, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSys_FindVirtMountPoint, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_FileSys_Initialize() + * ---------------------------------------------------- + */ +int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fsvolname, size_t blocksize, + osal_blockcount_t numblocks, bool should_format) +{ + UT_GenStub_SetupReturnBuffer(OS_FileSys_Initialize, int32); + + UT_GenStub_AddParam(OS_FileSys_Initialize, char *, address); + UT_GenStub_AddParam(OS_FileSys_Initialize, const char *, fsdevname); + UT_GenStub_AddParam(OS_FileSys_Initialize, const char *, fsvolname); + UT_GenStub_AddParam(OS_FileSys_Initialize, size_t, blocksize); + UT_GenStub_AddParam(OS_FileSys_Initialize, osal_blockcount_t, numblocks); + UT_GenStub_AddParam(OS_FileSys_Initialize, bool, should_format); + + UT_GenStub_Execute(OS_FileSys_Initialize, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_FileSys_Initialize, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-globaldefs-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-globaldefs-stubs.c new file mode 100644 index 000000000..92cfe839e --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-globaldefs-stubs.c @@ -0,0 +1,49 @@ +/* + * 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 os-shared-globaldefs header + */ + +#include + +#include "os-shared-globaldefs.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_DebugPrintf() + * ---------------------------------------------------- + */ +void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *Format, ...) +{ + va_list UtStub_ArgList; + + UT_GenStub_AddParam(OS_DebugPrintf, uint32, Level); + UT_GenStub_AddParam(OS_DebugPrintf, const char *, Func); + UT_GenStub_AddParam(OS_DebugPrintf, uint32, Line); + UT_GenStub_AddParam(OS_DebugPrintf, const char *, Format); + + va_start(UtStub_ArgList, Format); + UT_GenStub_Execute(OS_DebugPrintf, Va, NULL, UtStub_ArgList); + va_end(UtStub_ArgList); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-heap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-heap-impl-stubs.c new file mode 100644 index 000000000..024fbcca9 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-heap-impl-stubs.c @@ -0,0 +1,44 @@ +/* + * 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 os-shared-heap header + */ + +#include "os-shared-heap.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_HeapGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_HeapGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_HeapGetInfo_Impl, OS_heap_prop_t *, heap_prop); + + UT_GenStub_Execute(OS_HeapGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_HeapGetInfo_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c new file mode 100644 index 000000000..d6c91b80b --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-hooks.c @@ -0,0 +1,402 @@ +/* + * 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 "os-shared-idmap.h" +#include "utstubs.h" + +#define OSAL_MAX_VALID_PER_TYPE 16 + +/* + * Note that fabricates IDs that are compatible with the IDs from the other (public) API stubs + */ +static void UT_ObjIdCompose(uint32 indx, osal_objtype_t objtype, osal_id_t *id) +{ + *id = OS_ObjectIdFromInteger((unsigned long)indx | ((0x4000UL | objtype) << 16)); +} + +/* + * 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); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetMaxForObjectType' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetMaxForObjectType(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + int32 status; + uint32 max; + + if (UT_Stub_GetInt32StatusCode(Context, &status)) + { + /* interpret the registered status code as a max */ + max = status; + } + else if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) + { + max = OSAL_MAX_VALID_PER_TYPE; + } + else + { + max = 0; + } + + UT_Stub_SetReturnValue(FuncKey, max); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_GetBaseForObjectType' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_GetBaseForObjectType(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + int32 status; + uint32 base; + + if (UT_Stub_GetInt32StatusCode(Context, &status)) + { + /* interpret the registered status code as a max */ + base = status; + } + else if (idtype > OS_OBJECT_TYPE_UNDEFINED && idtype < OS_OBJECT_TYPE_USER) + { + base = OSAL_MAX_VALID_PER_TYPE * (idtype - 1); + } + else + { + base = 0; + } + + UT_Stub_SetReturnValue(FuncKey, base); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdGlobalFromToken' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdGlobalFromToken(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + static OS_common_record_t fake_record; + int32 status; + OS_common_record_t * recptr = &fake_record; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == 0 && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGlobalFromToken), &recptr, sizeof(recptr)) < sizeof(recptr)) + { + /* This function should never return null */ + recptr = &fake_record; + } + + UT_Stub_SetReturnValue(FuncKey, recptr); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdFinalizeNew' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdFinalizeNew(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + int32 operation_status = UT_Hook_GetArgValueByName(Context, "operation_status", int32); + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + osal_id_t * outid = UT_Hook_GetArgValueByName(Context, "outid", osal_id_t *); + int32 Status; + + if (!UT_Stub_GetInt32StatusCode(Context, &Status)) + { + /* pass through the argument status unless overridden */ + Status = 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; + } + + UT_Stub_SetReturnValue(FuncKey, Status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdFinalizeDelete' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdFinalizeDelete(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + int32 operation_status = UT_Hook_GetArgValueByName(Context, "operation_status", int32); + int32 Status; + + if (!UT_Stub_GetInt32StatusCode(Context, &Status)) + { + /* pass through the argument status unless overridden */ + Status = operation_status; + } + + UT_Stub_SetReturnValue(FuncKey, Status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdGetBySearch' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdGetBySearch(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_lock_mode_t lock_mode = UT_Hook_GetArgValueByName(Context, "lock_mode", OS_lock_mode_t); + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + 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 + */ + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetBySearch), token, sizeof(*token)) < sizeof(*token)) + { + UT_TokenCompose(lock_mode, 1, idtype, token); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdTransactionInit' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdTransactionInit(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdTransactionInit), token, sizeof(*token)) < sizeof(*token)) + { + memset(&token, 0, sizeof(token)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdFindByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdFindByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + osal_id_t * object_id = UT_Hook_GetArgValueByName(Context, "object_id", osal_id_t *); + 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 + */ + if (!UT_Stub_GetInt32StatusCode(Context, &Status)) + { + Status = 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); + } + + UT_Stub_SetReturnValue(FuncKey, Status); +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdGetByName' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdGetByName(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_lock_mode_t lock_mode = UT_Hook_GetArgValueByName(Context, "lock_mode", OS_lock_mode_t); + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + if (Status == OS_SUCCESS && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdGetByName), token, sizeof(*token)) < sizeof(*token)) + { + UT_TokenCompose(lock_mode, 1, idtype, token); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdGetById' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdGetById(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_lock_mode_t lock_mode = UT_Hook_GetArgValueByName(Context, "lock_mode", OS_lock_mode_t); + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + osal_id_t id = UT_Hook_GetArgValueByName(Context, "id", osal_id_t); + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + 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); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdTransferToken' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdTransferToken(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_object_token_t *token_from = UT_Hook_GetArgValueByName(Context, "token_from", OS_object_token_t *); + OS_object_token_t *token_to = UT_Hook_GetArgValueByName(Context, "token_to", OS_object_token_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + 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; + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdAllocateNew' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdAllocateNew(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + osal_objtype_t idtype = UT_Hook_GetArgValueByName(Context, "idtype", osal_objtype_t); + OS_object_token_t *token = UT_Hook_GetArgValueByName(Context, "token", OS_object_token_t *); + int32 Status; + + UT_Stub_GetInt32StatusCode(Context, &Status); + + 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); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdIteratorInit' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdIteratorInit(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_object_iter_t *iter = UT_Hook_GetArgValueByName(Context, "iter", OS_object_iter_t *); + + if (!UT_Stub_GetInt32StatusCode(Context, NULL) && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdIterateActive' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdIterateActive(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_object_iter_t *iter = UT_Hook_GetArgValueByName(Context, "iter", OS_object_iter_t *); + + if (!UT_Stub_GetInt32StatusCode(Context, NULL) && + UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIterateActive), iter, sizeof(*iter)) < sizeof(*iter)) + { + memset(iter, 0, sizeof(*iter)); + } +} + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_ObjectIdIteratorGetNext' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_ObjectIdIteratorGetNext(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + OS_object_iter_t *iter = UT_Hook_GetArgValueByName(Context, "iter", OS_object_iter_t *); + bool ReturnCode; + int32 Status; + + if (UT_Stub_GetInt32StatusCode(Context, &Status)) + { + ReturnCode = Status; + } + else + { + /* if test case has registered something, return true, otherwise return false */ + ReturnCode = (UT_Stub_CopyToLocal(UT_KEY(OS_ObjectIdIteratorGetNext), &iter->token, sizeof(iter->token)) == + sizeof(iter->token)); + } + UT_Stub_SetReturnValue(FuncKey, ReturnCode); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-impl-stubs.c new file mode 100644 index 000000000..92a6e007a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-impl-stubs.c @@ -0,0 +1,65 @@ +/* + * 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 os-shared-idmap header + */ + +#include "os-shared-idmap.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_Lock_Global_Impl() + * ---------------------------------------------------- + */ +void OS_Lock_Global_Impl(osal_objtype_t idtype) +{ + UT_GenStub_AddParam(OS_Lock_Global_Impl, osal_objtype_t, idtype); + + UT_GenStub_Execute(OS_Lock_Global_Impl, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_Unlock_Global_Impl() + * ---------------------------------------------------- + */ +void OS_Unlock_Global_Impl(osal_objtype_t idtype) +{ + UT_GenStub_AddParam(OS_Unlock_Global_Impl, osal_objtype_t, idtype); + + UT_GenStub_Execute(OS_Unlock_Global_Impl, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_WaitForStateChange_Impl() + * ---------------------------------------------------- + */ +void OS_WaitForStateChange_Impl(osal_objtype_t objtype, uint32 attempts) +{ + UT_GenStub_AddParam(OS_WaitForStateChange_Impl, osal_objtype_t, objtype); + UT_GenStub_AddParam(OS_WaitForStateChange_Impl, uint32, attempts); + + UT_GenStub_Execute(OS_WaitForStateChange_Impl, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c new file mode 100644 index 000000000..2d371a1bb --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-idmap-stubs.c @@ -0,0 +1,509 @@ +/* + * 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 os-shared-idmap header + */ + +#include "os-shared-idmap.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_GetBaseForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_GetMaxForObjectType(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdAllocateNew(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdFinalizeDelete(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdFinalizeNew(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdFindByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdGetById(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdGetByName(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdGetBySearch(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdGlobalFromToken(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdIterateActive(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdIteratorGetNext(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdIteratorInit(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdTransactionInit(void *, UT_EntryKey_t, const UT_StubContext_t *); +extern void UT_DefaultHandler_OS_ObjectIdTransferToken(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetBaseForObjectType() + * ---------------------------------------------------- + */ +uint32 OS_GetBaseForObjectType(osal_objtype_t idtype) +{ + UT_GenStub_SetupReturnBuffer(OS_GetBaseForObjectType, uint32); + + UT_GenStub_AddParam(OS_GetBaseForObjectType, osal_objtype_t, idtype); + + UT_GenStub_Execute(OS_GetBaseForObjectType, Basic, UT_DefaultHandler_OS_GetBaseForObjectType); + + return UT_GenStub_GetReturnValue(OS_GetBaseForObjectType, uint32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GetMaxForObjectType() + * ---------------------------------------------------- + */ +uint32 OS_GetMaxForObjectType(osal_objtype_t idtype) +{ + UT_GenStub_SetupReturnBuffer(OS_GetMaxForObjectType, uint32); + + UT_GenStub_AddParam(OS_GetMaxForObjectType, osal_objtype_t, idtype); + + UT_GenStub_Execute(OS_GetMaxForObjectType, Basic, UT_DefaultHandler_OS_GetMaxForObjectType); + + return UT_GenStub_GetReturnValue(OS_GetMaxForObjectType, uint32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_Lock_Global() + * ---------------------------------------------------- + */ +void OS_Lock_Global(OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_Lock_Global, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_Lock_Global, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectFilterActive() + * ---------------------------------------------------- + */ +bool OS_ObjectFilterActive(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectFilterActive, bool); + + UT_GenStub_AddParam(OS_ObjectFilterActive, void *, ref); + UT_GenStub_AddParam(OS_ObjectFilterActive, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ObjectFilterActive, const OS_common_record_t *, obj); + + UT_GenStub_Execute(OS_ObjectFilterActive, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectFilterActive, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdAllocateNew() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdAllocateNew(osal_objtype_t idtype, const char *name, OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdAllocateNew, int32); + + UT_GenStub_AddParam(OS_ObjectIdAllocateNew, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdAllocateNew, const char *, name); + UT_GenStub_AddParam(OS_ObjectIdAllocateNew, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdAllocateNew, Basic, UT_DefaultHandler_OS_ObjectIdAllocateNew); + + return UT_GenStub_GetReturnValue(OS_ObjectIdAllocateNew, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdConvertToken() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdConvertToken(OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdConvertToken, int32); + + UT_GenStub_AddParam(OS_ObjectIdConvertToken, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdConvertToken, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectIdConvertToken, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdFinalizeDelete() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdFinalizeDelete(int32 operation_status, OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdFinalizeDelete, int32); + + UT_GenStub_AddParam(OS_ObjectIdFinalizeDelete, int32, operation_status); + UT_GenStub_AddParam(OS_ObjectIdFinalizeDelete, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdFinalizeDelete, Basic, UT_DefaultHandler_OS_ObjectIdFinalizeDelete); + + return UT_GenStub_GetReturnValue(OS_ObjectIdFinalizeDelete, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdFinalizeNew() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_object_token_t *token, osal_id_t *outid) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdFinalizeNew, int32); + + UT_GenStub_AddParam(OS_ObjectIdFinalizeNew, int32, operation_status); + UT_GenStub_AddParam(OS_ObjectIdFinalizeNew, OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ObjectIdFinalizeNew, osal_id_t *, outid); + + UT_GenStub_Execute(OS_ObjectIdFinalizeNew, Basic, UT_DefaultHandler_OS_ObjectIdFinalizeNew); + + return UT_GenStub_GetReturnValue(OS_ObjectIdFinalizeNew, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdFindByName() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdFindByName(osal_objtype_t idtype, const char *name, osal_id_t *object_id) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdFindByName, int32); + + UT_GenStub_AddParam(OS_ObjectIdFindByName, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdFindByName, const char *, name); + UT_GenStub_AddParam(OS_ObjectIdFindByName, osal_id_t *, object_id); + + UT_GenStub_Execute(OS_ObjectIdFindByName, Basic, UT_DefaultHandler_OS_ObjectIdFindByName); + + return UT_GenStub_GetReturnValue(OS_ObjectIdFindByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdFindNextFree() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdFindNextFree(OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdFindNextFree, int32); + + UT_GenStub_AddParam(OS_ObjectIdFindNextFree, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdFindNextFree, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectIdFindNextFree, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdFindNextMatch() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdFindNextMatch(OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdFindNextMatch, int32); + + UT_GenStub_AddParam(OS_ObjectIdFindNextMatch, OS_ObjectMatchFunc_t, MatchFunc); + UT_GenStub_AddParam(OS_ObjectIdFindNextMatch, void *, arg); + UT_GenStub_AddParam(OS_ObjectIdFindNextMatch, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdFindNextMatch, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectIdFindNextMatch, int32); +} + +/* + * ---------------------------------------------------- + * Generated 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) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdGetById, int32); + + UT_GenStub_AddParam(OS_ObjectIdGetById, OS_lock_mode_t, lock_mode); + UT_GenStub_AddParam(OS_ObjectIdGetById, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdGetById, osal_id_t, id); + UT_GenStub_AddParam(OS_ObjectIdGetById, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdGetById, Basic, UT_DefaultHandler_OS_ObjectIdGetById); + + return UT_GenStub_GetReturnValue(OS_ObjectIdGetById, int32); +} + +/* + * ---------------------------------------------------- + * Generated 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) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdGetByName, int32); + + UT_GenStub_AddParam(OS_ObjectIdGetByName, OS_lock_mode_t, lock_mode); + UT_GenStub_AddParam(OS_ObjectIdGetByName, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdGetByName, const char *, name); + UT_GenStub_AddParam(OS_ObjectIdGetByName, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdGetByName, Basic, UT_DefaultHandler_OS_ObjectIdGetByName); + + return UT_GenStub_GetReturnValue(OS_ObjectIdGetByName, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdGetBySearch() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, + OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdGetBySearch, int32); + + UT_GenStub_AddParam(OS_ObjectIdGetBySearch, OS_lock_mode_t, lock_mode); + UT_GenStub_AddParam(OS_ObjectIdGetBySearch, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdGetBySearch, OS_ObjectMatchFunc_t, MatchFunc); + UT_GenStub_AddParam(OS_ObjectIdGetBySearch, void *, arg); + UT_GenStub_AddParam(OS_ObjectIdGetBySearch, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdGetBySearch, Basic, UT_DefaultHandler_OS_ObjectIdGetBySearch); + + return UT_GenStub_GetReturnValue(OS_ObjectIdGetBySearch, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdGlobalFromToken() + * ---------------------------------------------------- + */ +OS_common_record_t *OS_ObjectIdGlobalFromToken(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdGlobalFromToken, OS_common_record_t *); + + UT_GenStub_AddParam(OS_ObjectIdGlobalFromToken, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdGlobalFromToken, Basic, UT_DefaultHandler_OS_ObjectIdGlobalFromToken); + + return UT_GenStub_GetReturnValue(OS_ObjectIdGlobalFromToken, OS_common_record_t *); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdInit() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdInit(void) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdInit, int32); + + UT_GenStub_Execute(OS_ObjectIdInit, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectIdInit, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdIterateActive() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdIterateActive(osal_objtype_t objtype, OS_object_iter_t *iter) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdIterateActive, int32); + + UT_GenStub_AddParam(OS_ObjectIdIterateActive, osal_objtype_t, objtype); + UT_GenStub_AddParam(OS_ObjectIdIterateActive, OS_object_iter_t *, iter); + + UT_GenStub_Execute(OS_ObjectIdIterateActive, Basic, UT_DefaultHandler_OS_ObjectIdIterateActive); + + return UT_GenStub_GetReturnValue(OS_ObjectIdIterateActive, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdIteratorDestroy() + * ---------------------------------------------------- + */ +void OS_ObjectIdIteratorDestroy(OS_object_iter_t *iter) +{ + UT_GenStub_AddParam(OS_ObjectIdIteratorDestroy, OS_object_iter_t *, iter); + + UT_GenStub_Execute(OS_ObjectIdIteratorDestroy, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdIteratorGetNext() + * ---------------------------------------------------- + */ +bool OS_ObjectIdIteratorGetNext(OS_object_iter_t *iter) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdIteratorGetNext, bool); + + UT_GenStub_AddParam(OS_ObjectIdIteratorGetNext, OS_object_iter_t *, iter); + + UT_GenStub_Execute(OS_ObjectIdIteratorGetNext, Basic, UT_DefaultHandler_OS_ObjectIdIteratorGetNext); + + return UT_GenStub_GetReturnValue(OS_ObjectIdIteratorGetNext, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdIteratorInit() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdIteratorInit(OS_ObjectMatchFunc_t matchfunc, void *matcharg, osal_objtype_t objtype, + OS_object_iter_t *iter) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdIteratorInit, int32); + + UT_GenStub_AddParam(OS_ObjectIdIteratorInit, OS_ObjectMatchFunc_t, matchfunc); + UT_GenStub_AddParam(OS_ObjectIdIteratorInit, void *, matcharg); + UT_GenStub_AddParam(OS_ObjectIdIteratorInit, osal_objtype_t, objtype); + UT_GenStub_AddParam(OS_ObjectIdIteratorInit, OS_object_iter_t *, iter); + + UT_GenStub_Execute(OS_ObjectIdIteratorInit, Basic, UT_DefaultHandler_OS_ObjectIdIteratorInit); + + return UT_GenStub_GetReturnValue(OS_ObjectIdIteratorInit, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdIteratorProcessEntry() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdIteratorProcessEntry(OS_object_iter_t *iter, OS_ObjectIdIteratorProcessFunc_t func) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdIteratorProcessEntry, int32); + + UT_GenStub_AddParam(OS_ObjectIdIteratorProcessEntry, OS_object_iter_t *, iter); + UT_GenStub_AddParam(OS_ObjectIdIteratorProcessEntry, OS_ObjectIdIteratorProcessFunc_t, func); + + UT_GenStub_Execute(OS_ObjectIdIteratorProcessEntry, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectIdIteratorProcessEntry, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdRelease() + * ---------------------------------------------------- + */ +void OS_ObjectIdRelease(OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_ObjectIdRelease, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdRelease, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdTransactionCancel() + * ---------------------------------------------------- + */ +void OS_ObjectIdTransactionCancel(OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_ObjectIdTransactionCancel, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdTransactionCancel, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdTransactionFinish() + * ---------------------------------------------------- + */ +void OS_ObjectIdTransactionFinish(OS_object_token_t *token, const osal_id_t *final_id) +{ + UT_GenStub_AddParam(OS_ObjectIdTransactionFinish, OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ObjectIdTransactionFinish, const osal_id_t *, final_id); + + UT_GenStub_Execute(OS_ObjectIdTransactionFinish, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdTransactionInit() + * ---------------------------------------------------- + */ +int32 OS_ObjectIdTransactionInit(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectIdTransactionInit, int32); + + UT_GenStub_AddParam(OS_ObjectIdTransactionInit, OS_lock_mode_t, lock_mode); + UT_GenStub_AddParam(OS_ObjectIdTransactionInit, osal_objtype_t, idtype); + UT_GenStub_AddParam(OS_ObjectIdTransactionInit, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ObjectIdTransactionInit, Basic, UT_DefaultHandler_OS_ObjectIdTransactionInit); + + return UT_GenStub_GetReturnValue(OS_ObjectIdTransactionInit, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectIdTransferToken() + * ---------------------------------------------------- + */ +void OS_ObjectIdTransferToken(OS_object_token_t *token_from, OS_object_token_t *token_to) +{ + UT_GenStub_AddParam(OS_ObjectIdTransferToken, OS_object_token_t *, token_from); + UT_GenStub_AddParam(OS_ObjectIdTransferToken, OS_object_token_t *, token_to); + + UT_GenStub_Execute(OS_ObjectIdTransferToken, Basic, UT_DefaultHandler_OS_ObjectIdTransferToken); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ObjectNameMatch() + * ---------------------------------------------------- + */ +bool OS_ObjectNameMatch(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + UT_GenStub_SetupReturnBuffer(OS_ObjectNameMatch, bool); + + UT_GenStub_AddParam(OS_ObjectNameMatch, void *, ref); + UT_GenStub_AddParam(OS_ObjectNameMatch, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ObjectNameMatch, const OS_common_record_t *, obj); + + UT_GenStub_Execute(OS_ObjectNameMatch, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ObjectNameMatch, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_Unlock_Global() + * ---------------------------------------------------- + */ +void OS_Unlock_Global(OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_Unlock_Global, OS_object_token_t *, token); + + UT_GenStub_Execute(OS_Unlock_Global, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_WaitForStateChange() + * ---------------------------------------------------- + */ +void OS_WaitForStateChange(OS_object_token_t *token, uint32 attempts) +{ + UT_GenStub_AddParam(OS_WaitForStateChange, OS_object_token_t *, token); + UT_GenStub_AddParam(OS_WaitForStateChange, uint32, attempts); + + UT_GenStub_Execute(OS_WaitForStateChange, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c new file mode 100644 index 000000000..6413b0b05 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c @@ -0,0 +1,130 @@ +/* + * 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 os-shared-module header + */ + +#include "os-shared-module.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_GlobalSymbolLookup_Impl() + * ---------------------------------------------------- + */ +int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +{ + UT_GenStub_SetupReturnBuffer(OS_GlobalSymbolLookup_Impl, int32); + + UT_GenStub_AddParam(OS_GlobalSymbolLookup_Impl, cpuaddr *, SymbolAddress); + UT_GenStub_AddParam(OS_GlobalSymbolLookup_Impl, const char *, SymbolName); + + UT_GenStub_Execute(OS_GlobalSymbolLookup_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_GlobalSymbolLookup_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_ModuleGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ModuleGetInfo_Impl, OS_module_prop_t *, module_prop); + + UT_GenStub_Execute(OS_ModuleGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleLoad_Impl() + * ---------------------------------------------------- + */ +int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleLoad_Impl, int32); + + UT_GenStub_AddParam(OS_ModuleLoad_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ModuleLoad_Impl, const char *, translated_path); + + UT_GenStub_Execute(OS_ModuleLoad_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleLoad_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleSymbolLookup_Impl() + * ---------------------------------------------------- + */ +int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleSymbolLookup_Impl, int32); + + UT_GenStub_AddParam(OS_ModuleSymbolLookup_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ModuleSymbolLookup_Impl, cpuaddr *, SymbolAddress); + UT_GenStub_AddParam(OS_ModuleSymbolLookup_Impl, const char *, SymbolName); + + UT_GenStub_Execute(OS_ModuleSymbolLookup_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleSymbolLookup_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleUnload_Impl() + * ---------------------------------------------------- + */ +int32 OS_ModuleUnload_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleUnload_Impl, int32); + + UT_GenStub_AddParam(OS_ModuleUnload_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ModuleUnload_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleUnload_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SymbolTableDump_Impl() + * ---------------------------------------------------- + */ +int32 OS_SymbolTableDump_Impl(const char *filename, size_t size_limit) +{ + UT_GenStub_SetupReturnBuffer(OS_SymbolTableDump_Impl, int32); + + UT_GenStub_AddParam(OS_SymbolTableDump_Impl, const char *, filename); + UT_GenStub_AddParam(OS_SymbolTableDump_Impl, size_t, size_limit); + + UT_GenStub_Execute(OS_SymbolTableDump_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SymbolTableDump_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-module-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-module-init-stubs.c new file mode 100644 index 000000000..20b61f4aa --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-module-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-module header + */ + +#include "os-shared-module.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_ModuleAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleAPI_Init, int32); + + UT_GenStub_Execute(OS_ModuleAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-module-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-module-stubs.c new file mode 100644 index 000000000..4335cf31a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-module-stubs.c @@ -0,0 +1,62 @@ +/* + * 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 os-shared-module header + */ + +#include "os-shared-module.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ModuleLoad_Static() + * ---------------------------------------------------- + */ +int32 OS_ModuleLoad_Static(const char *ModuleName) +{ + UT_GenStub_SetupReturnBuffer(OS_ModuleLoad_Static, int32); + + UT_GenStub_AddParam(OS_ModuleLoad_Static, const char *, ModuleName); + + UT_GenStub_Execute(OS_ModuleLoad_Static, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ModuleLoad_Static, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SymbolLookup_Static() + * ---------------------------------------------------- + */ +int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName, const char *ModuleName) +{ + UT_GenStub_SetupReturnBuffer(OS_SymbolLookup_Static, int32); + + UT_GenStub_AddParam(OS_SymbolLookup_Static, cpuaddr *, SymbolAddress); + UT_GenStub_AddParam(OS_SymbolLookup_Static, const char *, SymbolName); + UT_GenStub_AddParam(OS_SymbolLookup_Static, const char *, ModuleName); + + UT_GenStub_Execute(OS_SymbolLookup_Static, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SymbolLookup_Static, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-impl-stubs.c new file mode 100644 index 000000000..cb2656cf9 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-impl-stubs.c @@ -0,0 +1,110 @@ +/* + * 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 os-shared-mutex header + */ + +#include "os-shared-mutex.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_MutSemCreate_Impl(const OS_object_token_t *token, uint32 options) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemCreate_Impl, int32); + + UT_GenStub_AddParam(OS_MutSemCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_MutSemCreate_Impl, uint32, options); + + UT_GenStub_Execute(OS_MutSemCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_MutSemDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemDelete_Impl, int32); + + UT_GenStub_AddParam(OS_MutSemDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_MutSemDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_MutSemGetInfo_Impl(const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_MutSemGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_MutSemGetInfo_Impl, OS_mut_sem_prop_t *, mut_prop); + + UT_GenStub_Execute(OS_MutSemGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemGive_Impl() + * ---------------------------------------------------- + */ +int32 OS_MutSemGive_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemGive_Impl, int32); + + UT_GenStub_AddParam(OS_MutSemGive_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_MutSemGive_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemGive_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutSemTake_Impl() + * ---------------------------------------------------- + */ +int32 OS_MutSemTake_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_MutSemTake_Impl, int32); + + UT_GenStub_AddParam(OS_MutSemTake_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_MutSemTake_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutSemTake_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-init-stubs.c new file mode 100644 index 000000000..ddcd517e7 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-mutex-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-mutex header + */ + +#include "os-shared-mutex.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_MutexAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_MutexAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_MutexAPI_Init, int32); + + UT_GenStub_Execute(OS_MutexAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_MutexAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c new file mode 100644 index 000000000..5b7b8f3c4 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-hooks.c @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "osapi-network.h" /* OSAL public API for this subsystem */ +#include "os-shared-network.h" +#include "utstubs.h" + +/* + * ----------------------------------------------------------------- + * Default handler implementation for 'OS_NetworkGetID_Impl' stub + * ----------------------------------------------------------------- + */ +void UT_DefaultHandler_OS_NetworkGetID_Impl(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + int32 *IdBuf = UT_Hook_GetArgValueByName(Context, "IdBuf", int32 *); + int32 status; + + UT_Stub_GetInt32StatusCode(Context, &status); + + if (status == 0) + { + *IdBuf = 42; + } +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-stubs.c new file mode 100644 index 000000000..b4bf6e9f1 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-network-impl-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 os-shared-network header + */ + +#include "os-shared-network.h" +#include "utgenstub.h" + +extern void UT_DefaultHandler_OS_NetworkGetID_Impl(void *, UT_EntryKey_t, const UT_StubContext_t *); + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NetworkGetHostName_Impl() + * ---------------------------------------------------- + */ +int32 OS_NetworkGetHostName_Impl(char *host_name, size_t name_len) +{ + UT_GenStub_SetupReturnBuffer(OS_NetworkGetHostName_Impl, int32); + + UT_GenStub_AddParam(OS_NetworkGetHostName_Impl, char *, host_name); + UT_GenStub_AddParam(OS_NetworkGetHostName_Impl, size_t, name_len); + + UT_GenStub_Execute(OS_NetworkGetHostName_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_NetworkGetHostName_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NetworkGetID_Impl() + * ---------------------------------------------------- + */ +int32 OS_NetworkGetID_Impl(int32 *IdBuf) +{ + UT_GenStub_SetupReturnBuffer(OS_NetworkGetID_Impl, int32); + + UT_GenStub_AddParam(OS_NetworkGetID_Impl, int32 *, IdBuf); + + UT_GenStub_Execute(OS_NetworkGetID_Impl, Basic, UT_DefaultHandler_OS_NetworkGetID_Impl); + + return UT_GenStub_GetReturnValue(OS_NetworkGetID_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-network-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-network-init-stubs.c new file mode 100644 index 000000000..5fd4daf56 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-network-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-network header + */ + +#include "os-shared-network.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_NetworkAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_NetworkAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_NetworkAPI_Init, int32); + + UT_GenStub_Execute(OS_NetworkAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_NetworkAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-printf-impl-stubs.c similarity index 68% rename from src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-printf-impl-stubs.c index 60fab614f..782b8136a 100644 --- a/src/unit-test-coverage/ut-stubs/src/portable-console-bsp-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-printf-impl-stubs.c @@ -19,25 +19,22 @@ */ /** - * \file portable-console-bsp-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-printf header */ -#include -#include -#include -#include - -#include "utstubs.h" - #include "os-shared-printf.h" +#include "utgenstub.h" /* -** Console output API (printf) -*/ + * ---------------------------------------------------- + * Generated stub function for OS_ConsoleOutput_Impl() + * ---------------------------------------------------- + */ void OS_ConsoleOutput_Impl(const OS_object_token_t *token) { - UT_DEFAULT_IMPL(OS_ConsoleOutput_Impl); + UT_GenStub_AddParam(OS_ConsoleOutput_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_ConsoleOutput_Impl, Basic, NULL); } diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-queue-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-queue-impl-stubs.c new file mode 100644 index 000000000..2fb30de83 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-queue-impl-stubs.c @@ -0,0 +1,117 @@ +/* + * 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 os-shared-queue header + */ + +#include "os-shared-queue.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_QueueCreate_Impl(const OS_object_token_t *token, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueCreate_Impl, int32); + + UT_GenStub_AddParam(OS_QueueCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_QueueCreate_Impl, uint32, flags); + + UT_GenStub_Execute(OS_QueueCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueueCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_QueueDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueDelete_Impl, int32); + + UT_GenStub_AddParam(OS_QueueDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_QueueDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueueDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_QueueGetInfo_Impl(const OS_object_token_t *token, OS_queue_prop_t *queue_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_QueueGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_QueueGetInfo_Impl, OS_queue_prop_t *, queue_prop); + + UT_GenStub_Execute(OS_QueueGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueueGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueGet_Impl() + * ---------------------------------------------------- + */ +int32 OS_QueueGet_Impl(const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueGet_Impl, int32); + + UT_GenStub_AddParam(OS_QueueGet_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_QueueGet_Impl, void *, data); + UT_GenStub_AddParam(OS_QueueGet_Impl, size_t, size); + UT_GenStub_AddParam(OS_QueueGet_Impl, size_t *, size_copied); + UT_GenStub_AddParam(OS_QueueGet_Impl, int32, timeout); + + UT_GenStub_Execute(OS_QueueGet_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueueGet_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueuePut_Impl() + * ---------------------------------------------------- + */ +int32 OS_QueuePut_Impl(const OS_object_token_t *token, const void *data, size_t size, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_QueuePut_Impl, int32); + + UT_GenStub_AddParam(OS_QueuePut_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_QueuePut_Impl, const void *, data); + UT_GenStub_AddParam(OS_QueuePut_Impl, size_t, size); + UT_GenStub_AddParam(OS_QueuePut_Impl, uint32, flags); + + UT_GenStub_Execute(OS_QueuePut_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueuePut_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-queue-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-queue-init-stubs.c new file mode 100644 index 000000000..444481596 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-queue-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-queue header + */ + +#include "os-shared-queue.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_QueueAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_QueueAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_QueueAPI_Init, int32); + + UT_GenStub_Execute(OS_QueueAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_QueueAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-select-impl-stubs.c new file mode 100644 index 000000000..24bd2dd86 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-select-impl-stubs.c @@ -0,0 +1,64 @@ +/* + * 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 os-shared-select header + */ + +#include "os-shared-select.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectMultiple_Impl() + * ---------------------------------------------------- + */ +int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectMultiple_Impl, int32); + + UT_GenStub_AddParam(OS_SelectMultiple_Impl, OS_FdSet *, ReadSet); + UT_GenStub_AddParam(OS_SelectMultiple_Impl, OS_FdSet *, WriteSet); + UT_GenStub_AddParam(OS_SelectMultiple_Impl, int32, msecs); + + UT_GenStub_Execute(OS_SelectMultiple_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectMultiple_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SelectSingle_Impl() + * ---------------------------------------------------- + */ +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs) +{ + UT_GenStub_SetupReturnBuffer(OS_SelectSingle_Impl, int32); + + UT_GenStub_AddParam(OS_SelectSingle_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SelectSingle_Impl, uint32 *, SelectFlags); + UT_GenStub_AddParam(OS_SelectSingle_Impl, int32, msecs); + + UT_GenStub_Execute(OS_SelectSingle_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SelectSingle_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-shell-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-shell-impl-stubs.c new file mode 100644 index 000000000..071d9824b --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-shell-impl-stubs.c @@ -0,0 +1,45 @@ +/* + * 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 os-shared-shell header + */ + +#include "os-shared-shell.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_ShellOutputToFile_Impl() + * ---------------------------------------------------- + */ +int32 OS_ShellOutputToFile_Impl(const OS_object_token_t *token, const char *Cmd) +{ + UT_GenStub_SetupReturnBuffer(OS_ShellOutputToFile_Impl, int32); + + UT_GenStub_AddParam(OS_ShellOutputToFile_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_ShellOutputToFile_Impl, const char *, Cmd); + + UT_GenStub_Execute(OS_ShellOutputToFile_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_ShellOutputToFile_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c new file mode 100644 index 000000000..22d8af09c --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c @@ -0,0 +1,243 @@ +/* + * 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 os-shared-sockets header + */ + +#include "os-shared-sockets.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAccept_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, + OS_SockAddr_t *Addr, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAccept_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAccept_Impl, const OS_object_token_t *, sock_token); + UT_GenStub_AddParam(OS_SocketAccept_Impl, const OS_object_token_t *, conn_token); + UT_GenStub_AddParam(OS_SocketAccept_Impl, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAccept_Impl, int32, timeout); + + UT_GenStub_Execute(OS_SocketAccept_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAccept_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrFromString_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrFromString_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAddrFromString_Impl, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrFromString_Impl, const char *, string); + + UT_GenStub_Execute(OS_SocketAddrFromString_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrFromString_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrGetPort_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrGetPort_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAddrGetPort_Impl, uint16 *, PortNum); + UT_GenStub_AddParam(OS_SocketAddrGetPort_Impl, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketAddrGetPort_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrGetPort_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrInit_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrInit_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAddrInit_Impl, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrInit_Impl, OS_SocketDomain_t, Domain); + + UT_GenStub_Execute(OS_SocketAddrInit_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrInit_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrSetPort_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrSetPort_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAddrSetPort_Impl, OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketAddrSetPort_Impl, uint16, PortNum); + + UT_GenStub_Execute(OS_SocketAddrSetPort_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrSetPort_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAddrToString_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAddrToString_Impl, int32); + + UT_GenStub_AddParam(OS_SocketAddrToString_Impl, char *, buffer); + UT_GenStub_AddParam(OS_SocketAddrToString_Impl, size_t, buflen); + UT_GenStub_AddParam(OS_SocketAddrToString_Impl, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketAddrToString_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAddrToString_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketBind_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketBind_Impl, int32); + + UT_GenStub_AddParam(OS_SocketBind_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SocketBind_Impl, const OS_SockAddr_t *, Addr); + + UT_GenStub_Execute(OS_SocketBind_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketBind_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketConnect_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketConnect_Impl, int32); + + UT_GenStub_AddParam(OS_SocketConnect_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SocketConnect_Impl, const OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_SocketConnect_Impl, int32, timeout); + + UT_GenStub_Execute(OS_SocketConnect_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketConnect_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketGetInfo_Impl(const OS_object_token_t *token, OS_socket_prop_t *sock_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_SocketGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SocketGetInfo_Impl, OS_socket_prop_t *, sock_prop); + + UT_GenStub_Execute(OS_SocketGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketOpen_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketOpen_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketOpen_Impl, int32); + + UT_GenStub_AddParam(OS_SocketOpen_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_SocketOpen_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketOpen_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketRecvFrom_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketRecvFrom_Impl(const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, + int32 timeout) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketRecvFrom_Impl, int32); + + UT_GenStub_AddParam(OS_SocketRecvFrom_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SocketRecvFrom_Impl, void *, buffer); + UT_GenStub_AddParam(OS_SocketRecvFrom_Impl, size_t, buflen); + UT_GenStub_AddParam(OS_SocketRecvFrom_Impl, OS_SockAddr_t *, RemoteAddr); + UT_GenStub_AddParam(OS_SocketRecvFrom_Impl, int32, timeout); + + UT_GenStub_Execute(OS_SocketRecvFrom_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketRecvFrom_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketSendTo_Impl() + * ---------------------------------------------------- + */ +int32 OS_SocketSendTo_Impl(const OS_object_token_t *token, const void *buffer, size_t buflen, + const OS_SockAddr_t *RemoteAddr) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketSendTo_Impl, int32); + + UT_GenStub_AddParam(OS_SocketSendTo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_SocketSendTo_Impl, const void *, buffer); + UT_GenStub_AddParam(OS_SocketSendTo_Impl, size_t, buflen); + UT_GenStub_AddParam(OS_SocketSendTo_Impl, const OS_SockAddr_t *, RemoteAddr); + + UT_GenStub_Execute(OS_SocketSendTo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketSendTo_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-init-stubs.c new file mode 100644 index 000000000..1424819be --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-sockets header + */ + +#include "os-shared-sockets.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_SocketAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_SocketAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_SocketAPI_Init, int32); + + UT_GenStub_Execute(OS_SocketAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_SocketAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-stubs.c new file mode 100644 index 000000000..9f7ebb928 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-sockets header + */ + +#include "os-shared-sockets.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_CreateSocketName() + * ---------------------------------------------------- + */ +void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name) +{ + UT_GenStub_AddParam(OS_CreateSocketName, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_CreateSocketName, const OS_SockAddr_t *, Addr); + UT_GenStub_AddParam(OS_CreateSocketName, const char *, parent_name); + + UT_GenStub_Execute(OS_CreateSocketName, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-task-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-task-impl-stubs.c new file mode 100644 index 000000000..959acb7b6 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-task-impl-stubs.c @@ -0,0 +1,219 @@ +/* + * 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 os-shared-task header + */ + +#include "os-shared-task.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskCreate_Impl, int32); + + UT_GenStub_AddParam(OS_TaskCreate_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TaskCreate_Impl, uint32, flags); + + UT_GenStub_Execute(OS_TaskCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskDelay_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskDelay_Impl(uint32 millisecond) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskDelay_Impl, int32); + + UT_GenStub_AddParam(OS_TaskDelay_Impl, uint32, millisecond); + + UT_GenStub_Execute(OS_TaskDelay_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskDelay_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskDelete_Impl, int32); + + UT_GenStub_AddParam(OS_TaskDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TaskDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskDetach_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskDetach_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskDetach_Impl, int32); + + UT_GenStub_AddParam(OS_TaskDetach_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TaskDetach_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskDetach_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskExit_Impl() + * ---------------------------------------------------- + */ +void OS_TaskExit_Impl(void) +{ + + UT_GenStub_Execute(OS_TaskExit_Impl, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskGetId_Impl() + * ---------------------------------------------------- + */ +osal_id_t OS_TaskGetId_Impl(void) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskGetId_Impl, osal_id_t); + + UT_GenStub_Execute(OS_TaskGetId_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskGetId_Impl, osal_id_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_TaskGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TaskGetInfo_Impl, OS_task_prop_t *, task_prop); + + UT_GenStub_Execute(OS_TaskGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskIdMatchSystemData_Impl() + * ---------------------------------------------------- + */ +bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskIdMatchSystemData_Impl, bool); + + UT_GenStub_AddParam(OS_TaskIdMatchSystemData_Impl, void *, ref); + UT_GenStub_AddParam(OS_TaskIdMatchSystemData_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TaskIdMatchSystemData_Impl, const OS_common_record_t *, obj); + + UT_GenStub_Execute(OS_TaskIdMatchSystemData_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskIdMatchSystemData_Impl, bool); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskMatch_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskMatch_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskMatch_Impl, int32); + + UT_GenStub_AddParam(OS_TaskMatch_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TaskMatch_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskMatch_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskRegister_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskRegister_Impl(osal_id_t global_task_id) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskRegister_Impl, int32); + + UT_GenStub_AddParam(OS_TaskRegister_Impl, osal_id_t, global_task_id); + + UT_GenStub_Execute(OS_TaskRegister_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskRegister_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskSetPriority_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskSetPriority_Impl(const OS_object_token_t *token, osal_priority_t new_priority) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskSetPriority_Impl, int32); + + UT_GenStub_AddParam(OS_TaskSetPriority_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TaskSetPriority_Impl, osal_priority_t, new_priority); + + UT_GenStub_Execute(OS_TaskSetPriority_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskSetPriority_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskValidateSystemData_Impl() + * ---------------------------------------------------- + */ +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, size_t sysdata_size) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskValidateSystemData_Impl, int32); + + UT_GenStub_AddParam(OS_TaskValidateSystemData_Impl, const void *, sysdata); + UT_GenStub_AddParam(OS_TaskValidateSystemData_Impl, size_t, sysdata_size); + + UT_GenStub_Execute(OS_TaskValidateSystemData_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskValidateSystemData_Impl, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-task-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-task-init-stubs.c new file mode 100644 index 000000000..95653c225 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-task-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-task header + */ + +#include "os-shared-task.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TaskAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_TaskAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_TaskAPI_Init, int32); + + UT_GenStub_Execute(OS_TaskAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TaskAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-task-stubs.c similarity index 63% rename from src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/os-shared-task-stubs.c index 00b07fb04..4476e7060 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-task-stubs.c @@ -19,22 +19,22 @@ */ /** - * \file osapi-heap-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov + * @file * + * Auto-Generated stub implementations for functions defined in os-shared-task header */ -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-heap.h" +#include "os-shared-task.h" +#include "utgenstub.h" /* - * Heap API low-level handler + * ---------------------------------------------------- + * Generated stub function for OS_TaskEntryPoint() + * ---------------------------------------------------- */ -UT_DEFAULT_STUB(OS_HeapGetInfo_Impl, (OS_heap_prop_t * heap_prop)) +void OS_TaskEntryPoint(osal_id_t global_task_id) +{ + UT_GenStub_AddParam(OS_TaskEntryPoint, osal_id_t, global_task_id); + + UT_GenStub_Execute(OS_TaskEntryPoint, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-time-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-time-init-stubs.c new file mode 100644 index 000000000..6cabe9887 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-time-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-time header + */ + +#include "os-shared-time.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimerCbAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_TimerCbAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_TimerCbAPI_Init, int32); + + UT_GenStub_Execute(OS_TimerCbAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimerCbAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-impl-stubs.c new file mode 100644 index 000000000..a8618d953 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-impl-stubs.c @@ -0,0 +1,119 @@ +/* + * 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 os-shared-timebase header + */ + +#include "os-shared-timebase.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseCreate_Impl() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseCreate_Impl, int32); + + UT_GenStub_AddParam(OS_TimeBaseCreate_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TimeBaseCreate_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseCreate_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseDelete_Impl() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseDelete_Impl(const OS_object_token_t *token) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseDelete_Impl, int32); + + UT_GenStub_AddParam(OS_TimeBaseDelete_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TimeBaseDelete_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseDelete_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseGetInfo_Impl() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseGetInfo_Impl(const OS_object_token_t *token, OS_timebase_prop_t *timer_prop) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseGetInfo_Impl, int32); + + UT_GenStub_AddParam(OS_TimeBaseGetInfo_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TimeBaseGetInfo_Impl, OS_timebase_prop_t *, timer_prop); + + UT_GenStub_Execute(OS_TimeBaseGetInfo_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseGetInfo_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseLock_Impl() + * ---------------------------------------------------- + */ +void OS_TimeBaseLock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_TimeBaseLock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TimeBaseLock_Impl, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseSet_Impl() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uint32 interval_time) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseSet_Impl, int32); + + UT_GenStub_AddParam(OS_TimeBaseSet_Impl, const OS_object_token_t *, token); + UT_GenStub_AddParam(OS_TimeBaseSet_Impl, uint32, start_time); + UT_GenStub_AddParam(OS_TimeBaseSet_Impl, uint32, interval_time); + + UT_GenStub_Execute(OS_TimeBaseSet_Impl, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseSet_Impl, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseUnlock_Impl() + * ---------------------------------------------------- + */ +void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_TimeBaseUnlock_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_TimeBaseUnlock_Impl, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-init-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-init-stubs.c new file mode 100644 index 000000000..07d69d682 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-init-stubs.c @@ -0,0 +1,42 @@ +/* + * 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 os-shared-timebase header + */ + +#include "os-shared-timebase.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBaseAPI_Init() + * ---------------------------------------------------- + */ +int32 OS_TimeBaseAPI_Init(void) +{ + UT_GenStub_SetupReturnBuffer(OS_TimeBaseAPI_Init, int32); + + UT_GenStub_Execute(OS_TimeBaseAPI_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_TimeBaseAPI_Init, int32); +} diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-stubs.c new file mode 100644 index 000000000..0452a47dd --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-timebase-stubs.c @@ -0,0 +1,57 @@ +/* + * 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 os-shared-timebase header + */ + +#include "os-shared-timebase.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for OS_Milli2Ticks() + * ---------------------------------------------------- + */ +int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks) +{ + UT_GenStub_SetupReturnBuffer(OS_Milli2Ticks, int32); + + UT_GenStub_AddParam(OS_Milli2Ticks, uint32, milli_seconds); + UT_GenStub_AddParam(OS_Milli2Ticks, int *, ticks); + + UT_GenStub_Execute(OS_Milli2Ticks, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_Milli2Ticks, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for OS_TimeBase_CallbackThread() + * ---------------------------------------------------- + */ +void OS_TimeBase_CallbackThread(osal_id_t timebase_id) +{ + UT_GenStub_AddParam(OS_TimeBase_CallbackThread, osal_id_t, timebase_id); + + UT_GenStub_Execute(OS_TimeBase_CallbackThread, Basic, NULL); +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c deleted file mode 100644 index cee315962..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c +++ /dev/null @@ -1,47 +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-binsem-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-binsem.h" - -/* -** Semaphore API -*/ - -UT_DEFAULT_STUB(OS_BinSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_BinSemFlush_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_BinSemGive_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_BinSemTake_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) -UT_DEFAULT_STUB(OS_BinSemDelete_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl, (const OS_object_token_t *token, OS_bin_sem_prop_t *bin_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c deleted file mode 100644 index d6dcf2a54..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c +++ /dev/null @@ -1,46 +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-countsem-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-countsem.h" - -/* -** Semaphore API -*/ - -UT_DEFAULT_STUB(OS_CountSemCreate_Impl, (const OS_object_token_t *token, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_CountSemGive_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_CountSemTake_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl, (const OS_object_token_t *token, uint32 msecs)) -UT_DEFAULT_STUB(OS_CountSemDelete_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl, (const OS_object_token_t *token, OS_count_sem_prop_t *count_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c deleted file mode 100644 index 9dc13ff57..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c +++ /dev/null @@ -1,88 +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-file-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-file.h" -#include "os-shared-dir.h" - -/* - * File API abstraction layer - */ - -UT_DEFAULT_STUB(OS_FileOpen_Impl, - (const OS_object_token_t *token, const char *local_path, int32 flags, int32 access_mode)) -UT_DEFAULT_STUB(OS_FileStat_Impl, (const char *local_path, os_fstat_t *filestat)) -UT_DEFAULT_STUB(OS_FileRemove_Impl, (const char *local_path)) -UT_DEFAULT_STUB(OS_FileRename_Impl, (const char *old_path, const char *new_path)) -UT_DEFAULT_STUB(OS_FileChmod_Impl, (const char *local_path, uint32 access_mode)) -UT_DEFAULT_STUB(OS_ShellOutputToFile_Impl, (const OS_object_token_t *token, const char *Cmd)) - -/* - * Directory API abstraction layer - */ -UT_DEFAULT_STUB(OS_DirCreate_Impl, (const char *local_path, uint32 access_mode)) -UT_DEFAULT_STUB(OS_DirOpen_Impl, (const OS_object_token_t *token, const char *local_path)) -UT_DEFAULT_STUB(OS_DirClose_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_DirRead_Impl, (const OS_object_token_t *token, os_dirent_t *dirent)) -UT_DEFAULT_STUB(OS_DirRewind_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_DirRemove_Impl, (const char *local_path)) - -/* - * Stream abstraction layer (applies to sockets and files) - */ -int32 OS_GenericRead_Impl(const OS_object_token_t *token, void *buffer, size_t nbytes, int32 timeout) -{ - int32 Status = UT_DEFAULT_IMPL(OS_GenericRead_Impl); - - if (Status == OS_SUCCESS) - { - Status = UT_Stub_CopyToLocal(UT_KEY(OS_GenericRead_Impl), buffer, nbytes); - } - - return Status; -} - -int32 OS_GenericWrite_Impl(const OS_object_token_t *token, const void *buffer, size_t nbytes, int32 timeout) -{ - int32 Status = UT_DEFAULT_IMPL(OS_GenericWrite_Impl); - - if (Status == OS_SUCCESS) - { - Status = UT_Stub_CopyFromLocal(UT_KEY(OS_GenericWrite_Impl), (const uint8 *)buffer, nbytes); - } - - return Status; -} - -UT_DEFAULT_STUB(OS_GenericSeek_Impl, (const OS_object_token_t *token, int32 offset, uint32 whence)) -UT_DEFAULT_STUB(OS_GenericClose_Impl, (const OS_object_token_t *token)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c deleted file mode 100644 index fedb8593b..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c +++ /dev/null @@ -1,45 +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-loader-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" -#include "os-shared-module.h" - -/* - * Module Loader API - */ -UT_DEFAULT_STUB(OS_ModuleLoad_Impl, (const OS_object_token_t *token, const char *translated_path)) -UT_DEFAULT_STUB(OS_ModuleUnload_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_ModuleGetInfo_Impl, (const OS_object_token_t *token, OS_module_prop_t *module_prop)) -UT_DEFAULT_STUB(OS_GlobalSymbolLookup_Impl, (cpuaddr * SymbolAddress, const char *SymbolName)) -UT_DEFAULT_STUB(OS_ModuleSymbolLookup_Impl, - (const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName)) -UT_DEFAULT_STUB(OS_SymbolTableDump_Impl, (const char *filename, size_t size_limit)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c deleted file mode 100644 index f106785f4..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c +++ /dev/null @@ -1,45 +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-mutex-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-mutex.h" - -/* -** Mutex API -*/ - -UT_DEFAULT_STUB(OS_MutSemCreate_Impl, (const OS_object_token_t *token, uint32 options)) -UT_DEFAULT_STUB(OS_MutSemGive_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_MutSemTake_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_MutSemDelete_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl, (const OS_object_token_t *token, OS_mut_sem_prop_t *mut_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c deleted file mode 100644 index f797457e7..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c +++ /dev/null @@ -1,67 +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-network-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" -#include "os-shared-network.h" -#include "os-shared-sockets.h" - -/* - * Sockets API abstraction layer - */ -UT_DEFAULT_STUB(OS_SocketOpen_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_SocketClose_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_SocketBind_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr)) -UT_DEFAULT_STUB(OS_SocketAccept_Impl, (const OS_object_token_t *sock_token, const OS_object_token_t *conn_token, - OS_SockAddr_t *Addr, int32 timeout)) -UT_DEFAULT_STUB(OS_SocketConnect_Impl, (const OS_object_token_t *token, const OS_SockAddr_t *Addr, int32 timeout)) -UT_DEFAULT_STUB(OS_SocketRecvFrom_Impl, - (const OS_object_token_t *token, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout)) -UT_DEFAULT_STUB(OS_SocketSendTo_Impl, - (const OS_object_token_t *token, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr)) -UT_DEFAULT_STUB(OS_SocketGetInfo_Impl, (const OS_object_token_t *token, OS_socket_prop_t *sock_prop)) - -UT_DEFAULT_STUB(OS_SocketAddrInit_Impl, (OS_SockAddr_t * Addr, OS_SocketDomain_t Domain)) -UT_DEFAULT_STUB(OS_SocketAddrToString_Impl, (char *buffer, size_t buflen, const OS_SockAddr_t *Addr)) -UT_DEFAULT_STUB(OS_SocketAddrGetPort_Impl, (uint16 * PortNum, const OS_SockAddr_t *Addr)) -UT_DEFAULT_STUB(OS_SocketAddrFromString_Impl, (OS_SockAddr_t * Addr, const char *string)) -UT_DEFAULT_STUB(OS_SocketAddrSetPort_Impl, (OS_SockAddr_t * Addr, uint16 PortNum)) -UT_DEFAULT_STUB(OS_NetworkGetHostName_Impl, (char *host_name, size_t name_len)) - -int32 OS_NetworkGetID_Impl(int32 *IdBuf) -{ - int32 Status = UT_DEFAULT_IMPL(OS_NetworkGetID_Impl); - if (Status == 0) - { - *IdBuf = 42; - } - return Status; -} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c deleted file mode 100644 index 238a8831f..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c +++ /dev/null @@ -1,46 +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-queue-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-queue.h" - -/* -** Message Queue API -*/ - -UT_DEFAULT_STUB(OS_QueueCreate_Impl, (const OS_object_token_t *token, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueDelete_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_QueueGet_Impl, - (const OS_object_token_t *token, void *data, size_t size, size_t *size_copied, int32 timeout)) -UT_DEFAULT_STUB(OS_QueuePut_Impl, (const OS_object_token_t *token, const void *data, size_t size, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueGetInfo_Impl, (const OS_object_token_t *token, OS_queue_prop_t *queue_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c deleted file mode 100644 index 4b8cff505..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c +++ /dev/null @@ -1,52 +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-select-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" -#include "os-shared-select.h" - -int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), token); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), SelectFlags); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), msecs); - - return UT_DEFAULT_IMPL(OS_SelectSingle_Impl); -} - -int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) -{ - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), ReadSet); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), WriteSet); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), msecs); - - return UT_DEFAULT_IMPL(OS_SelectMultiple_Impl); -} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-error-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/osapi-error-impl-stubs.c rename to src/unit-test-coverage/ut-stubs/src/osapi-shared-error-impl-table-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-stubs.c rename to src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-table-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c deleted file mode 100644 index fd3dd43d2..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c +++ /dev/null @@ -1,73 +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-task-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" - -#include "os-shared-task.h" -#include "osapi-idmap.h" - -/* -** Task API -*/ -UT_DEFAULT_STUB(OS_TaskMatch_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_TaskDetach_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_TaskCreate_Impl, (const OS_object_token_t *token, uint32 flags)) -UT_DEFAULT_STUB(OS_TaskDelete_Impl, (const OS_object_token_t *token)) -void OS_TaskExit_Impl(void) -{ - UT_DEFAULT_IMPL(OS_TaskExit_Impl); -} - -UT_DEFAULT_STUB(OS_TaskDelay_Impl, (uint32 millisecond)) -UT_DEFAULT_STUB(OS_TaskSetPriority_Impl, (const OS_object_token_t *token, osal_priority_t new_priority)) -osal_id_t OS_TaskGetId_Impl(void) -{ - int32 status; - osal_id_t id; - - status = UT_DEFAULT_IMPL_RC(OS_TaskGetId_Impl, 1); - - /* convert the int32 status value to an osal_id_t - - * (this assumes the types are compatible) */ - id = OS_ObjectIdFromInteger(status); - - return id; -} -UT_DEFAULT_STUB(OS_TaskGetInfo_Impl, (const OS_object_token_t *token, OS_task_prop_t *task_prop)) -UT_DEFAULT_STUB(OS_TaskRegister_Impl, (osal_id_t global_task_id)) - -bool OS_TaskIdMatchSystemData_Impl(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj) -{ - return UT_DEFAULT_IMPL(OS_TaskIdMatchSystemData_Impl); -} - -UT_DEFAULT_STUB(OS_TaskValidateSystemData_Impl, (const void *sysdata, size_t sysdata_size)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c deleted file mode 100644 index f04c150ca..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c +++ /dev/null @@ -1,59 +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-timer-impl-stubs.c - * \ingroup ut-stubs - * \author joseph.p.hickey@nasa.gov - * - */ - -#include -#include -#include -#include - -#include "utstubs.h" -#include "os-shared-timebase.h" -#include "os-shared-clock.h" - -/* -** OS Time/Tick related API -*/ -UT_DEFAULT_STUB(OS_TimeBaseCreate_Impl, (const OS_object_token_t *token)) -UT_DEFAULT_STUB(OS_TimeBaseSet_Impl, (const OS_object_token_t *token, uint32 start_time, uint32 interval_time)) -UT_DEFAULT_STUB(OS_TimeBaseDelete_Impl, (const OS_object_token_t *token)) -void OS_TimeBaseLock_Impl(const OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_TimeBaseLock_Impl); -} - -void OS_TimeBaseUnlock_Impl(const OS_object_token_t *token) -{ - UT_DEFAULT_IMPL(OS_TimeBaseUnlock_Impl); -} - -UT_DEFAULT_STUB(OS_TimeBaseGetInfo_Impl, (const OS_object_token_t *token, OS_timebase_prop_t *timer_prop)) - -/* - * Clock API low-level handlers - */ -UT_DEFAULT_STUB(OS_GetLocalTime_Impl, (OS_time_t * time_struct)) -UT_DEFAULT_STUB(OS_SetLocalTime_Impl, (const OS_time_t *time_struct)) diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index ec994c992..b97b2edd1 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -52,7 +52,9 @@ set(VXWORKS_COVERAGE_LINK_LIST ut_vxworks_impl_stubs ut_bsp_impl_stubs ut_osapi_impl_stubs + ut_osapi_init_stubs ut_osapi_shared_stubs + ut_osapi_table_stubs ut_osapi_stubs ut_libc_stubs ) diff --git a/src/ut-stubs/osapi-file-stubs.c b/src/ut-stubs/osapi-file-stubs.c index 4b0f30adf..75044c8ec 100644 --- a/src/ut-stubs/osapi-file-stubs.c +++ b/src/ut-stubs/osapi-file-stubs.c @@ -105,14 +105,14 @@ int32 OS_FileOpenCheck(const char *Filename) * Generated stub function for OS_OpenCreate() * ---------------------------------------------------- */ -int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) +int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access_mode) { 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_AddParam(OS_OpenCreate, int32, access_mode); UT_GenStub_Execute(OS_OpenCreate, Basic, UT_DefaultHandler_OS_OpenCreate); @@ -162,12 +162,12 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 * Generated stub function for OS_chmod() * ---------------------------------------------------- */ -int32 OS_chmod(const char *path, uint32 access) +int32 OS_chmod(const char *path, uint32 access_mode) { UT_GenStub_SetupReturnBuffer(OS_chmod, int32); UT_GenStub_AddParam(OS_chmod, const char *, path); - UT_GenStub_AddParam(OS_chmod, uint32, access); + UT_GenStub_AddParam(OS_chmod, uint32, access_mode); UT_GenStub_Execute(OS_chmod, Basic, NULL); From 479c02167399331b25539ca1e4746e6fbf59e836 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 27 Apr 2021 09:34:53 -0400 Subject: [PATCH 09/12] Fix #969, socket accept using incorrect record The OS_SocketAccept call was using the incorrect token, using the server/acceptor socket when it should have used the connection socket. The bug overwrote data in the acceptor socket, but it would only cause an issue when the user attempted to use the server socket to accept a second connection, but the tests only performed a single connection. This also improves the network-api-test to do multiple connections, re-using the same acceptor socket between them. --- src/os/shared/src/osapi-sockets.c | 2 +- src/tests/network-api-test/network-api-test.c | 327 +++++++++++------- 2 files changed, 202 insertions(+), 127 deletions(-) diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index 9068107b9..a62d4e14c 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -266,7 +266,7 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t * if (return_code == OS_SUCCESS) { conn_record = OS_OBJECT_TABLE_GET(OS_global_stream_table, conn_token); - conn = OS_OBJECT_TABLE_GET(OS_stream_table, sock_token); + conn = OS_OBJECT_TABLE_GET(OS_stream_table, conn_token); /* Incr the refcount to record the fact that an operation is pending on this */ memset(conn, 0, sizeof(OS_stream_internal_record_t)); diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index d2689bdff..af8225552 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -34,6 +34,12 @@ #define UT_EXIT_LOOP_MAX 100 +/* + * Number of client->server connections to create. + * This tests that the server socket can accept multiple connections. + */ +#define UT_STREAM_CONNECTION_COUNT 4 + osal_id_t s_task_id; osal_id_t p1_socket_id; osal_id_t p2_socket_id; @@ -45,6 +51,8 @@ OS_SockAddr_t s_addr; OS_SockAddr_t c_addr; bool networkImplemented = true; +char ServerFn_ErrorString[128]; + /***************************************************************************** * * Datagram Network Functional Test Setup @@ -406,20 +414,9 @@ void Server_Fn(void) osal_id_t connsock_id = OS_OBJECT_ID_UNDEFINED; uint32 iter; OS_SockAddr_t addr; - char Buf_rcv_s[4] = {0}; char Buf_trans[8] = {0}; uint8 Buf_each_char_s[256] = {0}; - - /* Accept incoming connections */ - OS_SocketAccept(s_socket_id, &connsock_id, &addr, OS_PEND); - - /* Recieve incoming data from client*/ - OS_TimedRead(connsock_id, Buf_rcv_s, sizeof(Buf_rcv_s), 10); - - /* Transform the incoming data and send it back to client */ - strcpy(Buf_trans, "uvw"); - strcat(Buf_trans, Buf_rcv_s); - OS_TimedWrite(connsock_id, Buf_trans, sizeof(Buf_trans), 10); + int32 Status; /* Send all 256 chars to client */ for (iter = 0; iter < 256; iter++) @@ -427,10 +424,61 @@ void Server_Fn(void) Buf_each_char_s[iter] = iter; } - OS_TimedWrite(connsock_id, Buf_each_char_s, sizeof(Buf_each_char_s), 10); + iter = 0; + while (iter < UT_STREAM_CONNECTION_COUNT) + { + ++iter; + + /* Accept incoming connections */ + Status = OS_SocketAccept(s_socket_id, &connsock_id, &addr, OS_PEND); + if (Status != OS_SUCCESS) + { + snprintf(ServerFn_ErrorString, sizeof(ServerFn_ErrorString), "OS_SocketAccept() return code=%d", + (int)Status); + break; + } + + /* Recieve incoming data from client (should be exactly 4 bytes) */ + Status = OS_TimedRead(connsock_id, Buf_trans, sizeof(Buf_trans), 10); + if (Status != 4) + { + snprintf(ServerFn_ErrorString, sizeof(ServerFn_ErrorString), "OS_TimedRead() return code=%d", (int)Status); + break; + } + + /* Send back to client: + * 1. uint32 value indicating number of connections so far (4 bytes) + * 2. Original value recieved above (4 bytes) + * 3. String of all possible 8-bit chars [0-255] (256 bytes) + */ + Status = OS_TimedWrite(connsock_id, &iter, sizeof(iter), 10); + if (Status != sizeof(iter)) + { + snprintf(ServerFn_ErrorString, sizeof(ServerFn_ErrorString), "OS_TimedWrite(uint32) return code=%d", + (int)Status); + break; + } + + Status = OS_TimedWrite(connsock_id, Buf_trans, 4, 10); + if (Status != 4) + { + snprintf(ServerFn_ErrorString, sizeof(ServerFn_ErrorString), "OS_TimedWrite(Buf_trans) return code=%d", + (int)Status); + break; + } + + Status = OS_TimedWrite(connsock_id, Buf_each_char_s, sizeof(Buf_each_char_s), 10); + if (Status != sizeof(Buf_each_char_s)) + { + snprintf(ServerFn_ErrorString, sizeof(ServerFn_ErrorString), + "OS_TimedWrite(Buf_each_char_s) return code=%d", (int)Status); + break; + } + + OS_close(connsock_id); + } OS_close(s_socket_id); - OS_close(connsock_id); } /* end Server_Fn */ @@ -451,14 +499,23 @@ void TestStreamNetworkApi(void) OS_task_prop_t taskprop; char Buf_rcv_c[4] = {0}; char Buf_send_c[4] = {0}; - char Buf_rcv_trans[8] = {0}; - char Buf_expec_trans[8] = {0}; uint8 Buf_each_expected[256] = {0}; uint8 Buf_each_char_rcv[256] = {0}; + /* Init the char buffer */ + for (iter = 0; iter < 256; iter++) + { + Buf_each_expected[iter] = iter; + } + /* - * Set up a server + * NOTE: The server cannot directly use UtAssert because the library is not thread-safe + * If the server task encounters an error, it will write the string to this buffer, and it + * will be reported at the end of this routine. + * + * Be sure it is empty to start with. */ + memset(ServerFn_ErrorString, 0, sizeof(ServerFn_ErrorString)); /* Open a server socket */ s_socket_id = OS_OBJECT_ID_UNDEFINED; @@ -493,13 +550,15 @@ void TestStreamNetworkApi(void) * Set up a client */ - /* Open a client socket */ - expected = OS_SUCCESS; - c_socket_id = OS_OBJECT_ID_UNDEFINED; + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ - actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(c_socket_id), "c_socket_id (%lu) != 0", OS_ObjectIdToInteger(c_socket_id)); + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); /* Initialize client address */ actual = OS_SocketAddrInit(&c_addr, OS_SocketDomain_INET); @@ -514,113 +573,123 @@ void TestStreamNetworkApi(void) UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection + * Connect to a server - this is done in a loop + * to confirm a server socket can be re-used for multiple clients */ - - /* Create a server task/thread */ - status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - /* - * Test for invalid input parameters - */ - - /* OS_TimedRead */ - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_TimedRead(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_INVALID_POINTER; - actual = OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_ERROR_TIMEOUT; - actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - /* OS_TimedWrite */ - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_TimedWrite(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_INVALID_POINTER; - actual = OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - /* OS_SocketAccept */ - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, NULL, NULL, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, NULL, &temp_addr, 10); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, &temp_id, NULL, 10); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketConnect */ - expected = OS_INVALID_POINTER; - actual = OS_SocketConnect(c_socket_id, NULL, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketConnect(c_socket_id, &s_addr, 0); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketConnect(temp_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - /* - * Once connection is made between - * server and client, transfer data - */ - - /* Send data to server to be transformed and sent back */ - strcpy(Buf_send_c, "xyz"); - expected = sizeof(Buf_send_c); - actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - /* Recieve back transformed data from server*/ - expected = sizeof(Buf_expec_trans); - strcpy(Buf_expec_trans, "uvwxyz"); - - actual = OS_TimedRead(c_socket_id, Buf_rcv_trans, sizeof(Buf_rcv_trans), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - UtAssert_True(strcmp(Buf_rcv_trans, Buf_expec_trans) == 0, "Buf_rcv_trans (%s) == Buf_expected (%s)", - Buf_rcv_trans, Buf_expec_trans); - - /* Recieve all 256 chars from server one at a time */ - expected = sizeof(Buf_each_char_rcv); - actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - /* Verify all 256 chars received */ - for (iter = 0; iter < 256; iter++) + iter = 0; + while (iter < UT_STREAM_CONNECTION_COUNT) { - Buf_each_expected[iter] = iter; + /* Open a client socket */ + expected = OS_SUCCESS; + c_socket_id = OS_OBJECT_ID_UNDEFINED; + + actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(c_socket_id), "c_socket_id (%lu) != 0", OS_ObjectIdToInteger(c_socket_id)); + + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Test for invalid input parameters - + * This is done after valid connection when the c_socket_id is valid, + * but it only needs to be done once, so only do this on the first pass. + */ + if (iter == 0) + { + /* OS_TimedRead */ + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_TimedRead(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_ERROR_TIMEOUT; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + /* OS_TimedWrite */ + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_TimedWrite(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + /* OS_SocketAccept */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, NULL, NULL, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, NULL, &temp_addr, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, &temp_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketConnect */ + expected = OS_INVALID_POINTER; + actual = OS_SocketConnect(c_socket_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketConnect(c_socket_id, &s_addr, 0); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", + (long)actual); + + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_SocketConnect(temp_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INVALID_ID", (long)actual); + } + + /* + * Once connection is made between + * server and client, transfer data + */ + ++iter; + snprintf(Buf_send_c, sizeof(Buf_send_c), "%03x", (iter + 0xabc) & 0xfff); + + /* Send data to server */ + expected = sizeof(Buf_send_c); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + /* Recieve back data from server, first is loop count */ + expected = sizeof(loopcnt); + actual = OS_TimedRead(c_socket_id, &loopcnt, sizeof(loopcnt), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + UtAssert_UINT32_EQ(iter, loopcnt); + + /* Recieve back data from server, next is original string */ + expected = sizeof(Buf_rcv_c); + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + UtAssert_True(strcmp(Buf_send_c, Buf_rcv_c) == 0, "Buf_rcv_c (%s) == Buf_send_c (%s)", Buf_rcv_c, + Buf_send_c); + + /* Recieve back data from server, next is 8-bit charset */ + expected = sizeof(Buf_each_char_rcv); + actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + UtAssert_True(memcmp(Buf_each_expected, Buf_each_char_rcv, sizeof(Buf_each_expected)) == 0, + "buffer content match"); + + /* Server should close the socket, reads will return 0 indicating EOF */ + expected = 0; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + OS_close(c_socket_id); } - UtAssert_True(memcmp(Buf_each_expected, Buf_each_char_rcv, sizeof(Buf_each_expected)) == 0, - "buffer content match"); - - /* Once connection socket is closed, verify that no data is recieved */ - expected = 0; - actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - /* * NOTE: Tests for invalid and other nominal input parameters * to some of the network functions being called here are already @@ -635,6 +704,12 @@ void TestStreamNetworkApi(void) loopcnt++; } UtAssert_True(loopcnt < UT_EXIT_LOOP_MAX, "Task exited after %ld iterations", (long)loopcnt); + + /* Check that the server function did NOT Report any errors */ + if (ServerFn_ErrorString[0] != 0) + { + UtAssert_Failed("Server_Fn(): %s", ServerFn_ErrorString); + } } } /* end TestStreamNetworkApi */ From dcb9f8323cacd89daa66499b083a999361863771 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 27 Apr 2021 11:25:09 -0400 Subject: [PATCH 10/12] Fix #970, update documentation for read/write Update the API documentation for OS_read/write/TimedRead/TimedWrite. Clarify that zero will be returned on EOF condition, and in the case of the timed API calls, the OS_ERR_TIMEOUT status code will be returned if the timeout expired without the handle becoming readable/writable during that time. This is intended to allow the caller to differentiate between a handle which is in a state where it cannot read/write data (e.g. at EOF, or a pipe/socket with remote end closed) and handle which is simply idle or busy. --- src/os/inc/osapi-file.h | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/os/inc/osapi-file.h b/src/os/inc/osapi-file.h index 185cc36ff..0b05b1df6 100644 --- a/src/os/inc/osapi-file.h +++ b/src/os/inc/osapi-file.h @@ -160,6 +160,9 @@ int32 OS_close(osal_id_t filedes); * * Reads up to nbytes from a file, and puts them into buffer. * + * If the file position is at the end of file (or beyond, if the OS allows) then this + * function will return 0. + * * @param[in] filedes The handle ID to operate on * @param[out] buffer Storage location for file data * @param[in] nbytes Maximum number of bytes to read @@ -171,6 +174,7 @@ int32 OS_close(osal_id_t filedes); * @retval #OS_INVALID_POINTER if buffer is a null pointer * @retval #OS_ERROR if OS call failed * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * @retval 0 if at end of file/stream data */ int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes); @@ -192,6 +196,7 @@ int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes); * @retval #OS_INVALID_POINTER if buffer is NULL * @retval #OS_ERROR if OS call failed * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * @retval 0 if file/stream cannot accept any more data */ int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes); @@ -201,28 +206,37 @@ int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes); * * This implements a time-limited read and is primarily intended for use with * sockets but may also work with any other stream-like resource that the underlying - * OS supports. + * OS supports, such as pipes or special devices. * * If data is immediately available on the file/socket, this will return that data * along with the actual number of bytes that were immediately available. It will * not block. * - * If no data is immediately available, this will wait up to the given timeout for + * If the file position is at the end of file or end of stream data (e.g. if the remote + * end has closed the connection), then this function will immediately return 0 without + * blocking for the timeout period. + * + * If no data is immediately available, but the underlying resource/stream is still + * connected to a peer, this will wait up to the given timeout for additional * data to appear. If no data appears within the timeout period, then this returns - * an error code (not zero). + * the #OS_ERROR_TIMEOUT status code. This allows the caller to differentiate + * an open (but idle) socket connection from a connection which has been closed + * by the remote peer. * * In all cases this will return successfully as soon as at least 1 byte of actual * data is available. It will not attempt to read the entire input buffer. * * If an EOF condition occurs prior to timeout, this function returns zero. * - * @param[in] filedes The handle ID to operate on - * @param[in] buffer Source location for file data - * @param[in] nbytes Maximum number of bytes to read - * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) + * @param[in] filedes The handle ID to operate on + * @param[out] buffer Storage location for file data + * @param[in] nbytes Maximum number of bytes to read + * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) * - * @return Byte count on success, zero for timeout, or appropriate error code, - * see @ref OSReturnCodes + * @returns Byte count on success or appropriate error code, see @ref OSReturnCodes + * @retval #OS_ERROR_TIMEOUT if no data became available during timeout period + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * @retval 0 if at end of file/stream data */ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout); @@ -252,8 +266,10 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout * @param[in] nbytes Maximum number of bytes to read * @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever) * - * @return Byte count on success, zero for timeout, or appropriate error code, - * see @ref OSReturnCodes + * @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes + * @retval #OS_ERROR_TIMEOUT if no data became available during timeout period + * @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid + * @retval 0 if file/stream cannot accept any more data */ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout); From 05a20f1b96b6729620da18814b6a793a041b0a01 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 27 Apr 2021 12:59:05 -0400 Subject: [PATCH 11/12] Fix #969, Use UtAssert tool API for count pattern The stream test was sending an 8-bit count pattern to validate the connection, but was not using the provided API to do so. This provides the exact same test but uses the provided API from UtAssert to implement it, rather than duplicating the logic. Notably, this also confirms that the tool functions work as expected, since there were no other OSAL tests using this API. --- src/tests/network-api-test/network-api-test.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index af8225552..e5a02bd37 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -418,11 +418,8 @@ void Server_Fn(void) uint8 Buf_each_char_s[256] = {0}; int32 Status; - /* Send all 256 chars to client */ - for (iter = 0; iter < 256; iter++) - { - Buf_each_char_s[iter] = iter; - } + /* Fill the memory with a count pattern */ + UtMemFill(Buf_each_char_s, sizeof(Buf_each_char_s)); iter = 0; while (iter < UT_STREAM_CONNECTION_COUNT) @@ -499,15 +496,8 @@ void TestStreamNetworkApi(void) OS_task_prop_t taskprop; char Buf_rcv_c[4] = {0}; char Buf_send_c[4] = {0}; - uint8 Buf_each_expected[256] = {0}; uint8 Buf_each_char_rcv[256] = {0}; - /* Init the char buffer */ - for (iter = 0; iter < 256; iter++) - { - Buf_each_expected[iter] = iter; - } - /* * NOTE: The server cannot directly use UtAssert because the library is not thread-safe * If the server task encounters an error, it will write the string to this buffer, and it @@ -679,8 +669,7 @@ void TestStreamNetworkApi(void) expected = sizeof(Buf_each_char_rcv); actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - UtAssert_True(memcmp(Buf_each_expected, Buf_each_char_rcv, sizeof(Buf_each_expected)) == 0, - "buffer content match"); + UtAssert_MemCmpCount(Buf_each_char_rcv, sizeof(Buf_each_char_rcv), "Verify byte count pattern"); /* Server should close the socket, reads will return 0 indicating EOF */ expected = 0; From 9466f3f0e1127cd6ac674a09c0aeabba6ecfbe13 Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Wed, 28 Apr 2021 18:00:15 -0400 Subject: [PATCH 12/12] IC:2021-04-27, Bump to v5.1.0-rc1+dev411 --- README.md | 15 +++++++++++++++ src/os/inc/osapi-version.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5dd1f2e7f..33c3fddc4 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,21 @@ The autogenerated OSAL user's guide can be viewed at