3 # Copyright (c) 2020 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
32 from framework
import core
, status
33 from framework
.replay
import backends
34 from framework
.replay
import query_traces_yaml
as qty
35 from framework
.replay
.download_utils
import ensure_file
36 from framework
.replay
.image_checksum
import hexdigest_from_image
37 from framework
.replay
.options
import OPTIONS
39 __all__
= ['from_yaml',
43 def _replay(trace_path
, results_path
):
45 success
= backends
.dump(trace_path
, results_path
, [])
46 except (backends
.DumpBackendNotImplementedError
,
47 backends
.DumpBackendError
) as e
:
52 print("[check_image] Trace {} couldn't be replayed. "
53 "See above logs for more information.".format(trace_path
))
56 file_name
= path
.basename(trace_path
)
57 files
= glob(path
.join(results_path
, file_name
+ '-*' + '.png'))
59 print('[check_image] No dumped files found '
60 'in the results path "{}". '
61 'See above logs for more information.'.format(results_path
))
64 return hexdigest_from_image(image_file
), image_file
67 def _check_trace(trace_path
, expected_checksum
):
68 ensure_file(trace_path
)
72 trace_dir
= path
.dirname(trace_path
)
73 dir_in_results
= path
.join('trace', OPTIONS
.device_name
or '', trace_dir
)
74 results_path
= path
.join(OPTIONS
.results_path
, dir_in_results
)
75 core
.check_dir(results_path
)
77 checksum
, image_file
= _replay(path
.join(OPTIONS
.db_path
, trace_path
),
80 print('[check_image]\n'
82 ' expected: {}'.format(checksum
or 'error', expected_checksum
))
84 json_result
['images'] = [
85 {'image_desc': trace_path
,
86 'checksum_ref': expected_checksum
,
87 'checksum_render': None,
88 'image_ref': expected_checksum
+ '.png',
89 'image_render': None}]
92 return status
.CRASH
, json_result
94 json_result
['images'][0]['checksum_render'] = checksum
95 json_result
['images'][0]['image_render'] = checksum
+ '.png'
97 if checksum
== expected_checksum
:
98 if not OPTIONS
.keep_image
:
100 print('[check_image] Images match for:\n {}\n'.format(trace_path
))
103 print('[check_image] Images differ for:\n {}'.format(trace_path
))
104 print('[check_image] For more information see '
105 'https://gitlab.freedesktop.org/'
106 'mesa/piglit/blob/master/replayer/README.md\n')
109 if result
is not status
.PASS
or OPTIONS
.keep_image
:
110 root
, ext
= path
.splitext(image_file
)
111 image_file_dest
= '{}-{}{}'.format(root
, checksum
, ext
)
112 shutil
.move(image_file
, image_file_dest
)
113 json_result
['images'][0]['image_render'] = image_file_dest
115 return result
, json_result
118 def _print_result(result
, trace_path
, json_result
):
120 json_result
['result'] = str(result
)
122 output
+= json
.dumps(json_result
)
126 def from_yaml(yaml_file
):
127 y
= qty
.load_yaml(yaml_file
)
129 OPTIONS
.set_download_url(qty
.download_url(y
))
131 global_result
= status
.PASS
132 # TODO: print in subtest format
134 t_list
= qty
.traces(y
, device_name
=OPTIONS
.device_name
, checksum
=True)
136 result
, json_result
= _check_trace(t
['path'], t
['checksum'])
137 if result
is not status
.PASS
and global_result
is not status
.CRASH
:
138 global_result
= result
139 # json_results.update(json_result)
140 # _print_result(result, t['path'], json_result)
145 def trace(trace_path
, expected_checksum
):
146 result
, json_result
= _check_trace(trace_path
, expected_checksum
)
147 _print_result(result
, trace_path
, json_result
)