Skip to content

Commit

Permalink
tests: Beautify test output
Browse files Browse the repository at this point in the history
We can run an individual test for each implementation now. Further, the
test names are easier to recognize.

Signed-off-by: Johannes Demel <[email protected]>
  • Loading branch information
jdemel committed Aug 20, 2024
1 parent ea1604b commit 0858869
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 89 deletions.
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_executable(
${volk_test_files}
)

target_compile_features(volk_tests PUBLIC cxx_std_20)

target_link_libraries(volk_tests
PRIVATE
GTest::gtest_main
Expand Down
61 changes: 26 additions & 35 deletions tests/test_volk_32f_x3_sum_of_poly_32f.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class volk_32f_x3_sum_of_poly_32f_test : public VolkTest
protected:
void SetUp() override
{
initialize_implementation_names(volk_32f_x3_sum_of_poly_32f_get_func_desc());
initialize_data(GetParam());
initialize_test(GetParam());
initialize_data(vector_length);
}

void initialize_data(const size_t length)
Expand Down Expand Up @@ -66,6 +66,7 @@ class volk_32f_x3_sum_of_poly_32f_test : public VolkTest
result = volk::vector<float>(1, 0.0);
ua_result.push_back(result.at(0));
ua_result.push_back(result.at(0));
tolerance = std::max(expected * 1e-5, 1e-5);
}

void execute_aligned(const std::string impl_name)
Expand All @@ -76,6 +77,7 @@ class volk_32f_x3_sum_of_poly_32f_test : public VolkTest
cutoff.data(),
vector_length,
impl_name.c_str());
EXPECT_NEAR(result.at(0), expected, tolerance);
}

void execute_unaligned(const std::string impl_name)
Expand All @@ -86,6 +88,7 @@ class volk_32f_x3_sum_of_poly_32f_test : public VolkTest
ua_cutoff.data() + 1,
vector_length,
impl_name.c_str());
EXPECT_NEAR(ua_result.at(1), expected, tolerance);
}

// void TearDown() override {}
Expand All @@ -99,42 +102,30 @@ class volk_32f_x3_sum_of_poly_32f_test : public VolkTest
volk::vector<float> result;
volk::vector<float> ua_result;
float expected = 0.0f;
float tolerance = 1.0e-5;
};


TEST_P(volk_32f_x3_sum_of_poly_32f_test, aligned)
{
for (auto name : implementation_names) {
auto tol = std::max(expected * 1e-5, 1e-5);
fmt::print(
"test aligned implementation: {:>12}, size={} ...", name, vector_length);
auto start = std::chrono::steady_clock::now();

execute_aligned(name);

std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
EXPECT_NEAR(result.at(0), expected, tol);
}
}

TEST_P(volk_32f_x3_sum_of_poly_32f_test, unaligned)
TEST_P(volk_32f_x3_sum_of_poly_32f_test, run)
{
for (auto name : unaligned_impl_names) {
auto tol = std::max(expected * 1e-5, 1e-5);
fmt::print(
"test unaligned implementation: {:>12}, size={} ...", name, vector_length);
auto start = std::chrono::steady_clock::now();

execute_unaligned(name);

std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
EXPECT_NEAR(ua_result.at(1), expected, tol);
fmt::print("test {} implementation: {:>12}, size={} ...",
is_aligned_implementation ? "aligned" : "unaligned",
implementation_name,
vector_length);
auto start = std::chrono::steady_clock::now();

if (is_aligned_implementation) {
execute_aligned(implementation_name);
} else {
execute_unaligned(implementation_name);
}
std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
}


INSTANTIATE_TEST_SUITE_P(volk_32f_x3_sum_of_poly_32f,
volk_32f_x3_sum_of_poly_32f_test,
testing::Values(7, 32, 128, 1023, 65535, 131071));
INSTANTIATE_TEST_SUITE_P(
volk_32f_x3_sum_of_poly_32f,
volk_32f_x3_sum_of_poly_32f_test,
testing::Combine(testing::ValuesIn(get_kernel_implementation_name_list(
volk_32f_x3_sum_of_poly_32f_get_func_desc())),
testing::ValuesIn(default_vector_sizes)),
generate_volk_test_name());
65 changes: 24 additions & 41 deletions tests/test_volk_32fc_x2_multiply_32fc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <gtest/gtest-param-test.h>
#include <gtest/gtest.h>
#include <volk/volk.h>
#include <volk/volk_alloc.hh>
#include <chrono>


class volk_32fc_x2_multiply_32fc_test : public VolkTest
{
protected:
void SetUp() override
{
initialize_implementation_names(volk_32fc_x2_multiply_32fc_get_func_desc());
initialize_data(GetParam());
initialize_test(GetParam());
initialize_data(vector_length);
}

void initialize_data(const size_t length)
Expand Down Expand Up @@ -61,10 +61,9 @@ class volk_32fc_x2_multiply_32fc_test : public VolkTest
vec1.data() + 1,
vector_length - 1,
impl_name.c_str());
EXPECT_TRUE(AreComplexFloatingPointArraysAlmostEqual(expected, ua_result));
}

// void TearDown() override {}
size_t vector_length;
volk::vector<lv_32fc_t> vec0;
volk::vector<lv_32fc_t> vec1;
volk::vector<lv_32fc_t> result;
Expand All @@ -73,46 +72,30 @@ class volk_32fc_x2_multiply_32fc_test : public VolkTest
volk::vector<lv_32fc_t> ua_result;
};


