aboutsummaryrefslogtreecommitdiff
path: root/piglit-run.py
blob: 6d6ec770f1ff8ed89b182b0c94afb811226a6680 (plain)
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
112
113
114
115
116
117
118
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
144
145
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
#
# 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
# PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR(S) 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.


import argparse
import os.path as path
import sys, os
import time
import traceback
import json

sys.path.append(path.dirname(path.realpath(sys.argv[0])))
import framework.core as core
from framework.threads import synchronized_self

#############################################################################
##### Main program
#############################################################################

def main():
	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",
			metavar = "<test name>",
			default = None,
			help    = "Name of this test run")
	excGroup1.add_argument("-r", "--resume",
			action  = "store_true",
			help    = "Resume an interupted test run")

	# Setting the --dry-run flag is equivalent to env.execute=false
	parser.add_argument("-d", "--dry-run",
			action  = "store_false",
			dest    = "execute",
			help    = "Do not execute the tests")
	parser.add_argument("-t", "--include-tests",
			default = [],
			action  = "append",
			metavar = "<regex>",
			help    = "Run only matching tests (can be used more than once)")
	parser.add_argument("--tests",
			default = [],
			action  = "append",
			metavar = "<regex>",
			help    = "Run only matching tests (can be used more than once) " \
			          "DEPRECATED: use --include-tests instead")
	parser.add_argument("-x", "--exclude-tests",
			default = [],
			action  = "append",
			metavar = "<regex>",
			help    = "Exclude matching tests (can be used more than once)")

	# The new option going forward should be --no-concurrency, but to
	# maintain backwards compatability the --c, --concurrent option should
	# also be maintained. This code allows only one of the two options to be
	# supplied, or it throws an error
	excGroup2 = parser.add_mutually_exclusive_group()
	excGroup2.add_argument("--no-concurrency",
			action  = "store_false",
			dest    = "concurrency",
			help    = "Disable concurrent test runs")
	excGroup2.add_argument("-c", "--concurrent",
			action  = "store",
			metavar = "<boolean>",
			choices = ["1", "0", "on", "off"],
			help    = "Deprecated: Turn concrrent runs on or off")

	parser.add_argument("-p", "--platform",
			choices = ["glx", "x11_egl", "wayland", "gbm"],
			help    = "Name of windows system passed to waffle")
	parser.add_argument("--valgrind",
			action  =  "store_true",
			help    = "Run tests in valgrind's memcheck")
	parser.add_argument("testProfile",
			metavar = "<Path to test profile>",
			help    = "Path to testfile to run")
	parser.add_argument("resultsPath",
			metavar = "<Results Path>",
			help    = "Path to results folder")

	args = parser.parse_args()


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

	# Deprecated:
	# If the deprecated -c, --concurrent flag is passed, override
	# args.concurrency (which would otherwise be set by the --no-concurrency)
	# flag and print a warning.
	if args.concurrent is not None:
		if (args.concurrent == '1' or args.concurrent == 'on'):
			args.concurrency = True
			print "Warning: Option -c, --concurrent is deprecated, " \
					"concurrent test runs are on by default"
		elif (args.concurrent == '0' or args.concurrent == 'off'):
			args.concurrency = False
			print "Warning: Option -c, --concurrent is deprecated, " \
					"use --no-concurrency for non-concurrent test runs"
		# Ne need for else, since argparse restricts the arguments allowed

	# If the deprecated tests option was passed print a warning
	if args.tests != []:
		# This merges any options passed into the --tests option into the
		# ones passed into -t or --tests-include and throws out duplicates
		args.include_tests = list(set(args.include_tests + args.tests))
		print "Warning: Option --tests is deprecated, use " \
				"--include-tests instead"

	# If resume is requested attempt to load the results file
	# in the specified path
	if args.resume is True:
		resultsDir = path.realpath(args.resultsPath)

		# 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
		resultsDir = args.resultsPath

	# Pass arguments into Environment
	env = core.Environment(concurrent=args.concurrency,
			exclude_filter=args.exclude_tests,
			include_filter=args.include_tests,
			execute=args.execute,
			valgrind=args.valgrind)

	# 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)
	json_writer.write_dict_key('filter')
	result_file.write(json.dumps(args.include_tests))
	json_writer.write_dict_key('exclude_filter')
	result_file.write(json.dumps(args.exclude_tests))
	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


if __name__ == "__main__":
	main()