3 # Copyright (c) 2014, 2019 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.
36 import os.path as path
40 def setup_module_search_path():
41 """Add Piglit's data directory to Python's module search path.
43 This enables Python to import Piglit's framework module.
45 CAUTION: This script must import the framework that *belongs to this
46 script*. Mayhem occurs if this script accidentally imports a framework
47 module that belongs to a different Piglit source tree or belongs to
48 a different Piglit installation.
50 CAUTION: This script file must be located in the Piglit source tree or in
51 an installed location. Otherwise this function may fail to find the
52 framework module or, worse, it may succeed in finding a different Piglit's
56 # To avoid accidentally importing a framework module that belongs to
57 # a different Piglit, base the search for Piglit's data directory on the
58 # absolute path of the this script and *not* on the process's working
60 abs_script_dir = path.abspath(path.dirname(path.realpath(__file__)))
62 tested_piglit_data_dirs = []
64 def is_piglit_data_dir(dirpath):
65 tested_piglit_data_dirs.append(dirpath)
66 return path.exists(path.join(dirpath, 'framework'))
68 # This script may be in two valid locations:
70 # - At the top of a Piglit source tree, as below. In this case, Piglit's
71 # data directory is the source directory itself.
73 # ${piglit_source_dir}/${script_name} -> This script.
74 # ${piglit_source_dir}/ -> Piglit's data directory.
75 # ${piglit_source_dir}/framework -> Piglit's framework module
77 if is_piglit_data_dir(abs_script_dir):
78 sys.path.append(abs_script_dir)
83 # - In an installed location. Piglit's installation layout looks like
84 # this, where ${ext} may be empty or ".py":
86 # ${prefix}/${bindir}/${script_name}${ext} -> This script.
87 # ${prefix}/${libdir}/${script_name}/ -> Piglit's data directory.
88 # ${prefix}/${libdir}/${script_name}/framework -> Piglit framework module.
90 abs_bindir = abs_script_dir
91 script_basename_noext = os.path.splitext(os.path.basename(__file__))[0]
92 for libdir in ('lib64', 'lib32', 'lib'):
93 abs_libdir = path.normpath(path.join(abs_bindir, '..', libdir))
94 abs_data_dir = path.join(abs_libdir, script_basename_noext)
95 if is_piglit_data_dir(abs_data_dir):
96 sys.path.insert(0, abs_data_dir)
99 print('error: failed to find piglit data directory. exiting...', file=sys.stderr)
100 for test_dir in tested_piglit_data_dirs:
101 print('error: tested directory {0!r}'.format(test_dir), file=sys.stderr)
105 setup_module_search_path()
106 import framework.programs.run as run
107 import framework.programs.summary as summary
108 import framework.programs.print_commands as pc
112 """ Parse argument and call other executables """
113 input_ = sys.argv[1:]
115 parser = argparse.ArgumentParser()
116 subparsers = parser.add_subparsers()
117 print_cmd = subparsers.add_parser('print-cmd',
119 help="Print piglit commands, one per line.")
120 print_cmd.set_defaults(func=pc.main)
122 parse_run = subparsers.add_parser('run',
124 help="Run a piglit test")
125 parse_run.set_defaults(func=run.run)
126 resume = subparsers.add_parser('resume',
128 help="resume an interrupted piglit run")
129 resume.set_defaults(func=run.resume)
130 parse_summary = subparsers.add_parser('summary', help='summary generators')
131 summary_parser = parse_summary.add_subparsers()
132 html = summary_parser.add_parser('html',
134 help='generate html reports from results')
135 html.set_defaults(func=summary.html)
136 console = summary_parser.add_parser('console',
138 help='print results to terminal')
139 console.set_defaults(func=summary.console)
140 csv = summary_parser.add_parser('csv',
142 help='generate csv from results')
143 csv.set_defaults(func=summary.csv)
144 formatted = summary_parser.add_parser('formatted',
146 help='generate formatted output from results')
147 formatted.set_defaults(func=summary.formatted)
148 aggregate = summary_parser.add_parser('aggregate',
150 help="Aggregate incomplete piglit run.")
151 aggregate.set_defaults(func=summary.aggregate)
152 feature = summary_parser.add_parser('feature',
154 help="generate feature readiness html report.")
155 feature.set_defaults(func=summary.feature)
157 # Parse the known arguments (piglit run or piglit summary html for
158 # example), and then pass the arguments that this parser doesn't know about
160 parsed, args = parser.parse_known_args(input_)
163 except AttributeError:
166 sys.exit(runner(args))
169 if __name__ == '__main__':