Skip to content

Commit

Permalink
removed cudftestutil's gtest dependency and made it header-only
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Sep 28, 2024
1 parent 4eb2ce0 commit f83f7f3
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 46 deletions.
27 changes: 7 additions & 20 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>>"
"$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>>"
cudftestutil INTERFACE "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>>"
"$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>>"
)

target_link_libraries(
cudftestutil
PUBLIC Threads::Threads cudf cudftest_default_stream
PRIVATE GTest::gmock GTest::gtest $<TARGET_NAME_IF_EXISTS:conda_env>
cudftestutil INTERFACE Threads::Threads cudf cudftest_default_stream
$<TARGET_NAME_IF_EXISTS:conda_env>
)

target_include_directories(
cudftestutil PUBLIC "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>"
cudftestutil INTERFACE "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>"
)
rapids_cuda_set_runtime(cudftestutil USE_STATIC ${CUDA_STATIC_RUNTIME})
add_library(cudf::cudftestutil ALIAS cudftestutil)
Expand Down
12 changes: 5 additions & 7 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_NAME_IF_EXISTS:conda_env>
)
target_link_libraries(cudf_benchmark_common PRIVATE cudf_datagen $<TARGET_NAME_IF_EXISTS:conda_env>)
add_custom_command(
OUTPUT CUDF_BENCHMARKS
COMMAND echo Running benchmarks
Expand Down
17 changes: 17 additions & 0 deletions cpp/benchmarks/common/random_seed_impl.cpp
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/random_seed_impl.hpp>
3 changes: 1 addition & 2 deletions cpp/include/cudf_test/cudf_gtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#pragma once

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cudf_test/testing_api.hpp>

/**
* @brief test macro to be expects `expr` to return cudaSuccess
Expand Down
29 changes: 29 additions & 0 deletions cpp/include/cudf_test/cudf_test_impl.cuh
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/column_utilities_impl.cuh>
#include <cudf_test/debug_utilities_impl.cuh>
#include <cudf_test/table_utilities_impl.cuh>
#include <cudf_test/tdigest_utilities_impl.cuh>
27 changes: 27 additions & 0 deletions cpp/include/cudf_test/cudf_test_impl.hpp
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/metadata_utilities_impl.hpp>
#include <cudf_test/random_seed_impl.hpp>
5 changes: 2 additions & 3 deletions cpp/include/cudf_test/metadata_utilities_impl.hpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,8 +15,7 @@
*/

#include <cudf_test/io_metadata_utilities.hpp>

#include <gmock/gmock.h>
#include <cudf_test/testing_api.hpp>

namespace cudf::test {

Expand Down
35 changes: 35 additions & 0 deletions cpp/include/cudf_test/testing_api.hpp
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/testing_api_gtest.hpp>
#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
22 changes: 22 additions & 0 deletions cpp/include/cudf_test/testing_api_gtest.hpp
Original file line number Diff line number Diff line change
@@ -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 <gmock/gmock.h>
#include <gtest/gtest.h>
35 changes: 22 additions & 13 deletions cpp/include/cudf_test/testing_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/cxxopts.hpp>
#include <cudf_test/stream_checking_resource_adaptor.hpp>
#include <cudf_test/testing_api.hpp>

#include <cudf/utilities/error.hpp>
#include <cudf/utilities/export.hpp>
Expand Down Expand Up @@ -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(); \
}
5 changes: 4 additions & 1 deletion cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<BUILD_INTERFACE:${CUDF_BINARY_DIR}/gtests>"
Expand All @@ -59,6 +61,7 @@ function(ConfigureTest CMAKE_TEST_NAME)
PRIVATE cudftestutil GTest::gmock GTest::gmock_main GTest::gtest GTest::gtest_main
nvtx3::nvtx3-cpp $<TARGET_NAME_IF_EXISTS:conda_env> "${_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}
Expand Down
17 changes: 17 additions & 0 deletions cpp/tests/cudf_test_impl.cpp
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/cudf_test_impl.hpp>
17 changes: 17 additions & 0 deletions cpp/tests/cudf_test_impl.cu
Original file line number Diff line number Diff line change
@@ -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 <cudf_test/cudf_test_impl.cuh>

0 comments on commit f83f7f3

Please sign in to comment.