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 tmp_out_dir = name + '-tmp-out/'
54 out_dir = name + '-out/'
55 trim_file = name + '.trace.trim'
58 rm_and_mkdir(tmp_out_dir)
60 if (not os.path.exists(ref_dir)):
62 subprocess.check_call([self.options.apitrace,
63 "dump-images", "--call-nos=no",
64 "--output=" + ref_dir, trace_file]);
66 # Count the number of frame snapshots generated
68 for dirpath, dirs, files in os.walk(ref_dir):
69 # Don't descend into any sub-directories (not that there
74 for frame in range(frames):
76 subprocess.check_call([self.options.apitrace,
78 "--frame=%d/frame" % (frame),
79 "--output=" + trim_file, trace_file])
81 print "An error occurred while trimming " + \
82 "frame %d from %s" % (frame, trace_file)
85 subprocess.check_call([self.options.apitrace,
86 "dump-images", "--call-nos=no",
87 "--output=" + tmp_out_dir + "frame",
90 print "An error occurred replaying " + \
91 "%s to generate a frame snapshot" % (trim_file)
93 os.rename("%s/frame0000000000.png" % (tmp_out_dir),
94 "%s/%010d.png" % (tmp_out_dir, frame))
96 subprocess.check_call([self.options.apitrace,
98 ref_dir, tmp_out_dir])
100 print "Trimmed frame did not match " + \
101 "reference images. See " + name + "-index.html"
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))
108 subprocess.check_call([self.options.apitrace,
109 "diff-images", "-v", ref_dir, out_dir])
111 print "Trimmed frame did not match " + \
112 "reference images. See " + name + "-index.html"
115 os.rename("index.html", name + "-index.html")
120 self.trim_stress(self.args[0])
124 if __name__ == '__main__':
125 TrimStressDriver().run()