forked from FastLED/FastLED
- Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest.py
More file actions
Latest commit
430 lines (359 loc) · 15.9 KB
/
Copy pathtest.py
File metadata and controls
430 lines (359 loc) · 15.9 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/usr/bin/env python3
import_thread
importjson
importos
importsys
importthreading
importtime
importtraceback
importwarnings
frompathlibimportPath
fromci.runners.avr8js_runnerimportrun_avr8js_tests
fromci.runners.docker_runnerimportrun_docker_tests
fromci.runners.qemu_runnerimportrun_qemu_tests
fromci.util.fingerprintimportFingerprintManager
fromci.util.global_interrupt_handlerimport (
signal_interrupt,
wait_for_cleanup,
)
fromci.util.output_formatterimportTimestampFormatter
fromci.util.running_process_managerimportRunningProcessManagerSingleton
fromci.util.sccache_configimportshow_sccache_stats
fromci.util.test_argsimportparse_args
fromci.util.test_envimport (
dump_thread_stacks,
setup_environment,
setup_force_exit,
)
fromci.util.test_runnerimportrunnerastest_runner
fromci.util.test_typesimport (
process_test_flags,
)
fromci.util.timestamp_printimportts_print
_CANCEL_WATCHDOG=threading.Event()
_TIMEOUT_EVERYTHING=600
# Platform to emulator backend mapping for --run command
def_load_backends():
backend_path=Path(__file__).parent/"ci"/"runners"/"backends.json"
withopen(backend_path) asf:
returnjson.load(f)
_RUN_PLATFORM_BACKENDS=_load_backends()
ifos.environ.get("GITHUB_ACTIONS"):
_TIMEOUT_EVERYTHING=1200# Extended timeout for GitHub CI builds
ts_print(
f"GitHub Actions environment detected - using extended timeout: {_TIMEOUT_EVERYTHING} seconds"
)
defmake_watch_dog_thread(
seconds: int,
) ->threading.Thread: # 60 seconds default timeout
defwatchdog_timer() ->None:
time.sleep(seconds)
if_CANCEL_WATCHDOG.is_set():
return
warnings.warn(f"Watchdog timer expired after {seconds} seconds.")
dump_thread_stacks()
ts_print(f"Watchdog timer expired after {seconds} seconds - forcing exit")
# Dump outstanding running processes (if any)
try:
RunningProcessManagerSingleton.dump_active()
exceptKeyboardInterrupt:
handle_keyboard_interrupt_properly()
raise
exceptExceptionase:
ts_print(f"Failed to dump active processes: {e}")
traceback.print_stack()
time.sleep(0.5)
os._exit(2) # Exit with error code 2 to indicate timeout (SIGTERM)
thr=threading.Thread(target=watchdog_timer, daemon=True, name="WatchdogTimer")
thr.start()
returnthr
defmain() ->None:
try:
# Record start time
start_time=time.time()
# Change to script directory first
os.chdir(Path(__file__).parent)
# Parse and process arguments
args=parse_args()
# Handle --list-tests flag: list available tests and exit
ifargs.list_tests:
fromci.meson.test_discoveryimportlist_all_tests
list_all_tests(filter_pattern=args.test, filter_type=None)
sys.exit(0)
# Handle --no-unity flag
ifargs.no_unity:
ts_print("(--no-unity is assumed by default now)")
# Default to parallel execution for better performance
# Users can disable parallel compilation by setting NO_PARALLEL=1 or using --no-parallel
ifos.environ.get("NO_PARALLEL", "0") =="1":
args.no_parallel=True
args=process_test_flags(args)
timeout=_TIMEOUT_EVERYTHING
# Adjust watchdog timeout based on test configuration
# Sequential builds with debug mode (sanitizers) are very slow, especially on Windows
ifargs.debugandargs.no_parallel:
# 45 minutes for sequential debug builds (sanitizers are slow)
timeout=2700
ts_print(
f"Adjusted watchdog timeout for sequential debug builds: {timeout} seconds"
)
# Sequential examples compilation can take up to 30 minutes
elifargs.examplesisnotNoneandargs.no_parallel:
# 35 minutes for sequential examples compilation
timeout=2100
ts_print(
f"Adjusted watchdog timeout for sequential examples compilation: {timeout} seconds"
)
# Set up watchdog timer
_=make_watch_dog_thread(seconds=timeout)
# Handle --no-interactive flag
ifargs.no_interactive:
os.environ["FASTLED_CI_NO_INTERACTIVE"] ="true"
os.environ["GITHUB_ACTIONS"] = (
"true"# This ensures all subprocess also run in non-interactive mode
)
# Handle --interactive flag
ifargs.interactive:
os.environ.pop("FASTLED_CI_NO_INTERACTIVE", None)
os.environ.pop("GITHUB_ACTIONS", None)
# Set up remaining environment based on arguments
setup_environment(args)
# Handle stack trace control
enable_stack_trace=notargs.no_stack_trace
# Stack trace messages are only useful when debugging timeouts
# Don't clutter normal output with this implementation detail
# Validate conflicting arguments
ifargs.no_interactiveandargs.interactive:
ts_print(
"Error: --interactive and --no-interactive cannot be used together",
file=sys.stderr,
)
sys.exit(1)
# Set up fingerprint caching
cache_dir=Path(".cache")
# Determine build mode (default to "quick")
# IMPORTANT: If --debug is set, use "debug" mode even if --build-mode is not specified
# This ensures fingerprint caching correctly separates debug builds from quick builds
build_mode= (
args.build_modeifargs.build_modeelse ("debug"ifargs.debugelse"quick")
)
fingerprint_manager=FingerprintManager(cache_dir, build_mode=build_mode)
# Calculate fingerprints
src_code_change=fingerprint_manager.check_all()
cpp_test_change=fingerprint_manager.check_cpp(args)
examples_change=fingerprint_manager.check_examples(args)
python_test_change=fingerprint_manager.check_python()
wasm_change=fingerprint_manager.check_wasm()
# Handle --docker flag: run tests in Docker container
ifargs.docker:
ts_print("=== Docker Testing ===")
exit_code=run_docker_tests(args)
sys.exit(exit_code)
# Handle --run flag (unified emulation interface)
ifargs.runisnotNone:
iflen(args.run) <1:
ts_print("Error: --run requires a platform/board (e.g., esp32s3, uno)")
sys.exit(1)
platform=args.run[0].lower()
# Look up backend from mapping table
backend=None
forb, platformsin_RUN_PLATFORM_BACKENDS.items():
ifplatforminplatforms:
backend=b
break
ifbackendisNone:
# Platform not found - show error with supported platforms
ts_print(f"Error: Unknown platform '{platform}'")
ts_print()
ts_print("Supported platforms:")
# Group platforms by backend
forb, platformsin_RUN_PLATFORM_BACKENDS.items():
ts_print(f" {b.upper()}: {', '.join(sorted(platforms))}")
sys.exit(1)
# Route to appropriate backend
ifbackend=="qemu":
ts_print(f"=== QEMU Testing ({platform}) ===")
# Convert --run to --qemu format for backward compatibility
args.qemu=args.run
run_qemu_tests(args)
return
elifbackend=="avr8js":
ts_print(f"=== avr8js Testing ({platform}) ===")
# Run avr8js tests
run_avr8js_tests(args)
return
else:
ts_print(
f"Error: Unknown backend '{backend}' for platform '{platform}'"
)
sys.exit(1)
# Handle QEMU testing (deprecated - use --run)
ifargs.qemuisnotNone:
ts_print("=== QEMU Testing ===")
ts_print("Note: --qemu is deprecated, use --run instead")
run_qemu_tests(args)
return
# Track test success/failure for fingerprint status
tests_passed=False
try:
# Run tests using the test runner with sequential example compilation
# Check if we need to use sequential execution to avoid resource conflicts
ifnotargs.unitandnotargs.examplesandnotargs.pyandargs.full:
# Full test mode - use RunningProcessGroup for dependency-based execution
fromci.util.running_process_groupimport (
ExecutionMode,
ProcessExecutionConfig,
RunningProcessGroup,
)
fromci.util.test_runnerimport (
create_examples_test_process,
create_python_test_process,
)
# Create Python test process (runs first)
python_process=create_python_test_process(
enable_stack_trace=False, run_slow=True
)
python_process.auto_run=False
# Create examples compilation process
examples_process=create_examples_test_process(
args, notargs.no_stack_trace
)
examples_process.auto_run=False
# Configure sequential execution with dependencies
config=ProcessExecutionConfig(
execution_mode=ExecutionMode.SEQUENTIAL_WITH_DEPENDENCIES,
verbose=args.verbose,
timeout_seconds=2100, # 35 minutes for sequential examples compilation
live_updates=True, # Enable real-time display
display_type="auto", # Auto-detect best display format
)
# Create process group and set up dependency
group=RunningProcessGroup(config=config, name="FullTestSequence")
group.add_process(python_process)
group.add_dependency(
examples_process, python_process
) # examples depends on python
try:
# Start real-time display for full test mode
display_thread=None
ifnotargs.verboseandconfig.live_updates:
try:
fromci.util.process_status_displayimport (
display_process_status,
)
display_thread=display_process_status(
group,
display_type=config.display_type,
update_interval=config.update_interval,
)
exceptImportError:
pass# Fall back to normal execution
timings=group.run()
# Stop display thread if it was started
ifdisplay_thread:
time.sleep(0.5)
ts_print("Sequential test execution completed successfully")
# Print timing summary
iftimings:
ts_print("\nExecution Summary:")
fortimingintimings:
ts_print(f" {timing.name}: {timing.duration:.2f}s")
exceptKeyboardInterrupt:
_thread.interrupt_main()
raise
exceptExceptionase:
ts_print(f"Sequential test execution failed: {e}")
sys.exit(1)
else:
# Use normal test runner for other cases
# Force change flags=True when running a specific test to disable fingerprint cache
# Also force when --no-fingerprint or --force is used
force_cpp_test_change= (
cpp_test_change
or (args.testisnotNone)
orargs.no_fingerprint
orargs.force
)
# Note: args.examples == [] means "all examples" (e.g., default mode or --examples flag)
# args.examples with specific items (e.g., ['Blink']) means specific examples requested
# Only force when specific examples are requested, not for "run all examples"
force_examples_change= (
examples_change
or (args.examplesisnotNoneandlen(args.examples) >0)
orargs.no_fingerprint
orargs.force
)
force_python_test_change= (
python_test_change
or (args.testisnotNone)
orargs.no_fingerprint
orargs.force
)
force_wasm_change=wasm_changeorargs.no_fingerprintorargs.force
force_src_code_change= (
src_code_changeorargs.no_fingerprintorargs.force
)
# Only show cache status when it's enabled (the notable case)
# When disabled (--no-fingerprint), this is the default so no message needed
test_runner(
args,
force_src_code_change,
force_cpp_test_change,
force_examples_change,
force_python_test_change,
force_wasm_change,
fingerprint_manager=fingerprint_manager,
)
# If we got here, tests passed
tests_passed=True
exceptSystemExitase:
# Test runner calls sys.exit() on failure
ife.code!=0:
tests_passed=False
raise
finally:
# Only save fingerprints when running ALL tests, not specific tests
# This prevents running a specific test from marking the full fingerprint as valid
# Note: args.examples == [] means "all examples" (e.g., --cpp mode), which is OK
# args.examples with specific items (e.g., ['Blink']) means specific examples only
running_specific_examples= (
args.examplesisnotNoneandlen(args.examples) >0
)
running_all_tests= (
args.testisNone
andnotrunning_specific_examples
andnotargs.no_fingerprint
)
ifrunning_all_tests:
status="success"iftests_passedelse"failure"
fingerprint_manager.save_all(status)
# Set up force exit daemon and exit
_=setup_force_exit()
_CANCEL_WATCHDOG.set()
# Print total execution time
elapsed_time=time.time() -start_time
print(f"Total: {elapsed_time:.2f}s")
sys.exit(0)
exceptKeyboardInterrupt:
# Only notify main thread if we're in a worker thread
ifthreading.current_thread() !=threading.main_thread():
fromci.util.global_interrupt_handlerimport (
handle_keyboard_interrupt_properly,
)
handle_keyboard_interrupt_properly()
signal_interrupt()
wait_for_cleanup()
sys.exit(130)
if__name__=="__main__":
try:
main()
exceptKeyboardInterrupt:
# Only notify main thread if we're in a worker thread
ifthreading.current_thread() !=threading.main_thread():
fromci.util.global_interrupt_handlerimport (
handle_keyboard_interrupt_properly,
)
handle_keyboard_interrupt_properly()
signal_interrupt()
wait_for_cleanup()
sys.exit(130)