-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
223 lines (205 loc) · 7.73 KB
/
main.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import pyautogui
import requests
import os
import zipfile
import subprocess
import time
import PIL.Image
import PIL.ImageChops
import sys
import argparse
import json
import traceback
import testroms.blarg
import testroms.mooneye
import testroms.acid
import testroms.samesuite
import testroms.ax6
import testroms.daid
import testroms.hacktix
import testroms.cpp
import testroms.mealybug
from emulators.kigb import KiGB
from emulators.bgb import BGB
from emulators.vba import VBA, VBAM
from emulators.mgba import MGBA
from emulators.sameboy import SameBoy
from emulators.nocash import NoCash
from emulators.gambatte import GambatteSpeedrun
from emulators.emulicious import Emulicious
from emulators.bdm import BDM
from emulators.higan import Higan
from emulators.goomba import Goomba
from emulators.binjgb import Binjgb
from emulators.pyboy import PyBoy
from emulators.ares import Ares
from emulators.emmy import Emmy
from emulators.gameroy import GameRoy
from util import *
from test import *
emulators = [
BDM(),
MGBA(), # Black screen on github actions
KiGB(), # Crashes on github actions
SameBoy(),
BGB(),
VBA(),
VBAM(),
NoCash(),
GambatteSpeedrun(),
Emulicious(),
# Higan(), # Crashes all over the place.
Goomba(),
Binjgb(),
PyBoy(),
Ares(),
Emmy(),
GameRoy(),
]
tests = testroms.acid.all + testroms.blarg.all + testroms.daid.all + testroms.ax6.all + testroms.mooneye.all + testroms.samesuite.all + testroms.hacktix.all + testroms.cpp.all + testroms.mealybug.all
def checkFilter(input, filter_data):
if filter_data is None:
return True
input = str(input)
# if there is at least one !QUERY, a value not matching any of the negative
# querys will be accepted.
out_filter = False
for f in filter_data:
if f.startswith("!"):
out_filter = True
if f[1:] in input:
return False
if out_filter:
return True
# if there are no !QUERY, a value matching any of the querys will be
# accpeted.
for f in filter_data:
if not f.startswith("!"):
if f in input:
return True
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--test', action='append', help="Filter for tests with keywords")
parser.add_argument('--emulator', action='append', help="Filter to test only emulators with keywords")
parser.add_argument('--model', action='append', help="Filter for tests of given model")
parser.add_argument('--get-runtime', action='store_true')
parser.add_argument('--get-startuptime', action='store_true')
parser.add_argument('--dump-emulators-json', action='store_true')
parser.add_argument('--dump-tests-json', action='store_true')
args = parser.parse_args()
for model in args.model or []:
if model not in ["DMG", "CGB", "SGB"]:
print("Model %s is invalid. Only DMG, CGB and SGB are valid models")
exit(1)
tests = [
test
for test in tests
if checkFilter(test, args.test) and checkFilter(test.model, args.model)
]
emulators = [emulator for emulator in emulators if checkFilter(emulator, args.emulator)]
print("%d emulators" % (len(emulators)))
print("%d tests" % (len(tests)))
if args.get_runtime:
for emulator in emulators:
emulator.setup()
for test in tests:
if not checkFilter(test, args.test):
continue
print("%s: %s: %g seconds" % (emulator, test, emulator.getRunTimeFor(test)))
emulator.undoSetup()
sys.exit()
if args.dump_emulators_json:
json.dump({
str(emulator): {
"file": emulator.getJsonFilename(),
"url": emulator.url,
} for emulator in emulators
}, open("emulators.json", "wt"), indent=" ")
if args.dump_tests_json:
json.dump([
{
'name': str(test),
'description': test.description,
'url': test.url,
} for test in tests
], open("tests.json", "wt"), indent=" ")
if args.dump_tests_json or args.dump_emulators_json:
sys.exit()
if args.get_startuptime:
f = open("startuptime.html", "wt")
f.write("<html><body>\n")
for emulator in emulators:
try:
emulator.setup()
dmg_start_time, dmg_screenshot = emulator.measureStartupTime(model=DMG)
gbc_start_time, gbc_screenshot = emulator.measureStartupTime(model=CGB)
sgb_start_time, sgb_screenshot = emulator.measureStartupTime(model=SGB)
if dmg_screenshot is not None:
print("Startup time: %s = %g (dmg)" % (emulator, dmg_start_time or 0.0))
f.write("%s (dmg)<br>\n<img src='data:image/png;base64,%s'><br>\n" % (emulator, imageToBase64(dmg_screenshot)))
if gbc_screenshot is not None:
print("Startup time: %s = %g (gbc)" % (emulator, gbc_start_time or 0.0))
f.write("%s (gbc)<br>\n<img src='data:image/png;base64,%s'><br>\n" % (emulator, imageToBase64(gbc_screenshot)))
if sgb_screenshot is not None:
print("Startup time: %s = %g (sgb)" % (emulator, sgb_start_time or 0.0))
f.write("%s (sgb)<br>\n<img src='data:image/png;base64,%s'><br>\n" % (emulator, imageToBase64(sgb_screenshot)))
emulator.undoSetup()
except Exception as e:
print(f'Exception while running {emulator}')
traceback.print_exc()
f.write("%s: <br>\n<pre>%s</pre>\n<br>\n" % (emulator, traceback.format_exc()))
f.write("</body></html>")
sys.exit()
results = {}
for emulator in emulators:
results[emulator] = {}
try:
emulator.setup()
except Exception:
print(f'Exception while setting up {emulator}')
traceback.print_exc()
continue
for test in tests:
skip = False
for feature in test.required_features:
if feature not in emulator.features:
skip = True
print("Skipping %s on %s because of missing feature %s" % (test, emulator, feature))
if not skip:
try:
result = emulator.run(test)
if result is not None:
results[emulator][test] = result
except KeyboardInterrupt:
exit(0)
except:
print("Emulator %s failed to run properly" % (emulator))
traceback.print_exc()
emulator.undoSetup()
emulators.sort(key=lambda emulator: len([result[0] for result in results[emulator].values() if result.result != "FAIL"]), reverse=True)
for emulator in emulators:
def toBase64(data):
if data is None:
return ''
try:
return imageToBase64(data)
except:
print(f'Exception while converting image to base64')
traceback.print_exc()
return ''
data = {
'emulator': str(emulator),
'date': time.time(),
'tests': {
str(test): {
'result': result.result,
'startuptime': result.startuptime,
'runtime': result.runtime,
'screenshot': toBase64(result.screenshot)
}
for test, result in results[emulator].items()
},
}
if results[emulator]:
json.dump(data, open(emulator.getJsonFilename(), "wt"), indent=" ")