Debian Codegraph @

tests/CMakeLists.txt

raw
1 # Copyright (c) 2014-2022, The Monero Project
2 #
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without modification, are
6 # permitted provided that the following conditions are met:
7 #
8 # 1. Redistributions of source code must retain the above copyright notice, this list of
9 # conditions and the following disclaimer.
10 #
11 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 # of conditions and the following disclaimer in the documentation and/or other
13 # materials provided with the distribution.
14 #
15 # 3. Neither the name of the copyright holder nor the names of its contributors may be
16 # used to endorse or promote products derived from this software without specific
17 # prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31 set(MONERO_WALLET_CRYPTO_BENCH "auto" CACHE STRING "Select wallet crypto libraries for benchmarking")
32
33 # The docs say this only affects grouping in IDEs
34 set(folder "tests")
35 set(TEST_DATA_DIR "${CMAKE_CURRENT_LIST_DIR}/data")
36
37 if (WIN32 AND STATIC)
38 add_definitions(-DSTATICLIB)
39 endif ()
40
41 find_package(GTest)
42
43 if (GTest_FOUND)
44 include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
45 else ()
46 message(STATUS "GTest not found on the system: will use GTest bundled with this source")
47
48 include(ExternalProject)
49 ExternalProject_Add(googletest
50 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gtest
51 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/gtest
52 DOWNLOAD_COMMAND ""
53 UPDATE_COMMAND ""
54 INSTALL_COMMAND ""
55 )
56 add_library(gtest UNKNOWN IMPORTED)
57 add_library(gtest_main UNKNOWN IMPORTED)
58 set_target_properties(gtest PROPERTIES
59 IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/gtest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}"
60 )
61 set_target_properties(gtest_main PROPERTIES
62 IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/gtest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
63 )
64 add_dependencies(gtest googletest)
65 add_dependencies(gtest_main googletest)
66
67 # Emulate the FindGTest module's variable.
68 set(GTEST_LIBRARIES gtest gtest_main)
69 set(GTEST_BOTH_LIBRARIES gtest gtest_main)
70 include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest/include")
71 endif (GTest_FOUND)
72
73 message(STATUS "Copying test data directory...")
74 file(COPY data DESTINATION .) # Copy data directory from source root to build root
75
76 if (CMAKE_BUILD_TYPE STREQUAL "fuzz" OR OSSFUZZ)
77 add_subdirectory(fuzz)
78 else ()
79 add_subdirectory(core_tests)
80 add_subdirectory(fuzz)
81 add_subdirectory(crypto)
82 add_subdirectory(functional_tests)
83 add_subdirectory(performance_tests)
84 add_subdirectory(unit_tests)
85 add_subdirectory(difficulty)
86 add_subdirectory(block_weight)
87 add_subdirectory(hash)
88 add_subdirectory(net_load_tests)
89 endif()
90
91 if (BUILD_GUI_DEPS)
92 add_subdirectory(libwallet_api_tests)
93 endif()
94
95 if (TREZOR_DEBUG)
96 add_subdirectory(trezor)
97 endif()
98
99 # add_subdirectory(daemon_tests)
100
101 set(hash_targets_sources
102 hash-target.cpp)
103
104 set(hash_targets_headers)
105
106 monero_add_minimal_executable(hash-target-tests
107 ${hash_targets_sources}
108 ${hash_targets_headers})
109 target_link_libraries(hash-target-tests
110 PRIVATE
111 cryptonote_core)
112 set_property(TARGET hash-target-tests
113 PROPERTY
114 FOLDER "${folder}")
115
116 add_test(
117 NAME hash-target
118 COMMAND hash-target-tests)
119
120 #
121 # Configure wallet crypto benchmark
122 #
123 if (${MONERO_WALLET_CRYPTO_BENCH} STREQUAL "auto")
124 set(MONERO_WALLET_CRYPTO_BENCH "cn")
125 monero_crypto_autodetect(AVAILABLE BEST)
126 if (DEFINED AVAILABLE)
127 list(APPEND MONERO_WALLET_CRYPTO_BENCH ${AVAILABLE})
128 endif ()
129 message("Wallet crypto bench is using ${MONERO_WALLET_CRYPTO_BENCH}")
130 endif ()
131
132 list(REMOVE_DUPLICATES MONERO_WALLET_CRYPTO_BENCH)
133 list(REMOVE_ITEM MONERO_WALLET_CRYPTO_BENCH "cn") # always used for comparison
134 set(MONERO_WALLET_CRYPTO_BENCH_NAMES "(cn)")
135 foreach(BENCH IN LISTS MONERO_WALLET_CRYPTO_BENCH)
136 monero_crypto_valid(${BENCH} VALID)
137 if (NOT VALID)
138 message(FATAL_ERROR "Invalid MONERO_WALLET_CRYPTO_BENCH option ${BENCH}")
139 endif ()
140
141 monero_crypto_get_target(${BENCH} BENCH_LIBRARY)
142 list(APPEND BENCH_OBJECTS $<TARGET_OBJECTS:${BENCH_LIBRARY}>)
143
144 monero_crypto_get_namespace(${BENCH} BENCH_NAMESPACE)
145 set(MONERO_WALLET_CRYPTO_BENCH_NAMES "${MONERO_WALLET_CRYPTO_BENCH_NAMES}(${BENCH_NAMESPACE})")
146 endforeach ()
147
148 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/benchmark.h.in" "${MONERO_GENERATED_HEADERS_DIR}/tests/benchmark.h")
149 monero_add_minimal_executable(monero-wallet-crypto-bench benchmark.cpp ${BENCH_OBJECTS})
150 target_link_libraries(monero-wallet-crypto-bench cncrypto)
151
152 add_test(NAME wallet-crypto-bench COMMAND monero-wallet-crypto-bench)
153
154
155 set(enabled_tests
156 core_tests
157 difficulty
158 block_weight
159 hash
160 performance_tests
161 fuzz
162 unit_tests)
163
164 add_custom_target(tests DEPENDS enabled_tests)
165 set_property(TARGET tests PROPERTY FOLDER "${folder}")