From 6bf68c81c8084564a05d0812ce33312685bb1810 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 2 Oct 2024 11:18:41 +0200 Subject: [PATCH 1/3] skip the test log2_approx.complete when using ctest To skip the test, we use the gtest command line parameter "--gtest_filter" to filter out the unwanted test. This parameter is described as follows: --gtest_filter=POSITIVE_PATTERNS[-NEGATIVE_PATTERNS] Run only the tests whose name matches one of the positive patterns but none of the negative patterns. '?' matches any single character; '*' matches any substring; ':' separates two patterns. --- openair1/PHY/TOOLS/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/TOOLS/tests/CMakeLists.txt b/openair1/PHY/TOOLS/tests/CMakeLists.txt index 591dfcd430..2b846a8cd3 100644 --- a/openair1/PHY/TOOLS/tests/CMakeLists.txt +++ b/openair1/PHY/TOOLS/tests/CMakeLists.txt @@ -14,4 +14,4 @@ add_executable(test_log2_approx test_log2_approx.cpp ../log2_approx.c) target_link_libraries(test_log2_approx PRIVATE GTest::gtest LOG minimal_lib) add_dependencies(tests test_log2_approx) add_test(NAME test_log2_approx - COMMAND ./test_log2_approx) + COMMAND ./test_log2_approx --gtest_filter=-log2_approx.complete) From d6f9bcd1ccccf168ff7ff49325b1070b4183b3c7 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 2 Oct 2024 11:21:09 +0200 Subject: [PATCH 2/3] fix test log2_approx64.boundaries The test was actually never executed correctly (unsigned -10 is never <= 10), and log2_approx64_ref() was not accurate enough. Therefore replace it by directly comparing one value above and one value below each rounding boundary. --- openair1/PHY/TOOLS/tests/test_log2_approx.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp index c05540b61c..2a8536a3c1 100644 --- a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp +++ b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp @@ -10,11 +10,6 @@ uint8_t log2_approx_ref(uint32_t x) return std::round(std::log2(x)); } -uint8_t log2_approx64_ref(unsigned long long int x) -{ - return std::round(std::log2(static_cast(x))); -} - TEST(log2_approx, complete) { for (uint32_t i = 0; i < UINT32_MAX; i++) @@ -23,12 +18,10 @@ TEST(log2_approx, complete) TEST(log2_approx64, boundaries) { - for (long double i = 0; i < 64; i++) { - unsigned long long i2 = std::pow(2.0L, i + 0.5L); - for (unsigned long long j = -10; j <= 10; j++) { - unsigned long long x = i2 + j; - EXPECT_EQ(log2_approx64(x), log2_approx64_ref(x)); - } + for (int i = 0; i < 64; i++) { + unsigned long long int i2 = std::pow(2.0L, i + 0.5L); + EXPECT_EQ(log2_approx64(i2), i) << "log2(" << i2 << ")"; + EXPECT_EQ(log2_approx64(i2 + 1), i + 1) << "log2(" << i2 + 1 << ")"; } } From 28656a1adff749c05cee4ef809752cf359fd1b7d Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 2 Oct 2024 11:25:52 +0200 Subject: [PATCH 3/3] add test log2_approx.boundaries --- openair1/PHY/TOOLS/tests/test_log2_approx.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp index 2a8536a3c1..6728041c52 100644 --- a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp +++ b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp @@ -16,6 +16,15 @@ TEST(log2_approx, complete) EXPECT_EQ(log2_approx(i), log2_approx_ref(i)); } +TEST(log2_approx, boundaries) +{ + for (int i = 0; i < 32; i++) { + uint32_t i2 = std::pow(2.0, i + 0.5); + EXPECT_EQ(log2_approx(i2), i) << "log2(" << i2 << ")"; + EXPECT_EQ(log2_approx(i2 + 1), i + 1) << "log2(" << i2 + 1 << ")"; + } +} + TEST(log2_approx64, boundaries) { for (int i = 0; i < 64; i++) {