| 1 |
# Copyright (c) 2010, 2026, Oracle and/or its affiliates. |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License, version 2.0, |
| 5 |
# as published by the Free Software Foundation. |
| 6 |
# |
| 7 |
# This program is designed to work with certain software (including |
| 8 |
# but not limited to OpenSSL) that is licensed under separate terms, |
| 9 |
# as designated in a particular file or component or in included license |
| 10 |
# documentation. The authors of MySQL hereby grant you an additional |
| 11 |
# permission to link the program and your derivative works with the |
| 12 |
# separately licensed software that they have either included with |
| 13 |
# the program or referenced in the documentation. |
| 14 |
# |
| 15 |
# This program is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU General Public License, version 2.0, for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU General Public License |
| 21 |
# along with this program; if not, write to the Free Software |
| 22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 |
|
| 24 |
IF(NOT WITH_UNIT_TESTS) |
| 25 |
RETURN() |
| 26 |
ENDIF() |
| 27 |
|
| 28 |
MSVC_CPPCHECK_DISABLE() |
| 29 |
|
| 30 |
IF(WITH_LTO OR CMAKE_COMPILER_FLAG_WITH_LTO) |
| 31 |
# We get ODR violations because of multiple bison parsers. |
| 32 |
MY_CHECK_CXX_COMPILER_WARNING("error=odr" HAS_WARN_FLAG) |
| 33 |
IF(HAS_WARN_FLAG) |
| 34 |
STRING_APPEND(CMAKE_EXE_LINKER_FLAGS " ${HAS_WARN_FLAG}") |
| 35 |
ENDIF() |
| 36 |
ENDIF() |
| 37 |
|
| 38 |
# Some tests require Boost. |
| 39 |
INCLUDE_DIRECTORIES(SYSTEM ${BOOST_PATCHES_DIR} ${BOOST_INCLUDE_DIR}) |
| 40 |
|
| 41 |
INCLUDE_DIRECTORIES(SYSTEM ${GMOCK_INCLUDE_DIRS}) |
| 42 |
|
| 43 |
# TODO(sgunders): Remove when all GMock tests use MOCK_METHOD(). |
| 44 |
STRING(REPLACE "-Wsuggest-override" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 45 |
|
| 46 |
MY_CHECK_CXX_COMPILER_FLAG("-fno-builtin-memcmp" HAVE_NO_BUILTIN_MEMCMP) |
| 47 |
|
| 48 |
SET(DISABLE_PSI_DEFINITIONS |
| 49 |
"DISABLE_PSI_COND" |
| 50 |
"DISABLE_PSI_FILE" |
| 51 |
"DISABLE_PSI_MEMORY" |
| 52 |
"DISABLE_PSI_METADATA" |
| 53 |
"DISABLE_PSI_MUTEX" |
| 54 |
"DISABLE_PSI_RWLOCK" |
| 55 |
"DISABLE_PSI_STAGE" |
| 56 |
) |
| 57 |
|
| 58 |
# Set these in the cache to make them available globally |
| 59 |
SET(DISABLE_PSI_DEFINITIONS ${DISABLE_PSI_DEFINITIONS} CACHE INTERNAL "") |
| 60 |
|
| 61 |
# Set up valgrind options to use with ctest. |
| 62 |
# Use `ctest (...) -D ExperimentalMemCheck` to run. |
| 63 |
IF(LINUX OR FREEBSD) |
| 64 |
FIND_PROGRAM(MEMORYCHECK_COMMAND valgrind) |
| 65 |
SET(MEMORYCHECK_COMMAND_OPTIONS |
| 66 |
"--leak-check=full --errors-for-leak-kinds=definite,indirect --error-exitcode=42" |
| 67 |
CACHE INTERNAL "") |
| 68 |
SET(MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/mysql-test/valgrind.supp" |
| 69 |
CACHE INTERNAL "") |
| 70 |
ENDIF() |
| 71 |
|
| 72 |
# main-wrapper libraries (with tap-compatible option). |
| 73 |
ADD_LIBRARY(gunit_small STATIC |
| 74 |
benchmark.cc |
| 75 |
fake_costmodel.cc |
| 76 |
gunit_test_main.cc |
| 77 |
skip_trailing.cc |
| 78 |
strnxfrm.cc |
| 79 |
thread_utils.cc |
| 80 |
fake_table.cc |
| 81 |
) |
| 82 |
SET_TARGET_PROPERTIES(gunit_small |
| 83 |
PROPERTIES COMPILE_DEFINITIONS "${DISABLE_PSI_DEFINITIONS}" |
| 84 |
) |
| 85 |
|
| 86 |
ADD_STATIC_LIBRARY(gunit_large |
| 87 |
benchmark.cc |
| 88 |
gunit_test_main_server.cc |
| 89 |
test_utils.cc |
| 90 |
thread_utils.cc |
| 91 |
LINK_LIBRARIES ext::icu ext::zlib extra::unordered_dense |
| 92 |
) |
| 93 |
|
| 94 |
# Add a library for enable_win_jemalloc.cc |
| 95 |
# and link it with both gunit_small and gunit_large below. |
| 96 |
UNSET(UNITTEST_JEMALLOC_LIB) |
| 97 |
IF(WIN32) |
| 98 |
ADD_LIBRARY(unittest_jemalloc STATIC ../../sql/enable_win_jemalloc.cc) |
| 99 |
SET(UNITTEST_JEMALLOC_LIB unittest_jemalloc) |
| 100 |
ENDIF() |
| 101 |
|
| 102 |
ADD_DEPENDENCIES(gunit_small GenError) |
| 103 |
ADD_DEPENDENCIES(gunit_large GenError) |
| 104 |
TARGET_LINK_LIBRARIES(gunit_small |
| 105 |
mysys strings ${GTEST_LIBRARIES} ${UNITTEST_JEMALLOC_LIB} extra::rapidjson) |
| 106 |
TARGET_LINK_LIBRARIES(gunit_large |
| 107 |
mysys strings ${GTEST_LIBRARIES} ${UNITTEST_JEMALLOC_LIB} extra::rapidjson) |
| 108 |
|
| 109 |
IF(WIN32) |
| 110 |
## Create an object library of nt_servc.cc, so we don't have to |
| 111 |
## compile it again for each target |
| 112 |
ADD_LIBRARY(my_nt_servc OBJECT ../../sql/nt_servc.cc) |
| 113 |
ENDIF() |
| 114 |
|
| 115 |
# Add some defines. |
| 116 |
ADD_DEFINITIONS(-DMYSQL_SERVER -DEXTRA_CODE_FOR_UNIT_TESTING) |
| 117 |
ADD_DEFINITIONS(-DERRMSG_DIR="${PROJECT_BINARY_DIR}/share") |
| 118 |
ADD_DEFINITIONS(-DDATA_DIR="${CMAKE_CURRENT_BINARY_DIR}") |
| 119 |
|
| 120 |
# Add tests (link them with gunit/gmock libraries) |
| 121 |
SET(TESTS |
| 122 |
alignment |
| 123 |
bitmap |
| 124 |
bounds_checked_array |
| 125 |
byteorder |
| 126 |
calloc |
| 127 |
charset_bug28956360 |
| 128 |
charset_bug32788301 |
| 129 |
collation_loader |
| 130 |
cost_estimate |
| 131 |
dbug |
| 132 |
decimal |
| 133 |
dns_srv_data |
| 134 |
dphyp |
| 135 |
dynarray |
| 136 |
filesort_buffer |
| 137 |
filesort_compare |
| 138 |
filesort_mergechunk |
| 139 |
inplace_vector |
| 140 |
integer_digits |
| 141 |
intrusive_list_iterator |
| 142 |
key |
| 143 |
like_range |
| 144 |
m_string |
| 145 |
mdl |
| 146 |
mem_root_deque |
| 147 |
mutex_lock |
| 148 |
my_alloc |
| 149 |
my_bitmap |
| 150 |
my_error |
| 151 |
my_fileutils |
| 152 |
my_gcvt |
| 153 |
my_murmur3 |
| 154 |
my_rcu_lock |
| 155 |
my_thread |
| 156 |
my_timer |
| 157 |
mysys_base64 |
| 158 |
mysys_lf |
| 159 |
mysys_my_b_vprintf |
| 160 |
mysys_my_checksum |
| 161 |
mysys_my_getopt |
| 162 |
mysys_my_getpw |
| 163 |
mysys_my_loadpath |
| 164 |
mysys_my_malloc |
| 165 |
mysys_my_pwrite |
| 166 |
mysys_my_rdtsc |
| 167 |
mysys_my_read |
| 168 |
mysys_my_symlink |
| 169 |
mysys_my_time |
| 170 |
mysys_my_write |
| 171 |
mysys_pathfuncs |
| 172 |
opt_recperkey |
| 173 |
overflow_bitset |
| 174 |
partitioned_rwlock |
| 175 |
pattern_matcher |
| 176 |
prealloced_array |
| 177 |
priority_queue |
| 178 |
pump_object_filter |
| 179 |
record_buffer |
| 180 |
sql_class_header |
| 181 |
sql_list |
| 182 |
sql_plist |
| 183 |
sql_string |
| 184 |
stl_alloc |
| 185 |
stream_cipher |
| 186 |
strings_skip_trailing |
| 187 |
strings_strnxfrm |
| 188 |
strings_utf8 |
| 189 |
strings_valid_check |
| 190 |
strtod |
| 191 |
strtoll |
| 192 |
template_utils |
| 193 |
thread_utils |
| 194 |
timespec |
| 195 |
unhex |
| 196 |
val_int_compare |
| 197 |
) |
| 198 |
|
| 199 |
SET(ALL_SMALL_TESTS) |
| 200 |
FOREACH(test ${TESTS}) |
| 201 |
LIST(APPEND ALL_SMALL_TESTS ${test}-t.cc) |
| 202 |
ENDFOREACH() |
| 203 |
|
| 204 |
# Add tests (link them with gunit/gmock libraries and the server libraries) |
| 205 |
SET(SERVER_TESTS |
| 206 |
bgc_ticket_manager |
| 207 |
character_set_deprecation |
| 208 |
compare_access_paths |
| 209 |
connect_joins |
| 210 |
copy_info |
| 211 |
create_field |
| 212 |
dd_cache |
| 213 |
dd_column_statistics |
| 214 |
dd_info_schema_native_func |
| 215 |
dd_pfs |
| 216 |
dd_properties |
| 217 |
dd_schema |
| 218 |
dd_sdi |
| 219 |
dd_string_type |
| 220 |
dd_table |
| 221 |
debug_sync |
| 222 |
decoy_user |
| 223 |
explain_filename |
| 224 |
field |
| 225 |
get_diagnostics |
| 226 |
gis_algos |
| 227 |
gis_area |
| 228 |
gis_buffer |
| 229 |
gis_difference |
| 230 |
gis_distance |
| 231 |
gis_frechet_distance |
| 232 |
gis_geometries |
| 233 |
gis_hausdorff_distance |
| 234 |
gis_intersection |
| 235 |
gis_is_simple |
| 236 |
gis_isvalid |
| 237 |
gis_line_interpolate_point |
| 238 |
gis_relops |
| 239 |
gis_rtree_support |
| 240 |
gis_setops |
| 241 |
gis_srs |
| 242 |
gis_symdifference |
| 243 |
gis_transform |
| 244 |
gis_union |
| 245 |
gis_wkb_parser |
| 246 |
gis_wkb_writer |
| 247 |
graph_simplification |
| 248 |
handler |
| 249 |
hash_join |
| 250 |
histograms |
| 251 |
histogram_selectivity |
| 252 |
hypergraph_optimizer |
| 253 |
initialize_password |
| 254 |
insert_delayed |
| 255 |
interesting_orders |
| 256 |
into_syntax |
| 257 |
item |
| 258 |
item_filter |
| 259 |
item_func_case |
| 260 |
item_func_now_local |
| 261 |
item_func_regexp |
| 262 |
item_json_func |
| 263 |
item_like |
| 264 |
item_timefunc |
| 265 |
join_syntax |
| 266 |
join_tab_sort |
| 267 |
json_binary |
| 268 |
json_dom |
| 269 |
json_path |
| 270 |
locking_clause_syntax |
| 271 |
locking_service |
| 272 |
log_throttle |
| 273 |
log_timestamp |
| 274 |
make_sortkey |
| 275 |
mdl_sync |
| 276 |
my_decimal |
| 277 |
mysqld_funcs |
| 278 |
opt_costconstants |
| 279 |
opt_costmodel |
| 280 |
opt_guessrecperkey |
| 281 |
opt_range |
| 282 |
opt_ref |
| 283 |
opt_trace |
| 284 |
persisted_variables |
| 285 |
protocol_classic |
| 286 |
regexp_engine |
| 287 |
regexp_facade |
| 288 |
security_context |
| 289 |
segfault |
| 290 |
select_lex_visitor |
| 291 |
sha2_password |
| 292 |
sql_table |
| 293 |
subquery_syntax |
| 294 |
table_cache |
| 295 |
table_factor_syntax |
| 296 |
table_list |
| 297 |
tc_log_mmap |
| 298 |
temptable_allocator |
| 299 |
temptable_storage |
| 300 |
thd_manager |
| 301 |
union_syntax |
| 302 |
unique |
| 303 |
value_map |
| 304 |
walk_access_paths |
| 305 |
wild_case_compare |
| 306 |
ha_info_iterator |
| 307 |
xid_extract |
| 308 |
log_event_status_size |
| 309 |
) |
| 310 |
# Endless loop in FatalSignalDeathTest |
| 311 |
IF(LINUX_ALPINE) |
| 312 |
LIST(REMOVE_ITEM SERVER_TESTS segfault) |
| 313 |
ENDIF() |
| 314 |
|
| 315 |
IF(MY_COMPILER_IS_GNU AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12) |
| 316 |
ADD_COMPILE_FLAGS(regexp_engine-t.cc COMPILE_FLAGS "-Wno-restrict") |
| 317 |
ENDIF() |
| 318 |
|
| 319 |
IF(WIN32) |
| 320 |
LIST(APPEND SERVER_TESTS win_tests) |
| 321 |
ENDIF() |
| 322 |
|
| 323 |
# Suppress -Wformat-overflow= for my_safe_snprintf(" %s ", nullptr) |
| 324 |
MY_CHECK_CXX_COMPILER_WARNING("format-overflow" HAS_WARN_FLAG) |
| 325 |
IF(HAS_WARN_FLAG) |
| 326 |
ADD_COMPILE_FLAGS(segfault-t.cc COMPILE_FLAGS ${HAS_WARN_FLAG}) |
| 327 |
ENDIF() |
| 328 |
|
| 329 |
# Warnings about missing PGO profile data are not useful for unit tests. |
| 330 |
DISABLE_MISSING_PROFILE_WARNING() |
| 331 |
|
| 332 |
SET(ALL_LARGE_TESTS) |
| 333 |
FOREACH(test ${SERVER_TESTS}) |
| 334 |
LIST(APPEND ALL_LARGE_TESTS ${test}-t.cc) |
| 335 |
ENDFOREACH() |
| 336 |
|
| 337 |
SET(SQL_GUNIT_LIB_SOURCE |
| 338 |
${CMAKE_SOURCE_DIR}/sql/filesort_utils.cc |
| 339 |
${CMAKE_SOURCE_DIR}/sql/mdl.cc |
| 340 |
${CMAKE_SOURCE_DIR}/sql/stream_cipher.cc |
| 341 |
${CMAKE_SOURCE_DIR}/sql/sql_list.cc |
| 342 |
${CMAKE_SOURCE_DIR}/sql/stateless_allocator.cc |
| 343 |
${CMAKE_SOURCE_DIR}/sql-common/sql_string.cc |
| 344 |
${CMAKE_SOURCE_DIR}/sql/thr_malloc.cc |
| 345 |
${CMAKE_SOURCE_DIR}/sql/join_optimizer/hypergraph.cc |
| 346 |
${CMAKE_SOURCE_DIR}/sql/join_optimizer/online_cycle_finder.cc |
| 347 |
${CMAKE_SOURCE_DIR}/sql/join_optimizer/overflow_bitset.cc |
| 348 |
${CMAKE_SOURCE_DIR}/sql/locks/shared_spin_lock.cc |
| 349 |
) |
| 350 |
|
| 351 |
ADD_LIBRARY(sqlgunitlib STATIC ${SQL_GUNIT_LIB_SOURCE}) |
| 352 |
ADD_DEPENDENCIES(sqlgunitlib GenError) |
| 353 |
SET_TARGET_PROPERTIES(sqlgunitlib |
| 354 |
PROPERTIES COMPILE_DEFINITIONS "${DISABLE_PSI_DEFINITIONS}" |
| 355 |
) |
| 356 |
|
| 357 |
MYSQL_ADD_EXECUTABLE(merge_small_tests-t ${ALL_SMALL_TESTS} |
| 358 |
ADD_TEST merge_small_tests |
| 359 |
COMPILE_DEFINITIONS ${DISABLE_PSI_DEFINITIONS} |
| 360 |
ENABLE_EXPORTS |
| 361 |
EXCLUDE_FROM_GCOV |
| 362 |
LINK_LIBRARIES sqlgunitlib gunit_small extra::rapidjson |
| 363 |
) |
| 364 |
|
| 365 |
IF(WIN32) |
| 366 |
LIST(APPEND ALL_LARGE_TESTS ../../sql/nt_servc.cc) |
| 367 |
ENDIF() |
| 368 |
LIST(APPEND ALL_LARGE_TESTS ../../storage/example/ha_example.cc) |
| 369 |
|
| 370 |
MYSQL_ADD_EXECUTABLE(merge_large_tests-t ${ALL_LARGE_TESTS} |
| 371 |
ADD_TEST merge_large_tests |
| 372 |
ENABLE_EXPORTS |
| 373 |
EXCLUDE_FROM_GCOV |
| 374 |
LINK_LIBRARIES gunit_large server_unittest_library |
| 375 |
) |
| 376 |
|
| 377 |
FOREACH(test ${TESTS}) |
| 378 |
MYSQL_ADD_EXECUTABLE(${test}-t ${test}-t.cc |
| 379 |
COMPILE_DEFINITIONS ${DISABLE_PSI_DEFINITIONS} |
| 380 |
ENABLE_EXPORTS |
| 381 |
EXCLUDE_FROM_ALL |
| 382 |
LINK_LIBRARIES sqlgunitlib gunit_small |
| 383 |
SKIP_INSTALL |
| 384 |
ADD_GCOV_TEST ${test} |
| 385 |
) |
| 386 |
ENDFOREACH() |
| 387 |
|
| 388 |
# Disable by default, since it dumps a stack trace. |
| 389 |
# We don't want ppl to think there was a segfault or something. |
| 390 |
# See also the mtr test main.print_stacktrace |
| 391 |
MYSQL_ADD_EXECUTABLE(mysys_stacktrace-t mysys_stacktrace-t.cc |
| 392 |
COMPILE_DEFINITIONS ${DISABLE_PSI_DEFINITIONS} |
| 393 |
ENABLE_EXPORTS |
| 394 |
EXCLUDE_FROM_ALL |
| 395 |
LINK_LIBRARIES sqlgunitlib gunit_small |
| 396 |
SKIP_INSTALL |
| 397 |
) |
| 398 |
|
| 399 |
# See comments about __builtin_memcmp in the source file. |
| 400 |
IF(HAVE_NO_BUILTIN_MEMCMP) |
| 401 |
ADD_COMPILE_FLAGS( |
| 402 |
filesort_compare-t.cc |
| 403 |
COMPILE_FLAGS "-fno-builtin-memcmp" |
| 404 |
) |
| 405 |
ENDIF() |
| 406 |
|
| 407 |
FOREACH(test ${SERVER_TESTS}) |
| 408 |
SET(SRC_FILES ${test}-t.cc) |
| 409 |
IF(WIN32) |
| 410 |
LIST(APPEND SRC_FILES $<TARGET_OBJECTS:my_nt_servc>) |
| 411 |
ENDIF() |
| 412 |
IF(test MATCHES "table_cache") |
| 413 |
LIST(APPEND SRC_FILES ../../storage/example/ha_example.cc) |
| 414 |
ENDIF() |
| 415 |
MYSQL_ADD_EXECUTABLE(${test}-t ${SRC_FILES} |
| 416 |
ENABLE_EXPORTS |
| 417 |
EXCLUDE_FROM_ALL |
| 418 |
LINK_LIBRARIES gunit_large server_unittest_library |
| 419 |
SKIP_INSTALL |
| 420 |
ADD_GCOV_TEST ${test} |
| 421 |
) |
| 422 |
ENDFOREACH() |
| 423 |
|
| 424 |
ADD_LIBRARY(rpl_channel_credentials_lib STATIC |
| 425 |
${CMAKE_SOURCE_DIR}/sql/rpl_channel_credentials.cc |
| 426 |
) |
| 427 |
|
| 428 |
MYSQL_ADD_EXECUTABLE(rpl_channel_credentials-t rpl_channel_credentials-t.cc |
| 429 |
ENABLE_EXPORTS |
| 430 |
ADD_TEST rpl_channel_credentials |
| 431 |
LINK_LIBRARIES rpl_channel_credentials_lib gunit_small |
| 432 |
) |
| 433 |
|
| 434 |
ADD_LIBRARY(rpl_commit_order_queue_lib STATIC |
| 435 |
${CMAKE_SOURCE_DIR}/sql/changestreams/apply/commit_order_queue.cc |
| 436 |
) |
| 437 |
|
| 438 |
MYSQL_ADD_EXECUTABLE(rpl_commit_order_queue-t rpl_commit_order_queue-t.cc |
| 439 |
ENABLE_EXPORTS |
| 440 |
ADD_TEST rpl_commit_order_queue |
| 441 |
LINK_LIBRARIES rpl_commit_order_queue_lib gunit_small sqlgunitlib |
| 442 |
) |
| 443 |
|
| 444 |
ADD_SUBDIRECTORY(ddl_rewriter) |
| 445 |
ADD_SUBDIRECTORY(innodb) |
| 446 |
ADD_SUBDIRECTORY(keyring) |
| 447 |
ADD_SUBDIRECTORY(components/mysql_server) |
| 448 |
ADD_SUBDIRECTORY(components/keyring_common) |
| 449 |
ADD_SUBDIRECTORY(xplugin) |
| 450 |
ADD_SUBDIRECTORY(group_replication) |
| 451 |
ADD_SUBDIRECTORY(libmysqlgcs) |
| 452 |
ADD_SUBDIRECTORY(temptable) |
| 453 |
ADD_SUBDIRECTORY(binlogevents) |
| 454 |
ADD_SUBDIRECTORY(memory) |
| 455 |
ADD_SUBDIRECTORY(containers) |
| 456 |
ADD_SUBDIRECTORY(locks) |
| 457 |
ADD_SUBDIRECTORY(changestreams) |