Skip to content

Commit

Permalink
Fix nasa#121, initial implementation of coverage test
Browse files Browse the repository at this point in the history
Create a "ut-stubs" and "ut-coverage" subdirectory under each
of the submodules, and hook into the build system gated upon
the setting of BPLIB_ENABLE_UNIT_TESTS.

This is only the initial framework, most test cases are still not
implemented and need to be added.
  • Loading branch information
jphickey committed Oct 17, 2022
1 parent 3773e06 commit 9f3cd78
Show file tree
Hide file tree
Showing 67 changed files with 6,369 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
list(APPEND BPLIB_COMMON_COMPILE_OPTIONS -Wall -Werror -pedantic -Wno-format-truncation -Wno-stringop-truncation)
endif()

# If standalone build and not cross compile, then enable creation of the "make test" target
if (BPLIB_ENABLE_UNIT_TESTS AND BPLIB_STANDALONE_BUILD_MODE AND NOT CMAKE_CROSSCOMPILING)
enable_testing()
endif()

add_subdirectory(os)
add_subdirectory(common)
add_subdirectory(lib)
Expand Down
6 changes: 6 additions & 0 deletions cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ target_include_directories(bplib_cache PUBLIC
$<TARGET_PROPERTY:bplib,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:bplib_base,INTERFACE_INCLUDE_DIRECTORIES>
)

# Add unit test coverage subdirectory
if(BPLIB_ENABLE_UNIT_TESTS)
add_subdirectory(ut-stubs)
add_subdirectory(ut-coverage)
endif(BPLIB_ENABLE_UNIT_TESTS)
62 changes: 62 additions & 0 deletions cache/ut-coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##################################################################
#
# coverage test build recipe
#
# This CMake file contains the recipe for building the coverage tests.
# It is invoked from the parent directory when unit tests are enabled.
#
##################################################################

add_library(utobj_bplib_cache OBJECT
../src/v7_cache.c
../src/v7_cache_custody.c
../src/v7_cache_fsm.c
)

target_compile_definitions(utobj_bplib_cache PRIVATE
$<TARGET_PROPERTY:bplib_cache,COMPILE_DEFINITIONS>
$<TARGET_PROPERTY:ut_coverage_compile,INTERFACE_COMPILE_DEFINITIONS>
)

target_compile_options(utobj_bplib_cache PRIVATE
$<TARGET_PROPERTY:bplib_cache,COMPILE_OPTIONS>
$<TARGET_PROPERTY:ut_coverage_compile,INTERFACE_COMPILE_OPTIONS>
)

target_include_directories(utobj_bplib_cache PRIVATE
$<TARGET_PROPERTY:bplib_cache,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:ut_coverage_compile,INTERFACE_INCLUDE_DIRECTORIES>
)

# Add executable
add_executable(bplib_cache_testrunner
test_bplib_cache_setup.c
test_v7_cache.c
test_v7_cache_custody.c
test_v7_cache_fsm.c
$<TARGET_OBJECTS:utobj_bplib_cache>
)

target_include_directories(bplib_cache_testrunner PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
$<TARGET_PROPERTY:bplib_cache,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(bplib_cache_testrunner PUBLIC
ut_coverage_link
bplib_base_stubs
bplib_mpool_stubs
bplib_common_stubs
bplib_os_stubs
bplib_v7_stubs
ut_assert
)

add_test(bplib_cache_testrunner bplib_cache_testrunner)

# Install the executables to a staging area for test in cross environments
if (INSTALL_TARGET_LIST)
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS bplib_cache_testrunner DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()
endif()
30 changes: 30 additions & 0 deletions cache/ut-coverage/test_bplib_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/

#ifndef TEST_BPLIB_CACHE_H
#define TEST_BPLIB_CACHE_H

#include "utassert.h"
#include "utstubs.h"
#include "uttest.h"

void TestBplibCacheCustody_Register(void);
void TestBplibCacheFsm_Register(void);
void TestBplibCache_Register(void);

#endif
29 changes: 29 additions & 0 deletions cache/ut-coverage/test_bplib_cache_setup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/

/*
* Includes
*/
#include "test_bplib_cache.h"

void UtTest_Setup(void)
{
TestBplibCacheCustody_Register();
TestBplibCacheFsm_Register();
TestBplibCache_Register();
}
24 changes: 24 additions & 0 deletions cache/ut-coverage/test_v7_cache.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/

/*
* Includes
*/
#include "test_bplib_cache.h"

void TestBplibCache_Register(void) {}
24 changes: 24 additions & 0 deletions cache/ut-coverage/test_v7_cache_custody.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/

/*
* Includes
*/
#include "test_bplib_cache.h"

void TestBplibCacheCustody_Register(void) {}
24 changes: 24 additions & 0 deletions cache/ut-coverage/test_v7_cache_fsm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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.
************************************************************************/

/*
* Includes
*/
#include "test_bplib_cache.h"

void TestBplibCacheFsm_Register(void) {}
19 changes: 19 additions & 0 deletions cache/ut-stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##################################################################
#
# Bundle Protocol Library (BPLib) CMake build recipe
#
# This is for the "cache" stub functions
#
##################################################################

add_library(bplib_cache_stubs STATIC
v7_cache_stubs.c
)

target_include_directories(bplib_cache_stubs PUBLIC
$<TARGET_PROPERTY:bplib_cache,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(bplib_cache_stubs PUBLIC
ut_assert
)
Loading

0 comments on commit 9f3cd78

Please sign in to comment.