3 # Copyright (c) 2014 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 """ Wrapper for piglit executables
25 This imports functions from the framework and calls them with the argument
26 parts that the parser defined here doesn't know how to parse.
28 It is very important that the final parser not generate a help message
29 (add_help=False in the constructor arguments), otherwise this parser will
30 capture -h/--help and the results will not be useful.
34 from __future__ import (
35 absolute_import, division, print_function, unicode_literals
39 import os.path as path
45 def setup_module_search_path():
46 """Add Piglit's data directory to Python's module search path.
48 This enables Python to import Piglit's framework module.
50 CAUTION: This script must import the framework that *belongs to this
51 script*. Mayhem occurs if this script accidentally imports a framework
52 module that belongs to a different Piglit source tree or belongs to
53 a different Piglit installation.
55 CAUTION: This script file must be located in the Piglit source tree or in
56 an installed location. Otherwise this function may fail to find the
57 framework module or, worse, it may succeed in finding a different Piglit's
61 # To avoid accidentally importing a framework module that belongs to
62 # a different Piglit, base the search for Piglit's data directory on the
63 # absolute path of the this script and *not* on the process's working
65 abs_script_dir = os.path.abspath(os.path.dirname(__file__))
67 tested_piglit_data_dirs = []
69 def is_piglit_data_dir(dirpath):
70 tested_piglit_data_dirs.append(dirpath)
71 return path.exists(path.join(dirpath, 'framework'))
73 # This script may be in two valid locations:
75 # - At the top of a Piglit source tree, as below. In this case, Piglit's
76 # data directory is the source directory itself.
78 # ${piglit_source_dir}/${script_name} -> This script.
79 # ${piglit_source_dir}/ -> Piglit's data directory.
80 # ${piglit_source_dir}/framework -> Piglit's framework module
82 if is_piglit_data_dir(abs_script_dir):
83 sys.path.append(abs_script_dir)
88 # - In an installed location. Piglit's installation layout looks like
89 # this, where ${ext} may be empty or ".py":
91 # ${prefix}/${bindir}/${script_name}${ext} -> This script.
92 # ${prefix}/${libdir}/${script_name}/ -> Piglit's data directory.
93 # ${prefix}/${libdir}/${script_name}/framework -> Piglit framework module.
95 abs_bindir = abs_script_dir
96 script_basename_noext = os.path.splitext(os.path.basename(__file__))[0]
97 for libdir in ('lib64', 'lib32', 'lib'):
98 abs_libdir = path.normpath(path.join(abs_bindir, '..', libdir))
99 abs_data_dir = path.join(abs_libdir, script_basename_noext)
100 if is_piglit_data_dir(abs_data_dir):
101 sys.path.insert(0, abs_data_dir)
104 print('error: failed to find piglit data directory. exiting...', file=sys.stderr)
105 for test_dir in tested_piglit_data_dirs:
106 print('error: tested directory {0!r}'.format(test_dir), file=sys.stderr)
110 setup_module_search_path()
111 import framework.programs.run as run
112 import framework.programs.summary as summary
113 import framework.programs.print_commands as pc
117 """ Parse argument and call other executables """
119 input_ = [i.decode('utf-8') for i in sys.argv[1:]]
121 input_ = sys.argv[1:]
123 parser = argparse.ArgumentParser()
124 subparsers = parser.add_subparsers()
125 print_cmd = subparsers.add_parser('print-cmd',
127 help="Print piglit commands, one per line.")
128 print_cmd.set_defaults(func=pc.main)
130 parse_run = subparsers.add_parser('run',
132 help="Run a piglit test")
133 parse_run.set_defaults(func=run.run)
134 resume = subparsers.add_parser('resume',
136 help="resume an interrupted piglit run")
137 resume.set_defaults(func=run.resume)
138 parse_summary = subparsers.add_parser('summary', help='summary generators')
139 summary_parser = parse_summary.add_subparsers()
140 html = summary_parser.add_parser('html',
142 help='generate html reports from results')
143 html.set_defaults(func=summary.html)
144 console = summary_parser.add_parser('console',
146 help='print results to terminal')
147 console.set_defaults(func=summary.console)
148 csv = summary_parser.add_parser('csv',
150 help='generate csv from results')
151 csv.set_defaults(func=summary.csv)
152 aggregate = summary_parser.add_parser('aggregate',
154 help="Aggregate incomplete piglit run.")
155 aggregate.set_defaults(func=summary.aggregate)
156 feature = summary_parser.add_parser('feature',
158 help="generate feature readiness html report.")
159 feature.set_defaults(func=summary.feature)
161 # Parse the known arguments (piglit run or piglit summary html for
162 # example), and then pass the arguments that this parser doesn't know about
164 parsed, args = parser.parse_known_args(input_)
167 except AttributeError:
170 sys.exit(runner(args))
173 if __name__ == '__main__':