]> git.cworth.org Git - apitrace-tests/blob - tool_driver.py
Be more lenient with shader matching.
[apitrace-tests] / tool_driver.py
1 #!/usr/bin/env python
2 ##########################################################################
3 #
4 # Copyright 2011 Jose Fonseca
5 # All Rights Reserved.
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 # THE SOFTWARE.
24 #
25 ##########################################################################/
26
27 '''Tool test driver.'''
28
29
30 import os.path
31 import subprocess
32 import sys
33
34
35 from base_driver import *
36
37
38 class AsciiComparer:
39
40     def __init__(self, srcStream, refStream, verbose=False):
41         self.srcStream = srcStream
42         self.refStream = refStream
43     
44     def readLines(self, stream):
45         lines = []
46         for line in stream:
47             line = line[:-1]
48             lines.append(line)
49         return lines
50
51     def compare(self):
52         refLines = self.readLines(self.refStream)
53         srcLines = self.readLines(self.srcStream)
54
55         numLines = max(len(refLines), len(srcLines))
56
57         for lineNo in xrange(numLines):
58             try:
59                 refLine = refLines[lineNo]
60             except IndexError:
61                 fail('unexpected junk: %r' % srcLines[lineNo])
62
63             try:
64                 srcLine = srcLines[lineNo]
65             except IndexError:
66                 fail('unexpected EOF: %r expected' % refLine)
67
68             if refLine != srcLine:
69                 fail('mismatch: expected %r but got %r' % (refLine ,srcLine))
70
71
72
73 class ToolDriver(Driver):
74
75     def runScript(self, refScript):
76         '''Run the application standalone, skipping this test if it fails by
77         some reason.'''
78
79         refStream = open(refScript, 'rt')
80         cwd = os.path.dirname(os.path.abspath(refScript))
81
82         while True:
83             args = refStream.readline().split()
84             cmd = [self.options.apitrace] + args
85
86             if args[0] == 'dump':
87                 break
88
89             p = popen(cmd, cwd=cwd, universal_newlines=True)
90             p.wait()
91             if p.returncode != 0:
92                 fail('`apitrace %s` returned code %i' % (args[0], p.returncode))
93             
94         p = popen(cmd, cwd=cwd, stdout=subprocess.PIPE, universal_newlines=True)
95
96         comparer = AsciiComparer(p.stdout, refStream, self.options.verbose)
97         comparer.compare()
98
99         p.wait()
100         if p.returncode != 0:
101             fail('`apitrace %s` returned code %i' % (args[0], p.returncode))
102     
103     def run(self):
104         self.parseOptions()
105
106         for arg in self.args:
107             self.runScript(arg)
108
109         pass_()
110
111
112 if __name__ == '__main__':
113     ToolDriver().run()