Path: blob/main/glslc/test/option_dash_cap_O.py
1560 views
# Copyright 2016 The Shaderc Authors. All rights reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.1314import expect15from environment import File, Directory16from glslc_test_framework import inside_glslc_testsuite17from placeholder import FileShader1819MINIMAL_SHADER = '#version 310 es\nvoid main() {}'20EMPTY_SHADER_IN_CWD = Directory('.', [File('shader.vert', MINIMAL_SHADER)])2122ASSEMBLY_WITH_DEBUG_SOURCE = [23'; SPIR-V\n',24'; Version: 1.0\n',25'; Generator: Google Shaderc over Glslang; 11\n',26'; Bound: 7\n',27'; Schema: 0\n',28' OpCapability Shader\n',29' %2 = OpExtInstImport "GLSL.std.450"\n',30' OpMemoryModel Logical GLSL450\n',31' OpEntryPoint Vertex %main "main"\n',32' %1 = OpString "shader.vert"\n',33' OpSource ESSL 310 %1 "// OpModuleProcessed entry-point main\n',34'// OpModuleProcessed client vulkan100\n',35'// OpModuleProcessed target-env vulkan1.0\n',36'// OpModuleProcessed entry-point main\n',37'#line 1\n',38'#version 310 es\n',39'void main() {}"\n',40' OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"\n',41' OpSourceExtension "GL_GOOGLE_include_directive"\n',42' OpName %main "main"\n',43' %void = OpTypeVoid\n',44' %4 = OpTypeFunction %void\n',45' OpLine %1 2 11\n',46' %main = OpFunction %void None %4\n',47' %6 = OpLabel\n',48' OpReturn\n',49' OpFunctionEnd\n']5051ASSEMBLY_WITH_DEBUG = [52'; SPIR-V\n',53'; Version: 1.0\n',54'; Generator: Google Shaderc over Glslang; 11\n',55'; Bound: 6\n',56'; Schema: 0\n',57' OpCapability Shader\n',58' %1 = OpExtInstImport "GLSL.std.450"\n',59' OpMemoryModel Logical GLSL450\n',60' OpEntryPoint Vertex %main "main"\n',61' OpSource ESSL 310\n',62' OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"\n',63' OpSourceExtension "GL_GOOGLE_include_directive"\n',64' OpName %main "main"\n',65' %void = OpTypeVoid\n',66' %3 = OpTypeFunction %void\n',67' %main = OpFunction %void None %3\n',68' %5 = OpLabel\n',69' OpReturn\n',70' OpFunctionEnd\n']7172ASSEMBLY_WITHOUT_DEBUG = [73'; SPIR-V\n',74'; Version: 1.0\n',75'; Generator: Google Shaderc over Glslang; 11\n',76'; Bound: 6\n',77'; Schema: 0\n',78' OpCapability Shader\n',79' %1 = OpExtInstImport "GLSL.std.450"\n',80' OpMemoryModel Logical GLSL450\n',81' OpEntryPoint Vertex %4 "main"\n',82' %void = OpTypeVoid\n',83' %3 = OpTypeFunction %void\n',84' %4 = OpFunction %void None %3\n', # %4 vs. %main85' %5 = OpLabel\n',86' OpReturn\n',87' OpFunctionEnd\n']888990@inside_glslc_testsuite('OptionDashCapO')91class TestDashCapO0(expect.ValidFileContents):92"""Tests that -O0 works."""9394environment = EMPTY_SHADER_IN_CWD95glslc_args = ['-S', '-O0', 'shader.vert']96target_filename = 'shader.vert.spvasm'97expected_file_contents = ASSEMBLY_WITH_DEBUG9899@inside_glslc_testsuite('OptionDashCapO')100class TestDashCapOPerformance(expect.ValidFileContents):101"""Tests -O works."""102103environment = EMPTY_SHADER_IN_CWD104glslc_args = ['-S', '-O', 'shader.vert']105target_filename = 'shader.vert.spvasm'106expected_file_contents = ASSEMBLY_WITHOUT_DEBUG107108@inside_glslc_testsuite('OptionDashCapO')109class TestDashCapOs(expect.ValidFileContents):110"""Tests that -Os works."""111112environment = EMPTY_SHADER_IN_CWD113glslc_args = ['-S', '-Os', 'shader.vert']114target_filename = 'shader.vert.spvasm'115expected_file_contents = ASSEMBLY_WITHOUT_DEBUG116117118@inside_glslc_testsuite('OptionDashCapO')119class TestDashCapOOverriding(expect.ValidFileContents):120"""Tests that if there are multiple -O's, only the last one takes effect."""121122environment = EMPTY_SHADER_IN_CWD123glslc_args = ['-S', '-Os', '-O0', '-Os', '-O0', 'shader.vert']124target_filename = 'shader.vert.spvasm'125expected_file_contents = ASSEMBLY_WITH_DEBUG126127128@inside_glslc_testsuite('OptionDashCapO')129class TestDashCapOWithDashG(expect.ValidFileContents):130"""Tests that -g restrains -O from turning on strip debug info."""131132environment = EMPTY_SHADER_IN_CWD133glslc_args = ['-S', '-Os', '-g', 'shader.vert']134target_filename = 'shader.vert.spvasm'135expected_file_contents = ASSEMBLY_WITH_DEBUG_SOURCE136137138@inside_glslc_testsuite('OptionDashCapO')139class TestDashGWithDashCapO(expect.ValidFileContents):140"""Tests that -g restrains -O from turning on strip debug info."""141142environment = EMPTY_SHADER_IN_CWD143glslc_args = ['-S', '-g', '-Os', 'shader.vert']144target_filename = 'shader.vert.spvasm'145expected_file_contents = ASSEMBLY_WITH_DEBUG_SOURCE146147148@inside_glslc_testsuite('OptionDashCapO')149class TestWrongOptLevel(expect.NoGeneratedFiles, expect.ErrorMessage):150"""Tests erroring out with wrong optimization level."""151152shader = FileShader(MINIMAL_SHADER, '.vert')153glslc_args = ['-c', '-O2', shader]154expected_error = "glslc: error: invalid value '2' in '-O2'\n"155156157