Skip to content

Commit dd12a0f

Browse files
authored
Improve groupby test utils to include the original location of failure (#20718)
Currently, many groupby tests call to `test_single_agg()` and other utility functions in `groupby_test_util.*` (`test_sum_agg()` and `test_single_scan()`) to execute the test. When a failure happens, GTest only issues a trace location to somewhere in `test_single_agg()` while there is not any information about the actual failed test. That makes debugging a bit tricky. This PR reimplements thesef test functions, adding one more parameter `std::source_location const& location = std::source_location::current()` to carry the caller's information. With this, GTest will report an additional line containing the location of the failed test. For example: ``` Google Test trace: cudf/cpp/tests/groupby/groupby_test_util.cpp:75: <-- line of failure cudf/cpp/tests/groupby/groupby_test_util.cpp:36: Original failure location: cudf/cpp/tests/groupby/sum_tests.cpp:192 ``` Authors: - Nghia Truong (https://github.com/ttnghia) Approvers: - Paul Mattione (https://github.com/pmattione-nvidia) - David Wendt (https://github.com/davidwendt) URL: #20718
1 parent 027c2c2 commit dd12a0f

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

cpp/tests/groupby/groupby_test_util.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -27,8 +27,12 @@ void test_single_agg(cudf::column_view const& keys,
2727
cudf::sorted keys_are_sorted,
2828
std::vector<cudf::order> const& column_order,
2929
std::vector<cudf::null_order> const& null_precedence,
30-
cudf::sorted reference_keys_are_sorted)
30+
cudf::sorted reference_keys_are_sorted,
31+
std::source_location const& location)
3132
{
33+
SCOPED_TRACE("Original failure location: " + std::string{location.file_name()} + ":" +
34+
std::to_string(location.line()));
35+
3236
auto const [sorted_expect_keys, sorted_expect_vals] = [&]() {
3337
if (reference_keys_are_sorted == cudf::sorted::NO) {
3438
auto const sort_expect_order =
@@ -86,7 +90,8 @@ void test_single_agg(cudf::column_view const& keys,
8690
void test_sum_agg(cudf::column_view const& keys,
8791
cudf::column_view const& values,
8892
cudf::column_view const& expected_keys,
89-
cudf::column_view const& expected_values)
93+
cudf::column_view const& expected_values,
94+
std::source_location const& location)
9095
{
9196
auto const do_test = [&](auto const use_sort_option) {
9297
test_single_agg(keys,
@@ -95,7 +100,12 @@ void test_sum_agg(cudf::column_view const& keys,
95100
expected_values,
96101
cudf::make_sum_aggregation<cudf::groupby_aggregation>(),
97102
use_sort_option,
98-
cudf::null_policy::INCLUDE);
103+
cudf::null_policy::INCLUDE,
104+
cudf::sorted::NO,
105+
{},
106+
{},
107+
cudf::sorted::NO,
108+
location);
99109
};
100110
do_test(force_use_sort_impl::YES);
101111
do_test(force_use_sort_impl::NO);
@@ -109,12 +119,15 @@ void test_single_scan(cudf::column_view const& keys,
109119
cudf::null_policy include_null_keys,
110120
cudf::sorted keys_are_sorted,
111121
std::vector<cudf::order> const& column_order,
112-
std::vector<cudf::null_order> const& null_precedence)
122+
std::vector<cudf::null_order> const& null_precedence,
123+
std::source_location const& location)
113124
{
125+
SCOPED_TRACE("Original failure location: " + std::string{location.file_name()} + ":" +
126+
std::to_string(location.line()));
127+
114128
std::vector<cudf::groupby::scan_request> requests;
115129
requests.emplace_back();
116130
requests[0].values = values;
117-
118131
requests[0].aggregations.push_back(std::move(agg));
119132

120133
cudf::groupby::groupby gb_obj(

cpp/tests/groupby/groupby_test_util.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2020-2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -8,6 +8,8 @@
88
#include <cudf/groupby.hpp>
99
#include <cudf/types.hpp>
1010

11+
#include <source_location>
12+
1113
enum class force_use_sort_impl : bool { NO, YES };
1214

1315
void test_single_agg(cudf::column_view const& keys,
@@ -20,12 +22,13 @@ void test_single_agg(cudf::column_view const& keys,
2022
cudf::sorted keys_are_sorted = cudf::sorted::NO,
2123
std::vector<cudf::order> const& column_order = {},
2224
std::vector<cudf::null_order> const& null_precedence = {},
23-
cudf::sorted reference_keys_are_sorted = cudf::sorted::NO);
24-
25+
cudf::sorted reference_keys_are_sorted = cudf::sorted::NO,
26+
std::source_location const& location = std::source_location::current());
2527
void test_sum_agg(cudf::column_view const& keys,
2628
cudf::column_view const& values,
2729
cudf::column_view const& expected_keys,
28-
cudf::column_view const& expected_values);
30+
cudf::column_view const& expected_values,
31+
std::source_location const& location = std::source_location::current());
2932

3033
void test_single_scan(cudf::column_view const& keys,
3134
cudf::column_view const& values,
@@ -35,4 +38,5 @@ void test_single_scan(cudf::column_view const& keys,
3538
cudf::null_policy include_null_keys = cudf::null_policy::EXCLUDE,
3639
cudf::sorted keys_are_sorted = cudf::sorted::NO,
3740
std::vector<cudf::order> const& column_order = {},
38-
std::vector<cudf::null_order> const& null_precedence = {});
41+
std::vector<cudf::null_order> const& null_precedence = {},
42+
std::source_location const& location = std::source_location::current());

0 commit comments

Comments
 (0)