strip_debug_info_test.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2016 Google Inc.
  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 <vector>
  15. #include "test/opt/pass_fixture.h"
  16. #include "test/opt/pass_utils.h"
  17. namespace spvtools {
  18. namespace opt {
  19. namespace {
  20. using StripLineDebugInfoTest = PassTest<::testing::Test>;
  21. TEST_F(StripLineDebugInfoTest, LineNoLine) {
  22. std::vector<const char*> text = {
  23. // clang-format off
  24. "OpCapability Shader",
  25. "%1 = OpExtInstImport \"GLSL.std.450\"",
  26. "OpMemoryModel Logical GLSL450",
  27. "OpEntryPoint Vertex %2 \"main\"",
  28. "%3 = OpString \"minimal.vert\"",
  29. "OpModuleProcessed \"42\"",
  30. "OpModuleProcessed \"43\"",
  31. "OpModuleProcessed \"44\"",
  32. "OpNoLine",
  33. "OpLine %3 10 10",
  34. "%void = OpTypeVoid",
  35. "OpLine %3 100 100",
  36. "%5 = OpTypeFunction %void",
  37. "%2 = OpFunction %void None %5",
  38. "OpLine %3 1 1",
  39. "OpNoLine",
  40. "OpLine %3 2 2",
  41. "OpLine %3 3 3",
  42. "%6 = OpLabel",
  43. "OpLine %3 4 4",
  44. "OpNoLine",
  45. "OpReturn",
  46. "OpLine %3 4 4",
  47. "OpNoLine",
  48. "OpFunctionEnd",
  49. // clang-format on
  50. };
  51. SinglePassRunAndCheck<StripDebugInfoPass>(JoinAllInsts(text),
  52. JoinNonDebugInsts(text),
  53. /* skip_nop = */ false);
  54. // Let's add more debug instruction before the "OpString" instruction.
  55. const std::vector<const char*> more_text = {
  56. "OpSourceContinued \"I'm a happy shader! Yay! ;)\"",
  57. "OpSourceContinued \"wahahaha\"",
  58. "OpSource ESSL 310",
  59. "OpSource ESSL 310",
  60. "OpSourceContinued \"wahahaha\"",
  61. "OpSourceContinued \"wahahaha\"",
  62. "OpSourceExtension \"save-the-world-extension\"",
  63. "OpName %2 \"main\"",
  64. };
  65. text.insert(text.begin() + 4, more_text.cbegin(), more_text.cend());
  66. SinglePassRunAndCheck<StripDebugInfoPass>(JoinAllInsts(text),
  67. JoinNonDebugInsts(text),
  68. /* skip_nop = */ false);
  69. }
  70. using StripDebugInfoTest = PassTest<::testing::TestWithParam<const char*>>;
  71. TEST_P(StripDebugInfoTest, Kind) {
  72. std::vector<const char*> text = {
  73. "OpCapability Shader",
  74. "OpMemoryModel Logical GLSL450",
  75. GetParam(),
  76. };
  77. SinglePassRunAndCheck<StripDebugInfoPass>(JoinAllInsts(text),
  78. JoinNonDebugInsts(text),
  79. /* skip_nop = */ false);
  80. }
  81. // Test each possible non-line debug instruction.
  82. // clang-format off
  83. INSTANTIATE_TEST_SUITE_P(
  84. SingleKindDebugInst, StripDebugInfoTest,
  85. ::testing::ValuesIn(std::vector<const char*>({
  86. "OpSourceContinued \"I'm a happy shader! Yay! ;)\"",
  87. "OpSource ESSL 310",
  88. "OpSourceExtension \"save-the-world-extension\"",
  89. "OpName %main \"main\"",
  90. "OpMemberName %struct 0 \"field\"",
  91. "%1 = OpString \"name.vert\"",
  92. "OpModuleProcessed \"42\"",
  93. })));
  94. // clang-format on
  95. } // namespace
  96. } // namespace opt
  97. } // namespace spvtools