-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cross_platform.py
More file actions
executable file
·289 lines (244 loc) · 9.38 KB
/
test_cross_platform.py
File metadata and controls
executable file
·289 lines (244 loc) · 9.38 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
#!/usr/bin/env python3
"""
ZIBO Keyboard Input Plugin Cross-Platform Test Script
Validates the compilation configuration correctness for Windows, macOS, and Linux platforms
Usage:
python test_cross_platform.py
"""
import os
import sys
import shutil
import subprocess
import json
from pathlib import Path
def run_command(command, cwd=None, capture_output=True):
"""Execute command and return result"""
try:
result = subprocess.run(
command,
shell=True,
cwd=cwd,
capture_output=capture_output,
text=True
)
return {
'success': result.returncode == 0,
'returncode': result.returncode,
'stdout': result.stdout if capture_output else '',
'stderr': result.stderr if capture_output else ''
}
except Exception as e:
return {
'success': False,
'returncode': -1,
'stdout': '',
'stderr': str(e)
}
def test_file_existence():
"""Test if required files exist"""
print("[CHECK] Testing file existence...")
required_files = [
'CMakeLists.txt',
'mac_exports.txt',
'win_exports.def',
'linux_exports.txt',
'build.sh',
'build_windows.bat',
'build_linux.sh',
'build_all.py',
'XPLM-SDK/Libraries/Mac/XPLM.framework',
'XPLM-SDK/Libraries/Win/XPLM_64.lib',
'XPLM-SDK/Libraries/Win/XPWidgets_64.lib',
'XPLM-SDK/Libraries/Lin/XPLM_64.so',
'XPLM-SDK/Libraries/Lin/XPWidgets_64.so',
'src/main.cpp'
]
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
if missing_files:
print(f"[ERROR] Missing files: {missing_files}")
return False
else:
print("[SUCCESS] All required files exist")
return True
def test_symbol_export_files():
"""Test symbol export file formats"""
print("\n[CHECK] Testing symbol export files...")
tests = []
# Test Mac export file
with open('mac_exports.txt', 'r') as f:
mac_exports = f.read()
if all(symbol in mac_exports for symbol in ['XPluginStart', 'XPluginStop', 'XPluginEnable', 'XPluginDisable', 'XPluginReceiveMessage']):
tests.append(("Mac exports", True))
else:
tests.append(("Mac exports", False))
# Test Windows export file
with open('win_exports.def', 'r') as f:
win_exports = f.read()
if 'EXPORTS' in win_exports and all(symbol in win_exports for symbol in ['XPluginStart', 'XPluginStop']):
tests.append(("Windows exports", True))
else:
tests.append(("Windows exports", False))
# Test Linux export file
with open('linux_exports.txt', 'r') as f:
linux_exports = f.read()
if 'global:' in linux_exports and 'local:' in linux_exports and 'XPluginStart;' in linux_exports:
tests.append(("Linux exports", True))
else:
tests.append(("Linux exports", False))
all_passed = True
for test_name, passed in tests:
if passed:
print(f"[SUCCESS] {test_name}: Format correct")
else:
print(f"[ERROR] {test_name}: Format incorrect")
all_passed = False
return all_passed
def test_cmake_configuration(platform):
"""Test platform-specific CMake configuration"""
print(f"\n[CHECK] Testing {platform} platform CMake configuration...")
test_dir = f"test_builds/{platform}"
if Path(test_dir).exists():
shutil.rmtree(test_dir)
Path(test_dir).mkdir(parents=True)
# Set platform-specific CMake parameters
if platform == 'linux':
cmake_cmd = f"cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=Release ../.."
elif platform == 'windows':
cmake_cmd = f"cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_BUILD_TYPE=Release ../.."
else: # mac
cmake_cmd = f"cmake -DCMAKE_BUILD_TYPE=Release ../.."
result = run_command(cmake_cmd, cwd=test_dir)
if not result['success']:
print(f"[ERROR] {platform}: CMake configuration failed")
print(f"Error: {result['stderr']}")
return False
# Check generated files
build_files = list(Path(test_dir).glob('*'))
if len(build_files) < 3: # Should have at least Makefile, CMakeCache.txt, etc
print(f"[ERROR] {platform}: Too few build files generated")
return False
# Check specific configuration items
expected_output = {
'linux': 'lin.xpl',
'windows': 'win.xpl',
'mac': 'mac.xpl'
}
expected_libs = {
'linux': ['XPLM_64.so', 'XPWidgets_64.so'],
'windows': ['XPLM_64.lib', 'XPWidgets_64.lib'],
'mac': ['XPLM.framework', 'XPWidgets.framework']
}
# Search for key information in configuration files
config_found = False
for file_path in Path(test_dir).rglob('*'):
if file_path.is_file():
try:
content = file_path.read_text()
if expected_output[platform] in content:
config_found = True
break
except:
continue
if config_found:
print(f"[SUCCESS] {platform}: CMake configuration correct, output file set to {expected_output[platform]}")
return True
else:
print(f"[ERROR] {platform}: Expected output file configuration not found")
return False
def test_build_scripts():
"""Test build script syntax"""
print("\n[CHECK] Testing build script syntax...")
tests = []
# Test bash script syntax
for script in ['build.sh', 'build_linux.sh']:
result = run_command(f"bash -n {script}")
tests.append((script, result['success']))
# Test Python script syntax
result = run_command("python3 -m py_compile build_all.py")
tests.append(("build_all.py", result['success']))
# Test Python script help function
result = run_command("python3 build_all.py --help")
tests.append(("build_all.py --help", result['success']))
all_passed = True
for script_name, passed in tests:
if passed:
print(f"[SUCCESS] {script_name}: Syntax correct")
else:
print(f"[ERROR] {script_name}: Syntax error")
all_passed = False
return all_passed
def test_library_files():
"""Test SDK library files"""
print("\n[CHECK] Testing SDK library files...")
lib_tests = [
('Win/XPLM_64.lib', 'current ar archive'),
('Win/XPWidgets_64.lib', 'current ar archive'),
('Lin/XPLM_64.so', 'ELF 64-bit LSB shared object'),
('Mac/XPLM.framework/XPLM', 'Mach-O')
]
all_passed = True
for lib_path, expected_type in lib_tests:
full_path = f"XPLM-SDK/Libraries/{lib_path}"
if Path(full_path).exists():
result = run_command(f"file '{full_path}'")
if result['success'] and expected_type in result['stdout']:
print(f"[SUCCESS] {lib_path}: Format correct ({expected_type})")
else:
print(f"[ERROR] {lib_path}: Format incorrect or cannot detect")
all_passed = False
else:
print(f"[ERROR] {lib_path}: File does not exist")
all_passed = False
return all_passed
def main():
print("[TEST] ZIBO Keyboard Input Plugin Cross-Platform Compilation Configuration Test")
print("=" * 70)
# Check if in project root directory
if not Path('CMakeLists.txt').exists():
print("[ERROR] Please run this script in the project root directory")
return 1
# Run all tests
tests = [
("File Existence", test_file_existence),
("Symbol Export Files", test_symbol_export_files),
("Build Script Syntax", test_build_scripts),
("SDK Library Files", test_library_files),
]
# CMake configuration tests
cmake_tests = [
("macOS CMake Configuration", lambda: test_cmake_configuration('mac')),
("Linux CMake Configuration", lambda: test_cmake_configuration('linux')),
("Windows CMake Configuration", lambda: test_cmake_configuration('windows')),
]
all_tests = tests + cmake_tests
passed_tests = 0
total_tests = len(all_tests)
for test_name, test_func in all_tests:
try:
if test_func():
passed_tests += 1
else:
print(f"\n[WARNING] {test_name} test failed")
except Exception as e:
print(f"\n[ERROR] {test_name} test error: {e}")
# Cleanup test files
if Path('test_builds').exists():
shutil.rmtree('test_builds')
print(f"\n" + "=" * 70)
print(f"[RESULT] Test Results: {passed_tests}/{total_tests} passed")
if passed_tests == total_tests:
print("[SUCCESS] All tests passed! Cross-platform compilation configuration is correct.")
print("\n[INFO] Next steps:")
print(" • On Windows: run build_windows.bat")
print(" • On macOS: run ./build.sh")
print(" • On Linux: run ./build_linux.sh")
print(" • Or use unified script: python3 build_all.py")
return 0
else:
print(f"[WARNING] {total_tests - passed_tests} tests failed, please check configuration.")
return 1
if __name__ == "__main__":
sys.exit(main())