blob: ff450b14b2e0337c22cdd885019f09476164d10a [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.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040060 -fshader-stage=<stage>
61 Treat subsequent input files as having stage <stage>.
62 Valid stages are vertex, fragment, tesscontrol, tesseval,
63 geometry, and compute.
64 -g Generate source-level debug information.
65 Currently this option has no effect.
66 --help Display available options.
Dejan Mircevski29174452016-02-18 18:11:57 -050067 --version Display compiler version information.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040068 -I <value> Add directory to include search path.
69 -o <file> Write output to <file>.
70 A file name of '-' represents standard output.
David Netocdefe182016-10-21 01:12:53 -040071 -std=<value> Version and profile for GLSL input files. Possible values
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040072 are concatenations of version and profile, e.g. 310es,
David Netocdefe182016-10-21 01:12:53 -040073 450core, etc. Ignored for HLSL files.
qiningb3cfde42016-05-14 01:43:31 -040074 -mfmt=<format> Output SPIR-V binary code using the selected format. This
75 option may be specified only when the compilation output is
76 in SPIR-V binary code form. Available options include bin, c
77 and num. By default the binary output format is bin.
qiningbde33a92016-02-01 14:30:07 -050078 -M Generate make dependencies. Implies -E and -w.
79 -MM An alias for -M.
80 -MD Generate make dependencies and compile.
81 -MF <file> Write dependency output to the given file.
82 -MT <target> Specify the target of the rule emitted by dependency
83 generation.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040084 -S Only run preprocess and compilation steps.
qiningf6d83742016-01-28 16:05:11 -050085 --target-env=<environment>
86 Set the target shader environment, and the semantics
87 of warnings and errors. Valid values are 'opengl',
88 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040089 -w Suppresses all warning messages.
90 -Werror Treat all warnings as errors.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040091 -x <language> Treat subsequent input files as having type <language>.
David Netocdefe182016-10-21 01:12:53 -040092 Valid languages are: glsl, hlsl.
93 For files ending in .hlsl the default is hlsl.
94 Otherwise the default is glsl.
Andrew Woloszyne549e7b2015-07-16 11:07:40 -040095'''
96
97 expected_stderr = ''
98
99
100@inside_glslc_testsuite('Parameters')
101class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns):
102 """Tests that --help output is not too wide."""
103
104 glslc_args = ['--help']
105
106
107@inside_glslc_testsuite('Parameters')
108class UnknownSingleLetterArgument(expect.ErrorMessage):
109 """Tests that an unknown argument triggers an error message."""
110
111 glslc_args = ['-a']
112 expected_error = ["glslc: error: unknown argument: '-a'\n"]
113
114
115@inside_glslc_testsuite('Parameters')
116class UnknownMultiLetterArgument(expect.ErrorMessage):
117 """Tests that an unknown argument triggers an error message."""
118
119 glslc_args = ['-zzz']
120 expected_error = ["glslc: error: unknown argument: '-zzz'\n"]
121
122
123@inside_glslc_testsuite('Parameters')
124class UnsupportedOption(expect.ErrorMessage):
125 """Tests that an unsupported option triggers an error message."""
126
127 glslc_args = ['--unsupported-option']
128 expected_error = [
129 "glslc: error: unsupported option: '--unsupported-option'\n"]
130
131
132@inside_glslc_testsuite('File')
133class FileNotFound(expect.ErrorMessage):
134 """Tests the error message if a file cannot be found."""
135
136 blabla_file = TempFileName('blabla.frag')
137 glslc_args = [blabla_file]
138 expected_error = [
139 "glslc: error: cannot open input file: '", blabla_file,
140 "': No such file or directory\n"]
141
142
143@inside_glslc_testsuite('Unsupported')
144class LinkingNotSupported(expect.ErrorMessage):
145 """Tests the error message generated by linking not supported yet."""
146
David Netofab64112016-02-02 16:24:06 -0500147 shader1 = FileShader('#version 140\nvoid main() {}', '.vert')
148 shader2 = FileShader('#version 140\nvoid main() {}', '.frag')
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400149 glslc_args = [shader1, shader2]
150 expected_error = [
151 'glslc: error: linking multiple files is not supported yet. ',
152 'Use -c to compile files individually.\n']
153
154
155@inside_glslc_testsuite('Unsupported')
156class MultipleStdinUnsupported(expect.ErrorMessage):
157 """Tests the error message generated by having more than one - input."""
158
159 glslc_args = ['-c', '-fshader-stage=vertex', '-', '-']
160 expected_error = [
161 'glslc: error: specifying standard input "-" as input more'
162 ' than once is not allowed.\n']
163
164
165@inside_glslc_testsuite('Parameters')
166class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch):
167 """Tests that you must use -fshader-stage when specifying - as input."""
168 shader = StdinShader(
David Netofab64112016-02-02 16:24:06 -0500169 """#version 140
Andrew Woloszyne549e7b2015-07-16 11:07:40 -0400170 int a() {
171 }
172 void main() {
173 int x = a();
174 }
175 """)
176 glslc_args = [shader]
177
178 expected_stdout = ''
179 expected_stderr = [
180 "glslc: error: '-': -fshader-stage required when input is from "
181 'standard input "-"\n']