From 059831534c7e884f0a607ed86b582fd00d821731 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 26 Sep 2026 23:24:03 +0200 Subject: New upstream version 3.2.0~rc1+dfsg --- main.cpp | 672 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 631 insertions(+), 41 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 01aaf28e..ebd1221e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,6 +7,7 @@ #include #include #include +#include #include #include @@ -15,18 +17,23 @@ #include #include #include +#include #include #include #include #include #include #include +#include +#include #include #include +#include #include #include #include #include +#include #include #include #include @@ -34,9 +41,13 @@ #include #include #include +#include +#include +#include #include "ExceptionCatchingApplication.hpp" #include "Logger.hpp" +#include "PerformanceTrace.hpp" #include "revision_utils.hpp" #include "MetaDataRegistry.hpp" #include "qt_helpers.hpp" @@ -46,7 +57,20 @@ #include "WSJTXLogging.hpp" #include "MultiSettings.hpp" #include "widgets/mainwindow.h" +#include "Audio/AudioInputSource.hpp" +#include "Audio/soundout.h" +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST +#include "Audio/BWFFile.hpp" +#include "Audio/FixtureAudioInput.hpp" +#include "Audio/FixtureSoundOutput.hpp" +#include "Ft8TxLoopbackTestController.hpp" +#include "JttyTxLoopbackTestController.hpp" +#include "LiveAudioTestController.hpp" +#include "ReceiveHandoffTestController.hpp" +#include +#endif #include "commons.h" +#include "DecoderIpc.hpp" #include "lib/init_random_seed.h" #include "Radio.hpp" #include "models/FrequencyList.hpp" @@ -56,6 +80,7 @@ extern "C" { // Fortran procedures we need void four2a_(_Complex float *, int * nfft, int * ndim, int * isign, int * iform, int len); + void jtty_release_fft_resources(); } namespace @@ -101,10 +126,156 @@ namespace os << v.toString (); } } + + QString lock_file_details (QLockFile const& lock, QString const& path) + { + QStringList details {QCoreApplication::translate ("main", "Lock file: %1").arg (QDir::toNativeSeparators (path))}; + qint64 pid; + QString hostname; + QString appname; + if (lock.getLockInfo (&pid, &hostname, &appname)) + { + details << QCoreApplication::translate ("main", "Owner process: %1").arg (pid); + if (!appname.isEmpty ()) + { + details << QCoreApplication::translate ("main", "Owner application: %1").arg (appname); + } + if (!hostname.isEmpty ()) + { + details << QCoreApplication::translate ("main", "Owner host: %1").arg (hostname); + } + } + else + { + details << QCoreApplication::translate ("main", "Owner information is not available."); + } + return details.join ('\n'); + } + + QString diagnostic_text (QString text) + { + return text.replace ('\\', "\\\\") + .replace ('\n', "\\n") + .replace ('\r', "\\r") + .replace ('\t', "\\t") + .replace ('"', "\\\""); + } + + char const * window_modality_name (Qt::WindowModality modality) + { + switch (modality) + { + case Qt::NonModal: return "NonModal"; + case Qt::WindowModal: return "WindowModal"; + case Qt::ApplicationModal: return "ApplicationModal"; + } + return "Unknown"; + } + + void report_unexpected_modal (QWidget const& modal) + { + std::cerr << "WSJT-X startup smoke: unexpected modal window:" + << " class=" << modal.metaObject ()->className () + << " objectName=\"" << diagnostic_text (modal.objectName ()).toStdString () << '"' + << " title=\"" << diagnostic_text (modal.windowTitle ()).toStdString () << '"' + << " visible=" << (modal.isVisible () ? "true" : "false") + << " modal=" << (modal.isModal () ? "true" : "false") + << " modality=" << window_modality_name (modal.windowModality ()); + + if (auto const *message_box = qobject_cast (&modal)) + { + std::cerr << " text=\"" << diagnostic_text (message_box->text ()).toStdString () << '"' + << " informativeText=\"" + << diagnostic_text (message_box->informativeText ()).toStdString () << '"'; + } + if (auto const *progress_dialog = qobject_cast (&modal)) + { + std::cerr << " labelText=\"" + << diagnostic_text (progress_dialog->labelText ()).toStdString () << '"'; + } + std::cerr << std::endl; + } + + enum class LockFileAction + { + RemoveLockFile, + Retry, + Stop + }; + + struct LockFileRemovalResult + { + bool removed; + QString error; + }; + + LockFileRemovalResult remove_stale_lock_file (QLockFile& lock, QString const& path) + { + if (lock.removeStaleLockFile ()) + { + return {true, QString {}}; + } + + QFile lock_file {path}; + if (!lock_file.exists ()) + { + return {true, QString {}}; + } + if (lock_file.remove ()) + { + return {true, QString {}}; + } + return {false, QCoreApplication::translate ("main", "Remove error: %1").arg (lock_file.errorString ())}; + } + + LockFileAction query_lock_file_recovery (QLockFile const& lock, QString const& path) + { + MessageBox message_box {MessageBox::Question + , QCoreApplication::translate ("main", "Another instance may be running") + , MessageBox::NoButton}; + message_box.setInformativeText (QCoreApplication::translate ("main", "WSJT-X could not lock its temporary instance file. " + "\n\nIf another WSJT-X window is still running, choose No. " + "\nUse a unique rig name to run more than one instance. " + "\n\nIf WSJT-X crashed or will not restart, choose Remove Lock File. " + "\nChoose Retry after closing the other instance.")); + message_box.setDetailedText (lock_file_details (lock, path)); + + auto remove_button = message_box.addButton (QCoreApplication::translate ("main", "Remove Lock File"), MessageBox::ActionRole); + auto retry_button = message_box.addButton (MessageBox::Retry); + auto no_button = message_box.addButton (MessageBox::No); + message_box.setDefaultButton (retry_button); + message_box.setEscapeButton (no_button); + + if (message_box.exec () == -1) + { + return LockFileAction::Stop; + } + auto clicked_button = message_box.clickedButton (); + if (remove_button == clicked_button) + { + return LockFileAction::RemoveLockFile; + } + if (retry_button == clicked_button) + { + return LockFileAction::Retry; + } + return LockFileAction::Stop; + } + + bool test_mode_requested (int argc, char * argv[]) + { + for (int i = 1; i < argc; ++i) + { + if (QByteArray {argv[i]} == QByteArrayLiteral ("--test-mode")) return true; + } + return false; + } } int main(int argc, char *argv[]) { + PerformanceTrace::begin_run ("startup", "initial"); + PerformanceTrace::Phase process_bootstrap {"process.bootstrap"}; init_random_seed (); // make the Qt type magic happen @@ -114,13 +285,21 @@ int main(int argc, char *argv[]) // Multiple instances communicate with jt9 via this QSharedMemory mem_jt9; - // Read optional file to disable highDPI scaling - QFile f("DisableHighDpiScaling"); - if (!f.exists()) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + if (test_mode_requested (argc, argv)) QStandardPaths::setTestModeEnabled (true); + QApplication::setAttribute (Qt::AA_EnableHighDpiScaling); auto const env = QProcessEnvironment::systemEnvironment (); ExceptionCatchingApplication a(argc, argv); + bool startup_smoke_test {false}; + bool automated_test {false}; +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + bool live_audio_test {false}; + bool jtty_live_audio_test {false}; + bool jtty_tx_loopback_test {false}; + bool ft8_tx_loopback_test {false}; + bool receive_handoff_test {false}; +#endif try { // LOG_INfO ("+++++++++++++++++++++++++++ Resources ++++++++++++++++++++++++++++"); @@ -153,6 +332,16 @@ int main(int argc, char *argv[]) , "rig-name"); parser.addOption (rig_option); + QCommandLineOption n1mm_tcp_port_option (QStringList {} << "p" << "n1mm-tcp-port" << "n1mm_tcp_port" + , "N1MM Logger+ TCP port number." + , "TCP port"); + parser.addOption (n1mm_tcp_port_option); + + QCommandLineOption mode_option (QStringList {} << "mode" + , "Startup mode (ft8, ft4, jtty)." + , "mode"); + parser.addOption (mode_option); + // support for start up configuration QCommandLineOption cfg_option (QStringList {} << "c" << "config" , "Where is an existing one." @@ -169,6 +358,46 @@ int main(int argc, char *argv[]) , "Writable files in test location. Use with caution, for testing only."); parser.addOption (test_option); + QCommandLineOption startup_smoke_test_option ( + QStringList {} << "startup-smoke-test", + "Start the application, process initial GUI events, and exit."); + parser.addOption (startup_smoke_test_option); + +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + QCommandLineOption live_audio_test_option ( + QStringList {} << "live-audio-test", + "Feed a WAV fixture through the live receive path.", "wav-path"); + parser.addOption (live_audio_test_option); + QCommandLineOption live_audio_expected_option ( + QStringList {} << "live-audio-expected", + "Expected decoder output used by --live-audio-test.", "expected-path"); + parser.addOption (live_audio_expected_option); + QCommandLineOption live_audio_data_dir_option ( + QStringList {} << "live-audio-data-dir", + "Shipped decoder data used by --live-audio-test.", "directory"); + parser.addOption (live_audio_data_dir_option); + QCommandLineOption jtty_live_audio_test_option ( + QStringList {} << "jtty-live-audio-test", + "Feed a WAV fixture through the live JTTY receive path.", "wav-path"); + parser.addOption (jtty_live_audio_test_option); + QCommandLineOption jtty_live_audio_expected_option ( + QStringList {} << "jtty-live-audio-expected", + "Expected message used by --jtty-live-audio-test.", "text-path"); + parser.addOption (jtty_live_audio_expected_option); + QCommandLineOption jtty_tx_loopback_test_option ( + QStringList {} << "jtty-tx-loopback-test", + "Capture two gaplessly queued JTTY messages to a WAV file.", "wav-path"); + parser.addOption (jtty_tx_loopback_test_option); + QCommandLineOption ft8_tx_loopback_test_option ( + QStringList {} << "ft8-tx-loopback-test", + "Capture one period-aligned FT8 transmission to a WAV file.", "wav-path"); + parser.addOption (ft8_tx_loopback_test_option); + QCommandLineOption receive_handoff_test_option ( + QStringList {} << "receive-handoff-test", + "Backlog two synthetic periods at the MainWindow receive boundary."); + parser.addOption (receive_handoff_test_option); +#endif + if (!parser.parse (a.arguments ())) { MessageBox::critical_message (nullptr, "Command line error", parser.errorText ()); @@ -188,11 +417,68 @@ int main(int argc, char *argv[]) } } - QStandardPaths::setTestModeEnabled (parser.isSet (test_option)); + startup_smoke_test = parser.isSet (startup_smoke_test_option); +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + live_audio_test = parser.isSet (live_audio_test_option); + jtty_live_audio_test = parser.isSet (jtty_live_audio_test_option); + jtty_tx_loopback_test = parser.isSet (jtty_tx_loopback_test_option); + ft8_tx_loopback_test = parser.isSet (ft8_tx_loopback_test_option); + receive_handoff_test = parser.isSet (receive_handoff_test_option); + if (live_audio_test != parser.isSet (live_audio_expected_option) + || live_audio_test != parser.isSet (live_audio_data_dir_option)) + { + std::cerr << "--live-audio-test, --live-audio-expected, and " + "--live-audio-data-dir must be used together" + << std::endl; + return EXIT_FAILURE; + } + if (jtty_live_audio_test != parser.isSet (jtty_live_audio_expected_option)) + { + std::cerr << "--jtty-live-audio-test and --jtty-live-audio-expected " + "must be used together" << std::endl; + return EXIT_FAILURE; + } + if ((startup_smoke_test ? 1 : 0) + (live_audio_test ? 1 : 0) + + (jtty_live_audio_test ? 1 : 0) + + (jtty_tx_loopback_test ? 1 : 0) + + (ft8_tx_loopback_test ? 1 : 0) + + (receive_handoff_test ? 1 : 0) > 1) + { + std::cerr << "Startup, live-audio, and TX loopback tests are mutually exclusive" + << std::endl; + return EXIT_FAILURE; + } + if (live_audio_test) + { + QDir const decoderDataDir {parser.value (live_audio_data_dir_option)}; + QFileInfo const allCallsigns { + decoderDataDir.absoluteFilePath ("ALLCALL7.TXT")}; + if (!allCallsigns.isFile () || !allCallsigns.isReadable ()) + { + std::cerr << "--live-audio-data-dir does not contain a readable " + "ALLCALL7.TXT" + << std::endl; + return EXIT_FAILURE; + } + } + automated_test = startup_smoke_test || live_audio_test + || jtty_live_audio_test || jtty_tx_loopback_test || ft8_tx_loopback_test + || receive_handoff_test; +#else + automated_test = startup_smoke_test; +#endif + auto const smoke_phase = [startup_smoke_test] (char const *phase) { + if (startup_smoke_test) + { + std::cerr << "WSJT-X startup smoke: " << phase << std::endl; + } + }; + smoke_phase ("command line accepted"); + QStandardPaths::setTestModeEnabled (parser.isSet (test_option) || automated_test); // support for multiple instances running from a single installation bool multiple {false}; - if (parser.isSet (rig_option) || parser.isSet (test_option)) + if (parser.isSet (rig_option) || parser.isSet (test_option) || automated_test) { auto temp_name = parser.value (rig_option); if (!temp_name.isEmpty ()) @@ -206,7 +492,7 @@ int main(int argc, char *argv[]) a.setApplicationName (a.applicationName () + " - " + temp_name); } - if (parser.isSet (test_option)) + if (parser.isSet (test_option) || automated_test) { a.setApplicationName (a.applicationName () + " - test"); } @@ -217,6 +503,9 @@ int main(int argc, char *argv[]) // now we have the application name we can open the logging and settings WSJTXLogging lg; LOG_INFO (program_title (revision ()) << " - Program startup"); + process_bootstrap.finish (); + PerformanceTrace::milestone ("logging.ready"); + PerformanceTrace::Phase process_prepare {"process.prepare"}; MultiSettings multi_settings {parser.value (cfg_option)}; // find the temporary files path @@ -224,28 +513,38 @@ int main(int argc, char *argv[]) Q_ASSERT (temp_dir.exists ()); // sanity check // disallow multiple instances with same instance key - QLockFile instance_lock {temp_dir.absoluteFilePath (a.applicationName () + ".lock")}; + auto const instance_lock_path = temp_dir.absoluteFilePath (a.applicationName () + ".lock"); + QLockFile instance_lock {instance_lock_path}; instance_lock.setStaleLockTime (0); while (!instance_lock.tryLock ()) { if (QLockFile::LockFailedError == instance_lock.error ()) { - auto button = MessageBox::query_message (nullptr - , "Another instance may be running" - , "try to remove stale lock file?" - , QString {} - , MessageBox::Yes | MessageBox::Retry | MessageBox::No - , MessageBox::Yes); - switch (button) + switch (query_lock_file_recovery (instance_lock, instance_lock_path)) { - case MessageBox::Yes: - instance_lock.removeStaleLockFile (); + case LockFileAction::RemoveLockFile: + { + auto const removal = remove_stale_lock_file (instance_lock, instance_lock_path); + if (!removal.removed) + { + auto details = lock_file_details (instance_lock, instance_lock_path); + if (!removal.error.isEmpty ()) + { + details += '\n'; + details += removal.error; + } + MessageBox::warning_message (nullptr + , a.translate ("main", "Unable to remove stale lock file") + , a.translate ("main", "Close any running WSJT-X instance or remove the lock file manually after confirming WSJT-X is not running.") + , details); + } + } break; - case MessageBox::Retry: + case LockFileAction::Retry: break; - default: + case LockFileAction::Stop: throw std::runtime_error {"Multiple instances must have unique rig names"}; } } @@ -293,7 +592,14 @@ int main(int argc, char *argv[]) // for a new version, the user will be able to re-disable it // if they wish QString splash_flag_name {"Splash_v1.7"}; - if (multi_settings.common_value (splash_flag_name, true).toBool ()) +#if defined(WSJT_TSAN_TEST_PROFILE) + // GCC TSan cannot track Qt's instrumented SVG setjmp/longjmp rasterizer. + auto const skip_splash = automated_test; +#else + auto const skip_splash = false; +#endif + if (!skip_splash + && multi_settings.common_value (splash_flag_name, true).toBool ()) { QObject::connect (&splash, &SplashScreen::disabled, [&, splash_flag_name] { multi_settings.set_common_value (splash_flag_name, false); @@ -324,17 +630,51 @@ int main(int argc, char *argv[]) { throw std::runtime_error {("Database Error: " + db.lastError ().text ()).toStdString ()}; } - + smoke_phase ("SQLite opened"); // better performance traded for a risk of d/b corruption // on system crash or application crash // db.exec ("PRAGMA synchronous=OFF"); // system crash risk // db.exec ("PRAGMA journal_mode=MEMORY"); // application crash risk db.exec ("PRAGMA locking_mode=EXCLUSIVE"); + process_prepare.finish (); int result; - auto const& original_style_sheet = a.styleSheet (); + bool startup_smoke_ready {false}; + auto const prerelease_expiration = QDateTime { + {2026, 12, 31}, {23, 59, 59, 999}, Qt::UTC}; + bool prerelease_notice_pending = + QCoreApplication::applicationVersion ().contains ("-devel") + || QCoreApplication::applicationVersion ().contains ("-rc"); + auto const original_style_sheet = a.styleSheet (); + auto const original_font = a.font (); + auto const apply_application_appearance = [&] { + auto font = original_font; + if (!font.fromString (multi_settings.settings ()->value ( + "Configuration/Font", original_font.toString ()).toString ())) + { + font = original_font; + } + + auto const dark_style = multi_settings.settings ()->value ( + "MainWindow/DarkStyle", false).toBool (); + QString dark_style_sheet; + if (dark_style) + { + QFile file {":qdarkstyle/style.qss"}; + if (file.open (QFile::ReadOnly | QFile::Text)) + { + dark_style_sheet = QTextStream {&file}.readAll (); + } + } + + auto const style_sheet = application_style_sheet ( + original_style_sheet, dark_style_sheet, dark_style, font); + if (a.font () != font) a.setFont (font); + if (a.styleSheet () != style_sheet) a.setStyleSheet (style_sheet); + }; do { + PerformanceTrace::Phase runtime_prepare {"runtime.prepare"}; // dump settings auto sys_lg = sys::get (); if (auto rec = sys_lg.open_record @@ -383,10 +723,10 @@ int main(int argc, char *argv[]) if (mem_jt9.attach ()) // shared memory presence implies // orphaned jt9 sub-process { - dec_data_t * dd = reinterpret_cast (mem_jt9.data()); - mem_jt9.lock (); - dd->ipc[1] = 999; // tell jt9 to shut down - mem_jt9.unlock (); + if (DecoderIpc::hasShutdownControlSize (mem_jt9.size ())) + { + DecoderIpc::shutdownControl (mem_jt9.data ()); + } mem_jt9.detach (); // start again } else @@ -397,25 +737,40 @@ int main(int argc, char *argv[]) } if (!mem_jt9.attach ()) { - if (!mem_jt9.create (sizeof (dec_data))) + if (!mem_jt9.create (sizeof (shared_dec_data_t))) { - splash.hide (); - MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"), - a.translate ("main", "Unable to create shared memory segment")); + auto const shared_memory_error = mem_jt9.error (); + auto const shared_memory_error_text = mem_jt9.errorString (); + std::cerr << "WSJT-X startup: shared memory creation failed" + << " (error " << static_cast (shared_memory_error) << "): " + << shared_memory_error_text.toStdString () << std::endl; + if (!automated_test) + { + splash.hide (); + MessageBox::critical_message ( + nullptr, a.translate ("main", "Shared memory error"), + a.translate ("main", "Unable to create shared memory segment")); + } throw std::runtime_error {"Shared memory error"}; } LOG_INFO ("shmem size: " << mem_jt9.size ()); } else { - splash.hide (); - MessageBox::critical_message (nullptr, a.translate ("main", "Sub-process error"), - a.translate ("main", "Failed to close orphaned jt9 process")); + std::cerr << "WSJT-X startup: orphaned jt9 shared memory segment remained after " + "shutdown attempts" + << std::endl; + if (!automated_test) + { + splash.hide (); + MessageBox::critical_message ( + nullptr, a.translate ("main", "Sub-process error"), + a.translate ("main", "Failed to close orphaned jt9 process")); + } throw std::runtime_error {"Sub-process error"}; } - mem_jt9.lock (); - memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory - mem_jt9.unlock (); + auto * shared = reinterpret_cast (mem_jt9.data ()); + DecoderIpc::initialize (*shared); unsigned downSampleFactor; { @@ -436,23 +791,247 @@ int main(int argc, char *argv[]) #endif ).toBool () ? 1u : 4u; +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + if (live_audio_test) + { + BWFFile fixture {QAudioFormat {}, parser.value (live_audio_test_option)}; + if (fixture.open (BWFFile::ReadOnly)) + { + downSampleFactor = fixture.format ().sampleRate () == 48000 + ? 4u : 1u; + } + } + if (jtty_live_audio_test) + { + BWFFile fixture {QAudioFormat {}, + parser.value (jtty_live_audio_test_option)}; + if (fixture.open (BWFFile::ReadOnly)) + { + downSampleFactor = fixture.format ().sampleRate () == 48000 + ? 4u : 1u; + } + } + if (receive_handoff_test) downSampleFactor = 1u; +#endif + } QDir::setCurrent(qApp->applicationDirPath()); //This helps to find the SF executables + runtime_prepare.finish (); + + apply_application_appearance (); // run the application UI - MainWindow w(temp_dir, multiple, &multi_settings, &mem_jt9, downSampleFactor, &splash, env); + smoke_phase ("constructing MainWindow"); + PerformanceTrace::Phase main_window_construct {"mainwindow.construct"}; +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + FixtureAudioInput * fixture_input {nullptr}; + FixtureSoundOutput * fixture_output {nullptr}; + std::unique_ptr audio_input; + std::unique_ptr sound_output; + if (live_audio_test || jtty_live_audio_test || receive_handoff_test) + { + std::unique_ptr fixture { + new FixtureAudioInput { + receive_handoff_test ? QString {} + : parser.value (live_audio_test + ? live_audio_test_option + : jtty_live_audio_test_option), + receive_handoff_test ? FixtureAudioInput::Profile::ReceiveHandoff + : (live_audio_test ? FixtureAudioInput::Profile::Ft8 + : FixtureAudioInput::Profile::Jtty)}}; + fixture_input = fixture.get (); + audio_input = std::move (fixture); + } + if (jtty_tx_loopback_test || ft8_tx_loopback_test) + { + std::unique_ptr fixture { + new FixtureSoundOutput { + parser.value (jtty_tx_loopback_test + ? jtty_tx_loopback_test_option + : ft8_tx_loopback_test_option), + ft8_tx_loopback_test + ? FixtureSoundOutput::Profile::Ft8Period + : FixtureSoundOutput::Profile::JttyStrict}}; + fixture_output = fixture.get (); + sound_output = std::move (fixture); + } +#else + std::unique_ptr audio_input; +#endif + MainWindow w(temp_dir, multiple, &multi_settings, &mem_jt9, downSampleFactor, &splash, env, + automated_test, original_style_sheet, std::move (audio_input), +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + std::move (sound_output), +#else + {}, +#endif +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + live_audio_test ? parser.value (live_audio_data_dir_option) : QString {} +#else + QString {} +#endif + ); + main_window_construct.finish (); + smoke_phase ("MainWindow constructed"); +#ifdef Q_OS_WIN + quint16 mmtty_port = 0; + if (parser.isSet(n1mm_tcp_port_option)) { + mmtty_port = parser.value(n1mm_tcp_port_option).toUShort(); + } + + if (mmtty_port > 0) { + LOG_INFO("Starting JTTY/N1MM Logger interface on port: " << mmtty_port); + w.initMMTTY(mmtty_port); + } else { + LOG_INFO("JTTY/N1MM Logger interface not enabled (no port or matching rig name provided)."); + } +#endif + if (parser.isSet(mode_option)) { + bool lock_mode = parser.isSet(n1mm_tcp_port_option); + w.set_mode_from_command_line(parser.value(mode_option), lock_mode); + } + w.show(); + PerformanceTrace::milestone ("ui.show_returned"); + smoke_phase ("MainWindow shown"); + if (prerelease_notice_pending) + { + prerelease_notice_pending = false; + QTimer::singleShot (0, &w, [&w, automated_test, prerelease_expiration] { + if (!automated_test) + { + auto const expiration_date = QLocale::c ().toString ( + prerelease_expiration.date (), "MMMM d, yyyy"); + MessageBox::critical_message ( + &w, + "This is a pre-release version of WSJT-X " + version (false) + " made\n" + "available for testing purposes. By design it will\n" + "be nonfunctional after " + expiration_date + "."); + } + if (QDateTime::currentDateTimeUtc () >= prerelease_expiration) + { + w.close (); + } + }); + } +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + std::unique_ptr live_audio_controller; + std::unique_ptr receive_handoff_controller; + std::unique_ptr jtty_tx_controller; + std::unique_ptr ft8_tx_controller; + if (live_audio_test || jtty_live_audio_test) + { + a.setQuitOnLastWindowClosed (false); + live_audio_controller.reset (new LiveAudioTestController { + &w, fixture_input, + parser.value (live_audio_test + ? live_audio_expected_option + : jtty_live_audio_expected_option), + live_audio_test ? LiveAudioTestController::Mode::Ft8 + : LiveAudioTestController::Mode::Jtty}); + auto * controller = live_audio_controller.get (); + QTimer::singleShot (0, live_audio_controller.get (), + [controller] { + controller->begin (); + }); + } + if (receive_handoff_test) + { + a.setQuitOnLastWindowClosed (false); + receive_handoff_controller.reset (new ReceiveHandoffTestController { + &w, fixture_input}); + auto * controller = receive_handoff_controller.get (); + QTimer::singleShot (0, controller, [controller] { controller->begin (); }); + } + if (jtty_tx_loopback_test) + { + a.setQuitOnLastWindowClosed (false); + jtty_tx_controller.reset (new JttyTxLoopbackTestController { + &w, fixture_output, + parser.value (jtty_tx_loopback_test_option)}); + auto * controller = jtty_tx_controller.get (); + QTimer::singleShot (0, jtty_tx_controller.get (), + [controller] { + controller->begin (); + }); + } + if (ft8_tx_loopback_test) + { + a.setQuitOnLastWindowClosed (false); + ft8_tx_controller.reset (new Ft8TxLoopbackTestController { + &w, fixture_output, + parser.value (ft8_tx_loopback_test_option)}); + auto * controller = ft8_tx_controller.get (); + QTimer::singleShot (0, ft8_tx_controller.get (), + [controller] { + controller->begin (); + }); + } +#endif + if (startup_smoke_test) + { + QTimer::singleShot (1000, &w, [&a, &w, &smoke_phase, &startup_smoke_ready] { + smoke_phase ("event loop reached"); + if (auto *modal = QApplication::activeModalWidget ()) + { + report_unexpected_modal (*modal); + modal->close (); + w.close (); + a.exit (EXIT_FAILURE); + return; + } + if (w.close ()) + { + smoke_phase ("close accepted"); + startup_smoke_ready = true; + a.quit (); + } + else + { + std::cerr << "WSJT-X startup smoke: main window rejected close" << std::endl; + a.exit (EXIT_FAILURE); + } + }); + } splash.raise (); QObject::connect (&a, SIGNAL (lastWindowClosed()), &a, SLOT (quit())); result = a.exec(); + PerformanceTrace::milestone ("event_loop.exit"); + if (startup_smoke_test && !startup_smoke_ready) + { + std::cerr << "WSJT-X startup smoke: application exited before readiness" << std::endl; + result = EXIT_FAILURE; + } +#ifdef WSJT_ENABLE_LIVE_AUDIO_TEST + if ((live_audio_test || jtty_live_audio_test) + && (!live_audio_controller || !live_audio_controller->succeeded ())) + { + result = EXIT_FAILURE; + } + if (jtty_tx_loopback_test + && (!jtty_tx_controller || !jtty_tx_controller->succeeded ())) + { + result = EXIT_FAILURE; + } + if (ft8_tx_loopback_test + && (!ft8_tx_controller || !ft8_tx_controller->succeeded ())) + { + result = EXIT_FAILURE; + } + if (receive_handoff_test + && (!receive_handoff_controller + || !receive_handoff_controller->succeeded ())) + { + result = EXIT_FAILURE; + } +#endif - // ensure config switches start with the right style sheet - a.setStyleSheet (original_style_sheet); } - while (!result && !multi_settings.exit ()); + while (!multi_settings.exit () && !result && !automated_test); // clean up lazily initialized resources + jtty_release_fft_resources (); { int nfft {-1}; int ndim {1}; @@ -465,16 +1044,27 @@ int main(int argc, char *argv[]) fftwf_cleanup (); temp_dir.removeRecursively (); // clean up temp files + if (startup_smoke_test && !result) + { + smoke_phase ("cleanup complete"); + std::cout << "WSJT-X startup smoke test passed" << std::endl; + } return result; } catch (std::exception const& e) { - MessageBox::critical_message (nullptr, "Fatal error", e.what ()); + if (!automated_test) + { + MessageBox::critical_message (nullptr, "Fatal error", e.what ()); + } std::cerr << "Error: " << e.what () << '\n'; } catch (...) { - MessageBox::critical_message (nullptr, "Unexpected fatal error"); + if (!automated_test) + { + MessageBox::critical_message (nullptr, "Unexpected fatal error"); + } std::cerr << "Unexpected fatal error\n"; throw; // hoping the runtime might tell us more about the exception } -- cgit v1.2.3