Skip to content

Commit

Permalink
Enhance unit tests by adopting consistent naming conventions. (#641)
Browse files Browse the repository at this point in the history
This PR adopts uniform naming for unit tests, enhancing the clarity of
the CTest execution log. It also relocates map find and contains unit
tests into separate files to improve build efficiency.

---------

Co-authored-by: Daniel Jünger <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 20a16ec commit 644e553
Show file tree
Hide file tree
Showing 37 changed files with 216 additions and 116 deletions.
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ ConfigureTest(STATIC_SET_TEST
# - static_map tests ------------------------------------------------------------------------------
ConfigureTest(STATIC_MAP_TEST
static_map/capacity_test.cu
static_map/contains_test.cu
static_map/custom_type_test.cu
static_map/duplicate_keys_test.cu
static_map/erase_test.cu
static_map/find_test.cu
static_map/for_each_test.cu
static_map/hash_test.cu
static_map/heterogeneous_lookup_test.cu
Expand All @@ -87,7 +89,6 @@ ConfigureTest(STATIC_MAP_TEST
static_map/key_sentinel_test.cu
static_map/shared_memory_test.cu
static_map/stream_test.cu
static_map/unique_sequence_test.cu
static_map/rehash_test.cu)

###################################################################################################
Expand Down
8 changes: 6 additions & 2 deletions tests/bloom_filter/arrow_policy_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ void test_filter_bitset(Filter& filter, size_t num_keys)
})));
}

TEMPLATE_TEST_CASE_SIG(
"Arrow filter policy bitset validation", "", (class Key), (int32_t), (int64_t), (float))
TEMPLATE_TEST_CASE_SIG("bloom_filter arrow filter policy bitset validation",
"",
(class Key),
(int32_t),
(int64_t),
(float))
{
// Get test settings
auto const [sub_filters, num_keys] = get_arrow_filter_test_settings<Key>();
Expand Down
4 changes: 2 additions & 2 deletions tests/bloom_filter/unique_sequence_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void test_unique_sequence(Filter& filter, size_type num_keys)
}

