updated readme

This commit is contained in:
Robin Müller 2020-12-27 14:53:37 +01:00
parent d8d2f207e1
commit f60f02c5b8
2 changed files with 176 additions and 52 deletions

View File

@ -1,59 +1,19 @@
## FSFW Testing ## FSFW Testing
This repository contains testing and unit testing components.
[Catch2](https://github.com/catchorg/Catch2) has been used as a framework, This folder contains testing and unit testing components.
and these unit tests can only be run on a linux host machine.
The makefile with default settings creates the unit test binary which can be
run in the terminal or in eclipse.
### Instructions ### Instructions
To run the fsfw unittests in the project, perform following steps: The easiest way to run the unittest contained in this folder is to follow
the steps in the [test repository](https://egit.irs.uni-stuttgart.de/fsfw/fsfw_tests).
This is recommended even if the goal is to set up a custom test repository to have
a starting point.
1. Copy the testcfg folder the project root (folder containing the FSFW). To set up a custom test repository or project, following steps can be performed:
2. There is a makefile inside the testcfg folder which can be used to have
a starting point to compile the unit tests. Copy that Makefile to the project 1. Copy the user folder content into the project root.
root 2. Clone [Catch2](https://github.com/catchorg/Catch2) in the project root.
3. Create a folder named catch2 (can have other name which requires Makefile 3. Use the `CMakeLists.txt` as a starting point to add tests and build the test
adaption) and copy the Catch2 header files there (NOTE: CMake support executable.
not enabled yet!)
### Eclipse CDT settings
The default eclipse terminal has issues displaying the colors used
when running the unit test binary by catch2. To fix this issue,
install the ANSI Escape In Console package from the eclipse marketplace.
### GCOV integration
GCOV has been integrated as a code coverage tool.
It can be enabled by adding `GCOV=1` to the build process as an additional argument.
Coverage data will be provided in form of .gcno and .gcda files.
These can be displayed in eclipse by looking
for a .gcno or .gcda file in the \_obj folder, double-clicking it
and picking the right source-binary. This will generate
information about which lines of a file have run, provided it is open in
eclipse.
### LCOV integration
The files generated by GCOV can also be processed by the tool LCOV.
On ubuntu, the tool can be installed with the following command:
```sh
sudo apt-get install lcov
````
After that, the tool can be run by building the unit tests with `GCOV=1`,
running them at least one time and then executing the `lcov.sh` script.
### Adding unit tests
The catch unit tests are located in unittest/testfw. To add new unit tests,
add them to the UnitTestCatch.cpp file or add a new source file which
includes catch.hpp.
For writing basics tests, the [assertion documentation](https://github.com/catchorg/Catch2/blob/master/docs/assertions.md#top)
or the existing examples are a good guideliens.
For more advanced tests, refer to the [catch2 documentation](https://github.com/catchorg/Catch2/blob/master/docs/Readme.md#top).

View File

@ -1 +1,165 @@
add_subdirectory(core) ################################################################################
# CMake support for the Flight Software Framework Tests
#
# Developed in an effort to replace Make with a modern build system.
#
# Author: R. Mueller
################################################################################
################################################################################
# Pre-Project preparation
################################################################################
cmake_minimum_required(VERSION 3.13)
# set(CMAKE_VERBOSE TRUE)
set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/buildsystem/cmake")
# Tests can be built with the Host OSAL or with the Linux OSAL.
if(NOT OS_FSFW)
set(OS_FSFW host CACHE STRING "OS for the FSFW.")
endif()
option(CUSTOM_UNITTEST_RUNNER
"Specify whether custom main or Catch2 main is used" TRUE
)
# Perform steps like loading toolchain files where applicable.
#include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
#pre_project_config()
# Project Name
project(fsfw_tests C CXX)
################################################################################
# Pre-Sources preparation
################################################################################
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Set names and variables
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
if(CUSTOM_UNITTEST_RUNNER)
set(CATCH2_TARGET Catch2)
else()
set(CATCH2_TARGET Catch2WithMain)
endif()
set(LIB_FSFW_NAME fsfw)
# Set path names
set(FSFW_PATH fsfw)
set(CATCH2_PATH Catch2)
set(FSFW_TESTS_PATH fsfw/unittest)
set(TEST_SETUP_PATH unittest)
# Analyse different OS and architecture/target options and
# determine BSP_PATH
# FreeRTOS
if(${OS_FSFW} STREQUAL linux)
add_definitions(-DUNIX -DLINUX)
find_package(Threads REQUIRED)
# Hosted
else()
if(WIN32)
add_definitions(-DWIN32)
elseif(UNIX)
find_package(Threads REQUIRED)
add_definitions(-DUNIX -DLINUX)
endif()
endif()
set(FSFW_CONFIG_PATH testcfg)
################################################################################
# Executable and Sources
################################################################################
# Add executable
add_executable(${TARGET_NAME})
# Add subdirectories
add_subdirectory(${FSFW_PATH})
add_subdirectory(${CATCH2_PATH})
add_subdirectory(${FSFW_CONFIG_PATH})
add_subdirectory(${FSFW_TESTS_PATH})
add_subdirectory(${TEST_SETUP_PATH})
################################################################################
# Post-Sources preparation
################################################################################
# Add libraries for all sources.
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_FSFW_NAME}
${CATCH2_TARGET}
)
# Add include paths for all sources.
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${FSFW_CONFIG_PATH}
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNING_FLAGS
-Wall
-Wextra
-Wshadow=local
-Wimplicit-fallthrough=1
-Wno-unused-parameter
-Wno-psabi
)
# Remove unused sections.
target_compile_options(${TARGET_NAME} PRIVATE
"-ffunction-sections"
"-fdata-sections"
)
# Removed unused sections.
target_link_options(${TARGET_NAME} PRIVATE
"-Wl,--gc-sections"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(COMPILER_FLAGS "/permissive-")
endif()
if(CMAKE_VERBOSE)
message(STATUS "Warning flags: ${WARNING_FLAGS}")
endif()
# Compile options for all sources.
target_compile_options(${TARGET_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:C>:${WARNING_FLAGS} ${COMPILER_FLAGS}>
$<$<COMPILE_LANGUAGE:CXX>:${WARNING_FLAGS} ${COMPILER_FLAGS}>
${ABI_FLAGS}
)
if(NOT CMAKE_SIZE)
set(CMAKE_SIZE size)
if(WIN32)
set(FILE_SUFFIX ".exe")
endif()
endif()
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND echo "Build directory: ${CMAKE_BINARY_DIR}"
COMMAND echo "Target OSAL: ${OS_FSFW}"
COMMAND echo "Target Build Type: ${CMAKE_BUILD_TYPE}"
COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX}
)
include (${CMAKE_CURRENT_SOURCE_DIR}/buildsystem/cmake/BuildType.cmake)
set_build_type()