]> git.cworth.org Git - apitrace/commitdiff
Add snapshot comparison criteria in tracecheck.py
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 14 May 2011 13:56:08 +0000 (14:56 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 14 May 2011 13:56:08 +0000 (14:56 +0100)
scripts/tracecheck.py

index 28b0720fdd7cad6b3a7b0b2c5d7f63da04ebd57c..b5d6b7658c76b68f4253616e731da8e224f036d5 100755 (executable)
@@ -110,6 +110,14 @@ def main():
         '-r', '--retrace', metavar='PROGRAM',
         type='string', dest='retrace', default='glretrace',
         help='retrace command [default: %default]')
+    optparser.add_option(
+        '-c', '--compare', metavar='PREFIX',
+        type='string', dest='compare_prefix', default=None,
+        help='snapshot comparison prefix')
+    optparser.add_option(
+        '--precision-threshold', metavar='BITS',
+        type='float', dest='precision_threshold', default='12',
+        help='precision threshold in bits [default: %default]')
     optparser.add_option(
         '--gl-renderer', metavar='REGEXP',
         type='string', dest='gl_renderer_re', default='^.*$',
@@ -145,6 +153,9 @@ def main():
         for line in stdout.split('\n'):
             if line.startswith(gl_renderer_header):
                 gl_renderer = line[len(gl_renderer_header):]
+            if line.startswith('direct rendering: No'):
+                sys.stderr.write('Indirect rendering.\n')
+                skip()
 
         # and match it against the regular expression specified in the command
         # line.
@@ -153,13 +164,37 @@ def main():
             skip()
 
     # Run glretrace
-    retrace = [options.retrace] + args
-    sys.stdout.write(' '.join(retrace) + '\n')
+    command = [options.retrace]
+    if options.compare_prefix:
+        command += ['-c', options.compare_prefix]
+    else:
+        command += ['-b']
+    command += args
+    sys.stdout.write(' '.join(command) + '\n')
     sys.stdout.flush()
-    returncode = subprocess.call(retrace)
-    if returncode:
-        # TODO: allow other criterias here, such as, snapshot comparison or performance threshold
-        bad()
+    p = subprocess.Popen(command, stdout=subprocess.PIPE)
+    stdout, stderr = p.communicate()
+    if p.returncode:
+        if not options.compare_prefix:
+            bad()
+        else:
+            skip()
+
+    if options.compare_prefix:
+        failed = False
+        precision_re = re.compile('^Snapshot (\S+) average precision of (\S+) bits$')
+        for line in stdout.split('\n'):
+            mo = precision_re.match(line)
+            if mo:
+                print line
+                call_no = int(mo.group(1))
+                precision = float(mo.group(2))
+                if precision < options.precision_threshold:
+                    failed = True
+        if failed:
+            bad()
+
+    # TODO: allow more criterias here, such as, performance threshold
 
     # Success
     good()