-
Notifications
You must be signed in to change notification settings - Fork 2k
/
installers.py
147 lines (122 loc) · 4.84 KB
/
installers.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from __future__ import annotations
import json
import subprocess
import sys
import tempfile
from typing import Dict, List, Optional, Sequence
import click
import packaging.version
from chia.daemon.server import executable_for_service
from chia.util.timing import adjusted_timeout
def check_plotter(plotter: List[str], expected_output: bytes, specify_tmp: bool = True) -> None:
with tempfile.TemporaryDirectory() as path:
tmp_dir = []
if specify_tmp:
tmp_dir = ["--tmp_dir", path]
process = subprocess.Popen(
[executable_for_service("chia"), "plotters", *plotter, *tmp_dir, "--final_dir", path],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
out: Optional[bytes]
err: Optional[bytes]
try:
out, err = process.communicate(timeout=2)
except subprocess.TimeoutExpired as e:
err = e.stderr
out = e.stdout
else:
print(repr(err))
print(repr(out))
assert False, "expected to time out"
finally:
process.kill()
process.communicate()
assert err is None, repr(err)
assert out is not None
assert out.startswith(expected_output), repr(out)
@click.group("installers", help="Installer related helpers such as installer testing")
def installers_group() -> None:
pass
@installers_group.command(name="test")
@click.option("--expected-chia-version", "expected_chia_version_str", required=True)
@click.option("--require-madmax/--require-no-madmax", "require_madmax", default=True)
@click.option("--gui-command", multiple=True)
def test_command(expected_chia_version_str: str, require_madmax: bool, gui_command: Sequence[str]) -> None:
print("testing installed executables")
expected_chia_version = packaging.version.Version(expected_chia_version_str)
args = [executable_for_service("chia"), "version"]
print(f"launching: {args}")
chia_version_process = subprocess.run(
args,
capture_output=True,
encoding="utf-8",
timeout=adjusted_timeout(30),
)
assert chia_version_process.returncode == 0
assert chia_version_process.stderr == ""
chia_version = packaging.version.Version(chia_version_process.stdout)
print(chia_version)
assert chia_version == expected_chia_version, f"{chia_version} != {expected_chia_version}"
args = [executable_for_service("chia"), "plotters", "version"]
print(f"launching: {args}")
plotter_version_process = subprocess.run(
args,
capture_output=True,
encoding="utf-8",
timeout=adjusted_timeout(30),
)
print()
print(plotter_version_process.stdout)
print()
print(plotter_version_process.stderr)
print()
assert plotter_version_process.returncode == 0
assert plotter_version_process.stderr == ""
found_start = False
plotter_versions: Dict[str, packaging.version.Version] = {}
for line in plotter_version_process.stdout.splitlines():
if line.startswith("chiapos:"):
found_start = True
if not found_start:
continue
plotter, version = (segment.strip() for segment in line.split(":", maxsplit=1))
plotter_versions[plotter] = packaging.version.Version(version)
print(json.dumps({plotter: str(version) for plotter, version in plotter_versions.items()}, indent=4))
expected = {"chiapos", "bladebit"}
if require_madmax:
expected.add("madmax")
assert plotter_versions.keys() == expected, f"{expected=}"
# TODO: figure out a better test, these actually start plots which can use up disk
# space too fast
# check_plotter(plotter=["chiapos"], expected_output=b"\nStarting plotting progress")
# check_plotter(plotter=["madmax"], expected_output=b"Multi-threaded pipelined Chia")
# check_plotter(plotter=["bladebit", "diskplot", "--compress", "0"], expected_output=b"\nBladebit Chia Plotter")
# check_plotter(plotter=["bladebit", "cudaplot", "--compress", "0"], expected_output=b"\nBladebit Chia Plotter")
# check_plotter(
# plotter=["bladebit", "ramplot", "--compress", "0"],
# expected_output=b"\nBladebit Chia Plotter",
# specify_tmp_dir=False,
# )
args = [executable_for_service("chia"), "init"]
print(f"launching: {args}")
subprocess.run(
args,
check=True,
timeout=adjusted_timeout(30),
)
if len(gui_command) == 0:
print("skipping gui launch test")
else:
print(f"launching: {gui_command}")
sys.stdout.flush()
try:
subprocess.run(
args=gui_command,
check=True,
timeout=adjusted_timeout(30),
)
except subprocess.TimeoutExpired:
pass
else:
raise Exception("process terminated prior to timeout")