3 # Copyright © 2020-2021 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
26 import json
# type: ignore
29 from framework
import status
30 from framework
.replay
import backends
31 from framework
.replay
import query_traces_yaml
as qty
32 from framework
.replay
.backends
.apitrace
import APITraceBackend
33 from framework
.replay
.download_utils
import ensure_file
34 from framework
.replay
.options
import OPTIONS
36 __all__
= ['from_yaml',
40 def _replay(trace_path
):
43 frame_times
= APITraceBackend
.profile(trace_path
)
44 except (backends
.DumpBackendNotImplementedError
,
45 backends
.DumpBackendError
) as e
:
50 print("[frame_times] Trace {} couldn't be replayed. "
51 "See above logs for more information.".format(trace_path
))
57 def _run_trace(trace_path
):
58 ensure_file(trace_path
)
62 frame_times
= _replay(path
.join(OPTIONS
.db_path
, trace_path
))
63 if frame_times
is None:
64 print('[frame_times] error')
66 print(f
'[frame_times] {format(len(frame_times))}')
68 json_result
['images'] = [
69 {'image_desc': trace_path
,
70 'frame_times': frame_times
}]
72 if frame_times
is None:
73 return status
.CRASH
, json_result
75 return status
.PASS
, json_result
78 def _print_result(result
, trace_path
, json_result
):
80 json_result
['result'] = str(result
)
82 output
+= json
.dumps(json_result
)
86 def from_yaml(yaml_file
):
87 y
= qty
.load_yaml(yaml_file
)
89 OPTIONS
.set_download_url(qty
.download_url(y
))
91 global_result
= status
.PASS
92 # TODO: print in subtest format
94 t_list
= qty
.traces(y
, trace_extensions
=".trace", device_name
=OPTIONS
.device_name
)
96 result
, json_result
= _run_trace(t
['path'])
97 if result
is not status
.PASS
and global_result
is not status
.CRASH
:
98 global_result
= result
99 # json_results.update(json_result)
100 # _print_result(result, t['path'], json_result)
105 def trace(trace_path
):
106 result
, json_result
= _run_trace(trace_path
)
107 _print_result(result
, trace_path
, json_result
)