ids_limit_test.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2017 Pierre Moreau
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <string>
  15. #include "gmock/gmock.h"
  16. #include "test/link/linker_fixture.h"
  17. namespace spvtools {
  18. namespace {
  19. using ::testing::HasSubstr;
  20. using IdsLimit = spvtest::LinkerTest;
  21. TEST_F(IdsLimit, UnderLimit) {
  22. spvtest::Binaries binaries = {
  23. {
  24. SpvMagicNumber, SpvVersion, SPV_GENERATOR_CODEPLAY,
  25. 0x2FFFFFu, // NOTE: Bound
  26. 0u, // NOTE: Schema; reserved
  27. },
  28. {
  29. SpvMagicNumber, SpvVersion, SPV_GENERATOR_CODEPLAY,
  30. 0x100000u, // NOTE: Bound
  31. 0u, // NOTE: Schema; reserved
  32. }};
  33. spvtest::Binary linked_binary;
  34. ASSERT_EQ(SPV_SUCCESS, Link(binaries, &linked_binary));
  35. EXPECT_THAT(GetErrorMessage(), std::string());
  36. EXPECT_EQ(0x3FFFFEu, linked_binary[3]);
  37. }
  38. TEST_F(IdsLimit, OverLimit) {
  39. spvtest::Binaries binaries = {
  40. {
  41. SpvMagicNumber, SpvVersion, SPV_GENERATOR_CODEPLAY,
  42. 0x2FFFFFu, // NOTE: Bound
  43. 0u, // NOTE: Schema; reserved
  44. },
  45. {
  46. SpvMagicNumber, SpvVersion, SPV_GENERATOR_CODEPLAY,
  47. 0x100000u, // NOTE: Bound
  48. 0u, // NOTE: Schema; reserved
  49. },
  50. {
  51. SpvMagicNumber, SpvVersion, SPV_GENERATOR_CODEPLAY,
  52. 3u, // NOTE: Bound
  53. 0u, // NOTE: Schema; reserved
  54. }};
  55. spvtest::Binary linked_binary;
  56. EXPECT_EQ(SPV_ERROR_INVALID_ID, Link(binaries, &linked_binary));
  57. EXPECT_THAT(GetErrorMessage(),
  58. HasSubstr("The limit of IDs, 4194303, was exceeded: 4194304 is "
  59. "the current ID bound."));
  60. }
  61. } // namespace
  62. } // namespace spvtools