[Piglit] [PATCH] piglit-run.py: Add -s option for recording test stats

Tom Stellard tstellar at gmail.com
Sat Dec 11 17:56:17 PST 2010


The option '-s file' tells piglit to write test statistics to the
specified file.  Any output from the tests that begins with a ~ is
considered a statistic and will be written to the file.
---
 framework/core.py |   10 ++++++++++
 piglit-run.py     |    7 ++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index b237df6..efc8c2c 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -26,6 +26,7 @@
 import errno
 import os
 import platform
+import re
 import stat
 import subprocess
 import sys
@@ -264,6 +265,7 @@ class Environment:
 		self.execute = True
 		self.filter = []
 		self.exclude_filter = []
+		self.stats = []
 
 	def run(self, command):
 		try:
@@ -326,6 +328,11 @@ class Test:
 				print "    result: %(result)s" % { 'result': result['result'] }
 
 			result.write(env.file, path)
+			if env.stats:
+				env.stats.write(path + '\n')
+				if 'stats' in result:
+					for s in result['stats']:
+						env.stats.write(s + '\n')
 			if Test.sleep:
 				time.sleep(Test.sleep)
 		else:
@@ -343,6 +350,7 @@ class Test:
 	def handleErr(self, results, err):
 		errors = filter(lambda s: len(s) > 0, map(lambda s: s.strip(), err.split('\n')))
 
+		results['stats'] = [s for s in errors if re.match('~.+',s)]
 		ignored = [s for s in errors if self.isIgnored(s)]
 		errors = [s for s in errors if s not in ignored]
 
@@ -372,6 +380,8 @@ class TestProfile:
 
 	def run(self, env):
 		time_start = time.time()
+		if env.stats:
+			Test.ignoreErrors.append(re.compile("^~.+"))
 		self.tests.doRun(env, '')
 		time_end = time.time()
 		print >>env.file, "time:",(time_end-time_start)
diff --git a/piglit-run.py b/piglit-run.py
index 9f0eca6..6b8fc69 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -45,6 +45,7 @@ Options:
   -x regexp, --exclude-tests=regexp Excludey matching tests (can be used
                             more than once)
   -n name, --name=name      Name of the testrun
+  -s stats, --stats=file    Output statistics to file
 
 Example:
   %(progName)s tests/all.tests results/all
@@ -64,7 +65,7 @@ def main():
 	env = core.Environment()
 
 	try:
-		options, args = getopt(sys.argv[1:], "hdt:n:x:", [ "help", "dry-run", "tests=", "name=", "exclude-tests=" ])
+		options, args = getopt(sys.argv[1:], "hdt:n:x:s:", [ "help", "dry-run", "tests=", "name=", "stats=", "exclude-tests=" ])
 	except GetoptError:
 		usage()
 
@@ -81,6 +82,8 @@ def main():
 			env.exclude_filter[:0] = [re.compile(value)]
 		elif name in ('-n', '--name'):
 			OptionName = value
+		elif name in ('-s', '--stats'):
+			env.stats = open(value, 'w')
 
 	if len(args) != 2:
 		usage()
@@ -96,6 +99,8 @@ def main():
 	env.collectData()
 	profile.run(env)
 	env.file.close()
+	if env.stats:
+		env.stats.close()
 
 	print "Writing summary file..."
 	results = core.loadTestResults(resultsDir)
-- 
1.7.2.2



More information about the Piglit mailing list