]> git.cworth.org Git - apitrace-tests/blob - trim_stress_driver.py
Add stress tests from "apitrace trim".
[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 trimp.'''
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         out_dir = name + '-out/'
54         trim_file = name + '.trace.trim'
55
56         rm_and_mkdir(ref_dir)
57         rm_and_mkdir(out_dir)
58
59         subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + ref_dir, trace_file]);
60
61         # Count the number of frame snapshots generated
62         frames = 0
63         for dirpath, dirs, files in os.walk(ref_dir):
64             # Don't descend into any sub-directories (not that there
65             # should be any)
66             del dirs[:]
67             frames = len(files)
68
69         for frame in range(frames):
70             try:
71                 subprocess.check_call([self.options.apitrace, "trim", "--frame=%d" % (frame), "--output=" + trim_file, trace_file])
72             except:
73                 print "An error occurred while trimming frame %d from %s" % (frame, trace_file)
74                 fail()
75             try:
76                 subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + out_dir + "frame", trim_file])
77             except:
78                 print "An error occurred replaying %s to generate a frame snapshot" % (trim_file)
79                 fail()
80             os.rename("%s/frame0000000000.png" % (out_dir), "%s/%010d.png" % (out_dir, frame))
81
82         try:
83             subprocess.check_call([self.options.apitrace, "diff-images", "-v", ref_dir, out_dir])
84         except:
85             print "Trimmed frames did not match reference images. See " + name + "-index.html"
86             fail()
87         finally:
88             os.rename("index.html", name + "-index.html")
89
90     def run(self):
91         self.parseOptions()
92
93         self.trim_stress(self.args[0])
94
95         pass_()
96
97 if __name__ == '__main__':
98     TrimStressDriver().run()