-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
129 lines (110 loc) · 4.16 KB
/
cli.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
import click
import pathlib
import os
import signal
import subprocess
import shutil
import time
from threading import Thread
VITA3K_PATH = os.environ.get('VITA3K_PATH')
VITA3K_ENV_PATH = os.environ.get('VITA3K_DATA')
print("VITA3K_PATH: ", VITA3K_PATH)
print("VITA3K_DATA: ", VITA3K_ENV_PATH)
@click.group()
def ftvg():
pass
def waiter_thread(testname):
while True:
from os import listdir
from os.path import isfile, join
mypath = os.path.join('tests', testname, 'res')
ftvg_path = os.path.join(VITA3K_ENV_PATH, 'ux0', 'data', 'ftvg')
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
noexit = False
for file in onlyfiles:
if not os.path.exists(os.path.join(ftvg_path, 'res', file)):
noexit = True
if not noexit:
return
time.sleep(0.5)
import re
CRITERIA = 3
import struct
vertex_pat = re.compile(r'vertex ([0-9]+):\n(o.+)')
o_reg_pat = re.compile(r'o([0-9]+): ([0-9a-z]+)')
vertex_pat2 = re.compile(r'vertex ([0-9]+):\n(p.+)')
pa_reg_pat = re.compile(r'pa([0-9]+): ([0-9a-z]+)')
def get_pa_regs(text):
out = dict()
for (vnum, oregs) in re.findall(vertex_pat2, text):
item = dict()
for (onum, val) in re.findall(pa_reg_pat, oregs):
if val == '0':
item[onum] = 0
else:
item[onum] = struct.unpack('!f', bytes.fromhex(val))[0]
out[vnum] = item
return out
def get_o_regs(text):
out = dict()
for (vnum, oregs) in re.findall(vertex_pat, text):
item = dict()
for (onum, val) in re.findall(o_reg_pat, oregs):
item[onum] = int(val, base=16)
out[vnum] = item
return out
@ftvg.command()
@click.argument('testname')
def test(testname):
ftvg_path = os.path.join(VITA3K_ENV_PATH, 'ux0', 'data', 'ftvg')
if os.path.exists(ftvg_path):
shutil.rmtree(ftvg_path)
os.mkdir(ftvg_path)
shutil.copytree(os.path.join('tests', testname, 'gxp'), os.path.join(ftvg_path, 'gxp'))
shutil.copytree(os.path.join('tests', testname, 'input'), os.path.join(ftvg_path, 'input'))
os.mkdir(os.path.join(ftvg_path, 'res'))
pro = subprocess.Popen([os.path.join(VITA3K_PATH, 'Vita3K'), '-r', 'FTVGWK000'], cwd=VITA3K_PATH)
waiter = Thread(target=waiter_thread, args=(testname,))
waiter.start()
waiter.join()
from os import listdir
from os.path import isfile, join
mypath = os.path.join('tests', testname, 'res')
ftvg_path = os.path.join(VITA3K_ENV_PATH, 'ux0', 'data', 'ftvg')
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
maxo = 1000
if os.path.exists(os.path.join('tests', testname, 'regs.txt')):
with open(os.path.join('tests', testname, 'regs.txt')) as f:
maxo = int(f.read().replace('o0-o', ''))
total = 0
pass_total = 0
for file in onlyfiles:
wrongs = list()
passed = True
with open(os.path.join(ftvg_path, 'res', file)) as f:
with open(os.path.join(mypath, file)) as f2:
buf = f.read()
calculated = get_o_regs(buf)
expexted = get_o_regs(f2.read())
inputs = get_pa_regs(buf)
# for i in range(0,4):
# for j in range(8,21):
# wrongs.append('vertex {} pa{}: {}'.format(i, j, inputs[str(i)][str(j)]))
#pa0.xyzw, pa8.xyzw, pa12.xyzw, pa16.xyzw
for v, item in calculated.items():
for o, val in item.items():
if int(o) > maxo:
break
if abs(val - expexted[v][o]) > CRITERIA:
passed = False
wrongs.append('vertex {} o{} calculated: {} expexted: {}'.format(v, o, val, expexted[v][o]))
total += 1
if not passed:
print('test {} did not pass\n------------------\n{}\n\n'.format(file, '\n'.join(wrongs)))
else:
pass_total += 1
print('{} passed in {} test cases'.format(pass_total, total))
pro.send_signal(signal.CTRL_BREAK_EVENT)
pro.kill()
if __name__ == '__main__':
ftvg()