From e54b23eb1c22bddb8aecf90ded5fcb0d128c60b3 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Tue, 6 Aug 2024 19:51:16 +0300 Subject: [PATCH 01/44] Add tests for util/datetime into listfile (#155) --- util/CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 7fa756c4fa..c064dad7a9 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,7 +1,43 @@ add_subdirectory(charset) add_subdirectory(draft) +function(add_ydb_util_tests) + set(opts "") + set(oneval_args FOLDER) + set(multival_args TESTS LINK_LIBRARIES) + cmake_parse_arguments(ARGS + "${opts}" + "${oneval_args}" + "${multival_args}" + ${ARGN} + ) + list(PREPEND ARGS_LINK_LIBRARIES + yutil + cpp-testing-unittest_main + ) + foreach (__test_name_suffix IN LISTS ARGS_TESTS) + add_ydb_test(NAME "util-${ARGS_FOLDER}-${__test_name_suffix}" + SOURCES + "${ARGS_FOLDER}/${__test_name_suffix}.cpp" + LINK_LIBRARIES + ${ARGS_LINK_LIBRARIES} + LABELS + unit + ) + endforeach() +endfunction() + if (YDB_SDK_TESTS) + add_ydb_util_tests(FOLDER datetime + TESTS + base_ut + cputimer_ut + parser_deprecated_ut + parser_ut + process_uptime_ut + uptime_ut + ) + add_ydb_test(NAME util-digest-ut SOURCES digest/city_ut.cpp @@ -70,6 +106,7 @@ target_joined_source(yutil ${YDB_SDK_SOURCE_DIR}/util/datetime/base.cpp ${YDB_SDK_SOURCE_DIR}/util/datetime/constants.cpp ${YDB_SDK_SOURCE_DIR}/util/datetime/cputimer.cpp + ${YDB_SDK_SOURCE_DIR}/util/datetime/process_uptime.cpp ${YDB_SDK_SOURCE_DIR}/util/datetime/systime.cpp ${YDB_SDK_SOURCE_DIR}/util/datetime/uptime.cpp ) From d069898365539213519a71b45bdd8b04e2c8add2 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 16:05:58 +0300 Subject: [PATCH 02/44] Wrap other tests with 'add_ydb_util_tests' --- util/CMakeLists.txt | 61 +++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index c064dad7a9..4eff1ce50c 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -38,48 +38,37 @@ if (YDB_SDK_TESTS) uptime_ut ) - add_ydb_test(NAME util-digest-ut - SOURCES - digest/city_ut.cpp - digest/fnv_ut.cpp - digest/multi_ut.cpp - digest/murmur_ut.cpp - digest/sequence_ut.cpp - LINK_LIBRARIES - yutil - cpp-testing-unittest_main - LABELS - unit + add_ydb_util_tests(FOLDER digest + TESTS + city_ut + fnv_ut + multi_ut + murmur_ut + sequence_ut ) - add_ydb_test(NAME util-folder-ut - SOURCES - folder/dirut_ut.cpp - folder/filelist_ut.cpp - folder/fts_ut.cpp - folder/iterator_ut.cpp - folder/path_ut.cpp - folder/pathsplit_ut.cpp + + add_ydb_util_tests(FOLDER folder + TESTS + dirut_ut + filelist_ut + fts_ut + iterator_ut + path_ut + pathsplit_ut LINK_LIBRARIES - yutil - cpp-testing-unittest_main threading-future - LABELS - unit ) - add_ydb_test(NAME util-network-ut - SOURCES - network/address_ut.cpp - network/endpoint_ut.cpp - network/ip_ut.cpp - network/poller_ut.cpp - network/sock_ut.cpp - network/socket_ut.cpp + + add_ydb_util_tests(FOLDER network + TESTS + address_ut + endpoint_ut + ip_ut + poller_ut + sock_ut + socket_ut LINK_LIBRARIES - yutil - cpp-testing-unittest_main threading-future - LABELS - unit ) endif() From 3e9713a2353a865e45765e12743986607aa98c24 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 16:40:16 +0300 Subject: [PATCH 03/44] Add tests for util/generic into listfile (#158) --- util/CMakeLists.txt | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 4eff1ce50c..f6c27d515c 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -59,6 +59,79 @@ if (YDB_SDK_TESTS) threading-future ) + add_ydb_util_tests(FOLDER generic + TESTS + adaptor_ut + algorithm_ut + array_ref_ut + array_size_ut + bitmap_ut + bitops_ut + buffer_ut + cast_ut + deque_ut + enum_range_ut + explicit_type_ut + flags_ut + function_ref_ut + function_ut + guid_ut + hash_primes_ut + hash_ut + intrlist_ut + is_in_ut + iterator_range_ut + iterator_ut + lazy_value_ut + list_ut + mapfindptr_ut + map_ut + maybe_ut + mem_copy_ut + objects_counter_ut + overloaded_ut + ptr_ut + queue_ut + scope_ut + serialized_enum_ut + set_ut + singleton_ut + size_literals_ut + stack_ut + store_policy_ut + strbuf_ut + # TODO: either add library/cpp/containers/absl_flat_hash + # or use __cplusplus macro to switch to C++20 and use std::unordered_set + # string_transparent_hash_ut + string_ut + typelist_ut + typetraits_ut + utility_ut + va_args_ut + vector_ut + xrange_ut + ylimits_ut + ymath_ut + ) + + add_ydb_test(NAME util-generic-yexception_ut + SOURCES + generic/yexception_ut.c + generic/yexception_ut.cpp + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit + ) + if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin)$") + target_compile_definitions(util-generic-yexception_ut + PRIVATE + LIBCXX_BUILDING_LIBCXXRT + LIBCXX_BUILDING_LIBGCC + ) + endif() + add_ydb_util_tests(FOLDER network TESTS address_ut From d7420351ea49ca6378d31d2ba0a717e39d921aad Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 16:43:34 +0300 Subject: [PATCH 04/44] Add tests for util/memory into listfile (#159) --- util/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index f6c27d515c..8987807cbe 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -132,6 +132,15 @@ if (YDB_SDK_TESTS) ) endif() + add_ydb_util_tests(FOLDER memory + TESTS + addstorage_ut + blob_ut + pool_ut + smallobj_ut + tempbuf_ut + ) + add_ydb_util_tests(FOLDER network TESTS address_ut From 1137eba8dc14e3235155eb85c0a8ebbbc22a0fe5 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 17:02:24 +0300 Subject: [PATCH 05/44] Add tests for util/random into listfile (#161) --- util/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 8987807cbe..f262a86cad 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -141,6 +141,19 @@ if (YDB_SDK_TESTS) tempbuf_ut ) + add_ydb_util_tests(FOLDER random + TESTS + # TODO: fix common_ops_ut: TestStlCompatibility + common_ops_ut + easy_ut + entropy_ut + fast_ut + mersenne_ut + normal_ut + random_ut + shuffle_ut + ) + add_ydb_util_tests(FOLDER network TESTS address_ut From 8e32c0f9fe1229bd9d422ea76ae64e535f8ac221 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 17:07:15 +0300 Subject: [PATCH 06/44] Add tests for util/stream into listfile (#162) --- util/CMakeLists.txt | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index f262a86cad..7c5d908ac9 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -141,6 +141,18 @@ if (YDB_SDK_TESTS) tempbuf_ut ) + add_ydb_util_tests(FOLDER network + TESTS + address_ut + endpoint_ut + ip_ut + poller_ut + sock_ut + socket_ut + LINK_LIBRARIES + threading-future + ) + add_ydb_util_tests(FOLDER random TESTS # TODO: fix common_ops_ut: TestStlCompatibility @@ -154,16 +166,28 @@ if (YDB_SDK_TESTS) shuffle_ut ) - add_ydb_util_tests(FOLDER network + add_ydb_util_tests(FOLDER stream TESTS - address_ut - endpoint_ut - ip_ut - poller_ut - sock_ut - socket_ut - LINK_LIBRARIES - threading-future + aligned_ut + buffered_ut + buffer_ut + direct_io_ut + file_ut + format_std_ut + format_ut + hex_ut + input_ut + ios_ut + labeled_ut + length_ut + mem_ut + multi_ut + printf_ut + str_ut + tokenizer_ut + walk_ut + zerocopy_output_ut + zlib_ut ) endif() From b910b57cf5fc5588397cdc4e96e3ddc841543fb0 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 17:13:05 +0300 Subject: [PATCH 07/44] Add tests for util/string into listfile (#163) --- util/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 7c5d908ac9..91cfd4478f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -189,6 +189,24 @@ if (YDB_SDK_TESTS) zerocopy_output_ut zlib_ut ) + + add_ydb_util_tests(FOLDER string + TESTS + ascii_ut + builder_ut + cast_ut + escape_ut + hex_ut + join_ut + printf_ut + split_ut + strip_ut + strspn_ut + subst_ut + type_ut + util_ut + vector_ut + ) endif() _ydb_sdk_add_library(yutil) From fcc2203bf2e06465af70d0674e3d464246440586 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 17:17:04 +0300 Subject: [PATCH 08/44] Add tests for util/system into listfile (#164) --- util/CMakeLists.txt | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 91cfd4478f..04847bb696 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -207,6 +207,93 @@ if (YDB_SDK_TESTS) util_ut vector_ut ) + + add_ydb_util_tests(FOLDER system + TESTS + align_ut + atexit_ut + backtrace_ut + byteorder_ut + compat_ut + compiler_ut + condvar_ut + context_ut + cpu_id_ut + daemon_ut + datetime_ut + # TODO: direct_io_ut freezes + direct_io_ut + env_ut + error_ut + event_ut + execpath_ut + filemap_ut + file_ut + flock_ut + # TODO: fix fstat_ut + # TestFileStat::SymlinkToExistingFileTest + # TestFileStat::SymlinkToNonExistingFileTest + # TestFileStat::SymlinkToFileThatCantExistTest + fstat_ut + fs_ut + getpid_ut + guard_ut + hi_lo_ut + hostname_ut + info_ut + interrupt_signals_ut + mem_info_ut + mincore_ut + mktemp_ut + mutex_ut + nice_ut + pipe_ut + platform_ut + # TODO: fix progname_ut + # TProgramNameTest::TestIt + progname_ut + rusage_ut + rwlock_ut + sanitizers_ut + shellcommand_ut + shmat_ut + spinlock_ut + # TODO: fix src_location_ut + # TestLocation::Test1 + src_location_ut + # TODO: fix src_root_ut + # TestSourceRoot::TestStrip + src_root_ut + tempfile_ut + # TODO: fix thread_ut + # TSysThreadTest::TestSetGetThreadNameInChildThread + thread_ut + tls_ut + # TODO: fix type_name_ut + # TypeName::FromWellKnownTypes + # TypeName::FromWellKnownValues + # TypeName::FromWellKnownValues + type_name_ut + types_ut + # TODO: add library/cpp/testing/benchmark + # depends only on NBench::Clobber, that's a memory optimization barrier + # unaligned_mem_ut + user_ut + yassert_ut + ) + + if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_ydb_test(NAME util-system-fs_win_ut + SOURCES + system/fs_win_ut.cpp + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit + ) + endif() + endif() _ydb_sdk_add_library(yutil) From 57cfadc3fb45b464f607c151d54643313b3d2e83 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 18:07:27 +0300 Subject: [PATCH 09/44] Add tests for util/thread into listfile (#165) --- util/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 04847bb696..3fe4e1803d 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -294,6 +294,16 @@ if (YDB_SDK_TESTS) ) endif() + add_ydb_util_tests(FOLDER thread + TESTS + factory_ut + lfqueue_ut + lfstack_ut + pool_ut + singleton_ut + LINK_LIBRARIES + threading-future + ) endif() _ydb_sdk_add_library(yutil) From e3f91c8a85e7858d5b1f5186b6316ff6a09cfa1d Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 18:52:27 +0300 Subject: [PATCH 10/44] Fix progname_ut test (#164) --- util/CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 3fe4e1803d..a21b910254 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -249,9 +249,6 @@ if (YDB_SDK_TESTS) nice_ut pipe_ut platform_ut - # TODO: fix progname_ut - # TProgramNameTest::TestIt - progname_ut rusage_ut rwlock_ut sanitizers_ut @@ -282,6 +279,18 @@ if (YDB_SDK_TESTS) yassert_ut ) + # This test checks if the executable file's name (the same name as the target) + # is either "util-system-ut" or slightly different variations + add_ydb_test(NAME util-system-ut + SOURCES + system/progname_ut.cpp + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit + ) + if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_ydb_test(NAME util-system-fs_win_ut SOURCES From 461ed2b070ccf7fc9c6a655eb22249c4f0f4e8cc Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 20:02:57 +0300 Subject: [PATCH 11/44] Fix src_location_ut and src_root_ut (#164) --- util/CMakeLists.txt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index a21b910254..4a1c10313a 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -221,7 +221,8 @@ if (YDB_SDK_TESTS) cpu_id_ut daemon_ut datetime_ut - # TODO: direct_io_ut freezes + # TODO: fix direct_io_ut + # TDirectIoErrorHandling::Constructor: did not throw any exception (expected TFileError) direct_io_ut env_ut error_ut @@ -255,11 +256,7 @@ if (YDB_SDK_TESTS) shellcommand_ut shmat_ut spinlock_ut - # TODO: fix src_location_ut - # TestLocation::Test1 src_location_ut - # TODO: fix src_root_ut - # TestSourceRoot::TestStrip src_root_ut tempfile_ut # TODO: fix thread_ut @@ -268,7 +265,7 @@ if (YDB_SDK_TESTS) tls_ut # TODO: fix type_name_ut # TypeName::FromWellKnownTypes - # TypeName::FromWellKnownValues + # TypeName::FromArcadiaTypes # TypeName::FromWellKnownValues type_name_ut types_ut @@ -674,9 +671,10 @@ elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") ) endif() +# These definitions are needed to `util/system/src_root.h` works properly target_compile_definitions(yutil PUBLIC - ARCADIA_ROOT_CMAKE_HELPER=${YDB_SDK_SOURCE_DIR} - ARCADIA_BUILD_ROOT_CMAKE_HELPER=${YDB_SDK_BINARY_DIR} + ARCADIA_ROOT=${YDB_SDK_SOURCE_DIR} + ARCADIA_BUILD_ROOT=${YDB_SDK_BINARY_DIR} ) _ydb_sdk_install_targets(TARGETS yutil) From bbdc62232121fc3e3f52d9edd4f0074b7a000656 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 00:58:38 +0300 Subject: [PATCH 12/44] Fix thread_ut (#164) --- util/CMakeLists.txt | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 4a1c10313a..d0cbfab553 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -221,8 +221,6 @@ if (YDB_SDK_TESTS) cpu_id_ut daemon_ut datetime_ut - # TODO: fix direct_io_ut - # TDirectIoErrorHandling::Constructor: did not throw any exception (expected TFileError) direct_io_ut env_ut error_ut @@ -231,10 +229,6 @@ if (YDB_SDK_TESTS) filemap_ut file_ut flock_ut - # TODO: fix fstat_ut - # TestFileStat::SymlinkToExistingFileTest - # TestFileStat::SymlinkToNonExistingFileTest - # TestFileStat::SymlinkToFileThatCantExistTest fstat_ut fs_ut getpid_ut @@ -259,14 +253,7 @@ if (YDB_SDK_TESTS) src_location_ut src_root_ut tempfile_ut - # TODO: fix thread_ut - # TSysThreadTest::TestSetGetThreadNameInChildThread - thread_ut tls_ut - # TODO: fix type_name_ut - # TypeName::FromWellKnownTypes - # TypeName::FromArcadiaTypes - # TypeName::FromWellKnownValues type_name_ut types_ut # TODO: add library/cpp/testing/benchmark @@ -277,10 +264,14 @@ if (YDB_SDK_TESTS) ) # This test checks if the executable file's name (the same name as the target) - # is either "util-system-ut" or slightly different variations + # is either "util-system-ut" or slightly different variations. + # It also compares the executable file's name and the current thread name, + # whose length can't be more than 16 bytes in Linux, so "util-system-ut" is + # a suitable name. add_ydb_test(NAME util-system-ut SOURCES system/progname_ut.cpp + system/thread_ut.cpp LINK_LIBRARIES yutil cpp-testing-unittest_main From 0dd83b689f489c753ace5185eb73a4b6606ca1e4 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 01:24:30 +0300 Subject: [PATCH 13/44] Temporary comment broken tests --- util/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index d0cbfab553..6a4518800b 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -100,8 +100,7 @@ if (YDB_SDK_TESTS) stack_ut store_policy_ut strbuf_ut - # TODO: either add library/cpp/containers/absl_flat_hash - # or use __cplusplus macro to switch to C++20 and use std::unordered_set + # See fix/util-unit-tests branch # string_transparent_hash_ut string_ut typelist_ut @@ -221,7 +220,8 @@ if (YDB_SDK_TESTS) cpu_id_ut daemon_ut datetime_ut - direct_io_ut + # See fix/util-unit-tests branch + # direct_io_ut env_ut error_ut event_ut @@ -229,7 +229,8 @@ if (YDB_SDK_TESTS) filemap_ut file_ut flock_ut - fstat_ut + # See fix/util-unit-tests branch + # fstat_ut fs_ut getpid_ut guard_ut @@ -254,7 +255,8 @@ if (YDB_SDK_TESTS) src_root_ut tempfile_ut tls_ut - type_name_ut + # See fix/util-unit-tests branch + # type_name_ut types_ut # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier @@ -301,7 +303,7 @@ if (YDB_SDK_TESTS) LINK_LIBRARIES threading-future ) -endif() +endif(YDB_SDK_TESTS) _ydb_sdk_add_library(yutil) From fa026cc6e0c3496dd5495b0469dae6c6534d8ec1 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 13:58:22 +0300 Subject: [PATCH 14/44] Rename wrapper function to 'add_ydb_multiple_tests' and move to testing module --- cmake/testing.cmake | 68 +++++++ util/CMakeLists.txt | 481 ++++++++++++++++++++++++-------------------- 2 files changed, 327 insertions(+), 222 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 0cd06c4e1a..583683b2cd 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -150,3 +150,71 @@ function(add_ydb_test) vcs_info(${YDB_TEST_NAME}) endfunction() + +#[=============================================================================[ + This wrapper over `add_ydb_test` adds a separate test for each test file in + FILES list. Mandatory PREFIX will prepend the test name. All the test files + must have either an absolute or relative path. If test files have a relative + path, their paths will be prepended by BASE_DIR, and then, if BASE_DIR is not + empty, BASE_DIR will also prepend the test name after PREFIX. If BASE_DIR is + empty then the current source directory is used instead. All other parameters + of `add_ydb_test` except NAME and SOURCES are passed after ADD_YDB_TEST_ARGS + keyword. +#]=============================================================================] +function(add_ydb_multiple_tests) + set(opts "") + set(oneval_args PREFIX BASE_DIR) + set(multival_args FILES ADD_YDB_TEST_ARGS) + cmake_parse_arguments(ARGS + "${opts}" + "${oneval_args}" + "${multival_args}" + ${ARGN} + ) + + if (NOT ARGS_PREFIX) + message(FATAL_ERROR "Missing the PREFIX parameter.") + endif() + + if (NOT ARGS_FILES) + message(FATAL_ERROR "Missing the FILES list.") + endif() + + set(test_prefix "${ARGS_PREFIX}") + + if (NOT ARGS_BASE_DIR) + set(ARGS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + else() + set(test_prefix "${test_prefix}-${ARGS_BASE_DIR}") + endif() + + list(GET ARGS_FILES 0 firts_file_path) + if (IS_ABSOLUTE "${firts_file_path}") + set(file_path_is_absolute TRUE) + else() + set(file_path_is_absolute FALSE) + endif() + + foreach (test_path IN LISTS ARGS_FILES) + get_filename_component(test_suffix "${test_path}" NAME_WLE) + + if (NOT IS_ABSOLUTE "${test_path}") + if (file_path_is_absolute) + set(file_path_kind_error TRUE) + endif() + set(test_path "${ARGS_BASE_DIR}/${test_path}") + elseif (NOT file_path_is_absolute) + set(file_path_kind_error TRUE) + endif() + + if (file_path_kind_error) + message(FATAL_ERROR "All paths of test files must be either relative or absolute.") + endif() + + add_ydb_test(NAME "${test_prefix}-${test_suffix}" + SOURCES + "${test_path}" + ${ARGS_ADD_YDB_TEST_ARGS} + ) + endforeach() +endfunction() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 6a4518800b..2a7efe5ce3 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,116 +1,113 @@ add_subdirectory(charset) add_subdirectory(draft) -function(add_ydb_util_tests) - set(opts "") - set(oneval_args FOLDER) - set(multival_args TESTS LINK_LIBRARIES) - cmake_parse_arguments(ARGS - "${opts}" - "${oneval_args}" - "${multival_args}" - ${ARGN} - ) - list(PREPEND ARGS_LINK_LIBRARIES - yutil - cpp-testing-unittest_main - ) - foreach (__test_name_suffix IN LISTS ARGS_TESTS) - add_ydb_test(NAME "util-${ARGS_FOLDER}-${__test_name_suffix}" - SOURCES - "${ARGS_FOLDER}/${__test_name_suffix}.cpp" - LINK_LIBRARIES - ${ARGS_LINK_LIBRARIES} - LABELS - unit - ) - endforeach() -endfunction() - if (YDB_SDK_TESTS) - add_ydb_util_tests(FOLDER datetime - TESTS - base_ut - cputimer_ut - parser_deprecated_ut - parser_ut - process_uptime_ut - uptime_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR datetime + FILES + base_ut.cpp + cputimer_ut.cpp + parser_deprecated_ut.cpp + parser_ut.cpp + process_uptime_ut.cpp + uptime_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER digest - TESTS - city_ut - fnv_ut - multi_ut - murmur_ut - sequence_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR digest + FILES + city_ut.cpp + fnv_ut.cpp + multi_ut.cpp + murmur_ut.cpp + sequence_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER folder - TESTS - dirut_ut - filelist_ut - fts_ut - iterator_ut - path_ut - pathsplit_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR folder + FILES + dirut_ut.cpp + filelist_ut.cpp + fts_ut.cpp + iterator_ut.cpp + path_ut.cpp + pathsplit_ut.cpp + ADD_YDB_TEST_ARGS LINK_LIBRARIES + yutil + cpp-testing-unittest_main threading-future + LABELS + unit ) - add_ydb_util_tests(FOLDER generic - TESTS - adaptor_ut - algorithm_ut - array_ref_ut - array_size_ut - bitmap_ut - bitops_ut - buffer_ut - cast_ut - deque_ut - enum_range_ut - explicit_type_ut - flags_ut - function_ref_ut - function_ut - guid_ut - hash_primes_ut - hash_ut - intrlist_ut - is_in_ut - iterator_range_ut - iterator_ut - lazy_value_ut - list_ut - mapfindptr_ut - map_ut - maybe_ut - mem_copy_ut - objects_counter_ut - overloaded_ut - ptr_ut - queue_ut - scope_ut - serialized_enum_ut - set_ut - singleton_ut - size_literals_ut - stack_ut - store_policy_ut - strbuf_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR generic + FILES + adaptor_ut.cpp + algorithm_ut.cpp + array_ref_ut.cpp + array_size_ut.cpp + bitmap_ut.cpp + bitops_ut.cpp + buffer_ut.cpp + cast_ut.cpp + deque_ut.cpp + enum_range_ut.cpp + explicit_type_ut.cpp + flags_ut.cpp + function_ref_ut.cpp + function_ut.cpp + guid_ut.cpp + hash_primes_ut.cpp + hash_ut.cpp + intrlist_ut.cpp + is_in_ut.cpp + iterator_range_ut.cpp + iterator_ut.cpp + lazy_value_ut.cpp + list_ut.cpp + mapfindptr_ut.cpp + map_ut.cpp + maybe_ut.cpp + mem_copy_ut.cpp + objects_counter_ut.cpp + overloaded_ut.cpp + ptr_ut.cpp + queue_ut.cpp + scope_ut.cpp + serialized_enum_ut.cpp + set_ut.cpp + singleton_ut.cpp + size_literals_ut.cpp + stack_ut.cpp + store_policy_ut.cpp + strbuf_ut.cpp # See fix/util-unit-tests branch - # string_transparent_hash_ut - string_ut - typelist_ut - typetraits_ut - utility_ut - va_args_ut - vector_ut - xrange_ut - ylimits_ut - ymath_ut + # string_transparent_hash_ut.cpp + string_ut.cpp + typelist_ut.cpp + typetraits_ut.cpp + utility_ut.cpp + va_args_ut.cpp + vector_ut.cpp + xrange_ut.cpp + ylimits_ut.cpp + ymath_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) add_ydb_test(NAME util-generic-yexception_ut @@ -131,138 +128,173 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_util_tests(FOLDER memory - TESTS - addstorage_ut - blob_ut - pool_ut - smallobj_ut - tempbuf_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR memory + FILES + addstorage_ut.cpp + blob_ut.cpp + pool_ut.cpp + smallobj_ut.cpp + tempbuf_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER network - TESTS - address_ut - endpoint_ut - ip_ut - poller_ut - sock_ut - socket_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR network + FILES + address_ut.cpp + endpoint_ut.cpp + ip_ut.cpp + poller_ut.cpp + sock_ut.cpp + socket_ut.cpp + ADD_YDB_TEST_ARGS LINK_LIBRARIES + yutil + cpp-testing-unittest_main threading-future + LABELS + unit ) - add_ydb_util_tests(FOLDER random - TESTS - # TODO: fix common_ops_ut: TestStlCompatibility - common_ops_ut - easy_ut - entropy_ut - fast_ut - mersenne_ut - normal_ut - random_ut - shuffle_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR random + FILES + # See fix/util-unit-tests branch + # common_ops_ut.cpp + easy_ut.cpp + entropy_ut.cpp + fast_ut.cpp + mersenne_ut.cpp + normal_ut.cpp + random_ut.cpp + shuffle_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER stream - TESTS - aligned_ut - buffered_ut - buffer_ut - direct_io_ut - file_ut - format_std_ut - format_ut - hex_ut - input_ut - ios_ut - labeled_ut - length_ut - mem_ut - multi_ut - printf_ut - str_ut - tokenizer_ut - walk_ut - zerocopy_output_ut - zlib_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR stream + FILES + aligned_ut.cpp + buffered_ut.cpp + buffer_ut.cpp + direct_io_ut.cpp + file_ut.cpp + format_std_ut.cpp + format_ut.cpp + hex_ut.cpp + input_ut.cpp + ios_ut.cpp + labeled_ut.cpp + length_ut.cpp + mem_ut.cpp + multi_ut.cpp + printf_ut.cpp + str_ut.cpp + tokenizer_ut.cpp + walk_ut.cpp + zerocopy_output_ut.cpp + zlib_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER string - TESTS - ascii_ut - builder_ut - cast_ut - escape_ut - hex_ut - join_ut - printf_ut - split_ut - strip_ut - strspn_ut - subst_ut - type_ut - util_ut - vector_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR string + FILES + ascii_ut.cpp + builder_ut.cpp + cast_ut.cpp + escape_ut.cpp + hex_ut.cpp + join_ut.cpp + printf_ut.cpp + split_ut.cpp + strip_ut.cpp + strspn_ut.cpp + subst_ut.cpp + type_ut.cpp + util_ut.cpp + vector_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) - add_ydb_util_tests(FOLDER system - TESTS - align_ut - atexit_ut - backtrace_ut - byteorder_ut - compat_ut - compiler_ut - condvar_ut - context_ut - cpu_id_ut - daemon_ut - datetime_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR system + FILES + align_ut.cpp + atexit_ut.cpp + backtrace_ut.cpp + byteorder_ut.cpp + compat_ut.cpp + compiler_ut.cpp + condvar_ut.cpp + context_ut.cpp + cpu_id_ut.cpp + daemon_ut.cpp + datetime_ut.cpp # See fix/util-unit-tests branch - # direct_io_ut - env_ut - error_ut - event_ut - execpath_ut - filemap_ut - file_ut - flock_ut + # direct_io_ut.cpp + env_ut.cpp + error_ut.cpp + event_ut.cpp + execpath_ut.cpp + filemap_ut.cpp + file_ut.cpp + flock_ut.cpp # See fix/util-unit-tests branch - # fstat_ut - fs_ut - getpid_ut - guard_ut - hi_lo_ut - hostname_ut - info_ut - interrupt_signals_ut - mem_info_ut - mincore_ut - mktemp_ut - mutex_ut - nice_ut - pipe_ut - platform_ut - rusage_ut - rwlock_ut - sanitizers_ut - shellcommand_ut - shmat_ut - spinlock_ut - src_location_ut - src_root_ut - tempfile_ut - tls_ut + # fstat_ut.cpp + fs_ut.cpp + getpid_ut.cpp + guard_ut.cpp + hi_lo_ut.cpp + hostname_ut.cpp + info_ut.cpp + interrupt_signals_ut.cpp + mem_info_ut.cpp + mincore_ut.cpp + mktemp_ut.cpp + mutex_ut.cpp + nice_ut.cpp + pipe_ut.cpp + platform_ut.cpp + rusage_ut.cpp + rwlock_ut.cpp + sanitizers_ut.cpp + shellcommand_ut.cpp + shmat_ut.cpp + spinlock_ut.cpp + src_location_ut.cpp + src_root_ut.cpp + tempfile_ut.cpp + tls_ut.cpp # See fix/util-unit-tests branch - # type_name_ut - types_ut + # type_name_ut.cpp + types_ut.cpp # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier - # unaligned_mem_ut - user_ut - yassert_ut + # unaligned_mem_ut.cpp + user_ut.cpp + yassert_ut.cpp + ADD_YDB_TEST_ARGS + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit ) # This test checks if the executable file's name (the same name as the target) @@ -293,15 +325,20 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_util_tests(FOLDER thread - TESTS - factory_ut - lfqueue_ut - lfstack_ut - pool_ut - singleton_ut + add_ydb_multiple_tests(PREFIX util BASE_DIR thread + FILES + factory_ut.cpp + lfqueue_ut.cpp + lfstack_ut.cpp + pool_ut.cpp + singleton_ut.cpp + ADD_YDB_TEST_ARGS LINK_LIBRARIES + yutil + cpp-testing-unittest_main threading-future + LABELS + unit ) endif(YDB_SDK_TESTS) From de02d8bee1dea121ae9006650fa1df573c1c6eb7 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 22:58:43 +0300 Subject: [PATCH 15/44] Improve 'add_ydb_multiple_tests' --- cmake/testing.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 583683b2cd..68ea22f45c 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -186,6 +186,9 @@ function(add_ydb_multiple_tests) set(ARGS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") else() set(test_prefix "${test_prefix}-${ARGS_BASE_DIR}") + if (NOT IS_ABSOLUTE "${ARGS_BASE_DIR}") + set(ARGS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ARGS_BASE_DIR}") + endif() endif() list(GET ARGS_FILES 0 firts_file_path) @@ -198,6 +201,7 @@ function(add_ydb_multiple_tests) foreach (test_path IN LISTS ARGS_FILES) get_filename_component(test_suffix "${test_path}" NAME_WLE) + set(file_path_kind_error FALSE) if (NOT IS_ABSOLUTE "${test_path}") if (file_path_is_absolute) set(file_path_kind_error TRUE) From 8b41926009ca9f4d17d0160fefe97c0cdf557a07 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Mon, 12 Aug 2024 15:50:27 +0300 Subject: [PATCH 16/44] Simplify 'add_ydb_multiple_tests' command --- cmake/testing.cmake | 53 ++----- util/CMakeLists.txt | 368 ++++++++++++++++++++++---------------------- 2 files changed, 195 insertions(+), 226 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 68ea22f45c..cb70c97cdf 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -153,17 +153,14 @@ endfunction() #[=============================================================================[ This wrapper over `add_ydb_test` adds a separate test for each test file in - FILES list. Mandatory PREFIX will prepend the test name. All the test files - must have either an absolute or relative path. If test files have a relative - path, their paths will be prepended by BASE_DIR, and then, if BASE_DIR is not - empty, BASE_DIR will also prepend the test name after PREFIX. If BASE_DIR is - empty then the current source directory is used instead. All other parameters - of `add_ydb_test` except NAME and SOURCES are passed after ADD_YDB_TEST_ARGS - keyword. + FILES list. Mandatory PREFIX will prepend the test name. If test files have + a relative path, their paths will be prepended by CMAKE_CURRENT_SOURCE_DIR. + All other parameters of `add_ydb_test` except NAME and SOURCES are passed + after ADD_YDB_TEST_ARGS keyword. #]=============================================================================] function(add_ydb_multiple_tests) set(opts "") - set(oneval_args PREFIX BASE_DIR) + set(oneval_args PREFIX) set(multival_args FILES ADD_YDB_TEST_ARGS) cmake_parse_arguments(ARGS "${opts}" @@ -180,44 +177,16 @@ function(add_ydb_multiple_tests) message(FATAL_ERROR "Missing the FILES list.") endif() - set(test_prefix "${ARGS_PREFIX}") + foreach (testPath IN LISTS ARGS_FILES) + get_filename_component(testSuffix "${testPath}" NAME_WLE) - if (NOT ARGS_BASE_DIR) - set(ARGS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - else() - set(test_prefix "${test_prefix}-${ARGS_BASE_DIR}") - if (NOT IS_ABSOLUTE "${ARGS_BASE_DIR}") - set(ARGS_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ARGS_BASE_DIR}") - endif() - endif() - - list(GET ARGS_FILES 0 firts_file_path) - if (IS_ABSOLUTE "${firts_file_path}") - set(file_path_is_absolute TRUE) - else() - set(file_path_is_absolute FALSE) - endif() - - foreach (test_path IN LISTS ARGS_FILES) - get_filename_component(test_suffix "${test_path}" NAME_WLE) - - set(file_path_kind_error FALSE) - if (NOT IS_ABSOLUTE "${test_path}") - if (file_path_is_absolute) - set(file_path_kind_error TRUE) - endif() - set(test_path "${ARGS_BASE_DIR}/${test_path}") - elseif (NOT file_path_is_absolute) - set(file_path_kind_error TRUE) - endif() - - if (file_path_kind_error) - message(FATAL_ERROR "All paths of test files must be either relative or absolute.") + if (NOT IS_ABSOLUTE "${testPath}") + set(testPath "${CMAKE_CURRENT_SOURCE_DIR}/${testPath}") endif() - add_ydb_test(NAME "${test_prefix}-${test_suffix}" + add_ydb_test(NAME "${ARGS_PREFIX}-${testSuffix}" SOURCES - "${test_path}" + "${testPath}" ${ARGS_ADD_YDB_TEST_ARGS} ) endforeach() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 2a7efe5ce3..0225be39a2 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -2,14 +2,14 @@ add_subdirectory(charset) add_subdirectory(draft) if (YDB_SDK_TESTS) - add_ydb_multiple_tests(PREFIX util BASE_DIR datetime + add_ydb_multiple_tests(PREFIX util-datetime FILES - base_ut.cpp - cputimer_ut.cpp - parser_deprecated_ut.cpp - parser_ut.cpp - process_uptime_ut.cpp - uptime_ut.cpp + datetime/base_ut.cpp + datetime/cputimer_ut.cpp + datetime/parser_deprecated_ut.cpp + datetime/parser_ut.cpp + datetime/process_uptime_ut.cpp + datetime/uptime_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -18,13 +18,13 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR digest + add_ydb_multiple_tests(PREFIX util-digest FILES - city_ut.cpp - fnv_ut.cpp - multi_ut.cpp - murmur_ut.cpp - sequence_ut.cpp + digest/city_ut.cpp + digest/fnv_ut.cpp + digest/multi_ut.cpp + digest/murmur_ut.cpp + digest/sequence_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -33,14 +33,14 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR folder + add_ydb_multiple_tests(PREFIX util-folder FILES - dirut_ut.cpp - filelist_ut.cpp - fts_ut.cpp - iterator_ut.cpp - path_ut.cpp - pathsplit_ut.cpp + folder/dirut_ut.cpp + folder/filelist_ut.cpp + folder/fts_ut.cpp + folder/iterator_ut.cpp + folder/path_ut.cpp + folder/pathsplit_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -50,58 +50,58 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR generic + add_ydb_multiple_tests(PREFIX util-generic FILES - adaptor_ut.cpp - algorithm_ut.cpp - array_ref_ut.cpp - array_size_ut.cpp - bitmap_ut.cpp - bitops_ut.cpp - buffer_ut.cpp - cast_ut.cpp - deque_ut.cpp - enum_range_ut.cpp - explicit_type_ut.cpp - flags_ut.cpp - function_ref_ut.cpp - function_ut.cpp - guid_ut.cpp - hash_primes_ut.cpp - hash_ut.cpp - intrlist_ut.cpp - is_in_ut.cpp - iterator_range_ut.cpp - iterator_ut.cpp - lazy_value_ut.cpp - list_ut.cpp - mapfindptr_ut.cpp - map_ut.cpp - maybe_ut.cpp - mem_copy_ut.cpp - objects_counter_ut.cpp - overloaded_ut.cpp - ptr_ut.cpp - queue_ut.cpp - scope_ut.cpp - serialized_enum_ut.cpp - set_ut.cpp - singleton_ut.cpp - size_literals_ut.cpp - stack_ut.cpp - store_policy_ut.cpp - strbuf_ut.cpp + generic/adaptor_ut.cpp + generic/algorithm_ut.cpp + generic/array_ref_ut.cpp + generic/array_size_ut.cpp + generic/bitmap_ut.cpp + generic/bitops_ut.cpp + generic/buffer_ut.cpp + generic/cast_ut.cpp + generic/deque_ut.cpp + generic/enum_range_ut.cpp + generic/explicit_type_ut.cpp + generic/flags_ut.cpp + generic/function_ref_ut.cpp + generic/function_ut.cpp + generic/guid_ut.cpp + generic/hash_primes_ut.cpp + generic/hash_ut.cpp + generic/intrlist_ut.cpp + generic/is_in_ut.cpp + generic/iterator_range_ut.cpp + generic/iterator_ut.cpp + generic/lazy_value_ut.cpp + generic/list_ut.cpp + generic/mapfindptr_ut.cpp + generic/map_ut.cpp + generic/maybe_ut.cpp + generic/mem_copy_ut.cpp + generic/objects_counter_ut.cpp + generic/overloaded_ut.cpp + generic/ptr_ut.cpp + generic/queue_ut.cpp + generic/scope_ut.cpp + generic/serialized_enum_ut.cpp + generic/set_ut.cpp + generic/singleton_ut.cpp + generic/size_literals_ut.cpp + generic/stack_ut.cpp + generic/store_policy_ut.cpp + generic/strbuf_ut.cpp # See fix/util-unit-tests branch - # string_transparent_hash_ut.cpp - string_ut.cpp - typelist_ut.cpp - typetraits_ut.cpp - utility_ut.cpp - va_args_ut.cpp - vector_ut.cpp - xrange_ut.cpp - ylimits_ut.cpp - ymath_ut.cpp + # generic/string_transparent_hash_ut.cpp + generic/string_ut.cpp + generic/typelist_ut.cpp + generic/typetraits_ut.cpp + generic/utility_ut.cpp + generic/va_args_ut.cpp + generic/vector_ut.cpp + generic/xrange_ut.cpp + generic/ylimits_ut.cpp + generic/ymath_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -128,13 +128,13 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_multiple_tests(PREFIX util BASE_DIR memory + add_ydb_multiple_tests(PREFIX util-memory FILES - addstorage_ut.cpp - blob_ut.cpp - pool_ut.cpp - smallobj_ut.cpp - tempbuf_ut.cpp + memory/addstorage_ut.cpp + memory/blob_ut.cpp + memory/pool_ut.cpp + memory/smallobj_ut.cpp + memory/tempbuf_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -143,14 +143,14 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR network + add_ydb_multiple_tests(PREFIX util-network FILES - address_ut.cpp - endpoint_ut.cpp - ip_ut.cpp - poller_ut.cpp - sock_ut.cpp - socket_ut.cpp + network/address_ut.cpp + network/endpoint_ut.cpp + network/ip_ut.cpp + network/poller_ut.cpp + network/sock_ut.cpp + network/socket_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -160,17 +160,17 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR random + add_ydb_multiple_tests(PREFIX util-random FILES # See fix/util-unit-tests branch - # common_ops_ut.cpp - easy_ut.cpp - entropy_ut.cpp - fast_ut.cpp - mersenne_ut.cpp - normal_ut.cpp - random_ut.cpp - shuffle_ut.cpp + # random/common_ops_ut.cpp + random/easy_ut.cpp + random/entropy_ut.cpp + random/fast_ut.cpp + random/mersenne_ut.cpp + random/normal_ut.cpp + random/random_ut.cpp + random/shuffle_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -179,28 +179,28 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR stream + add_ydb_multiple_tests(PREFIX util-stream FILES - aligned_ut.cpp - buffered_ut.cpp - buffer_ut.cpp - direct_io_ut.cpp - file_ut.cpp - format_std_ut.cpp - format_ut.cpp - hex_ut.cpp - input_ut.cpp - ios_ut.cpp - labeled_ut.cpp - length_ut.cpp - mem_ut.cpp - multi_ut.cpp - printf_ut.cpp - str_ut.cpp - tokenizer_ut.cpp - walk_ut.cpp - zerocopy_output_ut.cpp - zlib_ut.cpp + stream/aligned_ut.cpp + stream/buffered_ut.cpp + stream/buffer_ut.cpp + stream/direct_io_ut.cpp + stream/file_ut.cpp + stream/format_std_ut.cpp + stream/format_ut.cpp + stream/hex_ut.cpp + stream/input_ut.cpp + stream/ios_ut.cpp + stream/labeled_ut.cpp + stream/length_ut.cpp + stream/mem_ut.cpp + stream/multi_ut.cpp + stream/printf_ut.cpp + stream/str_ut.cpp + stream/tokenizer_ut.cpp + stream/walk_ut.cpp + stream/zerocopy_output_ut.cpp + stream/zlib_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -209,22 +209,22 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR string + add_ydb_multiple_tests(PREFIX util-string FILES - ascii_ut.cpp - builder_ut.cpp - cast_ut.cpp - escape_ut.cpp - hex_ut.cpp - join_ut.cpp - printf_ut.cpp - split_ut.cpp - strip_ut.cpp - strspn_ut.cpp - subst_ut.cpp - type_ut.cpp - util_ut.cpp - vector_ut.cpp + string/ascii_ut.cpp + string/builder_ut.cpp + string/cast_ut.cpp + string/escape_ut.cpp + string/hex_ut.cpp + string/join_ut.cpp + string/printf_ut.cpp + string/split_ut.cpp + string/strip_ut.cpp + string/strspn_ut.cpp + string/subst_ut.cpp + string/type_ut.cpp + string/util_ut.cpp + string/vector_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -233,62 +233,62 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util BASE_DIR system + add_ydb_multiple_tests(PREFIX util-system FILES - align_ut.cpp - atexit_ut.cpp - backtrace_ut.cpp - byteorder_ut.cpp - compat_ut.cpp - compiler_ut.cpp - condvar_ut.cpp - context_ut.cpp - cpu_id_ut.cpp - daemon_ut.cpp - datetime_ut.cpp + system/align_ut.cpp + system/atexit_ut.cpp + system/backtrace_ut.cpp + system/byteorder_ut.cpp + system/compat_ut.cpp + system/compiler_ut.cpp + system/condvar_ut.cpp + system/context_ut.cpp + system/cpu_id_ut.cpp + system/daemon_ut.cpp + system/datetime_ut.cpp # See fix/util-unit-tests branch - # direct_io_ut.cpp - env_ut.cpp - error_ut.cpp - event_ut.cpp - execpath_ut.cpp - filemap_ut.cpp - file_ut.cpp - flock_ut.cpp + # system/direct_io_ut.cpp + system/env_ut.cpp + system/error_ut.cpp + system/event_ut.cpp + system/execpath_ut.cpp + system/filemap_ut.cpp + system/file_ut.cpp + system/flock_ut.cpp # See fix/util-unit-tests branch - # fstat_ut.cpp - fs_ut.cpp - getpid_ut.cpp - guard_ut.cpp - hi_lo_ut.cpp - hostname_ut.cpp - info_ut.cpp - interrupt_signals_ut.cpp - mem_info_ut.cpp - mincore_ut.cpp - mktemp_ut.cpp - mutex_ut.cpp - nice_ut.cpp - pipe_ut.cpp - platform_ut.cpp - rusage_ut.cpp - rwlock_ut.cpp - sanitizers_ut.cpp - shellcommand_ut.cpp - shmat_ut.cpp - spinlock_ut.cpp - src_location_ut.cpp - src_root_ut.cpp - tempfile_ut.cpp - tls_ut.cpp + # system/fstat_ut.cpp + system/fs_ut.cpp + system/getpid_ut.cpp + system/guard_ut.cpp + system/hi_lo_ut.cpp + system/hostname_ut.cpp + system/info_ut.cpp + system/interrupt_signals_ut.cpp + system/mem_info_ut.cpp + system/mincore_ut.cpp + system/mktemp_ut.cpp + system/mutex_ut.cpp + system/nice_ut.cpp + system/pipe_ut.cpp + system/platform_ut.cpp + system/rusage_ut.cpp + system/rwlock_ut.cpp + system/sanitizers_ut.cpp + system/shellcommand_ut.cpp + system/shmat_ut.cpp + system/spinlock_ut.cpp + system/src_location_ut.cpp + system/src_root_ut.cpp + system/tempfile_ut.cpp + system/tls_ut.cpp # See fix/util-unit-tests branch - # type_name_ut.cpp - types_ut.cpp + # system/type_name_ut.cpp + system/types_ut.cpp # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier - # unaligned_mem_ut.cpp - user_ut.cpp - yassert_ut.cpp + # system/unaligned_mem_ut.cpp + system/user_ut.cpp + system/yassert_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil @@ -325,13 +325,13 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_multiple_tests(PREFIX util BASE_DIR thread + add_ydb_multiple_tests(PREFIX util-thread FILES - factory_ut.cpp - lfqueue_ut.cpp - lfstack_ut.cpp - pool_ut.cpp - singleton_ut.cpp + thread/factory_ut.cpp + thread/lfqueue_ut.cpp + thread/lfstack_ut.cpp + thread/pool_ut.cpp + thread/singleton_ut.cpp ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil From 71f2646f0bc46d9c552aaf3180e74c01477b9bdd Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Tue, 13 Aug 2024 21:05:45 +0300 Subject: [PATCH 17/44] Fix __FILE__ expansion bug (#164) --- .github/actions/build/action.yaml | 2 +- CMakeLists.txt | 12 ++++++++++++ util/CMakeLists.txt | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml index d83fc67846..41e6c55486 100644 --- a/.github/actions/build/action.yaml +++ b/.github/actions/build/action.yaml @@ -9,7 +9,7 @@ runs: run: | mkdir -p ../build rm -rf ../build/* - cmake -DYDB_SDK_TESTS=On -DYDB_SDK_EXAMPLES=On --preset release + cmake -DYDB_SDK_TESTS=On -DYDB_SDK_EXAMPLES=On -DARCADIA_ROOT="../ydb-cpp-sdk" -DARCADIA_BUILD_ROOT="." --preset release - name: Build shell: bash run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 137feba447..7da70dfbb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,18 @@ set(YDB-CPP-SDK_AVAILABLE_COMPONENTS "" CACHE INTERNAL "") set(YDB-CPP-SDK_COMPONENT_TARGETS "" CACHE INTERNAL "") file(READ "src/client/resources/ydb_sdk_version.txt" YDB_SDK_VERSION) +#[=============================================================================[ + NOTE: if `ccache` is used with the environment variable `CCACHE_BASEDIR`, + these cached variable should be set manually by passing them to `cmake` as + `-DARCADIA_ROOT=source/path/relative/to/build/dir` and + `-DARCADIA_BUILD_ROOT=.`, because in that case the macro `__FILE__` will be + expanded to a relative path, even if the source code file was specified as + an absolute path, and we have to know the proper prefix of that path. + See details: https://ccache.dev/manual/3.1.html#_compiling_in_different_directories +#]=============================================================================] +set(ARCADIA_ROOT ${YDB_SDK_SOURCE_DIR} CACHE PATH "The source root directory") +set(ARCADIA_BUILD_ROOT ${YDB_SDK_BINARY_DIR} CACHE PATH "The build root directory") + include(GNUInstallDirs) include(CMakePackageConfigHelpers) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 0225be39a2..0cce97bdce 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -701,10 +701,10 @@ elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") ) endif() -# These definitions are needed to `util/system/src_root.h` works properly +# NOTE: these definitions are needed to `util/system/src_root.h` works properly target_compile_definitions(yutil PUBLIC - ARCADIA_ROOT=${YDB_SDK_SOURCE_DIR} - ARCADIA_BUILD_ROOT=${YDB_SDK_BINARY_DIR} + ARCADIA_ROOT=${ARCADIA_ROOT} + ARCADIA_BUILD_ROOT=${ARCADIA_BUILD_ROOT} ) _ydb_sdk_install_targets(TARGETS yutil) From 13a8df79dd0bc5d747dbf2ee9f9782a00968d73f Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Tue, 13 Aug 2024 21:15:08 +0300 Subject: [PATCH 18/44] Simplify 'add_ydb_multiple_tests' command again --- cmake/testing.cmake | 28 ++++++++++++---------------- util/CMakeLists.txt | 26 +++++--------------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index cb70c97cdf..5d1c88c348 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -151,17 +151,12 @@ function(add_ydb_test) vcs_info(${YDB_TEST_NAME}) endfunction() -#[=============================================================================[ - This wrapper over `add_ydb_test` adds a separate test for each test file in - FILES list. Mandatory PREFIX will prepend the test name. If test files have - a relative path, their paths will be prepended by CMAKE_CURRENT_SOURCE_DIR. - All other parameters of `add_ydb_test` except NAME and SOURCES are passed - after ADD_YDB_TEST_ARGS keyword. -#]=============================================================================] +# This wrapper over `add_ydb_test` adds a separate test for each test file in +# FILES list. Mandatory PREFIX will prepend the test name. function(add_ydb_multiple_tests) - set(opts "") + set(opts GTEST) set(oneval_args PREFIX) - set(multival_args FILES ADD_YDB_TEST_ARGS) + set(multival_args FILES INCLUDE_DIRS LINK_LIBRARIES LABELS) cmake_parse_arguments(ARGS "${opts}" "${oneval_args}" @@ -177,17 +172,18 @@ function(add_ydb_multiple_tests) message(FATAL_ERROR "Missing the FILES list.") endif() + if (ARGS_GTEST) + set(ARGS_GTEST "GTEST") + endif() + foreach (testPath IN LISTS ARGS_FILES) get_filename_component(testSuffix "${testPath}" NAME_WLE) - - if (NOT IS_ABSOLUTE "${testPath}") - set(testPath "${CMAKE_CURRENT_SOURCE_DIR}/${testPath}") - endif() - - add_ydb_test(NAME "${ARGS_PREFIX}-${testSuffix}" + add_ydb_test(NAME "${ARGS_PREFIX}-${testSuffix}" ${ARGS_GTEST} SOURCES "${testPath}" - ${ARGS_ADD_YDB_TEST_ARGS} + INCLUDE_DIRS ${ARGS_INCLUDE_DIRS} + LINK_LIBRARIES ${ARGS_LINK_LIBRARIES} + LABELS ${ARGS_LABELS} ) endforeach() endfunction() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 0cce97bdce..894beb760c 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -10,7 +10,6 @@ if (YDB_SDK_TESTS) datetime/parser_ut.cpp datetime/process_uptime_ut.cpp datetime/uptime_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -25,7 +24,6 @@ if (YDB_SDK_TESTS) digest/multi_ut.cpp digest/murmur_ut.cpp digest/sequence_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -41,7 +39,6 @@ if (YDB_SDK_TESTS) folder/iterator_ut.cpp folder/path_ut.cpp folder/pathsplit_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -91,8 +88,7 @@ if (YDB_SDK_TESTS) generic/stack_ut.cpp generic/store_policy_ut.cpp generic/strbuf_ut.cpp - # See fix/util-unit-tests branch - # generic/string_transparent_hash_ut.cpp + generic/string_transparent_hash_ut.cpp generic/string_ut.cpp generic/typelist_ut.cpp generic/typetraits_ut.cpp @@ -102,7 +98,6 @@ if (YDB_SDK_TESTS) generic/xrange_ut.cpp generic/ylimits_ut.cpp generic/ymath_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -135,7 +130,6 @@ if (YDB_SDK_TESTS) memory/pool_ut.cpp memory/smallobj_ut.cpp memory/tempbuf_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -151,7 +145,6 @@ if (YDB_SDK_TESTS) network/poller_ut.cpp network/sock_ut.cpp network/socket_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -162,8 +155,7 @@ if (YDB_SDK_TESTS) add_ydb_multiple_tests(PREFIX util-random FILES - # See fix/util-unit-tests branch - # random/common_ops_ut.cpp + random/common_ops_ut.cpp random/easy_ut.cpp random/entropy_ut.cpp random/fast_ut.cpp @@ -171,7 +163,6 @@ if (YDB_SDK_TESTS) random/normal_ut.cpp random/random_ut.cpp random/shuffle_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -201,7 +192,6 @@ if (YDB_SDK_TESTS) stream/walk_ut.cpp stream/zerocopy_output_ut.cpp stream/zlib_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -225,7 +215,6 @@ if (YDB_SDK_TESTS) string/type_ut.cpp string/util_ut.cpp string/vector_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -246,8 +235,7 @@ if (YDB_SDK_TESTS) system/cpu_id_ut.cpp system/daemon_ut.cpp system/datetime_ut.cpp - # See fix/util-unit-tests branch - # system/direct_io_ut.cpp + system/direct_io_ut.cpp system/env_ut.cpp system/error_ut.cpp system/event_ut.cpp @@ -255,8 +243,7 @@ if (YDB_SDK_TESTS) system/filemap_ut.cpp system/file_ut.cpp system/flock_ut.cpp - # See fix/util-unit-tests branch - # system/fstat_ut.cpp + system/fstat_ut.cpp system/fs_ut.cpp system/getpid_ut.cpp system/guard_ut.cpp @@ -281,15 +268,13 @@ if (YDB_SDK_TESTS) system/src_root_ut.cpp system/tempfile_ut.cpp system/tls_ut.cpp - # See fix/util-unit-tests branch - # system/type_name_ut.cpp + system/type_name_ut.cpp system/types_ut.cpp # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier # system/unaligned_mem_ut.cpp system/user_ut.cpp system/yassert_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main @@ -332,7 +317,6 @@ if (YDB_SDK_TESTS) thread/lfstack_ut.cpp thread/pool_ut.cpp thread/singleton_ut.cpp - ADD_YDB_TEST_ARGS LINK_LIBRARIES yutil cpp-testing-unittest_main From a16fe02b7ffd7b10acb70f95e3629f7880059ac1 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Tue, 13 Aug 2024 21:19:39 +0300 Subject: [PATCH 19/44] Remove unnecessary CCACHE_PATH check If the variable CCACHE_PATH is already set before the call (as a normal or cache variable) then the search will not occur. --- cmake/ccache.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake index 1859d5f74f..ef68402c46 100644 --- a/cmake/ccache.cmake +++ b/cmake/ccache.cmake @@ -1,6 +1,4 @@ -if (NOT CCACHE_PATH) - find_program(CCACHE_PATH ccache) -endif() +find_program(CCACHE_PATH ccache) if (NOT CCACHE_PATH) message(AUTHOR_WARNING "Ccache is not found, that will increase the re-compilation time; " From 0dba8f48854849ecb980f1804340f76b38206ceb Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 14 Aug 2024 11:52:08 +0300 Subject: [PATCH 20/44] Fix cached variable's type --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7da70dfbb4..af1479efd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ file(READ "src/client/resources/ydb_sdk_version.txt" YDB_SDK_VERSION) an absolute path, and we have to know the proper prefix of that path. See details: https://ccache.dev/manual/3.1.html#_compiling_in_different_directories #]=============================================================================] -set(ARCADIA_ROOT ${YDB_SDK_SOURCE_DIR} CACHE PATH "The source root directory") -set(ARCADIA_BUILD_ROOT ${YDB_SDK_BINARY_DIR} CACHE PATH "The build root directory") +set(ARCADIA_ROOT ${YDB_SDK_SOURCE_DIR} CACHE INTERNAL "The source root directory") +set(ARCADIA_BUILD_ROOT ${YDB_SDK_BINARY_DIR} CACHE INTERNAL "The build root directory") include(GNUInstallDirs) include(CMakePackageConfigHelpers) From 1eee66e59713cb1d56c88d82448bb6695f7cb359 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 14 Aug 2024 14:29:21 +0300 Subject: [PATCH 21/44] Remove 'add_ydb_multiple_tests' command --- cmake/testing.cmake | 37 ------------------------- util/CMakeLists.txt | 67 ++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 75 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 5d1c88c348..0cd06c4e1a 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -150,40 +150,3 @@ function(add_ydb_test) vcs_info(${YDB_TEST_NAME}) endfunction() - -# This wrapper over `add_ydb_test` adds a separate test for each test file in -# FILES list. Mandatory PREFIX will prepend the test name. -function(add_ydb_multiple_tests) - set(opts GTEST) - set(oneval_args PREFIX) - set(multival_args FILES INCLUDE_DIRS LINK_LIBRARIES LABELS) - cmake_parse_arguments(ARGS - "${opts}" - "${oneval_args}" - "${multival_args}" - ${ARGN} - ) - - if (NOT ARGS_PREFIX) - message(FATAL_ERROR "Missing the PREFIX parameter.") - endif() - - if (NOT ARGS_FILES) - message(FATAL_ERROR "Missing the FILES list.") - endif() - - if (ARGS_GTEST) - set(ARGS_GTEST "GTEST") - endif() - - foreach (testPath IN LISTS ARGS_FILES) - get_filename_component(testSuffix "${testPath}" NAME_WLE) - add_ydb_test(NAME "${ARGS_PREFIX}-${testSuffix}" ${ARGS_GTEST} - SOURCES - "${testPath}" - INCLUDE_DIRS ${ARGS_INCLUDE_DIRS} - LINK_LIBRARIES ${ARGS_LINK_LIBRARIES} - LABELS ${ARGS_LABELS} - ) - endforeach() -endfunction() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 894beb760c..edef0118f0 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -2,8 +2,8 @@ add_subdirectory(charset) add_subdirectory(draft) if (YDB_SDK_TESTS) - add_ydb_multiple_tests(PREFIX util-datetime - FILES + add_ydb_test(NAME util-datetime-ut + SOURCES datetime/base_ut.cpp datetime/cputimer_ut.cpp datetime/parser_deprecated_ut.cpp @@ -17,8 +17,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-digest - FILES + add_ydb_test(NAME util-digest-ut + SOURCES digest/city_ut.cpp digest/fnv_ut.cpp digest/multi_ut.cpp @@ -31,8 +31,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-folder - FILES + add_ydb_test(NAME util-folder-ut + SOURCES folder/dirut_ut.cpp folder/filelist_ut.cpp folder/fts_ut.cpp @@ -47,8 +47,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-generic - FILES + add_ydb_test(NAME util-generic-ut + SOURCES generic/adaptor_ut.cpp generic/algorithm_ut.cpp generic/array_ref_ut.cpp @@ -123,8 +123,8 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_multiple_tests(PREFIX util-memory - FILES + add_ydb_test(NAME util-memory-ut + SOURCES memory/addstorage_ut.cpp memory/blob_ut.cpp memory/pool_ut.cpp @@ -137,8 +137,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-network - FILES + add_ydb_test(NAME util-network-ut + SOURCES network/address_ut.cpp network/endpoint_ut.cpp network/ip_ut.cpp @@ -153,8 +153,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-random - FILES + add_ydb_test(NAME util-random-ut + SOURCES random/common_ops_ut.cpp random/easy_ut.cpp random/entropy_ut.cpp @@ -170,8 +170,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-stream - FILES + add_ydb_test(NAME util-stream-ut + SOURCES stream/aligned_ut.cpp stream/buffered_ut.cpp stream/buffer_ut.cpp @@ -199,8 +199,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-string - FILES + add_ydb_test(NAME util-string-ut + SOURCES string/ascii_ut.cpp string/builder_ut.cpp string/cast_ut.cpp @@ -222,8 +222,8 @@ if (YDB_SDK_TESTS) unit ) - add_ydb_multiple_tests(PREFIX util-system - FILES + add_ydb_test(NAME util-system-ut + SOURCES system/align_ut.cpp system/atexit_ut.cpp system/backtrace_ut.cpp @@ -258,6 +258,9 @@ if (YDB_SDK_TESTS) system/nice_ut.cpp system/pipe_ut.cpp system/platform_ut.cpp + # NOTE: `progname_ut` checks if the executable file's name, aka the target's + # name, is either "util-system-ut" or slightly different variations + system/progname_ut.cpp system/rusage_ut.cpp system/rwlock_ut.cpp system/sanitizers_ut.cpp @@ -269,6 +272,10 @@ if (YDB_SDK_TESTS) system/tempfile_ut.cpp system/tls_ut.cpp system/type_name_ut.cpp + # NOTE: `thread_ut` compares the executable file's name and the current + # thread name, whose length can't be more than 16 bytes in Linux, + # so the test name shouldn't be longer than "util-system-ut" + system/thread_ut.cpp system/types_ut.cpp # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier @@ -282,22 +289,6 @@ if (YDB_SDK_TESTS) unit ) - # This test checks if the executable file's name (the same name as the target) - # is either "util-system-ut" or slightly different variations. - # It also compares the executable file's name and the current thread name, - # whose length can't be more than 16 bytes in Linux, so "util-system-ut" is - # a suitable name. - add_ydb_test(NAME util-system-ut - SOURCES - system/progname_ut.cpp - system/thread_ut.cpp - LINK_LIBRARIES - yutil - cpp-testing-unittest_main - LABELS - unit - ) - if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_ydb_test(NAME util-system-fs_win_ut SOURCES @@ -310,8 +301,8 @@ if (YDB_SDK_TESTS) ) endif() - add_ydb_multiple_tests(PREFIX util-thread - FILES + add_ydb_test(NAME util-thread-ut + SOURCES thread/factory_ut.cpp thread/lfqueue_ut.cpp thread/lfstack_ut.cpp From d8ffc2fdc979c576f88b8b7f6ad1f0933795426e Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 14 Aug 2024 15:02:35 +0300 Subject: [PATCH 22/44] Add info about filtering of legacy tests --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e3355def5..9475dcfb66 100644 --- a/README.md +++ b/README.md @@ -138,4 +138,14 @@ Running integration tests only: ```bash ctest -j$(nproc) --preset release-integration -``` \ No newline at end of file +``` + +Note that some tests use a legacy test library instead of GoogleTest, see `./ --help` for details. If you need to run only certain test cases, here is an alternative for `--gtest_filter` option: + +```bash +cat < --filter-file /dev/fd/0 +-ExcludedTestCase ++IncludedTestCase ++IncludedTestCase::TestName +EOF +``` From 9ac7ed97edd5ac550417952912d31131995657dd Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 23:52:36 +0300 Subject: [PATCH 23/44] Fix util/system/direct_io_ut (#164) 'direct_io_ut' from 'util/stream' doesn't remove its file, so 'direct_io_ut' from 'util/system' failed checking if the same file doesn't exist --- util/stream/direct_io_ut.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp index 1fada06ecb..db129e4670 100644 --- a/util/stream/direct_io_ut.cpp +++ b/util/stream/direct_io_ut.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "buffered.h" #include "direct_io.h" @@ -54,6 +55,7 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) { } UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE); + NFs::Remove(fileName); } Y_UNIT_TEST(ReadWriteTest) { From af4fca4c53319bab7c77e7c4dcb39af63013a693 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 23:55:50 +0300 Subject: [PATCH 24/44] Fix fstat_ut (#164) libc 'open' (in implementation of TFile) doesn't create non-existed parent directories in given path, so we have to do that for it --- util/system/fstat_ut.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index 300f76d7e6..9a62d335ec 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -105,6 +105,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) { #endif Y_UNIT_TEST(SymlinkToExistingFileTest) { + NFs::MakeDirectory(GetOutputPath()); const auto path = GetOutputPath() / "file_1"; const auto link = GetOutputPath() / "symlink_1"; TFile(path, EOpenModeFlag::CreateNew | EOpenModeFlag::RdWr); From 1d96b56417250c6b5429fc89867d7994015e1ed7 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Wed, 7 Aug 2024 23:56:26 +0300 Subject: [PATCH 25/44] Fix type_name_ut (#164) --- util/system/type_name.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp index 52f47a1ddd..84e9daf6ff 100644 --- a/util/system/type_name.cpp +++ b/util/system/type_name.cpp @@ -46,6 +46,7 @@ TString TypeName(const std::type_info& typeInfo) { TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction) #if defined(_linux_) || defined(_darwin_) SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX); + SubstGlobal(demangled, " >", ">"); #endif return demangled; } @@ -54,6 +55,7 @@ TString TypeName(const std::type_index& typeIndex) { TString demangled = CppDemangle(typeIndex.name()); #if defined(_linux_) || defined(_darwin_) SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX); + SubstGlobal(demangled, " >", ">"); #endif return demangled; } From b749b9a81854e6355dd6dbfb8ead5e49facd9384 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 00:13:47 +0300 Subject: [PATCH 26/44] Fix fstat_ut (#164) Need to remove the directory at the end of the test --- util/system/fstat_ut.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index 9a62d335ec..d4517ccefc 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -122,9 +122,12 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + + NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(SymlinkToNonExistingFileTest) { + NFs::MakeDirectory(GetOutputPath()); const auto path = GetOutputPath() / "file_2"; const auto link = GetOutputPath() / "symlink_2"; SAFE_SYMLINK(path, link); @@ -140,9 +143,12 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + + NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(SymlinkToFileThatCantExistTest) { + NFs::MakeDirectory(GetOutputPath()); const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; const auto link = GetOutputPath() / "symlink_3"; SAFE_SYMLINK(path, link); @@ -158,6 +164,8 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + + NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(FileDoesNotExistTest) { From eebe4b02cb629982b4db2c857ccba1f7f64dfa1f Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 01:17:45 +0300 Subject: [PATCH 27/44] Fix string_transparent_hash_ut (#158) --- util/generic/string_transparent_hash_ut.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/util/generic/string_transparent_hash_ut.cpp b/util/generic/string_transparent_hash_ut.cpp index b87fa2843e..07703bb979 100644 --- a/util/generic/string_transparent_hash_ut.cpp +++ b/util/generic/string_transparent_hash_ut.cpp @@ -3,7 +3,12 @@ #include "strbuf.h" #include -#include + +#if __cplusplus < 202002L + #include +#else + #include +#endif #include @@ -11,7 +16,15 @@ Y_UNIT_TEST_SUITE(StringHashFunctorTests) { Y_UNIT_TEST(TestTransparencyWithUnorderedSet) { // Using Abseil hash set because `std::unordered_set` is transparent only from C++20 (while // we stuck with C++17 right now). - absl::flat_hash_set, TEqualTo> s = {"foo"}; + using TTransparentHashSet = + #if __cplusplus < 202002L + absl::flat_hash_set + #else + std::unordered_set + #endif + , TEqualTo>; + + TTransparentHashSet s = {"foo"}; // If either `THash` or `TEqualTo` is not transparent compilation will fail. UNIT_ASSERT_UNEQUAL(s.find(TStringBuf("foo")), s.end()); UNIT_ASSERT_EQUAL(s.find(TStringBuf("bar")), s.end()); From 043286f2b9ed937fc5a279497d7a827f142b1b0d Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 8 Aug 2024 12:07:33 +0300 Subject: [PATCH 28/44] Fix common_ops_ut (#161) --- util/random/common_ops_ut.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/util/random/common_ops_ut.cpp b/util/random/common_ops_ut.cpp index 905912bd1e..9a0efa838f 100644 --- a/util/random/common_ops_ut.cpp +++ b/util/random/common_ops_ut.cpp @@ -45,25 +45,24 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { } Y_UNIT_TEST(TestStlCompatibility) { + // NOTE: Check if `TRng` can be passed to `std::normal_distribution::operator()`. + // These tests just have to be compilable, so the asserts below are always true. { TRng r; - r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.877167, 0.01); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); } { TRng r; - r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.5615566731, 0.01); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); } { TRng r; - r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.430375088, 0.01); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); } } } From 24e3e2840a3ccb56f55c293f15b66fa574c8f18a Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 10:16:38 +0300 Subject: [PATCH 29/44] Revert "Fix util/system/direct_io_ut (#164)" This reverts commit 9ac7ed97edd5ac550417952912d31131995657dd. --- util/stream/direct_io_ut.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp index db129e4670..1fada06ecb 100644 --- a/util/stream/direct_io_ut.cpp +++ b/util/stream/direct_io_ut.cpp @@ -2,7 +2,6 @@ #include #include -#include #include "buffered.h" #include "direct_io.h" @@ -55,7 +54,6 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) { } UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE); - NFs::Remove(fileName); } Y_UNIT_TEST(ReadWriteTest) { From 298518e389d0a9fbbc1dbb865b86fbe632b3c247 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:05:33 +0300 Subject: [PATCH 30/44] Add WORKING_DIRECTORY parameter to testing commands --- cmake/testing.cmake | 74 ++++++++++++++++++++++++++++----------------- util/CMakeLists.txt | 26 ++++++++++++++++ 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 0cd06c4e1a..b836ad257f 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -1,6 +1,6 @@ function(add_yunittest) set(opts "") - set(oneval_args NAME TEST_TARGET) + set(oneval_args NAME TEST_TARGET WORKING_DIRECTORY) set(multival_args TEST_ARG) cmake_parse_arguments(YUNITTEST_ARGS "${opts}" @@ -13,13 +13,19 @@ function(add_yunittest) get_property(SPLIT_TYPE TARGET ${YUNITTEST_ARGS_TEST_TARGET} PROPERTY SPLIT_TYPE) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack") - add_test(NAME ${YUNITTEST_ARGS_NAME} COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack" ${YUNITTEST_ARGS_TEST_ARG}) + add_test(NAME ${YUNITTEST_ARGS_NAME} + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run_testpack" ${YUNITTEST_ARGS_TEST_ARG} + WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY} + ) set_property(TEST ${YUNITTEST_ARGS_NAME} PROPERTY ENVIRONMENT "source_root=${YDB_SDK_SOURCE_DIR};build_root=${YDB_SDK_BINARY_DIR};test_split_factor=${SPLIT_FACTOR};test_split_type=${SPLIT_TYPE}") return() endif() if (${SPLIT_FACTOR} EQUAL 1) - add_test(NAME ${YUNITTEST_ARGS_NAME} COMMAND ${YUNITTEST_ARGS_TEST_TARGET} ${YUNITTEST_ARGS_TEST_ARG}) + add_test(NAME ${YUNITTEST_ARGS_NAME} + COMMAND ${YUNITTEST_ARGS_TEST_TARGET} ${YUNITTEST_ARGS_TEST_ARG} + WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY} + ) return() endif() @@ -29,8 +35,12 @@ function(add_yunittest) math(EXPR LastIdx "${SPLIT_FACTOR} - 1") foreach(Idx RANGE ${LastIdx}) add_test(NAME ${YUNITTEST_ARGS_NAME}_${Idx} - COMMAND Python3::Interpreter ${YDB_SDK_SOURCE_DIR}/scripts/split_unittest.py --split-factor ${SPLIT_FACTOR} ${FORK_MODE_ARG} --shard ${Idx} - $ ${YUNITTEST_ARGS_TEST_ARG}) + COMMAND Python3::Interpreter ${YDB_SDK_SOURCE_DIR}/scripts/split_unittest.py + --split-factor ${SPLIT_FACTOR} ${FORK_MODE_ARG} + --shard ${Idx} + $ ${YUNITTEST_ARGS_TEST_ARG} + WORKING_DIRECTORY ${YUNITTEST_ARGS_WORKING_DIRECTORY} + ) endforeach() endfunction() @@ -59,7 +69,7 @@ endfunction() function(add_ydb_test) set(opts GTEST) - set(oneval_args NAME) + set(oneval_args NAME WORKING_DIRECTORY) set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS) cmake_parse_arguments(YDB_TEST "${opts}" @@ -68,6 +78,10 @@ function(add_ydb_test) ${ARGN} ) + if (YDB_TEST_WORKING_DIRECTORY AND NOT EXISTS "${YDB_TEST_WORKING_DIRECTORY}") + file(MAKE_DIRECTORY "${YDB_TEST_WORKING_DIRECTORY}") + endif() + add_executable(${YDB_TEST_NAME}) target_include_directories(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_INCLUDE_DIRS}) target_link_libraries(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_LINK_LIBRARIES}) @@ -96,56 +110,60 @@ function(add_ydb_test) set_property( TARGET - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} PROPERTY - SPLIT_FACTOR - 1 + SPLIT_FACTOR + 1 ) if (YDB_TEST_GTEST) add_yunittest( NAME - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} TEST_TARGET - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} + WORKING_DIRECTORY + ${YDB_TEST_WORKING_DIRECTORY} ) else() add_yunittest( NAME - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} TEST_TARGET - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} TEST_ARG - --print-before-suite - --print-before-test - --fork-tests - --print-times - --show-fails + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails + WORKING_DIRECTORY + ${YDB_TEST_WORKING_DIRECTORY} ) endif() set_yunittest_property( TEST - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} PROPERTY - LABELS - MEDIUM - ${YDB_TEST_LABELS} + LABELS + MEDIUM + ${YDB_TEST_LABELS} ) set_yunittest_property( TEST - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} PROPERTY - PROCESSORS - 1 + PROCESSORS + 1 ) set_yunittest_property( TEST - ${YDB_TEST_NAME} + ${YDB_TEST_NAME} PROPERTY - TIMEOUT - 600 + TIMEOUT + 600 ) vcs_info(${YDB_TEST_NAME}) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index edef0118f0..d4634c9861 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,6 +3,8 @@ add_subdirectory(draft) if (YDB_SDK_TESTS) add_ydb_test(NAME util-datetime-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/datetime SOURCES datetime/base_ut.cpp datetime/cputimer_ut.cpp @@ -18,6 +20,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-digest-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/digest SOURCES digest/city_ut.cpp digest/fnv_ut.cpp @@ -32,6 +36,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-folder-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/folder SOURCES folder/dirut_ut.cpp folder/filelist_ut.cpp @@ -48,6 +54,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-generic-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/generic SOURCES generic/adaptor_ut.cpp generic/algorithm_ut.cpp @@ -106,6 +114,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-generic-yexception_ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/generic SOURCES generic/yexception_ut.c generic/yexception_ut.cpp @@ -124,6 +134,8 @@ if (YDB_SDK_TESTS) endif() add_ydb_test(NAME util-memory-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/memory SOURCES memory/addstorage_ut.cpp memory/blob_ut.cpp @@ -138,6 +150,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-network-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/network SOURCES network/address_ut.cpp network/endpoint_ut.cpp @@ -154,6 +168,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-random-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/random SOURCES random/common_ops_ut.cpp random/easy_ut.cpp @@ -171,6 +187,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-stream-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/stream SOURCES stream/aligned_ut.cpp stream/buffered_ut.cpp @@ -200,6 +218,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-string-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/string SOURCES string/ascii_ut.cpp string/builder_ut.cpp @@ -223,6 +243,8 @@ if (YDB_SDK_TESTS) ) add_ydb_test(NAME util-system-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/system SOURCES system/align_ut.cpp system/atexit_ut.cpp @@ -291,6 +313,8 @@ if (YDB_SDK_TESTS) if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_ydb_test(NAME util-system-fs_win_ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/system SOURCES system/fs_win_ut.cpp LINK_LIBRARIES @@ -302,6 +326,8 @@ if (YDB_SDK_TESTS) endif() add_ydb_test(NAME util-thread-ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/thread SOURCES thread/factory_ut.cpp thread/lfqueue_ut.cpp From b3ea0c8ea30058477d92db3a49c55440acd62219 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:06:33 +0300 Subject: [PATCH 31/44] Revert "Fix fstat_ut (#164)" This reverts commit b749b9a81854e6355dd6dbfb8ead5e49facd9384. --- util/system/fstat_ut.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index d4517ccefc..9a62d335ec 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -122,12 +122,9 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - - NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(SymlinkToNonExistingFileTest) { - NFs::MakeDirectory(GetOutputPath()); const auto path = GetOutputPath() / "file_2"; const auto link = GetOutputPath() / "symlink_2"; SAFE_SYMLINK(path, link); @@ -143,12 +140,9 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - - NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(SymlinkToFileThatCantExistTest) { - NFs::MakeDirectory(GetOutputPath()); const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; const auto link = GetOutputPath() / "symlink_3"; SAFE_SYMLINK(path, link); @@ -164,8 +158,6 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - - NFs::RemoveRecursive(GetOutputPath()); } Y_UNIT_TEST(FileDoesNotExistTest) { From 4821446e0a0d25b07a9cc03a4917b11e1f2b7fcd Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:11:30 +0300 Subject: [PATCH 32/44] Revert "Fix fstat_ut (#164)" This reverts commit af4fca4c53319bab7c77e7c4dcb39af63013a693. --- util/system/fstat_ut.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index 9a62d335ec..300f76d7e6 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -105,7 +105,6 @@ Y_UNIT_TEST_SUITE(TestFileStat) { #endif Y_UNIT_TEST(SymlinkToExistingFileTest) { - NFs::MakeDirectory(GetOutputPath()); const auto path = GetOutputPath() / "file_1"; const auto link = GetOutputPath() / "symlink_1"; TFile(path, EOpenModeFlag::CreateNew | EOpenModeFlag::RdWr); From 01697ebcfe5e0b3d440be559ec89f065b4c580ce Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:24:37 +0300 Subject: [PATCH 33/44] Add OUTPUT_DIRECTORY parameter to testing command --- cmake/testing.cmake | 6 +++++- util/CMakeLists.txt | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index b836ad257f..8a7364f77a 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -69,7 +69,7 @@ endfunction() function(add_ydb_test) set(opts GTEST) - set(oneval_args NAME WORKING_DIRECTORY) + set(oneval_args NAME WORKING_DIRECTORY OUTPUT_DIRECTORY) set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS) cmake_parse_arguments(YDB_TEST "${opts}" @@ -82,6 +82,10 @@ function(add_ydb_test) file(MAKE_DIRECTORY "${YDB_TEST_WORKING_DIRECTORY}") endif() + if (YDB_TEST_OUTPUT_DIRECTORY AND NOT EXISTS "${YDB_TEST_OUTPUT_DIRECTORY}") + file(MAKE_DIRECTORY "${YDB_TEST_OUTPUT_DIRECTORY}") + endif() + add_executable(${YDB_TEST_NAME}) target_include_directories(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_INCLUDE_DIRS}) target_link_libraries(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_LINK_LIBRARIES}) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index d4634c9861..97624be7dd 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -265,7 +265,6 @@ if (YDB_SDK_TESTS) system/filemap_ut.cpp system/file_ut.cpp system/flock_ut.cpp - system/fstat_ut.cpp system/fs_ut.cpp system/getpid_ut.cpp system/guard_ut.cpp @@ -311,6 +310,20 @@ if (YDB_SDK_TESTS) unit ) + add_ydb_test(NAME util-system-fstat_ut + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/system + OUTPUT_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/system/testing_out_stuff + SOURCES + system/fstat_ut.cpp + LINK_LIBRARIES + yutil + cpp-testing-unittest_main + LABELS + unit + ) + if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_ydb_test(NAME util-system-fs_win_ut WORKING_DIRECTORY From 640a783d87724b16d871f5dce0bad629739688c2 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:25:22 +0300 Subject: [PATCH 34/44] Revert "Fix type_name_ut (#164)" This reverts commit 1d96b56417250c6b5429fc89867d7994015e1ed7. --- util/system/type_name.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp index 84e9daf6ff..52f47a1ddd 100644 --- a/util/system/type_name.cpp +++ b/util/system/type_name.cpp @@ -46,7 +46,6 @@ TString TypeName(const std::type_info& typeInfo) { TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction) #if defined(_linux_) || defined(_darwin_) SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX); - SubstGlobal(demangled, " >", ">"); #endif return demangled; } @@ -55,7 +54,6 @@ TString TypeName(const std::type_index& typeIndex) { TString demangled = CppDemangle(typeIndex.name()); #if defined(_linux_) || defined(_darwin_) SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX); - SubstGlobal(demangled, " >", ">"); #endif return demangled; } From a71c29e6a5c868fd63ef8db438c734ceaa4a6d1e Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:26:01 +0300 Subject: [PATCH 35/44] Revert "Fix string_transparent_hash_ut (#158)" This reverts commit eebe4b02cb629982b4db2c857ccba1f7f64dfa1f. --- util/generic/string_transparent_hash_ut.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/util/generic/string_transparent_hash_ut.cpp b/util/generic/string_transparent_hash_ut.cpp index 07703bb979..b87fa2843e 100644 --- a/util/generic/string_transparent_hash_ut.cpp +++ b/util/generic/string_transparent_hash_ut.cpp @@ -3,12 +3,7 @@ #include "strbuf.h" #include - -#if __cplusplus < 202002L - #include -#else - #include -#endif +#include #include @@ -16,15 +11,7 @@ Y_UNIT_TEST_SUITE(StringHashFunctorTests) { Y_UNIT_TEST(TestTransparencyWithUnorderedSet) { // Using Abseil hash set because `std::unordered_set` is transparent only from C++20 (while // we stuck with C++17 right now). - using TTransparentHashSet = - #if __cplusplus < 202002L - absl::flat_hash_set - #else - std::unordered_set - #endif - , TEqualTo>; - - TTransparentHashSet s = {"foo"}; + absl::flat_hash_set, TEqualTo> s = {"foo"}; // If either `THash` or `TEqualTo` is not transparent compilation will fail. UNIT_ASSERT_UNEQUAL(s.find(TStringBuf("foo")), s.end()); UNIT_ASSERT_EQUAL(s.find(TStringBuf("bar")), s.end()); From fe8b6ef5b0ffb82a765dbf57ee493207cdf5de20 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:26:15 +0300 Subject: [PATCH 36/44] Revert "Fix common_ops_ut (#161)" This reverts commit 043286f2b9ed937fc5a279497d7a827f142b1b0d. --- util/random/common_ops_ut.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/random/common_ops_ut.cpp b/util/random/common_ops_ut.cpp index 9a0efa838f..905912bd1e 100644 --- a/util/random/common_ops_ut.cpp +++ b/util/random/common_ops_ut.cpp @@ -45,24 +45,25 @@ Y_UNIT_TEST_SUITE(TestCommonRNG) { } Y_UNIT_TEST(TestStlCompatibility) { - // NOTE: Check if `TRng` can be passed to `std::normal_distribution::operator()`. - // These tests just have to be compilable, so the asserts below are always true. { TRng r; + r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.877167, 0.01); } { TRng r; + r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.5615566731, 0.01); } { TRng r; + r.C_ = 17; std::normal_distribution nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), 0.0, nd.max()); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.430375088, 0.01); } } } From 798dc8876a3f9eab9fcb161d481ecaf62df14c46 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:32:55 +0300 Subject: [PATCH 37/44] Disable type_name_ut test (#164) --- util/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 97624be7dd..c203e159ac 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -279,9 +279,11 @@ if (YDB_SDK_TESTS) system/nice_ut.cpp system/pipe_ut.cpp system/platform_ut.cpp + # NOTE: `progname_ut` checks if the executable file's name, aka the target's # name, is either "util-system-ut" or slightly different variations system/progname_ut.cpp + system/rusage_ut.cpp system/rwlock_ut.cpp system/sanitizers_ut.cpp @@ -292,16 +294,22 @@ if (YDB_SDK_TESTS) system/src_root_ut.cpp system/tempfile_ut.cpp system/tls_ut.cpp - system/type_name_ut.cpp + + # NOTE: this test shouldn't be run with STL, so it's explicitly disabled + # system/type_name_ut.cpp + # NOTE: `thread_ut` compares the executable file's name and the current # thread name, whose length can't be more than 16 bytes in Linux, # so the test name shouldn't be longer than "util-system-ut" system/thread_ut.cpp + system/types_ut.cpp + # TODO: add library/cpp/testing/benchmark # depends only on NBench::Clobber, that's a memory optimization barrier # system/unaligned_mem_ut.cpp system/user_ut.cpp + system/yassert_ut.cpp LINK_LIBRARIES yutil From 4b26d73adc9bcb6b91d49663e1c56bf5103b7e98 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 11:36:05 +0300 Subject: [PATCH 38/44] Temporary comment string_transparent_hash_ut test (#158) --- util/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index c203e159ac..055359afcc 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -96,7 +96,8 @@ if (YDB_SDK_TESTS) generic/stack_ut.cpp generic/store_policy_ut.cpp generic/strbuf_ut.cpp - generic/string_transparent_hash_ut.cpp + # TODO: uncomment this test after we get the fix + # generic/string_transparent_hash_ut.cpp generic/string_ut.cpp generic/typelist_ut.cpp generic/typetraits_ut.cpp From 79af1e27db8862653b5484971b18aa9e1841bff2 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 12:28:42 +0300 Subject: [PATCH 39/44] Add TEST_ARG parameter to testing command --- cmake/testing.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 8a7364f77a..b4f1014f9a 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -70,7 +70,7 @@ endfunction() function(add_ydb_test) set(opts GTEST) set(oneval_args NAME WORKING_DIRECTORY OUTPUT_DIRECTORY) - set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS) + set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS TEST_ARG) cmake_parse_arguments(YDB_TEST "${opts}" "${oneval_args}" @@ -125,6 +125,8 @@ function(add_ydb_test) ${YDB_TEST_NAME} TEST_TARGET ${YDB_TEST_NAME} + TEST_ARG + ${YDB_TEST_TEST_ARG} WORKING_DIRECTORY ${YDB_TEST_WORKING_DIRECTORY} ) @@ -140,6 +142,7 @@ function(add_ydb_test) --fork-tests --print-times --show-fails + ${YDB_TEST_TEST_ARG} WORKING_DIRECTORY ${YDB_TEST_WORKING_DIRECTORY} ) From 0bed8c32e0c85228135eb4639df5f35e006186a1 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 12:29:22 +0300 Subject: [PATCH 40/44] Exclude broken test (#161) --- util/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 055359afcc..1c63cce081 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -185,6 +185,11 @@ if (YDB_SDK_TESTS) cpp-testing-unittest_main LABELS unit + TEST_ARG + --filter-file filter.txt + ) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/random/filter.txt + "-TestCommonRNG::TestStlCompatibility" ) add_ydb_test(NAME util-stream-ut From c73e65fb99b50991d232b8d1e4360058299bd3c6 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Thu, 22 Aug 2024 13:04:23 +0300 Subject: [PATCH 41/44] Add config presets for testing --- .github/actions/build/action.yaml | 2 +- CMakePresets.json | 51 ++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml index 41e6c55486..404fda1888 100644 --- a/.github/actions/build/action.yaml +++ b/.github/actions/build/action.yaml @@ -9,7 +9,7 @@ runs: run: | mkdir -p ../build rm -rf ../build/* - cmake -DYDB_SDK_TESTS=On -DYDB_SDK_EXAMPLES=On -DARCADIA_ROOT="../ydb-cpp-sdk" -DARCADIA_BUILD_ROOT="." --preset release + cmake --preset release-test-with-ccache-basedir - name: Build shell: bash run: | diff --git a/CMakePresets.json b/CMakePresets.json index 0a2b024500..7619864d8c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -40,6 +40,26 @@ "displayName": "Default Release Config", "description": "Default release build configuration using Ninja generator and Clang compiler", "binaryDir": "${sourceDir}/../build" + }, + { + "name": "release-test", + "inherits": "release", + "displayName": "Default Release Test Config", + "description": "Default release build configuration with all tests and examples", + "cacheVariables": { + "YDB_SDK_TESTS": "TRUE", + "YDB_SDK_EXAMPLES": "TRUE" + } + }, + { + "name": "release-test-with-ccache-basedir", + "inherits": "release-test", + "displayName": "Release Test Config CCACHE_BASEDIR Case", + "description": "Only for the case when using CCACHE_BASEDIR", + "cacheVariables": { + "ARCADIA_ROOT": "../ydb-cpp-sdk", + "ARCADIA_BUILD_ROOT": "." + } } ], "buildPresets": [ @@ -51,15 +71,20 @@ ], "testPresets": [ { - "name": "release", - "configurePreset": "release", - "displayName": "Default Release Tests", + "name": "common", + "hidden": true, "output": { "outputOnFailure": true }, "execution": { "timeout": 1200 - }, + } + }, + { + "name": "release", + "inherits": "common", + "configurePreset": "release-test", + "displayName": "Default Release Tests", "environment": { "YDB_ENDPOINT": "localhost:2136", "YDB_DATABASE": "/local" @@ -67,35 +92,25 @@ }, { "name": "release-unit", - "configurePreset": "release", + "inherits": "common", + "configurePreset": "release-test", "displayName": "Default Unit Release Tests", "filter" : { "include": { "label": "unit" } - }, - "output": { - "outputOnFailure": true - }, - "execution": { - "timeout": 1200 } }, { "name": "release-integration", - "configurePreset": "release", + "inherits": "common", + "configurePreset": "release-test", "displayName": "Default Integration Release Tests", - "output": { - "outputOnFailure": true - }, "filter" : { "include": { "label": "integration" } }, - "execution": { - "timeout": 1200 - }, "environment": { "YDB_ENDPOINT": "localhost:2136", "YDB_DATABASE": "/local" From da93098125e1365c545d261e5b91597b0aa2e9f2 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Sun, 25 Aug 2024 18:05:54 +0300 Subject: [PATCH 42/44] Fix ARCADIA_BUILD_ROOT (#164) --- CMakePresets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 7619864d8c..9bdc62add0 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -58,7 +58,7 @@ "description": "Only for the case when using CCACHE_BASEDIR", "cacheVariables": { "ARCADIA_ROOT": "../ydb-cpp-sdk", - "ARCADIA_BUILD_ROOT": "." + "ARCADIA_BUILD_ROOT": "" } } ], From 6372cf91567b1517f392dbcaf757f4da972d5101 Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Sun, 25 Aug 2024 18:13:32 +0300 Subject: [PATCH 43/44] Convert ARCADIA_[BUILD_]ROOT to native path (#164) --- util/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 1c63cce081..a4bddaca3f 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -730,6 +730,8 @@ elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") endif() # NOTE: these definitions are needed to `util/system/src_root.h` works properly +file(TO_NATIVE_PATH "${ARCADIA_ROOT}" ARCADIA_ROOT) +file(TO_NATIVE_PATH "${ARCADIA_BUILD_ROOT}" ARCADIA_BUILD_ROOT) target_compile_definitions(yutil PUBLIC ARCADIA_ROOT=${ARCADIA_ROOT} ARCADIA_BUILD_ROOT=${ARCADIA_BUILD_ROOT} From 45bd7a29b31e7223a890d92e0cbd43e68649125d Mon Sep 17 00:00:00 2001 From: Pavel Tsayukov Date: Sun, 25 Aug 2024 18:45:58 +0300 Subject: [PATCH 44/44] Revert "Fix ARCADIA_BUILD_ROOT (#164)" This reverts commit da93098125e1365c545d261e5b91597b0aa2e9f2. --- CMakePresets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 9bdc62add0..7619864d8c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -58,7 +58,7 @@ "description": "Only for the case when using CCACHE_BASEDIR", "cacheVariables": { "ARCADIA_ROOT": "../ydb-cpp-sdk", - "ARCADIA_BUILD_ROOT": "" + "ARCADIA_BUILD_ROOT": "." } } ],