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 | |
| 49 | expected_stdout = '''Usage: glslc [options] file... |
| 50 | |
| 51 | An input file of - represents standard input. |
| 52 | |
| 53 | Options: |
| 54 | -c Only run preprocess, compile, and assemble steps. |
| 55 | -Dmacro[=defn] Add an implicit macro definition. |
| 56 | -E Outputs only the results of the preprocessing step. |
| 57 | Output defaults to standard out. |
| 58 | -fshader-stage=<stage> |
| 59 | Treat subsequent input files as having stage <stage>. |
| 60 | Valid stages are vertex, fragment, tesscontrol, tesseval, |
| 61 | geometry, and compute. |
| 62 | -g Generate source-level debug information. |
| 63 | Currently this option has no effect. |
| 64 | --help Display available options. |
| 65 | -I <value> Add directory to include search path. |
| 66 | -o <file> Write output to <file>. |
| 67 | A file name of '-' represents standard output. |
| 68 | -std=<value> Version and profile for input files. Possible values |
| 69 | are concatenations of version and profile, e.g. 310es, |
| 70 | 450core, etc. |
qining | bde33a9 | 2016-02-01 14:30:07 -0500 | [diff] [blame^] | 71 | -M Generate make dependencies. Implies -E and -w. |
| 72 | -MM An alias for -M. |
| 73 | -MD Generate make dependencies and compile. |
| 74 | -MF <file> Write dependency output to the given file. |
| 75 | -MT <target> Specify the target of the rule emitted by dependency |
| 76 | generation. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 77 | -S Only run preprocess and compilation steps. |
qining | f6d8374 | 2016-01-28 16:05:11 -0500 | [diff] [blame] | 78 | --target-env=<environment> |
| 79 | Set the target shader environment, and the semantics |
| 80 | of warnings and errors. Valid values are 'opengl', |
| 81 | 'opengl_compat' and 'vulkan'. The default value is 'vulkan'. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 82 | -w Suppresses all warning messages. |
| 83 | -Werror Treat all warnings as errors. |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 84 | -x <language> Treat subsequent input files as having type <language>. |
| 85 | The only supported language is glsl. |
| 86 | ''' |
| 87 | |
| 88 | expected_stderr = '' |
| 89 | |
| 90 | |
| 91 | @inside_glslc_testsuite('Parameters') |
| 92 | class HelpIsNotTooWide(expect.StdoutNoWiderThan80Columns): |
| 93 | """Tests that --help output is not too wide.""" |
| 94 | |
| 95 | glslc_args = ['--help'] |
| 96 | |
| 97 | |
| 98 | @inside_glslc_testsuite('Parameters') |
| 99 | class UnknownSingleLetterArgument(expect.ErrorMessage): |
| 100 | """Tests that an unknown argument triggers an error message.""" |
| 101 | |
| 102 | glslc_args = ['-a'] |
| 103 | expected_error = ["glslc: error: unknown argument: '-a'\n"] |
| 104 | |
| 105 | |
| 106 | @inside_glslc_testsuite('Parameters') |
| 107 | class UnknownMultiLetterArgument(expect.ErrorMessage): |
| 108 | """Tests that an unknown argument triggers an error message.""" |
| 109 | |
| 110 | glslc_args = ['-zzz'] |
| 111 | expected_error = ["glslc: error: unknown argument: '-zzz'\n"] |
| 112 | |
| 113 | |
| 114 | @inside_glslc_testsuite('Parameters') |
| 115 | class UnsupportedOption(expect.ErrorMessage): |
| 116 | """Tests that an unsupported option triggers an error message.""" |
| 117 | |
| 118 | glslc_args = ['--unsupported-option'] |
| 119 | expected_error = [ |
| 120 | "glslc: error: unsupported option: '--unsupported-option'\n"] |
| 121 | |
| 122 | |
| 123 | @inside_glslc_testsuite('File') |
| 124 | class FileNotFound(expect.ErrorMessage): |
| 125 | """Tests the error message if a file cannot be found.""" |
| 126 | |
| 127 | blabla_file = TempFileName('blabla.frag') |
| 128 | glslc_args = [blabla_file] |
| 129 | expected_error = [ |
| 130 | "glslc: error: cannot open input file: '", blabla_file, |
| 131 | "': No such file or directory\n"] |
| 132 | |
| 133 | |
| 134 | @inside_glslc_testsuite('Unsupported') |
| 135 | class LinkingNotSupported(expect.ErrorMessage): |
| 136 | """Tests the error message generated by linking not supported yet.""" |
| 137 | |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 138 | shader1 = FileShader('#version 140\nvoid main() {}', '.vert') |
| 139 | shader2 = FileShader('#version 140\nvoid main() {}', '.frag') |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 140 | glslc_args = [shader1, shader2] |
| 141 | expected_error = [ |
| 142 | 'glslc: error: linking multiple files is not supported yet. ', |
| 143 | 'Use -c to compile files individually.\n'] |
| 144 | |
| 145 | |
| 146 | @inside_glslc_testsuite('Unsupported') |
| 147 | class MultipleStdinUnsupported(expect.ErrorMessage): |
| 148 | """Tests the error message generated by having more than one - input.""" |
| 149 | |
| 150 | glslc_args = ['-c', '-fshader-stage=vertex', '-', '-'] |
| 151 | expected_error = [ |
| 152 | 'glslc: error: specifying standard input "-" as input more' |
| 153 | ' than once is not allowed.\n'] |
| 154 | |
| 155 | |
| 156 | @inside_glslc_testsuite('Parameters') |
| 157 | class StdinWithoutShaderStage(expect.StdoutMatch, expect.StderrMatch): |
| 158 | """Tests that you must use -fshader-stage when specifying - as input.""" |
| 159 | shader = StdinShader( |
David Neto | fab6411 | 2016-02-02 16:24:06 -0500 | [diff] [blame] | 160 | """#version 140 |
Andrew Woloszyn | e549e7b | 2015-07-16 11:07:40 -0400 | [diff] [blame] | 161 | int a() { |
| 162 | } |
| 163 | void main() { |
| 164 | int x = a(); |
| 165 | } |
| 166 | """) |
| 167 | glslc_args = [shader] |
| 168 | |
| 169 | expected_stdout = '' |
| 170 | expected_stderr = [ |
| 171 | "glslc: error: '-': -fshader-stage required when input is from " |
| 172 | 'standard input "-"\n'] |