-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-bw-test.py
75 lines (63 loc) · 2.65 KB
/
build-bw-test.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 argparse
import subprocess
import os
import shutil
import random
CC=["riscv64-unknown-elf-gcc"]
CFLAGS=["-static", "-specs=htif_nano.specs", "-Wall", "-O2", "-fno-common", "-fno-builtin-printf", "-Icommon/"]
def compile(source_name, target_name, macros):
macro_flags = ["-D{}={}".format(name, macros[name]) for name in macros]
command = CC + CFLAGS + macro_flags + ["-o", target_name, source_name]
print(' '.join(command))
return subprocess.call(command)
def mac_to_hex(macaddr):
return '0x' + ''.join(reversed(macaddr.split(":")))
def ltoa(i):
return str(i) + "L"
MAC_TEMPLATE = "00:12:6D:00:00:{:02x}"
def main():
if os.path.isdir("testbuild"):
shutil.rmtree("testbuild")
os.makedirs("testbuild")
parser = argparse.ArgumentParser(description="Build client and server binaries")
parser.add_argument(
"-n", "--num-pairs", type=int, default=8)
parser.add_argument(
"-c", "--num-packets", type=int, default=100)
parser.add_argument(
"-w", "--packet-words", type=int, default=180)
parser.add_argument(
"-s", "--cycle-step", type=int, default=100000000)
args = parser.parse_args()
all_macs = [MAC_TEMPLATE.format(i) for i in range(2, 2 + 2 * args.num_pairs)]
server_macs = all_macs[args.num_pairs:]
client_macs = all_macs[:args.num_pairs]
end_cycle = (args.num_pairs + 1) * args.cycle_step
server_wait = args.num_pairs * args.cycle_step
client_wait = server_wait + 2 * args.cycle_step
client_server = list(range(args.num_pairs, 2 * args.num_pairs))
random.shuffle(client_server)
for (client_id, client_mac) in enumerate(client_macs):
server_id = client_server[client_id]
server_mac = all_macs[server_id]
SERVER_BASE = "testbuild/bw-test-server-{}".format(server_id)
CLIENT_BASE = "testbuild/bw-test-client-{}".format(client_id)
print("Client {} to Server {}".format(client_id, server_id))
compile(
"bw-test/server.c",
SERVER_BASE + ".riscv",
{"CLIENT_MACADDR": mac_to_hex(client_mac),
"NPACKETS": args.num_packets,
"PACKET_WORDS": args.packet_words,
"END_CYCLE": ltoa(end_cycle + server_wait)})
compile(
"bw-test/client.c",
CLIENT_BASE + ".riscv",
{"SERVER_MACADDR": mac_to_hex(server_mac),
"NPACKETS": args.num_packets,
"PACKET_WORDS": args.packet_words,
"START_CYCLE": ltoa((client_id + 1) * args.cycle_step),
"END_CYCLE": ltoa(end_cycle),
"WAIT_CYCLES": ltoa(client_wait)})
if __name__ == "__main__":
main()