Example #1
0
class TestDashCapMSingleInputAbsolutePathWithIncludeSubdir(
        DependencyInfoStdoutMatch):
    """Tests -M with single input file which does #include another file in a
    subdirectory of current directory and is represented in absolute path.
    e.g. glslc -M /usr/local/a.vert
      => a.vert.spv: /usr/local/a.vert /usr/local/include/b.vert
    """
    environment = Directory('.', [
        Directory('include', [File('b.vert', 'void foo(){}\n')]),
    ])
    shader_main = FileShader('#version 140\n#include "include/b.vert"',
                             '.vert')
    glslc_args = ['-M', shader_main]
    dependency_rules_expected = [{
        'target': shader_main,
        'target_extension': '.spv',
        'dependency': {shader_main}
        # The dependency here is not complete.  we can not get the absolute
        # path of include/b.vert here. It will be added in
        # check_stdout_dependency_info()
    }]

    def check_stdout_dependency_info(self, status):
        # Add the absolute path of include/b.vert to the dependency set
        self.dependency_rules_expected[0]['dependency'].add(
            os.path.dirname(self.shader_main.filename) + '/include/b.vert')
        return DependencyInfoStdoutMatch.check_stdout_dependency_info(
            self, status)
Example #2
0
class TestWorkDirEqInArg(expect.ValidNamedObjectFile):
    """Tests -working-directory=<dir-with-equal-sign-inside>."""

    environment = Directory('.', [
        Directory('=subdir', [File('shader.vert', 'void main() {}')]),
    ])
    glslc_args = ['-working-directory==subdir', 'shader.vert']
    expected_object_filenames = ('a.spv', )
Example #3
0
class VerifyIncludeSubdir(expect.StdoutMatch):
    """Tests #including a file from a subdirectory."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a1\n#include "subdir/a"\ncontent a2\n'),
        Directory('subdir', [File('a', 'content suba\n')])])

    glslc_args = ['-E', 'a.vert']

    expected_stdout = \
"""#version 140
Example #4
0
class VerifyCompileIncludeSubdir(expect.ValidObjectFile):
    """Tests #including a file from a subdirectory via full compilation."""

    environment = Directory('.', [
        File('a.vert',
             """#define BODY {}
             #include "subdir/a"
             void afun()BODY
             """),
        Directory('subdir', [File('a', 'void main() BODY\n')])])

    glslc_args = ['a.vert']
Example #5
0
class VerifyRelativeParent(expect.StdoutMatch):
    """Tests #including a parent file."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
        File('c.glsl', 'content c\n'),
        Directory('foo', [File('b.glsl', '#include "../c.glsl"\ncontent b\n')])
    ])

    glslc_args = ['-E', 'a.vert', '-Ifoo']

    expected_stdout = \
"""#version 140
Example #6
0
class VerifyRelativeNeighbourDirectory(expect.StdoutMatch):
    """Tests #including a relative file in a neighbour directory."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
        Directory('foo',
                  [File('b.glsl', '#include "../bar/c.glsl"\ncontent b\n')]),
        Directory('bar', [File('c.glsl', 'content c\n')])
    ])

    glslc_args = ['-E', 'a.vert']

    expected_stdout = \
"""#version 140
Example #7
0
class VerifyRelativeInclude(expect.StdoutMatch):
    """Tests #including a relative sibling."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
        Directory('foo', [
            File('b.glsl', '#include "c.glsl"\ncontent b\n'),
            File('c.glsl', 'content c\n')
        ])])

    glslc_args = ['-E', 'a.vert']

    expected_stdout = \
"""#version 140
Example #8
0
class VerifyIncludeDeepSubdir(expect.StdoutMatch):
    """Tests #including a file from a subdirectory nested a few levels down."""

    environment = Directory('.', [
        File('a.vert',
             '#version 140\ncontent a1\n#include "dir/subdir/subsubdir/a"\ncontent a2\n'),
        Directory('dir', [
            Directory('subdir', [
                Directory('subsubdir', [File('a', 'content incl\n')])])])])

    glslc_args = ['-E', 'a.vert']

    expected_stdout = \
