-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path_check.py
82 lines (65 loc) · 2.9 KB
/
_check.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
import subprocess
import time
from subprocess import PIPE
def run(cmd: str | list[str]):
stime = time.time()
cmd = " ".join(cmd) if isinstance(cmd, list) else cmd
res = subprocess.run(f"sh -c '{cmd}'", shell=True, text=True, stdout=PIPE, stderr=PIPE)
assert res.returncode == 0, f"Failed to run command: {cmd}"
return res.stdout, time.time() - stime
def parse_final(out: str):
out = [x for x in out.split("\n") if "it/s ~" in x][-1]
return out.split(" ~ ")[-1].replace(",", "").strip()
def check_add(hosts: list[str]):
out, elapsed = run(["make", "mul"])
ref_out = parse_final(out)
ref_addr33 = set([x.strip() for x in out.split("\n") if x.startswith("addr33:")])
ref_addr65 = set([x.strip() for x in out.split("\n") if x.startswith("addr65:")])
print(f">>> running cmd=add as ref ~ {elapsed:.2f}s")
for host in hosts:
print(f">>> running cmd=add {host}... ", end="")
out, elapsed = run(["make", "check-remote", f"host={host}", "cmd=mul"])
out = parse_final(out)
addr33 = set([x.strip() for x in out.split("\n") if x.startswith("addr33:")])
addr65 = set([x.strip() for x in out.split("\n") if x.startswith("addr65:")])
if ref_out == out and ref_addr33 == addr33 and ref_addr65 == addr65:
print(f"ok ~ {elapsed:.2f}s")
else:
print(f"failed ~ {elapsed:.2f}s")
print(f"{ref_out=} != {out=}") if out != ref_out else None
print(f"{ref_addr33=} != {addr33=}") if addr33 != ref_addr33 else None
print(f"{ref_addr65=} != {addr65=}") if addr65 != ref_addr65 else None
def check_mul(hosts: list[str]):
out, elapsed = run(["make", "mul"])
ref_out = parse_final(out)
print(f">>> running cmd=mul as ref ~ {elapsed:.2f}s")
for host in hosts:
print(f">>> running cmd=mul {host}... ", end="")
out, elapsed = run(["make", "check-remote", f"host={host}", "cmd=mul"])
out = parse_final(out)
if ref_out == out:
print(f"ok ~ {elapsed:.2f}s")
else:
print(f"failed ~ {elapsed:.2f}s")
print(f"{ref_out=} != {out=}") if out != ref_out else None
def check_blf(hosts: list[str]):
out, elapsed = run(["make", "blf"])
ref_out = parse_final(out)
print(f">>> running cmd=blf as ref ~ {elapsed:.2f}s")
for host in hosts:
print(f">>> running cmd=blf {host}... ", end="")
out, elapsed = run(["make", "check-remote", f"host={host}", "cmd=blf"])
out = parse_final(out)
if ref_out == out:
print(f"ok ~ {elapsed}s")
else:
print(f"failed ~ {elapsed}s")
print(f"{ref_out=} != {out=}") if out != ref_out else None
def main():
hosts = ["user@colima", "[email protected]"]
funcs = [check_add, check_mul, check_blf]
for func in funcs:
print(f"--- {func.__name__} ---")
func(hosts)
if __name__ == "__main__":
main()