Skip to content

Commit

Permalink
Merge pull request #16 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
Integration Candidate 2020-03-18
  • Loading branch information
astrogeco authored Mar 27, 2020
2 parents f499730 + fd777f3 commit 33efec3
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ sample_lib implements SAMPLE_Function, as an example for how to build and link a

## Version Notes

- 1.1.2: DEVELOPMENT
- Added coverage test and a stub library to facilitate unit test
- Minor updates (see https://github.com/nasa/sample_lib/pull/16)
- 1.1.1: DEVELOPMENT
- Minor updates (see https://github.com/nasa/sample_lib/pull/14)
- **1.1.0 OFFICIAL RELEASE**:
Expand All @@ -25,4 +28,3 @@ As a lab library, extensive testing is not performed prior to release and only m
For best results, submit issues:questions or issues:help wanted requests at https://github.com/nasa/cFS.

Official cFS page: http://cfs.gsfc.nasa.gov

11 changes: 2 additions & 9 deletions fsw/src/sample_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,16 @@
/*************************************************************************
** Includes
*************************************************************************/
#include "sample_lib.h"
#include "sample_lib_version.h"
#include "sample_lib_internal.h"

/* for "strncpy()" */
#include <string.h>

/*************************************************************************
** 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];

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand Down
61 changes: 61 additions & 0 deletions fsw/src/sample_lib_internal.h
Original file line number Diff line number Diff line change
@@ -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 <sample_lib.h>

/*************************************************************************
** 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 */
/************************/
6 changes: 3 additions & 3 deletions fsw/src/sample_lib_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sample_lib_version.h
**
** Purpose:
** Purpose:
** The SAMPLE Lib header file containing version number
**
** Notes:
Expand All @@ -32,10 +32,10 @@

#define SAMPLE_LIB_MAJOR_VERSION 1
#define SAMPLE_LIB_MINOR_VERSION 1
#define SAMPLE_LIB_REVISION 1
#define SAMPLE_LIB_REVISION 2
#define SAMPLE_LIB_MISSION_REV 0


#endif /* _sample_lib_version_h_ */

/************************/
Expand Down
100 changes: 100 additions & 0 deletions unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
$<TARGET_OBJECTS:ut_${TESTNAME}_object>
)

# 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()

Loading

0 comments on commit 33efec3

Please sign in to comment.