-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_compilation_readiness.py
More file actions
304 lines (235 loc) · 10.1 KB
/
test_compilation_readiness.py
File metadata and controls
304 lines (235 loc) · 10.1 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
#!/usr/bin/env python3
"""
Test compilation readiness - verify all components are ready for Docker compilation.
This test checks everything except the actual Docker execution.
"""
import json
import tempfile
from pathlib import Path
def test_docker_image_build_readiness():
"""Test that Docker image can be built (check Dockerfile and scripts)."""
print("=== Testing Docker Build Readiness ===")
# Check CUDA Dockerfile exists
dockerfile_path = Path("docker/cuda/Dockerfile")
if not dockerfile_path.exists():
print("✗ CUDA Dockerfile not found")
return False
print("✓ CUDA Dockerfile exists")
# Check compilation script exists
compile_script = Path("docker/cuda/scripts/compile.sh")
if not compile_script.exists():
print("✗ Compilation script not found")
return False
print("✓ Compilation script exists")
# Check validation script exists
validate_script = Path("docker/cuda/scripts/validate.sh")
if not validate_script.exists():
print("✗ Validation script not found")
return False
print("✓ Validation script exists")
# Check benchmark script exists
benchmark_script = Path("docker/cuda/scripts/benchmark.sh")
if not benchmark_script.exists():
print("✗ Benchmark script not found")
return False
print("✓ Benchmark script exists")
return True
def test_end_to_end_config_flow():
"""Test the complete configuration flow from generation to validation."""
print("\n=== Testing End-to-End Configuration Flow ===")
try:
from iree_docker_integration.config_validator import ConfigValidator
from iree_docker_integration.file_handler import SecureFileHandler
# Test configuration generation for all targets
targets = ['cuda', 'cpu', 'vulkan', 'metal']
for target in targets:
try:
validator = ConfigValidator.__new__(ConfigValidator)
validator.schema = {}
config = validator.generate_example_config(target)
# Validate the generated config
from iree_docker_integration.config_validator import IreeCompilationConfig
validated = IreeCompilationConfig(**config)
print(f"✓ {target.upper()} config generation and validation passed")
except Exception as e:
print(f"✗ {target.upper()} config failed: {e}")
return False
return True
except Exception as e:
print(f"✗ End-to-end config flow failed: {e}")
return False
def test_file_preparation_workflow():
"""Test the complete file preparation workflow."""
print("\n=== Testing File Preparation Workflow ===")
try:
from iree_docker_integration.file_handler import SecureFileHandler
file_handler = SecureFileHandler()
# Test with the actual test MLIR file
test_mlir = Path("input/test_model.mlir")
if not test_mlir.exists():
print("✗ Test MLIR file not found")
return False
# Validate input file
is_valid, error_msg = file_handler.validate_input_file(test_mlir)
if not is_valid:
print(f"✗ Input file validation failed: {error_msg}")
return False
print("✓ Input file validation passed")
# Test file preparation
prepared_input = file_handler.prepare_input_file(test_mlir, "test_model.mlir")
print(f"✓ Input file prepared: {prepared_input}")
# Test output directory preparation
prepared_output = file_handler.prepare_output_directory("test_model.vmfb")
print(f"✓ Output directory prepared: {prepared_output}")
# Test file info
file_info = file_handler.get_file_info(prepared_input)
print(f"✓ File info retrieved: {file_info.get('size_formatted', 'unknown')}")
# Cleanup
file_handler.cleanup_all_temporary_files()
print("✓ Cleanup completed")
return True
except Exception as e:
print(f"✗ File preparation workflow failed: {e}")
return False
def test_cli_integration():
"""Test CLI integration without Docker execution."""
print("\n=== Testing CLI Integration ===")
import subprocess
import sys
try:
# Test CLI help
result = subprocess.run([
"uv", "run", "iree-docker-compile", "--help"
], capture_output=True, text=True, cwd=".")
if result.returncode != 0:
print(f"✗ CLI help command failed: {result.stderr}")
return False
print("✓ CLI help command works")
# Test config generation
result = subprocess.run([
"uv", "run", "iree-docker-compile",
"generate-config", "--target", "cuda", "--output", "test-cli-config.json"
], capture_output=True, text=True, cwd=".")
if result.returncode != 0:
print(f"✗ CLI config generation failed: {result.stderr}")
return False
print("✓ CLI config generation works")
# Test config validation
result = subprocess.run([
"uv", "run", "iree-docker-compile",
"validate-config", "--config", "test-cli-config.json"
], capture_output=True, text=True, cwd=".")
if result.returncode != 0:
print(f"✗ CLI config validation failed: {result.stderr}")
return False
print("✓ CLI config validation works")
# Cleanup
Path("test-cli-config.json").unlink(missing_ok=True)
return True
except Exception as e:
print(f"✗ CLI integration test failed: {e}")
return False
def test_compilation_script_syntax():
"""Test that the compilation script has valid syntax."""
print("\n=== Testing Compilation Script Syntax ===")
try:
compile_script = Path("docker/cuda/scripts/compile.sh")
# Basic syntax check - ensure it's a valid shell script
with open(compile_script, 'r') as f:
content = f.read()
# Check for required components
required_elements = [
"#!/bin/bash",
"set -euo pipefail",
"CONFIG_FILE=",
"iree-compile",
"jq -r",
"log()",
"main()"
]
for element in required_elements:
if element not in content:
print(f"✗ Missing required element in compile.sh: {element}")
return False
print("✓ Compilation script syntax check passed")
# Check validation script
validate_script = Path("docker/cuda/scripts/validate.sh")
with open(validate_script, 'r') as f:
validate_content = f.read()
if "iree-run-module" not in validate_content:
print("✗ Validation script missing iree-run-module")
return False
print("✓ Validation script syntax check passed")
# Check benchmark script
benchmark_script = Path("docker/cuda/scripts/benchmark.sh")
with open(benchmark_script, 'r') as f:
benchmark_content = f.read()
if "iree-benchmark-module" not in benchmark_content:
print("✗ Benchmark script missing iree-benchmark-module")
return False
print("✓ Benchmark script syntax check passed")
return True
except Exception as e:
print(f"✗ Script syntax test failed: {e}")
return False
def test_docker_compose_readiness():
"""Test Docker Compose configuration if it exists."""
print("\n=== Testing Docker Compose Readiness ===")
compose_file = Path("docker-compose.yml")
if not compose_file.exists():
print("⚠ Docker Compose file not found (optional)")
return True
try:
import yaml
with open(compose_file, 'r') as f:
compose_config = yaml.safe_load(f)
# Check for IREE service
if 'services' not in compose_config:
print("✗ No services defined in docker-compose.yml")
return False
print("✓ Docker Compose file is valid YAML")
print(f"✓ Found {len(compose_config['services'])} service(s)")
return True
except ImportError:
print("⚠ PyYAML not available, skipping Docker Compose validation")
return True
except Exception as e:
print(f"✗ Docker Compose validation failed: {e}")
return False
def main():
"""Run all compilation readiness tests."""
print("=== IREE Docker Compilation Readiness Test ===\n")
tests = [
test_docker_image_build_readiness,
test_end_to_end_config_flow,
test_file_preparation_workflow,
test_cli_integration,
test_compilation_script_syntax,
test_docker_compose_readiness,
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
else:
print(f"Test {test.__name__} failed")
except Exception as e:
print(f"Test {test.__name__} crashed: {e}")
print(f"\n=== Compilation Readiness Results ===")
print(f"Passed: {passed}/{total}")
print(f"Failed: {total - passed}/{total}")
if passed == total:
print("✓ All compilation readiness tests passed!")
print("✓ System is ready for Docker-based IREE compilation")
print("✓ To test with Docker, ensure Docker daemon is running and build the image:")
print(" docker build -t iree-compiler:cuda-latest docker/cuda/")
return True
else:
print("✗ Some readiness tests failed")
print("✗ System may not be ready for Docker compilation")
return False
if __name__ == "__main__":
success = main()
exit(0 if success else 1)