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