[Piglit] [PATCH piglit 1/2] Make Python scripts independent of the current working directory
Matěj Cepl
mcepl at redhat.com
Tue Oct 11 11:43:12 PDT 2011
So it is now possible to run
$ piglit-run tests/quick-driver.tests /tmp/piglit
and then with this command
$ piglit-summary-html --overwrite /tmp/piglit/results /tmp/piglit/main
generate a report in /tmp/piglit/results/index.html & al.
Signed-off-by: Matěj Cepl <mcepl at redhat.com>
---
framework/core.py | 11 +++---
framework/gleantest.py | 10 +++---
piglit-merge-results.py | 3 +-
piglit-run.py | 11 +++++-
piglit-summary-html.py | 5 ++-
tests/all.tests | 92 +++++++++++++++++++++++-----------------------
tests/sanity.tests | 4 +-
7 files changed, 74 insertions(+), 62 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index 5c583c7..e6d9b4d 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -572,16 +572,17 @@ class TestProfile:
##### Loaders
#############################################################################
-def loadTestProfile(filename):
+def loadTestProfile(filename, resdir):
+ ns = {
+ '__file__': filename,
+ 'res_dir': resdir
+ }
try:
- ns = {
- '__file__': filename
- }
execfile(filename, ns)
- return ns['profile']
except:
traceback.print_exc()
raise Exception('Could not read tests profile')
+ return ns['profile']
def loadTestResults(path):
if os.path.isdir(path):
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 254cfcc..fe7c3b7 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -33,20 +33,20 @@ from exectest import ExecTest
def gleanExecutable():
return testBinDir + 'glean'
-def gleanResultDir():
- return os.path.join('.', 'results', 'glean')
+def gleanResultDir(r_dir):
+ return os.path.join(r_dir, 'results', 'glean')
class GleanTest(ExecTest):
globalParams = []
- def __init__(self, name):
+ def __init__(self, name, resdir):
ExecTest.__init__(self, \
- [gleanExecutable(), "-r", os.path.join(gleanResultDir(), name),
+ [gleanExecutable(), "-r", os.path.join(gleanResultDir(resdir), name),
"-o",
"-v", "-v", "-v",
"-t", "+"+name])
- checkDir(os.path.join(gleanResultDir(), name), False)
+ checkDir(os.path.join(gleanResultDir(resdir), name), False)
self.name = name
diff --git a/piglit-merge-results.py b/piglit-merge-results.py
index eff8d5c..26d5881 100755
--- a/piglit-merge-results.py
+++ b/piglit-merge-results.py
@@ -23,8 +23,9 @@
from getopt import getopt, GetoptError
-import sys
+import sys, os.path
+sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
import framework.core as core
diff --git a/piglit-run.py b/piglit-run.py
index c5f5a4a..4218b75 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -29,6 +29,7 @@ import sys, os
import time
import traceback
+sys.path.append(path.dirname(path.realpath(sys.argv[0])))
import framework.core as core
from framework.threads import synchronized_self
@@ -106,6 +107,11 @@ def main():
profileFilename = args[0]
resultsDir = args[1]
+ # Change to the piglit's path
+ start_dir = os.getcwd()
+ piglit_dir = path.dirname(path.realpath(sys.argv[0]))
+ os.chdir(piglit_dir)
+
core.checkDir(resultsDir, False)
results = core.TestrunResult()
@@ -126,7 +132,7 @@ def main():
for (key, value) in env.collectData().items():
json_writer.write_dict_item(key, value)
- profile = core.loadTestProfile(profileFilename)
+ profile = core.loadTestProfile(profileFilename, resultsDir)
time_start = time.time()
profile.run(env, json_writer)
@@ -143,5 +149,8 @@ def main():
print 'Thank you for running Piglit!'
print 'Results have been written to ' + result_filepath
+ # Return back to the original path
+ os.chdir(start_dir)
+
if __name__ == "__main__":
main()
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index a255a15..56e4449 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -23,9 +23,10 @@
from getopt import getopt, GetoptError
import cgi
-import os
+import os, os.path
import sys
+sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
import framework.core as core
import framework.summary
@@ -53,7 +54,7 @@ def writefile(filename, text):
f.write(text.encode('utf-8'))
f.close()
-templatedir = os.path.join(os.path.dirname(__file__), 'templates')
+templatedir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
Result = readfile(os.path.join(templatedir, 'result.html'))
ResultDetail = readfile(os.path.join(templatedir, 'result_detail.html'))
ResultList = readfile(os.path.join(templatedir, 'result_list.html'))
diff --git a/tests/all.tests b/tests/all.tests
index 40bc92c..beb5d43 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -59,65 +59,65 @@ def add_fbo_depthstencil_tests(group, format):
group[prefix + 'depthstencil-' + format + '-blit'] = PlainExecTest(['fbo-depthstencil', '-auto', 'blit', format])
glean = Group()
-glean['basic'] = GleanTest('basic')
-glean['api2'] = GleanTest('api2')
-glean['makeCurrent'] = GleanTest('makeCurrent')
-glean['blendFunc'] = GleanTest('blendFunc')
-glean['bufferObject'] = GleanTest('bufferObject')
-glean['clipFlat'] = GleanTest('clipFlat')
-glean['depthStencil'] = GleanTest('depthStencil')
-glean['fbo'] = GleanTest('fbo')
-glean['fpexceptions'] = GleanTest('fpexceptions')
-glean['getString'] = GleanTest('getString')
-glean['logicOp'] = GleanTest('logicOp')
-glean['maskedClear'] = GleanTest('maskedClear')
-glean['occluquery'] = GleanTest('occluQry')
-glean['orthoPosRandTris'] = GleanTest('orthoPosRandTris')
-glean['orthoPosRandRects'] = GleanTest('orthoPosRandRects')
-glean['orthoPosTinyQuads'] = GleanTest('orthoPosTinyQuads')
-glean['orthoPosHLines'] = GleanTest('orthoPosHLines')
-glean['orthoPosVLines'] = GleanTest('orthoPosVLines')
-glean['orthoPosPoints'] = GleanTest('orthoPosPoints')
-glean['paths'] = GleanTest('paths')
-glean['pbo'] = GleanTest('pbo')
-glean['polygonOffset'] = GleanTest('polygonOffset')
-glean['pixelFormats'] = GleanTest('pixelFormats')
-glean['pointAtten'] = GleanTest('pointAtten')
-glean['pointSprite'] = GleanTest('pointSprite')
-glean['exactRGBA'] = GleanTest('exactRGBA')
-glean['readPixSanity'] = GleanTest('readPixSanity')
-glean['rgbTriStrip'] = GleanTest('rgbTriStrip')
-glean['scissor'] = GleanTest('scissor')
-glean['shaderAPI'] = GleanTest('shaderAPI')
-glean['stencil2'] = GleanTest('stencil2')
-glean['teapot'] = GleanTest('teapot')
-glean['texCombine'] = GleanTest('texCombine')
-glean['texCube'] = GleanTest('texCube')
-glean['texEnv'] = GleanTest('texEnv')
-glean['texgen'] = GleanTest('texgen')
-glean['texRect'] = GleanTest('texRect')
-glean['texCombine4'] = GleanTest('texCombine4')
-glean['texSwizzle'] = GleanTest('texSwizzle')
-glean['texture_srgb'] = GleanTest('texture_srgb')
-glean['texUnits'] = GleanTest('texUnits')
-glean['vertArrayBGRA'] = GleanTest('vertArrayBGRA')
-glean['vertattrib'] = GleanTest('vertattrib')
+glean['basic'] = GleanTest('basic', res_dir)
+glean['api2'] = GleanTest('api2', res_dir)
+glean['makeCurrent'] = GleanTest('makeCurrent', res_dir)
+glean['blendFunc'] = GleanTest('blendFunc', res_dir)
+glean['bufferObject'] = GleanTest('bufferObject', res_dir)
+glean['clipFlat'] = GleanTest('clipFlat', res_dir)
+glean['depthStencil'] = GleanTest('depthStencil', res_dir)
+glean['fbo'] = GleanTest('fbo', res_dir)
+glean['fpexceptions'] = GleanTest('fpexceptions', res_dir)
+glean['getString'] = GleanTest('getString', res_dir)
+glean['logicOp'] = GleanTest('logicOp', res_dir)
+glean['maskedClear'] = GleanTest('maskedClear', res_dir)
+glean['occluquery'] = GleanTest('occluQry', res_dir)
+glean['orthoPosRandTris'] = GleanTest('orthoPosRandTris', res_dir)
+glean['orthoPosRandRects'] = GleanTest('orthoPosRandRects', res_dir)
+glean['orthoPosTinyQuads'] = GleanTest('orthoPosTinyQuads', res_dir)
+glean['orthoPosHLines'] = GleanTest('orthoPosHLines', res_dir)
+glean['orthoPosVLines'] = GleanTest('orthoPosVLines', res_dir)
+glean['orthoPosPoints'] = GleanTest('orthoPosPoints', res_dir)
+glean['paths'] = GleanTest('paths', res_dir)
+glean['pbo'] = GleanTest('pbo', res_dir)
+glean['polygonOffset'] = GleanTest('polygonOffset', res_dir)
+glean['pixelFormats'] = GleanTest('pixelFormats', res_dir)
+glean['pointAtten'] = GleanTest('pointAtten', res_dir)
+glean['pointSprite'] = GleanTest('pointSprite', res_dir)
+glean['exactRGBA'] = GleanTest('exactRGBA', res_dir)
+glean['readPixSanity'] = GleanTest('readPixSanity', res_dir)
+glean['rgbTriStrip'] = GleanTest('rgbTriStrip', res_dir)
+glean['scissor'] = GleanTest('scissor', res_dir)
+glean['shaderAPI'] = GleanTest('shaderAPI', res_dir)
+glean['stencil2'] = GleanTest('stencil2', res_dir)
+glean['teapot'] = GleanTest('teapot', res_dir)
+glean['texCombine'] = GleanTest('texCombine', res_dir)
+glean['texCube'] = GleanTest('texCube', res_dir)
+glean['texEnv'] = GleanTest('texEnv', res_dir)
+glean['texgen'] = GleanTest('texgen', res_dir)
+glean['texRect'] = GleanTest('texRect', res_dir)
+glean['texCombine4'] = GleanTest('texCombine4', res_dir)
+glean['texSwizzle'] = GleanTest('texSwizzle', res_dir)
+glean['texture_srgb'] = GleanTest('texture_srgb', res_dir)
+glean['texUnits'] = GleanTest('texUnits', res_dir)
+glean['vertArrayBGRA'] = GleanTest('vertArrayBGRA', res_dir)
+glean['vertattrib'] = GleanTest('vertattrib', res_dir)
def add_glsl1(name):
testname = 'glsl1-' + name
- glean[testname] = GleanTest('glsl1')
+ glean[testname] = GleanTest('glsl1', res_dir)
glean[testname].env['PIGLIT_TEST'] = name
execfile(os.path.dirname(__file__) + '/glean-glsl1.tests')
def add_fp1(name):
testname = 'fp1-' + name
- glean[testname] = GleanTest('fragProg1')
+ glean[testname] = GleanTest('fragProg1', res_dir)
glean[testname].env['PIGLIT_TEST'] = name
execfile(os.path.dirname(__file__) + '/glean-fragProg1.tests')
def add_vp1(name):
testname = 'vp1-' + name
- glean[testname] = GleanTest('vertProg1')
+ glean[testname] = GleanTest('vertProg1', res_dir)
glean[testname].env['PIGLIT_TEST'] = name
execfile(os.path.dirname(__file__) + '/glean-vertProg1.tests')
diff --git a/tests/sanity.tests b/tests/sanity.tests
index 13c65b7..bcab606 100644
--- a/tests/sanity.tests
+++ b/tests/sanity.tests
@@ -7,8 +7,8 @@ from framework.core import *
from framework.gleantest import *
glean = Group()
-glean['basic'] = GleanTest('basic')
-glean['readPixSanity'] = GleanTest('readPixSanity')
+glean['basic'] = GleanTest('basic', res_dir)
+glean['readPixSanity'] = GleanTest('readPixSanity', res_dir)
profile = TestProfile()
profile.tests['glean'] = glean
--
1.7.1
More information about the Piglit
mailing list