summaryrefslogtreecommitdiff
path: root/tests/unit/streaming
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /tests/unit/streaming
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'tests/unit/streaming')
-rw-r--r--tests/unit/streaming/CMakeLists.txt21
-rw-r--r--tests/unit/streaming/test_streaming_consumers.cpp199
-rw-r--r--tests/unit/streaming/test_streaming_period.f90116
3 files changed, 311 insertions, 25 deletions
diff --git a/tests/unit/streaming/CMakeLists.txt b/tests/unit/streaming/CMakeLists.txt
index 5a367f45..4db80617 100644
--- a/tests/unit/streaming/CMakeLists.txt
+++ b/tests/unit/streaming/CMakeLists.txt
@@ -1,16 +1,35 @@
add_executable (test_streaming_consumers test_streaming_consumers.cpp)
+add_dependencies (test_streaming_consumers test_decoder_engine_q65 test_decoder_engine_fst4)
target_link_libraries (test_streaming_consumers Qt5::Test)
target_compile_definitions (test_streaming_consumers PRIVATE
JT9_EXECUTABLE="$<TARGET_FILE:jt9>"
WSPRD_EXECUTABLE="$<TARGET_FILE:wsprd>"
+ FST4_ENGINE_WAV="${CMAKE_BINARY_DIR}/tests/unit/decoder_engine/fst4-engine.wav"
+ FST4W_ENGINE_WAV="${CMAKE_BINARY_DIR}/tests/unit/decoder_engine/fst4w-engine.wav"
+ Q65_ENGINE_WAV="${CMAKE_BINARY_DIR}/tests/unit/decoder_engine/q65-engine.wav"
)
add_test (NAME test_streaming_consumers COMMAND test_streaming_consumers)
set_tests_properties (test_streaming_consumers PROPERTIES
LABELS "streaming;runtime"
- TIMEOUT 120
+ TIMEOUT 360
+ FIXTURES_REQUIRED "q65_engine_wav;fst4_engine_wav;fst4w_engine_wav"
)
if (WSJT_ENABLE_TSAN)
set_tests_properties (test_streaming_consumers PROPERTIES
ENVIRONMENT "TSAN_OPTIONS=${wsjt_tsan_fortran_options}")
endif ()
+
+add_executable (test_streaming_period test_streaming_period.f90)
+wsjt_link_common_fortran (test_streaming_period)
+add_test (NAME test_streaming_period COMMAND test_streaming_period)
+set_tests_properties (test_streaming_period PROPERTIES LABELS "streaming")
+
+add_executable (test_streaming_apply ${PROJECT_SOURCE_DIR}/test/apply_routing_test.f90)
+wsjt_link_common_fortran (test_streaming_apply)
+add_test (NAME test_streaming_apply COMMAND test_streaming_apply)
+set_tests_properties (test_streaming_apply PROPERTIES LABELS "streaming")
+if (WSJT_ENABLE_TSAN)
+ set_tests_properties (test_streaming_apply PROPERTIES
+ ENVIRONMENT "TSAN_OPTIONS=${wsjt_tsan_fortran_options}")
+endif ()
diff --git a/tests/unit/streaming/test_streaming_consumers.cpp b/tests/unit/streaming/test_streaming_consumers.cpp
index ba605fe1..91ed0e2e 100644
--- a/tests/unit/streaming/test_streaming_consumers.cpp
+++ b/tests/unit/streaming/test_streaming_consumers.cpp
@@ -1,16 +1,20 @@
#include <limits>
+#include <cmath>
#include <QJsonDocument>
+#include <QFile>
#include <QJsonObject>
#include <QProcess>
#include <QTemporaryDir>
#include <QtTest>
+#include <QtEndian>
namespace
{
constexpr quint32 Jt9AudioCapacityBytes = 30u * 60u * 12000u * 2u;
constexpr quint32 WsprdAudioCapacityBytes = 8u * 114u * 12000u * 2u;
-constexpr int Ft4PeriodSamples = 21 * 3456;
+// FT4's 7.5 s period at 12 kHz.
+constexpr int Ft4PeriodSamples = 90000;
constexpr int Jt9TenSecondPeriodSamples = 10 * 12000;
struct ProcessResult
@@ -158,16 +162,6 @@ ParsedEvents parseEvents (QByteArray const& output)
return parsed;
}
}
- if (type == "warning" &&
- (!event.value ("code").isString () ||
- event.value ("code").toString ().isEmpty () ||
- !event.value ("discarded_samples").isDouble () ||
- event.value ("discarded_samples").toDouble () < 0.0))
- {
- parsed.error = QString {"invalid warning event: %1"}.arg (
- QString::fromUtf8 (line));
- return parsed;
- }
parsed.values.append (event);
}
return parsed;
@@ -244,6 +238,128 @@ class TestStreamingConsumers final : public QObject
Q_OBJECT
private slots:
+ void fst4DecodesWaveform_data ()
+ {
+ QTest::addColumn<QString> ("mode");
+ QTest::addColumn<QString> ("path");
+ QTest::addColumn<int> ("period");
+ QTest::addColumn<QString> ("message");
+ QTest::newRow ("fst4-15") << QString {"FST4"} << QString::fromUtf8 (FST4_ENGINE_WAV)
+ << 15 << QString {"K1ABC W9XYZ FN42"};
+ QTest::newRow ("fst4w-120") << QString {"FST4W"} << QString::fromUtf8 (FST4W_ENGINE_WAV)
+ << 120 << QString {"K1ABC FN42 37"};
+ }
+
+ void fst4DecodesWaveform ()
+ {
+ QFETCH (QString, mode);
+ QFETCH (QString, path);
+ QFETCH (int, period);
+ QFETCH (QString, message);
+ QFile recording {path};
+ QVERIFY2 (recording.open (QIODevice::ReadOnly), qPrintable (recording.errorString ()));
+ auto const wav = recording.readAll ();
+ QCOMPARE (wav.size (), 44 + period * 12000 * 2);
+ QCOMPARE (wav.left (4), QByteArray {"RIFF"});
+ QCOMPARE (wav.mid (36, 4), QByteArray {"data"});
+ QJsonObject configuration {{"t", "configure"}, {"mode", mode}, {"trperiod", period},
+ {"depth_level", 1}, {"nfa", 1300}, {"nfb", 1700}, {"rxfreq", 1500},
+ {"noise_blanker_level", 0}, {"utc", "00:15:00"}};
+ QTemporaryDir directory;
+ QVERIFY (directory.isValid ());
+ auto const input = sessionHeader () + controlFrame (
+ QJsonDocument {configuration}.toJson (QJsonDocument::Compact)) + frame (0x01u, wav.mid (44));
+ auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE),
+ {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path (), 360000);
+ verifyCompleted (result, 0);
+ auto const events = verifyEvents (result);
+ QCOMPARE (eventsMatching (events.values, "error").size (), 0);
+ bool found = false;
+ for (auto const& decode : eventsMatching (events.values, "decode"))
+ {
+ QCOMPARE (decode.value ("mode").toString (), QString {"FST4"});
+ found |= decode.value ("message").toString ().trimmed () == message;
+ }
+ QVERIFY2 (found, result.standardOutput.constData ());
+ QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 1);
+ }
+
+ void fst4PartialEofCompletesOnce ()
+ {
+ QTemporaryDir directory;
+ QVERIFY (directory.isValid ());
+ auto const input = sessionHeader () + controlFrame (
+ R"({"t":"configure","mode":"FST4W","trperiod":120,"depth_level":1,"nutc":15})") +
+ silentAudioFrame (12001);
+ auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE),
+ {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path ());
+ verifyCompleted (result, 0);
+ auto const events = verifyEvents (result);
+ QCOMPARE (eventsMatching (events.values, "error").size (), 0);
+ QCOMPARE (eventsMatching (events.values, "decode").size (), 0);
+ auto const completions = eventsMatching (events.values, "decode_finished");
+ QCOMPARE (completions.size (), 1);
+ QCOMPARE (completions.first ().value ("period_end").toString (), QString {"001500"});
+ }
+
+ void q65DecodesWaveform ()
+ {
+ QFile recording {QString::fromUtf8 (Q65_ENGINE_WAV)};
+ QVERIFY2 (recording.open (QIODevice::ReadOnly), qPrintable (recording.errorString ()));
+ auto const wav = recording.readAll ();
+ constexpr quint32 sampleBytes = 15 * 12000 * 2;
+ QCOMPARE (wav.size (), int (44 + sampleBytes));
+ QCOMPARE (wav.left (4), QByteArray {"RIFF"});
+ QCOMPARE (wav.mid (8, 8), QByteArray {"WAVEfmt "});
+ QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 16), quint32 (16));
+ QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 20), quint16 (1));
+ QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 22), quint16 (1));
+ QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 24), quint32 (12000));
+ QCOMPARE (qFromLittleEndian<quint16> (wav.constData () + 34), quint16 (16));
+ QCOMPARE (wav.mid (36, 4), QByteArray {"data"});
+ QCOMPARE (qFromLittleEndian<quint32> (wav.constData () + 40), sampleBytes);
+
+ QTemporaryDir directory;
+ QVERIFY (directory.isValid ());
+ auto const input = sessionHeader () + controlFrame (
+ R"({"t":"configure","mode":"Q65","trperiod":15,"submode":0,"depth_level":1,"nfa":1300,"nfb":1700,"rxfreq":1500,"utc":"00:15:00"})") +
+ frame (0x01u, wav.mid (44)) + controlFrame (R"({"t":"halt"})");
+ auto const result = runProcess (QString::fromUtf8 (JT9_EXECUTABLE),
+ {"-a", directory.path (), "-t", directory.path (), "--stream"}, input, directory.path ());
+ verifyCompleted (result, 0);
+ auto const events = verifyEvents (result);
+ QCOMPARE (eventsMatching (events.values, "error").size (), 0);
+ auto const decodes = eventsMatching (events.values, "decode");
+ QVERIFY2 (!decodes.isEmpty (), result.standardOutput.constData ());
+ bool found = false;
+ for (auto const& decode : decodes)
+ {
+ QCOMPARE (decode.value ("mode").toString (), QString {"Q65"});
+ QCOMPARE (decode.value ("time").toString (), QString {"001500"});
+ found |= decode.value ("message").toString ().trimmed () == "K1ABC W9XYZ FN42";
+ }
+ QVERIFY2 (found, result.standardOutput.constData ());
+ auto const completions = eventsMatching (events.values, "decode_finished");
+ QCOMPARE (completions.size (), 1);
+ QCOMPARE (completions.first ().value ("period_end").toString (), QString {"001500"});
+
+ QFile curves {directory.filePath ("red.dat")};
+ QVERIFY2 (curves.open (QIODevice::ReadOnly), qPrintable (curves.errorString ()));
+ auto const rows = curves.readAll ().trimmed ().split ('\n');
+ QVERIFY (rows.size () > 1);
+ for (auto const& row : rows)
+ {
+ auto const values = row.simplified ().split (' ');
+ QCOMPARE (values.size (), 3);
+ for (auto const& value : values)
+ {
+ bool ok;
+ auto const number = value.toDouble (&ok);
+ QVERIFY (ok && std::isfinite (number));
+ }
+ }
+ }
+
void jt9RejectsOversizedFrames_data ()
{
QTest::addColumn<quint32> ("declaredLength");
@@ -280,10 +396,8 @@ private slots:
verifyCompleted (result, 0);
auto const events = verifyEvents (result);
QCOMPARE (eventsMatching (events.values, "error", "unknown_mode").size (), 1);
- auto const warnings = eventsMatching (
- events.values, "warning", "period_boundary_discard");
- QCOMPARE (warnings.size (), 1);
- QCOMPARE (warnings.front ().value ("discarded_samples").toInt (), 2);
+ // The two samples past the 10 s period open the next period, drained at EOF.
+ QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 2);
}
void jt9RejectsOutOfRangeTrperiod_data ()
@@ -306,22 +420,59 @@ private slots:
QCOMPARE (eventsMatching (events.values, "decode").size (), 0);
}
- void jt9ReportsBoundaryDiscardOnce ()
+ // A straddling frame carries its remainder into the next period.
+ void jt9CarriesStraddlingFrameIntoNextPeriod ()
{
auto const exact = runJt9 (sessionHeader () +
silentAudioFrame (Ft4PeriodSamples), {"--ft4"});
verifyCompleted (exact, 0);
auto const exactEvents = verifyEvents (exact);
- QCOMPARE (eventsMatching (exactEvents.values, "warning").size (), 0);
+ QCOMPARE (eventsMatching (exactEvents.values, "decode_finished").size (), 1);
- auto const overflow = runJt9 (
+ auto const straddle = runJt9 (
sessionHeader () + silentAudioFrame (Ft4PeriodSamples + 2), {"--ft4"});
- verifyCompleted (overflow, 0);
- auto const overflowEvents = verifyEvents (overflow);
- auto const warnings = eventsMatching (
- overflowEvents.values, "warning", "period_boundary_discard");
- QCOMPARE (warnings.size (), 1);
- QCOMPARE (warnings.front ().value ("discarded_samples").toInt (), 2);
+ verifyCompleted (straddle, 0);
+ auto const straddleEvents = verifyEvents (straddle);
+ QCOMPARE (eventsMatching (straddleEvents.values, "decode_finished").size (), 2);
+
+ // The decoder's share alone is not a period; the EOF drain reports it.
+ auto const decoderOnly = runJt9 (
+ sessionHeader () + silentAudioFrame (21 * 3456), {"--ft4"});
+ verifyCompleted (decoderOnly, 0);
+ auto const decoderOnlyEvents = verifyEvents (decoderOnly);
+ QCOMPARE (eventsMatching (decoderOnlyEvents.values, "decode_finished").size (), 1);
+ }
+
+ // A configure that changes the period starts a new one; nothing of the
+ // old period drains at the new length.
+ void jt9StartsANewPeriodOnATrperiodChange ()
+ {
+ // Half a 10 s period, a change to 20 s, then exactly one 20 s period.
+ auto const result = runJt9 (
+ sessionHeader () +
+ controlFrame (R"({"t":"configure","trperiod":10})") +
+ silentAudioFrame (Jt9TenSecondPeriodSamples / 2) +
+ controlFrame (R"({"t":"configure","trperiod":20})") +
+ silentAudioFrame (2 * Jt9TenSecondPeriodSamples), {"-9"});
+ verifyCompleted (result, 0);
+ auto const events = verifyEvents (result);
+ QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 1);
+ }
+
+ // Repeating the current configuration mid-period leaves the period alone.
+ void jt9KeepsThePeriodOnAnUnchangedConfigure ()
+ {
+ // Half a 10 s period, the same configuration again, then the other half
+ // plus two samples: one full period, and the two samples open the next.
+ auto const result = runJt9 (
+ sessionHeader () +
+ controlFrame (R"({"t":"configure","mode":"JT9","trperiod":10})") +
+ silentAudioFrame (Jt9TenSecondPeriodSamples / 2) +
+ controlFrame (R"({"t":"configure","mode":"JT9","trperiod":10})") +
+ silentAudioFrame (Jt9TenSecondPeriodSamples / 2 + 2), {"-9"});
+ verifyCompleted (result, 0);
+ auto const events = verifyEvents (result);
+ QCOMPARE (eventsMatching (events.values, "decode_finished").size (), 2);
}
void wsprdRejectsOversizedFrames_data ()
diff --git a/tests/unit/streaming/test_streaming_period.f90 b/tests/unit/streaming/test_streaming_period.f90
new file mode 100644
index 00000000..6ac3ed0b
--- /dev/null
+++ b/tests/unit/streaming/test_streaming_period.f90
@@ -0,0 +1,116 @@
+program test_streaming_period
+ use streaming_period, only: period_state, period_begin, period_room, &
+ period_take, period_full, period_ready
+ implicit none
+
+ integer, parameter :: NMAX = 1800 * 12000
+ integer :: nfail = 0
+
+ call sizes()
+ call frames_of_128('FT8', 8, 15.d0, 180000, 50 * 3456)
+ call frames_of_128('FT4', 5, 7.5d0, 90000, 21 * 3456)
+ call straddle()
+ call short_periods()
+
+ if (nfail .eq. 0) then
+ print '(a)', 'ALL STREAMING PERIOD CHECKS PASSED'
+ else
+ print '(a,i0,a)', 'STREAMING PERIOD: ', nfail, ' CHECK(S) FAILED'
+ call exit(1)
+ end if
+
+contains
+
+ subroutine ok(label, cond)
+ character(len=*), intent(in) :: label
+ logical, intent(in) :: cond
+ if (cond) then
+ print '(a,a)', ' PASS ', label
+ else
+ print '(a,a)', ' FAIL ', label
+ nfail = nfail + 1
+ end if
+ end subroutine ok
+
+ subroutine sizes()
+ type(period_state) :: st
+ call period_begin(st, 15.d0, 8, NMAX)
+ call ok('FT8: period 180000, decoder 172800', &
+ st%nperiod .eq. 180000 .and. st%npts .eq. 50 * 3456)
+ call period_begin(st, 7.5d0, 5, NMAX)
+ call ok('FT4: period 90000, decoder 72576', &
+ st%nperiod .eq. 90000 .and. st%npts .eq. 21 * 3456)
+ call period_begin(st, 60.d0, 9, NMAX)
+ call ok('JT9: period 720000, decoder 720000', &
+ st%nperiod .eq. 720000 .and. st%npts .eq. 720000)
+ call period_begin(st, 30.d0, 8, NMAX)
+ call ok('FT8 at 30 s: decoder still 172800, period 360000', &
+ st%nperiod .eq. 360000 .and. st%npts .eq. 50 * 3456)
+ end subroutine sizes
+
+ subroutine frames_of_128(name, mode, tr, nperiod, npts)
+ character(len=*), intent(in) :: name
+ integer, intent(in) :: mode, nperiod, npts
+ real(8), intent(in) :: tr
+ type(period_state) :: st
+ integer :: left, ntake, nacc, iperiod, consumed, fed, ready_at
+ logical :: good
+ good = .true.
+ left = 0
+ do iperiod = 1, 3
+ call period_begin(st, tr, mode, NMAX)
+ consumed = 0; fed = 0; ready_at = -1
+ do while (.not. period_full(st))
+ if (left .eq. 0) left = 128
+ ntake = period_room(st, left)
+ call period_take(st, ntake, nacc)
+ left = left - ntake
+ consumed = consumed + ntake
+ fed = fed + nacc
+ if (ready_at .lt. 0 .and. period_ready(st)) ready_at = consumed
+ end do
+ ! `left` is what the frame crossing this boundary owes the next period.
+ good = good .and. consumed .eq. nperiod .and. fed .eq. npts &
+ .and. ready_at .ge. npts .and. ready_at .lt. npts + 128 &
+ .and. left .eq. mod(128 - mod(iperiod * nperiod, 128), 128)
+ end do
+ call ok(name // ': three periods of 128-sample frames — nperiod consumed,' &
+ // ' npts to the decoder, ready within a frame of npts, remainder carried', good)
+ end subroutine frames_of_128
+
+ subroutine straddle()
+ type(period_state) :: st
+ integer :: ntake, nacc, left
+ call period_begin(st, 7.5d0, 5, NMAX)
+ call period_take(st, 90000 - 100, nacc)
+ left = 128
+ ntake = period_room(st, left)
+ call ok('straddle: a 128-sample frame 100 short of the boundary yields 100', &
+ ntake .eq. 100)
+ call period_take(st, ntake, nacc)
+ left = left - ntake
+ call ok('straddle: the period is full and 28 samples remain', &
+ period_full(st) .and. left .eq. 28)
+ call period_begin(st, 7.5d0, 5, NMAX)
+ ntake = period_room(st, left)
+ call period_take(st, ntake, nacc)
+ call ok('straddle: the next period opens with those 28, all to the decoder', &
+ ntake .eq. 28 .and. nacc .eq. 28 .and. st%kperiod .eq. 28 .and. st%k .eq. 28)
+ call ok('straddle: nothing past the decoder share reaches it', &
+ period_room(st, 100000) .eq. 90000 - 28)
+ end subroutine straddle
+
+ subroutine short_periods()
+ type(period_state) :: st
+ call period_begin(st, 1.d0, 5, NMAX)
+ call ok('FT4 at 1 s: period stretched to the decoder share, 72576', &
+ st%nperiod .eq. st%npts .and. st%npts .eq. 21 * 3456)
+ call period_begin(st, 15.d0, 8, 100000)
+ call ok('small buffer: decoder share capped at the buffer, period 180000', &
+ st%npts .eq. 100000 .and. st%nperiod .eq. 180000)
+ call period_begin(st, 0.d0, 9, NMAX)
+ call ok('zero TRperiod: one second of decoder share, period the same', &
+ st%npts .eq. 12000 .and. st%nperiod .eq. 12000)
+ end subroutine short_periods
+
+end program test_streaming_period