use ctest to run unit tests in parallel (requires newer catch2)
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/main.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/main.yml
									
									
									
									
										vendored
									
									
								
							@ -25,5 +25,7 @@ jobs:
 | 
				
			|||||||
            ${{ github.workspace }}/build/
 | 
					            ${{ github.workspace }}/build/
 | 
				
			||||||
            ${{ github.workspace }}/build_qt/lcov/
 | 
					            ${{ github.workspace }}/build_qt/lcov/
 | 
				
			||||||
            ${{ github.workspace }}/build_qt/decn.c.gcov
 | 
					            ${{ github.workspace }}/build_qt/decn.c.gcov
 | 
				
			||||||
 | 
					            ${{ github.workspace }}/build_qt/Testing/
 | 
				
			||||||
            ${{ github.workspace }}/main.hex
 | 
					            ${{ github.workspace }}/main.hex
 | 
				
			||||||
          if-no-files-found: error
 | 
					          if-no-files-found: error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,9 @@ else()
 | 
				
			|||||||
	add_compile_options(-Wall -Wextra -pedantic)
 | 
						add_compile_options(-Wall -Wextra -pedantic)
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# CTest Catch2 tests
 | 
				
			||||||
 | 
					enable_testing()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Directory with source code
 | 
					# Directory with source code
 | 
				
			||||||
add_subdirectory(src)
 | 
					add_subdirectory(src)
 | 
				
			||||||
add_subdirectory(qt_gui)
 | 
					add_subdirectory(qt_gui)
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,6 @@ FROM ubuntu:18.04
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
 | 
					RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
 | 
				
			||||||
	build-essential \
 | 
						build-essential \
 | 
				
			||||||
	catch \
 | 
					 | 
				
			||||||
	clang \
 | 
						clang \
 | 
				
			||||||
	cmake \
 | 
						cmake \
 | 
				
			||||||
	git \
 | 
						git \
 | 
				
			||||||
@ -13,4 +12,10 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
 | 
				
			|||||||
	ninja-build \
 | 
						ninja-build \
 | 
				
			||||||
	qtdeclarative5-dev \
 | 
						qtdeclarative5-dev \
 | 
				
			||||||
	sdcc=3.5.0+dfsg-2build1 \
 | 
						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
 | 
					#code coverage
 | 
				
			||||||
add_library(coverage_config INTERFACE)
 | 
					add_library(coverage_config INTERFACE)
 | 
				
			||||||
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
 | 
					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)
 | 
					add_library(decn_cover decn.c)
 | 
				
			||||||
target_link_libraries(decn_cover PUBLIC coverage_config)
 | 
					target_link_libraries(decn_cover PUBLIC coverage_config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_executable(decn_test decn_test.c ../utils.c)
 | 
					# old tests (compare output with reference "golden" output file)
 | 
				
			||||||
target_link_libraries(decn_test decn_cover coverage_config Catch)
 | 
					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)
 | 
					# catch2 unit tests
 | 
				
			||||||
target_link_libraries(decn_tests decn_cover coverage_config mpfr Catch)
 | 
					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
 | 
					# decn prototyping
 | 
				
			||||||
add_subdirectory(proto)
 | 
					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
 | 
					#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 <string>
 | 
				
			||||||
#include <random>
 | 
					#include <random>
 | 
				
			||||||
#include <boost/multiprecision/mpfr.hpp>
 | 
					#include <boost/multiprecision/mpfr.hpp>
 | 
				
			||||||
#include <catch.hpp>
 | 
					#include <catch2/catch.hpp>
 | 
				
			||||||
#include "decn.h"
 | 
					#include "decn.h"
 | 
				
			||||||
#include "../utils.h"
 | 
					#include "../utils.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -31,7 +31,7 @@
 | 
				
			|||||||
namespace bmp = boost::multiprecision;
 | 
					namespace bmp = boost::multiprecision;
 | 
				
			||||||
using Catch::Matchers::Equals;
 | 
					using Catch::Matchers::Equals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const int NUM_RAND_TESTS = 1234567;
 | 
					static const int NUM_RAND_TESTS = 123456;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_CASE("build decn"){
 | 
					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);
 | 
						log_test_near1(0,  99, -1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("log random 0.8 to 0.99..."){
 | 
				
			||||||
	log_test_near1(80, 99, -1);
 | 
						log_test_near1(80, 99, -1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("log random 1.0 to 9.9"){
 | 
				
			||||||
	log_test_near1(10, 99, 0);
 | 
						log_test_near1(10, 99, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					TEST_CASE("log random 1.0 to 2.0"){
 | 
				
			||||||
	log_test_near1(10, 20, 0);
 | 
						log_test_near1(10, 20, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <boost/multiprecision/mpfr.hpp>
 | 
					#include <boost/multiprecision/mpfr.hpp>
 | 
				
			||||||
#include <catch.hpp>
 | 
					#include <catch2/catch.hpp>
 | 
				
			||||||
#include "decn.h"
 | 
					#include "decn.h"
 | 
				
			||||||
namespace bmp = boost::multiprecision;
 | 
					namespace bmp = boost::multiprecision;
 | 
				
			||||||
using Catch::Matchers::Equals;
 | 
					using Catch::Matchers::Equals;
 | 
				
			||||||
 | 
				
			|||||||
@ -17,11 +17,13 @@ cmake .. -GNinja
 | 
				
			|||||||
ninja
 | 
					ninja
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# run tests
 | 
					# run tests
 | 
				
			||||||
src/decn/decn_tests
 | 
					ctest -j $(nproc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# get coverage
 | 
					# get coverage
 | 
				
			||||||
echo "Running lcov"
 | 
					echo "Running lcov"
 | 
				
			||||||
lcov --capture --directory src/decn --output-file coverage.info
 | 
					lcov --capture --directory src/decn --output-file coverage.info
 | 
				
			||||||
 | 
					lcov --remove coverage.info "/usr/*" --output-file coverage.info
 | 
				
			||||||
genhtml coverage.info --output-directory lcov
 | 
					genhtml coverage.info --output-directory lcov
 | 
				
			||||||
echo "Running gcov"
 | 
					echo "Running gcov"
 | 
				
			||||||
gcov -b src/decn/CMakeFiles/decn_cover.dir/decn.c.gcno
 | 
					gcov -b src/decn/CMakeFiles/decn_cover.dir/decn.c.gcno
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user