Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 1 | # 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 | |
| 15 | import expect |
| 16 | import os.path |
| 17 | from glslc_test_framework import inside_glslc_testsuite |
| 18 | from placeholder import FileShader, StdinShader, TempFileName |
| 19 | |
| 20 | |
| 21 | @inside_glslc_testsuite('File') |
| 22 | class 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') |
| 30 | class 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 Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 34 | shader = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 35 | 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') |
| 43 | class 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 Neto | 91bfb4c | 2016-02-23 22:26:18 -0500 | [diff] [blame] | 49 | expected_stdout = '''glslc - Compile shaders into SPIR-V |
| 50 | |
| 51 | Usage: glslc [options] file... |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 52 | |
| 53 | An input file of - represents standard input. |
| 54 | |
| 55 | Options: |
| 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 Zhang | 1ccede1 | 2016-02-24 09:30:32 -0500 | [diff] [blame] | 59 | Output defaults to standard output. |
David Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame^] | 60 | -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 Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 71 | -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 Mircevski | 2917445 | 2016-02-18 18:11:57 -0500 | [diff] [blame] | 78 | --version Display compiler version information. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 79 | -I <value> Add directory to include search path. |
| 80 | -o <file> Write output to <file>. |
| 81 | A file name of '-' represents standard output. |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 82 | -std=<value> Version and profile for GLSL input files. Possible values |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 83 | are concatenations of version and profile, e.g. 310es, |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 84 | 450core, etc. Ignored for HLSL files. |
qining | b3cfde4 | 2016-05-14 01:43:31 -0400 | [diff] [blame] | 85 | -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. |
qining | bde33a9 | 2016-02-01 14:30:07 -0500 | [diff] [blame] | 89 | -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 Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 95 | -S Only run preprocess and compilation steps. |
qining | f6d8374 | 2016-01-28 16:05:11 -0500 | [diff] [blame] | 96 | --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 Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 100 | -w Suppresses all warning messages. |
| 101 | -Werror Treat all warnings as errors. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 102 | -x <language> Treat subsequent input files as having type <language>. |
David Neto | cdefe18 | 2016-10-21 01:12:53 -0400 | [diff] [blame] | 103 | Valid languages are: glsl, hlsl. |
| 104 | For files ending in .hlsl the default is hlsl. |
| 105 | Otherwise the default is glsl. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 106 | ''' |
| 107 | |
| 108 | expected_stderr = '' |
| 109 | |
| 110 | |
| 111 | @inside_glslc_testsuite('Parameters') |
| 112 | class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns): |
| 113 | """Tests that --help output is not too wide.""" |
| 114 | |
| 115 | glslc_args = ['--help'] |
| 116 | |
| 117 | |
| 118 | @inside_glslc_testsuite('Parameters') |
| 119 | class 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') |
| 127 | class 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') |
| 135 | class 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') |
| 144 | class 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') |
| 155 | class LinkingNotSupported(expect.ErrorMessage): |
| 156 | """Tests the error message generated by linking not supported yet.""" |
| 157 | |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 158 | shader1 = FileShader('#version 140\nvoid main() {}', '.vert') |
| 159 | shader2 = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 160 | 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') |
| 167 | class 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') |
| 177 | class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch): |
| 178 | """Tests that you must use -fshader-stage when specifying - as input.""" |
| 179 | shader = StdinShader( |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 180 | """#version 140 |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 181 | 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 Neto | 2df47b5 | 2016-11-12 13:55:21 -0800 | [diff] [blame^] | 193 | |
| 194 | |
| 195 | @inside_glslc_testsuite('Parameters') |
| 196 | class 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 |
| 203 | MaxClipPlanes 6 |
| 204 | MaxTextureUnits 2 |
| 205 | MaxTextureCoords 8 |
| 206 | MaxVertexAttribs 16 |
| 207 | MaxVertexUniformComponents 4096 |
| 208 | MaxVaryingFloats 60 |
| 209 | MaxVertexTextureImageUnits 16 |
| 210 | MaxCombinedTextureImageUnits 80 |
| 211 | MaxTextureImageUnits 16 |
| 212 | MaxFragmentUniformComponents 1024 |
| 213 | MaxDrawBuffers 2 |
| 214 | MaxVertexUniformVectors 256 |
| 215 | MaxVaryingVectors 15 |
| 216 | MaxFragmentUniformVectors 256 |
| 217 | MaxVertexOutputVectors 16 |
| 218 | MaxFragmentInputVectors 15 |
| 219 | MinProgramTexelOffset -8 |
| 220 | MaxProgramTexelOffset 7 |
| 221 | MaxClipDistances 8 |
| 222 | MaxComputeWorkGroupCountX 65535 |
| 223 | MaxComputeWorkGroupCountY 65535 |
| 224 | MaxComputeWorkGroupCountZ 65535 |
| 225 | MaxComputeWorkGroupSizeX 1024 |
| 226 | MaxComputeWorkGroupSizeY 1024 |
| 227 | MaxComputeWorkGroupSizeZ 64 |
| 228 | MaxComputeUniformComponents 512 |
| 229 | MaxComputeTextureImageUnits 16 |
| 230 | MaxComputeImageUniforms 8 |
| 231 | MaxComputeAtomicCounters 8 |
| 232 | MaxComputeAtomicCounterBuffers 1 |
| 233 | MaxVaryingComponents 60 |
| 234 | MaxVertexOutputComponents 64 |
| 235 | MaxGeometryInputComponents 64 |
| 236 | MaxGeometryOutputComponents 128 |
| 237 | MaxFragmentInputComponents 128 |
| 238 | MaxImageUnits 8 |
| 239 | MaxCombinedImageUnitsAndFragmentOutputs 8 |
| 240 | MaxCombinedShaderOutputResources 8 |
| 241 | MaxImageSamples 0 |
| 242 | MaxVertexImageUniforms 0 |
| 243 | MaxTessControlImageUniforms 0 |
| 244 | MaxTessEvaluationImageUniforms 0 |
| 245 | MaxGeometryImageUniforms 0 |
| 246 | MaxFragmentImageUniforms 8 |
| 247 | MaxCombinedImageUniforms 8 |
| 248 | MaxGeometryTextureImageUnits 16 |
| 249 | MaxGeometryOutputVertices 256 |
| 250 | MaxGeometryTotalOutputComponents 1024 |
| 251 | MaxGeometryUniformComponents 512 |
| 252 | MaxGeometryVaryingComponents 60 |
| 253 | MaxTessControlInputComponents 128 |
| 254 | MaxTessControlOutputComponents 128 |
| 255 | MaxTessControlTextureImageUnits 16 |
| 256 | MaxTessControlUniformComponents 1024 |
| 257 | MaxTessControlTotalOutputComponents 4096 |
| 258 | MaxTessEvaluationInputComponents 128 |
| 259 | MaxTessEvaluationOutputComponents 128 |
| 260 | MaxTessEvaluationTextureImageUnits 16 |
| 261 | MaxTessEvaluationUniformComponents 1024 |
| 262 | MaxTessPatchComponents 120 |
| 263 | MaxPatchVertices 32 |
| 264 | MaxTessGenLevel 64 |
| 265 | MaxViewports 16 |
| 266 | MaxVertexAtomicCounters 0 |
| 267 | MaxTessControlAtomicCounters 0 |
| 268 | MaxTessEvaluationAtomicCounters 0 |
| 269 | MaxGeometryAtomicCounters 0 |
| 270 | MaxFragmentAtomicCounters 8 |
| 271 | MaxCombinedAtomicCounters 8 |
| 272 | MaxAtomicCounterBindings 1 |
| 273 | MaxVertexAtomicCounterBuffers 0 |
| 274 | MaxTessControlAtomicCounterBuffers 0 |
| 275 | MaxTessEvaluationAtomicCounterBuffers 0 |
| 276 | MaxGeometryAtomicCounterBuffers 0 |
| 277 | MaxFragmentAtomicCounterBuffers 0 |
| 278 | MaxCombinedAtomicCounterBuffers 1 |
| 279 | MaxAtomicCounterBufferSize 32 |
| 280 | MaxTransformFeedbackBuffers 4 |
| 281 | MaxTransformFeedbackInterleavedComponents 64 |
| 282 | MaxCullDistances 8 |
| 283 | MaxCombinedClipAndCullDistances 8 |
| 284 | MaxSamples 4 |
| 285 | """ |