diff options
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 218 |
1 files changed, 152 insertions, 66 deletions
@@ -11,7 +11,6 @@ #include <fftw3.h> #include <QApplication> -#include <QSharedMemory> #include <QProcessEnvironment> #include <QTemporaryFile> #include <QDateTime> @@ -48,6 +47,7 @@ #include "ExceptionCatchingApplication.hpp" #include "Logger.hpp" #include "PerformanceTrace.hpp" +#include "prerelease_expiry.h" #include "revision_utils.hpp" #include "MetaDataRegistry.hpp" #include "qt_helpers.hpp" @@ -65,6 +65,7 @@ #include "Audio/FixtureSoundOutput.hpp" #include "Ft8TxLoopbackTestController.hpp" #include "JttyTxLoopbackTestController.hpp" +#include "WavDecodeTestController.hpp" #include "LiveAudioTestController.hpp" #include "ReceiveHandoffTestController.hpp" #include <QAudioFormat> @@ -282,9 +283,6 @@ int main(int argc, char *argv[]) Radio::register_types (); register_types (); - // Multiple instances communicate with jt9 via this - QSharedMemory mem_jt9; - if (test_mode_requested (argc, argv)) QStandardPaths::setTestModeEnabled (true); QApplication::setAttribute (Qt::AA_EnableHighDpiScaling); @@ -299,6 +297,12 @@ int main(int argc, char *argv[]) bool jtty_tx_loopback_test {false}; bool ft8_tx_loopback_test {false}; bool receive_handoff_test {false}; + bool jt9_wav_test {false}; + bool jt65_wav_test {false}; + bool q65_wav_test {false}; + bool fst4_wav_test {false}; + bool fst4w_wav_test {false}; + unsigned test_audio_speed {1}; #endif try { @@ -396,6 +400,50 @@ int main(int argc, char *argv[]) QStringList {} << "receive-handoff-test", "Backlog two synthetic periods at the MainWindow receive boundary."); parser.addOption (receive_handoff_test_option); + QCommandLineOption jt9_wav_test_option ( + QStringList {} << "jt9-wav-test", + "Decode a JT9 WAV through the application and repeat the decode.", "wav-path"); + parser.addOption (jt9_wav_test_option); + QCommandLineOption jt9_wav_expected_option ( + QStringList {} << "jt9-wav-expected", + "Message that must appear during both JT9 WAV decodes.", "message"); + parser.addOption (jt9_wav_expected_option); + QCommandLineOption jt65_wav_test_option ( + QStringList {} << "jt65-wav-test", + "Decode a JT65 WAV through the application and repeat the decode.", "wav-path"); + parser.addOption (jt65_wav_test_option); + QCommandLineOption jt65_wav_expected_option ( + QStringList {} << "jt65-wav-expected", + "Message that must appear during both JT65 WAV decodes.", "message"); + parser.addOption (jt65_wav_expected_option); + QCommandLineOption q65_wav_test_option ( + QStringList {} << "q65-wav-test", + "Decode a Q65 WAV through the application and repeat the decode.", "wav-path"); + parser.addOption (q65_wav_test_option); + QCommandLineOption q65_wav_expected_option ( + QStringList {} << "q65-wav-expected", + "Message that must appear during both Q65 WAV decodes.", "message"); + parser.addOption (q65_wav_expected_option); + QCommandLineOption fst4_wav_test_option ( + QStringList {} << "fst4-wav-test", + "Decode a FST4 WAV through the application and repeat the decode.", "wav-path"); + parser.addOption (fst4_wav_test_option); + QCommandLineOption fst4_wav_expected_option ( + QStringList {} << "fst4-wav-expected", + "Message that must appear during both FST4 WAV decodes.", "message"); + parser.addOption (fst4_wav_expected_option); + QCommandLineOption fst4w_wav_test_option ( + QStringList {} << "fst4w-wav-test", + "Decode a FST4W WAV through the application and repeat the decode.", "wav-path"); + parser.addOption (fst4w_wav_test_option); + QCommandLineOption fst4w_wav_expected_option ( + QStringList {} << "fst4w-wav-expected", + "Message that must appear during both FST4W WAV decodes.", "message"); + parser.addOption (fst4w_wav_expected_option); + QCommandLineOption test_audio_speed_option ( + QStringList {} << "test-audio-speed", + "JTTY fixture delivery speed (integer 1 through 4).", "factor", "1"); + parser.addOption (test_audio_speed_option); #endif if (!parser.parse (a.arguments ())) @@ -424,6 +472,21 @@ int main(int argc, char *argv[]) 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); + jt9_wav_test = parser.isSet (jt9_wav_test_option); + jt65_wav_test = parser.isSet (jt65_wav_test_option); + q65_wav_test = parser.isSet (q65_wav_test_option); + fst4_wav_test = parser.isSet (fst4_wav_test_option); + fst4w_wav_test = parser.isSet (fst4w_wav_test_option); + bool audio_speed_valid {false}; + test_audio_speed = parser.value (test_audio_speed_option).toUInt (&audio_speed_valid); + if (!audio_speed_valid || test_audio_speed < 1 || test_audio_speed > 4 + || (parser.isSet (test_audio_speed_option) + && !jtty_live_audio_test && !jtty_tx_loopback_test)) + { + std::cerr << "--test-audio-speed requires a JTTY audio test and an integer from 1 through 4" + << std::endl; + return EXIT_FAILURE; + } if (live_audio_test != parser.isSet (live_audio_expected_option) || live_audio_test != parser.isSet (live_audio_data_dir_option)) { @@ -438,13 +501,50 @@ int main(int argc, char *argv[]) "must be used together" << std::endl; return EXIT_FAILURE; } + if (jt9_wav_test != parser.isSet (jt9_wav_expected_option) + || (jt9_wav_test && parser.value (jt9_wav_expected_option).trimmed ().isEmpty ())) + { + std::cerr << "--jt9-wav-test and a nonempty --jt9-wav-expected must be used together" + << std::endl; + return EXIT_FAILURE; + } + if (jt65_wav_test != parser.isSet (jt65_wav_expected_option) + || (jt65_wav_test && parser.value (jt65_wav_expected_option).trimmed ().isEmpty ())) + { + std::cerr << "--jt65-wav-test and a nonempty --jt65-wav-expected must be used together" + << std::endl; + return EXIT_FAILURE; + } + if (q65_wav_test != parser.isSet (q65_wav_expected_option) + || (q65_wav_test && parser.value (q65_wav_expected_option).trimmed ().isEmpty ())) + { + std::cerr << "--q65-wav-test and a nonempty --q65-wav-expected must be used together" + << std::endl; + return EXIT_FAILURE; + } + if (fst4_wav_test != parser.isSet (fst4_wav_expected_option) + || (fst4_wav_test && parser.value (fst4_wav_expected_option).trimmed ().isEmpty ())) + { + std::cerr << "--fst4-wav-test and a nonempty --fst4-wav-expected must be used together" + << std::endl; + return EXIT_FAILURE; + } + if (fst4w_wav_test != parser.isSet (fst4w_wav_expected_option) + || (fst4w_wav_test && parser.value (fst4w_wav_expected_option).trimmed ().isEmpty ())) + { + std::cerr << "--fst4w-wav-test and a nonempty --fst4w-wav-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) + + (receive_handoff_test ? 1 : 0) + (jt9_wav_test ? 1 : 0) + + (jt65_wav_test ? 1 : 0) + (q65_wav_test ? 1 : 0) + (fst4_wav_test ? 1 : 0) + + (fst4w_wav_test ? 1 : 0) > 1) { - std::cerr << "Startup, live-audio, and TX loopback tests are mutually exclusive" + std::cerr << "Startup, audio, WAV, and receive-handoff tests are mutually exclusive" << std::endl; return EXIT_FAILURE; } @@ -463,7 +563,7 @@ int main(int argc, char *argv[]) } automated_test = startup_smoke_test || live_audio_test || jtty_live_audio_test || jtty_tx_loopback_test || ft8_tx_loopback_test - || receive_handoff_test; + || receive_handoff_test || jt9_wav_test || jt65_wav_test || q65_wav_test || fst4_wav_test || fst4w_wav_test; #else automated_test = startup_smoke_test; #endif @@ -554,6 +654,9 @@ int main(int argc, char *argv[]) } } + // Release the mapping before the instance lock, including on startup failure. + DecoderIpc::Session decoderSession; + // load UI translations L10nLoader l10n {&a, locale, parser.value (lang_option)}; @@ -640,11 +743,8 @@ int main(int argc, char *argv[]) int result; 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 prerelease_expiration = QDateTime::fromSecsSinceEpoch (WSJT_PRERELEASE_EXPIRY, Qt::UTC); + bool prerelease_notice_pending = WSJT_PRERELEASE_EXPIRY > 0; auto const original_style_sheet = a.styleSheet (); auto const original_font = a.font (); auto const apply_application_appearance = [&] { @@ -713,64 +813,22 @@ int main(int argc, char *argv[]) sys_lg.push_record (boost::move (rec)); } - // Create and initialize shared memory segment - // Multiple instances: use rig_name as shared memory key - mem_jt9.setKey(a.applicationName ()); - - // try and shut down any orphaned jt9 process - for (int i = 3; i; --i) // three tries to close old jt9 + auto const sessionStatus = decoderSession.open (DecoderIpc::memoryName (instance_lock_path), + instance_lock_path + QStringLiteral (".decoder")); + if (DecoderIpc::Status::Ok != sessionStatus) { - if (mem_jt9.attach ()) // shared memory presence implies - // orphaned jt9 sub-process - { - if (DecoderIpc::hasShutdownControlSize (mem_jt9.size ())) - { - DecoderIpc::shutdownControl (mem_jt9.data ()); - } - mem_jt9.detach (); // start again - } - else - { - break; // good to go - } - QThread::sleep (1); // wait for jt9 to end - } - if (!mem_jt9.attach ()) - { - if (!mem_jt9.create (sizeof (shared_dec_data_t))) - { - 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<int> (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 - { - std::cerr << "WSJT-X startup: orphaned jt9 shared memory segment remained after " - "shutdown attempts" + std::cerr << "WSJT-X startup: " << decoderSession.errorString ().toStdString () << 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")); + nullptr, a.translate ("main", "Shared memory error"), + decoderSession.errorString ()); } - throw std::runtime_error {"Sub-process error"}; + throw std::runtime_error {"Decoder session error"}; } - auto * shared = reinterpret_cast<shared_dec_data_t *> (mem_jt9.data ()); - DecoderIpc::initialize (*shared); + LOG_INFO ("shmem size: " << decoderSession.size ()); unsigned downSampleFactor; { @@ -839,7 +897,8 @@ int main(int argc, char *argv[]) : jtty_live_audio_test_option), receive_handoff_test ? FixtureAudioInput::Profile::ReceiveHandoff : (live_audio_test ? FixtureAudioInput::Profile::Ft8 - : FixtureAudioInput::Profile::Jtty)}}; + : FixtureAudioInput::Profile::Jtty), + test_audio_speed}}; fixture_input = fixture.get (); audio_input = std::move (fixture); } @@ -852,14 +911,15 @@ int main(int argc, char *argv[]) : ft8_tx_loopback_test_option), ft8_tx_loopback_test ? FixtureSoundOutput::Profile::Ft8Period - : FixtureSoundOutput::Profile::JttyStrict}}; + : FixtureSoundOutput::Profile::JttyStrict, + test_audio_speed}}; fixture_output = fixture.get (); sound_output = std::move (fixture); } #else std::unique_ptr<AudioInputSource> audio_input; #endif - MainWindow w(temp_dir, multiple, &multi_settings, &mem_jt9, downSampleFactor, &splash, env, + MainWindow w(temp_dir, multiple, &multi_settings, decoderSession, downSampleFactor, &splash, env, automated_test, original_style_sheet, std::move (audio_input), #ifdef WSJT_ENABLE_LIVE_AUDIO_TEST std::move (sound_output), @@ -909,7 +969,7 @@ int main(int argc, char *argv[]) "available for testing purposes. By design it will\n" "be nonfunctional after " + expiration_date + "."); } - if (QDateTime::currentDateTimeUtc () >= prerelease_expiration) + if (!automated_test && QDateTime::currentDateTimeUtc () >= prerelease_expiration) { w.close (); } @@ -918,6 +978,7 @@ int main(int argc, char *argv[]) #ifdef WSJT_ENABLE_LIVE_AUDIO_TEST std::unique_ptr<LiveAudioTestController> live_audio_controller; std::unique_ptr<ReceiveHandoffTestController> receive_handoff_controller; + std::unique_ptr<WavDecodeTestController> wav_decode_controller; std::unique_ptr<JttyTxLoopbackTestController> jtty_tx_controller; std::unique_ptr<Ft8TxLoopbackTestController> ft8_tx_controller; if (live_audio_test || jtty_live_audio_test) @@ -936,6 +997,26 @@ int main(int argc, char *argv[]) controller->begin (); }); } + if (jt9_wav_test || jt65_wav_test || q65_wav_test || fst4_wav_test || fst4w_wav_test) + { + a.setQuitOnLastWindowClosed (false); + wav_decode_controller.reset (new WavDecodeTestController { + &w, parser.value (jt9_wav_test ? jt9_wav_test_option + : jt65_wav_test ? jt65_wav_test_option + : q65_wav_test ? q65_wav_test_option + : fst4_wav_test ? fst4_wav_test_option : fst4w_wav_test_option), + parser.value (jt9_wav_test ? jt9_wav_expected_option + : jt65_wav_test ? jt65_wav_expected_option + : q65_wav_test ? q65_wav_expected_option + : fst4_wav_test ? fst4_wav_expected_option : fst4w_wav_expected_option), + jt9_wav_test ? WavDecodeTestController::Mode::Jt9 + : jt65_wav_test ? WavDecodeTestController::Mode::Jt65 + : q65_wav_test ? WavDecodeTestController::Mode::Q65 + : fst4_wav_test ? WavDecodeTestController::Mode::Fst4 + : WavDecodeTestController::Mode::Fst4w}); + auto * controller = wav_decode_controller.get (); + QTimer::singleShot (0, controller, [controller] { controller->begin (); }); + } if (receive_handoff_test) { a.setQuitOnLastWindowClosed (false); @@ -1019,6 +1100,11 @@ int main(int argc, char *argv[]) { result = EXIT_FAILURE; } + if ((jt9_wav_test || jt65_wav_test || q65_wav_test || fst4_wav_test || fst4w_wav_test) + && (!wav_decode_controller || !wav_decode_controller->succeeded ())) + { + result = EXIT_FAILURE; + } if (receive_handoff_test && (!receive_handoff_controller || !receive_handoff_controller->succeeded ())) |
