Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_mfmt.py
1560 views
1
# Copyright 2016 The Shaderc Authors. All rights reserved.
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
import expect
16
import re
17
from glslc_test_framework import inside_glslc_testsuite
18
from placeholder import FileShader
19
20
MINIMAL_SHADER = '#version 140\nvoid main() {}'
21
# Regular expression patterns for the minimal shader. The magic number should
22
# match exactly, and there should not be a trailing comma at the end of the
23
# list. When -mfmt=c is specified, curly brackets should be presented.
24
MINIMAL_SHADER_NUM_FORMAT_PATTERN = "^0x07230203.*[0-9a-f]$"
25
MINIMAL_SHADER_C_FORMAT_PATTERN = "^\{0x07230203.*[0-9a-f]\}"
26
ERROR_SHADER = '#version 140\n#error\nvoid main() {}'
27
28
29
@inside_glslc_testsuite('OptionMfmt')
30
class TestFmtCWorksWithDashC(expect.ValidFileContents):
31
"""Tests that -mfmt=c works with -c for single input file. SPIR-V binary
32
code output should be emitted as a C-style initializer list in the output
33
file.
34
"""
35
shader = FileShader(MINIMAL_SHADER, '.vert')
36
glslc_args = [shader, '-c', '-mfmt=c', '-o', 'output_file']
37
target_filename = 'output_file'
38
expected_file_contents = re.compile(MINIMAL_SHADER_C_FORMAT_PATTERN, re.S)
39
40
41
@inside_glslc_testsuite('OptionMfmt')
42
class TestFmtNumWorksWithDashC(expect.ValidFileContents):
43
"""Tests that -mfmt=num works with -c for single input file. SPIR-V binary
44
code output should be emitted as a list of hex numbers in the output file.
45
"""
46
shader = FileShader(MINIMAL_SHADER, '.vert')
47
glslc_args = [shader, '-c', '-mfmt=num', '-o', 'output_file']
48
target_filename = 'output_file'
49
expected_file_contents = re.compile(MINIMAL_SHADER_NUM_FORMAT_PATTERN, re.S)
50
51
52
@inside_glslc_testsuite('OptionMfmt')
53
class TestFmtBinWorksWithDashC(expect.ValidObjectFile):
54
"""Tests that -mfmt=bin works with -c for single input file. This test
55
should simply have the SPIR-V binary generated.
56
"""
57
shader = FileShader(MINIMAL_SHADER, '.vert')
58
glslc_args = [shader, '-c', '-mfmt=bin']
59
60
61
@inside_glslc_testsuite('OptionMfmt')
62
class TestFmtCWithLinking(expect.ValidFileContents):
63
"""Tests that -mfmt=c works when linkding is enabled (no -c specified).
64
SPIR-V binary code should be emitted as a C-style initializer list in the
65
output file.
66
"""
67
shader = FileShader(MINIMAL_SHADER, '.vert')
68
glslc_args = [shader, '-mfmt=c']
69
target_filename = 'a.spv'
70
expected_file_contents = re.compile(MINIMAL_SHADER_C_FORMAT_PATTERN, re.S)
71
72
73
@inside_glslc_testsuite('OptionMfmt')
74
class TestFmtNumWithLinking(expect.ValidFileContents):
75
"""Tests that -mfmt=num works when linkding is enabled (no -c specified).
76
SPIR-V binary code should be emitted as a C-style initializer list in the
77
output file.
78
"""
79
shader = FileShader(MINIMAL_SHADER, '.vert')
80
glslc_args = [shader, '-mfmt=num']
81
target_filename = 'a.spv'
82
expected_file_contents = re.compile(MINIMAL_SHADER_NUM_FORMAT_PATTERN, re.S)
83
84
85
@inside_glslc_testsuite('OptionMfmt')
86
class TestFmtCErrorWhenOutputDisasembly(expect.ErrorMessage):
87
"""Tests that specifying '-mfmt=c' when the compiler is set to
88
disassembly mode should trigger an error.
89
"""
90
shader = FileShader(MINIMAL_SHADER, '.vert')
91
glslc_args = [shader, '-mfmt=c', '-S', '-o', 'output_file']
92
expected_error = ("glslc: error: cannot emit output as a C-style "
93
"initializer list when only preprocessing the source\n")
94
95
96
@inside_glslc_testsuite('OptionMfmt')
97
class TestFmtNumErrorWhenOutputDisasembly(expect.ErrorMessage):
98
"""Tests that specifying '-mfmt=num' when the compiler is set to
99
disassembly mode should trigger an error.
100
"""
101
shader = FileShader(MINIMAL_SHADER, '.vert')
102
glslc_args = [shader, '-mfmt=num', '-S', '-o', 'output_file']
103
expected_error = (
104
"glslc: error: cannot emit output as a list of hex numbers "
105
"when only preprocessing the source\n")
106
107
108
@inside_glslc_testsuite('OptionMfmt')
109
class TestFmtBinErrorWhenOutputDisasembly(expect.ErrorMessage):
110
"""Tests that specifying '-mfmt=bin' when the compiler is set to
111
disassembly mode should trigger an error.
112
"""
113
shader = FileShader(MINIMAL_SHADER, '.vert')
114
glslc_args = [shader, '-mfmt=bin', '-S', '-o', 'output_file']
115
expected_error = ("glslc: error: cannot emit output as a binary "
116
"when only preprocessing the source\n")
117
118
119
@inside_glslc_testsuite('OptionMfmt')
120
class TestFmtNumErrorWhenOutputPreprocess(expect.ErrorMessage):
121
"""Tests that specifying '-mfmt=num' when the compiler is set to
122
preprocessing only mode should trigger an error.
123
"""
124
shader = FileShader(MINIMAL_SHADER, '.vert')
125
glslc_args = [shader, '-mfmt=num', '-E', '-o', 'output_file']
126
expected_error = (
127
"glslc: error: cannot emit output as a list of hex numbers "
128
"when only preprocessing the source\n")
129
130
131
@inside_glslc_testsuite('OptionMfmt')
132
class TestFmtCErrorWithDashCapM(expect.ErrorMessage):
133
"""Tests that specifying '-mfmt=c' should trigger an error when the
134
compiler is set to dump dependency info as the output (-M or -MM is
135
specified).
136
"""
137
shader = FileShader(MINIMAL_SHADER, '.vert')
138
glslc_args = [shader, '-mfmt=c', '-M', '-o', 'output_file']
139
expected_error = ("glslc: error: cannot emit output as a C-style "
140
"initializer list when only preprocessing the source\n")
141
142
143
@inside_glslc_testsuite('OptionMfmt')
144
class TestFmtCWorksWithDashCapMD(expect.ValidFileContents):
145
"""Tests that -mfmt=c works with '-c -MD'. SPIR-V binary code
146
should be emitted as a C-style initializer list in the output file.
147
"""
148
shader = FileShader(MINIMAL_SHADER, '.vert')
149
glslc_args = [shader, '-mfmt=c', '-c', '-MD', '-o', 'output_file']
150
target_filename = 'output_file'
151
expected_file_contents = re.compile(MINIMAL_SHADER_C_FORMAT_PATTERN, re.S)
152
153
154
@inside_glslc_testsuite('OptionMfmt')
155
class TestFmtNumWorksWithDashCapMD(expect.ValidFileContents):
156
"""Tests that -mfmt=num works with '-c -MD'. SPIR-V binary code
157
should be emitted as a C-style initializer list in the output file.
158
"""
159
shader = FileShader(MINIMAL_SHADER, '.vert')
160
glslc_args = [shader, '-mfmt=num', '-c', '-MD', '-o', 'output_file']
161
target_filename = 'output_file'
162
expected_file_contents = re.compile(MINIMAL_SHADER_NUM_FORMAT_PATTERN, re.S)
163
164
165
@inside_glslc_testsuite('OptionMfmt')
166
class TestFmtCExitsElegantlyWithErrorInShader(expect.ErrorMessage):
167
"""Tests that the compiler fails elegantly with -mfmt=c when there are
168
errors in the input shader.
169
"""
170
shader = FileShader(ERROR_SHADER, '.vert')
171
glslc_args = [shader, '-mfmt=c']
172
expected_error = [shader, ':3: error: \'#error\' :\n',
173
'1 error generated.\n']
174
175
176
@inside_glslc_testsuite('OptionMfmt')
177
class TestFmtNumExitsElegantlyWithErrorInShader(expect.ErrorMessage):
178
"""Tests that the compiler fails elegantly with -mfmt=num when there are
179
errors in the input shader.
180
"""
181
shader = FileShader(ERROR_SHADER, '.vert')
182
glslc_args = [shader, '-mfmt=num']
183
expected_error = [shader, ':3: error: \'#error\' :\n',
184
'1 error generated.\n']
185
186
187
@inside_glslc_testsuite('OptionMfmt')
188
class TestFmtBinExitsElegantlyWithErrorInShader(expect.ErrorMessage):
189
"""Tests that the compiler fails elegantly with -mfmt=binary when there are
190
errors in the input shader.
191
"""
192
shader = FileShader(ERROR_SHADER, '.vert')
193
glslc_args = [shader, '-mfmt=bin']
194
expected_error = [shader, ':3: error: \'#error\' :\n',
195
'1 error generated.\n']
196
197