diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 136f43ee706..5883377d422 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -861,15 +861,7 @@ if(CUDF_BUILD_TESTUTIL) add_library(cudf::cudftest_default_stream ALIAS cudftest_default_stream) - add_library( - cudftestutil SHARED - tests/io/metadata_utilities.cpp - tests/utilities/column_utilities.cu - tests/utilities/debug_utilities.cu - tests/utilities/random_seed.cpp - tests/utilities/table_utilities.cu - tests/utilities/tdigest_utilities.cu - ) + add_library(cudftestutil INTERFACE) set_target_properties( cudftestutil @@ -878,28 +870,23 @@ if(CUDF_BUILD_TESTUTIL) # set target compile options CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON - CXX_VISIBILITY_PRESET hidden CUDA_STANDARD 17 CUDA_STANDARD_REQUIRED ON - CUDA_VISIBILITY_PRESET hidden - POSITION_INDEPENDENT_CODE ON - INTERFACE_POSITION_INDEPENDENT_CODE ON ) target_compile_options( - cudftestutil PUBLIC "$:${CUDF_CXX_FLAGS}>>" - "$:${CUDF_CUDA_FLAGS}>>" + cudftestutil INTERFACE "$:${CUDF_CXX_FLAGS}>>" + "$:${CUDF_CUDA_FLAGS}>>" ) target_link_libraries( - cudftestutil - PUBLIC Threads::Threads cudf cudftest_default_stream - PRIVATE GTest::gmock GTest::gtest $ + cudftestutil INTERFACE Threads::Threads cudf cudftest_default_stream + $ ) target_include_directories( - cudftestutil PUBLIC "$" - "$" + cudftestutil INTERFACE "$" + "$" ) rapids_cuda_set_runtime(cudftestutil USE_STATIC ${CUDA_STATIC_RUNTIME}) add_library(cudf::cudftestutil ALIAS cudftestutil) diff --git a/cpp/benchmarks/CMakeLists.txt b/cpp/benchmarks/CMakeLists.txt index 4113e38dcf4..ee6094ff857 100644 --- a/cpp/benchmarks/CMakeLists.txt +++ b/cpp/benchmarks/CMakeLists.txt @@ -65,14 +65,12 @@ target_include_directories( # Use an OBJECT library so we only compile these helper source files only once add_library( cudf_benchmark_common OBJECT - "${CUDF_SOURCE_DIR}/tests/utilities/random_seed.cpp" - synchronization/synchronization.cpp - io/cuio_common.cpp - common/table_utilities.cpp - common/benchmark_utilities.cpp - common/nvbench_utilities.cpp + common/random_seed_impl.cpp synchronization/synchronization.cpp io/cuio_common.cpp + common/table_utilities.cpp common/benchmark_utilities.cpp common/nvbench_utilities.cpp +) +target_link_libraries( + cudf_benchmark_common PRIVATE cudftestutil cudf_datagen $ ) -target_link_libraries(cudf_benchmark_common PRIVATE cudf_datagen $) add_custom_command( OUTPUT CUDF_BENCHMARKS COMMAND echo Running benchmarks diff --git a/cpp/benchmarks/common/random_seed_impl.cpp b/cpp/benchmarks/common/random_seed_impl.cpp new file mode 100644 index 00000000000..7b261e9262f --- /dev/null +++ b/cpp/benchmarks/common/random_seed_impl.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include diff --git a/cpp/include/cudf_test/cudf_gtest.hpp b/cpp/include/cudf_test/cudf_gtest.hpp index 89394fbd1c3..0c17224bd12 100644 --- a/cpp/include/cudf_test/cudf_gtest.hpp +++ b/cpp/include/cudf_test/cudf_gtest.hpp @@ -16,8 +16,7 @@ #pragma once -#include -#include +#include /** * @brief test macro to be expects `expr` to return cudaSuccess diff --git a/cpp/include/cudf_test/cudf_test_impl.cuh b/cpp/include/cudf_test/cudf_test_impl.cuh new file mode 100644 index 00000000000..03ea63f9a3e --- /dev/null +++ b/cpp/include/cudf_test/cudf_test_impl.cuh @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/** + * @file cudf_test_impl.cuh + * @brief Contains CUDA C++ symbol definitions for cudf_test APIs. This header must be included to + * one translation unit. + * + */ + +#include +#include +#include +#include diff --git a/cpp/include/cudf_test/cudf_test_impl.hpp b/cpp/include/cudf_test/cudf_test_impl.hpp new file mode 100644 index 00000000000..61d100ccc25 --- /dev/null +++ b/cpp/include/cudf_test/cudf_test_impl.hpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/** + * @file cudf_test_impl.cuh + * @brief Contains C++ symbol definitions for cudf_test APIs. Must be included to one translation + * unit. + * + */ + +#include +#include diff --git a/cpp/include/cudf_test/metadata_utilities_impl.hpp b/cpp/include/cudf_test/metadata_utilities_impl.hpp index 84f04f67038..3439124b1bd 100644 --- a/cpp/include/cudf_test/metadata_utilities_impl.hpp +++ b/cpp/include/cudf_test/metadata_utilities_impl.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ #include - -#include +#include namespace cudf::test { diff --git a/cpp/include/cudf_test/testing_api.hpp b/cpp/include/cudf_test/testing_api.hpp new file mode 100644 index 00000000000..b1c876f75d3 --- /dev/null +++ b/cpp/include/cudf_test/testing_api.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/** + * @file testing_api.hpp + * @brief exposes the testing APIs, GTEST can be disabled by defining CUDF_TEST_EXCLUDE_GTEST=1, and + * then including a testing API that conforms to GTEST's API before including any cudf_test headers. + * The testing API must define CUDF_TEST_TESTING_API_IMPL to signal cudf_test that it conforms to + * the GTest API. + * + */ + +#if !(defined(CUDF_TEST_EXCLUDE_GTEST) && CUDF_TEST_EXCLUDE_GTEST) +#include +#endif + +#if !defined(CUDF_TEST_TESTING_API_IMPL) +#error \ + "No CUDF Testing API implementation found, Include a testing API that conforms to the GoogleTest API before including libcudftestutil headers" +#endif diff --git a/cpp/include/cudf_test/testing_api_gtest.hpp b/cpp/include/cudf_test/testing_api_gtest.hpp new file mode 100644 index 00000000000..63bed5d90ba --- /dev/null +++ b/cpp/include/cudf_test/testing_api_gtest.hpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#define CUDF_TEST_TESTING_API_IMPL + +#include +#include diff --git a/cpp/include/cudf_test/testing_main.hpp b/cpp/include/cudf_test/testing_main.hpp index 272c91133f8..3dd82a8a06b 100644 --- a/cpp/include/cudf_test/testing_main.hpp +++ b/cpp/include/cudf_test/testing_main.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -191,22 +192,30 @@ inline auto make_stream_mode_adaptor(cxxopts::ParseResult const& cmd_opts) return adaptor; } +/** + * @brief Should be called in every test program that uses rmm allocators since it maintains the + * lifespan of the rmm default memory resource. this function parses the command line to customize + * test behavior, like the allocation mode used for creating the default memory resource. + * + */ +inline void init_cudf_test(int argc, char** argv) +{ + // static lifetime to keep rmm resource alive till tests end + auto const cmd_opts = parse_cudf_test_opts(argc, argv); + [[maybe_unused]] static auto mr = make_memory_resource_adaptor(cmd_opts); + [[maybe_unused]] static auto adaptor = make_stream_mode_adaptor(cmd_opts); +} + /** * @brief Macro that defines main function for gtest programs that use rmm * - * Should be included in every test program that uses rmm allocators since - * it maintains the lifespan of the rmm default memory resource. * This `main` function is a wrapper around the google test generated `main`, - * maintaining the original functionality. In addition, this custom `main` - * function parses the command line to customize test behavior, like the - * allocation mode used for creating the default memory resource. + * maintaining the original functionality. */ -#define CUDF_TEST_PROGRAM_MAIN() \ - int main(int argc, char** argv) \ - { \ - ::testing::InitGoogleTest(&argc, argv); \ - auto const cmd_opts = parse_cudf_test_opts(argc, argv); \ - [[maybe_unused]] auto mr = make_memory_resource_adaptor(cmd_opts); \ - [[maybe_unused]] auto adaptor = make_stream_mode_adaptor(cmd_opts); \ - return RUN_ALL_TESTS(); \ +#define CUDF_TEST_PROGRAM_MAIN() \ + int main(int argc, char** argv) \ + { \ + ::testing::InitGoogleTest(&argc, argv); \ + init_cudf_test(argc, argv); \ + return RUN_ALL_TESTS(); \ } diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index b67d922d377..6e5a565939b 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -41,7 +41,9 @@ function(ConfigureTest CMAKE_TEST_NAME) set(_CUDF_TEST_STREAM_MODE cudf) endif() - add_executable(${CMAKE_TEST_NAME} ${_CUDF_TEST_UNPARSED_ARGUMENTS}) + add_executable( + ${CMAKE_TEST_NAME} ${_CUDF_TEST_UNPARSED_ARGUMENTS} cudf_test_impl.cu cudf_test_impl.cpp + ) set_target_properties( ${CMAKE_TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$" @@ -59,6 +61,7 @@ function(ConfigureTest CMAKE_TEST_NAME) PRIVATE cudftestutil GTest::gmock GTest::gmock_main GTest::gtest GTest::gtest_main nvtx3::nvtx3-cpp $ "${_CUDF_TEST_EXTRA_LIBS}" ) + target_compile_definitions(${CMAKE_TEST_NAME} PRIVATE CUDF_TEST_EXCLUDE_GTEST=0) rapids_cuda_set_runtime(${CMAKE_TEST_NAME} USE_STATIC ${CUDA_STATIC_RUNTIME}) rapids_test_add( NAME ${CMAKE_TEST_NAME} diff --git a/cpp/tests/cudf_test_impl.cpp b/cpp/tests/cudf_test_impl.cpp new file mode 100644 index 00000000000..1951c036129 --- /dev/null +++ b/cpp/tests/cudf_test_impl.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include diff --git a/cpp/tests/cudf_test_impl.cu b/cpp/tests/cudf_test_impl.cu new file mode 100644 index 00000000000..279e19bc0c1 --- /dev/null +++ b/cpp/tests/cudf_test_impl.cu @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include