Skip to content

Commit

Permalink
Wrap tests in anon namespace to enable integration in Chromium
Browse files Browse the repository at this point in the history
Also add HWY_TEST_MAIN for msvc and "// HWY_ONCE",
Fix missing includes,
fix unused-function in targets_test,
workaround SVE2 bug via non-const Iota + require recent Clang.
workaround MSVC timeout by splitting two tests

PiperOrigin-RevId: 686156435
  • Loading branch information
jan-wassenberg authored and copybara-github committed Oct 15, 2024
1 parent 75cb75a commit a97b5d3
Show file tree
Hide file tree
Showing 75 changed files with 745 additions and 455 deletions.
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,14 @@ HWY_TESTS = [
("hwy/", "targets_test"),
("hwy/tests/", "arithmetic_test"),
("hwy/tests/", "bit_permute_test"),
("hwy/tests/", "blockwise_combine_test"),
("hwy/tests/", "blockwise_shift_test"),
("hwy/tests/", "blockwise_test"),
("hwy/tests/", "cast_test"),
("hwy/tests/", "combine_test"),
("hwy/tests/", "compare_test"),
("hwy/tests/", "compress_test"),
("hwy/tests/", "concat_test"),
("hwy/tests/", "convert_test"),
("hwy/tests/", "count_test"),
("hwy/tests/", "crypto_test"),
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,14 @@ set(HWY_TEST_FILES
hwy/examples/skeleton_test.cc
hwy/tests/arithmetic_test.cc
hwy/tests/bit_permute_test.cc
hwy/tests/blockwise_combine_test.cc
hwy/tests/blockwise_shift_test.cc
hwy/tests/blockwise_test.cc
hwy/tests/cast_test.cc
hwy/tests/combine_test.cc
hwy/tests/compare_test.cc
hwy/tests/compress_test.cc
hwy/tests/concat_test.cc
hwy/tests/convert_test.cc
hwy/tests/count_test.cc
hwy/tests/crypto_test.cc
Expand Down
4 changes: 2 additions & 2 deletions hwy/abort_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#include "hwy/tests/test_util-inl.h" // HWY_ASSERT_EQ

namespace hwy {
namespace {

#ifdef GTEST_HAS_DEATH_TEST
namespace {
std::string GetBaseName(std::string const& file_name) {
auto last_slash = file_name.find_last_of("/\\");
return file_name.substr(last_slash + 1);
}
} // namespace

TEST(AbortDeathTest, AbortDefault) {
std::string expected = std::string("Abort at ") + GetBaseName(__FILE__) +
Expand Down Expand Up @@ -68,6 +67,7 @@ TEST(AbortTest, AbortOverrideChain) {
HWY_ASSERT(GetAbortFunc() == nullptr);
}

} // namespace
} // namespace hwy

HWY_TEST_MAIN();
3 changes: 1 addition & 2 deletions hwy/aligned_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class FakeAllocator {
} // namespace

namespace hwy {
namespace {

#if !HWY_TEST_STANDALONE
class AlignedAllocatorTest : public testing::Test {};
Expand Down Expand Up @@ -283,8 +284,6 @@ TEST(AlignedAllocatorTest, TestDefaultInit) {
(addr2 >> (kBits - 1)) >> (kBits - 1));
}

namespace {

using std::array;
using std::vector;

Expand Down
9 changes: 6 additions & 3 deletions hwy/base_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

HWY_NOINLINE void TestAllLimits() {
HWY_ASSERT_EQ(uint8_t{0}, LimitsMin<uint8_t>());
Expand Down Expand Up @@ -837,14 +838,15 @@ HWY_NOINLINE void TestAllSpecialFloat() {
test(bfloat16_t());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(BaseTest);
HWY_EXPORT_AND_TEST_P(BaseTest, TestAllLimits);
HWY_EXPORT_AND_TEST_P(BaseTest, TestAllLowestHighest);
Expand All @@ -858,6 +860,7 @@ HWY_EXPORT_AND_TEST_P(BaseTest, TestAllMul128);
HWY_EXPORT_AND_TEST_P(BaseTest, TestAllEndian);
HWY_EXPORT_AND_TEST_P(BaseTest, TestAllSpecialFloat);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/algo/copy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

// Returns random integer in [0, 128), which fits in any lane type.
template <typename T>
Expand Down Expand Up @@ -189,19 +190,21 @@ void TestAllCopyIf() {
ForUI163264(ForPartialVectors<ForeachCountAndMisalign<TestCopyIf>>());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(CopyTest);
HWY_EXPORT_AND_TEST_P(CopyTest, TestAllFill);
HWY_EXPORT_AND_TEST_P(CopyTest, TestAllCopy);
HWY_EXPORT_AND_TEST_P(CopyTest, TestAllCopyIf);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/algo/find_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

// Returns random number in [-8, 8] - we use knowledge of the range to Find()
// values we know are not present.
Expand Down Expand Up @@ -210,18 +211,20 @@ void TestAllFindIf() {
ForAllTypes(ForPartialVectors<ForeachCountAndMisalign<TestFindIf>>());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(FindTest);
HWY_EXPORT_AND_TEST_P(FindTest, TestAllFind);
HWY_EXPORT_AND_TEST_P(FindTest, TestAllFindIf);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/algo/transform_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

constexpr double kAlpha = 1.5; // arbitrary scalar

Expand Down Expand Up @@ -440,14 +441,15 @@ void TestAllReplace() {
ForFloatTypes(ForPartialVectors<ForeachCountAndMisalign<TestReplace>>());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(TransformTest);
HWY_EXPORT_AND_TEST_P(TransformTest, TestAllGenerate);
HWY_EXPORT_AND_TEST_P(TransformTest, TestAllForeach);
Expand All @@ -456,6 +458,7 @@ HWY_EXPORT_AND_TEST_P(TransformTest, TestAllTransform1);
HWY_EXPORT_AND_TEST_P(TransformTest, TestAllTransform2);
HWY_EXPORT_AND_TEST_P(TransformTest, TestAllReplace);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/bit_pack/bit_pack_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ size_t last_bits = 0;
uint64_t best_target = ~0ull;
#endif
namespace HWY_NAMESPACE {
namespace {

template <size_t kBits, typename T>
T Random(RandomState& rng) {
Expand Down Expand Up @@ -222,20 +223,22 @@ void TestAllPack64() {
#endif
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(BitPackTest);
HWY_EXPORT_AND_TEST_P(BitPackTest, TestAllPack8);
HWY_EXPORT_AND_TEST_P(BitPackTest, TestAllPack16);
HWY_EXPORT_AND_TEST_P(BitPackTest, TestAllPack32);
HWY_EXPORT_AND_TEST_P(BitPackTest, TestAllPack64);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/dot/dot_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

template <typename T1, typename T2>
HWY_NOINLINE T1 SimpleDot(const T1* pa, const T2* pb, size_t num) {
Expand Down Expand Up @@ -269,19 +270,21 @@ void TestAllDotF32BF16() {
// Both bf16.
void TestAllDotBF16() { ForShrinkableVectors<TestDot>()(bfloat16_t()); }

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(DotTest);
HWY_EXPORT_AND_TEST_P(DotTest, TestAllDot);
HWY_EXPORT_AND_TEST_P(DotTest, TestAllDotF32BF16);
HWY_EXPORT_AND_TEST_P(DotTest, TestAllDotBF16);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/image/image_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

// Ensure we can always write full aligned vectors.
struct TestAlignedT {
Expand Down Expand Up @@ -133,18 +134,20 @@ struct TestUnalignedT {

void TestUnaligned() { ForUnsignedTypes(TestUnalignedT()); }

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(ImageTest);
HWY_EXPORT_AND_TEST_P(ImageTest, TestAligned);
HWY_EXPORT_AND_TEST_P(ImageTest, TestUnaligned);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
9 changes: 6 additions & 3 deletions hwy/contrib/math/math_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

// We have had test failures caused by excess precision due to keeping
// intermediate results in 80-bit x87 registers. One such failure mode is that
Expand Down Expand Up @@ -625,14 +626,15 @@ HWY_NOINLINE void TestAllHypot() {
ForFloat3264Types(ForPartialVectors<TestHypot>());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(HwyMathTest);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcos);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcosh);
Expand All @@ -656,6 +658,7 @@ HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosSin);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosCos);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllHypot);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

#endif
HWY_TEST_MAIN();
#endif // HWY_ONCE
7 changes: 5 additions & 2 deletions hwy/contrib/matvec/matvec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
HWY_BEFORE_NAMESPACE();
namespace hwy {
namespace HWY_NAMESPACE {
namespace {

template <typename MatT, typename T>
HWY_NOINLINE void SimpleMatVecAdd(const MatT* HWY_RESTRICT mat,
Expand Down Expand Up @@ -272,19 +273,21 @@ void TestAllMatVecBF16Both() {
ForGEVectors<32, TestMatVecAdd<bfloat16_t, bfloat16_t>>()(float());
}

} // namespace
// NOLINTNEXTLINE(google-readability-namespace-comments)
} // namespace HWY_NAMESPACE
} // namespace hwy
HWY_AFTER_NAMESPACE();

#if HWY_ONCE

namespace hwy {
namespace {
HWY_BEFORE_TEST(MatVecTest);
HWY_EXPORT_AND_TEST_P(MatVecTest, TestAllMatVecAdd);
HWY_EXPORT_AND_TEST_P(MatVecTest, TestAllMatVecBF16);
HWY_EXPORT_AND_TEST_P(MatVecTest, TestAllMatVecBF16Both);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy

HWY_TEST_MAIN();
#endif // HWY_ONCE
Loading

0 comments on commit a97b5d3

Please sign in to comment.