make building tests optional:

* disable build specific commandline options when built without tests
This commit is contained in:
Richard Holland
2021-07-05 12:37:29 +02:00
committed by manojsdoshi
parent 90aa3c75a7
commit da26d11593
6 changed files with 480 additions and 411 deletions

View File

@@ -123,6 +123,25 @@ matrix:
- CMAKE_ADD="-Dcoverage=ON" - CMAKE_ADD="-Dcoverage=ON"
- TARGET=coverage_report - TARGET=coverage_report
- SKIP_TESTS=true - SKIP_TESTS=true
# test-free builds
- <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/
compiler: gcc-8
name: no-tests-unity, gcc-8
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
- BUILD_TYPE=Debug
- CMAKE_ADD="-Dtests=OFF"
- SKIP_TESTS=true
- <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/
compiler: clang-8
name: no-tests-non-unity, clang-8
env:
- MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"
- BUILD_TYPE=Debug
- CMAKE_ADD="-Dtests=OFF -Dunity=OFF"
- SKIP_TESTS=true
# nounity # nounity
- <<: *linux - <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/ OR commit_message =~ /travis_run_nounity/ if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/ OR commit_message =~ /travis_run_nounity/

View File

@@ -292,6 +292,7 @@ install (
# WARNING!! -- horrible levelization ahead # WARNING!! -- horrible levelization ahead
# (these files should be isolated or moved...but # (these files should be isolated or moved...but
# unfortunately unit_test.h above creates this dependency) # unfortunately unit_test.h above creates this dependency)
if (tests)
install ( install (
FILES FILES
src/beast/extras/beast/unit_test/amount.hpp src/beast/extras/beast/unit_test/amount.hpp
@@ -311,7 +312,7 @@ install (
FILES FILES
src/beast/extras/beast/unit_test/detail/const_container.hpp src/beast/extras/beast/unit_test/detail/const_container.hpp
DESTINATION include/beast/unit_test/detail) DESTINATION include/beast/unit_test/detail)
endif () #tests
#[===================================================================[ #[===================================================================[
rippled executable rippled executable
#]===================================================================] #]===================================================================]
@@ -325,6 +326,9 @@ add_executable (rippled src/ripple/app/main/Application.h)
if (unity) if (unity)
set_target_properties(rippled PROPERTIES UNITY_BUILD ON) set_target_properties(rippled PROPERTIES UNITY_BUILD ON)
endif () endif ()
if (tests)
target_compile_definitions(rippled PUBLIC ENABLE_TESTS)
endif()
target_sources (rippled PRIVATE target_sources (rippled PRIVATE
#[===============================[ #[===============================[
main sources: main sources:
@@ -655,11 +659,14 @@ target_sources (rippled PRIVATE
src/ripple/shamap/impl/SHAMapNodeID.cpp src/ripple/shamap/impl/SHAMapNodeID.cpp
src/ripple/shamap/impl/SHAMapSync.cpp src/ripple/shamap/impl/SHAMapSync.cpp
src/ripple/shamap/impl/SHAMapTreeNode.cpp src/ripple/shamap/impl/SHAMapTreeNode.cpp
src/ripple/shamap/impl/ShardFamily.cpp src/ripple/shamap/impl/ShardFamily.cpp)
#[===============================[ #[===============================[
test sources: test sources:
subdir: app subdir: app
#]===============================] #]===============================]
if (tests)
target_sources (rippled PRIVATE
src/test/app/AccountDelete_test.cpp src/test/app/AccountDelete_test.cpp
src/test/app/AccountTxPaging_test.cpp src/test/app/AccountTxPaging_test.cpp
src/test/app/AmendmentTable_test.cpp src/test/app/AmendmentTable_test.cpp
@@ -966,6 +973,8 @@ target_sources (rippled PRIVATE
subdir: unit_test subdir: unit_test
#]===============================] #]===============================]
src/test/unit_test/multi_runner.cpp) src/test/unit_test/multi_runner.cpp)
endif () #tests
target_link_libraries (rippled target_link_libraries (rippled
Ripple::boost Ripple::boost
Ripple::opts Ripple::opts
@@ -985,9 +994,11 @@ endif ()
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
# any files that don't play well with unity should be added here # any files that don't play well with unity should be added here
if (tests)
set_source_files_properties( set_source_files_properties(
# these two seem to produce conflicts in beast teardown template methods # these two seem to produce conflicts in beast teardown template methods
src/test/rpc/ValidatorRPC_test.cpp src/test/rpc/ValidatorRPC_test.cpp
src/test/rpc/ShardArchiveHandler_test.cpp src/test/rpc/ShardArchiveHandler_test.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
endif () #tests
endif () endif ()

View File

@@ -1,7 +1,7 @@
#[===================================================================[ #[===================================================================[
docs target (optional) docs target (optional)
#]===================================================================] #]===================================================================]
if (tests)
find_package (Doxygen) find_package (Doxygen)
if (NOT TARGET Doxygen::doxygen) if (NOT TARGET Doxygen::doxygen)
message (STATUS "doxygen executable not found -- skipping docs target") message (STATUS "doxygen executable not found -- skipping docs target")
@@ -76,3 +76,4 @@ add_custom_command (
add_custom_target (docs add_custom_target (docs
DEPENDS "${doxygen_index_file}" DEPENDS "${doxygen_index_file}"
SOURCES "${dependencies}") SOURCES "${dependencies}")
endif ()

View File

@@ -6,6 +6,8 @@ option (assert "Enables asserts, even in release builds" OFF)
option (reporting "Build rippled with reporting mode enabled" OFF) option (reporting "Build rippled with reporting mode enabled" OFF)
option (tests "Build tests" ON)
option (unity "Creates a build using UNITY support in cmake. This is the default" ON) option (unity "Creates a build using UNITY support in cmake. This is the default" ON)
if (unity) if (unity)
if (CMAKE_VERSION VERSION_LESS 3.16) if (CMAKE_VERSION VERSION_LESS 3.16)

View File

@@ -34,8 +34,10 @@
#include <ripple/resource/Fees.h> #include <ripple/resource/Fees.h>
#include <ripple/rpc/RPCHandler.h> #include <ripple/rpc/RPCHandler.h>
#ifdef ENABLE_TESTS
#include <beast/unit_test/match.hpp> #include <beast/unit_test/match.hpp>
#include <test/unit_test/multi_runner.h> #include <test/unit_test/multi_runner.h>
#endif // ENABLE_TESTS
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
@@ -184,6 +186,7 @@ printHelp(const po::options_description& desc)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifdef ENABLE_TESTS
/* simple unit test selector that allows a comma separated list /* simple unit test selector that allows a comma separated list
* of selectors * of selectors
*/ */
@@ -335,6 +338,7 @@ runUnitTests(
} }
} }
#endif // ENABLE_TESTS
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int int
@@ -405,6 +409,7 @@ run(int argc, char** argv)
"DEPRECATED: include with rpc_ip instead. " "DEPRECATED: include with rpc_ip instead. "
"Specify the port number for RPC command."); "Specify the port number for RPC command.");
#ifdef ENABLE_TESTS
po::options_description test("Unit Test Options"); po::options_description test("Unit Test Options");
test.add_options()( test.add_options()(
"quiet,q", "quiet,q",
@@ -433,6 +438,7 @@ run(int argc, char** argv)
"unittest-jobs", "unittest-jobs",
po::value<std::size_t>(), po::value<std::size_t>(),
"Number of unittest jobs to run in parallel (child processes)."); "Number of unittest jobs to run in parallel (child processes).");
#endif // ENABLE_TESTS
// These are hidden options, not intended to be shown in the usage/help // These are hidden options, not intended to be shown in the usage/help
// message // message
@@ -443,20 +449,37 @@ run(int argc, char** argv)
"Specify rpc command and parameters. This option must be repeated " "Specify rpc command and parameters. This option must be repeated "
"for each command/param. Positional parameters also serve this " "for each command/param. Positional parameters also serve this "
"purpose, " "purpose, "
"so this option is not needed for users")( "so this option is not needed for users")
"unittest-child", #ifdef ENABLE_TESTS
"For internal use only when spawning child unit test processes.")( ("unittest-child",
"fg", "Deprecated: server always in foreground mode."); "For internal use only when spawning child unit test processes.")
#else
("unittest", "Disabled in this build.")(
"unittest-child", "Disabled in this build.")
#endif // ENABLE_TESTS
("fg", "Deprecated: server always in foreground mode.");
// Interpret positional arguments as --parameters. // Interpret positional arguments as --parameters.
po::positional_options_description p; po::positional_options_description p;
p.add("parameters", -1); p.add("parameters", -1);
po::options_description all; po::options_description all;
all.add(gen).add(rpc).add(data).add(test).add(hidden); all.add(gen)
.add(rpc)
.add(data)
#ifdef ENABLE_TESTS
.add(test)
#endif // ENABLE_TESTS
.add(hidden);
po::options_description desc; po::options_description desc;
desc.add(gen).add(rpc).add(data).add(test); desc.add(gen)
.add(rpc)
.add(data)
#ifdef ENABLE_TESTS
.add(test)
#endif // ENABLE_TESTS
;
// Parse options, if no error. // Parse options, if no error.
try try
@@ -489,6 +512,14 @@ run(int argc, char** argv)
return 0; return 0;
} }
#ifndef ENABLE_TESTS
if (vm.count("unittest") || vm.count("unittest-child"))
{
std::cerr << "rippled: Tests disabled in this build." << std::endl;
std::cerr << "Try 'rippled --help' for a list of options." << std::endl;
return 1;
}
#else
// Run the unit tests if requested. // Run the unit tests if requested.
// The unit tests will exit the application with an appropriate return code. // The unit tests will exit the application with an appropriate return code.
// //
@@ -528,6 +559,7 @@ run(int argc, char** argv)
return 1; return 1;
} }
} }
#endif // ENABLE_TESTS
auto config = std::make_unique<Config>(); auto config = std::make_unique<Config>();

View File

@@ -31,9 +31,11 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace ripple { namespace ripple {
#ifdef ENABLE_TESTS
namespace test { namespace test {
class ShardArchiveHandler_test; class ShardArchiveHandler_test;
} }
#endif // ENABLE_TESTS
namespace RPC { namespace RPC {
/** Handles the download and import of one or more shard archives. */ /** Handles the download and import of one or more shard archives. */
@@ -42,7 +44,9 @@ class ShardArchiveHandler
public: public:
using TimerOpCounter = using TimerOpCounter =
ClosureCounter<void, boost::system::error_code const&>; ClosureCounter<void, boost::system::error_code const&>;
#ifdef ENABLE_TESTS
friend class test::ShardArchiveHandler_test; friend class test::ShardArchiveHandler_test;
#endif // ENABLE_TESTS
static boost::filesystem::path static boost::filesystem::path
getDownloadDirectory(Config const& config); getDownloadDirectory(Config const& config);