use ctest to run unit tests in parallel (requires newer catch2)
This commit is contained in:
parent
08f1d199c1
commit
46851eab9f
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -25,5 +25,7 @@ jobs:
|
||||
${{ github.workspace }}/build/
|
||||
${{ github.workspace }}/build_qt/lcov/
|
||||
${{ github.workspace }}/build_qt/decn.c.gcov
|
||||
${{ github.workspace }}/build_qt/Testing/
|
||||
${{ github.workspace }}/main.hex
|
||||
if-no-files-found: error
|
||||
|
||||
|
@ -4,20 +4,23 @@ project(stc_rpncalc C CXX)
|
||||
find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "using address sanitizer")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
||||
link_libraries(asan)
|
||||
message(STATUS "using address sanitizer")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
||||
link_libraries(asan)
|
||||
endif()
|
||||
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (for tests debug make sense)")
|
||||
|
||||
# Compiler warnings
|
||||
if(MSVC)
|
||||
add_compile_options(/W4 /WX)
|
||||
add_compile_options(/W4 /WX)
|
||||
else()
|
||||
add_compile_options(-Wall -Wextra -pedantic)
|
||||
add_compile_options(-Wall -Wextra -pedantic)
|
||||
endif()
|
||||
|
||||
# CTest Catch2 tests
|
||||
enable_testing()
|
||||
|
||||
# Directory with source code
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(qt_gui)
|
||||
|
@ -2,7 +2,6 @@ FROM ubuntu:18.04
|
||||
|
||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
build-essential \
|
||||
catch \
|
||||
clang \
|
||||
cmake \
|
||||
git \
|
||||
@ -13,4 +12,10 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
ninja-build \
|
||||
qtdeclarative5-dev \
|
||||
sdcc=3.5.0+dfsg-2build1 \
|
||||
vim-tiny
|
||||
vim-tiny \
|
||||
wget
|
||||
|
||||
# install more up-to-date catch2
|
||||
RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/c/catch2/catch2_2.13.0-1_all.deb
|
||||
RUN echo "1d501c7f817cfcd46dd1b79edc10896d catch2_2.13.0-1_all.deb" | md5sum --check --
|
||||
RUN dpkg -i catch2_2.13.0-1_all.deb
|
||||
|
@ -1,11 +1,3 @@
|
||||
add_library(Catch INTERFACE)
|
||||
if(EXISTS /usr/include/catch/catch.hpp)
|
||||
target_include_directories(Catch INTERFACE /usr/include/catch)
|
||||
elseif(EXISTS /usr/include/catch2/catch.hpp)
|
||||
target_include_directories(Catch INTERFACE /usr/include/catch2)
|
||||
else()
|
||||
endif()
|
||||
|
||||
#code coverage
|
||||
add_library(coverage_config INTERFACE)
|
||||
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
|
||||
@ -18,11 +10,35 @@ add_library(decn decn.c ../utils.c)
|
||||
add_library(decn_cover decn.c)
|
||||
target_link_libraries(decn_cover PUBLIC coverage_config)
|
||||
|
||||
add_executable(decn_test decn_test.c ../utils.c)
|
||||
target_link_libraries(decn_test decn_cover coverage_config Catch)
|
||||
# old tests (compare output with reference "golden" output file)
|
||||
add_executable(decn_test
|
||||
decn_test.c
|
||||
../utils.c
|
||||
)
|
||||
target_link_libraries(decn_test
|
||||
decn_cover
|
||||
coverage_config
|
||||
)
|
||||
|
||||
add_executable(decn_tests catch_main.cpp decn_tests.cpp decn_tests_trig.cpp ../utils.c)
|
||||
target_link_libraries(decn_tests decn_cover coverage_config mpfr Catch)
|
||||
# catch2 unit tests
|
||||
find_package(Catch2 REQUIRED)
|
||||
enable_testing()
|
||||
set (BUILD_TESTING ON)
|
||||
add_executable(decn_tests
|
||||
catch_main.cpp
|
||||
decn_tests.cpp
|
||||
decn_tests_trig.cpp
|
||||
../utils.c
|
||||
)
|
||||
target_link_libraries(decn_tests
|
||||
mpfr
|
||||
decn_cover
|
||||
coverage_config
|
||||
Catch2::Catch2
|
||||
)
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests(decn_tests)
|
||||
|
||||
# decn prototyping
|
||||
add_subdirectory(proto)
|
||||
|
@ -21,4 +21,4 @@
|
||||
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <boost/multiprecision/mpfr.hpp>
|
||||
#include <catch.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include "decn.h"
|
||||
#include "../utils.h"
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
namespace bmp = boost::multiprecision;
|
||||
using Catch::Matchers::Equals;
|
||||
|
||||
static const int NUM_RAND_TESTS = 1234567;
|
||||
static const int NUM_RAND_TESTS = 123456;
|
||||
|
||||
|
||||
TEST_CASE("build decn"){
|
||||
@ -570,10 +570,16 @@ static void log_test_near1(int lsu0_low, int lsu0_high, int exp){
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("log random near 1"){
|
||||
TEST_CASE("log random 0 to 0.99..."){
|
||||
log_test_near1(0, 99, -1);
|
||||
}
|
||||
TEST_CASE("log random 0.8 to 0.99..."){
|
||||
log_test_near1(80, 99, -1);
|
||||
}
|
||||
TEST_CASE("log random 1.0 to 9.9"){
|
||||
log_test_near1(10, 99, 0);
|
||||
}
|
||||
TEST_CASE("log random 1.0 to 2.0"){
|
||||
log_test_near1(10, 20, 0);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <boost/multiprecision/mpfr.hpp>
|
||||
#include <catch.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include "decn.h"
|
||||
namespace bmp = boost::multiprecision;
|
||||
using Catch::Matchers::Equals;
|
||||
|
@ -17,11 +17,13 @@ cmake .. -GNinja
|
||||
ninja
|
||||
|
||||
# run tests
|
||||
src/decn/decn_tests
|
||||
ctest -j $(nproc)
|
||||
|
||||
# get coverage
|
||||
echo "Running lcov"
|
||||
lcov --capture --directory src/decn --output-file coverage.info
|
||||
lcov --remove coverage.info "/usr/*" --output-file coverage.info
|
||||
genhtml coverage.info --output-directory lcov
|
||||
echo "Running gcov"
|
||||
gcov -b src/decn/CMakeFiles/decn_cover.dir/decn.c.gcno
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user