piglit-run.py 6.9 KB
Newer Older
1
#!/usr/bin/env python
Nicolai Hähnle's avatar
Nicolai Hähnle committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#
# 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:
#
# 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
18
# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) BE
Nicolai Hähnle's avatar
Nicolai Hähnle committed
19 20 21 22 23 24
# 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.


Dylan Baker's avatar
Dylan Baker committed
25
import argparse
Dylan Baker's avatar
Dylan Baker committed
26 27
import sys
import os
28 29 30
import os.path as path
import time
import traceback
31
import json
Nicolai Hähnle's avatar
Nicolai Hähnle committed
32

33
sys.path.append(path.dirname(path.realpath(sys.argv[0])))
Nicolai Hähnle's avatar
Nicolai Hähnle committed
34
import framework.core as core
35 36
from framework.threads import synchronized_self

Nicolai Hähnle's avatar
Nicolai Hähnle committed
37 38

def main():
Dylan Baker's avatar
Dylan Baker committed
39 40 41 42 43
    parser = argparse.ArgumentParser(sys.argv)
    # Either require that a name for the test is passed or that
    # resume is requested
    excGroup1 = parser.add_mutually_exclusive_group()
    excGroup1.add_argument("-n", "--name",
Dylan Baker's avatar
Dylan Baker committed
44 45 46
                           metavar="<test name>",
                           default=None,
                           help="Name of this test run")
Dylan Baker's avatar
Dylan Baker committed
47
    excGroup1.add_argument("-r", "--resume",
Dylan Baker's avatar
Dylan Baker committed
48 49
                           action="store_true",
                           help="Resume an interupted test run")
Dylan Baker's avatar
Dylan Baker committed
50 51
    # Setting the --dry-run flag is equivalent to env.execute=false
    parser.add_argument("-d", "--dry-run",
Dylan Baker's avatar
Dylan Baker committed
52 53 54
                        action="store_false",
                        dest="execute",
                        help="Do not execute the tests")
Dylan Baker's avatar
Dylan Baker committed
55
    parser.add_argument("-t", "--include-tests",
56 57 58 59 60
                        default=[],
                        action="append",
                        metavar="<regex>",
                        help="Run only matching tests "
                             "(can be used more than once)")
Dylan Baker's avatar
Dylan Baker committed
61
    parser.add_argument("-x", "--exclude-tests",
62 63 64 65 66
                        default=[],
                        action="append",
                        metavar="<regex>",
                        help="Exclude matching tests "
                             "(can be used more than once)")
67
    parser.add_argument("-1", "--no-concurrency",
68 69 70
                        action="store_false",
                        dest="concurrency",
                        help="Disable concurrent test runs")
Dylan Baker's avatar
Dylan Baker committed
71
    parser.add_argument("-p", "--platform",
Dylan Baker's avatar
Dylan Baker committed
72 73
                        choices=["glx", "x11_egl", "wayland", "gbm"],
                        help="Name of windows system passed to waffle")
Dylan Baker's avatar
Dylan Baker committed
74
    parser.add_argument("--valgrind",
Dylan Baker's avatar
Dylan Baker committed
75 76
                        action="store_true",
                        help="Run tests in valgrind's memcheck")
77 78
    parser.add_argument("--dmesg",
                        action="store_true",
79 80
                        help="Capture a difference in dmesg before and "
                             "after each test")
Dylan Baker's avatar
Dylan Baker committed
81
    parser.add_argument("testProfile",
Dylan Baker's avatar
Dylan Baker committed
82 83
                        metavar="<Path to test profile>",
                        help="Path to testfile to run")
Dylan Baker's avatar
Dylan Baker committed
84
    parser.add_argument("resultsPath",
Dylan Baker's avatar
Dylan Baker committed
85 86
                        metavar="<Results Path>",
                        help="Path to results folder")
Dylan Baker's avatar
Dylan Baker committed
87 88 89 90 91 92
    args = parser.parse_args()

    # Set the platform to pass to waffle
    if args.platform is not None:
        os.environ['PIGLIT_PLATFORM'] = args.platform

93 94 95
    # Always Convert Results Path from Relative path to Actual Path.
    resultsDir = path.realpath(args.resultsPath)

Dylan Baker's avatar
Dylan Baker committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    # If resume is requested attempt to load the results file
    # in the specified path
    if args.resume is True:
        # Load settings from the old results JSON
        old_results = core.loadTestResults(resultsDir)
        profileFilename = old_results.options['profile']

        # Changing the args to the old args allows us to set them
        # all in one places down the way
        args.exclude_tests = old_results.options['exclude_filter']
        args.include_tests = old_results.options['filter']

    # Otherwise parse additional settings from the command line
    else:
        profileFilename = args.testProfile

    # Pass arguments into Environment
    env = core.Environment(concurrent=args.concurrency,
Dylan Baker's avatar
Dylan Baker committed
114 115 116
                           exclude_filter=args.exclude_tests,
                           include_filter=args.include_tests,
                           execute=args.execute,
117 118
                           valgrind=args.valgrind,
                           dmesg=args.dmesg)
Dylan Baker's avatar
Dylan Baker committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

    # Change working directory to the root of the piglit directory
    piglit_dir = path.dirname(path.realpath(sys.argv[0]))
    os.chdir(piglit_dir)

    core.checkDir(resultsDir, False)

    results = core.TestrunResult()

    # Set results.name
    if args.name is not None:
        results.name = args.name
    else:
        results.name = path.basename(resultsDir)

    # Begin json.
    result_filepath = os.path.join(resultsDir, 'main')
    result_file = open(result_filepath, 'w')
    json_writer = core.JSONWriter(result_file)
    json_writer.open_dict()

    # Write out command line options for use in resuming.
    json_writer.write_dict_key('options')
    json_writer.open_dict()
    json_writer.write_dict_item('profile', profileFilename)
144 145
    json_writer.write_dict_item('filter', args.include_tests)
    json_writer.write_dict_item('exclude_filter', args.exclude_tests)
Dylan Baker's avatar
Dylan Baker committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
    json_writer.close_dict()

    json_writer.write_dict_item('name', results.name)
    for (key, value) in env.collectData().items():
        json_writer.write_dict_item(key, value)

    profile = core.loadTestProfile(profileFilename)

    json_writer.write_dict_key('tests')
    json_writer.open_dict()
    # If resuming an interrupted test run, re-write all of the existing
    # results since we clobbered the results file.  Also, exclude them
    # from being run again.
    if args.resume is True:
        for (key, value) in old_results.tests.items():
            if os.path.sep != '/':
                key = key.replace(os.path.sep, '/', -1)
            json_writer.write_dict_item(key, value)
            env.exclude_tests.add(key)

    time_start = time.time()
    profile.run(env, json_writer)
    time_end = time.time()

    json_writer.close_dict()

    results.time_elapsed = time_end - time_start
    json_writer.write_dict_item('time_elapsed', results.time_elapsed)

    # End json.
    json_writer.close_dict()
    json_writer.file.close()

    print
    print 'Thank you for running Piglit!'
    print 'Results have been written to ' + result_filepath
182

Dylan Baker's avatar
Dylan Baker committed
183

Nicolai Hähnle's avatar
Nicolai Hähnle committed
184
if __name__ == "__main__":
Dylan Baker's avatar
Dylan Baker committed
185
    main()