"""#version 140
Example #9
0
class TestWorkDirCompileFileOutput(expect.ValidNamedObjectFile):
    """Tests -working-directory=<dir> when compiling input file and specifying
    output filename."""

    environment = Directory('.', [
        Directory('subdir',
                  [Directory('bin', []),
                   File('shader.vert', MINIMAL_SHADER)])
    ])
    glslc_args = [
        '-c', '-o', 'bin/spv', '-working-directory=subdir', 'shader.vert'
    ]
    # Output file should be generated into subdir/bin/.
    expected_object_filenames = ('subdir/bin/spv', )
Example #10
0
class TestDashCapMSingleInputRelativePathWithDashI(DependencyInfoStdoutMatch):
    """Tests -M with single input file works with -I option. The #include
    directive does not specify 'include/' for the file to be include.
    e.g. glslc -M a.vert -I include
      => a.vert.spv: a.vert include/b.vert
    """
    environment = Directory('.', [
        File('a.vert', ('#version 140\n#include "b.vert"'
                        '\nvoid main(){}\n')),
        Directory('include', [File('b.vert', 'void foo(){}\n')]),
    ])
    glslc_args = ['-M', 'a.vert', '-I', 'include']
    dependency_rules_expected = [{'target': 'a.vert.spv',
                                  'dependency': {'a.vert', 'include/b.vert'}}]
Example #11
0
class VerifyRelativeOnlyToSelf(expect.ErrorMessage):
    """Tests that a relative includes are only relative to yourself."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "foo/b.glsl"\n'),
        File('c.glsl', 'content c\n'),
        Directory('foo', [File('b.glsl', '#include "c.glsl"\ncontent b\n')]),
    ])

    glslc_args = ['-E', 'a.vert']

    expected_error = [
        "foo/b.glsl:1: error: '#include' : Cannot find or open include file.\n",
        '1 error generated.\n'
    ]
Example #12
0
class TestDashCapMSingleInputRelativePathWithIncludeSubdir(
    DependencyInfoStdoutMatch):
    """Tests -M with single input file which does #include another file in a
    subdirectory of current directory and is represented in relative path.
    e.g. glslc -M a.vert
      => a.vert.spv: a.vert include/b.vert
    """
    environment = Directory('.', [
        File('a.vert', ('#version 140\n#include "include/b.vert"'
                        '\nvoid main(){}\n')),
        Directory('include', [File('b.vert', 'void foo(){}\n')]),
    ])
    glslc_args = ['-M', 'a.vert']
    dependency_rules_expected = [{'target': 'a.vert.spv',
                                  'dependency': {'a.vert', 'include/b.vert'}}]
class TestFLimitFileSetsLowerMinTexelOffset(expect.ValidObjectFile):
    """Tests -flimit-file with lower than default argument.  The shader uses that offset."""

    limits_file = File('limits.txt', 'MinProgramTexelOffset -9')
    shader = File('shader.vert', shader_source_with_tex_offset(-9))
    environment = Directory('.', [limits_file, shader])
    glslc_args = ['-c', shader.name, '-flimit-file', limits_file.name]
Example #14
0
class VerifyCompileIncludeDeepSubdir(expect.ValidObjectFile):
    """Tests #including a file from a subdirectory nested a few levels down
       via full compilation."""

    environment = Directory('.', [
        File('a.vert',
             """#version 140
             #define BODY {}
             #include "dir/subdir/subsubdir/a"
             void afun()BODY
             """),
        Directory('dir', [
            Directory('subdir', [
                Directory('subsubdir', [File('a', 'void main() BODY\n')])])])])

    glslc_args = ['a.vert']
Example #15
0
class TestDashCapMDMultipleFileDisassemblyMode(expect.ValidNamedAssemblyFile,
                                               DependencyInfoFileMatch):
    """Tests that -MD generates dependency info file for multiple files in
    disassembly mode.
    e.g. glslc -MD a.vert b.vert -S
      => <a.vert.spvasm: valid SPIR-V assembly file>
      => <a.vert.spvasm.d: dependency info: "a.vert.spvasm: a.vert">
      => <b.vert.spvasm: valid SPIR-V assembly file>
      => <b.vert.spvasm.d: dependency info: "b.vert.spvasm: b.vert">
    """
    environment = Directory(
        '.', [File('a.vert', MINIMAL_SHADER),
              File('b.vert', MINIMAL_SHADER)])
    glslc_args = ['-MD', 'a.vert', 'b.vert', '-S']
    expected_assembly_filenames = (
        'a.vert.spvasm',
        'b.vert.spvasm',
    )
    dependency_info_filenames = ['a.vert.spvasm.d', 'b.vert.spvasm.d']

    dependency_info_files_expected_contents = []
    dependency_info_files_expected_contents.append([{
        'target': 'a.vert.spvasm',
        'dependency': {'a.vert'}
    }])
    dependency_info_files_expected_contents.append([{
        'target': 'b.vert.spvasm',
        'dependency': {'b.vert'}
    }])
