From 900f7b18be1919612e83c97e139652b59a349f18 Mon Sep 17 00:00:00 2001 From: Jacqueline Deans Date: Thu, 13 Oct 2022 14:23:16 -0500 Subject: [PATCH] Generate test coverage and use Coveralls for tracking and visualization (#1366) * Add code-coverage make target and github actions workflow * Upload coverage to coveralls * Add coverage badge to readme * Fix some test makefiles to correctly propagate flags --- .github/workflows/code_coverage.yml | 69 +++++++++++++++++++ Makefile | 5 ++ README.md | 10 ++- share/trick/makefiles/config_Linux.mk | 2 +- trick_source/.gitignore | 2 + trick_source/sim_services/Clock/test/Makefile | 8 +-- .../sim_services/Executive/test/Makefile | 4 +- .../sim_services/MemoryManager/test/Makefile | 4 +- .../trick_utils/interpolator/test/Makefile | 6 +- .../trick_utils/unicode/test/Makefile | 6 +- 10 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/code_coverage.yml diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml new file mode 100644 index 00000000..59fadd1a --- /dev/null +++ b/.github/workflows/code_coverage.yml @@ -0,0 +1,69 @@ +name: Code Coverage + +on: + push: + branches: + - master + paths-ignore: + - 'docs/**' + - '.github/workflows/**' + - '!.github/workflows/code_coverage.yml' + pull_request: + +jobs: + code-coverage: + runs-on: ubuntu-latest + container: docker://oraclelinux:8 + steps: + - name: Update Package Manager + run: | + dnf -y install epel-release + dnf -y update + dnf install -y 'dnf-command(config-manager)' + + - name: Install Dependencies + run: | + dnf install -y bison clang flex git llvm make maven cmake zip clang-devel gcc gcc-c++ java-11-openjdk-devel libxml2-devel llvm-devel llvm-static ncurses-devel openmotif openmotif-devel perl perl-Digest-MD5 udunits2 udunits2-devel which zlib-devel python2-devel python3-devel swig diffutils lcov + + - name: Install GTest + run: | + dnf config-manager --enable ol8_codeready_builder + dnf install -y gtest-devel + + - name: Checkout repository + uses: actions/checkout@master + + - name: Configure Trick + run: | + export MAKEFLAGS=-j`nproc` + export PYTHON_VERSION=3 + ./configure + - name: Build Trick + run: | + export MAKEFLAGS=-j`nproc` + export CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + export LDFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_LDFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + make + - name: Generate Code Coverage + run: | + export MAKEFLAGS=-j`nproc` + export CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + export LDFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_LDFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_CFLAGS="-fprofile-arcs -ftest-coverage -O0" + export TRICK_SYSTEM_CXXFLAGS="-fprofile-arcs -ftest-coverage -O0" + make code-coverage + - name: Upload to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: "./coverage.info" diff --git a/Makefile b/Makefile index 4efba252..071946d4 100644 --- a/Makefile +++ b/Makefile @@ -307,6 +307,11 @@ sim_test: pytest: make -C share/trick/pymods/trick +code-coverage: test + lcov --capture --directory trick_source/sim_services --output-file coverage_large.info + lcov --remove coverage_large.info '/Library/*' '/usr/*' '*/io_src/*' '*/test/*' -o coverage.info + rm coverage_large.info + lcov --list coverage.info #requirements: # @ $(MAKE) -C trick_test/requirements_docs install diff --git a/README.md b/README.md index dcce16a9..d83bb195 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,18 @@ Linux -

- -

macOS -

- -

macOS + +Coverage Status +

+

The Trick Simulation Environment, developed at the NASA Johnson Space Center, is a powerful simulation development framework that enables users to build applications for all phases of space vehicle development. Trick expedites the creation of simulations for early vehicle design, performance evaluation, flight software development, flight vehicle dynamic load analysis, and virtual/hardware in the loop training. Trick's purpose is to provide a common set of simulation capabilities that allow users to concentrate on their domain specific models, rather than simulation-specific functions like job ordering, input file processing, or data recording.

diff --git a/share/trick/makefiles/config_Linux.mk b/share/trick/makefiles/config_Linux.mk index 4a6b6745..bcd966bd 100644 --- a/share/trick/makefiles/config_Linux.mk +++ b/share/trick/makefiles/config_Linux.mk @@ -24,7 +24,7 @@ endif SHARED_LIB_OPT := -shared RPATH = -Wl,-rpath=${TRICK_LIB_DIR} -TRICK_SYSTEM_LDFLAGS = -Wl,--export-dynamic +TRICK_SYSTEM_LDFLAGS += -Wl,--export-dynamic PLATFORM_LIBS = -lrt LD_WHOLE_ARCHIVE := -Wl,-whole-archive diff --git a/trick_source/.gitignore b/trick_source/.gitignore index e69de29b..853fc650 100644 --- a/trick_source/.gitignore +++ b/trick_source/.gitignore @@ -0,0 +1,2 @@ +*.gcda +*.gcno \ No newline at end of file diff --git a/trick_source/sim_services/Clock/test/Makefile b/trick_source/sim_services/Clock/test/Makefile index 8d00cd53..be4f65dc 100644 --- a/trick_source/sim_services/Clock/test/Makefile +++ b/trick_source/sim_services/Clock/test/Makefile @@ -8,7 +8,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../share/trick/makefiles/Makefile.common # Flags passed to the preprocessor. -TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} +TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} LIBS = -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main @@ -38,10 +38,10 @@ clean : rm -f $(TESTS) *.o GetTimeOfDayClock_test.o : GetTimeOfDayClock_test.cpp - $(TRICK_CXX) $(TRICK_CPPFLAGS) -c $< + $(TRICK_CXX) $(TRICK_CXXFLAGS) -c $< GetTimeOfDayClock_test : ${GETTIMEOFDAY_CLOCK_OBJECTS} - $(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) -o $@ $^ ${LIBS} + $(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) $(TRICK_CXXFLAGS) -o $@ $^ ${LIBS} exec_get_rt_nap_stub.o : exec_get_rt_nap_stub.cpp - $(TRICK_CXX) $(TRICK_CPPFLAGS) -c $< + $(TRICK_CXX) $(TRICK_CXXFLAGS) -c $< diff --git a/trick_source/sim_services/Executive/test/Makefile b/trick_source/sim_services/Executive/test/Makefile index 0f032a43..94cf5cc8 100644 --- a/trick_source/sim_services/Executive/test/Makefile +++ b/trick_source/sim_services/Executive/test/Makefile @@ -8,7 +8,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../share/trick/makefiles/Makefile.common # Flags passed to the preprocessor. -TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} +TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} TRICK_LIBS = -L ${TRICK_LIB_DIR} -ltrick_mm -ltrick_units -ltrick TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main @@ -31,7 +31,7 @@ clean : rm -f $(TESTS) *.o Executive_test.o : Executive_test.cpp - $(TRICK_CXX) $(TRICK_CPPFLAGS) -c $< + $(TRICK_CXX) $(TRICK_CXXFLAGS) -c $< Executive_test : Executive_test.o $(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) -o $@ $^ $(OTHER_OBJECTS) $(TRICK_LIBS) $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS) diff --git a/trick_source/sim_services/MemoryManager/test/Makefile b/trick_source/sim_services/MemoryManager/test/Makefile index f9b5df08..dd729046 100644 --- a/trick_source/sim_services/MemoryManager/test/Makefile +++ b/trick_source/sim_services/MemoryManager/test/Makefile @@ -10,8 +10,8 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../share/trick/makefiles/Mak # Replace -isystem with -I so ICG doesn't skip Trick headers TRICK_SYSTEM_CXXFLAGS := $(subst -isystem,-I,$(TRICK_SYSTEM_CXXFLAGS)) -#COVERAGE_FLAGS += -fprofile-arcs -ftest-coverage -O0 -#TRICK_SYSTEM_LDFLAGS += ${COVERAGE_FLAGS} +COVERAGE_FLAGS += -fprofile-arcs -ftest-coverage -O0 +TRICK_SYSTEM_LDFLAGS += ${COVERAGE_FLAGS} # Flags passed to the preprocessor. TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -Wno-sign-compare ${COVERAGE_FLAGS} -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} diff --git a/trick_source/trick_utils/interpolator/test/Makefile b/trick_source/trick_utils/interpolator/test/Makefile index 376371a6..05ff5f11 100644 --- a/trick_source/trick_utils/interpolator/test/Makefile +++ b/trick_source/trick_utils/interpolator/test/Makefile @@ -8,7 +8,7 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common # Flags passed to the preprocessor. -TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} +TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} TRICK_LIBS = ${TRICK_LIB_DIR}/libtrick.a TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main -lpthread @@ -34,8 +34,8 @@ clean : rm -rf io_src xml Interpolator_unittest.o : Interpolator_unittest.cc - $(TRICK_CXX) $(TRICK_CPPFLAGS) -c $< + $(TRICK_CXX) $(TRICK_CXXFLAGS) -c $< Interpolator_unittest : Interpolator_unittest.o - $(TRICK_CXX) $(TRICK_CPPFLAGS) -o $@ $^ $(OTHER_OBJECTS) -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS) + $(TRICK_CXX) $(TRICK_CXXFLAGS) -o $@ $^ $(OTHER_OBJECTS) -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS) diff --git a/trick_source/trick_utils/unicode/test/Makefile b/trick_source/trick_utils/unicode/test/Makefile index f63c944b..64af3645 100644 --- a/trick_source/trick_utils/unicode/test/Makefile +++ b/trick_source/trick_utils/unicode/test/Makefile @@ -8,7 +8,7 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common # Flags passed to the preprocessor. -TRICK_CPPFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} +TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} TRICK_LIBS = ${TRICK_LIB_DIR}/libtrick.a TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lpthread @@ -34,8 +34,8 @@ clean : rm -rf io_src xml unicode_utils_test.o : unicode_utils_test.cpp - $(TRICK_CXX) $(TRICK_CPPFLAGS) -c $< + $(TRICK_CXX) $(TRICK_CXXFLAGS) -c $< unicode_utils_test : unicode_utils_test.o - $(TRICK_CXX) $(TRICK_CPPFLAGS) -o $@ $^ $(OTHER_OBJECTS) -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS) + $(TRICK_CXX) $(TRICK_CXXFLAGS) -o $@ $^ $(OTHER_OBJECTS) -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)