Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_dash_o.py
1560 views
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, TempFileName
19
from builtins import bytes
20
21
22
@inside_glslc_testsuite('OptionDashO')
23
class TestOptionDashOConcatenatedArg(expect.SuccessfulReturn,
24
expect.CorrectObjectFilePreamble):
25
"""Tests that we can concatenate -o and the output filename."""
26
27
shader = FileShader('#version 140\nvoid main() {}', '.vert')
28
glslc_args = ['-ofoo', shader]
29
30
def check_output_foo(self, status):
31
output_name = os.path.join(status.directory, 'foo')
32
return self.verify_object_file_preamble(output_name)
33
34
35
@inside_glslc_testsuite('OptionDashO')
36
class ManyOutputFilesWithDashO(expect.ErrorMessage):
37
"""Tests -o and -c with several files generates an error."""
38
39
shader1 = FileShader('', '.vert')
40
shader2 = FileShader('', '.frag')
41
glslc_args = ['-o', 'foo', '-c', shader1, shader2]
42
expected_error = [
43
'glslc: error: cannot specify -o when '
44
'generating multiple output files\n']
45
46
47
@inside_glslc_testsuite('OptionDashO')
48
class OutputFileLocation(expect.SuccessfulReturn,
49
expect.CorrectObjectFilePreamble):
50
"""Tests that the -o flag puts a file in a new location."""
51
52
shader = FileShader('#version 310 es\nvoid main() {}', '.frag')
53
glslc_args = [shader, '-o', TempFileName('a.out')]
54
55
def check_output_a_out(self, status):
56
output_name = os.path.join(status.directory, 'a.out')
57
return self.verify_object_file_preamble(output_name)
58
59
60
@inside_glslc_testsuite('OptionDashO')
61
class DashOMissingArgumentIsAnError(expect.ErrorMessage):
62
"""Tests that -o without an argument is an error."""
63
64
glslc_args = ['-o']
65
expected_error = ['glslc: error: argument to \'-o\' is missing ' +
66
'(expected 1 value)\n']
67
68
69
@inside_glslc_testsuite('OptionDashO')
70
class OutputFileBinaryAvoidsCRLFTranslation(expect.ReturnCodeIsZero,
71
expect.NoOutputOnStderr,
72
expect.NoGeneratedFiles,
73
expect.CorrectBinaryLengthAndPreamble):
74
"""Tests that the -o flag emits a binary file without CR/LF translation.
75
"""
76
77
# A shader whose compiled output has three bytes that are newlines.
78
# If the output stream converts the newlines to CR/LF, then we end up
79
# with a file that is 4k + 3 bytes long. That will be caught by the
80
# object file checks.
81
SHADER_WITH_THREE_NEWLINES_IN_BINARY = """#version 450
82
layout(location = 0) out uint ovar;
83
void main() { ovar = 9; }
84
"""
85
86
shader = FileShader(SHADER_WITH_THREE_NEWLINES_IN_BINARY, '.vert')
87
glslc_args = [shader, '-o', '-']
88
89
def check_stdout_binary(self, status):
90
binary = bytes(status.stdout)
91
newlines = [x for x in binary if x == ord('\n')]
92
num_newlines = len(newlines)
93
if num_newlines % 4 == 0:
94
return False, "Bad test. Need nontrivial number of newlines"
95
if num_newlines != 2:
96
return False, ("Update this test. Expected 3 newlines in the "
97
"binary, but found {}").format(num_newlines)
98
return self.verify_binary_length_and_header(bytes(status.stdout))
99
100