]> git.cworth.org Git - apitrace-tests/blobdiff - driver.py
Specify the api to trace.
[apitrace-tests] / driver.py
index 7f04f2495a8cf3de5a450121692fd9a02793d29c..8c7d1268bb61e9e2fc2a1b5fe82d14f1f5209979 100755 (executable)
--- a/driver.py
+++ b/driver.py
@@ -31,6 +31,7 @@ import optparse
 import os.path
 import platform
 import re
+import shutil
 import subprocess
 import sys
 import time
@@ -56,11 +57,16 @@ def _get_build_path(path):
         sys.exit(1)
     return path
 
+def _get_build_program(program):
+    if platform.system() == 'Windows':
+        program += '.exe'
+    return _get_build_path(program)
+
 
 class TestCase:
 
+    api = 'gl'
     max_frames = None
-
     trace_file = None
 
     def __init__(self, name, args, cwd=None, build=None, results = '.'):
@@ -91,26 +97,33 @@ class TestCase:
             if not os.path.exists(trace_dir):
                 os.makedirs(trace_dir)
 
+        cmd = self.args
         env = os.environ.copy()
         
         system = platform.system()
+        local_wrapper = None
         if system == 'Windows':
-            # TODO
-            self.skip('tracing not supported on Windows')
             wrapper = _get_build_path('wrappers/opengl32.dll')
-        elif system == 'Darwin':
-            wrapper = _get_build_path('wrappers/OpenGL')
-            env['DYLD_LIBRARY_PATH'] = os.path.dirname(wrapper)
+            local_wrapper = os.path.join(os.path.dirname(self.args[0]), os.path.basename(wrapper))
+            shutil.copy(wrapper, local_wrapper)
+            env['TRACE_FILE'] = self.trace_file
         else:
-            wrapper = _get_build_path('glxtrace.so')
-            env['LD_PRELOAD'] = wrapper
-
-        env['TRACE_FILE'] = self.trace_file
+            apitrace = _get_build_program('apitrace')
+            cmd = [
+                apitrace, 'trace', 
+                '--api', self.api,
+                '--output', self.trace_file,
+                '--'
+            ] + cmd
         if self.max_frames is not None:
             env['TRACE_FRAMES'] = str(self.max_frames)
 
-        p = popen(self.args, env=env, cwd=self.cwd)
-        p.wait()
+        try:
+            p = popen(cmd, env=env, cwd=self.cwd)
+            p.wait()
+        finally:
+            if local_wrapper is not None:
+                os.remove(local_wrapper)
 
         if not os.path.exists(self.trace_file):
             self.fail('no trace file generated\n')
@@ -119,13 +132,14 @@ class TestCase:
 
     def dump(self):
 
-        cmd = [_get_build_path('tracedump'), '--color=never', self.trace_file]
+        cmd = [_get_build_program('apitrace'), 'dump', '--color=never', self.trace_file]
         p = popen(cmd, stdout=subprocess.PIPE)
 
         swapbuffers = 0
         flushes = 0
 
         ref_line = ''
+        src_lines = []
         if self.ref_dump is not None:
             ref = open(self.ref_dump, 'rt')
             ref_line = ref.readline().rstrip()
@@ -145,11 +159,18 @@ class TestCase:
                     if src_line == ref_line:
                         sys.stdout.write(src_line + '\n')
                         ref_line = ref.readline().rstrip()
+                        src_lines = []
+                    else:
+                        src_lines.append(src_line)
+
         p.wait()
         if p.returncode != 0:
-            self.fail('tracedump returned code %i' % p.returncode)
+            self.fail('`apitrace dump` returned code %i' % p.returncode)
         if ref_line:
-            self.fail('missing call %s' % ref_line)
+            if src_lines:
+                self.fail('missing call `%s` (found `%s`)' % (ref_line, src_lines[0]))
+            else:
+                self.fail('missing call %s' % ref_line)
 
     def run(self):
         self.standalone()
@@ -236,6 +257,10 @@ def main():
     optparser = optparse.OptionParser(
         usage='\n\t%prog [options] -- program [args] ...',
         version='%%prog')
+    optparser.add_option(
+        '-a', '--api', metavar='API',
+        type='string', dest='api', default='gl',
+        help='api to trace')
     optparser.add_option(
         '-B', '--build', metavar='PATH',
         type='string', dest='build', default='..',
@@ -264,6 +289,7 @@ def main():
         build = options.build,
         results = options.results,
     )
+    test.api = options.api
     test.ref_dump = options.ref_dump
 
     test.run()