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