framework: fix run with valgrind option
[piglit.git] / framework / test / oclconform.py
blob2012047c94e350b57fcbffc64637cd1b46d24a1e
1 # coding=utf-8
2 # Copyright 2016, 2019 Intel Corporation
3 # Copyright 2014 Advanced Micro Devices, Inc.
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
24 # Authors: Tom Stellard <thomas.stellard@amd.com>
27 import re
28 import subprocess
29 from os.path import join
30 from sys import stderr
32 import framework.grouptools as grouptools
33 from framework.core import PIGLIT_CONFIG
34 from .base import Test
36 __all__ = [
37 'OCLConform',
38 'add_oclconform_tests',
42 def get_test_section_name(test):
43 return 'oclconform-{}'.format(test)
46 class OCLConform(Test):
47 def interpret_result(self):
48 if self.result.returncode != 0 or 'FAIL' in self.result.out:
49 self.result.result = 'fail'
50 else:
51 self.result.result = 'pass'
54 def add_sub_test(profile, test_name, subtest_name, subtest):
55 profile.test_list[grouptools.join('oclconform', test_name,
56 subtest_name)] = subtest
59 def add_test(profile, test_name, test):
60 profile.test_list[grouptools.join('oclconform', test_name)] = test
63 def add_oclconform_tests(profile):
64 section_name = 'oclconform'
65 if not PIGLIT_CONFIG.has_section(section_name):
66 return
68 bindir = PIGLIT_CONFIG.get(section_name, 'bindir')
69 options = PIGLIT_CONFIG.options(section_name)
71 tests = (o for o in options if PIGLIT_CONFIG.get(section_name, o) is None)
73 for test in tests:
74 test_section_name = get_test_section_name(test)
75 if not PIGLIT_CONFIG.has_section(test_section_name):
76 print("Warning: no section defined for {}".format(test),
77 file=stderr)
78 continue
80 test_name = PIGLIT_CONFIG.get(test_section_name, 'test_name')
81 should_run_concurrent = PIGLIT_CONFIG.has_option(test_section_name,
82 'concurrent')
83 if PIGLIT_CONFIG.has_option(test_section_name, 'list_subtests'):
84 list_tests = PIGLIT_CONFIG.get(test_section_name,
85 'list_subtests')
86 subtest_regex = PIGLIT_CONFIG.get(test_section_name,
87 'subtest_regex')
88 subtest_regex.encode('unicode_escape')
89 run_subtests = PIGLIT_CONFIG.get(test_section_name, 'run_subtest')
90 list_tests = list_tests.split()
92 subtests = subprocess.check_output(
93 args=list_tests, cwd=bindir).decode('utf-8').split('\n')
94 for subtest in subtests:
95 m = re.match(subtest_regex, subtest)
96 if not m:
97 continue
98 subtest = m.group(1)
99 subtest_command = join(bindir,
100 run_subtests.replace('<subtest>',
101 subtest))
102 add_sub_test(profile, test_name, subtest,
103 OCLConform(command=subtest_command.split(),
104 run_concurrent=should_run_concurrent))
105 else:
106 run_test = PIGLIT_CONFIG.get(test_section_name, 'run_test')
107 add_test(profile, test_name,
108 OCLConform(command=run_test.split(),
109 run_concurrent=should_run_concurrent))