cl: Fix missing OpenCL 3.0 definition
[piglit.git] / framework / replay / compare_replay.py
blob3245075ffd711646fb73a1cab654a48f2e26a2bf
1 # coding=utf-8
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
27 import os
28 import shutil
29 from glob import glob
30 from os import path
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',
40 'trace']
43 def _replay(trace_path, results_path):
44 try:
45 success = backends.dump(trace_path, results_path, [])
46 except (backends.DumpBackendNotImplementedError,
47 backends.DumpBackendError) as e:
48 print(e)
49 success = False
51 if not success:
52 print("[check_image] Trace {} couldn't be replayed. "
53 "See above logs for more information.".format(trace_path))
54 return None, None
55 else:
56 file_name = path.basename(trace_path)
57 files = glob(path.join(results_path, file_name + '-*' + '.png'))
58 if not files:
59 print('[check_image] No dumped files found '
60 'in the results path "{}". '
61 'See above logs for more information.'.format(results_path))
62 return None, None
63 image_file = files[0]
64 return hexdigest_from_image(image_file), image_file
67 def _check_trace(trace_path, expected_checksum):
68 ensure_file(trace_path)
70 json_result = {}
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),
78 results_path)
80 print('[check_image]\n'
81 ' actual: {}\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}]
91 if checksum is 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:
99 os.remove(image_file)
100 print('[check_image] Images match for:\n {}\n'.format(trace_path))
101 result = status.PASS
102 else:
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')
107 result = status.FAIL
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):
119 output = 'PIGLIT: '
120 json_result['result'] = str(result)
122 output += json.dumps(json_result)
123 print(output)
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
133 # json_results = {}
134 t_list = qty.traces(y, device_name=OPTIONS.device_name, checksum=True)
135 for t in t_list:
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)
142 return global_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)
149 return result