cl: Fix missing OpenCL 3.0 definition
[piglit.git] / framework / replay / query_traces_yaml.py
blob4338af6bab56367943329376973a77519e362127
1 # coding=utf-8
3 # Copyright © 2019, 2022 Collabora Ltd
4 # Copyright © 2020 Valve Corporation.
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 # OR 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
20 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 # OTHER DEALINGS IN THE SOFTWARE.
24 # SPDX-License-Identifier: MIT
27 from os import path
28 from typing import Any, Generator, Optional, Union
30 import yaml
32 from framework import exceptions
34 __all__ = ['download_url',
35 'load_yaml',
36 'trace_checksum',
37 'traces']
40 def load_yaml(y):
41 try:
42 return yaml.safe_load(y) or {}
43 except yaml.YAMLError:
44 raise exceptions.PiglitFatalError(
45 'Cannot use the provided stream. Is it YAML?')
48 def trace_checksum(trace: Any, device_name: Optional[str]) -> str:
49 '''returns checksum of trace'''
50 try:
51 data = trace[device_name]
52 for item, val in data.items():
53 if item == "checksum":
54 return val
55 return ''
57 except StopIteration:
58 return ''
59 except KeyError:
60 return ''
63 def download_url(y):
64 try:
65 return y['traces-db']['download-url'] if 'traces-db' in y else None
66 except KeyError:
67 return None
70 def traces(
71 y: Any,
72 trace_extensions: Optional[str] = None,
73 device_name: Optional[str] = None,
74 checksum: Union[str, bool] = False
75 ) -> Generator[dict, None, None]:
77 def _trace_extension(trace_path: str) -> str:
78 name, extension = path.splitext(trace_path)
80 return extension
81 traces = y.get('traces', {}) or {}
83 if trace_extensions is not None:
84 extensions = trace_extensions.split(',')
86 def _filter_trace_extension(trace: str) -> bool:
87 try:
88 return _trace_extension(trace) in extensions
89 except KeyError:
90 return False
92 traces = {t: data for t, data in traces.items() if _filter_trace_extension(t)}
94 for trace_file, devdata in traces.items():
95 for dev, properties in devdata.items():
96 if device_name and (device_name != dev):
97 continue
98 if (
99 properties
100 and "label" in properties
101 and isinstance(properties["label"], list)
102 and {"skip", "hang", "crash", "fail", "unsupported"}.intersection(properties["label"])
104 continue
106 found_trace = {"path": trace_file}
107 if not checksum:
108 yield found_trace
109 break
111 try:
112 found_trace["checksum"] = trace_checksum(devdata, device_name)
113 yield found_trace
114 except KeyError:
115 yield {}