From b734bcaebbadce04023131b5c5f93b08833db145 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 21 Nov 2019 11:22:38 -0500 Subject: [PATCH] Fix #9: Add unit test example for sample_lib Implements a coverage test for sample_lib code as well as a stub library to facilitate unit test of external code that calls functions within sample_lib. --- CMakeLists.txt | 6 + fsw/src/sample_lib.c | 11 +- fsw/src/sample_lib_internal.h | 61 ++++++ unit-test/CMakeLists.txt | 100 +++++++++ .../coveragetest/coveragetest_sample_lib.c | 204 ++++++++++++++++++ .../sample_lib_coveragetest_common.h | 77 +++++++ unit-test/inc/OCS_string.h | 44 ++++ unit-test/override_inc/README.txt | 10 + unit-test/override_inc/string.h | 46 ++++ unit-test/override_src/libc_string_stubs.c | 84 ++++++++ ut-stubs/CMakeLists.txt | 23 ++ ut-stubs/sample_lib_stubs.c | 79 +++++++ 12 files changed, 736 insertions(+), 9 deletions(-) create mode 100644 fsw/src/sample_lib_internal.h create mode 100644 unit-test/CMakeLists.txt create mode 100644 unit-test/coveragetest/coveragetest_sample_lib.c create mode 100644 unit-test/coveragetest/sample_lib_coveragetest_common.h create mode 100644 unit-test/inc/OCS_string.h create mode 100644 unit-test/override_inc/README.txt create mode 100644 unit-test/override_inc/string.h create mode 100644 unit-test/override_src/libc_string_stubs.c create mode 100644 ut-stubs/CMakeLists.txt create mode 100644 ut-stubs/sample_lib_stubs.c diff --git a/CMakeLists.txt b/CMakeLists.txt index cb148db..d023093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,3 +13,9 @@ aux_source_directory(fsw/src LIB_SRC_FILES) # Create the app module add_cfe_app(sample_lib ${LIB_SRC_FILES}) +if (ENABLE_UNIT_TESTS) + add_subdirectory(ut-stubs) + add_subdirectory(unit-test) +endif (ENABLE_UNIT_TESTS) + + diff --git a/fsw/src/sample_lib.c b/fsw/src/sample_lib.c index 129a1f5..4f39dbf 100644 --- a/fsw/src/sample_lib.c +++ b/fsw/src/sample_lib.c @@ -28,23 +28,16 @@ /************************************************************************* ** Includes *************************************************************************/ -#include "sample_lib.h" #include "sample_lib_version.h" +#include "sample_lib_internal.h" /* for "strncpy()" */ #include -/************************************************************************* -** Macro Definitions -*************************************************************************/ - -#define SAMPLE_LIB_BUFFER_SIZE 16 - - /************************************************************************* ** Private Data Structures *************************************************************************/ -static char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; +char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ diff --git a/fsw/src/sample_lib_internal.h b/fsw/src/sample_lib_internal.h new file mode 100644 index 0000000..f7753cc --- /dev/null +++ b/fsw/src/sample_lib_internal.h @@ -0,0 +1,61 @@ +/************************************************************************ +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: sample_lib_internal.h +** +** Purpose: +** An example of an internal (private) header file for SAMPLE Lib +** +** Notes: +** +*************************************************************************/ +#ifndef _sample_lib_internal_h_ +#define _sample_lib_internal_h_ + +/* Include all external/public definitions */ +#include + +/************************************************************************* +** Macro Definitions +*************************************************************************/ + +#define SAMPLE_LIB_BUFFER_SIZE 16 + + +/************************************************************************* +** Internal Data Structures +*************************************************************************/ +extern char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; + +/************************************************************************* +** Function Declarations +*************************************************************************/ + +/** + * Library initialization routine/entry point + */ +int32 SAMPLE_LibInit(void); + + +#endif /* _sample_lib_internal_h_ */ + +/************************/ +/* End of File Comment */ +/************************/ diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt new file mode 100644 index 0000000..e101ce8 --- /dev/null +++ b/unit-test/CMakeLists.txt @@ -0,0 +1,100 @@ +################################################################## +# +# Coverage Unit Test build recipe +# +# This CMake file contains the recipe for building the sample unit tests. +# It is invoked from the parent directory when unit tests are enabled. +# +################################################################## + +# +# NOTE on the subdirectory structures here: +# +# - "inc" provides local header files shared between the coveragetest, +# wrappers, and overrides source code units +# - "coveragetest" contains source code for the actual unit test cases +# The primary objective is to get line/path coverage on the FSW +# code units. +# - "wrappers" contains wrappers for the FSW code. The wrapper adds +# any UT-specific scaffolding to facilitate the coverage test, and +# includes the unmodified FSW source file. +# - "overrides" provides implementation of LOCAL stub functions to +# that replace external calls. This is for use cases where the +# normal link-time replacements is not sufficient/possible, and +# a different implementation needs to be called at compile-time +# instead. +# +# IMPORTANT: Most UT test cases do not need the "overrides" feature, +# it is primarily for cases where a C library function needs to be +# overridden. It's use-case is included here as an example. + + +set(UT_NAME sample_lib) + +# Use the UT_Assert public API +# This is also allowed to directly include files in the "fsw/src" +# directory that are normally private to the implementation +include_directories(${osal_MISSION_DIR}/ut_assert/inc) +include_directories(${PROJECT_SOURCE_DIR}/fsw/src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +# The "overrides" target provides replacements for C library +# calls that cannot be handled at link time. Most UT test +# cases will NOT need this feature. +add_library(ut_${UT_NAME}_overrides STATIC + override_src/libc_string_stubs.c +) + +# The LIB_SRC_FILES variable should contain the list of source files for the FSW build +# This assumes a 1:1 relationship between FSW source units and coverage tests +# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit +# Although sample_lib has only one source file, this is done in a loop such that +# the general pattern should work for several files as well. +foreach(SRCFILE ${LIB_SRC_FILES}) + get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) + + set(TESTNAME "${UT_NAME}-${UNITNAME}") + set(UNIT_SOURCE_FILE "${CFE_SAMPLE_LIB_SOURCE_DIR}/fsw/src/${UNITNAME}.c") + set(TESTCASE_SOURCE_FILE "coveragetest/coveragetest_${UNITNAME}.c") + + # Compile the source unit under test as a OBJECT + add_library(ut_${TESTNAME}_object OBJECT + ${UNIT_SOURCE_FILE} + ) + + # Apply the UT_C_FLAGS to the units under test + # This should enable coverage analysis on platforms that support this + set_target_properties(ut_${TESTNAME}_object PROPERTIES + COMPILE_FLAGS "${UT_C_FLAGS}") + + # For this object target only, the "override" includes should be injected + # into the include path BEFORE any other include path. This is so the + # override will take precedence over any system-provided version. + target_include_directories(ut_${TESTNAME}_object PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/override_inc) + + # Compile a test runner application, which contains the + # actual coverage test code (test cases) and the unit under test + add_executable(${TESTNAME}-testrunner + ${TESTCASE_SOURCE_FILE} + $ + ) + + # This also needs to be linked with UT_C_FLAGS (for coverage) + set_target_properties(${TESTNAME}-testrunner PROPERTIES + LINK_FLAGS "${UT_C_FLAGS}") + + # This is also linked with any other stub libraries needed, + # as well as the UT assert framework + target_link_libraries(${TESTNAME}-testrunner + ut_${UT_NAME}_stubs + ut_${UT_NAME}_overrides + ut_cfe-core_stubs + ut_assert + ) + + # Add it to the set of tests to run as part of "make test" + add_test(${TESTNAME} ${TESTNAME}-testrunner) + +endforeach() + diff --git a/unit-test/coveragetest/coveragetest_sample_lib.c b/unit-test/coveragetest/coveragetest_sample_lib.c new file mode 100644 index 0000000..a478368 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_lib.c @@ -0,0 +1,204 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: coveragetest_sample_lib.c +** +** Purpose: +** Coverage Unit Test cases for the SAMPLE library +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE library. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ + +#include "sample_lib_coveragetest_common.h" + +/* + * This code needs to access the "override" stubs for string.h, + * as well as the normal system string.h. It is differentiated + * by explicitly specifying the "overrides/" prefix here. + */ +#include +#include +#include + +char UT_TESTBUFFER[] = "SAMPLELIB_UT"; + +/* + * Local test state structure + */ +typedef struct +{ + bool format_string_valid; + bool printf_content_valid; + +} SAMPLE_Function_TestState_t; + + +/* + * A local helper (hook) function for the OS_printf stub provided by OSAL. + * This confirms internal content of the format string and arguments. + */ +static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount, + const UT_StubContext_t *Context, va_list va) +{ + SAMPLE_Function_TestState_t *State = UserObj; + + /* + * The OS_printf() stub passes format string as the argument + * This confirms the whole string; normally this level of test + * detail would not be needed, but this serves as an example + * of how it can be done. + */ + if (Context->ArgCount > 0 && + strcmp(Context->ArgPtr[0], + "SAMPLE_Function called, buffer=\'%s\'\n") == 0) + { + State->format_string_valid = true; + + /* + * The remainder of the OS_printf() arguments are in the va_list + * The first argument should be a pointer to the internal buffer, + * which in this case should match the content of UT_TESTBUFFER + * (because it was overridden as part of the init) + */ + if (strcmp(va_arg(va, const char *), UT_TESTBUFFER) == 0) + { + State->printf_content_valid = true; + } + } + + return 0; +} + + + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ + +void Test_SAMPLE_LibInit(void) +{ + /* + * Test Case For: + * int32 SAMPLE_LibInit( void ) + */ + + /* Set a data buffer for strncpy() + * This overriddes what it would normally do */ + UT_SetDataBuffer(UT_KEY(OCS_strncpy), UT_TESTBUFFER, + sizeof (UT_TESTBUFFER), false); + + /* nominal case should return SUCCESS */ + UT_TEST_FUNCTION_RC(SAMPLE_LibInit(), CFE_SUCCESS); + + /* A simple confirmation that "OS_printf" was invoked + * exactly 1 time during the previous function call */ + UtAssert_True(UT_GetStubCount(UT_KEY(OS_printf)) == 1, "OS_printf called"); + + /* + * Test that the internal buffer contains the right thing + * In this case, it is the locally-provided (override) content + * + * This requires use of the local accessor routine to get to the + * internal buffer, which is declared "static" + */ + UtAssert_StrCmp(UT_TESTBUFFER, SAMPLE_Buffer, + "Internal buffer content valid"); + + /* Test failure of the underlying library call */ + UT_SetForceFail(UT_KEY(OCS_strncpy), -1); + + /* off-nominal case should return CFE_STATUS_NOT_IMPLEMENTED */ + UT_TEST_FUNCTION_RC(SAMPLE_LibInit(), CFE_STATUS_NOT_IMPLEMENTED); +} + +void Test_SAMPLE_Function(void) +{ + /* + * Test Case For: + * void SAMPLE_Function( void ) + */ + SAMPLE_Function_TestState_t state; + + /* + * This function has no conditionals, but it does call + * OS_printf with a string. This can be tested in UT. + */ + memset(&state, 0, sizeof(state)); + UT_SetVaHookFunction(UT_KEY(OS_printf), UT_printf_hook, &state); + + /* + * Invoke the actual function + */ + SAMPLE_Function(); + + /* + * Make sure that the extra conditions checked by the + * hook function were satisfied + */ + UtAssert_True(state.format_string_valid, "OS_printf format string test"); + UtAssert_True(state.printf_content_valid, "OS_printf content test"); +} + + + +/* + * Setup function prior to every test + */ +void Sample_UT_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Teardown function after every test + */ +void Sample_UT_TearDown(void) +{ + +} + + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_LibInit); + ADD_TEST(SAMPLE_Function); +} + + + + + diff --git a/unit-test/coveragetest/sample_lib_coveragetest_common.h b/unit-test/coveragetest/sample_lib_coveragetest_common.h new file mode 100644 index 0000000..1d2cf83 --- /dev/null +++ b/unit-test/coveragetest/sample_lib_coveragetest_common.h @@ -0,0 +1,77 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: sample_lib_coveragetest_common.h +** +** Purpose: +** Common definitions for all sample_lib coverage tests +*/ + +#ifndef _SAMPLE_LIB_COVERAGETEST_COMMON_H_ +#define _SAMPLE_LIB_COVERAGETEST_COMMON_H_ + +/* + * Includes + */ + +#include +#include +#include + +/* + * Use the public API/definitions from CFE and SAMPLE LIB + */ +#include +#include + +/* + * Macro to call a function and check its int32 return code + * + * This just simplifies the use of UtAssert_True() for the + * frequent case where a function needs to be called and + * an int32 return code needs to be tested. + */ +#define UT_TEST_FUNCTION_RC(func,exp) \ +{ \ + int32 rcexp = exp; \ + int32 rcact = func; \ + UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", \ + #func, (long)rcact, #exp, (long)rcexp); \ +} + +/* + * Macro to add a test case to the list of tests to execute + * This just simplifies the use of UtTest_Add() + */ +#define ADD_TEST(test) UtTest_Add((Test_ ## test),Sample_UT_Setup,Sample_UT_TearDown, #test) + +/* + * Setup function prior to every test + */ +void Sample_UT_Setup(void); + +/* + * Teardown function after every test + */ +void Sample_UT_TearDown(void); + +#endif + diff --git a/unit-test/inc/OCS_string.h b/unit-test/inc/OCS_string.h new file mode 100644 index 0000000..165be43 --- /dev/null +++ b/unit-test/inc/OCS_string.h @@ -0,0 +1,44 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: string.h +** +** Purpose: +** "Override" file for the system string.h file +** +** Notes: +** This would provide stub functions for those normally found +** in string.h. In this case, it is only providing a stub for +** strncpy(). +*/ + +#ifndef _STUB_STRING_H_ +#define _STUB_STRING_H_ + +/* ----------------------------------------- */ +/* prototypes normally declared in string.h */ +/* ----------------------------------------- */ + +extern char *OCS_strncpy (char * dest, const char * src, unsigned long size); + + +#endif /* _STUB_STRING_H_ */ + diff --git a/unit-test/override_inc/README.txt b/unit-test/override_inc/README.txt new file mode 100644 index 0000000..29746b4 --- /dev/null +++ b/unit-test/override_inc/README.txt @@ -0,0 +1,10 @@ +OVERRIDE DIRECTORY FOR UNIT TESTS + +This directory is inserted into the compilation include path prior to any other +include paths when compiling FSW code modules for unit testing. This may provide +alternate definitions of any dependent header files, in case the UT needs to +be directed to alternate implementations that cannot be substituted at link time. +For instance, this may provide alternate definitions of the C library calls. + +This directory may be empty if the UT does not require this feature. + diff --git a/unit-test/override_inc/string.h b/unit-test/override_inc/string.h new file mode 100644 index 0000000..9f499e6 --- /dev/null +++ b/unit-test/override_inc/string.h @@ -0,0 +1,46 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: string.h +** +** Purpose: +** "Override" file for the system string.h file +** +** Notes: +** This would provide stub functions for those normally found +** in string.h. In this case, it is only providing a stub for +** strncpy(). +*/ + +#ifndef _OVERRIDE_STRING_H_ +#define _OVERRIDE_STRING_H_ + +#include + +/* ----------------------------------------- */ +/* mappings for declarations in string.h */ +/* ----------------------------------------- */ + +#define strncpy OCS_strncpy + + +#endif /* _OVERRIDE_STRING_H_ */ + diff --git a/unit-test/override_src/libc_string_stubs.c b/unit-test/override_src/libc_string_stubs.c new file mode 100644 index 0000000..8979188 --- /dev/null +++ b/unit-test/override_src/libc_string_stubs.c @@ -0,0 +1,84 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: libc_string_stubs.c +** +** Purpose: +** Demonstrates the concept of compile-time replacement +** for C library calls. +** +** This provides the implementation of the "OCS_strncpy" +** function, which is the stub for the C library strncpy call. +** +** Notes: +** For most Unit tests this is _NOT_ necessary. Whenever +** possible, FSW code should only call CFE/OSAL/PSP code for +** which there are already stubs available and the the +** replacements can be made transparently at link time. +*/ + +/* + * Note - these are the _real_ system headers here + * as the "overrides" dir is _not_ part of the include path here + */ +#include +#include +#include +#include "utstubs.h" + +/* + * This is for the prototype of the "OCS_strncpy()" function + */ +#include + + +/* ********************************** + * Implementation of OCS_strncpy stub + * **********************************/ +char *OCS_strncpy(char *dst, const char *src, unsigned long size) +{ + int32 Status; + uint32 CopySize; + + Status = UT_DEFAULT_IMPL(OCS_strncpy); + + if (Status != 0) + { + /* + * a "failure" response - + * the real C library would never do this. + */ + return (char*)0; + } + /* + * Demonstrate use of a test-provided local data buffer + * this provides the "real" data that is written to the output + */ + CopySize = UT_Stub_CopyToLocal(UT_KEY(OCS_strncpy), dst, size); + if (CopySize < size) + { + /* clear the remained, as strncpy would */ + memset(&dst[CopySize], 0, size - CopySize); + } + + /* normal response is to return a pointer to the source */ + return dst; +} diff --git a/ut-stubs/CMakeLists.txt b/ut-stubs/CMakeLists.txt new file mode 100644 index 0000000..c48b49f --- /dev/null +++ b/ut-stubs/CMakeLists.txt @@ -0,0 +1,23 @@ +################################################################## +# +# SAMPLE library stub function build recipe +# +# This CMake file contains the recipe for building the stub function +# libraries that correlate with the library public API. This supports +# unit testing of OTHER modules, where the test cases for those modules +# are linked with the stubs supplied here. +# +################################################################## + +# Use the UT assert public headers +include_directories(${osal_MISSION_DIR}/ut_assert/inc) + +# Create a static library containing all stubs. +# +# There should be a 1:1 relationship between application source files +# and the stub files. Each stub file should provide the same set of +# functions that the application source file provides. +add_library(ut_sample_lib_stubs STATIC + sample_lib_stubs.c +) + diff --git a/ut-stubs/sample_lib_stubs.c b/ut-stubs/sample_lib_stubs.c new file mode 100644 index 0000000..a519428 --- /dev/null +++ b/ut-stubs/sample_lib_stubs.c @@ -0,0 +1,79 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://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: sample_lib_stubs.c +** +** Purpose: +** Unit test stubs for the SAMPLE library +** +** Notes: +** A stub function file should be implemented for each +** FSW source code unit. This defines the same functions +** as the public API of the Library. +** +** This is to support testing of OTHER applications which +** depend on / call into this library. The unit test of +** the external application will be linked with this stub +** library, rather than the real implementation. +*/ + +/* + * The stub functions always share the same API header file as the + * main FSW code does. This should define the same functions + * with the same parameters. + */ +#include "sample_lib.h" + +/* + * The "utstubs.h" provides the generic stub framework from UT Assert + */ +#include "utstubs.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Sample Init function stub */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_LibInit(void) +{ + /* + * The UT_DEFAULT_IMPL macro is generally sufficient + * for any call that does not have output parameters + * and returns an integer status code. + * + * The default return value is 0, unless the test + * case configures something different. + */ + return UT_DEFAULT_IMPL(SAMPLE_LibInit); + +}/* End SAMPLE_LibInit */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Sample Lib function stub */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_Function( void ) +{ + return UT_DEFAULT_IMPL(SAMPLE_Function); + +} /* End SAMPLE_Function */ +