From 470405e0ed2015d419951384f722a43b322ce989 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 14 Oct 2015 14:40:24 -0400 Subject: [PATCH] Add disabled tests for disassembler literal emission Currently, negative numbers are printed as if they were first statically cast to unsigned. --- test/TextToBinary.Constant.cpp | 100 ++++++++++++++++++++++++++++++++++++++ test/TextToBinary.ControlFlow.cpp | 52 +++++++++++++++++++- 2 files changed, 150 insertions(+), 2 deletions(-) diff --git a/test/TextToBinary.Constant.cpp b/test/TextToBinary.Constant.cpp index 9c12f2f..9d90625 100644 --- a/test/TextToBinary.Constant.cpp +++ b/test/TextToBinary.Constant.cpp @@ -29,6 +29,8 @@ #include "UnitSPIRV.h" +#include + #include "gmock/gmock.h" #include "TestFixture.h" @@ -328,6 +330,104 @@ INSTANTIATE_TEST_CASE_P( })); // clang-format on +using RoundTripTest = + spvtest::TextToBinaryTestBase<::testing::TestWithParam>; + +const int64_t kMaxUnsigned48Bit = (int64_t(1) << 48) - 1; +const int64_t kMaxSigned48Bit = (int64_t(1) << 47) - 1; +const int64_t kMinSigned48Bit = -kMaxSigned48Bit - 1; + +TEST_P(RoundTripTest, Sample) { + EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), + Eq(GetParam())); +} + +// TODO(dneto): Enable support once this works. +INSTANTIATE_TEST_CASE_P(DISABLED_OpConstantRoundTrip, RoundTripTest, + ::testing::ValuesIn(std::vector{ + // 16 bit + "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 0\n", + "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 65535\n", + "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 -32768\n", + "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 32767\n", + "%1 = OpTypeInt 32 0\n%2 = OpConstant %1 0\n", + // 32 bit + std::string("%1 = OpTypeInt 32 0\n%2 = OpConstant %1 0\n"), + std::string("%1 = OpTypeInt 32 0\n%2 = OpConstant %1 ") + + std::to_string(UINT32_MAX) + "\n", + std::string("%1 = OpTypeInt 32 1\n%2 = OpConstant %1 ") + + std::to_string(INT32_MAX) + "\n", + std::string("%1 = OpTypeInt 32 1\n%2 = OpConstant %1 ") + + std::to_string(INT32_MIN) + "\n", + // 48 bit + std::string("%1 = OpTypeInt 48 0\n%2 = OpConstant %1 0\n"), + std::string("%1 = OpTypeInt 48 0\n%2 = OpConstant %1 ") + + std::to_string(kMaxUnsigned48Bit) + "\n", + std::string("%1 = OpTypeInt 48 1\n%2 = OpConstant %1 ") + + std::to_string(kMaxSigned48Bit) + "\n", + std::string("%1 = OpTypeInt 48 1\n%2 = OpConstant %1 ") + + std::to_string(kMinSigned48Bit) + "\n", + // 64 bit + std::string("%1 = OpTypeInt 64 0\n%2 = OpConstant %1 0\n"), + std::string("%1 = OpTypeInt 64 0\n%2 = OpConstant %1 ") + + std::to_string(UINT64_MAX) + "\n", + std::string("%1 = OpTypeInt 64 1\n%2 = OpConstant %1 ") + + std::to_string(INT64_MAX) + "\n", + std::string("%1 = OpTypeInt 64 1\n%2 = OpConstant %1 ") + + std::to_string(INT64_MIN) + "\n", + // 32-bit float + "%1 = OpTypeFloat 32\n%2 = OpConstant %1 0\n", + "%1 = OpTypeFloat 32\n%2 = OpConstant %1 13.5\n", + "%1 = OpTypeFloat 32\n%2 = OpConstant %1 -12.5\n", + // 64-bit float + "%1 = OpTypeFloat 64\n%2 = OpConstant %1 0\n", + "%1 = OpTypeFloat 64\n%2 = OpConstant %1 1.79769e+308\n", + "%1 = OpTypeFloat 64\n%2 = OpConstant %1 -1.79769e+308\n", + })); + +// TODO(dneto): Enable support once this works. +INSTANTIATE_TEST_CASE_P(DISABLED_OpSpecConstantRoundTrip, RoundTripTest, + ::testing::ValuesIn(std::vector{ + // 16 bit + "%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 0\n", + "%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 65535\n", + "%1 = OpTypeInt 16 1\n%2 = OpSpecConstant %1 -32768\n", + "%1 = OpTypeInt 16 1\n%2 = OpSpecConstant %1 32767\n", + "%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 0\n", + // 32 bit + std::string("%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 0\n"), + std::string("%1 = OpTypeInt 32 0\n%2 = OpSpecConstant %1 ") + + std::to_string(UINT32_MAX) + "\n", + std::string("%1 = OpTypeInt 32 1\n%2 = OpSpecConstant %1 ") + + std::to_string(INT32_MAX) + "\n", + std::string("%1 = OpTypeInt 32 1\n%2 = OpSpecConstant %1 ") + + std::to_string(INT32_MIN) + "\n", + // 48 bit + std::string("%1 = OpTypeInt 48 0\n%2 = OpSpecConstant %1 0\n"), + std::string("%1 = OpTypeInt 48 0\n%2 = OpSpecConstant %1 ") + + std::to_string(kMaxUnsigned48Bit) + "\n", + std::string("%1 = OpTypeInt 48 1\n%2 = OpSpecConstant %1 ") + + std::to_string(kMaxSigned48Bit) + "\n", + std::string("%1 = OpTypeInt 48 1\n%2 = OpSpecConstant %1 ") + + std::to_string(kMinSigned48Bit) + "\n", + // 64 bit + std::string("%1 = OpTypeInt 64 0\n%2 = OpSpecConstant %1 0\n"), + std::string("%1 = OpTypeInt 64 0\n%2 = OpSpecConstant %1 ") + + std::to_string(UINT64_MAX) + "\n", + std::string("%1 = OpTypeInt 64 1\n%2 = OpSpecConstant %1 ") + + std::to_string(INT64_MAX) + "\n", + std::string("%1 = OpTypeInt 64 1\n%2 = OpSpecConstant %1 ") + + std::to_string(INT64_MIN) + "\n", + // 32-bit float + "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 0\n", + "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 13.5\n", + "%1 = OpTypeFloat 32\n%2 = OpSpecConstant %1 -12.5\n", + // 64-bit float + "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 0\n", + "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 1.79769e+308\n", + "%1 = OpTypeFloat 64\n%2 = OpSpecConstant %1 -1.79769e+308\n", + })); + // TODO(dneto): OpConstantTrue // TODO(dneto): OpConstantFalse // TODO(dneto): OpConstantComposite diff --git a/test/TextToBinary.ControlFlow.cpp b/test/TextToBinary.ControlFlow.cpp index d620bfd..62bec7e 100644 --- a/test/TextToBinary.ControlFlow.cpp +++ b/test/TextToBinary.ControlFlow.cpp @@ -284,6 +284,56 @@ INSTANTIATE_TEST_CASE_P( MakeSwitchTestCase(64, 1, "0x700000123", { 0x123, 7 }, "12", {12, 0}), }))); +using RoundTripTest = + spvtest::TextToBinaryTestBase<::testing::TestWithParam>; + +TEST_P(RoundTripTest, Sample) { + EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), + Eq(GetParam())); +} + +// TODO(dneto): Enable this test. +INSTANTIATE_TEST_CASE_P( + DISABLED_OpSwitchRoundTripUnsignedIntegers, RoundTripTest, + ::testing::ValuesIn(std::vector({ + // Unsigned 16-bit. + "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 65535\nOpSwitch %2 %3\n", + // Unsigned 32-bit, three non-default cases. + "%1 = OpTypeInt 32 0\n%2 = OpConstant %1 123456\n" + "OpSwitch %2 %3 100 %4 102 %5 1000000 %6\n", + // Unsigned 48-bit, three non-default cases. + "%1 = OpTypeInt 48 0\n%2 = OpConstant %1 5000000000\n" + "OpSwitch %2 %3 100 %4 102 %5 6000000000 %6\n", + // Unsigned 64-bit, three non-default cases. + "%1 = OpTypeInt 64 0\n%2 = OpConstant %1 9223372036854775807\n" + "OpSwitch %2 %3 100 %4 102 %5 9000000000000000000 %6\n", + }))); + +INSTANTIATE_TEST_CASE_P( + DISABLED_OpSwitchRoundTripSignedIntegers, RoundTripTest, + ::testing::ValuesIn(std::vector{ + // Signed 16-bit, with two non-default cases + "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 32767\n" + "OpSwitch %2 %3 99 %4 -102 %5\n", + "%1 = OpTypeInt 16 1\n%2 = OpConstant %1 -32768\n" + "OpSwitch %2 %3 99 %4 -102 %5\n", + // Signed 32-bit, two non-default cases. + "%1 = OpTypeInt 32 1\n%2 = OpConstant %1 -123456\n" + "OpSwitch %2 %3 100 %4 -102\n", + "%1 = OpTypeInt 32 1\n%2 = OpConstant %1 123456\n" + "OpSwitch %2 %3 100 %4 -102\n", + // Signed 48-bit, three non-default cases. + "%1 = OpTypeInt 48 1\n%2 = OpConstant %1 5000000000\n" + "OpSwitch %2 %3 100 %4 -7000000000 %5 6000000000 %6\n", + "%1 = OpTypeInt 48 1\n%2 = OpConstant %1 -5000000000\n" + "OpSwitch %2 %3 100 %4 -7000000000 %5 6000000000 %6\n", + // Signed 64-bit, three non-default cases. + "%1 = OpTypeInt 64 1\n%2 = OpConstant %1 9223372036854775807\n" + "OpSwitch %2 %3 100 %4 7000000000 %5 -1000000000000000000 %6\n", + "%1 = OpTypeInt 64 1\n%2 = OpConstant %1 -9223372036854775808\n" + "OpSwitch %2 %3 100 %4 7000000000 %5 -1000000000000000000 %6\n", + })); + using OpSwitchInvalidTypeTestCase = spvtest::TextToBinaryTestBase<::testing::TestWithParam>; @@ -328,8 +378,6 @@ INSTANTIATE_TEST_CASE_P( })); // clang-format on -// TODO(awoloszyn): Add tests for switch with different operand widths -// once non-32-bit support is in. // TODO(dneto): OpPhi // TODO(dneto): OpLoopMerge // TODO(dneto): OpLabel -- 2.7.4