forked from apitrace/apitrace-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trim_stress_driver.py
127 lines (107 loc) · 4.8 KB
/
trim_stress_driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# Copyright 2012 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
'''Stress test driver for apitrace trim.'''
import os, errno, re, shutil, subprocess
from base_driver import *
def rm_and_mkdir(dir):
# Operate only on local directories
dir = './' + dir
# Failing to delete a directory that doesn't exist is no failure
def rmtree_onerror(function, path, excinfo):
if excinfo[0] == OSError and excinfo[1].errno != errno.ENOENT:
raise
shutil.rmtree(dir, onerror = rmtree_onerror)
os.makedirs(dir)
class TrimStressDriver(Driver):
def trim_stress(self, trace_file):
"Execute an apitrace-trim stress test for the given trace."
(dir, file_name) = os.path.split(trace_file)
(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(out_dir)
rm_and_mkdir(tmp_out_dir)
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
for dirpath, dirs, files in os.walk(ref_dir):
# 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", "--auto",
"--frame=%d/frame" % (frame),
"--output=" + trim_file, trace_file])
except:
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=" + tmp_out_dir + "frame",
trim_file])
except:
print "An error occurred replaying " + \
"%s to generate a frame snapshot" % (trim_file)
fail()
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",
"-o", name + "-index.html",
ref_dir, tmp_out_dir])
except:
print "Trimmed frame did not match " + \
"reference images. See " + name + "-index.html"
fail()
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",
"-o", name + "-index.html",
ref_dir, out_dir])
except:
print "Trimmed frame did not match " + \
"reference images. See " + name + "-index.html"
fail()
def run(self):
self.parseOptions()
self.trim_stress(self.args[0])
pass_()
if __name__ == '__main__':
TrimStressDriver().run()