Example #16
0
class TestDashCapMDMultipleFilePreprocessingOnlyMode(expect.StdoutMatch,
                                                     DependencyInfoFileMatch):
    """Tests that -MD generates dependency info file for multiple files in
    preprocessing only mode.
    e.g. glslc -MD a.vert b.vert -E
      => stdout: preprocess result of a.vert and b.vert
      => <a.vert.spv.d: dependency info: "a.vert.spv: a.vert">
      => <b.vert.spv.d: dependency info: "b.vert.spv: b.vert">
    """
    environment = Directory(
        '.', [File('a.vert', MINIMAL_SHADER),
              File('b.vert', MINIMAL_SHADER)])
    glslc_args = ['-MD', 'a.vert', 'b.vert', '-E']
    dependency_info_filenames = ['a.vert.spv.d', 'b.vert.spv.d']
    dependency_info_files_expected_contents = []
    dependency_info_files_expected_contents.append([{
        'target': 'a.vert.spv',
        'dependency': {'a.vert'}
    }])
    dependency_info_files_expected_contents.append([{
        'target': 'b.vert.spv',
        'dependency': {'b.vert'}
    }])
    expected_stdout = ("#version 140\nvoid main(){ }\n"
                       "#version 140\nvoid main(){ }\n")
Example #17
0
class VerifyRelativeOverridesDashI(expect.StdoutMatch):
    """Tests that relative includes override -I parameters."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
        File('b.glsl', 'content base_b\n'),
        Directory('foo', [
            File('b.glsl', '#include "c.glsl"\ncontent b\n'),
            File('c.glsl', 'content c\n')
        ])
    ])

    glslc_args = ['-E', 'a.vert', '-Ifoo']

    expected_stdout = \
"""#version 140
Example #18
0
class TestWorkDirEqNoArgCompileFile(expect.ValidNamedObjectFile):
    """Tests -working-directory=<empty> when compiling input file."""

    environment = Directory('.', [EMPTY_SHADER_IN_SUBDIR])
    glslc_args = ['-c', '-working-directory=', 'subdir/shader.vert']
    # Output file should be generated into subdir/.
    expected_object_filenames = ('subdir/shader.vert.spv', )
Example #19
0
class TestDashCapMDMultipleFile(expect.ValidNamedObjectFile,
                                DependencyInfoFileMatch):
    """Tests that -MD generates dependency info file for multiple files.
    e.g. glslc -MD a.vert b.vert -c
      => <a.vert.spv: valid SPIR-V object file>
      => <a.vert.spv.d: dependency info: "a.vert.spv: a.vert">
      => <b.vert.spv: valid SPIR-V object file>
      => <b.vert.spv.d: dependency info: "b.vert.spv: b.vert">
    """
    environment = Directory(
        '.', [File('a.vert', MINIMAL_SHADER),
              File('b.vert', MINIMAL_SHADER)])
    glslc_args = ['-MD', 'a.vert', 'b.vert', '-c']
    expected_object_filenames = (
        'a.vert.spv',
        'b.vert.spv',
    )

    dependency_info_filenames = ['a.vert.spv.d', 'b.vert.spv.d']
    dependency_info_files_expected_contents = []
    dependency_info_files_expected_contents.append([{
        'target': 'a.vert.spv',
        'dependency': {'a.vert'}
    }])
    dependency_info_files_expected_contents.append([{
        'target': 'b.vert.spv',
        'dependency': {'b.vert'}
    }])
Example #20
0
class TestDashCapMInputAbsolutePathWithInclude(DependencyInfoStdoutMatch):
    """Tests -M have included files represented in absolute paths when the input
    file is represented in absolute path.
    E.g. Assume a.vert has '#include "b.vert"'
         glslc -M /usr/local/a.vert
      => a.vert.spv: /usr/local/a.vert /usr/local/b.vert
    """
    environment = Directory('.', [File('b.vert', 'void foo(){}\n')])
    shader_main = FileShader(
        '#version 140\n#include "b.vert"\nvoid main(){}\n', '.vert')

    glslc_args = ['-M', shader_main]
    dependency_rules_expected = [{
        'target': shader_main,
        'target_extension': '.spv',
        'dependency': {shader_main}
        # The dependency here is not complete.  we can not get the absolute path
        # of b.vert here. It will be added in check_stdout_dependency_info()
    }]

    def check_stdout_dependency_info(self, status):
        # Add the absolute path of b.vert to the dependency set
        self.dependency_rules_expected[0]['dependency'].add(
            os.path.dirname(self.shader_main.filename) + '/b.vert')
        return DependencyInfoStdoutMatch.check_stdout_dependency_info(
            self, status)
Example #21
0
class TestPSSfromIncludedFile(expect.ValidObjectFile):
    """Tests that #pragma shader_stage() from included files works."""

    environment = Directory('.', [
        File('a.glsl', '#include "b.glsl"\n'
             'void main() { gl_Position = vec4(1.); }\n'),
        File('b.glsl', '#pragma shader_stage(vertex)')])
    glslc_args = ['-c', 'a.glsl']
