Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/test/option_dash_M.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
import sys
18
from environment import File, Directory
19
from glslc_test_framework import inside_glslc_testsuite
20
from placeholder import FileShader
21
from glslc_test_framework import GlslCTest
22
23
MINIMAL_SHADER = '#version 140\nvoid main() {}'
24
EMPTY_SHADER_IN_CURDIR = Directory('.', [File('shader.vert', MINIMAL_SHADER)])
25
EMPTY_SHADER_IN_SUBDIR = Directory('subdir',
26
[File('shader.vert', MINIMAL_SHADER)])
27
28
29
def process_test_specified_dependency_info_rules(test_specified_rules):
30
"""A helper function to process the expected dependency info rules
31
specified in tests before checking the actual dependency rule output.
32
33
This is required because the filename and path of temporary files created
34
through FileShader is unknown at the time the expected dependency info rules
35
are declared.
36
37
Note this function process the given rule list in-place.
38
"""
39
for rule in test_specified_rules:
40
# If the 'target' value is not a hard-coded file name but a
41
# FileShader, we need its full path, append extension to it and
42
# strip the directory component from it to get the complete target
43
# name.
44
if isinstance(rule['target'], FileShader):
45
rule['target'] = rule['target'].filename
46
if 'target_extension' in rule:
47
if rule['target_extension'] is not None:
48
rule['target'] = rule['target'] + rule['target_extension']
49
rule.pop('target_extension')
50
rule['target'] = os.path.basename(rule['target'])
51
52
# The dependency set may have FileShader too, we need to replace
53
# them with their absolute paths.
54
dependent_file_name_set = set()
55
for dependent_file in rule['dependency']:
56
if isinstance(dependent_file, FileShader):
57
dependent_file_name_set.add(dependent_file.filename)
58
else:
59
dependent_file_name_set.add(dependent_file)
60
rule['dependency'] = dependent_file_name_set
61
62
63
def parse_text_rules(text_lines):
64
""" A helper function to read text lines and construct and returns a list of
65
dependency rules which can be used for comparison.
66
67
The list is built with the text order. Each rule is described in the
68
following way:
69
{'target': <target name>, 'dependency': <set of dependent filenames>}
70
"""
71
rules = []
72
for line in text_lines:
73
if line.strip() == "":
74
continue
75
rule = {'target': line.split(': ')[0].strip(),
76
'dependency': set(line.split(': ')[-1].strip().split(' '))}
77
rules.append(rule)
78
return rules
79
80
81
class DependencyInfoStdoutMatch(GlslCTest):
82
"""Mixin class for tests that can expect dependency info in Stdout.
83
84
To mix in this class, the subclass needs to provide
85
dependency_rules_expected as a list of dictionaries, each dictionary
86
describes one expected make rule for a target file. A expected rule should
87
be specified in the following way:
88
89
rule = {'target': <target name>,
90
'target_extension': <.spv, .spvasm or None>,
91
'dependency': <dependent file names>}
92
93
The 'target_extension' field is optional, its value will be appended to
94
'target' to get complete target name.
95
96
And the list 'dependency_rules_expected' is a list of such rules and the
97
order of the rules does matter.
98
"""
99
100
def check_stdout_dependency_info(self, status):
101
if not status.stdout:
102
return False, 'Expect dependency rules on stdout'
103
104
if sys.version_info[0] == 2:
105
rules = parse_text_rules(status.stdout.decode('utf-8').split('\n'))
106
elif sys.version_info[0] == 3:
107
rules = parse_text_rules(str(status.stdout,
108
encoding='utf-8',
109
errors='ignore').split('\n'))
110
111
process_test_specified_dependency_info_rules(
112
self.dependency_rules_expected)
113
114
if self.dependency_rules_expected != rules:
115
return False, ('Incorrect dependency info:\n{ac_rules}\n'
116
'Expected:\n{ex_rules}\n'
117
'Stdout output:\n{ac_stdout}\n'.format(
118
ac_rules=rules,
119
ex_rules=self.dependency_rules_expected,
120
ac_stdout=status.stdout))
121
return True, ''
122
123
124
@inside_glslc_testsuite('OptionsCapM')
125
class TestDashCapMSingleInputRelativePathNoInclude(DependencyInfoStdoutMatch):
126
"""Tests -M with single input file which doesn't contain #include and is
127
represented in relative path.
128
e.g. glslc -M shader.vert
129
=> shader.vert.spv: shader.vert
130
"""
131
environment = EMPTY_SHADER_IN_CURDIR
132
glslc_args = ['-M', 'shader.vert']
133
dependency_rules_expected = [{'target': "shader.vert.spv",
134
'dependency': {"shader.vert"}}]
135
136
137
@inside_glslc_testsuite('OptionsCapM')
138
class TestDashCapMSingleInputAbsolutePathNoInclude(DependencyInfoStdoutMatch):
139
"""Tests -M with single input file which doesn't contain #include and is
140
represented in absolute path.
141
e.g. glslc -M /usr/local/shader.vert
142
=> shader.vert.spv: /usr/local/shader.vert
143
"""
144
shader = FileShader(MINIMAL_SHADER, '.vert')
145
glslc_args = ['-M', shader]
146
dependency_rules_expected = [{'target': shader,
147
'target_extension': '.spv',
148
'dependency': {shader}}]
149
150
151
@inside_glslc_testsuite('OptionsCapM')
152
class TestDashCapMSingleInputRelativePathWithInclude(
153
DependencyInfoStdoutMatch):
154
"""Tests -M with single input file which does contain #include and is
155
represented in relative path.
156
e.g. glslc -M a.vert
157
=> a.vert.spv: a.vert b.vert
158
"""
159
environment = Directory('.', [
160
File('a.vert', '#version 140\n#include "b.vert"\nvoid main(){}\n'),
161
File('b.vert', 'void foo(){}\n'),
162
])
163
glslc_args = ['-M', 'a.vert']
164
dependency_rules_expected = [{'target': 'a.vert.spv',
165
'dependency': {'a.vert', 'b.vert'}}]
166
167
168
@inside_glslc_testsuite('OptionsCapM')
169
class TestDashCapMSingleInputRelativePathWithIncludeSubdir(
170
DependencyInfoStdoutMatch):
171
"""Tests -M with single input file which does #include another file in a
172
subdirectory of current directory and is represented in relative path.
173
e.g. glslc -M a.vert
174
=> a.vert.spv: a.vert include/b.vert
175
"""
176
environment = Directory('.', [
177
File('a.vert', ('#version 140\n#include "include/b.vert"'
178
'\nvoid main(){}\n')),
179
Directory('include', [File('b.vert', 'void foo(){}\n')]),
180
])
181
glslc_args = ['-M', 'a.vert']
182
dependency_rules_expected = [{'target': 'a.vert.spv',
183
'dependency': {'a.vert', 'include/b.vert'}}]
184
185
186
@inside_glslc_testsuite('OptionsCapM')
187
class TestDashCapMSingleInputRelativePathWithDashI(DependencyInfoStdoutMatch):
188
"""Tests -M with single input file works with -I option. The #include
189
directive does not specify 'include/' for the file to be include.
190
e.g. glslc -M a.vert -I include
191
=> a.vert.spv: a.vert include/b.vert
192
"""
193
environment = Directory('.', [
194
File('a.vert', ('#version 140\n#include "b.vert"'
195
'\nvoid main(){}\n')),
196
Directory('include', [File('b.vert', 'void foo(){}\n')]),
197
])
198
glslc_args = ['-M', 'a.vert', '-I', 'include']
199
dependency_rules_expected = [{'target': 'a.vert.spv',
200
'dependency': {'a.vert', 'include/b.vert'}}]
201
202
203
@inside_glslc_testsuite('OptionsCapM')
204
class TestDashCapMSingleInputRelativePathWithNestedInclude(
205
DependencyInfoStdoutMatch):
206
"""Tests -M with single input file under nested #include case. The input file
207
is represented in relative path.
208
e.g. glslc -M a.vert
209
=> a.vert.spv: a.vert b.vert c.vert
210
"""
211
environment = Directory('.', [
212
File('a.vert', '#version 140\n#include "b.vert"\nvoid main(){}\n'),
213
File('b.vert', 'void foo(){}\n#include "c.vert"\n'),
214
File('c.vert', 'void bar(){}\n'),
215
])
216
glslc_args = ['-M', 'a.vert']
217
218
dependency_rules_expected = [{'target': 'a.vert.spv',
219
'dependency':
220
{'a.vert', 'b.vert', 'c.vert'}}]
221
222
223
@inside_glslc_testsuite('OptionsCapM')
224
class TestDashCapMMultipleInputRelativePathNoInclude(
225
DependencyInfoStdoutMatch):
226
"""Tests -M with multiple input file which don't contain #include and are
227
represented in relative paths.
228
e.g. glslc -M a.vert b.vert
229
=> a.vert.spv: a.vert
230
b.vert.spv: b.vert
231
"""
232
environment = Directory('.', [
233
File('a.vert', MINIMAL_SHADER),
234
File('b.vert', MINIMAL_SHADER),
235
])
236
glslc_args = ['-M', 'a.vert', 'b.vert']
237
238
dependency_rules_expected = [{'target': 'a.vert.spv',
239
'dependency': {'a.vert'}},
240
{'target': 'b.vert.spv',
241
'dependency': {'b.vert'}}, ]
242
243
244
@inside_glslc_testsuite('OptionsCapM')
245
class TestDashCapMMultipleInputAbsolutePathNoInclude(
246
DependencyInfoStdoutMatch):
247
"""Tests -M with single input file which doesn't contain #include and is
248
represented in absolute path.
249
e.g. glslc -M /usr/local/a.vert /usr/local/b.vert
250
=> a.vert.spv: /usr/local/a.vert
251
b.vert.spv: /usr/local/b.vert
252
"""
253
shader_a = FileShader(MINIMAL_SHADER, '.vert')
254
shader_b = FileShader(MINIMAL_SHADER, '.vert')
255
glslc_args = ['-M', shader_a, shader_b]
256
257
dependency_rules_expected = [{'target': shader_a,
258
'target_extension': '.spv',
259
'dependency': {shader_a}},
260
{'target': shader_b,
261
'target_extension': '.spv',
262
'dependency': {shader_b}}, ]
263
264
265
@inside_glslc_testsuite('OptionsCapM')
266
class TestDashCapMDashCapMT(DependencyInfoStdoutMatch):
267
"""Tests -MT works with -M. User can specify the target object name in the
268
generated dependency info.
269
e.g. glslc -M shader.vert -MT target
270
=> target: shader.vert
271
"""
272
environment = EMPTY_SHADER_IN_CURDIR
273
glslc_args = ['-M', 'shader.vert', '-MT', 'target']
274
dependency_rules_expected = [{'target': 'target',
275
'dependency': {'shader.vert'}}]
276
277
278
@inside_glslc_testsuite('OptionsCapM')
279
class TestDashCapMInputAbsolutePathWithInclude(DependencyInfoStdoutMatch):
280
"""Tests -M have included files represented in absolute paths when the input
281
file is represented in absolute path.
282
E.g. Assume a.vert has '#include "b.vert"'
283
glslc -M /usr/local/a.vert
284
=> a.vert.spv: /usr/local/a.vert /usr/local/b.vert
285
"""
286
environment = Directory('.', [File('b.vert', 'void foo(){}\n')])
287
shader_main = FileShader(
288
'#version 140\n#include "b.vert"\nvoid main(){}\n', '.vert')
289
290
glslc_args = ['-M', shader_main]
291
dependency_rules_expected = [{
292
'target': shader_main,
293
'target_extension': '.spv',
294
'dependency': {shader_main}
295
# The dependency here is not complete. we can not get the absolute path
296
# of b.vert here. It will be added in check_stdout_dependency_info()
297
}]
298
299
def check_stdout_dependency_info(self, status):
300
# Add the absolute path of b.vert to the dependency set
301
self.dependency_rules_expected[0]['dependency'].add(os.path.dirname(
302
self.shader_main.filename) + '/b.vert')
303
return DependencyInfoStdoutMatch.check_stdout_dependency_info(self,
304
status)
305
306
307
@inside_glslc_testsuite('OptionsCapM')
308
class TestDashCapMSingleInputAbsolutePathWithIncludeSubdir(
309
DependencyInfoStdoutMatch):
310
"""Tests -M with single input file which does #include another file in a
311
subdirectory of current directory and is represented in absolute path.
312
e.g. glslc -M /usr/local/a.vert
313
=> a.vert.spv: /usr/local/a.vert /usr/local/include/b.vert
314
"""
315
environment = Directory('.', [
316
Directory('include', [File('b.vert', 'void foo(){}\n')]),
317
])
318
shader_main = FileShader('#version 140\n#include "include/b.vert"\n',
319
'.vert')
320
glslc_args = ['-M', shader_main]
321
dependency_rules_expected = [{
322
'target': shader_main,
323
'target_extension': '.spv',
324
'dependency': {shader_main}
325
# The dependency here is not complete. we can not get the absolute
326
# path of include/b.vert here. It will be added in
327
# check_stdout_dependency_info()
328
}]
329
330
def check_stdout_dependency_info(self, status):
331
# Add the absolute path of include/b.vert to the dependency set
332
self.dependency_rules_expected[0]['dependency'].add(os.path.dirname(
333
self.shader_main.filename) + '/include/b.vert')
334
return DependencyInfoStdoutMatch.check_stdout_dependency_info(self,
335
status)
336
337
338
@inside_glslc_testsuite('OptionsCapM')
339
class TestDashCapMOverridesOtherModes(DependencyInfoStdoutMatch):
340
"""Tests -M overrides other compiler mode options, includeing -E, -c and -S.
341
"""
342
environment = Directory('.', [
343
File('a.vert', MINIMAL_SHADER),
344
File('b.vert', MINIMAL_SHADER),
345
])
346
glslc_args = ['-M', '-E', '-c', '-S', 'a.vert', 'b.vert']
347
dependency_rules_expected = [{'target': 'a.vert.spv',
348
'dependency': {'a.vert'}},
349
{'target': 'b.vert.spv',
350
'dependency': {'b.vert'}}]
351
352
353
@inside_glslc_testsuite('OptionsCapM')
354
class TestDashCapMMEquivalentToCapM(DependencyInfoStdoutMatch):
355
"""Tests that -MM behaves as -M.
356
e.g. glslc -MM shader.vert
357
=> shader.vert.spv: shader.vert
358
"""
359
environment = EMPTY_SHADER_IN_CURDIR
360
glslc_args = ['-MM', 'shader.vert']
361
dependency_rules_expected = [{'target': 'shader.vert.spv',
362
'dependency': {'shader.vert'}}]
363
364
365
@inside_glslc_testsuite('OptionsCapM')
366
class TestDashCapMImpliesDashCapE(DependencyInfoStdoutMatch,
367
expect.NoOutputOnStderr):
368
"""Tests that -M implies -E, a .glsl file without an explict stage should
369
not generate an error.
370
e.g. glslc -M shader.glsl
371
=> shader.spv: shader.glsl
372
<no error message should be generated>
373
"""
374
environment = Directory('.', [File('shader.glsl', MINIMAL_SHADER)])
375
glslc_args = ['-M', 'shader.glsl']
376
dependency_rules_expected = [{'target': 'shader.spv',
377
'dependency': {'shader.glsl'}}]
378
379
380
@inside_glslc_testsuite('OptionsCapM')
381
class TestDashCapMImpliesDashW(DependencyInfoStdoutMatch,
382
expect.NoOutputOnStderr):
383
"""Tests that -M implies -w, a deprecated attribute should not generate
384
warning message.
385
e.g. glslc -M shader.vert
386
=> shader.vert.spv: shader.vert
387
<no warning message should be generated>
388
"""
389
environment = Directory('.', [File(
390
'shader.vert', """#version 400
391
layout(location=0) attribute float x;
392
void main() {}""")])
393
glslc_args = ['-M', 'shader.vert']
394
dependency_rules_expected = [{'target': 'shader.vert.spv',
395
'dependency': {'shader.vert'}}]
396
397
398
@inside_glslc_testsuite('OptionsCapM')
399
class TestDashCapMMImpliesDashCapE(DependencyInfoStdoutMatch,
400
expect.NoOutputOnStderr):
401
"""Tests that -M implies -E, a .glsl file without an explict stage should
402
not generate an error.
403
e.g. glslc -MM shader.glsl
404
=> shader.spv: shader.glsl
405
<no error message should be generated>
406
"""
407
environment = Directory('.', [File('shader.glsl', MINIMAL_SHADER)])
408
glslc_args = ['-MM', 'shader.glsl']
409
dependency_rules_expected = [{'target': 'shader.spv',
410
'dependency': {'shader.glsl'}}]
411
412
413
@inside_glslc_testsuite('OptionsCapM')
414
class TestDashCapMMImpliesDashW(DependencyInfoStdoutMatch,
415
expect.NoOutputOnStderr):
416
"""Tests that -MM implies -w, a deprecated attribute should not generate
417
warning message.
418
e.g. glslc -MM shader.vert
419
=> shader.vert.spv: shader.vert
420
<no warning message should be generated>
421
"""
422
environment = Directory('.', [File(
423
'shader.vert', """
424
#version 400
425
layout(location = 0) attribute float x;
426
void main() {}""")])
427
glslc_args = ['-MM', 'shader.vert']
428
dependency_rules_expected = [{'target': 'shader.vert.spv',
429
'dependency': {'shader.vert'}}]
430
431
432
@inside_glslc_testsuite('OptionsCapM')
433
class TestDashCapMD(expect.ValidFileContents, expect.ValidNamedObjectFile):
434
"""Tests that -MD generates dependency info file and compilation output.
435
e.g. glslc -MD shader.vert
436
=> <a.spv: valid SPIR-V object file>
437
=> <shader.vert.spv.d: dependency info>
438
"""
439
environment = EMPTY_SHADER_IN_CURDIR
440
glslc_args = ['-MD', 'shader.vert']
441
expected_object_filenames = ('a.spv', )
442
target_filename = 'shader.vert.spv.d'
443
expected_file_contents = ['shader.vert.spv: shader.vert\n']
444
445
446
class DependencyInfoFileMatch(GlslCTest):
447
"""Mixin class for tests that can expect dependency info files.
448
449
To mix in this class, subclasses need to provide dependency_info_filenames
450
and dependency_info_files_expected_contents which are two lists.
451
list dependency_info_filenames contains the dependency info file names and
452
list dependency_info_files_expected_contents contains the expected matching
453
dependency rules.
454
The item order of the two lists should match, which means:
455
dependency_info_files_expected_contents[i] should describe the
456
dependency rules saved in dependency_info_filenames[i]
457
458
The content of each dependency info file is described in same 'list of dict'
459
structure explained in class DependencyInfoStdoutMatch's doc string.
460
"""
461
462
def check_dependency_info_files(self, status):
463
dep_info_files = \
464
[os.path.join(status.directory,
465
f) for f in self.dependency_info_filenames]
466
for i, df in enumerate(dep_info_files):
467
if not os.path.isfile(df):
468
return False, 'Cannot find file: ' + df
469
try:
470
with open(df, 'r') as dff:
471
content = dff.read()
472
rules = parse_text_rules(content.split('\n'))
473
474
process_test_specified_dependency_info_rules(
475
self.dependency_info_files_expected_contents[i])
476
477
if self.dependency_info_files_expected_contents[
478
i] != rules:
479
return False, (
480
'Incorrect dependency info:\n{ac_rules}\n'
481
'Expected:\n{ex_rules}\n'
482
'Incorrect file output:\n{ac_out}\n'
483
'Incorrect dependency info file:\n{ac_file}\n'.format(
484
ac_rules=rules,
485
ex_rules=self.dependency_rules_expected,
486
ac_stdout=content,
487
ac_file=df))
488
except IOError:
489
return False, ('Could not open dependency info file ' + df +
490
' for reading')
491
return True, ''
492
493
494
@inside_glslc_testsuite('OptionsCapM')
495
class TestDashCapMWorksWithDashO(DependencyInfoFileMatch):
496
"""Tests -M works with -o option. When user specifies an output file name
497
with -o, the dependency info should be dumped to the user specified output
498
file.
499
"""
500
environment = EMPTY_SHADER_IN_CURDIR
501
glslc_args = ['-M', 'shader.vert', '-o', 'dep_info']
502
dependency_info_filenames = ('dep_info', )
503
dependency_info_files_expected_contents = []
504
dependency_info_files_expected_contents.append(
505
[{'target': 'shader.vert.spv',
506
'dependency': {'shader.vert'}}])
507
508
509
@inside_glslc_testsuite('OptionsCapM')
510
class TestDashCapMDMultipleFile(expect.ValidNamedObjectFile,
511
DependencyInfoFileMatch):
512
"""Tests that -MD generates dependency info file for multiple files.
513
e.g. glslc -MD a.vert b.vert -c
514
=> <a.vert.spv: valid SPIR-V object file>
515
=> <a.vert.spv.d: dependency info: "a.vert.spv: a.vert">
516
=> <b.vert.spv: valid SPIR-V object file>
517
=> <b.vert.spv.d: dependency info: "b.vert.spv: b.vert">
518
"""
519
environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
520
File('b.vert', MINIMAL_SHADER)])
521
glslc_args = ['-MD', 'a.vert', 'b.vert', '-c']
522
expected_object_filenames = ('a.vert.spv', 'b.vert.spv', )
523
524
dependency_info_filenames = ['a.vert.spv.d', 'b.vert.spv.d']
525
dependency_info_files_expected_contents = []
526
dependency_info_files_expected_contents.append([{'target': 'a.vert.spv',
527
'dependency': {'a.vert'}}
528
])
529
dependency_info_files_expected_contents.append([{'target': 'b.vert.spv',
530
'dependency': {'b.vert'}}
531
])
532
533
534
@inside_glslc_testsuite('OptionsCapM')
535
class TestDashCapMDMultipleFilePreprocessingOnlyMode(expect.StdoutMatch,
536
DependencyInfoFileMatch):
537
"""Tests that -MD generates dependency info file for multiple files in
538
preprocessing only mode.
539
e.g. glslc -MD a.vert b.vert -E
540
=> stdout: preprocess result of a.vert and b.vert
541
=> <a.vert.spv.d: dependency info: "a.vert.spv: a.vert">
542
=> <b.vert.spv.d: dependency info: "b.vert.spv: b.vert">
543
"""
544
environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
545
File('b.vert', MINIMAL_SHADER)])
546
glslc_args = ['-MD', 'a.vert', 'b.vert', '-E']
547
dependency_info_filenames = ['a.vert.spv.d', 'b.vert.spv.d']
548
dependency_info_files_expected_contents = []
549
dependency_info_files_expected_contents.append([{'target': 'a.vert.spv',
550
'dependency': {'a.vert'}}
551
])
552
dependency_info_files_expected_contents.append([{'target': 'b.vert.spv',
553
'dependency': {'b.vert'}}
554
])
555
expected_stdout = ("#version 140\nvoid main() { }\n"
556
"#version 140\nvoid main() { }\n")
557
558
559
@inside_glslc_testsuite('OptionsCapM')
560
class TestDashCapMDMultipleFileDisassemblyMode(expect.ValidNamedAssemblyFile,
561
DependencyInfoFileMatch):
562
"""Tests that -MD generates dependency info file for multiple files in
563
disassembly mode.
564
e.g. glslc -MD a.vert b.vert -S
565
=> <a.vert.spvasm: valid SPIR-V assembly file>
566
=> <a.vert.spvasm.d: dependency info: "a.vert.spvasm: a.vert">
567
=> <b.vert.spvasm: valid SPIR-V assembly file>
568
=> <b.vert.spvasm.d: dependency info: "b.vert.spvasm: b.vert">
569
"""
570
environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
571
File('b.vert', MINIMAL_SHADER)])
572
glslc_args = ['-MD', 'a.vert', 'b.vert', '-S']
573
expected_assembly_filenames = ('a.vert.spvasm', 'b.vert.spvasm', )
574
dependency_info_filenames = ['a.vert.spvasm.d', 'b.vert.spvasm.d']
575
576
dependency_info_files_expected_contents = []
577
dependency_info_files_expected_contents.append([{'target': 'a.vert.spvasm',
578
'dependency': {'a.vert'}}
579
])
580
dependency_info_files_expected_contents.append([{'target': 'b.vert.spvasm',
581
'dependency': {'b.vert'}}
582
])
583
584
585
@inside_glslc_testsuite('OptionsCapM')
586
class TestDashCapMT(expect.ValidFileContents, expect.ValidNamedObjectFile):
587
"""Tests that -MT generates dependency info file with specified target label.
588
e.g. glslc -MD shader.vert -MT target_label
589
=> <a.spv: valid SPIR-V object file>
590
=> <shader.vert.spv.d: dependency info: "target_label: shader.vert">
591
"""
592
environment = EMPTY_SHADER_IN_CURDIR
593
glslc_args = ['-MD', 'shader.vert', '-MT', 'target_label']
594
expected_object_filenames = ('a.spv', )
595
target_filename = 'shader.vert.spv.d'
596
expected_file_contents = ['target_label: shader.vert\n']
597
598
599
@inside_glslc_testsuite('OptionsCapM')
600
class TestDashCapMF(expect.ValidFileContents, expect.ValidNamedObjectFile):
601
"""Tests that -MF dumps dependency info into specified file.
602
e.g. glslc -MD shader.vert -MF dep_file
603
=> <a.spv: valid SPIR-V object file>
604
=> <dep_file: dependency info: "shader.vert.spv: shader.vert">
605
"""
606
environment = EMPTY_SHADER_IN_CURDIR
607
glslc_args = ['-MD', 'shader.vert', '-MF', 'dep_file']
608
expected_object_filenames = ('a.spv', )
609
target_filename = 'dep_file'
610
expected_file_contents = ['shader.vert.spv: shader.vert\n']
611
612
613
@inside_glslc_testsuite('OptionsCapM')
614
class TestDashCapMDSpecifyOutputFileName(expect.ValidFileContents,
615
expect.ValidNamedObjectFile):
616
"""Tests that -MD has the default dependency info file name and target
617
label correct when -o <output_file_name> appears in the command line.
618
The default dependency info file name and target label should be deduced
619
from the linking-disabled compilation output.
620
e.g. glslc -MD subdir/shader.vert -c -o output
621
=> <./output: valid SPIR-V object file>
622
=> <./output.d: dependency info: "output: shader.vert">
623
"""
624
environment = EMPTY_SHADER_IN_SUBDIR
625
glslc_args = ['-MD', 'subdir/shader.vert', '-c', '-o', 'output']
626
expected_object_filenames = ('output', )
627
target_filename = 'output.d'
628
expected_file_contents = ['output: subdir/shader.vert\n']
629
630
631
@inside_glslc_testsuite('OptionsCapM')
632
class TestDashCapMDWithDashMFDashMTDashO(expect.ValidFileContents,
633
expect.ValidNamedObjectFile):
634
"""Tests that -MD, -MF, -MT and -o gernates dependency info file and
635
compilation output file correctly
636
e.g. glslc -MD subdir/shader.vert -c -o subdir/out -MF dep_info -MT label
637
=> <subdir/out: valid SPIR-V object file>
638
=> <dep_info: dependency info: "label: shader.vert">
639
"""
640
environment = EMPTY_SHADER_IN_SUBDIR
641
glslc_args = ['-MD', 'subdir/shader.vert', '-c', '-o', 'subdir/out', '-MF',
642
'dep_info', '-MT', 'label']
643
expected_object_filenames = ('subdir/out', )
644
target_filename = 'dep_info'
645
expected_file_contents = ['label: subdir/shader.vert\n']
646
647
648
@inside_glslc_testsuite('OptionsCapM')
649
class TestDashCapMDWithDashMFDashMTDashODisassemblyMode(
650
expect.ValidFileContents, expect.ValidNamedAssemblyFile):
651
"""Tests that -MD, -MF, -MT and -o gernates dependency info file and
652
compilation output file correctly in disassembly mode
653
e.g. glslc -MD subdir/shader.vert -s -o subdir/out -MF dep_info -MT label
654
=> <subdir/out: valid SPIR-V object file>
655
=> <dep_info: dependency info: "label: shader.vert">
656
"""
657
environment = EMPTY_SHADER_IN_SUBDIR
658
glslc_args = ['-MD', 'subdir/shader.vert', '-S', '-o', 'subdir/out', '-MF',
659
'dep_info', '-MT', 'label']
660
expected_assembly_filenames = ('subdir/out', )
661
target_filename = 'dep_info'
662
expected_file_contents = ['label: subdir/shader.vert\n']
663
664
665
@inside_glslc_testsuite('OptionsCapM')
666
class TestErrorSetBothDashCapMAndDashCapMD(expect.StderrMatch):
667
"""Tests that when both -M (or -MM) and -MD are specified, glslc should exit
668
with an error message complaining the case and neither dependency info
669
output nor compilation output. This test has -MD before -M flag.
670
"""
671
environment = EMPTY_SHADER_IN_CURDIR
672
glslc_args = ['-MD', '-M', 'shader.vert']
673
expected_stderr = ['glslc: error: both -M (or -MM) and -MD are specified. '
674
'Only one should be used at one time.\n']
675
676
677
@inside_glslc_testsuite('OptionsCapM')
678
class TestErrorSetBothDashCapMDAndDashCapM(expect.StderrMatch):
679
"""Tests that when both -M (or -MM) and -MD are specified, glslc should exit
680
with an error message complaining the case and neither dependency info
681
output nor compilation output. This test has -M before -MD flag.
682
"""
683
environment = EMPTY_SHADER_IN_CURDIR
684
glslc_args = ['-M', '-MD', 'shader.vert']
685
expected_stderr = ['glslc: error: both -M (or -MM) and -MD are specified. '
686
'Only one should be used at one time.\n']
687
688
689
@inside_glslc_testsuite('OptionsCapM')
690
class TestErrorDashCapMFWithMultipleInputFiles(expect.StderrMatch):
691
"""Tests that when -MF option is specified, only one input file should be
692
provided."""
693
environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
694
File('b.vert', MINIMAL_SHADER)])
695
glslc_args = ['-MD', 'a.vert', 'b.vert', '-c', '-MF', 'dep_info']
696
expected_stderr = ['glslc: error: '
697
'to specify dependency info file name or dependency '
698
'info target, only one input file is allowed.\n']
699
700
701
@inside_glslc_testsuite('OptionsCapM')
702
class TestErrorDashCapMTWithMultipleInputFiles(expect.StderrMatch):
703
"""Tests that when -MT option is specified, only one input file should be
704
provided."""
705
environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
706
File('b.vert', MINIMAL_SHADER)])
707
glslc_args = ['-M', 'a.vert', 'b.vert', '-c', '-MT', 'target']
708
expected_stderr = ['glslc: error: '
709
'to specify dependency info file name or dependency '
710
'info target, only one input file is allowed.\n']
711
712
713
@inside_glslc_testsuite('OptionsCapM')
714
class TestErrorDashCapMFMissingDashMAndDashMD(expect.StderrMatch):
715
"""Tests that when only -MF is specified while -M and -MD are not specified,
716
glslc should emit an error complaining that the user must specifiy either
717
-M (-MM) or -MD to generate dependency info.
718
"""
719
environment = EMPTY_SHADER_IN_CURDIR
720
glslc_args = ['-MF', 'dep_info', 'shader.vert', '-c']
721
expected_stderr = ['glslc: error: '
722
'to generate dependencies you must specify either -M '
723
'(-MM) or -MD\n']
724
725
726
@inside_glslc_testsuite('OptionsCapM')
727
class TestErrorDashCapMTMissingDashMAndMDWith(expect.StderrMatch):
728
"""Tests that when only -MF and -MT is specified while -M and -MD are not
729
specified, glslc should emit an error complaining that the user must
730
specifiy either -M (-MM) or -MD to generate dependency info.
731
"""
732
environment = EMPTY_SHADER_IN_CURDIR
733
glslc_args = ['-MF', 'dep_info', '-MT', 'target', 'shader.vert', '-c']
734
expected_stderr = ['glslc: error: '
735
'to generate dependencies you must specify either -M '
736
'(-MM) or -MD\n']
737
738
739
@inside_glslc_testsuite('OptionsCapM')
740
class TestErrorMissingDependencyInfoFileName(expect.StderrMatch):
741
"""Tests that dependency file name is missing when -MF is specified."""
742
environment = EMPTY_SHADER_IN_CURDIR
743
glslc_args = ['target', 'shader.vert', '-c', '-MF']
744
expected_stderr = ['glslc: error: '
745
'missing dependency info filename after \'-MF\'\n']
746
747
748
@inside_glslc_testsuite('OptionsCapM')
749
class TestErrorMissingDependencyTargetName(expect.StderrMatch):
750
"""Tests that dependency target name is missing when -MT is specified."""
751
environment = EMPTY_SHADER_IN_CURDIR
752
glslc_args = ['target', 'shader.vert', '-c', '-MT']
753
expected_stderr = ['glslc: error: '
754
'missing dependency info target after \'-MT\'\n']
755
756