blob: b00d75f6ff6c92c047aa7189c091f498d632ac0b [file] [log] [blame]
Andrew Woloszyne549e7b2015-07-16 11:07:40 -04001# Copyright 2015 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
15import expect
16import os.path
17from glslc_test_framework import inside_glslc_testsuite
18from placeholder import FileShader, StdinShader, TempFileName
19
20
21@inside_glslc_testsuite('File')
22class SimpleFileCompiled(expect.ValidObjectFile):
23 """Tests whether or not a simple glsl file compiles."""
24
25 shader = FileShader('#version 310 es\nvoid main() {}', '.frag')
26 glslc_args = ['-c', shader]
27
28
29@inside_glslc_testsuite('File')
30class NotSpecifyingOutputName(expect.SuccessfulReturn,
31 expect.CorrectObjectFilePreamble):
32 """Tests that when there is no -o and -E/-S/-c specified, output as a.spv."""
33
David Netofab64112016-02-02 16:24:06 -050034 shader = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040035 glslc_args = [shader]
36
37 def check_output_a_spv(self, status):
38 output_name = os.path.join(status.directory, 'a.spv')
39 return self.verify_object_file_preamble(output_name)
40
41
42@inside_glslc_testsuite('Parameters')
43class HelpParameters(
44 expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch):
45 """Tests the --help flag outputs correctly and does not produce and error."""
46
47 glslc_args = ['--help']
48
David Neto91bfb4c2016-02-23 22:26:18 -050049 expected_stdout = '''glslc - Compile shaders into SPIR-V
50
51Usage: glslc [options] file...
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040052
53An input file of - represents standard input.
54
55Options:
56 -c Only run preprocess, compile, and assemble steps.
57 -Dmacro[=defn] Add an implicit macro definition.
58 -E Outputs only the results of the preprocessing step.
Lei Zhang1ccede12016-02-24 09:30:32 -050059 Output defaults to standard output.
David Neto2df47b52016-11-12 13:55:21 -080060 -fentry-point=<name>
61 Specify the entry point name for HLSL compilation, for
62 all subsequent source files. Default is "main".
63 -flimit=<settings>
64 Specify resource limits. Each limit is specified by a limit
65 name followed by an integer value. Tokens should be
66 separated by whitespace. If the same limit is specified
67 several times, only the last setting takes effect.
68 --show-limits Display available limit names and their default values.
69 -flimit-file <file>
70 Set limits as specified in the given file.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040071 -fshader-stage=<stage>
72 Treat subsequent input files as having stage <stage>.
73 Valid stages are vertex, fragment, tesscontrol, tesseval,
74 geometry, and compute.
75 -g Generate source-level debug information.
76 Currently this option has no effect.
77 --help Display available options.
Dejan Mircevski29174452016-02-18 18:11:57 -050078 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040079 -I <value> Add directory to include search path.
80 -o <file> Write output to <file>.
81 A file name of '-' represents standard output.
David Netocdefe182016-10-21 01:12:53 -040082 -std=<value> Version and profile for GLSL input files. Possible values
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040083 are concatenations of version and profile, e.g. 310es,
David Netocdefe182016-10-21 01:12:53 -040084 450core, etc. Ignored for HLSL files.
qiningb3cfde42016-05-14 01:43:31 -040085 -mfmt=<format> Output SPIR-V binary code using the selected format. This
86 option may be specified only when the compilation output is
87 in SPIR-V binary code form. Available options include bin, c
88 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -050089 -M Generate make dependencies. Implies -E and -w.
90 -MM An alias for -M.
91 -MD Generate make dependencies and compile.
92 -MF <file> Write dependency output to the given file.
93 -MT <target> Specify the target of the rule emitted by dependency
94 generation.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040095 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -050096 --target-env=<environment>
97 Set the target shader environment, and the semantics
98 of warnings and errors. Valid values are 'opengl',
99 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400100 -w Suppresses all warning messages.
101 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400102 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -0400103 Valid languages are: glsl, hlsl.
104 For files ending in .hlsl the default is hlsl.
105 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400106'''
107
108 expected_stderr = ''
109
110
111@inside_glslc_testsuite('Parameters')
112class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
113 """Tests that --help output is not too wide."""
114
115 glslc_args = ['--help']
116
117
118@inside_glslc_testsuite('Parameters')
119class UnknownSingleLetterArgument(expect.ErrorMessage):
120 """Tests that an unknown argument triggers an error message."""
121
122 glslc_args = ['-a']
123 expected_error = ["glslc: error: unknown argument: '-a'\n"]
124
125
126@inside_glslc_testsuite('Parameters')
127class UnknownMultiLetterArgument(expect.ErrorMessage):
128 """Tests that an unknown argument triggers an error message."""
129
130 glslc_args = ['-zzz']
131 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
132
133
134@inside_glslc_testsuite('Parameters')
135class UnsupportedOption(expect.ErrorMessage):
136 """Tests that an unsupported option triggers an error message."""
137
138 glslc_args = ['--unsupported-option']
139 expected_error = [
140 "glslc: error: unsupported option: '--unsupported-option'\n"]
141
142
143@inside_glslc_testsuite('File')
144class FileNotFound(expect.ErrorMessage):
145 """Tests the error message if a file cannot be found."""
146
147 blabla_file = TempFileName('blabla.frag')
148 glslc_args = [blabla_file]
149 expected_error = [
150 "glslc: error: cannot open input file: '", blabla_file,
151 "': No such file or directory\n"]
152
153
154@inside_glslc_testsuite('Unsupported')
155class LinkingNotSupported(expect.ErrorMessage):
156 """Tests the error message generated by linking not supported yet."""
157
David Netofab64112016-02-02 16:24:06 -0500158 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
159 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400160 glslc_args = [shader1, shader2]
161 expected_error = [
162 'glslc: error: linking multiple files is not supported yet. ',
163 'Use -c to compile files individually.\n']
164
165
166@inside_glslc_testsuite('Unsupported')
167class MultipleStdinUnsupported(expect.ErrorMessage):
168 """Tests the error message generated by having more than one - input."""
169
170 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
171 expected_error = [
172 'glslc: error: specifying standard input "-" as input more'
173 ' than once is not allowed.\n']
174
175
176@inside_glslc_testsuite('Parameters')
177class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
178 """Tests that you must use -fshader-stage when specifying - as input."""
179 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500180 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400181 int a() {
182 }
183 void main() {
184 int x = a();
185 }
186 """)
187 glslc_args = [shader]
188
189 expected_stdout = ''
190 expected_stderr = [
191 "glslc: error: '-': -fshader-stage required when input is from "
192 'standard input "-"\n']
David Neto2df47b52016-11-12 13:55:21 -0800193
194
195@inside_glslc_testsuite('Parameters')
196class LimitsHelp(expect.StdoutMatch, expect.StderrMatch):
197 """Tests --show-limits shows correct output."""
198
199 glslc_args = ['--show-limits']
200
201 expected_stderr = ''
202 expected_stdout = """MaxLights 8
203MaxClipPlanes 6
204MaxTextureUnits 2
205MaxTextureCoords 8
206MaxVertexAttribs 16
207MaxVertexUniformComponents 4096
208MaxVaryingFloats 60
209MaxVertexTextureImageUnits 16
210MaxCombinedTextureImageUnits 80
211MaxTextureImageUnits 16
212MaxFragmentUniformComponents 1024
213MaxDrawBuffers 2
214MaxVertexUniformVectors 256
215MaxVaryingVectors 15
216MaxFragmentUniformVectors 256
217MaxVertexOutputVectors 16
218MaxFragmentInputVectors 15
219MinProgramTexelOffset -8
220MaxProgramTexelOffset 7
221MaxClipDistances 8
222MaxComputeWorkGroupCountX 65535
223MaxComputeWorkGroupCountY 65535
224MaxComputeWorkGroupCountZ 65535
225MaxComputeWorkGroupSizeX 1024
226MaxComputeWorkGroupSizeY 1024
227MaxComputeWorkGroupSizeZ 64
228MaxComputeUniformComponents 512
229MaxComputeTextureImageUnits 16
230MaxComputeImageUniforms 8
231MaxComputeAtomicCounters 8
232MaxComputeAtomicCounterBuffers 1
233MaxVaryingComponents 60
234MaxVertexOutputComponents 64
235MaxGeometryInputComponents 64
236MaxGeometryOutputComponents 128
237MaxFragmentInputComponents 128
238MaxImageUnits 8
239MaxCombinedImageUnitsAndFragmentOutputs 8
240MaxCombinedShaderOutputResources 8
241MaxImageSamples 0
242MaxVertexImageUniforms 0
243MaxTessControlImageUniforms 0
244MaxTessEvaluationImageUniforms 0
245MaxGeometryImageUniforms 0
246MaxFragmentImageUniforms 8
247MaxCombinedImageUniforms 8
248MaxGeometryTextureImageUnits 16
249MaxGeometryOutputVertices 256
250MaxGeometryTotalOutputComponents 1024
251MaxGeometryUniformComponents 512
252MaxGeometryVaryingComponents 60
253MaxTessControlInputComponents 128
254MaxTessControlOutputComponents 128
255MaxTessControlTextureImageUnits 16
256MaxTessControlUniformComponents 1024
257MaxTessControlTotalOutputComponents 4096
258MaxTessEvaluationInputComponents 128
259MaxTessEvaluationOutputComponents 128
260MaxTessEvaluationTextureImageUnits 16
261MaxTessEvaluationUniformComponents 1024
262MaxTessPatchComponents 120
263MaxPatchVertices 32
264MaxTessGenLevel 64
265MaxViewports 16
266MaxVertexAtomicCounters 0
267MaxTessControlAtomicCounters 0
268MaxTessEvaluationAtomicCounters 0
269MaxGeometryAtomicCounters 0
270MaxFragmentAtomicCounters 8
271MaxCombinedAtomicCounters 8
272MaxAtomicCounterBindings 1
273MaxVertexAtomicCounterBuffers 0
274MaxTessControlAtomicCounterBuffers 0
275MaxTessEvaluationAtomicCounterBuffers 0
276MaxGeometryAtomicCounterBuffers 0
277MaxFragmentAtomicCounterBuffers 0
278MaxCombinedAtomicCounterBuffers 1
279MaxAtomicCounterBufferSize 32
280MaxTransformFeedbackBuffers 4
281MaxTransformFeedbackInterleavedComponents 64
282MaxCullDistances 8
283MaxCombinedClipAndCullDistances 8
284MaxSamples 4
285"""