diff --git a/.gcov/make/make_gcov_01_generic.gmk b/.gcov/make/make_gcov_01_generic.gmk new file mode 100644 index 00000000..42d99116 --- /dev/null +++ b/.gcov/make/make_gcov_01_generic.gmk @@ -0,0 +1,114 @@ +# ------------------------------------------------------------------------------ +# Copyright Christopher Kormanyos 2022. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# ------------------------------------------------------------------------------ + +PATH_MAKE = $(CURDIR) +PATH_PRJ = $(PATH_MAKE)/../.. +PATH_SRC = $(PATH_PRJ) +PATH_BIN = $(PATH_MAKE)/bin +PATH_ERR = $(PATH_MAKE)/err +PATH_OBJ = $(PATH_MAKE)/obj + +CAT = cat +GNUECHO = echo +LS = ls +MKDIR = mkdir +GCOV = gcov +LCOV = lcov +GENHTML = genhtml +RM = rm +SED = sed + +include make_gcov_02_files.gmk +include make_gcov_03_flags.gmk + +FILES_ALL = $(FILES_PRJ) +FILES_O = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .o, $(FILES_ALL)))) +FILES_GCOV = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .gcov, $(FILES_ALL)))) + +# ------------------------------------------------------------------------------ +# VPATH definition: VPATH is required for make to find the source files. +# ------------------------------------------------------------------------------ +VPATH := $(sort $(dir $(FILES_ALL))) + + +# ------------------------------------------------------------------------------ +# Executable file: +# ------------------------------------------------------------------------------ + +.PHONY: $(PATH_BIN)/wide_integer.exe +$(PATH_BIN)/wide_integer.exe: $(FILES_O) + # Link coverage-instrumented executable + @$(GNUECHO) +++ link object files to $(PATH_BIN)/wide_integer.exe + @$(CC) -x none $(CXXFLAGS) $(FILES_O) -o $(PATH_BIN)/wide_integer.exe + @$(GNUECHO) + + +# ------------------------------------------------------------------------------ +# Main dependency: +# Compile all files and link them. +# Run gcov and get results. +# (See also https://github.com/codecov/example-cpp11-cmake) +# ------------------------------------------------------------------------------ + +.PHONY: gcov +gcov: $(PATH_BIN)/wide_integer.exe + # Obtain results + @$(GNUECHO) +++ execute $(PATH_BIN)/wide_integer.exe + @$(PATH_BIN)/wide_integer.exe + @$(GNUECHO) + @$(GNUECHO) +++ running gcov + @$(GCOV) $(GCOV_FLAGS) $(addsuffix .cpp,$(FILES_PRJ)) + @$(GNUECHO) + @$(GNUECHO) +++ running lcov + @$(LCOV) $(LCOV_BRANCH) -c --directory obj --output-file coverage_unfiltered.info + @$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --output-file coverage.info + @$(GNUECHO) + @$(GNUECHO) +++ running genhtml + @$(GENHTML) coverage.info $(LCOV_BRANCH) --demangle-cpp --output-directory $(PATH_BIN)/report + @$(GNUECHO) + +# ------------------------------------------------------------------------------ +# Clean temporary files. +# ------------------------------------------------------------------------------ + +.PHONY: clean +clean: + # creating output directories + @$(GNUECHO) +++ cleaning output directories + @-$(RM) -rf $(PATH_BIN)* || uname -r + @-$(RM) -rf $(PATH_ERR)* || uname -r + @-$(RM) -rf $(PATH_OBJ)* || uname -r + @-$(RM) -f *.gcov || uname -r + @-$(RM) -f coverage* || uname -r + @$(GNUECHO) + + +# ------------------------------------------------------------------------------ +# Prepare the gcov build. +# ------------------------------------------------------------------------------ + +.PHONY: prepare +prepare: clean + @$(GNUECHO) +++ creating output directories + @-$(MKDIR) -p $(PATH_BIN) + @-$(MKDIR) -p $(PATH_ERR) + @-$(MKDIR) -p $(PATH_OBJ) + @$(GNUECHO) + @$(GNUECHO) +++ print gcov version + @$(GCOV) --version + @$(GNUECHO) + @$(GNUECHO) +++ print include paths + @$(GNUECHO) $(C_INCLUDES) + @$(GNUECHO) + +# ------------------------------------------------------------------------------ +# pattern rule for compilation of cpp-files +# ------------------------------------------------------------------------------ +$(PATH_OBJ)/%.o : %.cpp + @-$(GNUECHO) +++ compiling: $(notdir $<) to $(notdir $(PATH_OBJ)/$(basename $(@F)).o) + @-$(CC) $(CXXFLAGS) -x c++ -c $(C_INCLUDES) $(C_DEFINES) $< -o $(PATH_OBJ)/$(basename $(@F)).o 2> $(PATH_ERR)/$(basename $(@F)).err + @-$(SED) -e 's|.h:\([0-9]*\),|.h(\1) :|' -e 's|:\([0-9]*\):|(\1) :|' $(PATH_ERR)/$(basename $(@F)).err diff --git a/.gcov/make/make_gcov_02_files.gmk b/.gcov/make/make_gcov_02_files.gmk new file mode 100644 index 00000000..6e842788 --- /dev/null +++ b/.gcov/make/make_gcov_02_files.gmk @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------ +# Copyright Christopher Kormanyos 2022. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# ------------------------------------------------------------------------------ + +FILES_PRJ = $(PATH_SRC)/test/test \ + $(PATH_SRC)/test/test_uintwide_t_boost_backend \ + $(PATH_SRC)/test/test_uintwide_t_edge_cases \ + $(PATH_SRC)/test/test_uintwide_t_examples \ + $(PATH_SRC)/test/test_uintwide_t_float_convert \ + $(PATH_SRC)/test/test_uintwide_t_int_convert \ + $(PATH_SRC)/test/test_uintwide_t_n_base \ + $(PATH_SRC)/test/test_uintwide_t_n_binary_ops_base \ + $(PATH_SRC)/test/test_uintwide_t_spot_values \ + $(PATH_SRC)/examples/example000a_builtin_convert \ + $(PATH_SRC)/examples/example000_numeric_limits \ + $(PATH_SRC)/examples/example001_mul_div \ + $(PATH_SRC)/examples/example001a_div_mod \ + $(PATH_SRC)/examples/example002_shl_shr \ + $(PATH_SRC)/examples/example003_sqrt \ + $(PATH_SRC)/examples/example003a_cbrt \ + $(PATH_SRC)/examples/example004_rootk_pow \ + $(PATH_SRC)/examples/example005_powm \ + $(PATH_SRC)/examples/example005a_pow_factors_of_p99 \ + $(PATH_SRC)/examples/example006_gcd \ + $(PATH_SRC)/examples/example007_random_generator \ + $(PATH_SRC)/examples/example008_miller_rabin_prime \ + $(PATH_SRC)/examples/example008a_miller_rabin_prime \ + $(PATH_SRC)/examples/example009_timed_mul \ + $(PATH_SRC)/examples/example009a_timed_mul_4_by_4 \ + $(PATH_SRC)/examples/example009b_timed_mul_8_by_8 \ + $(PATH_SRC)/examples/example010_uint48_t \ + $(PATH_SRC)/examples/example011_uint24_t \ + $(PATH_SRC)/examples/example012_rsa_crypto diff --git a/.gcov/make/make_gcov_03_flags.gmk b/.gcov/make/make_gcov_03_flags.gmk new file mode 100644 index 00000000..ab8a172b --- /dev/null +++ b/.gcov/make/make_gcov_03_flags.gmk @@ -0,0 +1,80 @@ +# ------------------------------------------------------------------------------ +# Copyright Christopher Kormanyos 2022. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# ------------------------------------------------------------------------------ + +BOOST_ROOT_FOR_GCOV = /mnt/c/boost/boost_1_78_0 +CC = g++ +STD = c++11 +ALL_COV = 0 + +ifneq ($(MY_BOOST_ROOT),) +BOOST_ROOT_FOR_GCOV := $(MY_BOOST_ROOT) +endif + +ifneq ($(MY_CC),) +CC := $(MY_CC) +endif + +ifneq ($(MY_STD),) +STD := $(MY_STD) +endif + +ifneq ($(MY_STD),) +STD := $(MY_STD) +endif + +ifneq ($(MY_ALL_COV),) +ALL_COV := $(MY_ALL_COV) +endif + +CXXFLAGS = -march=native \ + -mtune=native \ + -O2 \ + -Wall \ + -Wextra \ + -Wconversion \ + -Wsign-conversion \ + -std=$(STD) \ + -pthread \ + -lpthread \ + -fno-inline-functions \ + -fprofile-arcs \ + -ftest-coverage + +C_DEFINES = WIDE_INTEGER_HAS_COVERAGE \ + WIDE_INTEGER_HAS_LIMB_TYPE_UINT64 + +C_INCLUDES = $(PATH_SRC) \ + $(BOOST_ROOT_FOR_GCOV) + +C_DEFINES :=$(addprefix -D,$(C_DEFINES)) +C_INCLUDES :=$(addprefix -I,$(C_INCLUDES)) + +GCOV_FLAGS = --object-directory obj \ + --demangled-names + + +# ------------------------------------------------------------------------------ +# All gcov flags: The GCOV_FLAGS below are equivalent to -abcfu +# ------------------------------------------------------------------------------ + +ifneq ($(ALL_COV),0) +GCOV_FLAGS := $(GCOV_FLAGS) \ + --all-blocks \ + --branch-counts \ + --branch-probabilities \ + --function-summaries \ + --unconditional-branches +endif + +LCOV_BRANCH = + +ifneq ($(ALL_COV),0) +LCOV_BRANCH := --rc lcov_branch_coverage=1 +endif + +LCOV_REMOVES = '/usr/*' \ + '*boost/*' diff --git a/.github/workflows/wide_integer_codecov.yml b/.github/workflows/wide_integer_codecov.yml new file mode 100644 index 00000000..6f9ac8c0 --- /dev/null +++ b/.github/workflows/wide_integer_codecov.yml @@ -0,0 +1,62 @@ +# ------------------------------------------------------------------------------ +# Copyright Christopher Kormanyos 2022. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# ------------------------------------------------------------------------------ + +name: wide_integer_codecov +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] +jobs: + gnumake-gcc-gcov-native: + runs-on: ubuntu-20.04 + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + standard: [ c++11 ] + compiler: [ g++ ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - name: update-tools + run: sudo apt install lcov + - name: clone-submods-bootstrap-headers-boost-develop + run: | + git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root + cd ../boost-root + git submodule update --init tools + git submodule update --init libs/config + git submodule update --init libs/multiprecision + ./bootstrap.sh + ./b2 headers + - name: gnumake-gcc-gcov-native + run: | + grep BOOST_VERSION ../boost-root/boost/version.hpp + cd .gcov/make + echo "build and run gcov/lcov/genhtml" + echo "make prepare -f make_gcov_01_generic.gmk MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}" + echo + make prepare -f make_gcov_01_generic.gmk MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }} + echo + echo "make gcov -f make_gcov_01_generic.gmk --jobs=8 MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }}" + echo + make gcov -f make_gcov_01_generic.gmk --jobs=8 MY_ALL_COV=0 MY_BOOST_ROOT=../../../boost-root MY_CC=${{ matrix.compiler }} MY_STD=${{ matrix.standard }} + echo + echo "return to wide-integer root directory" + cd ../.. + - name: upload-codecov + uses: codecov/codecov-action@v2 + with: + files: .gcov/make/coverage.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + functionalities: fix diff --git a/README.md b/README.md index 5bce237b..3696bb2c 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![Coverity Scan](https://scan.coverity.com/projects/24742/badge.svg)](https://scan.coverity.com/projects/ckormanyos-wide-integer) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ckormanyos_wide-integer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ckormanyos_wide-integer) [![Boost Software License 1.0](https://img.shields.io/badge/license-BSL%201.0-blue.svg)](https://github.com/ckormanyos/wide-integer/blob/master/LICENSE_1_0.txt) +[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/ckormanyos/wide-integer)](https://img.shields.io/github/commit-activity/y/ckormanyos/wide-integer) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ckormanyos/wide-integer)](https://github.com/ckormanyos/wide-integer) Wide-integer implements a generic C++ template for extended width diff --git a/test/test.cpp b/test/test.cpp index 374f764d..5e11a655 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -21,6 +21,10 @@ // make prepare -f make_tidy_01_generic.gmk MY_BOOST_ROOT=/mnt/c/boost/boost_1_79_0 // make tidy -f make_tidy_01_generic.gmk --jobs=8 MY_BOOST_ROOT=/mnt/c/boost/boost_1_79_0 +// cd .gcov/make +// make prepare -f make_gcov_01_generic.gmk MY_ALL_COV=0 MY_BOOST_ROOT=/mnt/c/boost/boost_1_79_0 MY_CC=g++ +// make gcov -f make_gcov_01_generic.gmk --jobs=8 MY_ALL_COV=0 MY_BOOST_ROOT=/mnt/c/boost/boost_1_79_0 MY_CC=g++ + // cd /mnt/c/Users/User/Documents/Ks/PC_Software/NumericalPrograms/ExtendedNumberTypes/wide_integer // PATH=/home/chris/local/coverity/cov-analysis-linux64-2021.12.1/bin:$PATH // cov-build --dir cov-int g++ -finline-functions -march=native -mtune=native -O3 -Wall -Wextra -Wconversion -Wsign-conversion -std=c++11 -DWIDE_INTEGER_HAS_LIMB_TYPE_UINT64 -DWIDE_INTEGER_HAS_MUL_8_BY_8_UNROLL -I. -I/mnt/c/boost/boost_1_79_0 -pthread -lpthread test/test.cpp test/test_uintwide_t_boost_backend.cpp test/test_uintwide_t_edge_cases.cpp test/test_uintwide_t_examples.cpp test/test_uintwide_t_float_convert.cpp test/test_uintwide_t_int_convert.cpp test/test_uintwide_t_n_base.cpp test/test_uintwide_t_n_binary_ops_base.cpp examples/example000a_builtin_convert.cpp test/test_uintwide_t_spot_values.cpp examples/example000_numeric_limits.cpp examples/example001_mul_div.cpp examples/example001a_div_mod.cpp examples/example002_shl_shr.cpp examples/example003_sqrt.cpp examples/example003a_cbrt.cpp examples/example004_rootk_pow.cpp examples/example005_powm.cpp examples/example005a_pow_factors_of_p99.cpp examples/example006_gcd.cpp examples/example007_random_generator.cpp examples/example008_miller_rabin_prime.cpp examples/example008a_miller_rabin_prime.cpp examples/example009_timed_mul.cpp examples/example009a_timed_mul_4_by_4.cpp examples/example009b_timed_mul_8_by_8.cpp examples/example010_uint48_t.cpp examples/example011_uint24_t.cpp examples/example012_rsa_crypto.cpp -o wide_integer.exe @@ -69,7 +73,7 @@ #define UINTWIDE_T_REDUCE_TEST_DEPTH #endif #elif defined(__GNUC__) - #if defined(__SANITIZE_THREAD__) + #if defined(__SANITIZE_THREAD__) || defined(WIDE_INTEGER_HAS_COVERAGE) #define UINTWIDE_T_REDUCE_TEST_DEPTH #endif #endif @@ -324,8 +328,14 @@ auto test_uintwide_t_0002048() -> bool auto test_uintwide_t_0008192() -> bool { + #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) + constexpr auto count = static_cast(1UL << 8U); + #else + constexpr auto count = static_cast(1UL << 5U); + #endif + std::cout << "running: test_uintwide_t_0008192" << std::endl; - test_uintwide_t_n_binary_ops_template<8192U> test_uintwide_t_n_binary_ops_template_instance(1UL << 8U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + test_uintwide_t_n_binary_ops_template<8192U> test_uintwide_t_n_binary_ops_template_instance(count); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) const auto result_is_ok = test_uintwide_t_n_binary_ops_template_instance.do_test(test_uintwide_t_n_binary_ops_rounds); return result_is_ok; @@ -345,9 +355,9 @@ auto test_uintwide_t_0008192_limb_type_uint64_t() -> bool auto test_uintwide_t_0012288() -> bool { #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) - constexpr auto count = static_cast(1UL << 5U); - #else constexpr auto count = static_cast(1UL << 7U); + #else + constexpr auto count = static_cast(1UL << 4U); #endif std::cout << "running: test_uintwide_t_0012288" << std::endl; @@ -360,9 +370,9 @@ auto test_uintwide_t_0012288() -> bool auto test_uintwide_t_0032768() -> bool { #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) - constexpr auto count = static_cast(1UL << 5U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - #else constexpr auto count = static_cast(1UL << 7U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + #else + constexpr auto count = static_cast(1UL << 4U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) #endif std::cout << "running: test_uintwide_t_0032768" << std::endl; @@ -372,23 +382,27 @@ auto test_uintwide_t_0032768() -> bool return result_is_ok; } -#if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) auto test_uintwide_t_0065536_alloc() -> bool { + #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) + constexpr auto count = static_cast(1UL << 5U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + #else + constexpr auto count = static_cast(1UL << 2U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + #endif + std::cout << "running: test_uintwide_t_0065536_alloc" << std::endl; - test_uintwide_t_n_binary_ops_template<65536U, std::uint32_t, std::allocator> test_uintwide_t_n_binary_ops_template_instance(1UL << 6U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + test_uintwide_t_n_binary_ops_template<65536U, std::uint32_t, std::allocator> test_uintwide_t_n_binary_ops_template_instance(count); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) const auto result_is_ok = test_uintwide_t_n_binary_ops_template_instance.do_test(test_uintwide_t_n_binary_ops_rounds); return result_is_ok; } -#endif auto test_uintwide_t_0008192_by_0012288() -> bool { #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) - constexpr auto count = static_cast(1UL << 5U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - #else constexpr auto count = static_cast(1UL << 7U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + #else + constexpr auto count = static_cast(1UL << 4U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) #endif std::cout << "running: test_uintwide_t_0008192_by_0012288" << std::endl; @@ -401,9 +415,9 @@ auto test_uintwide_t_0008192_by_0012288() -> bool auto test_uintwide_t_0012288_by_0008192() -> bool { #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) - constexpr auto count = static_cast(1UL << 5U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - #else constexpr auto count = static_cast(1UL << 7U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + #else + constexpr auto count = static_cast(1UL << 4U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) #endif std::cout << "running: test_uintwide_t_0012288_by_0008192" << std::endl; @@ -474,9 +488,7 @@ auto run() -> bool // NOLINT(readability-function-cognitive-complexity) #endif result_is_ok = (test_uintwide_t_0012288() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; result_is_ok = (test_uintwide_t_0032768() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; - #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) result_is_ok = (test_uintwide_t_0065536_alloc() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; - #endif result_is_ok = (test_uintwide_t_0008192_by_0012288() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; result_is_ok = (test_uintwide_t_0012288_by_0008192() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; result_is_ok = (test_uintwide_t_0000032_by_0000032_4_by_4() && result_is_ok); std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl; diff --git a/wide_integer.vcxproj b/wide_integer.vcxproj index fc3d1963..1d834912 100644 --- a/wide_integer.vcxproj +++ b/wide_integer.vcxproj @@ -236,7 +236,11 @@ + + + + diff --git a/wide_integer.vcxproj.filters b/wide_integer.vcxproj.filters index fb3145f0..1542c8a9 100644 --- a/wide_integer.vcxproj.filters +++ b/wide_integer.vcxproj.filters @@ -38,6 +38,12 @@ {c8663027-03cc-43d3-a3bc-927bbbdb3b3f} + + {d3d4d6ad-0796-4bd5-b015-cd9c948caccf} + + + {09bf1894-26c1-40a4-870e-f338f0940b7b} + @@ -199,6 +205,18 @@ .github\workflows + + .gcov\make + + + .gcov\make + + + .gcov\make + + + .github\workflows +