From a43df54b67aaff7cba47f2ce1c2449063ead1788 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:54:51 -0800 Subject: [PATCH] Command-line test mode: return before console settings and devices Tests need no console, serial port or camera. Loading the console settings, polling serial ports and cameras, and the device cleanup ran before the test-mode check, so a test run could touch devices another running instance holds. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/CommonFramework/Main.cpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Main.cpp b/SerialPrograms/Source/CommonFramework/Main.cpp index ef6742e2eb..68ddf65f45 100644 --- a/SerialPrograms/Source/CommonFramework/Main.cpp +++ b/SerialPrograms/Source/CommonFramework/Main.cpp @@ -185,14 +185,6 @@ int run_program(int argc, char *argv[]){ - ScopeExit cleanup([]{ -#ifdef PA_SDL - global_gamepad_tracker().stop(); -#endif - SerialPortPoller::instance().stop(); - GlobalMediaServices::instance().stop(); - }); - // Several novice developers struggled to build and run the program due to missing Resources folder. // Add this check to pop a message box when Resources folder is missing. if (!check_resource_folder(logger)){ @@ -208,13 +200,6 @@ int run_program(int argc, char *argv[]){ logger.log(error.message(), COLOR_RED); } - // Load the Switch framework settings now, not only when their panel is opened. - OptionsPanelWrapper().make_panel()->load_json_from_global(); - - // Preload a bunch of stuff now so they are ready later. - SerialPortPoller::instance().ports(); - get_all_cameras(); - // Force all the Qt thread pools to be constructed now on the main thread. GlobalThreadPools::qt_worker_threadpool(); GlobalThreadPools::qt_event_threadpool(); @@ -246,10 +231,27 @@ int run_program(int argc, char *argv[]){ return 1; } + // Tests need no console, serial port or camera. Return before touching + // them, so tests can run while another instance holds the devices. if (GlobalSettings::instance().COMMAND_LINE_TEST_MODE){ return run_command_line_tests(augment_test_color_distortions, test_substring); } + ScopeExit cleanup([]{ +#ifdef PA_SDL + global_gamepad_tracker().stop(); +#endif + SerialPortPoller::instance().stop(); + GlobalMediaServices::instance().stop(); + }); + + // Load the Switch framework settings now, not only when their panel is opened. + OptionsPanelWrapper().make_panel()->load_json_from_global(); + + // Preload a bunch of stuff now so they are ready later. + SerialPortPoller::instance().ports(); + get_all_cameras(); + // Check whether the hardware is powerful enough to run this program. if (!check_hardware()){ return 1;