3 # Copyright (c) 2017 Intel Corporation
4 # Copyright © 2020 Valve Corporation.
5 # Copyright © 2021 Collabora Ltd.
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 # and/or sell copies of the Software, and to permit persons to whom the
12 # Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 # OTHER DEALINGS IN THE SOFTWARE.
25 # SPDX-License-Identifier: MIT
27 """A profile that runs PiglitReplayerTest instances from a YAML description
30 This profile requires some configuration in piglit.conf, or the use of
31 environment variables.
33 In piglit.conf one should set the following:
34 [replay]:subcommand -- Replay command to run.
35 [replay]:description_file -- Path to the replay description file.
36 [replay]:device_name -- Name of the device selected for the replay.
38 Alternatively (or in addition, since environment variables have precedence),
40 PIGLIT_REPLAY_SUBCOMMAND -- environment equivalent of [replay]:subcommand
41 PIGLIT_REPLAY_DESCRIPTION_FILE -- environment equivalent of [replay]:description_file
42 PIGLIT_REPLAY_DEVICE_NAME -- environment equivalent of [replay]:device_name
44 Optionally, in piglit.conf one could set also the following:
45 [replay]:extra_args -- Space-separated list of extra command line arguments for replayer.
46 [replay]:apitrace_bin -- Path to the apitrace executable.
47 [replay]:eglretrace_bin -- Path to the eglretrace (apitrace) executable.
48 [replay]:wine_bin -- Path to the Wine executable.
49 [replay]:wine_apitrace_bin -- Path to the Windows' apitrace executable to be run under Wine.
50 [replay]:wine_d3dretrace_bin -- Path to the Windows' d3dretrace (apitrace) executable to be run under Wine.
51 [replay]:gfxrecon-info_bin -- Path to the gfxrecon-info (GFXReconstruct) executable.
52 [replay]:gfxrecon-replay_bin -- Path to the gfxrecon-replay (GFXReconstruct) executable.
53 [replay]:gfxrecon-replay_extra_args -- Space-separated list of extra command line arguments for gfxrecon-replay.
54 [replay]:loop_times -- Number of times to replay the last frame in profile mode
56 Alternatively (or in addition, since environment variables have precedence),
58 PIGLIT_REPLAY_EXTRA_ARGS -- environment equivalent of [replay]:extra_args
59 PIGLIT_REPLAY_APITRACE_BINARY -- environment equivalent of [replay]:apitrace_bin
60 PIGLIT_REPLAY_EGLRETRACE_BINARY -- environment equivalent of [replay]:eglretrace_bin
61 PIGLIT_REPLAY_WINE_BINARY -- environment equivalent of [replay]:wine_bin
62 PIGLIT_REPLAY_WINE_APITRACE_BINARY -- environment equivalent of [replay]:wine_apitrace_bin
63 PIGLIT_REPLAY_WINE_D3DRETRACE_BINARY -- environment equivalent of [replay]:wine_d3dretrace_bin
64 PIGLIT_REPLAY_GFXRECON_INFO_BINARY -- environment equivalent of [replay]:gfxrecon-info_bin
65 PIGLIT_REPLAY_GFXRECON_REPLAY_BINARY -- environment equivalent of [replay]:gfxrecon-replay_bin
66 PIGLIT_REPLAY_GFXRECON_REPLAY_EXTRA_ARGS -- environment equivalent of [replay]:gfxrecon-replay_extra_args
67 PIGLIT_REPLAY_LOOP_TIMES -- environment equivalent of [replay]:loop_times
75 from framework
import core
, exceptions
, grouptools
, profile
, status
76 from framework
.replay
import query_traces_yaml
as qty
77 from framework
.test
.base
import DummyTest
78 from framework
.test
.piglit_test
import PiglitReplayerTest
82 _SUBCOMMAND
= core
.get_option('PIGLIT_REPLAY_SUBCOMMAND',
83 ('replay', 'subcommand'),
86 _DESCRIPTION_FILE
= core
.get_option('PIGLIT_REPLAY_DESCRIPTION_FILE',
87 ('replay', 'description_file'),
90 _DEVICE_NAME
= core
.get_option('PIGLIT_REPLAY_DEVICE_NAME',
91 ('replay', 'device_name'),
94 _EXTRA_ARGS
= core
.get_option('PIGLIT_REPLAY_EXTRA_ARGS',
95 ('replay', 'extra_args'),
98 class ReplayProfile(object):
100 def __init__(self
, subcommand
, filename
, device_name
):
102 with
open(filename
, 'r') as f
:
103 self
.yaml
= qty
.load_yaml(f
)
104 except FileNotFoundError
:
105 raise exceptions
.PiglitFatalError(
106 'Cannot open "{}"'.format(filename
))
108 self
.subcommand
= subcommand
109 self
.device_name
= device_name
110 self
.extra_args
= ['--device-name', device_name
,
111 '--download-url', qty
.download_url(self
.yaml
)] \
113 self
.forced_test_list
= []
114 self
.filters
= profile
.Filters()
116 'dmesg': profile
.get_dmesg(False),
117 'monitor': profile
.Monitoring(False),
118 'ignore_missing': False,
122 if not (self
.filters
or self
.forced_test_list
):
123 return sum(1 for _
in qty
.traces(self
.yaml
, device_name
=self
.device_name
))
124 return sum(1 for _
in self
.itertests())
127 """This hook sets the PiglitReplayerTest.results_path variable.
129 Setting this variable allows the files created by PiglitReplayerTest to
130 be placed into the results directory.
132 PiglitReplayerTest
.RESULTS_PATH
= self
.results_dir
137 def _itertests(self
):
138 """Always iterates tests instead of using the forced test_list."""
140 # When profiling, only run apitrace traces
141 trace_extensions
= ".trace" if self
.subcommand
== 'profile' else None
142 for t
in qty
.traces(self
.yaml
, trace_extensions
=trace_extensions
, device_name
=self
.device_name
, checksum
=True):
143 group_path
= path
.join('trace', self
.device_name
, t
['path'])
144 k
= grouptools
.from_path(group_path
)
145 trace_extra_args
= [t
['path']]
146 if self
.subcommand
== 'compare':
147 trace_extra_args
.append(t
['checksum'])
148 v
= PiglitReplayerTest(self
.subcommand
, self
.extra_args
+ trace_extra_args
)
151 for k
, v
in self
.filters
.run(_iter()):
155 if self
.forced_test_list
:
156 alltests
= dict(self
._itertests
())
157 opts
= collections
.OrderedDict()
158 for n
in self
.forced_test_list
:
159 if self
.options
['ignore_missing'] and n
not in alltests
:
160 opts
[n
] = DummyTest(n
, status
.NOTRUN
)
162 opts
[n
] = alltests
[n
]
165 return iter(self
._itertests
())
168 profile
= ReplayProfile(_SUBCOMMAND
, _DESCRIPTION_FILE
, _DEVICE_NAME
)