]> git.cworth.org Git - apitrace-tests/blob - trim_stress_driver.py
trim_stress: Fail test at first frame which doesn't match reference
[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, 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             frames = len(files)
73
74         for frame in range(frames):
75             try:
76                 subprocess.check_call([self.options.apitrace,
77                                        "trim", "--auto",
78                                        "--frame=%d/frame" % (frame),
79                                        "--output=" + trim_file, trace_file])
80             except:
81                 print "An error occurred while trimming " + \
82                     "frame %d from %s" % (frame, trace_file)
83                 fail()
84             try:
85                 subprocess.check_call([self.options.apitrace,
86                                        "dump-images", "--call-nos=no",
87                                        "--output=" + tmp_out_dir + "frame",
88                                        trim_file])
89             except:
90                 print "An error occurred replaying " + \
91                     "%s to generate a frame snapshot" % (trim_file)
92                 fail()
93             os.rename("%s/frame0000000000.png" % (tmp_out_dir),
94                       "%s/%010d.png" % (tmp_out_dir, frame))
95             try:
96                 subprocess.check_call([self.options.apitrace,
97                                        "diff-images", "-v",
98                                        ref_dir, tmp_out_dir])
99             except:
100                 print "Trimmed frame did not match " + \
101                     "reference images. See " + name + "-index.html"
102                 fail()
103             finally:
104                 os.rename("index.html", name + "-index.html")
105             os.rename("%s/%010d.png" % (tmp_out_dir, frame),
106                       "%s/%010d.png" % (out_dir, frame))
107         try:
108             subprocess.check_call([self.options.apitrace,
109                                    "diff-images", "-v", ref_dir, out_dir])
110         except:
111             print "Trimmed frame did not match " + \
112                 "reference images. See " + name + "-index.html"
113             fail()
114         finally:
115             os.rename("index.html", name + "-index.html")
116
117     def run(self):
118         self.parseOptions()
119
120         self.trim_stress(self.args[0])
121
122         pass_()
123
124 if __name__ == '__main__':
125     TrimStressDriver().run()