3 # Copyright (c) 2012 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation
7 # files (the "Software"), to deal in the Software without
8 # restriction, including without limitation the rights to use,
9 # copy, modify, merge, publish, distribute, sublicense, and/or
10 # sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following
14 # This permission notice shall be included in all copies or
15 # substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 # DEALINGS IN THE SOFTWARE.
26 """Integration for running intel-gpu-tools with the piglit framework.
28 To use this either configure piglit.conf's [igt] section, or set IGT_TEST_ROOT
29 to the root of a built igt directory.
31 This will stop if you are not running as root, or if there are other users of
32 drm. Even if you have rendernode support enabled.
36 from __future__
import (
37 absolute_import
, division
, print_function
, unicode_literals
44 from framework
import grouptools
, exceptions
, core
, options
45 from framework
import dmesg
46 from framework
.profile
import TestProfile
, Test
51 def check_environment():
52 """Check that the environment that piglit is running in is appropriate.
54 IGT requires root, debugfs to be mounted, and to be the only drm client.
57 debugfs_path
= "/sys/kernel/debug/dri"
59 raise exceptions
.PiglitInternalError(
60 "Test Environment check: not root!")
61 if not os
.path
.isdir(debugfs_path
):
62 raise exceptions
.PiglitInternalError(
63 "Test Environment check: debugfs not mounted properly!")
64 for subdir
in os
.listdir(debugfs_path
):
65 if not os
.path
.isdir(os
.path
.join(debugfs_path
, subdir
)):
67 clients
= open(os
.path
.join(debugfs_path
, subdir
, "clients"), 'r')
68 lines
= clients
.readlines()
70 raise exceptions
.PiglitInternalError(
71 "Test Environment check: other drm clients running!")
74 if 'IGT_TEST_ROOT' in os
.environ
:
75 IGT_TEST_ROOT
= os
.environ
['IGT_TEST_ROOT']
77 IGT_TEST_ROOT
= os
.path
.join(
78 core
.PIGLIT_CONFIG
.required_get('igt', 'path'), 'tests')
80 if not os
.path
.exists(IGT_TEST_ROOT
):
81 raise exceptions
.PiglitFatalError(
82 'IGT directory does not exist. Missing: {}'.format(IGT_TEST_ROOT
))
84 # check for the test lists
85 if os
.path
.exists(os
.path
.join(IGT_TEST_ROOT
, 'test-list.txt')):
86 TEST_LISTS
= ['test-list.txt']
87 elif (os
.path
.exists(os
.path
.join(IGT_TEST_ROOT
, 'single-tests.txt')) and
88 os
.path
.exists(os
.path
.join(IGT_TEST_ROOT
, 'multi-tests.txt'))):
89 TEST_LISTS
= ['single-tests.txt', 'multi-tests.txt']
91 raise exceptions
.PiglitFatalError("intel-gpu-tools test lists not found.")
94 class IGTTestProfile(TestProfile
):
95 """Test profile for intel-gpu-tools tests."""
98 if options
.OPTIONS
.execute
:
101 except exceptions
.PiglitInternalError
as e
:
102 raise exceptions
.PiglitFatalError(str(e
))
105 profile
= IGTTestProfile() # pylint: disable=invalid-name
109 """Test class for running libdrm."""
110 def __init__(self
, binary
, arguments
=None):
111 if arguments
is None:
113 super(IGTTest
, self
).__init
__(
114 [os
.path
.join(IGT_TEST_ROOT
, binary
)] + arguments
)
117 def interpret_result(self
):
118 super(IGTTest
, self
).interpret_result()
120 if self
.result
.returncode
== 0:
121 if not self
.result
.err
:
122 self
.result
.result
= 'pass'
124 self
.result
.result
= 'warn'
125 elif self
.result
.returncode
== 77:
126 self
.result
.result
= 'skip'
127 elif self
.result
.returncode
== 78:
128 self
.result
.result
= 'timeout'
129 elif self
.result
.returncode
== 139:
130 self
.result
.result
= 'crash'
132 self
.result
.result
= 'fail'
135 def list_tests(listname
):
136 """Parse igt test list and return them as a list."""
137 with
open(os
.path
.join(IGT_TEST_ROOT
, listname
), 'r') as f
:
138 lines
= (line
.rstrip() for line
in f
.readlines())
144 return line
.split(" ")
146 if "TESTLIST" in line
:
152 def add_subtest_cases(test
):
153 """Get subtest instances."""
155 out
= subprocess
.check_output(
156 [os
.path
.join(IGT_TEST_ROOT
, test
), '--list-subtests'],
157 env
=os
.environ
.copy(),
158 universal_newlines
=True)
159 except subprocess
.CalledProcessError
as e
:
160 # a return code of 79 indicates there are no subtests
161 if e
.returncode
== 79:
162 profile
.test_list
[grouptools
.join('igt', test
)] = IGTTest(test
)
163 elif e
.returncode
!= 0:
164 print("Error: Could not list subtests for " + test
)
168 # If we reach here there are no subtests.
171 for subtest
in (s
for s
in out
.splitlines() if s
):
172 profile
.test_list
[grouptools
.join('igt', test
, subtest
)] = \
173 IGTTest(test
, ['--run-subtest', subtest
])
176 def populate_profile():
178 for test_list
in TEST_LISTS
:
179 tests
.extend(list_tests(test_list
))
182 add_subtest_cases(test
)
186 profile
.options
['dmesg'] = dmesg
.get_dmesg(True)
187 profile
.options
['dmesg'].regex
= re
.compile(r
"(\[drm:|drm_|intel_|i915_)")