summaryrefslogtreecommitdiff
path: root/tests/unit/ft8
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /tests/unit/ft8
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'tests/unit/ft8')
-rw-r--r--tests/unit/ft8/CMakeLists.txt51
-rw-r--r--tests/unit/ft8/test_ft8_decode_ranges.f9068
-rw-r--r--tests/unit/ft8/test_ft8_mtd_decode_coordinator.cpp327
-rw-r--r--tests/unit/ft8/test_ft8_mtd_decode_scheduler.cpp137
-rw-r--r--tests/unit/ft8/test_ft8_mtd_residual.f90281
-rw-r--r--tests/unit/ft8/test_ft8_mtd_transaction_concurrent.f90195
6 files changed, 1059 insertions, 0 deletions
diff --git a/tests/unit/ft8/CMakeLists.txt b/tests/unit/ft8/CMakeLists.txt
new file mode 100644
index 00000000..18eb4557
--- /dev/null
+++ b/tests/unit/ft8/CMakeLists.txt
@@ -0,0 +1,51 @@
+add_executable (test_ft8_mtd_decode_scheduler
+ test_ft8_mtd_decode_scheduler.cpp
+ ${CMAKE_SOURCE_DIR}/Ft8MtdDecodeScheduler.cpp
+)
+target_include_directories (test_ft8_mtd_decode_scheduler PRIVATE ${CMAKE_SOURCE_DIR})
+target_link_libraries (test_ft8_mtd_decode_scheduler Qt5::Test)
+add_test (NAME test_ft8_mtd_decode_scheduler COMMAND test_ft8_mtd_decode_scheduler)
+
+add_executable (test_ft8_mtd_decode_coordinator
+ test_ft8_mtd_decode_coordinator.cpp
+ ${CMAKE_SOURCE_DIR}/Ft8MtdDecodeCoordinator.cpp
+ ${CMAKE_SOURCE_DIR}/Ft8MtdDecodeScheduler.cpp
+ ${CMAKE_SOURCE_DIR}/DecoderIpc.cpp
+ ${CMAKE_SOURCE_DIR}/lib/decoder_ipc_control.cpp
+)
+target_include_directories (test_ft8_mtd_decode_coordinator PRIVATE
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/lib
+)
+target_link_libraries (test_ft8_mtd_decode_coordinator Qt5::Test)
+add_test (NAME test_ft8_mtd_decode_coordinator COMMAND test_ft8_mtd_decode_coordinator)
+
+add_executable (test_ft8_decode_ranges
+ test_ft8_decode_ranges.f90)
+target_include_directories (test_ft8_decode_ranges PRIVATE ${CMAKE_BINARY_DIR})
+wsjt_link_common_fortran (test_ft8_decode_ranges)
+
+add_test (NAME test_ft8_decode_ranges COMMAND test_ft8_decode_ranges)
+
+add_executable (test_ft8_mtd_residual
+ test_ft8_mtd_residual.f90)
+target_include_directories (test_ft8_mtd_residual PRIVATE ${CMAKE_BINARY_DIR})
+wsjt_link_common_fortran (test_ft8_mtd_residual)
+
+add_test (NAME test_ft8_mtd_residual COMMAND test_ft8_mtd_residual)
+
+if (TARGET wsjt_fort_omp)
+ add_executable (test_ft8_mtd_transaction_concurrent
+ test_ft8_mtd_transaction_concurrent.f90)
+ target_include_directories (test_ft8_mtd_transaction_concurrent PRIVATE
+ ${WSJT_FORTRAN_OPENMP_MODULE_DIR})
+ target_link_libraries (test_ft8_mtd_transaction_concurrent PRIVATE
+ wsjt_fort_omp wsjt_fortran_openmp)
+
+ add_test (NAME test_ft8_mtd_transaction_concurrent
+ COMMAND test_ft8_mtd_transaction_concurrent)
+ set_tests_properties (test_ft8_mtd_transaction_concurrent PROPERTIES
+ ENVIRONMENT "OMP_DYNAMIC=FALSE;OMP_NUM_THREADS=4;OMP_THREAD_LIMIT=4"
+ PROCESSORS 4
+ TIMEOUT 30)
+endif ()
diff --git a/tests/unit/ft8/test_ft8_decode_ranges.f90 b/tests/unit/ft8/test_ft8_decode_ranges.f90
new file mode 100644
index 00000000..9f6f2466
--- /dev/null
+++ b/tests/unit/ft8/test_ft8_decode_ranges.f90
@@ -0,0 +1,68 @@
+program test_ft8_decode_ranges
+ use ft8_decode_ranges, only: max_ft8_decode_ranges, partition_ft8_decode_range
+ implicit none
+
+ integer :: requested_ranges
+
+ do requested_ranges=1,max_ft8_decode_ranges
+ call assert_partition(200,1000,requested_ranges,requested_ranges)
+ enddo
+
+ call assert_empty_partition(4900,1000,12)
+ call assert_partition(1000,1000,12,1)
+ call assert_partition(999,1000,12,2)
+ call assert_partition(4900,5000,12,12)
+ call assert_upper_bounds(200,1000,11, &
+ [272,345,418,491,564,637,710,783,856,928,1000])
+ call assert_upper_bounds(200,1000,12, &
+ [266,333,400,467,534,601,668,735,802,868,934,1000])
+
+contains
+
+ subroutine assert_empty_partition(nfa,nfb,requested_ranges)
+ integer, intent(in) :: nfa,nfb,requested_ranges
+ integer :: range_low(max_ft8_decode_ranges)
+ integer :: range_high(max_ft8_decode_ranges)
+ integer :: nranges
+
+ call partition_ft8_decode_range(nfa,nfb,requested_ranges,range_low,range_high,nranges)
+ if(nranges.ne.0) error stop 'reversed range must produce no partitions'
+ end subroutine assert_empty_partition
+
+ subroutine assert_upper_bounds(nfa,nfb,requested_ranges,expected_high)
+ integer, intent(in) :: nfa,nfb,requested_ranges
+ integer, intent(in) :: expected_high(:)
+ integer :: range_low(max_ft8_decode_ranges)
+ integer :: range_high(max_ft8_decode_ranges)
+ integer :: nranges
+
+ call partition_ft8_decode_range(nfa,nfb,requested_ranges,range_low,range_high,nranges)
+ if(nranges.ne.size(expected_high)) error stop 'unexpected exact partition count'
+ if(any(range_high(1:nranges).ne.expected_high)) error stop 'unexpected partition boundary'
+ end subroutine assert_upper_bounds
+
+ subroutine assert_partition(nfa,nfb,requested_ranges,expected_ranges)
+ integer, intent(in) :: nfa,nfb,requested_ranges,expected_ranges
+ integer :: i,max_width,min_width,nranges
+ integer :: range_low(max_ft8_decode_ranges)
+ integer :: range_high(max_ft8_decode_ranges)
+
+ call partition_ft8_decode_range(nfa,nfb,requested_ranges,range_low,range_high,nranges)
+
+ if(nranges.ne.expected_ranges) error stop 'unexpected partition count'
+ if(range_low(1).ne.nfa) error stop 'partitioning changed the lower bound'
+ if(range_high(nranges).ne.nfb) error stop 'partitioning changed the upper bound'
+
+ do i=1,nranges
+ if(range_low(i).gt.range_high(i)) error stop 'partition is reversed'
+ if(i.gt.1) then
+ if(range_low(i).ne.range_high(i-1)+1) error stop 'partitions are not contiguous'
+ endif
+ enddo
+
+ min_width=minval(range_high(1:nranges)-range_low(1:nranges)+1)
+ max_width=maxval(range_high(1:nranges)-range_low(1:nranges)+1)
+ if(max_width-min_width.gt.1) error stop 'partitions are not balanced'
+ end subroutine assert_partition
+
+end program test_ft8_decode_ranges
diff --git a/tests/unit/ft8/test_ft8_mtd_decode_coordinator.cpp b/tests/unit/ft8/test_ft8_mtd_decode_coordinator.cpp
new file mode 100644
index 00000000..2debacb3
--- /dev/null
+++ b/tests/unit/ft8/test_ft8_mtd_decode_coordinator.cpp
@@ -0,0 +1,327 @@
+#include <QtTest>
+
+#include <memory>
+#include <vector>
+
+#include "Ft8MtdDecodeCoordinator.hpp"
+
+namespace
+{
+ using Stage = Ft8MtdDecodeCoordinator::Stage;
+ using Action = Ft8MtdDecodeCoordinator::Action;
+ using DrainResult = Ft8MtdDecodeCoordinator::DrainResult;
+ using PendingPublishResult = Ft8MtdDecodeCoordinator::PendingPublishResult;
+
+ std::unique_ptr<Ft8MtdDecodeCoordinator::PendingMtdDecode> pendingDecode (
+ qint64 period, int nutc, short firstSample)
+ {
+ auto pending = std::make_unique<Ft8MtdDecodeCoordinator::PendingMtdDecode> ();
+ pending->period = period;
+ pending->payload.params.nmode = 8;
+ pending->payload.params.lmultift8 = true;
+ pending->payload.params.nutc = nutc;
+ pending->payload.samples[0] = firstSample;
+ pending->context.mode = "FT8";
+ pending->context.periodFrequency = 14074000;
+ pending->context.band = "20m";
+ pending->context.multithreadFt8 = true;
+ pending->context.ft8ThreadCount = 4;
+ pending->context.decodeDepth = 3;
+ return pending;
+ }
+
+ class FakeBackend
+ {
+ public:
+ void startEarly (Stage stage, qint64 period, int earlyStageCount)
+ {
+ auto const decision = coordinator.request (
+ stage, period, earlyStageCount, active);
+ QCOMPARE (decision.action, Action::Publish);
+ active = true;
+ activeStage = stage;
+ activePeriod = period;
+ coordinator.published (stage, period);
+ publishedPeriods.push_back (period);
+ }
+
+ Action submitFinal (qint64 period, int nutc, short firstSample,
+ int earlyStageCount = 1)
+ {
+ auto const decision = coordinator.request (
+ Stage::Final, period, earlyStageCount,
+ active || coordinator.hasPending ());
+ if (Action::Publish == decision.action)
+ {
+ active = true;
+ activeStage = Stage::Final;
+ activePeriod = period;
+ coordinator.published (Stage::Final, period);
+ publishedPeriods.push_back (period);
+ publishedNutcs.push_back (nutc);
+ return decision.action;
+ }
+
+ return coordinator.deferFinal (
+ pendingDecode (period, nutc, firstSample));
+ }
+
+ void completeAndDrain ()
+ {
+ QVERIFY (active);
+ coordinator.completed (activeStage, activePeriod);
+ active = false;
+ activeStage = Stage::None;
+ activePeriod = -1;
+ if (!coordinator.hasPending ()) return;
+
+ auto const outcome = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return true;},
+ [this] (Ft8MtdDecodeCoordinator::PendingMtdDecode const& pending) {
+ active = true;
+ activeStage = Stage::Final;
+ activePeriod = pending.period;
+ publishedPeriods.push_back (pending.period);
+ publishedNutcs.push_back (pending.payload.params.nutc);
+ publishedFirstSamples.push_back (pending.payload.samples[0]);
+ publishedContext = pending.context;
+ return PendingPublishResult::Published;
+ });
+ QCOMPARE (outcome.result, DrainResult::Published);
+ }
+
+ bool externallyBusy () const
+ {
+ return active || coordinator.hasPending ();
+ }
+
+ Ft8MtdDecodeCoordinator coordinator;
+ bool active {false};
+ Stage activeStage {Stage::None};
+ qint64 activePeriod {-1};
+ std::vector<qint64> publishedPeriods;
+ std::vector<int> publishedNutcs;
+ std::vector<short> publishedFirstSamples;
+ DecodeOperatingContext publishedContext;
+ };
+}
+
+class TestFt8MtdDecodeCoordinator final : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void slowEarlyDecodeRetainsAndPublishesFinalOnce ();
+ void unrelatedCompletionDoesNotPublishPendingFinal ();
+ void multiPeriodOverrunPublishesOnlyNewestFinal ();
+ void pendingSnapshotIsImmutable ();
+ void pendingContextReachesFinalPublication ();
+ void pendingCountsAsBusyUntilDrain ();
+ void temporaryBackendFailurePreservesPending ();
+ void fatalBackendFailureDropsPending ();
+ void publicationFailureLeavesPendingForRestart ();
+ void changedContextDropsPendingWithoutPublishing ();
+ void cancellationDropsPendingAndSchedulingState ();
+};
+
+void TestFt8MtdDecodeCoordinator::slowEarlyDecodeRetainsAndPublishesFinalOnce ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 100, 1);
+
+ QCOMPARE (backend.submitFinal (100, 120000, 17), Action::DeferFinal);
+ QVERIFY (backend.externallyBusy ());
+ backend.completeAndDrain ();
+
+ QVERIFY (backend.publishedPeriods == std::vector<qint64> ({100, 100}));
+ QVERIFY (backend.publishedNutcs == std::vector<int> ({120000}));
+ QCOMPARE (backend.activeStage, Stage::Final);
+ QCOMPARE (backend.activePeriod, qint64 {100});
+ QVERIFY (backend.active);
+ QVERIFY (!backend.coordinator.hasPending ());
+}
+
+void TestFt8MtdDecodeCoordinator::unrelatedCompletionDoesNotPublishPendingFinal ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 150, 1);
+ backend.submitFinal (150, 120015, 18);
+
+ backend.coordinator.completed (Stage::EarlyOne, 149);
+
+ QVERIFY (backend.coordinator.hasPending ());
+ QVERIFY (backend.publishedPeriods == std::vector<qint64> ({150}));
+
+ backend.completeAndDrain ();
+ QVERIFY (backend.publishedPeriods == std::vector<qint64> ({150, 150}));
+}
+
+void TestFt8MtdDecodeCoordinator::multiPeriodOverrunPublishesOnlyNewestFinal ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 200, 1);
+ QCOMPARE (backend.submitFinal (200, 130000, 20), Action::DeferFinal);
+ QCOMPARE (backend.submitFinal (201, 130015, 21), Action::ReplaceFinal);
+ QCOMPARE (backend.submitFinal (202, 130030, 22), Action::ReplaceFinal);
+
+ backend.completeAndDrain ();
+
+ QVERIFY (backend.publishedPeriods == std::vector<qint64> ({200, 202}));
+ QVERIFY (backend.publishedNutcs == std::vector<int> ({130030}));
+ QVERIFY (backend.publishedFirstSamples == std::vector<short> ({22}));
+}
+
+void TestFt8MtdDecodeCoordinator::pendingSnapshotIsImmutable ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 300, 1);
+ int sourceNutC {140000};
+ short sourceSample {31};
+ backend.submitFinal (300, sourceNutC, sourceSample);
+ sourceNutC = 140015;
+ sourceSample = 32;
+
+ backend.completeAndDrain ();
+
+ QCOMPARE (backend.publishedNutcs.back (), 140000);
+ QCOMPARE (backend.publishedFirstSamples.back (), short {31});
+}
+
+void TestFt8MtdDecodeCoordinator::pendingContextReachesFinalPublication ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 350, 1);
+ backend.submitFinal (350, 140015, 35);
+
+ backend.completeAndDrain ();
+
+ auto const& context = backend.publishedContext;
+ QCOMPARE (context.mode, QStringLiteral ("FT8"));
+ QCOMPARE (context.periodFrequency, Radio::Frequency {14074000});
+ QCOMPARE (context.band, QStringLiteral ("20m"));
+ QVERIFY (context.multithreadFt8);
+ QCOMPARE (context.ft8ThreadCount, 4);
+ QCOMPARE (context.decodeDepth, 3);
+}
+
+void TestFt8MtdDecodeCoordinator::pendingCountsAsBusyUntilDrain ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 400, 1);
+ backend.submitFinal (400, 150000, 41);
+
+ backend.active = false;
+ QVERIFY (backend.coordinator.hasPending ());
+ QVERIFY (backend.externallyBusy ());
+ backend.active = true;
+ backend.completeAndDrain ();
+ QVERIFY (backend.externallyBusy ());
+}
+
+void TestFt8MtdDecodeCoordinator::temporaryBackendFailurePreservesPending ()
+{
+ Ft8MtdDecodeCoordinator coordinator;
+ coordinator.deferFinal (pendingDecode (500, 160000, 51));
+
+ auto const unavailable = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return true;},
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {
+ return PendingPublishResult::Unavailable;
+ });
+ QCOMPARE (unavailable.result, DrainResult::Retained);
+ QVERIFY (coordinator.hasPending ());
+
+ auto shared = std::make_unique<shared_dec_data_t> ();
+ DecoderIpc::initialize (*shared);
+ int publishCalls {0};
+ auto const published = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return true;},
+ [&] (Ft8MtdDecodeCoordinator::PendingMtdDecode const& pending) {
+ ++publishCalls;
+ return DecoderIpc::publishFt8Mtd (*shared, pending.payload, 1)
+ ? PendingPublishResult::Published : PendingPublishResult::Failed;
+ });
+
+ QCOMPARE (published.result, DrainResult::Published);
+ QCOMPARE (publishCalls, 1);
+ QVERIFY (!coordinator.hasPending ());
+ QCOMPARE (shared->payload.params.nutc, 160000);
+ QCOMPARE (shared->payload.d2[0], short {51});
+
+ auto const empty = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return true;},
+ [&] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {
+ ++publishCalls;
+ return PendingPublishResult::Published;
+ });
+ QCOMPARE (empty.result, DrainResult::NoPending);
+ QCOMPARE (publishCalls, 1);
+}
+
+void TestFt8MtdDecodeCoordinator::fatalBackendFailureDropsPending ()
+{
+ Ft8MtdDecodeCoordinator coordinator;
+ coordinator.deferFinal (pendingDecode (510, 160015, 52));
+
+ auto const outcome = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return true;},
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {
+ return PendingPublishResult::Failed;
+ });
+
+ QCOMPARE (outcome.result, DrainResult::Failed);
+ QVERIFY (!coordinator.hasPending ());
+}
+
+void TestFt8MtdDecodeCoordinator::publicationFailureLeavesPendingForRestart ()
+{
+ FakeBackend backend;
+ backend.startEarly (Stage::EarlyOne, 515, 1);
+ backend.submitFinal (515, 160020, 52);
+
+ backend.coordinator.publicationFailed (Stage::EarlyOne, 515);
+ QVERIFY (backend.coordinator.hasPending ());
+
+ backend.completeAndDrain ();
+
+ QVERIFY (backend.publishedPeriods == std::vector<qint64> ({515, 515}));
+ QVERIFY (!backend.coordinator.hasPending ());
+}
+
+void TestFt8MtdDecodeCoordinator::changedContextDropsPendingWithoutPublishing ()
+{
+ Ft8MtdDecodeCoordinator coordinator;
+ coordinator.request (Stage::Final, 520, 1, true);
+ coordinator.deferFinal (pendingDecode (520, 160030, 53));
+ int publishCalls {0};
+
+ auto const outcome = coordinator.drainPending (
+ [] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {return false;},
+ [&] (Ft8MtdDecodeCoordinator::PendingMtdDecode const&) {
+ ++publishCalls;
+ return PendingPublishResult::Published;
+ });
+
+ QCOMPARE (outcome.result, DrainResult::Obsolete);
+ QCOMPARE (publishCalls, 0);
+ QVERIFY (!coordinator.hasPending ());
+ QVERIFY (!coordinator.degraded ());
+}
+
+void TestFt8MtdDecodeCoordinator::cancellationDropsPendingAndSchedulingState ()
+{
+ Ft8MtdDecodeCoordinator coordinator;
+ coordinator.request (Stage::Final, 600, 1, true);
+ coordinator.deferFinal (pendingDecode (600, 170000, 61));
+ QVERIFY (coordinator.degraded ());
+
+ coordinator.cancel ();
+
+ QVERIFY (!coordinator.hasPending ());
+ QVERIFY (!coordinator.degraded ());
+ QCOMPARE (coordinator.nextProbePeriod (), qint64 {0});
+}
+
+QTEST_GUILESS_MAIN (TestFt8MtdDecodeCoordinator)
+
+#include "test_ft8_mtd_decode_coordinator.moc"
diff --git a/tests/unit/ft8/test_ft8_mtd_decode_scheduler.cpp b/tests/unit/ft8/test_ft8_mtd_decode_scheduler.cpp
new file mode 100644
index 00000000..13b96ce5
--- /dev/null
+++ b/tests/unit/ft8/test_ft8_mtd_decode_scheduler.cpp
@@ -0,0 +1,137 @@
+#include <QtTest>
+
+#include "Ft8MtdDecodeScheduler.hpp"
+
+class TestFt8MtdDecodeScheduler final : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void eligibilityRequiresIndependentMtdFinal ();
+ void idleRequestsPublishImmediately ();
+ void earlyRequestsNeverQueue ();
+ void finalRequestsDeferOrReplace ();
+ void failedProbesBackOffExponentially ();
+ void oneEarlyPassMtdConfigurationRecovers ();
+ void twoEarlyPassMtdConfigurationRequiresBothEarlyPasses ();
+ void cancelRestoresBoundedInitialState ();
+};
+
+using Stage = Ft8MtdDecodeScheduler::Stage;
+using Action = Ft8MtdDecodeScheduler::Action;
+
+void TestFt8MtdDecodeScheduler::eligibilityRequiresIndependentMtdFinal ()
+{
+ QVERIFY (!Ft8MtdDecodeScheduler::supportsBackpressure (false, false));
+ QVERIFY (Ft8MtdDecodeScheduler::supportsBackpressure (true, false));
+ QVERIFY (!Ft8MtdDecodeScheduler::supportsBackpressure (true, true));
+}
+
+void TestFt8MtdDecodeScheduler::idleRequestsPublishImmediately ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ QCOMPARE (scheduler.request (Stage::EarlyOne, 10, 1, false, false).action,
+ Action::Publish);
+ QCOMPARE (scheduler.request (Stage::Final, 10, 1, false, false).action,
+ Action::Publish);
+ QVERIFY (!scheduler.degraded ());
+}
+
+void TestFt8MtdDecodeScheduler::earlyRequestsNeverQueue ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ auto const decision = scheduler.request (Stage::EarlyOne, 20, 1, true, false);
+ QCOMPARE (decision.action, Action::SkipEarly);
+ QVERIFY (decision.enteredDegraded);
+ QVERIFY (scheduler.degraded ());
+}
+
+void TestFt8MtdDecodeScheduler::finalRequestsDeferOrReplace ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ QCOMPARE (scheduler.request (Stage::Final, 30, 1, true, false).action,
+ Action::DeferFinal);
+ QCOMPARE (scheduler.request (Stage::Final, 31, 1, true, true).action,
+ Action::ReplaceFinal);
+}
+
+void TestFt8MtdDecodeScheduler::failedProbesBackOffExponentially ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ auto result = scheduler.request (Stage::EarlyOne, 40, 1, true, false);
+ QCOMPARE (result.skippedPeriods, 1);
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {42});
+ QCOMPARE (scheduler.request (Stage::EarlyOne, 41, 1, false, false).action,
+ Action::SkipEarly);
+
+ result = scheduler.request (Stage::EarlyOne, 42, 1, true, false);
+ QCOMPARE (result.skippedPeriods, 2);
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {45});
+ result = scheduler.request (Stage::EarlyOne, 45, 1, true, false);
+ QCOMPARE (result.skippedPeriods, 4);
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {50});
+ result = scheduler.request (Stage::EarlyOne, 50, 1, true, false);
+ QCOMPARE (result.skippedPeriods, 8);
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {59});
+ result = scheduler.request (Stage::EarlyOne, 59, 1, true, false);
+ QCOMPARE (result.skippedPeriods, 8);
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {68});
+}
+
+void TestFt8MtdDecodeScheduler::oneEarlyPassMtdConfigurationRecovers ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ scheduler.request (Stage::Final, 60, 1, true, false);
+ QCOMPARE (scheduler.request (Stage::EarlyOne, 62, 1, false, false).action,
+ Action::Publish);
+ scheduler.published (Stage::EarlyOne, 62);
+ scheduler.completed (Stage::EarlyOne, 62);
+ QCOMPARE (scheduler.request (Stage::Final, 62, 1, false, false).action,
+ Action::Publish);
+ QVERIFY (scheduler.published (Stage::Final, 62));
+ QVERIFY (!scheduler.degraded ());
+}
+
+void TestFt8MtdDecodeScheduler::twoEarlyPassMtdConfigurationRequiresBothEarlyPasses ()
+{
+ Ft8MtdDecodeScheduler complete;
+ complete.request (Stage::Final, 70, 2, true, false);
+ complete.request (Stage::EarlyOne, 72, 2, false, false);
+ complete.published (Stage::EarlyOne, 72);
+ complete.completed (Stage::EarlyOne, 72);
+ QCOMPARE (complete.request (Stage::EarlyTwo, 72, 2, false, false).action,
+ Action::Publish);
+ complete.published (Stage::EarlyTwo, 72);
+ complete.completed (Stage::EarlyTwo, 72);
+ QCOMPARE (complete.request (Stage::Final, 72, 2, false, false).action,
+ Action::Publish);
+ QVERIFY (complete.published (Stage::Final, 72));
+ QVERIFY (!complete.degraded ());
+
+ Ft8MtdDecodeScheduler incomplete;
+ incomplete.request (Stage::Final, 80, 2, true, false);
+ incomplete.request (Stage::EarlyOne, 82, 2, false, false);
+ incomplete.published (Stage::EarlyOne, 82);
+ incomplete.completed (Stage::EarlyOne, 82);
+ incomplete.request (Stage::EarlyTwo, 82, 2, false, false);
+ incomplete.published (Stage::EarlyTwo, 82);
+ QCOMPARE (incomplete.request (Stage::Final, 82, 2, true, false).action,
+ Action::DeferFinal);
+ QVERIFY (incomplete.degraded ());
+}
+
+void TestFt8MtdDecodeScheduler::cancelRestoresBoundedInitialState ()
+{
+ Ft8MtdDecodeScheduler scheduler;
+ scheduler.request (Stage::Final, 80, 1, true, true);
+ QVERIFY (scheduler.degraded ());
+ scheduler.cancel ();
+ QVERIFY (!scheduler.degraded ());
+ QCOMPARE (scheduler.nextProbePeriod (), qint64 {0});
+ QCOMPARE (scheduler.request (Stage::EarlyOne, 81, 1, false, false).action,
+ Action::Publish);
+}
+
+QTEST_GUILESS_MAIN (TestFt8MtdDecodeScheduler)
+
+#include "test_ft8_mtd_decode_scheduler.moc"
diff --git a/tests/unit/ft8/test_ft8_mtd_residual.f90 b/tests/unit/ft8/test_ft8_mtd_residual.f90
new file mode 100644
index 00000000..c71957fb
--- /dev/null
+++ b/tests/unit/ft8/test_ft8_mtd_residual.f90
@@ -0,0 +1,281 @@
+program test_ft8_mtd_residual
+ use iso_fortran_env, only : int64
+ use ft8_mtd_residual
+ use ft8_mod1, only : cw,endcorr
+ implicit none
+
+ integer, parameter :: frame_samples=151680
+
+ call test_interaction_boundary()
+ call test_independent_delta_commits()
+ call test_conflict_and_duplicate()
+ call test_candidate_refresh()
+ call test_real_subtractor_equivalence()
+ call test_phase_epoch_conflict()
+ call test_half_sample_endpoints()
+ call test_pass7_restore()
+
+contains
+
+ subroutine test_interaction_boundary()
+ type(ft8_subtraction_descriptor) :: left,right
+ integer :: tones(79)
+
+ tones=1
+ call mtd_prepare(spread(0.0,1,mtd_residual_samples),1)
+ call mtd_make_descriptor(left,1,tones,1000.0,0.5)
+ call mtd_make_descriptor(right,1,tones,1049.999,0.5)
+ if(.not.mtd_descriptors_conflict(left,right)) error stop &
+ 'frequencies less than 50 Hz apart must interact'
+ call mtd_make_descriptor(right,1,tones,1050.0,0.5)
+ if(mtd_descriptors_conflict(left,right)) error stop &
+ 'frequencies exactly 50 Hz apart must be independent'
+ call mtd_make_descriptor(left,1,tones,1000.0,-12.5)
+ call mtd_make_descriptor(right,1,tones,1000.0,14.9)
+ if(mtd_descriptors_conflict(left,right)) error stop &
+ 'disjoint subtraction supports must be independent'
+ if(mtd_start_sample(0.00005).ne.1) error stop &
+ 'positive fractional start samples must truncate toward zero'
+ if(mtd_start_sample(-0.00023333333).ne.-1) error stop &
+ 'negative fractional start samples must truncate toward zero'
+ end subroutine test_interaction_boundary
+
+ subroutine test_independent_delta_commits()
+ type(ft8_subtraction_descriptor) :: first,second
+ real, allocatable :: source(:),worker_one(:),worker_two(:),actual(:)
+ real, allocatable :: first_delta(:),second_delta(:)
+ integer(int64) :: first_epoch,first_generation,second_epoch,second_generation
+ integer :: tones(79),outcome
+
+ allocate(source(mtd_residual_samples),worker_one(mtd_residual_samples), &
+ worker_two(mtd_residual_samples),actual(mtd_residual_samples), &
+ first_delta(frame_samples),second_delta(frame_samples))
+ source=0.0
+ first_delta=0.0
+ second_delta=0.0
+ first_delta(1)=-1.0
+ second_delta(1)=-2.0
+ tones=1
+
+ call mtd_prepare(source,2)
+ call mtd_publish_worker(1)
+ call mtd_publish_worker(2)
+ worker_one=mtd_worker_residual(:,1)
+ worker_two=mtd_worker_residual(:,2)
+ call mtd_capture_generation(1,first_epoch,first_generation)
+ call mtd_capture_generation(2,second_epoch,second_generation)
+ call mtd_make_descriptor(first,1,tones,1000.0,0.0)
+ call mtd_make_descriptor(second,1,tones,1100.0,0.0)
+
+ worker_one(1)=worker_one(1)+first_delta(1)
+ call mtd_try_commit_delta(1,worker_one,first,first_epoch,first_generation, &
+ first_delta,outcome)
+ if(outcome.ne.mtd_commit_current) error stop 'first commit was not current'
+ worker_two(1)=worker_two(1)+second_delta(1)
+ call mtd_try_commit_delta(2,worker_two,second,second_epoch,second_generation, &
+ second_delta,outcome)
+ if(outcome.ne.mtd_commit_independent) error stop &
+ 'stale independent commit did not use the fast path'
+ call mtd_finish(actual)
+ if(actual(1).ne.-3.0) error stop 'independent updates were not both preserved'
+ if(worker_two(1).ne.-3.0) error stop 'stale worker did not receive canonical state'
+ end subroutine test_independent_delta_commits
+
+ subroutine test_conflict_and_duplicate()
+ type(ft8_subtraction_descriptor) :: first,second,duplicate
+ real, allocatable :: source(:),worker_one(:),worker_two(:),actual(:)
+ real, allocatable :: delta(:)
+ integer(int64) :: epoch_one,generation_one,epoch_two,generation_two
+ integer :: tones(79),outcome
+
+ allocate(source(mtd_residual_samples),worker_one(mtd_residual_samples), &
+ worker_two(mtd_residual_samples),actual(mtd_residual_samples), &
+ delta(frame_samples))
+ source=0.0
+ delta=0.0
+ delta(1)=-1.0
+ tones=2
+ call mtd_prepare(source,2)
+ call mtd_publish_worker(1)
+ call mtd_publish_worker(2)
+ worker_one=mtd_worker_residual(:,1)
+ worker_two=mtd_worker_residual(:,2)
+ call mtd_capture_generation(1,epoch_one,generation_one)
+ call mtd_capture_generation(2,epoch_two,generation_two)
+ call mtd_make_descriptor(first,1,tones,1000.0,0.0)
+ call mtd_make_descriptor(second,1,tones,1025.0,0.0)
+ worker_one(1)=worker_one(1)+delta(1)
+ call mtd_try_commit_delta(1,worker_one,first,epoch_one,generation_one,delta,outcome)
+ worker_two(1)=worker_two(1)+delta(1)
+ call mtd_try_commit_delta(2,worker_two,second,epoch_two,generation_two,delta,outcome)
+ if(outcome.ne.mtd_commit_conflict) error stop &
+ 'interacting stale commit must request a refit'
+
+ call mtd_capture_generation(2,epoch_two,generation_two)
+ worker_two(1)=worker_two(1)+delta(1)
+ call mtd_try_commit_delta(2,worker_two,second,epoch_two,generation_two,delta,outcome)
+ if(outcome.ne.mtd_commit_current) error stop 'refitted commit was not published'
+
+ duplicate=second
+ call mtd_capture_generation(1,epoch_one,generation_one)
+ worker_one(1)=worker_one(1)+delta(1)
+ call mtd_try_commit_delta(1,worker_one,duplicate,epoch_one,generation_one, &
+ delta,outcome)
+ if(outcome.ne.mtd_commit_duplicate) error stop 'duplicate subtraction was repeated'
+ call mtd_finish(actual)
+ if(actual(1).ne.-2.0) error stop 'conflict or duplicate lost transaction state'
+ end subroutine test_conflict_and_duplicate
+
+ subroutine test_candidate_refresh()
+ type(ft8_subtraction_descriptor) :: descriptor
+ real, allocatable :: source(:),worker_one(:)
+ real, allocatable :: delta(:)
+ integer(int64) :: epoch,generation
+ integer :: tones(79),outcome
+ logical :: newdat1,rebuild
+
+ allocate(source(mtd_residual_samples),worker_one(mtd_residual_samples), &
+ delta(frame_samples))
+ source=0.0
+ delta=0.0
+ delta(1)=-1.0
+ tones=3
+ call mtd_prepare(source,2)
+ call mtd_publish_worker(1)
+ call mtd_publish_worker(2)
+ call mtd_mark_spectrum_current(2)
+ worker_one=mtd_worker_residual(:,1)
+ call mtd_capture_generation(1,epoch,generation)
+ call mtd_make_descriptor(descriptor,1,tones,1100.0,0.0)
+ worker_one(1)=worker_one(1)+delta(1)
+ call mtd_try_commit_delta(1,worker_one,descriptor,epoch,generation,delta,outcome)
+
+ newdat1=.false.
+ call mtd_refresh_candidate(2,1000.0,newdat1,rebuild)
+ if(rebuild) error stop 'far publication unnecessarily invalidated the spectrum'
+ call mtd_refresh_candidate(2,1100.0,newdat1,rebuild)
+ if(.not.rebuild) error stop 'near publication did not invalidate the spectrum'
+ if(mtd_worker_residual(1,2).ne.-1.0) error stop &
+ 'near publication did not refresh the worker residual'
+ call mtd_mark_spectrum_current(2)
+ newdat1=.false.
+ call mtd_refresh_candidate(2,1100.0,newdat1,rebuild)
+ if(rebuild) error stop 'current spectrum was invalidated again'
+ end subroutine test_candidate_refresh
+
+ subroutine test_real_subtractor_equivalence()
+ real, allocatable :: source(:),expected(:),actual(:)
+ integer :: i,tones(79),outcome
+
+ allocate(source(mtd_residual_samples),expected(mtd_residual_samples), &
+ actual(mtd_residual_samples))
+ do i=1,mtd_residual_samples
+ source(i)=0.01*sin(real(i)/300.0)
+ enddo
+ tones=0
+ cw=cmplx(1.0,0.0)
+ endcorr=1.0
+ expected=source
+ call subtractft8var(expected,tones,1000.0,0.5)
+
+ call mtd_prepare(source,1)
+ call mtd_publish_worker(1)
+ call mtd_commit_subtraction(1,1,tones,1000.0,0.5, &
+ mtd_worker_residual(:,1),outcome)
+ call mtd_finish(actual)
+ if(outcome.ne.mtd_commit_current) error stop &
+ 'uncontended real subtraction did not use the current path'
+ if(any(actual.ne.expected)) error stop &
+ 'prepared delta publication differs from serial subtraction'
+ end subroutine test_real_subtractor_equivalence
+
+ subroutine test_phase_epoch_conflict()
+ type(ft8_subtraction_descriptor) :: descriptor
+ real, allocatable :: source(:),delta(:),worker_residual(:)
+ integer(int64) :: epoch,generation
+ integer :: tones(79),outcome
+
+ allocate(source(mtd_residual_samples),delta(frame_samples), &
+ worker_residual(mtd_residual_samples))
+ source=0.0
+ delta=0.0
+ delta(1)=-1.0
+ tones=4
+ call mtd_prepare(source,1)
+ call mtd_publish_worker(1)
+ worker_residual=mtd_worker_residual(:,1)
+ call mtd_capture_generation(1,epoch,generation)
+ call mtd_make_descriptor(descriptor,3,tones,1000.0,0.0)
+ call mtd_transform_phase(4)
+ worker_residual(1)=worker_residual(1)+delta(1)
+ call mtd_try_commit_delta(1,worker_residual,descriptor,epoch,generation, &
+ delta,outcome)
+ if(outcome.ne.mtd_commit_conflict) error stop &
+ 'pre-transform transaction was not rejected'
+ call mtd_capture_generation(1,epoch,generation)
+ worker_residual(1)=worker_residual(1)+delta(1)
+ call mtd_try_commit_delta(1,worker_residual,descriptor,epoch,generation, &
+ delta,outcome)
+ if(outcome.ne.mtd_commit_conflict) error stop &
+ 'stale descriptor epoch was accepted after refresh'
+ end subroutine test_phase_epoch_conflict
+
+ subroutine test_half_sample_endpoints()
+ real, allocatable :: residual(:)
+
+ allocate(residual(mtd_residual_samples))
+ residual=0.0
+ residual(1:3)=[2.0,4.0,8.0]
+ residual(mtd_residual_samples)=16.0
+ call mtd_forward_half_sample(residual)
+ if(residual(1).ne.3.0 .or. residual(2).ne.6.0) error stop &
+ 'forward half-sample transform changed interior behavior'
+ if(residual(mtd_residual_samples).ne.16.0) error stop &
+ 'forward half-sample transform changed the trailing endpoint'
+
+ residual=0.0
+ residual(1:3)=[2.0,4.0,8.0]
+ call mtd_backward_half_sample(residual)
+ if(residual(1).ne.2.0) error stop &
+ 'backward half-sample transform changed the leading endpoint'
+ if(residual(2).ne.3.0 .or. residual(3).ne.6.0) error stop &
+ 'backward half-sample transform changed interior behavior'
+ end subroutine test_half_sample_endpoints
+
+ subroutine test_pass7_restore()
+ type(ft8_subtraction_descriptor) :: descriptor
+ real, allocatable :: source(:),expected(:),forward(:),actual(:),delta(:)
+ integer(int64) :: epoch,generation
+ integer :: i,tones(79),outcome
+
+ allocate(source(mtd_residual_samples),expected(mtd_residual_samples), &
+ forward(mtd_residual_samples),actual(mtd_residual_samples), &
+ delta(frame_samples))
+ do i=1,mtd_residual_samples
+ source(i)=real(mod(i,101))
+ enddo
+ expected=source
+ call mtd_backward_half_sample(expected)
+ forward=source
+ call mtd_forward_half_sample(forward)
+ delta=0.0
+ delta(1)=-1.0
+ tones=5
+ call mtd_prepare(source,1)
+ call mtd_transform_phase(4)
+ call mtd_publish_worker(1)
+ call mtd_capture_generation(1,epoch,generation)
+ call mtd_make_descriptor(descriptor,4,tones,1000.0,0.0)
+ mtd_worker_residual(1,1)=mtd_worker_residual(1,1)+delta(1)
+ call mtd_try_commit_delta(1,mtd_worker_residual(:,1),descriptor,epoch, &
+ generation,delta,outcome)
+ call mtd_finish(actual)
+ if(all(actual.eq.forward)) error stop &
+ 'cycle-two transaction did not mutate the forward residual'
+ call mtd_transform_phase(7)
+ call mtd_finish(actual)
+ if(any(actual.ne.expected)) error stop &
+ 'pass 7 must restore and shift the saved post-pass-3 residual'
+ end subroutine test_pass7_restore
+
+end program test_ft8_mtd_residual
diff --git a/tests/unit/ft8/test_ft8_mtd_transaction_concurrent.f90 b/tests/unit/ft8/test_ft8_mtd_transaction_concurrent.f90
new file mode 100644
index 00000000..a69b8531
--- /dev/null
+++ b/tests/unit/ft8/test_ft8_mtd_transaction_concurrent.f90
@@ -0,0 +1,195 @@
+program test_ft8_mtd_transaction_concurrent
+ use iso_fortran_env, only : int64
+ use omp_lib
+ use ft8_mtd_residual
+ implicit none
+
+ integer, parameter :: frame_samples=151680
+
+ if(omp_get_max_threads().lt.4) error stop 'four OpenMP workers are required'
+ call test_independent_publishers()
+ call test_duplicate_publishers()
+ call test_coherent_snapshots()
+
+contains
+
+ subroutine test_independent_publishers()
+ real, allocatable :: source(:),actual(:)
+ integer :: outcomes(4),worker,tones(79)
+ integer(int64) :: epoch,generation
+ type(ft8_subtraction_descriptor) :: descriptor
+
+ allocate(source(mtd_residual_samples),actual(mtd_residual_samples))
+ source=0.0
+ call mtd_prepare(source,4)
+
+!$omp parallel num_threads(4) private(worker,tones,epoch,generation,descriptor)
+ block
+ real, allocatable :: delta(:)
+ allocate(delta(frame_samples))
+ worker=omp_get_thread_num()+1
+ delta=0.0
+ delta(1)=-real(worker)
+ tones=worker
+ call mtd_publish_worker(worker)
+ call mtd_capture_generation(worker,epoch,generation)
+ call mtd_make_descriptor(descriptor,1,tones, &
+ 800.0+100.0*real(worker),0.0)
+ mtd_worker_residual(1,worker)=mtd_worker_residual(1,worker)+delta(1)
+!$omp barrier
+ call mtd_try_commit_delta(worker,mtd_worker_residual(:,worker),descriptor, &
+ epoch,generation,delta,outcomes(worker))
+ deallocate(delta)
+ end block
+!$omp end parallel
+
+ call mtd_finish(actual)
+ if(actual(1).ne.-10.0) error stop 'parallel independent updates were lost'
+ if(count(outcomes.eq.mtd_commit_current).ne.1) error stop &
+ 'exactly one same-generation transaction must commit first'
+ if(count(outcomes.eq.mtd_commit_independent).ne.3) error stop &
+ 'stale independent transactions did not use the fast path'
+ end subroutine test_independent_publishers
+
+ subroutine test_duplicate_publishers()
+ real, allocatable :: source(:),actual(:)
+ integer :: outcomes(4),worker,tones(79)
+ integer(int64) :: epoch,generation
+ type(ft8_subtraction_descriptor) :: descriptor
+
+ allocate(source(mtd_residual_samples),actual(mtd_residual_samples))
+ source=0.0
+ call mtd_prepare(source,4)
+
+!$omp parallel num_threads(4) private(worker,epoch,generation,descriptor,tones)
+ block
+ real, allocatable :: delta(:)
+ allocate(delta(frame_samples))
+ worker=omp_get_thread_num()+1
+ delta=0.0
+ delta(1)=-1.0
+ tones=7
+ call mtd_publish_worker(worker)
+ call mtd_capture_generation(worker,epoch,generation)
+ call mtd_make_descriptor(descriptor,1,tones,1000.0,0.0)
+ mtd_worker_residual(1,worker)=mtd_worker_residual(1,worker)+delta(1)
+!$omp barrier
+ call mtd_try_commit_delta(worker,mtd_worker_residual(:,worker),descriptor, &
+ epoch,generation,delta,outcomes(worker))
+ deallocate(delta)
+ end block
+!$omp end parallel
+
+ call mtd_finish(actual)
+ if(actual(1).ne.-1.0) error stop 'duplicate transaction was applied more than once'
+ if(count(outcomes.eq.mtd_commit_current).ne.1) error stop &
+ 'duplicate race did not produce one winner'
+ if(count(outcomes.eq.mtd_commit_duplicate).ne.3) error stop &
+ 'duplicate race did not reject all later publishers'
+ end subroutine test_duplicate_publishers
+
+ subroutine test_coherent_snapshots()
+ integer, parameter :: writer_iterations=50,reader_iterations=500
+ real, allocatable :: source(:),actual(:)
+ real :: snapshot_value
+ integer :: worker,iteration,tones(79),outcome,writers_started,reader_ready, &
+ first_commits,reader_observed
+ integer(int64) :: epoch,generation
+ logical :: torn_snapshot,intermediate_observed
+ type(ft8_subtraction_descriptor) :: descriptor
+
+ allocate(source(mtd_residual_samples),actual(mtd_residual_samples))
+ source=0.0
+ torn_snapshot=.false.
+ intermediate_observed=.false.
+ writers_started=0
+ reader_ready=0
+ first_commits=0
+ reader_observed=0
+ call mtd_prepare(source,4)
+
+!$omp parallel num_threads(4) private(worker,iteration,tones,outcome,epoch, &
+!$omp generation,descriptor,snapshot_value) &
+!$omp shared(torn_snapshot,intermediate_observed,writers_started,reader_ready, &
+!$omp first_commits,reader_observed)
+ block
+ real, allocatable :: delta(:)
+ allocate(delta(frame_samples))
+ worker=omp_get_thread_num()+1
+ call mtd_publish_worker(worker)
+!$omp barrier
+ if(worker.le.3) then
+ delta=-1.0
+!$omp atomic update
+ writers_started=writers_started+1
+ do
+!$omp atomic read
+ outcome=reader_ready
+ if(outcome.eq.1) exit
+ enddo
+ do iteration=1,writer_iterations
+ tones=0
+ tones(1)=iteration
+ tones(2)=worker
+ call mtd_make_descriptor(descriptor,1,tones, &
+ 700.0+100.0*real(worker),0.0)
+ do
+ call mtd_capture_generation(worker,epoch,generation)
+ mtd_worker_residual(1:frame_samples,worker)= &
+ mtd_worker_residual(1:frame_samples,worker)+delta
+ call mtd_try_commit_delta(worker,mtd_worker_residual(:,worker), &
+ descriptor,epoch,generation,delta,outcome)
+ if(outcome.ne.mtd_commit_conflict) exit
+ enddo
+ if(iteration.eq.1) then
+!$omp atomic update
+ first_commits=first_commits+1
+ do
+!$omp atomic read
+ outcome=reader_observed
+ if(outcome.eq.1) exit
+ enddo
+ endif
+ enddo
+ else
+ do
+!$omp atomic read
+ outcome=writers_started
+ if(outcome.eq.3) exit
+ enddo
+!$omp atomic write
+ reader_ready=1
+ do
+!$omp atomic read
+ outcome=first_commits
+ if(outcome.eq.3) exit
+ enddo
+ call mtd_publish_worker(worker)
+ snapshot_value=-mtd_worker_residual(1,worker)
+ intermediate_observed=snapshot_value.eq.3.0
+!$omp atomic write
+ reader_observed=1
+ do iteration=1,reader_iterations
+ call mtd_publish_worker(worker)
+ if(minval(mtd_worker_residual(1:frame_samples,worker)).ne. &
+ maxval(mtd_worker_residual(1:frame_samples,worker))) &
+ torn_snapshot=.true.
+ snapshot_value=-mtd_worker_residual(1,worker)
+ if(snapshot_value.gt.0.0 .and. &
+ snapshot_value.lt.real(3*writer_iterations)) &
+ intermediate_observed=.true.
+ enddo
+ endif
+ deallocate(delta)
+ end block
+!$omp end parallel
+
+ if(torn_snapshot) error stop 'reader observed a torn canonical snapshot'
+ if(.not.intermediate_observed) error stop &
+ 'coherence reader did not overlap the publishers'
+ call mtd_finish(actual)
+ if(actual(1).ne.-real(3*writer_iterations)) error stop &
+ 'coherence stress did not publish every transaction'
+ end subroutine test_coherent_snapshots
+
+end program test_ft8_mtd_transaction_concurrent