From b6deac6f97e09863cedf67bd5b6093ccaaabb42a Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 21 May 2020 10:49:12 -0400 Subject: [PATCH 1/2] Fix #15, Apply standard style --- fsw/public_inc/sample_lib.h | 13 ++++--- fsw/src/sample_lib.c | 33 ++++++++--------- fsw/src/sample_lib_internal.h | 6 ++-- fsw/src/sample_lib_version.h | 10 +++--- .../coveragetest/coveragetest_sample_lib.c | 35 ++++--------------- .../sample_lib_coveragetest_common.h | 16 ++++----- unit-test/inc/OCS_string.h | 4 +-- unit-test/override_inc/string.h | 4 +-- unit-test/override_src/libc_string_stubs.c | 5 ++- ut-stubs/sample_lib_stubs.c | 9 ++--- 10 files changed, 46 insertions(+), 89 deletions(-) diff --git a/fsw/public_inc/sample_lib.h b/fsw/public_inc/sample_lib.h index 60e6d10..187d411 100644 --- a/fsw/public_inc/sample_lib.h +++ b/fsw/public_inc/sample_lib.h @@ -20,7 +20,7 @@ ** ** File: sample_lib.h ** -** Purpose: +** Purpose: ** Specification for the sample library functions. ** *************************************************************************/ @@ -58,21 +58,20 @@ *************************************************************************/ int32 SAMPLE_LibInit(void); - /************************************************************************/ -/** \brief Sample Lib Function -** +/** \brief Sample Lib Function +** ** \par Description ** This is a sample function ** ** \par Assumptions, External Events, and Notes: ** None -** +** ** \return Execution status, see \ref CFEReturnCodes ** -** +** *************************************************************************/ -int32 SAMPLE_Function( void ); +int32 SAMPLE_Function(void); #endif /* _sample_lib_h_ */ diff --git a/fsw/src/sample_lib.c b/fsw/src/sample_lib.c index 4f39dbf..7536590 100644 --- a/fsw/src/sample_lib.c +++ b/fsw/src/sample_lib.c @@ -20,7 +20,7 @@ ** ** File: sample_lib.c ** -** Purpose: +** Purpose: ** Sample CFS library ** *************************************************************************/ @@ -42,7 +42,7 @@ char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* Library Initialization Routine */ -/* cFE requires that a library have an initialization routine */ +/* cFE requires that a library have an initialization routine */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_LibInit(void) @@ -57,37 +57,32 @@ int32 SAMPLE_LibInit(void) * the pointer to the destination buffer, so it should be impossible * for this to ever fail when linked with a compliant C library. */ - if (strncpy(SAMPLE_Buffer, "SAMPLE DATA", sizeof(SAMPLE_Buffer)-1) != - SAMPLE_Buffer) + if (strncpy(SAMPLE_Buffer, "SAMPLE DATA", sizeof(SAMPLE_Buffer) - 1) != SAMPLE_Buffer) { return CFE_STATUS_NOT_IMPLEMENTED; } - + /* ensure termination */ - SAMPLE_Buffer[sizeof(SAMPLE_Buffer)-1] = 0; + SAMPLE_Buffer[sizeof(SAMPLE_Buffer) - 1] = 0; + OS_printf("SAMPLE Lib Initialized. Version %d.%d.%d.%d\n", SAMPLE_LIB_MAJOR_VERSION, SAMPLE_LIB_MINOR_VERSION, + SAMPLE_LIB_REVISION, SAMPLE_LIB_MISSION_REV); - OS_printf ("SAMPLE Lib Initialized. Version %d.%d.%d.%d\n", - SAMPLE_LIB_MAJOR_VERSION, - SAMPLE_LIB_MINOR_VERSION, - SAMPLE_LIB_REVISION, - SAMPLE_LIB_MISSION_REV); - return CFE_SUCCESS; - -}/* End SAMPLE_LibInit */ + +} /* End SAMPLE_LibInit */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* Sample Lib function */ +/* Sample Lib function */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_Function( void ) +int32 SAMPLE_Function(void) { - OS_printf ("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer); + OS_printf("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer); + + return (CFE_SUCCESS); - return(CFE_SUCCESS); - } /* End SAMPLE_Function */ /************************/ diff --git a/fsw/src/sample_lib_internal.h b/fsw/src/sample_lib_internal.h index f7753cc..c674267 100644 --- a/fsw/src/sample_lib_internal.h +++ b/fsw/src/sample_lib_internal.h @@ -20,7 +20,7 @@ ** ** File: sample_lib_internal.h ** -** Purpose: +** Purpose: ** An example of an internal (private) header file for SAMPLE Lib ** ** Notes: @@ -36,8 +36,7 @@ ** Macro Definitions *************************************************************************/ -#define SAMPLE_LIB_BUFFER_SIZE 16 - +#define SAMPLE_LIB_BUFFER_SIZE 16 /************************************************************************* ** Internal Data Structures @@ -53,7 +52,6 @@ extern char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; */ int32 SAMPLE_LibInit(void); - #endif /* _sample_lib_internal_h_ */ /************************/ diff --git a/fsw/src/sample_lib_version.h b/fsw/src/sample_lib_version.h index 3672f7f..052de0d 100644 --- a/fsw/src/sample_lib_version.h +++ b/fsw/src/sample_lib_version.h @@ -29,12 +29,10 @@ #ifndef _sample_lib_version_h_ #define _sample_lib_version_h_ - -#define SAMPLE_LIB_MAJOR_VERSION 1 -#define SAMPLE_LIB_MINOR_VERSION 1 -#define SAMPLE_LIB_REVISION 3 -#define SAMPLE_LIB_MISSION_REV 0 - +#define SAMPLE_LIB_MAJOR_VERSION 1 +#define SAMPLE_LIB_MINOR_VERSION 1 +#define SAMPLE_LIB_REVISION 3 +#define SAMPLE_LIB_MISSION_REV 0 #endif /* _sample_lib_version_h_ */ diff --git a/unit-test/coveragetest/coveragetest_sample_lib.c b/unit-test/coveragetest/coveragetest_sample_lib.c index a478368..c3679e3 100644 --- a/unit-test/coveragetest/coveragetest_sample_lib.c +++ b/unit-test/coveragetest/coveragetest_sample_lib.c @@ -61,13 +61,12 @@ typedef struct } 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) +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; @@ -77,9 +76,7 @@ static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount, * 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) + if (Context->ArgCount > 0 && strcmp(Context->ArgPtr[0], "SAMPLE_Function called, buffer=\'%s\'\n") == 0) { State->format_string_valid = true; @@ -98,8 +95,6 @@ static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount, return 0; } - - /* ********************************************************************************** ** TEST CASE FUNCTIONS @@ -115,8 +110,7 @@ void Test_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); + 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); @@ -132,8 +126,7 @@ void Test_SAMPLE_LibInit(void) * 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"); + UtAssert_StrCmp(UT_TESTBUFFER, SAMPLE_Buffer, "Internal buffer content valid"); /* Test failure of the underlying library call */ UT_SetForceFail(UT_KEY(OCS_strncpy), -1); @@ -170,24 +163,15 @@ void Test_SAMPLE_Function(void) UtAssert_True(state.printf_content_valid, "OS_printf content test"); } - - /* * Setup function prior to every test */ -void Sample_UT_Setup(void) -{ - UT_ResetState(0); -} +void Sample_UT_Setup(void) { UT_ResetState(0); } /* * Teardown function after every test */ -void Sample_UT_TearDown(void) -{ - -} - +void Sample_UT_TearDown(void) {} /* * Register the test cases to execute with the unit test tool @@ -197,8 +181,3 @@ 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 index 1d2cf83..e6cf7ce 100644 --- a/unit-test/coveragetest/sample_lib_coveragetest_common.h +++ b/unit-test/coveragetest/sample_lib_coveragetest_common.h @@ -49,19 +49,18 @@ * 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); \ -} +#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) +#define ADD_TEST(test) UtTest_Add((Test_##test), Sample_UT_Setup, Sample_UT_TearDown, #test) /* * Setup function prior to every test @@ -74,4 +73,3 @@ void Sample_UT_Setup(void); void Sample_UT_TearDown(void); #endif - diff --git a/unit-test/inc/OCS_string.h b/unit-test/inc/OCS_string.h index 165be43..8e85b98 100644 --- a/unit-test/inc/OCS_string.h +++ b/unit-test/inc/OCS_string.h @@ -37,8 +37,6 @@ /* prototypes normally declared in string.h */ /* ----------------------------------------- */ -extern char *OCS_strncpy (char * dest, const char * src, unsigned long size); - +extern char *OCS_strncpy(char *dest, const char *src, unsigned long size); #endif /* _STUB_STRING_H_ */ - diff --git a/unit-test/override_inc/string.h b/unit-test/override_inc/string.h index 9f499e6..abc7cd7 100644 --- a/unit-test/override_inc/string.h +++ b/unit-test/override_inc/string.h @@ -39,8 +39,6 @@ /* mappings for declarations in string.h */ /* ----------------------------------------- */ -#define strncpy OCS_strncpy - +#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 index 8979188..505ff72 100644 --- a/unit-test/override_src/libc_string_stubs.c +++ b/unit-test/override_src/libc_string_stubs.c @@ -49,13 +49,12 @@ */ #include - /* ********************************** * Implementation of OCS_strncpy stub * **********************************/ char *OCS_strncpy(char *dst, const char *src, unsigned long size) { - int32 Status; + int32 Status; uint32 CopySize; Status = UT_DEFAULT_IMPL(OCS_strncpy); @@ -66,7 +65,7 @@ char *OCS_strncpy(char *dst, const char *src, unsigned long size) * a "failure" response - * the real C library would never do this. */ - return (char*)0; + return (char *)0; } /* * Demonstrate use of a test-provided local data buffer diff --git a/ut-stubs/sample_lib_stubs.c b/ut-stubs/sample_lib_stubs.c index a519428..d77087c 100644 --- a/ut-stubs/sample_lib_stubs.c +++ b/ut-stubs/sample_lib_stubs.c @@ -64,16 +64,11 @@ int32 SAMPLE_LibInit(void) */ return UT_DEFAULT_IMPL(SAMPLE_LibInit); -}/* End SAMPLE_LibInit */ +} /* End SAMPLE_LibInit */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* Sample Lib function stub */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_Function( void ) -{ - return UT_DEFAULT_IMPL(SAMPLE_Function); - -} /* End SAMPLE_Function */ - +int32 SAMPLE_Function(void) { return UT_DEFAULT_IMPL(SAMPLE_Function); } /* End SAMPLE_Function */ From 3b5bca17440cd668dfd84d14f128e398bfbd8c4f Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Sat, 23 May 2020 10:45:42 -0400 Subject: [PATCH 2/2] Fix #15, Only inline empty functions --- unit-test/coveragetest/coveragetest_sample_lib.c | 5 ++++- ut-stubs/sample_lib_stubs.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/unit-test/coveragetest/coveragetest_sample_lib.c b/unit-test/coveragetest/coveragetest_sample_lib.c index c3679e3..fef951b 100644 --- a/unit-test/coveragetest/coveragetest_sample_lib.c +++ b/unit-test/coveragetest/coveragetest_sample_lib.c @@ -166,7 +166,10 @@ void Test_SAMPLE_Function(void) /* * Setup function prior to every test */ -void Sample_UT_Setup(void) { UT_ResetState(0); } +void Sample_UT_Setup(void) +{ + UT_ResetState(0); +} /* * Teardown function after every test diff --git a/ut-stubs/sample_lib_stubs.c b/ut-stubs/sample_lib_stubs.c index d77087c..9cdacc9 100644 --- a/ut-stubs/sample_lib_stubs.c +++ b/ut-stubs/sample_lib_stubs.c @@ -71,4 +71,7 @@ int32 SAMPLE_LibInit(void) /* Sample Lib function stub */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_Function(void) { return UT_DEFAULT_IMPL(SAMPLE_Function); } /* End SAMPLE_Function */ +int32 SAMPLE_Function(void) +{ + return UT_DEFAULT_IMPL(SAMPLE_Function); +} /* End SAMPLE_Function */