glx-oml-sync-control-timing: Fix error message if glXWaitForMscOML fails
[piglit.git] / tests / igt.py
blob5842810deef4f4239fc0532a66ebcadc6e86e873
2 # Copyright (c) 2012 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person
5 # obtaining a copy of this software and associated documentation
6 # files (the "Software"), to deal in the Software without
7 # restriction, including without limitation the rights to use,
8 # copy, modify, merge, publish, distribute, sublicense, and/or
9 # sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following
11 # conditions:
13 # This permission notice shall be included in all copies or
14 # substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
25 """Integration for running intel-gpu-tools with the piglit framework.
27 To use this either configure piglit.conf's [igt] section, or set IGT_TEST_ROOT
28 to the root of a built igt directory.
30 This will stop if you are not running as root, or if there are other users of
31 drm. Even if you have rendernode support enabled.
33 """
35 from __future__ import (
36 absolute_import, division, print_function, unicode_literals
39 import os
40 import re
41 import subprocess
43 from framework import grouptools, exceptions, core, options
44 from framework import dmesg
45 from framework.profile import TestProfile, Test
47 __all__ = ['profile']
50 def check_environment():
51 """Check that the environment that piglit is running in is appropriate.
53 IGT requires root, debugfs to be mounted, and to be the only drm client.
55 """
56 debugfs_path = "/sys/kernel/debug/dri"
57 if os.getuid() != 0:
58 raise exceptions.PiglitInternalError(
59 "Test Environment check: not root!")
60 if not os.path.isdir(debugfs_path):
61 raise exceptions.PiglitInternalError(
62 "Test Environment check: debugfs not mounted properly!")
63 for subdir in os.listdir(debugfs_path):
64 if not os.path.isdir(os.path.join(debugfs_path, subdir)):
65 continue
66 clients = open(os.path.join(debugfs_path, subdir, "clients"), 'r')
67 lines = clients.readlines()
68 if len(lines) > 2:
69 raise exceptions.PiglitInternalError(
70 "Test Environment check: other drm clients running!")
73 if 'IGT_TEST_ROOT' in os.environ:
74 IGT_TEST_ROOT = os.environ['IGT_TEST_ROOT']
75 else:
76 IGT_TEST_ROOT = os.path.join(
77 core.PIGLIT_CONFIG.required_get('igt', 'path'), 'tests')
79 if not os.path.exists(IGT_TEST_ROOT):
80 raise exceptions.PiglitFatalError(
81 'IGT directory does not exist. Missing: {}'.format(IGT_TEST_ROOT))
83 # check for the test lists
84 if os.path.exists(os.path.join(IGT_TEST_ROOT, 'test-list.txt')):
85 TEST_LISTS = ['test-list.txt']
86 elif (os.path.exists(os.path.join(IGT_TEST_ROOT, 'single-tests.txt')) and
87 os.path.exists(os.path.join(IGT_TEST_ROOT, 'multi-tests.txt'))):
88 TEST_LISTS = ['single-tests.txt', 'multi-tests.txt']
89 else:
90 raise exceptions.PiglitFatalError("intel-gpu-tools test lists not found.")
93 class IGTTestProfile(TestProfile):
94 """Test profile for intel-gpu-tools tests."""
96 def setup(self):
97 if options.OPTIONS.execute:
98 try:
99 check_environment()
100 except exceptions.PiglitInternalError as e:
101 raise exceptions.PiglitFatalError(str(e))
104 profile = IGTTestProfile() # pylint: disable=invalid-name
107 class IGTTest(Test):
108 """Test class for running libdrm."""
109 def __init__(self, binary, arguments=None):
110 if arguments is None:
111 arguments = []
112 super(IGTTest, self).__init__(
113 [os.path.join(IGT_TEST_ROOT, binary)] + arguments)
114 self.timeout = 600
116 def interpret_result(self):
117 super(IGTTest, self).interpret_result()
119 if self.result.returncode == 0:
120 if not self.result.err:
121 self.result.result = 'pass'
122 else:
123 self.result.result = 'warn'
124 elif self.result.returncode == 77:
125 self.result.result = 'skip'
126 elif self.result.returncode == 78:
127 self.result.result = 'timeout'
128 elif self.result.returncode == 139:
129 self.result.result = 'crash'
130 else:
131 self.result.result = 'fail'
134 def list_tests(listname):
135 """Parse igt test list and return them as a list."""
136 with open(os.path.join(IGT_TEST_ROOT, listname), 'r') as f:
137 lines = (line.rstrip() for line in f.readlines())
139 found_header = False
141 for line in lines:
142 if found_header:
143 return line.split(" ")
145 if "TESTLIST" in line:
146 found_header = True
148 return []
151 def add_subtest_cases(test):
152 """Get subtest instances."""
153 try:
154 out = subprocess.check_output(
155 [os.path.join(IGT_TEST_ROOT, test), '--list-subtests'],
156 env=os.environ.copy(),
157 universal_newlines=True)
158 except subprocess.CalledProcessError as e:
159 # a return code of 79 indicates there are no subtests
160 if e.returncode == 79:
161 profile.test_list[grouptools.join('igt', test)] = IGTTest(test)
162 elif e.returncode != 0:
163 print("Error: Could not list subtests for " + test)
164 else:
165 raise
167 # If we reach here there are no subtests.
168 return
170 for subtest in (s for s in out.splitlines() if s):
171 profile.test_list[grouptools.join('igt', test, subtest)] = \
172 IGTTest(test, ['--run-subtest', subtest])
175 def populate_profile():
176 tests = []
177 for test_list in TEST_LISTS:
178 tests.extend(list_tests(test_list))
180 for test in tests:
181 add_subtest_cases(test)
184 populate_profile()
185 profile.options['dmesg'] = dmesg.get_dmesg(True)
186 profile.options['dmesg'].regex = re.compile(r"(\[drm:|drm_|intel_|i915_)")