Add more structure constructor tests.
[piglit/hramrach.git] / framework / exectest.py
blob46b041be6f119d47a63a4b063e5ab200beb24ff3
1 #!/usr/bin/env python
3 # Permission is hereby granted, free of charge, to any person
4 # obtaining a copy of this software and associated documentation
5 # files (the "Software"), to deal in the Software without
6 # restriction, including without limitation the rights to use,
7 # copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following
10 # conditions:
12 # This permission notice shall be included in all copies or
13 # substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
24 import os
25 import subprocess
27 from core import Test, testBinDir, TestResult
29 def add_plain_test(group, name):
30 group[name] = PlainExecTest([name, '-auto'])
32 #############################################################################
33 ##### PlainExecTest: Simply run an executable
34 ##### Expect one line prefixed PIGLIT: in the output, which contains a
35 ##### result dictionary. The plain output is appended to this dictionary
36 #############################################################################
37 class PlainExecTest(Test):
38 def __init__(self, command):
39 Test.__init__(self)
40 self.command = command
41 # Prepend testBinDir to the path.
42 self.command[0] = testBinDir + self.command[0]
43 self.env = {}
45 def run(self):
47 fullenv = os.environ.copy()
48 for e in self.env:
49 fullenv[e] = str(self.env[e])
51 proc = subprocess.Popen(
52 self.command,
53 stdout=subprocess.PIPE,
54 stderr=subprocess.PIPE,
55 env=fullenv,
56 universal_newlines=True
58 out, err = proc.communicate()
60 outlines = out.split('\n')
61 outpiglit = map(lambda s: s[7:], filter(lambda s: s.startswith('PIGLIT:'), outlines))
63 results = TestResult()
65 if len(outpiglit) > 0:
66 try:
67 results.update(eval(''.join(outpiglit), {}))
68 out = '\n'.join(filter(lambda s: not s.startswith('PIGLIT:'), outlines))
69 except:
70 results['result'] = 'fail'
71 results['note'] = 'Failed to parse result string'
73 if 'result' not in results:
74 results['result'] = 'fail'
76 if proc.returncode != 0:
77 results['result'] = 'fail'
78 results['note'] = 'Returncode was %d' % (proc.returncode)
80 self.handleErr(results, err)
82 results['info'] = "@@@Returncode: %d\n\nErrors:\n%s\n\nOutput:\n%s" % (proc.returncode, err, out)
83 results['returncode'] = proc.returncode
85 return results