From 49c36f0015c985eda0f640ce0152c4d7dde662c8 Mon Sep 17 00:00:00 2001 From: serkixenos Date: Thu, 12 Nov 2020 17:36:00 +0100 Subject: [PATCH] [DO NOT MERGE] Code coverage tests --- .gitlab-ci.yml | 13 +++++++--- CMakeLists.txt | 4 +-- tests/CMakeLists.txt | 6 +++++ .../init_tests.cpp} | 21 ++++----------- tests/app/main.cpp | 2 +- tests/benchmarks/main.cpp | 2 +- tests/betting/betting_tests.cpp | 18 ------------- tests/betting/init_tests.cpp | 26 +++++++++++++++++++ tests/cli/init_tests.cpp | 26 +++++++++++++++++++ tests/cli/main.cpp | 3 +-- tests/elasticsearch/main.cpp | 2 +- tests/intense/main.cpp | 2 +- .../peerplays_sidechain_tests.cpp | 2 +- tests/performance/performance_tests.cpp | 2 +- tests/random/random_tests.cpp | 2 +- tests/tests/init_tests.cpp | 26 +++++++++++++++++++ tests/tournament/tournament_tests.cpp | 2 +- 17 files changed, 109 insertions(+), 50 deletions(-) rename tests/{tests/main.cpp => all_graphene_tests/init_tests.cpp} (60%) create mode 100644 tests/betting/init_tests.cpp create mode 100644 tests/cli/init_tests.cpp create mode 100644 tests/tests/init_tests.cpp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da6baf86..69e453f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,7 @@ build: - rm -rf build - mkdir build - cd build - - cmake -DCMAKE_BUILD_TYPE=Release .. + - cmake -DENABLE_COVERAGE_TESTING=true .. - make -j$(nproc) artifacts: untracked: true @@ -34,8 +34,13 @@ test: dependencies: - build script: - - ./build/tests/betting_test --log_level=message - - ./build/tests/chain_test --log_level=message - - ./build/tests/cli_test --log_level=message + - ./build/tests/all_graphene_tests --log_level=message + - lcov --capture --directory ./build/ --output-file ./build/coverage.info + - genhtml --output-directory ./build/coverage ./build/coverage.info + artifacts: + untracked: true + paths: + - build/coverage + - build/coverage.info tags: - builder diff --git a/CMakeLists.txt b/CMakeLists.txt index 4df202b3..d816c306 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,10 +147,10 @@ else( WIN32 ) # Apple AND Linux endif( WIN32 ) -set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build Peerplays for code coverage analysis") +#set(ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build Peerplays for code coverage analysis") if(ENABLE_COVERAGE_TESTING) - SET(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0") endif() add_subdirectory( libraries ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ff915a9..08410e79 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -62,4 +62,10 @@ file(GLOB ES_SOURCES "elasticsearch/*.cpp") add_executable( es_test ${ES_SOURCES} ) target_link_libraries( es_test PRIVATE graphene_tests_common ) +list(FILTER UNIT_TESTS EXCLUDE REGEX "[/]init_tests[.]cpp$") +list(FILTER BETTING_TESTS EXCLUDE REGEX "[/]init_tests[.]cpp$") +list(FILTER CLI_SOURCES EXCLUDE REGEX "[/]init_tests[.]cpp$") +add_executable( all_graphene_tests ./all_graphene_tests/init_tests.cpp ${UNIT_TESTS} ${BETTING_TESTS} ${CLI_SOURCES} ) +target_link_libraries( all_graphene_tests PRIVATE graphene_wallet graphene_witness graphene_tests_common ${PLATFORM_SPECIFIC_LIBS} ) + add_subdirectory( generate_empty_blocks ) diff --git a/tests/tests/main.cpp b/tests/all_graphene_tests/init_tests.cpp similarity index 60% rename from tests/tests/main.cpp rename to tests/all_graphene_tests/init_tests.cpp index 405e7c10..b05317a9 100644 --- a/tests/tests/main.cpp +++ b/tests/all_graphene_tests/init_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * Copyright (c) 2019 PBSA, and contributors. * * The MIT License * @@ -21,20 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include -extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; +#define BOOST_TEST_MODULE "All Graphene Tests" +#include -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); - if( genesis_timestamp_str != nullptr ) - { - GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); - } - std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; - return nullptr; -} +BOOST_AUTO_TEST_SUITE(AllGrapheneTests) +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/app/main.cpp b/tests/app/main.cpp index bd58a518..c4133e09 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -41,7 +41,7 @@ #include "../common/genesis_file_util.hpp" #define BOOST_TEST_MODULE Test Application -#include +#include using namespace graphene; diff --git a/tests/benchmarks/main.cpp b/tests/benchmarks/main.cpp index 706318d6..40e137ce 100644 --- a/tests/benchmarks/main.cpp +++ b/tests/benchmarks/main.cpp @@ -22,4 +22,4 @@ * THE SOFTWARE. */ #define BOOST_TEST_MODULE "C++ Benchmarks for Graphene Blockchain Database" -#include +#include diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index 7dff8b82..4e825bf8 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -3000,21 +3000,3 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_final_test ) // } BOOST_AUTO_TEST_SUITE_END() - - - -//#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" -#include -#include -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - - // betting operations don't take effect until HARDFORK 1000 - GRAPHENE_TESTING_GENESIS_TIMESTAMP = HARDFORK_1000_TIME.sec_since_epoch() + 2; - - return nullptr; -} - diff --git a/tests/betting/init_tests.cpp b/tests/betting/init_tests.cpp new file mode 100644 index 00000000..d8fff70b --- /dev/null +++ b/tests/betting/init_tests.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2019 PBSA, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define BOOST_TEST_MODULE "Betting Tests" +#include diff --git a/tests/cli/init_tests.cpp b/tests/cli/init_tests.cpp new file mode 100644 index 00000000..440820cc --- /dev/null +++ b/tests/cli/init_tests.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2019 PBSA, and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define BOOST_TEST_MODULE CLI Tests +#include diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index c6b587e8..00e58400 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -27,8 +27,7 @@ #include -#define BOOST_TEST_MODULE Test Application -#include +#include /////////////////////////////// // Tests diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index c948616f..3cb7303e 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -32,7 +32,7 @@ #include "../common/database_fixture.hpp" #define BOOST_TEST_MODULE Elastic Search Database Tests -#include +#include using namespace graphene::chain; using namespace graphene::chain::test; diff --git a/tests/intense/main.cpp b/tests/intense/main.cpp index c337407f..1d39b03a 100644 --- a/tests/intense/main.cpp +++ b/tests/intense/main.cpp @@ -23,7 +23,7 @@ */ #include #include -#include +#include boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { std::srand(time(NULL)); diff --git a/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp b/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp index 84577384..a45e5831 100644 --- a/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp +++ b/tests/peerplays_sidechain/peerplays_sidechain_tests.cpp @@ -5,7 +5,7 @@ BOOST_AUTO_TEST_CASE(peerplays_sidechain) { } -#include +#include #include #include diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index e7d0c98b..41b5cc83 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( transfer_benchmark ) //#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" #include #include -#include +#include boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { std::srand(time(NULL)); diff --git a/tests/random/random_tests.cpp b/tests/random/random_tests.cpp index e224439a..747e3192 100644 --- a/tests/random/random_tests.cpp +++ b/tests/random/random_tests.cpp @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_SUITE_END() //#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" #include #include -#include +#include boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { for (int i=1; i diff --git a/tests/tournament/tournament_tests.cpp b/tests/tournament/tournament_tests.cpp index 8aa88479..d5b51ba3 100644 --- a/tests/tournament/tournament_tests.cpp +++ b/tests/tournament/tournament_tests.cpp @@ -2260,7 +2260,7 @@ BOOST_AUTO_TEST_SUITE_END() //#define BOOST_TEST_MODULE "C++ Unit Tests for Graphene Blockchain Database" #include #include -#include +#include boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { std::srand(time(NULL));