-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerate_tests.py
75 lines (58 loc) · 2.42 KB
/
generate_tests.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
import json
import os
import struct
from argparse import ArgumentParser
class TestCase:
def __init__(self, key, value):
self.name = str.encode(key) + b'\x00'
self.rkgPath = str.encode("../"+value["rkgPath"]) + b'\x00'
self.krkgPath = str.encode("../"+value["krkgPath"]) + b'\x00'
self.targetFrame = value["targetFrame"]
def generate_tests(filename = 'testCases.json', out_filename = 'out/testCases.bin'):
# Parse test cases from JSON
tests = []
with open(filename) as f:
data = json.load(f)
for key, value in data.items():
tests.append(TestCase(key, value))
TEST_CASE_HEADER = b'TSTH'
TEST_CASE_FOOTER = b'TSTF'
BINARY_VER_MAJOR = 1
BINARY_VER_MINOR = 0
# Generate binary (enforce big-endian)
os.makedirs("out", exist_ok=True)
with open(out_filename, 'wb') as f:
# Number of test cases
f.write(struct.pack('>H', len(tests)))
# Major version
f.write(struct.pack('>H', BINARY_VER_MAJOR))
# Minor version
f.write(struct.pack('>H', BINARY_VER_MINOR))
for test in tests:
# Alignment check header
f.write(struct.pack('>4s', TEST_CASE_HEADER))
# Total memory size for this test case (excluding header/footer)
nameLen = len(test.name)
rkgLen = len(test.rkgPath)
krkgLen = len(test.krkgPath)
totalSize = 2 + nameLen + 2 + rkgLen + 2 + krkgLen + 2
f.write(struct.pack('>H', totalSize))
# Test name
f.write(struct.pack('>H', nameLen))
f.write(struct.pack('>' + str(nameLen) + 's', test.name))
# RKG
f.write(struct.pack('>H', rkgLen))
f.write(struct.pack('>' + str(rkgLen) + 's', test.rkgPath))
# KRKG
f.write(struct.pack('>H', krkgLen))
f.write(struct.pack('>' + str(krkgLen) + 's', test.krkgPath))
# Total frames of run sync expected
f.write(struct.pack('>H', test.targetFrame))
# Alignment check footer
f.write(struct.pack('<4s', TEST_CASE_FOOTER))
if __name__ == '__main__':
parser = ArgumentParser(description="Generate test cases binary file")
parser.add_argument('input', help="Path to the .json file")
parser.add_argument('output', help="Path to the .bin file")
args = parser.parse_args()
generate_tests(args.input, args.output)