-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_suite.py
executable file
·53 lines (40 loc) · 1.48 KB
/
test_suite.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
#!/usr/bin/python3
import sys
import os
import subprocess
from tqdm import tqdm
import glob
BIN_DIR = 'testing/bin'
CODE_DIR = 'testing/code'
if not os.path.isdir(BIN_DIR):
os.mkdir(BIN_DIR)
code_files = glob.glob(f'{CODE_DIR}/*.c')
success = 0
total = len(code_files)
for fn in tqdm(code_files):
bin_base = fn.split('/')[-1].split('.')[0]
bin_path = f'{BIN_DIR}/{bin_base}'
c_r = subprocess.check_call(
f'aarch64-linux-gnu-gcc -march=armv8.3-a -S -o - {fn}' # make Arm64 assembly
f'| python3 arm2riscv.py' # transpile
f'| riscv64-linux-gnu-gcc -x assembler - -pthread -static -o {bin_path}_transpiled.out', # linker stage
shell=True)
if c_r != 0:
print('failed on build', fn)
exit(1)
tflag = '-pthread' if 'thread' in fn else ''
subprocess.check_call(f'aarch64-linux-gnu-gcc {fn} -march=armv8.3-a -static {tflag} -o {bin_path}_basic.out', shell=True)
transpiled = subprocess.check_output(f'qemu-riscv64-static {bin_path}_transpiled.out', shell=True)
basic = subprocess.check_output(f'qemu-aarch64-static {bin_path}_basic.out', shell=True)
if transpiled == basic:
success += 1
else:
tqdm.write(f'failed test {fn}')
# diffs.append([fn, basic, transpiled])
print(f'Passed {success} / {total} tests')
# for fn, reference, transpiled in diffs:
# print(f'Failed test: {fn}')
# print('Should have been:')
# print(str(reference))
# print('Was:')
# print(str(transpiled))