File: oclconform.py

package info (click to toggle)
piglit 0~git20180515-62ef6b0db-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 102,084 kB
  • sloc: ansic: 244,201; xml: 47,485; python: 28,308; lisp: 19,320; cpp: 10,678; sh: 301; makefile: 33; pascal: 5
file content (111 lines) | stat: -rw-r--r-- 4,419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2016 Intel Corporation
# Copyright 2014 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Authors: Tom Stellard <thomas.stellard@amd.com>
#

from __future__ import (
    absolute_import, division, print_function, unicode_literals
)
import re
import subprocess
from os.path import join
from sys import stderr

import framework.grouptools as grouptools
from framework.core import PIGLIT_CONFIG
from .base import Test

__all__ = [
    'OCLConform',
    'add_oclconform_tests',
]


def get_test_section_name(test):
    return 'oclconform-{}'.format(test)


class OCLConform(Test):
    def interpret_result(self):
        if self.result.returncode != 0 or 'FAIL' in self.result.out:
            self.result.result = 'fail'
        else:
            self.result.result = 'pass'


def add_sub_test(profile, test_name, subtest_name, subtest):
    profile.test_list[grouptools.join('oclconform', test_name,
                                      subtest_name)] = subtest


def add_test(profile, test_name, test):
    profile.test_list[grouptools.join('oclconform', test_name)] = test


def add_oclconform_tests(profile):
    section_name = 'oclconform'
    if not PIGLIT_CONFIG.has_section(section_name):
        return

    bindir = PIGLIT_CONFIG.get(section_name, 'bindir')
    options = PIGLIT_CONFIG.options(section_name)

    tests = (o for o in options if PIGLIT_CONFIG.get(section_name, o) is None)

    for test in tests:
        test_section_name = get_test_section_name(test)
        if not PIGLIT_CONFIG.has_section(test_section_name):
            print("Warning: no section defined for {}".format(test),
                  file=stderr)
            continue

        test_name = PIGLIT_CONFIG.get(test_section_name, 'test_name')
        should_run_concurrent = PIGLIT_CONFIG.has_option(test_section_name,
                                                         'concurrent')
        if PIGLIT_CONFIG.has_option(test_section_name, 'list_subtests'):
            list_tests = PIGLIT_CONFIG.get(test_section_name,
                                           'list_subtests')
            subtest_regex = PIGLIT_CONFIG.get(test_section_name,
                                              'subtest_regex')
            subtest_regex.encode('unicode_escape')
            run_subtests = PIGLIT_CONFIG.get(test_section_name, 'run_subtest')
            list_tests = list_tests.split()

            subtests = subprocess.check_output(
                args=list_tests, cwd=bindir).decode('utf-8').split('\n')
            for subtest in subtests:
                m = re.match(subtest_regex, subtest)
                if not m:
                    continue
                subtest = m.group(1)
                subtest_command = join(bindir,
                                       run_subtests.replace('<subtest>',
                                                            subtest))
                add_sub_test(profile, test_name, subtest,
                             OCLConform(command=subtest_command.split(),
                                        run_concurrent=should_run_concurrent))
        else:
            run_test = PIGLIT_CONFIG.get(test_section_name, 'run_test')
            add_test(profile, test_name,
                     OCLConform(command=run_test.split(),
                                run_concurrent=should_run_concurrent))