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 konw 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 print_function
37 import os.path as path
41 def setup_module_search_path():
42 """Add Piglit's data directory to Python's module search path.
44 This enables Python to import Piglit's framework module.
46 CAUTION: This script must import the framework that *belongs to this
47 script*. Mayhem occurs if this script accidentally imports a framework
48 module that belongs to a different Piglit source tree or belongs to
49 a different Piglit installation.
51 CAUTION: This script file must be located in the Piglit source tree or in
52 an installed location. Otherwise this function may fail to find the
53 framework module or, worse, it may succeed in finding a different Piglit's
57 # To avoid accidentally importing a framework module that belongs to
58 # a different Piglit, base the search for Piglit's data directory on the
59 # absolute path of the this script and *not* on the process's working
61 abs_script_dir = os.path.abspath(os.path.dirname(__file__))
63 tested_piglit_data_dirs = []
65 def is_piglit_data_dir(dirpath):
66 tested_piglit_data_dirs.append(dirpath)
67 return path.exists(path.join(dirpath, 'framework'))
69 # This script may be in two valid locations:
71 # - At the top of a Piglit source tree, as below. In this case, Piglit's
72 # data directory is the source directory itself.
74 # ${piglit_source_dir}/${script_name} -> This script.
75 # ${piglit_source_dir}/ -> Piglit's data directory.
76 # ${piglit_source_dir}/framework -> Piglit's framework module
78 if is_piglit_data_dir(abs_script_dir):
79 sys.path.append(abs_script_dir)
84 # - In an installed location. Piglit's installation layout looks like
85 # this, where ${ext} may be empty or ".py":
87 # ${prefix}/${bindir}/${script_name}${ext} -> This script.
88 # ${prefix}/${libdir}/${script_name}/ -> Piglit's data directory.
89 # ${prefix}/${libdir}/${script_name}/framework -> Piglit framework module.
91 abs_bindir = abs_script_dir
92 script_basename_noext = os.path.splitext(os.path.basename(__file__))[0]
93 for libdir in ('lib64', 'lib32', 'lib'):
94 abs_libdir = path.normpath(path.join(abs_bindir, '..', libdir))
95 abs_data_dir = path.join(abs_libdir, script_basename_noext)
96 if is_piglit_data_dir(abs_data_dir):
97 sys.path.insert(0, abs_data_dir)
100 print('error: failed to find piglit data directory. exiting...', file=sys.stderr)
101 for test_dir in tested_piglit_data_dirs:
102 print('error: tested directory {0!r}'.format(test_dir), file=sys.stderr)
106 setup_module_search_path()
107 import framework.programs.run as run
108 import framework.programs.summary as summary
112 """ Parse argument and call other executables """
113 parser = argparse.ArgumentParser()
114 subparsers = parser.add_subparsers()
116 parse_run = subparsers.add_parser('run',
118 help="Run a piglit test")
119 parse_run.set_defaults(func=run.run)
120 resume = subparsers.add_parser('resume',
122 help="resume an interrupted piglit run")
123 resume.set_defaults(func=run.resume)
124 parse_summary = subparsers.add_parser('summary', help='summary generators')
125 summary_parser = parse_summary.add_subparsers()
126 html = summary_parser.add_parser('html',
128 help='generate html reports from results')
129 html.set_defaults(func=summary.html)
130 console = summary_parser.add_parser('console',
132 help='print results to terminal')
133 console.set_defaults(func=summary.console)
134 csv = summary_parser.add_parser('csv',
136 help='generate csv from results')
137 csv.set_defaults(func=summary.csv)
138 aggregate = summary_parser.add_parser('aggregate',
140 help="Aggregate incomplete piglit run.")
141 aggregate.set_defaults(func=summary.aggregate)
143 # Parse the known arguments (piglit run or piglit summary html for
144 # example), and then pass the arguments that this parser doesn't know about
146 parsed, args = parser.parse_known_args()
147 returncode = parsed.func(args)
151 if __name__ == '__main__':