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
28 from typing
import Any
, Generator
, Optional
, Union
32 from framework
import exceptions
34 __all__
= ['download_url',
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'''
51 data
= trace
[device_name
]
52 for item
, val
in data
.items():
53 if item
== "checksum":
65 return y
['traces-db']['download-url'] if 'traces-db' in y
else None
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
)
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:
88 return _trace_extension(trace
) in extensions
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
):
100 and "label" in properties
101 and isinstance(properties
["label"], list)
102 and {"skip", "hang", "crash", "fail", "unsupported"}.intersection(properties
["label"])
106 found_trace
= {"path": trace_file
}
112 found_trace
["checksum"] = trace_checksum(devdata
, device_name
)