framework: fix run with valgrind option
[piglit.git] / framework / test / opencv.py
blobc107d2495eda5056565b23910f43c4aaa10754e0
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 import path
31 from .gtest import GTest
32 from framework.core import PIGLIT_CONFIG
33 from framework.test import CL_CONCURRENT
34 import framework.grouptools as grouptools
36 __all__ = [
37 'OpenCVTest',
38 'add_opencv_tests',
42 class OpenCVTest(GTest):
43 def __init__(self, test_prog, testname):
44 options = [test_prog, '--gtest_filter=' + testname, '--gtest_color=no']
45 if PIGLIT_CONFIG.has_option('opencv', 'workdir'):
46 options.append('-w {}'.format(PIGLIT_CONFIG.get('opencv', 'workdir')))
47 GTest.__init__(self, options, run_concurrent=CL_CONCURRENT)
50 def add_opencv_tests(profile):
51 if not PIGLIT_CONFIG.has_option('opencv', 'opencv_test_ocl_bindir'):
52 return
54 opencv_test_ocl = path.join(PIGLIT_CONFIG.get('opencv',
55 'opencv_test_ocl_bindir'), 'opencv_test_ocl')
56 individual = PIGLIT_CONFIG.has_option('opencv', 'individual')
57 if not path.isfile(opencv_test_ocl):
58 print('Warning: {} does not exist.\nSkipping OpenCV '
59 'tests...'.format(opencv_test_ocl))
60 return
61 tests = subprocess.check_output(
62 [opencv_test_ocl, '--gtest_list_tests']).decode('utf-8')
63 test_list = tests.splitlines()
64 group_name = ''
65 full_test_name = ''
66 for line in test_list:
67 #Test groups names start at the beginning of the line and end with '.'
68 m = re.match('([^.]+\.)$', line)
69 if m:
70 group_name = m.group(1)
71 group_desc = group_name[:-1]
72 full_test_name = 'opencv/{}'.format(group_desc)
73 if not individual:
74 profile.test_list[full_test_name] = OpenCVTest(opencv_test_ocl,
75 '{}*'.format(group_name))
76 continue
78 if not individual:
79 continue
81 # Test names are indent by 2 spaces
82 m = re.match(' ([^ ]+)', line)
83 if m:
84 test_name = m.group(1)
85 profile.test_list[grouptools.join(full_test_name, test_name)] = \
86 OpenCVTest(opencv_test_ocl, '{}{}'.format(group_name ,test_name))