2 ##########################################################################
4 # Copyright 2011 Jose Fonseca
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:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
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
25 ##########################################################################/
27 '''Tool test driver.'''
35 from base_driver import *
40 def __init__(self, srcStream, refFileName, verbose=False):
41 self.srcStream = srcStream
42 self.refFileName = refFileName
44 self.refStream = open(refFileName, 'rt')
48 def readLines(self, stream):
56 refLines = self.readLines(self.refStream)
57 srcLines = self.readLines(self.srcStream)
59 numLines = max(len(refLines), len(srcLines))
61 for lineNo in xrange(numLines):
63 refLine = refLines[lineNo]
65 fail('unexpected junk: %r' % self.srcLines[lineNo])
68 srcLine = srcLines[lineNo]
70 fail('unexpected EOF: %r expected' % refLine)
72 if refLine != srcLine:
73 fail('mismatch: expected %r but got %r' % (refLine ,srcLine))
77 class ToolDriver(Driver):
80 '''Run the application standalone, skipping this test if it fails by
83 if self.options.ref_dump:
84 stdout = subprocess.PIPE
88 cmd = [self.options.apitrace] + self.args
89 p = popen(cmd, cwd=options.cwd, stdout=stdout)
91 if self.options.ref_dump:
92 comparer = AsciiComparer(p.stdout, self.options.ref_dump, self.options.verbose)
97 fail('tool returned code %i' % p.returncode)
99 def createOptParser(self):
100 optparser = Driver.createOptParser(self)
102 optparser.add_option(
103 '--ref-dump', metavar='PATH',
104 type='string', dest='ref_dump', default=None,
105 help='reference dump')
112 (options, args) = self.parseOptions()
119 if __name__ == '__main__':