forked from overviewer/Minecraft-Overviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testRender.py
161 lines (140 loc) · 5.19 KB
/
testRender.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/python
"Test Render Script"
import os, shutil, tempfile, time, sys, math, re
from subprocess import Popen, PIPE, STDOUT, CalledProcessError
from optparse import OptionParser
overviewer_scripts = ['./overviewer.py', './gmap.py']
def check_call(*args, **kwargs):
quiet = False
if "quiet" in kwargs.keys():
quiet = kwargs["quiet"]
del kwargs["quiet"]
if quiet:
kwargs['stdout'] = PIPE
kwargs['stderr'] = STDOUT
p = Popen(*args, **kwargs)
output = ""
if quiet:
while p.poll() == None:
output += p.communicate()[0]
returncode = p.wait()
if returncode:
if quiet:
print output
raise CalledProcessError(returncode, args)
return returncode
def check_output(*args, **kwargs):
kwargs['stdout'] = PIPE
# will hang for HUGE output... you were warned
p = Popen(*args, **kwargs)
returncode = p.wait()
if returncode:
raise CalledProcessError(returncode, args)
return p.communicate()[0]
def clean_render(overviewerargs, quiet):
tempdir = tempfile.mkdtemp('mc-overviewer-test')
overviewer_script = None
for script in overviewer_scripts:
if os.path.exists(script):
overviewer_script = script
break
if overviewer_script is None:
sys.stderr.write("could not find main overviewer script\n")
sys.exit(1)
try:
# check_call raises CalledProcessError when overviewer.py exits badly
check_call([sys.executable, 'setup.py', 'clean', 'build'], quiet=quiet)
try:
check_call([sys.executable, overviewer_script, '-d'] + overviewerargs, quiet=quiet)
except CalledProcessError:
pass
starttime = time.time()
check_call([sys.executable, overviewer_script,] + overviewerargs + [tempdir,], quiet=quiet)
endtime = time.time()
return endtime - starttime
finally:
shutil.rmtree(tempdir, True)
def get_stats(timelist):
stats = {}
stats['count'] = len(timelist)
stats['minimum'] = min(timelist)
stats['maximum'] = max(timelist)
stats['average'] = sum(timelist) / float(len(timelist))
meandiff = map(lambda x: (x - stats['average'])**2, timelist)
stats['standard deviation'] = math.sqrt(sum(meandiff) / float(len(meandiff)))
return stats
commitre = re.compile('^commit ([a-z0-9]{40})$', re.MULTILINE)
branchre = re.compile('^\\* (.+)$', re.MULTILINE)
def get_current_commit():
gittext = check_output(['git', 'branch'])
match = branchre.search(gittext)
if match and not ("no branch" in match.group(1)):
return match.group(1)
gittext = check_output(['git', 'show', 'HEAD'])
match = commitre.match(gittext)
if match == None:
return None
return match.group(1)
def get_commits(gitrange):
gittext = check_output(['git', 'log', '--raw', '--reverse', gitrange])
for match in commitre.finditer(gittext):
yield match.group(1)
def set_commit(commit):
check_call(['git', 'checkout', commit], quiet=True)
parser = OptionParser(usage="usage: %prog [options] -- [overviewer options/world]")
parser.add_option("-n", "--number", metavar="N",
action="store", type="int", dest="number", default=3,
help="number of renders per commit [default: 3]")
parser.add_option("-c", "--commits", metavar="RANGE",
action="append", type="string", dest="commits", default=[],
help="the commit (or range of commits) to test [default: current]")
parser.add_option("-v", "--verbose",
action="store_false", dest="quiet", default=True,
help="don't suppress overviewer output")
parser.add_option("-k", "--keep-going",
action="store_false", dest="fatal_errors", default=True,
help="don't stop testing when Overviewer croaks")
parser.add_option("-l", "--log", dest="log", default="", metavar="FILE",
help="log all test results to a file")
(options, args) = parser.parse_args()
if len(args) == 0:
parser.print_help()
sys.exit(0)
commits = []
for commit in options.commits:
if '..' in commit:
commits = get_commits(commit)
else:
commits.append(commit)
if not commits:
commits = [get_current_commit(),]
log = None
if options.log != "":
log = open(options.log, "w")
reset_commit = get_current_commit()
try:
for commit in commits:
print "testing commit", commit
set_commit(commit)
timelist = []
print " -- ",
try:
for i in range(options.number):
sys.stdout.write(str(i+1)+" ")
sys.stdout.flush()
timelist.append(clean_render(args, options.quiet))
print "... done"
stats = get_stats(timelist)
print stats
if log:
log.write("%s %s\n" % (commit, repr(stats)))
except CalledProcessError, e:
if options.fatal_errors:
print
print "Overviewer croaked, exiting..."
print "(to avoid this, use --keep-going)"
sys.exit(1)
finally:
set_commit(reset_commit)
if log:
log.close()