-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_rust_native_kernel_bridge.py
More file actions
332 lines (305 loc) · 12.3 KB
/
check_rust_native_kernel_bridge.py
File metadata and controls
332 lines (305 loc) · 12.3 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python3
"""Build and test Rust dynamic loading of LLVM-produced native kernels."""
from __future__ import annotations
import json
import shutil
import subprocess
import sys
from pathlib import Path
from build_native_kernel_library import build_native_kernel_library, shared_library_suffix
ROOT = Path(__file__).resolve().parents[3]
BUILD_DIR = ROOT / "b" / "rsn"
RUST_DIR = ROOT / "Implementations/Reference/Runtime/rust"
EXAMPLE05_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/05_bounded_ui_accumulator/native_kernel_manifest.json"
EXAMPLE06_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/06_boolean_value_roundtrip/native_kernel_manifest.json"
EXAMPLE07_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/07_string_value_roundtrip/native_kernel_manifest.json"
EXAMPLE08_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/08_enum_value_roundtrip/native_kernel_manifest.json"
EXAMPLE09_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/09_path_value_roundtrip/native_kernel_manifest.json"
EXAMPLE10_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/10_button_press_to_boolean/native_kernel_manifest.json"
EXAMPLE11_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/11_button_switch_when_pressed/native_kernel_manifest.json"
EXAMPLE12_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/12_button_switch_when_released/native_kernel_manifest.json"
EXAMPLE13_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/13_button_latch_when_pressed/native_kernel_manifest.json"
EXAMPLE14_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/14_button_latch_when_released/native_kernel_manifest.json"
EXAMPLE15_MANIFEST = ROOT / "Implementations/Reference/LLVM/examples/15_button_latch_until_released/native_kernel_manifest.json"
def require_tool(name: str) -> None:
if shutil.which(name) is None:
raise RuntimeError(f"required tool not found on PATH: {name}")
def run(command: list[str], *, cwd: Path = ROOT) -> subprocess.CompletedProcess[str]:
print("$ " + " ".join(command))
result = subprocess.run(command, cwd=cwd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
if result.stdout:
print(result.stdout.rstrip())
if result.stderr:
print(result.stderr.rstrip(), file=sys.stderr)
if result.returncode != 0:
raise RuntimeError(f"command failed with exit {result.returncode}: {' '.join(command)}")
return result
def main() -> int:
try:
require_tool("cargo")
library05 = build_native_kernel_library(
manifest_path=EXAMPLE05_MANIFEST,
output_path=BUILD_DIR / f"example05_kernel{shared_library_suffix()}",
)
library06 = build_native_kernel_library(
manifest_path=EXAMPLE06_MANIFEST,
output_path=BUILD_DIR / f"example06_kernel{shared_library_suffix()}",
)
library07 = build_native_kernel_library(
manifest_path=EXAMPLE07_MANIFEST,
output_path=BUILD_DIR / f"example07_kernel{shared_library_suffix()}",
)
library08 = build_native_kernel_library(
manifest_path=EXAMPLE08_MANIFEST,
output_path=BUILD_DIR / f"example08_kernel{shared_library_suffix()}",
)
library09 = build_native_kernel_library(
manifest_path=EXAMPLE09_MANIFEST,
output_path=BUILD_DIR / f"example09_kernel{shared_library_suffix()}",
)
library10 = build_native_kernel_library(
manifest_path=EXAMPLE10_MANIFEST,
output_path=BUILD_DIR / f"example10_kernel{shared_library_suffix()}",
)
library11 = build_native_kernel_library(
manifest_path=EXAMPLE11_MANIFEST,
output_path=BUILD_DIR / f"example11_kernel{shared_library_suffix()}",
)
library12 = build_native_kernel_library(
manifest_path=EXAMPLE12_MANIFEST,
output_path=BUILD_DIR / f"example12_kernel{shared_library_suffix()}",
)
library13 = build_native_kernel_library(
manifest_path=EXAMPLE13_MANIFEST,
output_path=BUILD_DIR / f"example13_kernel{shared_library_suffix()}",
)
library14 = build_native_kernel_library(
manifest_path=EXAMPLE14_MANIFEST,
output_path=BUILD_DIR / f"example14_kernel{shared_library_suffix()}",
)
library15 = build_native_kernel_library(
manifest_path=EXAMPLE15_MANIFEST,
output_path=BUILD_DIR / f"example15_kernel{shared_library_suffix()}",
)
result05 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"6",
"--native-kernel-manifest",
str(EXAMPLE05_MANIFEST),
"--native-kernel-library",
str(library05),
], cwd=RUST_DIR)
artifact05 = json.loads(result05.stdout)
assert artifact05["outputs"]["public"]["result"] == 30
assert artifact05["outputs"]["ui"]["ind_result"] == 30
result06 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"06",
"--native-kernel-manifest",
str(EXAMPLE06_MANIFEST),
"--native-kernel-library",
str(library06),
], cwd=RUST_DIR)
artifact06 = json.loads(result06.stdout)
assert artifact06["outputs"]["public"]["result"] is True
assert artifact06["outputs"]["ui"]["bool_result"] is True
result07 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"hello world",
"--example",
"07",
"--native-kernel-manifest",
str(EXAMPLE07_MANIFEST),
"--native-kernel-library",
str(library07),
], cwd=RUST_DIR)
artifact07 = json.loads(result07.stdout)
assert artifact07["outputs"]["public"]["result_text"] == "hello world"
assert artifact07["outputs"]["ui"]["str_result"] == "hello world"
result08 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"fault",
"--example",
"08",
"--native-kernel-manifest",
str(EXAMPLE08_MANIFEST),
"--native-kernel-library",
str(library08),
], cwd=RUST_DIR)
artifact08 = json.loads(result08.stdout)
assert artifact08["outputs"]["public"]["result_mode"] == "fault"
assert artifact08["outputs"]["ui"]["mode_result"] == "fault"
result09 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"C:/FROG/from_rust_bridge.txt",
"--example",
"09",
"--native-kernel-manifest",
str(EXAMPLE09_MANIFEST),
"--native-kernel-library",
str(library09),
], cwd=RUST_DIR)
artifact09 = json.loads(result09.stdout)
assert artifact09["outputs"]["public"]["result_path"] == "C:/FROG/from_rust_bridge.txt"
assert artifact09["outputs"]["ui"]["path_result"] == "C:/FROG/from_rust_bridge.txt"
result10 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"10",
"--native-kernel-manifest",
str(EXAMPLE10_MANIFEST),
"--native-kernel-library",
str(library10),
], cwd=RUST_DIR)
artifact10 = json.loads(result10.stdout)
assert artifact10["outputs"]["public"]["pressed"] is True
assert artifact10["outputs"]["ui"]["trigger_button"] is True
assert artifact10["outputs"]["ui"]["pressed_indicator"] is True
result11 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"11",
"--native-kernel-manifest",
str(EXAMPLE11_MANIFEST),
"--native-kernel-library",
str(library11),
], cwd=RUST_DIR)
artifact11 = json.loads(result11.stdout)
assert artifact11["outputs"]["public"]["switched"] is True
assert artifact11["outputs"]["ui"]["trigger_button"] is True
assert artifact11["outputs"]["ui"]["switched_indicator"] is True
result12 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"12",
"--native-kernel-manifest",
str(EXAMPLE12_MANIFEST),
"--native-kernel-library",
str(library12),
], cwd=RUST_DIR)
artifact12 = json.loads(result12.stdout)
assert artifact12["outputs"]["public"]["switched"] is False
assert artifact12["outputs"]["ui"]["trigger_button"] is False
assert artifact12["outputs"]["ui"]["switched_indicator"] is False
result12_release = run([
"cargo",
"run",
"--offline",
"--",
"run",
"false",
"--example",
"12",
"--native-kernel-manifest",
str(EXAMPLE12_MANIFEST),
"--native-kernel-library",
str(library12),
], cwd=RUST_DIR)
artifact12_release = json.loads(result12_release.stdout)
assert artifact12_release["outputs"]["public"]["switched"] is True
assert artifact12_release["outputs"]["ui"]["trigger_button"] is True
assert artifact12_release["outputs"]["ui"]["switched_indicator"] is True
result13 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"13",
"--native-kernel-manifest",
str(EXAMPLE13_MANIFEST),
"--native-kernel-library",
str(library13),
], cwd=RUST_DIR)
artifact13 = json.loads(result13.stdout)
assert artifact13["outputs"]["public"]["latched"] is True
assert artifact13["outputs"]["ui"]["trigger_button"] is False
assert artifact13["outputs"]["ui"]["latched_indicator"] is True
assert artifact13["execution_summary"]["button_stored_value"] is False
assert artifact13["execution_summary"]["program_read_value"] is True
result14 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"false",
"--example",
"14",
"--native-kernel-manifest",
str(EXAMPLE14_MANIFEST),
"--native-kernel-library",
str(library14),
], cwd=RUST_DIR)
artifact14 = json.loads(result14.stdout)
assert artifact14["outputs"]["public"]["latched"] is True
assert artifact14["outputs"]["ui"]["trigger_button"] is False
assert artifact14["outputs"]["ui"]["latched_indicator"] is True
assert artifact14["execution_summary"]["button_stored_value"] is False
assert artifact14["execution_summary"]["program_read_value"] is True
result15 = run([
"cargo",
"run",
"--offline",
"--",
"run",
"true",
"--example",
"15",
"--native-kernel-manifest",
str(EXAMPLE15_MANIFEST),
"--native-kernel-library",
str(library15),
], cwd=RUST_DIR)
artifact15 = json.loads(result15.stdout)
assert artifact15["outputs"]["public"]["latched"] is True
assert artifact15["outputs"]["ui"]["trigger_button"] is True
assert artifact15["outputs"]["ui"]["latched_indicator"] is True
assert artifact15["execution_summary"]["button_stored_value"] is True
assert artifact15["execution_summary"]["button_physical_pressed"] is True
print("Rust dynamic native kernel bridge check: ok")
return 0
except (RuntimeError, AssertionError, json.JSONDecodeError) as exc:
print(f"Rust dynamic native kernel bridge check: FAILED: {exc}", file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())