3 # Copyright 2012 Intel Corporation
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:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
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
25 '''Stress test driver for apitrace trim.'''
27 import os, errno, shutil, subprocess
29 from base_driver import *
31 def rm_and_mkdir(dir):
33 # Operate only on local directories
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:
41 shutil.rmtree(dir, onerror = rmtree_onerror)
44 class TrimStressDriver(Driver):
46 def trim_stress(self, trace_file):
47 "Execute an apitrace-trim stress test for the given trace."
49 (dir, file_name) = os.path.split(trace_file)
50 (name, extension) = file_name.rsplit('.', 1)
52 ref_dir = name + '-ref/'
53 out_dir = name + '-out/'
54 trim_file = name + '.trace.trim'
59 subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + ref_dir, trace_file]);
61 # Count the number of frame snapshots generated
63 for dirpath, dirs, files in os.walk(ref_dir):
64 # Don't descend into any sub-directories (not that there
69 for frame in range(frames):
71 subprocess.check_call([self.options.apitrace, "trim", "--auto", "--frame=%d" % (frame), "--output=" + trim_file, trace_file])
73 print "An error occurred while trimming frame %d from %s" % (frame, trace_file)
76 subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + out_dir + "frame", trim_file])
78 print "An error occurred replaying %s to generate a frame snapshot" % (trim_file)
80 os.rename("%s/frame0000000000.png" % (out_dir), "%s/%010d.png" % (out_dir, frame))
83 subprocess.check_call([self.options.apitrace, "diff-images", "-v", ref_dir, out_dir])
85 print "Trimmed frames did not match reference images. See " + name + "-index.html"
88 os.rename("index.html", name + "-index.html")
93 self.trim_stress(self.args[0])
97 if __name__ == '__main__':
98 TrimStressDriver().run()