cl: Fix missing OpenCL 3.0 definition
[piglit.git] / replayer / replayer.py
blob87ec9cc15fde336542f0ad3628f4ee131eba5510
1 #!/usr/bin/env python3
2 # coding=utf-8
4 # Copyright (c) 2014, 2019 Intel Corporation
5 # Copyright © 2020 Valve Corporation.
6 # Copyright © 2021 Collabora Ltd.
8 # Permission is hereby granted, free of charge, to any person
9 # obtaining a copy of this software and associated documentation
10 # files (the "Software"), to deal in the Software without
11 # restriction, including without limitation the rights to use,
12 # copy, modify, merge, publish, distribute, sublicense, and/or
13 # sell copies of the Software, and to permit persons to whom the
14 # Software is furnished to do so, subject to the following
15 # conditions:
17 # This permission notice shall be included in all copies or
18 # substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
21 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
22 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE
24 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 # DEALINGS IN THE SOFTWARE.
29 # SPDX-License-Identifier: MIT
32 """ Wrapper for replayer executable
34 This imports functions from the replay framework and calls them with the
35 argument parts that the parser defined here doesn't know how to parse.
37 It is very important that the final parser not generate a help message
38 (add_help=False in the constructor arguments), otherwise this parser will
39 capture -h/--help and the results will not be useful.
41 """
43 import argparse
44 import os
45 import os.path as path
46 import sys
49 def setup_module_search_path():
50 """Add Piglit's data directory to Python's module search path.
52 This enables Python to import Piglit's framework module.
54 CAUTION: This script must import the framework that *belongs to this
55 script*. Mayhem occurs if this script accidentally imports a framework
56 module that belongs to a different Piglit source tree or belongs to
57 a different Piglit installation.
59 CAUTION: This script file must be located in the Piglit source tree or in
60 an installed location. Otherwise this function may fail to find the
61 framework module or, worse, it may succeed in finding a different Piglit's
62 framework module.
63 """
65 piglit_data_dir = os.environ.get('PIGLIT_SOURCE_DIR', None)
66 if piglit_data_dir is None:
67 print('error: the PIGLIT_SOURCE_DIR env variable is not set. '
68 'exiting ...', file=sys.stderr)
69 sys.exit(1)
71 if path.exists(path.join(piglit_data_dir, 'framework')):
72 sys.path.append(piglit_data_dir)
73 return
75 print('error: failed to find piglit data directory. '
76 'exiting...',file=sys.stderr)
77 sys.exit(1)
80 setup_module_search_path()
81 from framework import status
82 import framework.replay.programs.compare as compare
83 import framework.replay.programs.query as query
84 import framework.replay.programs.download as download
85 import framework.replay.programs.checksum as checksum
86 import framework.replay.programs.dump as dump
87 import framework.replay.programs.profile as profile
90 def main():
91 """ Parse argument and call other executables """
92 input_ = sys.argv[1:]
94 parser = argparse.ArgumentParser()
96 # Add a destination due to
97 # https://github.com/python/cpython/pull/3027#issuecomment-330910633
98 subparsers = parser.add_subparsers(dest='command', required=True)
100 parser_checksum = subparsers.add_parser(
101 'checksum',
102 add_help=False,
103 help=('Calculates the checksums of a local image file.'))
104 parser_checksum.set_defaults(func=checksum.checksum)
106 parser_compare = subparsers.add_parser(
107 'compare',
108 add_help=False,
109 help=('Trace replay compare methods.'))
110 parser_compare.set_defaults(func=compare.compare)
112 parser_download = subparsers.add_parser(
113 'download',
114 add_help=False,
115 help=('Downloads a remote file into the db path.'))
116 parser_download.set_defaults(func=download.download)
118 parser_dump = subparsers.add_parser(
119 'dump',
120 add_help=False,
121 help=('Dumps image(s) from a trace file.'))
122 parser_dump.set_defaults(func=dump.dump)
124 parser_query = subparsers.add_parser(
125 'query',
126 add_help=False,
127 help=('Queries for specific information '
128 'from a traces description file listing traces '
129 'and their checksums for each device.'))
130 parser_query.set_defaults(func=query.query)
132 parser_profile = subparsers.add_parser(
133 'profile',
134 add_help=False,
135 help=('Measure frame times of a trace file.'))
136 parser_profile.set_defaults(func=profile.profile)
138 # Parse the known arguments (replayer compare or replayer query for
139 # example), and then pass the arguments that this parser doesn't know about
140 # to that executable
141 parsed, args = parser.parse_known_args(input_)
142 try:
143 runner = parsed.func
144 except AttributeError:
145 parser.print_help()
146 sys.exit(1)
148 result = runner(args)
149 if result is not status.PASS:
150 sys.exit(1 if result is status.CRASH else 2)
153 if __name__ == '__main__':
154 main()