TEST_P(volk_32fc_x2_multiply_32fc_test, aligned)
TEST_P(volk_32fc_x2_multiply_32fc_test, run)
{
for (auto name : implementation_names) {
fmt::print(
"test aligned implementation: {:>12}, size={} ...", name, vector_length);
auto start = std::chrono::steady_clock::now();

execute_aligned(name);

std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
EXPECT_TRUE(AreComplexFloatingPointArraysAlmostEqual(expected, result));
fmt::print("test {} implementation: {:>12}, size={} ...",
is_aligned_implementation ? "aligned" : "unaligned",
implementation_name,
vector_length);
auto start = std::chrono::steady_clock::now();

if (is_aligned_implementation) {
execute_aligned(implementation_name);
} else {
execute_unaligned(implementation_name);
}
}

TEST_P(volk_32fc_x2_multiply_32fc_test, unaligned)
{
for (auto name : unaligned_impl_names) {
RecordProperty("aligned", false);
RecordProperty("implementation", name);
RecordProperty("size", vector_length);
fmt::print(
"test unaligned implementation: {:>12}, size={} ...", name, vector_length);
auto start = std::chrono::steady_clock::now();

execute_unaligned(name);

std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
EXPECT_TRUE(AreComplexFloatingPointArraysAlmostEqual(expected, ua_result));
}
std::chrono::duration<double> elapsed = std::chrono::steady_clock::now() - start;
fmt::print("\tduration={}\n", elapsed);
}


INSTANTIATE_TEST_SUITE_P(volk_32fc_x2_multiply_32fc,
volk_32fc_x2_multiply_32fc_test,
testing::Values(7, 32, 128, 1023, 131071),
testing::PrintToStringParamName()
// [](const testing::TestParamInfo<int>& info) {
// return fmt::format("{}", info.param);
// }
);
INSTANTIATE_TEST_SUITE_P(
volk_32fc_x2_multiply_32fc,
volk_32fc_x2_multiply_32fc_test,
testing::Combine(testing::ValuesIn(get_kernel_implementation_name_list(
volk_32fc_x2_multiply_32fc_get_func_desc())),
testing::ValuesIn(default_vector_sizes)),
generate_volk_test_name());
27 changes: 24 additions & 3 deletions tests/volk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ::testing::AssertionResult AreComplexFloatingPointArraysAlmostEqual(const T& exp
return ::testing::AssertionSuccess();
}

std::vector<std::string> get_kernel_implementation_name_list(volk_func_desc_t desc)
std::vector<std::string> get_kernel_implementation_name_list(const volk_func_desc_t desc)
{
std::vector<std::string> names;
for (size_t i = 0; i < desc.n_impls; i++) {
Expand All @@ -65,17 +65,38 @@ std::vector<std::string> get_kernel_implementation_name_list(volk_func_desc_t de
return names;
}

bool is_aligned_implementation_name(const std::string& name)
{
return name.rfind("a_", 0) == 0;
}

std::tuple<std::vector<std::string>, std::vector<std::string>>
separate_implementations_by_alignment(std::vector<std::string> names)
separate_implementations_by_alignment(const std::vector<std::string>& names)
{
std::vector<std::string> aligned;
std::vector<std::string> unaligned;
for (auto name : names) {
if (name.rfind("a_", 0) == 0) {
if (is_aligned_implementation_name(name)) {
aligned.push_back(name);
} else {
unaligned.push_back(name);
}
}
return { aligned, unaligned };
}

std::vector<std::string>
get_aligned_kernel_implementation_names(const volk_func_desc_t desc)
{
auto impls = get_kernel_implementation_name_list(desc);
auto [aligned, unaligned] = separate_implementations_by_alignment(impls);
return aligned;
}

std::vector<std::string>
get_unaligned_kernel_implementation_names(const volk_func_desc_t desc)
{
auto impls = get_kernel_implementation_name_list(desc);
auto [aligned, unaligned] = separate_implementations_by_alignment(impls);
return unaligned;
}
36 changes: 26 additions & 10 deletions tests/volk_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,43 @@
#include <fmt/ranges.h>
#include <gtest/gtest.h>
#include <volk/volk.h>
#include <array>
#include <tuple>

static constexpr std::array<size_t, 5> default_vector_sizes{ 7, 32, 128, 1023, 131071 };

std::vector<std::string> get_kernel_implementation_name_list(volk_func_desc_t desc);
std::vector<std::string> get_kernel_implementation_name_list(const volk_func_desc_t desc);

bool is_aligned_implementation_name(const std::string& name);

std::tuple<std::vector<std::string>, std::vector<std::string>>
separate_implementations_by_alignment(std::vector<std::string> names);
separate_implementations_by_alignment(const std::vector<std::string>& names);

std::vector<std::string>
get_aligned_kernel_implementation_names(const volk_func_desc_t desc);
std::vector<std::string>
get_unaligned_kernel_implementation_names(const volk_func_desc_t desc);

struct generate_volk_test_name {
template <class ParamType>
std::string operator()(const ::testing::TestParamInfo<ParamType>& info) const
{
return fmt::format("{}_{}", std::get<0>(info.param), std::get<1>(info.param));
}
};

class VolkTest : public ::testing::TestWithParam<int>
class VolkTest : public ::testing::TestWithParam<std::tuple<std::string, size_t>>
{
protected:
void initialize_implementation_names(volk_func_desc_t desc)
void initialize_test(const std::tuple<std::string, size_t>& param)
{
implementation_names = get_kernel_implementation_name_list(desc);
std::tie(aligned_impl_names, unaligned_impl_names) =
separate_implementations_by_alignment(implementation_names);
std::tie(implementation_name, vector_length) = param;
is_aligned_implementation = is_aligned_implementation_name(implementation_name);
}

std::vector<std::string> implementation_names;
std::vector<std::string> aligned_impl_names;
std::vector<std::string> unaligned_impl_names;
std::string implementation_name;
bool is_aligned_implementation;
size_t vector_length;
};


Expand Down

0 comments on commit 0858869

Please sign in to comment.