X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=blobdiff_plain;f=trim_stress_driver.py;h=048062a1f9d92d48cf4f25dfeb3c6eb3ce87b4e2;hp=5b10f146acfd025590cf5b6dc655200f205a50aa;hb=8351c1e187d8f65477db05a07bacd5d184c2b950;hpb=9959d37f389caf62a4869de0e9fd25af98f716ca diff --git a/trim_stress_driver.py b/trim_stress_driver.py index 5b10f14..048062a 100644 --- a/trim_stress_driver.py +++ b/trim_stress_driver.py @@ -22,9 +22,9 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -'''Stress test driver for apitrace trimp.''' +'''Stress test driver for apitrace trim.''' -import os, errno, shutil, subprocess +import os, errno, re, shutil, subprocess from base_driver import * @@ -50,13 +50,18 @@ class TrimStressDriver(Driver): (name, extension) = file_name.rsplit('.', 1) ref_dir = name + '-ref/' + tmp_out_dir = name + '-tmp-out/' out_dir = name + '-out/' trim_file = name + '.trace.trim' - rm_and_mkdir(ref_dir) rm_and_mkdir(out_dir) + rm_and_mkdir(tmp_out_dir) - subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + ref_dir, trace_file]); + if (not os.path.exists(ref_dir)): + rm_and_mkdir(ref_dir) + subprocess.check_call([self.options.apitrace, + "dump-images", "--call-nos=no", + "--output=" + ref_dir, trace_file]); # Count the number of frame snapshots generated frames = 0 @@ -64,25 +69,50 @@ class TrimStressDriver(Driver): # Don't descend into any sub-directories (not that there # should be any) del dirs[:] + pattern = re.compile("[0-9]*\.png") + def f(x): return re.match(pattern, x) + files = filter(f, files) frames = len(files) for frame in range(frames): try: - subprocess.check_call([self.options.apitrace, "trim", "--frame=%d" % (frame), "--output=" + trim_file, trace_file]) + subprocess.check_call([self.options.apitrace, + "trim", "--auto", + "--frame=%d/frame" % (frame), + "--output=" + trim_file, trace_file]) except: - print "An error occurred while trimming frame %d from %s" % (frame, trace_file) + print "An error occurred while trimming " + \ + "frame %d from %s" % (frame, trace_file) fail() try: - subprocess.check_call([self.options.apitrace, "dump-images", "--call-nos=no", "--output=" + out_dir + "frame", trim_file]) + subprocess.check_call([self.options.apitrace, + "dump-images", "--call-nos=no", + "--output=" + tmp_out_dir + "frame", + trim_file]) except: - print "An error occurred replaying %s to generate a frame snapshot" % (trim_file) + print "An error occurred replaying " + \ + "%s to generate a frame snapshot" % (trim_file) fail() - os.rename("%s/frame0000000000.png" % (out_dir), "%s/%010d.png" % (out_dir, frame)) - + os.rename("%s/frame0000000000.png" % (tmp_out_dir), + "%s/%010d.png" % (tmp_out_dir, frame)) + try: + subprocess.check_call([self.options.apitrace, + "diff-images", "-v", + ref_dir, tmp_out_dir]) + except: + print "Trimmed frame did not match " + \ + "reference images. See " + name + "-index.html" + fail() + finally: + os.rename("index.html", name + "-index.html") + os.rename("%s/%010d.png" % (tmp_out_dir, frame), + "%s/%010d.png" % (out_dir, frame)) try: - subprocess.check_call([self.options.apitrace, "diff-images", "-v", ref_dir, out_dir]) + subprocess.check_call([self.options.apitrace, + "diff-images", "-v", ref_dir, out_dir]) except: - print "Trimmed frames did not match reference images. See " + name + "-index.html" + print "Trimmed frame did not match " + \ + "reference images. See " + name + "-index.html" fail() finally: os.rename("index.html", name + "-index.html")