Skip to content

Commit a34c02e

Browse files
authored
Merge pull request #26 from nasa/fix-8-add-sample-app-tests
Fix #8, Add sample app tests
2 parents a0b5e29 + 7465a6a commit a34c02e

File tree

8 files changed

+834
-4
lines changed

8 files changed

+834
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ add_cfe_app(sample_app fsw/src/sample_app.c)
1313

1414
# Add table
1515
add_cfe_tables(sampleTable fsw/src/sample_table.c)
16+
17+
# If UT is enabled, then add the tests from the subdirectory
18+
# Note that this is an app, and therefore does not provide
19+
# stub functions, as other entities would not typically make
20+
# direct function calls into this application.
21+
if (ENABLE_UNIT_TESTS)
22+
add_subdirectory(unit-test)
23+
endif (ENABLE_UNIT_TESTS)
24+

fsw/src/sample_app.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
#include "sample_table.h"
3535

3636
/* The sample_lib module provides the SAMPLE_Function() prototype */
37-
#include <sample_lib.h>
38-
3937
#include <string.h>
38+
#include "sample_lib.h"
4039

4140
/*
4241
** global data

fsw/src/sample_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
**
3-
** GSC-18128-1, "Core Flight Executive Version 6.6"
3+
** GSC-18128-1, "Core Flight Executive Version 6.7"
44
**
55
** Copyright (c) 2006-2019 United States Government as represented by
66
** the Administrator of the National Aeronautics and Space Administration.

fsw/src/sample_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
**
3-
** GSC-18128-1, "Core Flight Executive Version 6.6"
3+
** GSC-18128-1, "Core Flight Executive Version 6.7"
44
**
55
** Copyright (c) 2006-2019 United States Government as represented by
66
** the Administrator of the National Aeronautics and Space Administration.

unit-test/CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
##################################################################
2+
#
3+
# Coverage Unit Test build recipe
4+
#
5+
# This CMake file contains the recipe for building the sample unit tests.
6+
# It is invoked from the parent directory when unit tests are enabled.
7+
#
8+
##################################################################
9+
10+
#
11+
#
12+
# NOTE on the subdirectory structures here:
13+
#
14+
# - "inc" provides local header files shared between the coveragetest,
15+
# wrappers, and overrides source code units
16+
# - "coveragetest" contains source code for the actual unit test cases
17+
# The primary objective is to get line/path coverage on the FSW
18+
# code units.
19+
# - "wrappers" contains wrappers for the FSW code. The wrapper adds
20+
# any UT-specific scaffolding to facilitate the coverage test, and
21+
# includes the unmodified FSW source file.
22+
#
23+
24+
set(UT_NAME sample_app)
25+
26+
# Use the UT assert public API, and allow direct
27+
# inclusion of source files that are normally private
28+
include_directories(${osal_MISSION_DIR}/ut_assert/inc)
29+
include_directories(${PROJECT_SOURCE_DIR}/fsw/src)
30+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
31+
32+
# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit
33+
# Although sample_app has only one source file, this is done in a loop such that
34+
# the general pattern should work for several files as well.
35+
foreach(SRCFILE sample_app.c)
36+
get_filename_component(UNITNAME "${SRCFILE}" NAME_WE)
37+
38+
set(TESTNAME "${UT_NAME}-${UNITNAME}")
39+
set(UNIT_SOURCE_FILE "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/${UNITNAME}.c")
40+
set(TESTCASE_SOURCE_FILE "coveragetest/coveragetest_${UNITNAME}.c")
41+
42+
# Compile the source unit under test as a OBJECT
43+
add_library(ut_${TESTNAME}_object OBJECT
44+
${UNIT_SOURCE_FILE}
45+
)
46+
47+
# Apply the UT_C_FLAGS to the units under test
48+
# This should enable coverage analysis on platforms that support this
49+
set_target_properties(ut_${TESTNAME}_object PROPERTIES
50+
COMPILE_FLAGS "${UT_C_FLAGS}")
51+
52+
# Compile a test runner application, which contains the
53+
# actual coverage test code (test cases) and the unit under test
54+
add_executable(${TESTNAME}-testrunner
55+
${TESTCASE_SOURCE_FILE}
56+
$<TARGET_OBJECTS:ut_${TESTNAME}_object>
57+
)
58+
59+
# This also needs to be linked with UT_C_FLAGS (for coverage)
60+
set_target_properties(${TESTNAME}-testrunner PROPERTIES
61+
LINK_FLAGS "${UT_C_FLAGS}")
62+
63+
# This is also linked with any other stub libraries needed,
64+
# as well as the UT assert framework
65+
target_link_libraries(${TESTNAME}-testrunner
66+
ut_sample_lib_stubs
67+
ut_cfe-core_stubs
68+
ut_assert
69+
)
70+
71+
# Add it to the set of tests to run as part of "make test"
72+
add_test(${TESTNAME} ${TESTNAME}-testrunner)
73+
74+
endforeach()
75+

0 commit comments

Comments
 (0)