TEMPLATE_TEST_CASE_SIG(
"Unique sequence with default policy",
"bloom_filter default policy tests",
"",
((class Key, class Policy), Key, Policy),
(int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint32_t, 1>),
Expand All @@ -105,7 +105,7 @@ TEMPLATE_TEST_CASE_SIG(
test_unique_sequence(filter, num_keys);
}

TEMPLATE_TEST_CASE_SIG("Unique sequence with arrow policy",
TEMPLATE_TEST_CASE_SIG("bloom_filter arrow policy tests",
"",
((class Key, class Policy), Key, Policy),
(int32_t, cuco::arrow_filter_policy<int32_t>),
Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_bitset/find_next_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-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 Down Expand Up @@ -37,7 +37,7 @@ __global__ void find_next_kernel(BitsetRef ref, size_type num_elements, OutputIt

extern bool modulo_bitgen(uint64_t i); // Defined in get_test.cu

TEST_CASE("Find next set test", "")
TEST_CASE("dynamic_bitset find next set test", "")
{
cuco::experimental::detail::dynamic_bitset bv;

Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_bitset/get_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-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 Down Expand Up @@ -37,7 +37,7 @@ __global__ void test_kernel(BitsetRef ref, size_type num_elements, OutputIt outp

bool modulo_bitgen(uint64_t i) { return i % 7 == 0; }

TEST_CASE("Get test", "")
TEST_CASE("dynamic_bitset get test", "")
{
cuco::experimental::detail::dynamic_bitset bv;

Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_bitset/rank_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-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 @@ -26,7 +26,7 @@

extern bool modulo_bitgen(uint64_t i); // Defined in get_test.cu

TEST_CASE("Rank test", "")
TEST_CASE("dynamic_bitset rank test", "")
{
cuco::experimental::detail::dynamic_bitset bv;

Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_bitset/select_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-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 Down Expand Up @@ -37,7 +37,7 @@ __global__ void select_false_kernel(BitsetRef ref, size_type num_elements, Outpu

extern bool modulo_bitgen(uint64_t i); // Defined in get_test.cu

TEST_CASE("Select test", "")
TEST_CASE("dynamic_bitset select test", "")
{
cuco::experimental::detail::dynamic_bitset bv;

Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_bitset/size_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-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 @@ -18,7 +18,7 @@

#include <catch2/catch_test_macros.hpp>

TEST_CASE("Size computation", "")
TEST_CASE("dynamic_bitset size computation test", "")
{
cuco::experimental::detail::dynamic_bitset bv;
using size_type = std::size_t;
Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_map/erase_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
* Copyright (c) 2022-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 @@ -25,7 +25,7 @@

#include <catch2/catch_template_test_macros.hpp>

TEMPLATE_TEST_CASE_SIG("erase key",
TEMPLATE_TEST_CASE_SIG("dynamic_map erase tests",
"",
((typename Key, typename Value), Key, Value),
(int32_t, int32_t),
Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_map/unique_sequence_test.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-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 Down Expand Up @@ -30,7 +30,7 @@

#include <catch2/catch_template_test_macros.hpp>

TEMPLATE_TEST_CASE_SIG("Unique sequence of keys",
TEMPLATE_TEST_CASE_SIG("dynamic_map unique sequence tests",
"",
((typename Key, typename Value), Key, Value),
(int32_t, int32_t),
Expand Down
2 changes: 1 addition & 1 deletion tests/static_map/capacity_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <catch2/catch_test_macros.hpp>

TEST_CASE("Static map capacity", "")
TEST_CASE("static_map capacity test", "")
{
using Key = int32_t;
using T = int32_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

using size_type = int32_t;

int32_t constexpr SENTINEL = -1;

template <typename Map>
void test_unique_sequence(Map& map, size_type num_keys)
{
Expand Down Expand Up @@ -63,17 +61,6 @@ void test_unique_sequence(Map& map, size_type num_keys)
REQUIRE(cuco::test::none_of(d_contained.begin(), d_contained.end(), thrust::identity{}));
}

SECTION("Non-inserted keys have no matches")
{
thrust::device_vector<Value> d_results(num_keys);

map.find(keys_begin, keys_begin + num_keys, d_results.begin());
auto zip = thrust::make_zip_iterator(thrust::make_tuple(
d_results.begin(), thrust::constant_iterator<Key>{map.empty_key_sentinel()}));

REQUIRE(cuco::test::all_of(zip, zip + num_keys, zip_equal));
}

SECTION("All conditionally inserted keys should be contained")
{
auto const inserted = map.insert_if(
Expand All @@ -92,7 +79,6 @@ void test_unique_sequence(Map& map, size_type num_keys)
}

map.insert(pairs_begin, pairs_begin + num_keys);
REQUIRE(map.size() == num_keys);

SECTION("All inserted keys should be contained.")
{
Expand All @@ -115,37 +101,6 @@ void test_unique_sequence(Map& map, size_type num_keys)
REQUIRE(cuco::test::all_of(zip, zip + num_keys, zip_equal));
}

SECTION("All inserted keys should be correctly recovered during find")
{
thrust::device_vector<Value> d_results(num_keys);

map.find(keys_begin, keys_begin + num_keys, d_results.begin());
auto zip = thrust::make_zip_iterator(thrust::make_tuple(d_results.begin(), keys_begin));

REQUIRE(cuco::test::all_of(zip, zip + num_keys, zip_equal));
}

SECTION("Conditional find should return valid values on even inputs.")
{
auto found_results = thrust::device_vector<Key>(num_keys);
auto gold_fn = cuda::proclaim_return_type<Value>([] __device__(auto const& i) {
return i % 2 == 0 ? static_cast<Value>(i) : Value{SENTINEL};
});

map.find_if(keys_begin,
keys_begin + num_keys,
thrust::counting_iterator<std::size_t>{0},
is_even,
found_results.begin());

REQUIRE(cuco::test::equal(
found_results.begin(),
found_results.end(),
thrust::make_transform_iterator(thrust::counting_iterator<Key>{0}, gold_fn),
cuda::proclaim_return_type<bool>(
[] __device__(auto const& found, auto const& gold) { return found == gold; })));
}

SECTION("All inserted key-values should be properly retrieved")
{
thrust::device_vector<Value> d_values(num_keys);
Expand All @@ -163,33 +118,23 @@ void test_unique_sequence(Map& map, size_type num_keys)
}

TEMPLATE_TEST_CASE_SIG(
"static_map: unique sequence",
"static_map: contains + retrieve_all tests",
"",
((typename Key, typename Value, cuco::test::probe_sequence Probe, int CGSize),
Key,
Value,
Probe,
CGSize),
(int32_t, int32_t, cuco::test::probe_sequence::double_hashing, 1),
(int32_t, int64_t, cuco::test::probe_sequence::double_hashing, 1),
(int32_t, int32_t, cuco::test::probe_sequence::double_hashing, 2),
(int32_t, int64_t, cuco::test::probe_sequence::double_hashing, 2),
(int64_t, int32_t, cuco::test::probe_sequence::double_hashing, 1),
(int64_t, int64_t, cuco::test::probe_sequence::double_hashing, 1),
(int64_t, int32_t, cuco::test::probe_sequence::double_hashing, 2),
(int64_t, int64_t, cuco::test::probe_sequence::double_hashing, 2),
(int32_t, int32_t, cuco::test::probe_sequence::linear_probing, 1),
(int32_t, int64_t, cuco::test::probe_sequence::linear_probing, 1),
(int32_t, int32_t, cuco::test::probe_sequence::linear_probing, 2),
(int32_t, int64_t, cuco::test::probe_sequence::linear_probing, 2),
(int64_t, int32_t, cuco::test::probe_sequence::linear_probing, 1),
(int64_t, int64_t, cuco::test::probe_sequence::linear_probing, 1),
(int64_t, int32_t, cuco::test::probe_sequence::linear_probing, 2),
(int64_t, int64_t, cuco::test::probe_sequence::linear_probing, 2))
{
constexpr size_type num_keys{400};
constexpr size_type gold_capacity = CGSize == 1 ? 422 // 211 x 1 x 2
: 412; // 103 x 2 x 2

// XXX: testing static extent is intended, DO NOT CHANGE
using extent_type = cuco::extent<size_type, num_keys>;
Expand All @@ -206,9 +151,7 @@ TEMPLATE_TEST_CASE_SIG(
probe,
cuco::cuda_allocator<cuda::std::byte>,
cuco::storage<2>>{
extent_type{}, cuco::empty_key<Key>{SENTINEL}, cuco::empty_value<Value>{SENTINEL}};

REQUIRE(map.capacity() == gold_capacity);
extent_type{}, cuco::empty_key<Key>{-1}, cuco::empty_value<Value>{-1}};

test_unique_sequence(map, num_keys);
}
2 changes: 1 addition & 1 deletion tests/static_map/custom_type_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct custom_key_equals {
}
};

TEMPLATE_TEST_CASE_SIG("User defined key and value type",
TEMPLATE_TEST_CASE_SIG("static_map custom key and value type tests",
"",
((typename Key, typename Value), Key, Value),
#if defined(CUCO_HAS_INDEPENDENT_THREADS) // Key type larger than 8B only supported for sm_70 and
Expand Down
Loading

0 comments on commit 644e553

Please sign in to comment.