Be more lenient with shader matching.
[apitrace-tests] / trim_stress_driver.py
1 #!/usr/bin/env python
2
3 # Copyright 2012 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation files
7 # (the "Software"), to deal in the Software without restriction,
8 # including without limitation the rights to use, copy, modify, merge,
9 # publish, distribute, sublicense, and/or sell copies of the Software,
10 # and to permit persons to whom the Software is furnished to do so,
11 # subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24
25 '''Stress test driver for apitrace trim.'''
26
27 import os, errno, re, shutil, subprocess
28
29 from base_driver import *
30
31 def rm_and_mkdir(dir):
32
33     # Operate only on local directories
34     dir = './' + dir
35
36     # Failing to delete a directory that doesn't exist is no failure
37     def rmtree_onerror(function, path, excinfo):
38         if excinfo[0] == OSError and excinfo[1].errno != errno.ENOENT:
39             raise
40
41     shutil.rmtree(dir, onerror = rmtree_onerror)
42     os.makedirs(dir)
43
44 class TrimStressDriver(Driver):
45
46     def trim_stress(self, trace_file):
47         "Execute an apitrace-trim stress test for the given trace."
48
49         (dir, file_name) = os.path.split(trace_file)
50         (name, extension) = file_name.rsplit('.', 1)
51
52         ref_dir = name + '-ref/'
53         tmp_out_dir = name + '-tmp-out/'
54         out_dir = name + '-out/'
55         trim_file = name + '.trace.trim'
56
57         rm_and_mkdir(out_dir)
58         rm_and_mkdir(tmp_out_dir)
59
60         if (not os.path.exists(ref_dir)):
61             rm_and_mkdir(ref_dir)
62             subprocess.check_call([self.options.apitrace,
63                                    "dump-images", "--call-nos=no",
64                                    "--output=" + ref_dir, trace_file]);
65
66         # Count the number of frame snapshots generated
67         frames = 0
68         for dirpath, dirs, files in os.walk(ref_dir):
69             # Don't descend into any sub-directories (not that there
70             # should be any)
71             del dirs[:]
72             pattern = re.compile("[0-9]*\.png")
73             def f(x): return re.match(pattern, x)
74             files = filter(f, files)
75             frames = len(files)
76
77         for frame in range(frames):
78             try:
79                 subprocess.check_call([self.options.apitrace,
80                                        "trim", "--auto",
81                                        "--frame=%d/frame" % (frame),
82                                        "--output=" + trim_file, trace_file])
83             except:
84                 print "An error occurred while trimming " + \
85                     "frame %d from %s" % (frame, trace_file)
86                 fail()
87             try:
88                 subprocess.check_call([self.options.apitrace,
89                                        "dump-images", "--call-nos=no",
90                                        "--output=" + tmp_out_dir + "frame",
91                                        trim_file])
92             except:
93                 print "An error occurred replaying " + \
94                     "%s to generate a frame snapshot" % (trim_file)
95                 fail()
96             os.rename("%s/frame0000000000.png" % (tmp_out_dir),
97                       "%s/%010d.png" % (tmp_out_dir, frame))
98             try:
99                 subprocess.check_call([self.options.apitrace,
100                                        "diff-images", "-v",
101                                        ref_dir, tmp_out_dir])
102             except:
103                 print "Trimmed frame did not match " + \
104                     "reference images. See " + name + "-index.html"
105                 fail()
106             finally:
107                 os.rename("index.html", name + "-index.html")
108             os.rename("%s/%010d.png" % (tmp_out_dir, frame),
109                       "%s/%010d.png" % (out_dir, frame))
110         try:
111             subprocess.check_call([self.options.apitrace,
112                                    "diff-images", "-v", ref_dir, out_dir])
113         except:
114             print "Trimmed frame did not match " + \
115                 "reference images. See " + name + "-index.html"
116             fail()
117         finally:
118             os.rename("index.html", name + "-index.html")
119
120     def run(self):
121         self.parseOptions()
122
123         self.trim_stress(self.args[0])
124
125         pass_()
126
127 if __name__ == '__main__':
128     TrimStressDriver().run()