piglit 4.58 KB
Newer Older
1
#!/usr/bin/env python2
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

# Copyright (c) 2014 Intel Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

""" Wrapper for piglit executables

This imports functions from the framework and calls them with the argument
parts that the parser defined here doesn't konw how to parse.

It is very important that the final parser not generate a help message
(add_help=False in the constructor arguments), otherwise this parser will
capture -h/--help and the results will not be useful.

"""

import os
import os.path as path
import sys
import argparse

39 40
# Setting sys.path is actually pretty complicated, since there are three
# seperate uses we need to detect:
41 42 43 44 45
# 1) piglit is being run in the source directory, built in tree
# 2) piglit is being run from the source directory outside of it, built in tree
# 3) piglit has been built out of tree and installed, and is being run in or
#    out of the install directory

46 47 48
# Case one is the implicit case. In this event nothing needs to be set, it
# should "just work" (tm)

49 50 51 52
# It is critical that this block be run before importing anything from
# framework (as there is no gaurantee that framework will be in python's path
# before this blck is run)

53
if not path.exists('framework/exectest.py'):
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    dirpath = path.dirname(path.abspath(__file__))
    # Case 2
    if path.exists(path.join(dirpath, 'framework/exectest.py')):
        sys.path.append(dirpath)
    # Case 3
    else:
        # In the case of windows piglit is called
        # piglit${the_date_of_install}.py, and the .py needs to be thrown away
        piglit = path.splitext(path.basename(__file__))[0]

        # In the install case we have another problem, one could have multiple
        # piglits installed as piglit${the_date_of_install}, and we need to
        # detect that.
        install_path = path.abspath(path.join(dirpath, '..', 'lib', piglit))
        sys.path.append(install_path)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

import framework.programs.run as run
import framework.programs.summary as summary


def main():
    """ Parse argument and call other executables """
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers()

    parse_run = subparsers.add_parser('run',
                                      add_help=False,
                                      help="Run a piglit test")
    parse_run.set_defaults(func=run.run)
    resume = subparsers.add_parser('resume',
                                   add_help=False,
                                   help="resume an interrupted piglit run")
    resume.set_defaults(func=run.resume)
    parse_summary = subparsers.add_parser('summary', help='summary generators')
    summary_parser = parse_summary.add_subparsers()
    html = summary_parser.add_parser('html',
                                     add_help=False,
                                     help='generate html reports from results')
    html.set_defaults(func=summary.html)
    console = summary_parser.add_parser('console',
                                        add_help=False,
                                        help='print results to terminal')
    console.set_defaults(func=summary.console)
    junit = summary_parser.add_parser('junit',
                                      add_help=False,
                                      help='generate junit xml from results')
    junit.set_defaults(func=summary.junit)

    # Parse the known arguments (piglit run or piglit summary html for
    # example), and then pass the arguments that this parser doesn't know about
    # to that executable
    parsed, args = parser.parse_known_args()
    returncode = parsed.func(args)
    sys.exit(returncode)


if __name__ == '__main__':
    main()