diff options
Diffstat (limited to 'llvm/unittests/Frontend')
-rw-r--r-- | llvm/unittests/Frontend/CMakeLists.txt | 3 | ||||
-rw-r--r-- | llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp | 177 | ||||
-rw-r--r-- | llvm/unittests/Frontend/PropertySetRegistryTest.cpp | 76 |
3 files changed, 78 insertions, 178 deletions
diff --git a/llvm/unittests/Frontend/CMakeLists.txt b/llvm/unittests/Frontend/CMakeLists.txt index 6e4ba5d..836a844 100644 --- a/llvm/unittests/Frontend/CMakeLists.txt +++ b/llvm/unittests/Frontend/CMakeLists.txt @@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS Analysis Core FrontendHLSL + FrontendOffloading FrontendOpenACC FrontendOpenMP Passes @@ -13,7 +14,6 @@ set(LLVM_LINK_COMPONENTS add_llvm_unittest(LLVMFrontendTests HLSLBindingTest.cpp HLSLRootSignatureDumpTest.cpp - HLSLRootSignatureRangesTest.cpp OpenACCTest.cpp OpenMPContextTest.cpp OpenMPIRBuilderTest.cpp @@ -22,6 +22,7 @@ add_llvm_unittest(LLVMFrontendTests OpenMPDecompositionTest.cpp OpenMPDirectiveNameTest.cpp OpenMPDirectiveNameParserTest.cpp + PropertySetRegistryTest.cpp DEPENDS acc_gen diff --git a/llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp b/llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp deleted file mode 100644 index be3f51e..0000000 --- a/llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp +++ /dev/null @@ -1,177 +0,0 @@ -//===------ HLSLRootSignatureRangeTest.cpp - RootSignature Range tests ----===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/Frontend/HLSL/RootSignatureValidations.h" -#include "gtest/gtest.h" - -using namespace llvm::hlsl::rootsig; - -namespace { - -TEST(HLSLRootSignatureTest, NoOverlappingInsertTests) { - // Ensures that there is never a reported overlap - ResourceRange::MapT::Allocator Allocator; - ResourceRange Range(Allocator); - - RangeInfo A; - A.LowerBound = 0; - A.UpperBound = 3; - EXPECT_EQ(Range.insert(A), std::nullopt); - - RangeInfo B; - B.LowerBound = 4; - B.UpperBound = 7; - EXPECT_EQ(Range.insert(B), std::nullopt); - - RangeInfo C; - C.LowerBound = 10; - C.UpperBound = RangeInfo::Unbounded; - EXPECT_EQ(Range.insert(C), std::nullopt); - - // A = [0;3] - EXPECT_EQ(Range.lookup(0), &A); - EXPECT_EQ(Range.lookup(2), &A); - EXPECT_EQ(Range.lookup(3), &A); - - // B = [4;7] - EXPECT_EQ(Range.lookup(4), &B); - EXPECT_EQ(Range.lookup(5), &B); - EXPECT_EQ(Range.lookup(7), &B); - - EXPECT_EQ(Range.lookup(8), nullptr); - EXPECT_EQ(Range.lookup(9), nullptr); - - // C = [10;unbounded] - EXPECT_EQ(Range.lookup(10), &C); - EXPECT_EQ(Range.lookup(42), &C); - EXPECT_EQ(Range.lookup(98237423), &C); - EXPECT_EQ(Range.lookup(RangeInfo::Unbounded), &C); -} - -TEST(HLSLRootSignatureTest, SingleOverlappingInsertTests) { - // Ensures that we correctly report an overlap when we insert a range that - // overlaps with one other range but does not cover (replace) it - ResourceRange::MapT::Allocator Allocator; - ResourceRange Range(Allocator); - - RangeInfo A; - A.LowerBound = 1; - A.UpperBound = 5; - EXPECT_EQ(Range.insert(A), std::nullopt); - - RangeInfo B; - B.LowerBound = 0; - B.UpperBound = 2; - EXPECT_EQ(Range.insert(B).value(), &A); - - RangeInfo C; - C.LowerBound = 4; - C.UpperBound = RangeInfo::Unbounded; - EXPECT_EQ(Range.insert(C).value(), &A); - - // A = [1;5] - EXPECT_EQ(Range.lookup(1), &A); - EXPECT_EQ(Range.lookup(2), &A); - EXPECT_EQ(Range.lookup(3), &A); - EXPECT_EQ(Range.lookup(4), &A); - EXPECT_EQ(Range.lookup(5), &A); - - // B = [0;0] - EXPECT_EQ(Range.lookup(0), &B); - - // C = [6; unbounded] - EXPECT_EQ(Range.lookup(6), &C); - EXPECT_EQ(Range.lookup(RangeInfo::Unbounded), &C); -} - -TEST(HLSLRootSignatureTest, MultipleOverlappingInsertTests) { - // Ensures that we correctly report an overlap when inserted range - // overlaps more than one range and it does not cover (replace) either - // range. In this case it will just fill in the interval between the two - ResourceRange::MapT::Allocator Allocator; - ResourceRange Range(Allocator); - - RangeInfo A; - A.LowerBound = 0; - A.UpperBound = 2; - EXPECT_EQ(Range.insert(A), std::nullopt); - - RangeInfo B; - B.LowerBound = 4; - B.UpperBound = 6; - EXPECT_EQ(Range.insert(B), std::nullopt); - - RangeInfo C; - C.LowerBound = 1; - C.UpperBound = 5; - EXPECT_EQ(Range.insert(C).value(), &A); - - // A = [0;2] - EXPECT_EQ(Range.lookup(0), &A); - EXPECT_EQ(Range.lookup(1), &A); - EXPECT_EQ(Range.lookup(2), &A); - - // B = [4;6] - EXPECT_EQ(Range.lookup(4), &B); - EXPECT_EQ(Range.lookup(5), &B); - EXPECT_EQ(Range.lookup(6), &B); - - // C = [3;3] - EXPECT_EQ(Range.lookup(3), &C); -} - -TEST(HLSLRootSignatureTest, CoverInsertTests) { - // Ensures that we correctly report an overlap when inserted range - // covers one or more ranges - ResourceRange::MapT::Allocator Allocator; - ResourceRange Range(Allocator); - - RangeInfo A; - A.LowerBound = 0; - A.UpperBound = 2; - EXPECT_EQ(Range.insert(A), std::nullopt); - - RangeInfo B; - B.LowerBound = 4; - B.UpperBound = 5; - EXPECT_EQ(Range.insert(B), std::nullopt); - - // Covers B - RangeInfo C; - C.LowerBound = 4; - C.UpperBound = 6; - EXPECT_EQ(Range.insert(C).value(), &B); - - // A = [0;2] - // C = [4;6] <- covers reference to B - EXPECT_EQ(Range.lookup(0), &A); - EXPECT_EQ(Range.lookup(1), &A); - EXPECT_EQ(Range.lookup(2), &A); - EXPECT_EQ(Range.lookup(3), nullptr); - EXPECT_EQ(Range.lookup(4), &C); - EXPECT_EQ(Range.lookup(5), &C); - EXPECT_EQ(Range.lookup(6), &C); - - // Covers all other ranges - RangeInfo D; - D.LowerBound = 0; - D.UpperBound = 7; - EXPECT_EQ(Range.insert(D).value(), &A); - - // D = [0;7] <- Covers reference to A and C - EXPECT_EQ(Range.lookup(0), &D); - EXPECT_EQ(Range.lookup(1), &D); - EXPECT_EQ(Range.lookup(2), &D); - EXPECT_EQ(Range.lookup(3), &D); - EXPECT_EQ(Range.lookup(4), &D); - EXPECT_EQ(Range.lookup(5), &D); - EXPECT_EQ(Range.lookup(6), &D); - EXPECT_EQ(Range.lookup(7), &D); -} - -} // namespace diff --git a/llvm/unittests/Frontend/PropertySetRegistryTest.cpp b/llvm/unittests/Frontend/PropertySetRegistryTest.cpp new file mode 100644 index 0000000..4c1cdb31 --- /dev/null +++ b/llvm/unittests/Frontend/PropertySetRegistryTest.cpp @@ -0,0 +1,76 @@ +//===- llvm/unittest/Frontend/PropertySetRegistry.cpp ---------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Frontend/Offloading/PropertySet.h" +#include "llvm/Support/MemoryBuffer.h" +#include "gtest/gtest.h" + +using namespace llvm::offloading; +using namespace llvm; + +void checkSerialization(const PropertySetRegistry &PSR) { + SmallString<0> Serialized; + raw_svector_ostream OS(Serialized); + writePropertiesToJSON(PSR, OS); + auto PSR2 = readPropertiesFromJSON({Serialized, ""}); + ASSERT_EQ("", toString(PSR2.takeError())); + EXPECT_EQ(PSR, *PSR2); +} + +TEST(PropertySetRegistryTest, PropertySetRegistry) { + PropertySetRegistry PSR; + checkSerialization(PSR); + + PSR["Category1"]["Prop1"] = 42U; + PSR["Category1"]["Prop2"] = ByteArray(StringRef("Hello").bytes()); + PSR["Category2"]["A"] = ByteArray{0, 4, 16, 32, 255}; + checkSerialization(PSR); + + PSR = PropertySetRegistry(); + PSR["ABC"]["empty_array"] = ByteArray(); + PSR["ABC"]["max_val"] = std::numeric_limits<uint32_t>::max(); + checkSerialization(PSR); +} + +TEST(PropertySetRegistryTest, IllFormedJSON) { + SmallString<0> Input; + + // Invalid json + Input = "{ invalid }"; + auto Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + Input = ""; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + // Not a JSON object + Input = "[1, 2, 3]"; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + // Property set not an object + Input = R"({ "Category": 42 })"; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + // Property value has non string/non-integer type + Input = R"({ "Category": { "Prop": [1, 2, 3] } })"; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + // Property value is an invalid base64 string + Input = R"({ "Category": { "Prop": ";" } })"; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); + + Input = R"({ "Category": { "Prop": "!@#$" } })"; + Res = readPropertiesFromJSON({Input, ""}); + EXPECT_NE("", toString(Res.takeError())); +} |