Example #22
0
class VerifyCompileIncludeOneSibling(expect.ValidObjectFile):
    """Tests #including a sibling file via full compilation."""

    environment = Directory('.', [
        File('a.vert', '#version 140\nvoid foo(){}\n#include "b"\n'),
        File('b', 'void main(){foo();}\n')])

    glslc_args = ['a.vert']
class TestFLimitFileInvalidContents(expect.ErrorMessage):
    """Tests -flimit-file bad file contents."""

    limits_file = File('limits.txt', 'thisIsBad')
    shader = File('shader.vert', shader_source_with_tex_offset(-9))
    environment = Directory('.', [limits_file, shader])
    glslc_args = ['-c', shader.name, '-flimit-file', limits_file.name]
    expected_error = 'glslc: error: -flimit-file error: invalid resource limit: thisIsBad\n'
Example #24
0
class VerifyRelativeIncludeWithDashI(expect.StdoutMatch):
    """Tests #including a relative file from a -I directory."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "bar/b.glsl"\n'),
        Directory('foo', [
            Directory('bar', [
                File('b.glsl', '#include "c.glsl"\ncontent b\n'),
            ]),
            File('c.glsl', 'content c\n')
        ])
    ])

    glslc_args = ['-E', 'a.vert', '-Ifoo']

    expected_stdout = \
"""#version 140
Example #25
0
class TestErrorDashCapMTWithMultipleInputFiles(expect.StderrMatch):
    """Tests that when -MT option is specified, only one input file should be
    provided."""
    environment = Directory('.', [File('a.vert', MINIMAL_SHADER),
                                  File('b.vert', MINIMAL_SHADER)])
    glslc_args = ['-M', 'a.vert', 'b.vert', '-c', '-MT', 'target']
    expected_stderr = ['glslc: error: '
                       'to specify dependency info file name or dependency '
                       'info target, only one input file is allowed.\n']
Example #26
0
class TestWorkDirDeepDir(expect.ValidNamedObjectFile):
    """Tests that -working-directory=<dir> works with directory hierarchies."""

    environment = Directory('subdir', [
        Directory('subsubdir', [
            File('one.vert', 'void main() {}'),
            File('two.frag', 'void main() {}')
        ]),
        File('zero.vert', 'void main() {}')
    ])
    glslc_args = [
        '-c', 'zero.vert', 'subsubdir/one.vert', 'subsubdir/two.frag',
        '-working-directory=subdir'
    ]
    # Output file should be generated into subdir/.
    expected_object_filenames = ('subdir/zero.vert.spv',
                                 'subdir/subsubdir/one.vert.spv',
                                 'subdir/subsubdir/two.frag.spv')
Example #27
0
class WorkDirDoesntAffectLinkedFile(expect.ValidNamedObjectFile):
    """A base class for tests asserting that -working-directory has no impact
    on the location of the output link file.
    """
    environment = Directory(
        '.',
        [
            Directory(
                'subdir',
                [
                    File('shader.vert', 'void main(){}'),
                    # Try to fake glslc into putting the linked file here, though it
                    # shouldn't (because -working-directory doesn't impact -o).
                    Directory('bin', [])
                ]),
            File('shader.vert', "fake file, doesn't compile."),
            Directory('bin', [])
        ])
Example #28
0
class VerifyIncludeWithoutNewline(expect.ErrorMessageSubstr):
    """Tests a #include without a newline."""

    environment = Directory('.', [
        File('a.vert', '#version 140\n#include "b"'),
        File('b', 'content b\n')])

    glslc_args = ['-E', 'a.vert']

    expected_error_substr = 'expected newline after header name: b'
Example #29
0
class TestMultipleWorkDir(expect.ValidNamedObjectFile):
    """Tests that if there are multiple -working-directory=<dir> specified,
    only the last one takes effect."""

    environment = Directory('.', [EMPTY_SHADER_IN_SUBDIR])
    glslc_args = [
        '-c', '-working-directory=i-dont-exist', '-working-directory',
        'i-think/me-neither', '-working-directory=subdir', 'shader.vert'
    ]
    # Output file should be generated into subdir/.
    expected_object_filenames = ('subdir/shader.vert.spv', )
Example #30
0
class VerifyDashIAbsolutePath(expect.StdoutMatch):
    """Tests that -I parameters can be absolute paths."""

    environment = Directory('.', [
        File('a.vert', '#version 140\ncontent a\n#include "b.glsl"\n'),
        Directory('foo', {File('b.glsl', 'content b\n')})
    ])

    glslc_args = ['-E', 'a.vert', '-I', SpecializedString('$directory/foo')]

    expected_stdout = SpecializedString("""#version 140
#extension GL_GOOGLE_include_directive : enable
#line 0 "a.vert"

content a
#line 0 "$directory/foo/b.glsl"
 content b
#line 3 "a.vert"

""")