summaryrefslogtreecommitdiff
path: root/tests/unit/map65
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/map65')
-rw-r--r--tests/unit/map65/CMakeLists.txt22
-rw-r--r--tests/unit/map65/decode_history/CMakeLists.txt18
-rw-r--r--tests/unit/map65/decode_history/decode_history_stubs.f90159
-rw-r--r--tests/unit/map65/decode_history/test_map65_decode_history.f9090
-rw-r--r--tests/unit/map65/test_map65_astro.f9062
-rw-r--r--tests/unit/map65/test_map65_decode_display_filter.cpp94
-rw-r--r--tests/unit/map65/test_map65_decode_requests.f90112
-rw-r--r--tests/unit/map65/test_map65_deep_search_cache.f90188
-rw-r--r--tests/unit/map65/test_map65_half_symbol_scheduler.cpp61
-rw-r--r--tests/unit/map65/test_map65_q65_dphi.f90126
-rw-r--r--tests/unit/map65/test_map65_q65b_timeout.f9046
-rw-r--r--tests/unit/map65/test_map65_result_selection.f9096
-rw-r--r--tests/unit/map65/test_map65_runtime_paths.cpp225
13 files changed, 1299 insertions, 0 deletions
diff --git a/tests/unit/map65/CMakeLists.txt b/tests/unit/map65/CMakeLists.txt
new file mode 100644
index 00000000..88064d64
--- /dev/null
+++ b/tests/unit/map65/CMakeLists.txt
@@ -0,0 +1,22 @@
+add_executable (test_map65_decode_display_filter
+ test_map65_decode_display_filter.cpp
+ ${CMAKE_SOURCE_DIR}/map65/map65_decode_display_filter.cpp
+)
+target_include_directories (test_map65_decode_display_filter PRIVATE ${CMAKE_SOURCE_DIR}/map65)
+target_link_libraries (test_map65_decode_display_filter Qt5::Test)
+add_test (NAME test_map65_decode_display_filter COMMAND test_map65_decode_display_filter)
+
+add_executable (test_map65_half_symbol_scheduler
+ test_map65_half_symbol_scheduler.cpp
+)
+target_include_directories (test_map65_half_symbol_scheduler PRIVATE ${CMAKE_SOURCE_DIR}/map65)
+target_link_libraries (test_map65_half_symbol_scheduler Qt5::Test)
+add_test (NAME test_map65_half_symbol_scheduler COMMAND test_map65_half_symbol_scheduler)
+
+add_executable (test_map65_runtime_paths
+ test_map65_runtime_paths.cpp
+ ${CMAKE_SOURCE_DIR}/map65/runtime_paths.cpp
+)
+target_include_directories (test_map65_runtime_paths PRIVATE ${CMAKE_SOURCE_DIR}/map65)
+target_link_libraries (test_map65_runtime_paths Qt5::Test)
+add_test (NAME test_map65_runtime_paths COMMAND test_map65_runtime_paths)
diff --git a/tests/unit/map65/decode_history/CMakeLists.txt b/tests/unit/map65/decode_history/CMakeLists.txt
new file mode 100644
index 00000000..6c8dc65d
--- /dev/null
+++ b/tests/unit/map65/decode_history/CMakeLists.txt
@@ -0,0 +1,18 @@
+# Compile the production control flow against deterministic DSP boundaries.
+# Keep replacement module files out of the production module directory.
+add_executable (test_map65_decode_history
+ decode_history_stubs.f90
+ test_map65_decode_history.f90
+ ${CMAKE_SOURCE_DIR}/map65/libm65/map65a.f90
+ ${CMAKE_SOURCE_DIR}/map65/libm65/getdphi.f90)
+target_include_directories (test_map65_decode_history BEFORE PRIVATE
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${PROJECT_BINARY_DIR}/map65/libm65)
+target_link_libraries (test_map65_decode_history PRIVATE m65impl)
+target_compile_options (test_map65_decode_history PRIVATE
+ $<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-fcheck=bounds>)
+set_source_files_properties (decode_history_stubs.f90 PROPERTIES
+ COMPILE_OPTIONS "$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-Wno-unused-dummy-argument>")
+add_test (NAME test_map65_decode_history COMMAND test_map65_decode_history)
+set_tests_properties (test_map65_decode_history PROPERTIES
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 30)
diff --git a/tests/unit/map65/decode_history/decode_history_stubs.f90 b/tests/unit/map65/decode_history/decode_history_stubs.f90
new file mode 100644
index 00000000..9582e19a
--- /dev/null
+++ b/tests/unit/map65/decode_history/decode_history_stubs.f90
@@ -0,0 +1,159 @@
+! These stand-ins supply one successful signal per mode. The production
+! map65a loop owns all JT65 suppression and both modes' history resets.
+module decode_history_observations
+ implicit none
+ integer :: jt65_attempts = 0, q65_successes = 0
+ integer :: phase_attempts(0:12) = 0
+ integer :: summary_count = 0, fitted_phase = -999
+ logical :: phase_has_signal(0:12) = .true.
+end module
+
+module stdout_channel_mod
+ use decode_history_observations
+ implicit none
+contains
+ subroutine write_stdout(line)
+ character(len=*), intent(in) :: line
+ if (index(line, '!Best-fit Dphi =') == 1) then
+ summary_count = summary_count + 1
+ read(line(index(line, '=')+1:), *) fitted_phase
+ endif
+ end subroutine
+end module
+
+module wideband_sync
+ implicit none
+ integer, parameter :: MAX_CANDIDATES = 50
+ integer :: nkhz_center
+ type candidate
+ real :: snr, f, xdt, pol
+ integer :: ipol, iflip, indx
+ end type
+contains
+ subroutine init_wideband_sync()
+ end subroutine
+
+ subroutine get_candidates(ss, savg, xpol, jz, nfa, nfb, nts_jt65, nts_q65, cand, ncand)
+ use npar_ptrs_mod, only: nfft_active
+ real, intent(in) :: ss(4,322,nfft_active), savg(4,nfft_active)
+ logical, intent(in) :: xpol
+ integer, intent(in) :: jz, nfa, nfb, nts_jt65, nts_q65
+ type(candidate), intent(out) :: cand(MAX_CANDIDATES)
+ integer, intent(out) :: ncand
+ ncand = 1
+ ! With nfcal=-1270, this places the Q65 signal at the zero-kHz cursor.
+ cand(1) = candidate(10.0, 48.00046, 0.0, 0.0, 1, 0, 1)
+ end subroutine
+end module
+
+module ccf65_legacy_mod
+ implicit none
+contains
+ subroutine ccf65(ss_plane, nhsym, ssmax, sync1, ipol1, jpz, dt1, flipk, &
+ syncshort, snr2, ipol2, dt2)
+ real, intent(in) :: ss_plane(4,322), ssmax
+ integer, intent(in) :: nhsym, jpz
+ real, intent(out) :: sync1, dt1, flipk, syncshort, snr2, dt2
+ integer, intent(out) :: ipol1, ipol2
+ sync1 = 10.0
+ dt1 = 0.0
+ flipk = 1.0
+ syncshort = -99.0
+ snr2 = 0.0
+ dt2 = 0.0
+ ipol1 = 1
+ ipol2 = 1
+ end subroutine
+end module
+
+module decode1a_mod
+ use iso_fortran_env, only: real64
+ use decode_history_observations
+ implicit none
+contains
+ subroutine decode1a(dd,newdat,f0,nflip,mode65,nfsample,xpol, &
+ mycall,hiscall,hisgrid,neme,ndepth,nqd,dphi,ndphi, &
+ nutc,nkhz,ndf,ipol,ntol,sync2,a,dt,pol,nkv,nhist,nsum,nsave,qual,decoded)
+ use npar_ptrs_mod, only: nsmax_active
+ real, intent(in) :: dd(4,nsmax_active), dphi
+ real(real64), intent(in) :: f0
+ integer, intent(in) :: nflip, mode65, nfsample, neme, ndepth, nqd, ndphi, nutc, nkhz, ndf, ntol
+ logical, intent(in) :: xpol
+ character(len=12), intent(in) :: mycall, hiscall
+ character(len=6), intent(in) :: hisgrid
+ integer, intent(inout) :: newdat, ipol, nkv, nhist, nsum, nsave
+ real, intent(inout) :: sync2, a(5), dt, pol, qual
+ character(len=22), intent(out) :: decoded
+ integer :: trial
+ newdat = 0
+ decoded = ' '
+ if (mode65 == 0) return
+ jt65_attempts = jt65_attempts + 1
+ trial = nint(dphi * 57.2957795 / 30.0)
+ if (ndphi == 1) then
+ phase_attempts(trial) = phase_attempts(trial) + 1
+ if (.not. phase_has_signal(trial)) return
+ endif
+ decoded = 'K1ABC W9XYZ FN42'
+ sync2 = 100.0
+ a = 0.0
+ dt = 0.0
+ pol = 0.0
+ qual = 5.0 + 4.0*sin(dphi)
+ nkv = 1
+ nhist = 0
+ nsum = 0
+ nsave = 0
+ ipol = 1
+ end subroutine
+end module
+
+module q65b_mod
+ use iso_fortran_env, only: real64
+ use decode_history_observations
+ implicit none
+contains
+ subroutine q65b(nutc,nqd,nxant,fcenter,nfcal,nfsample,ikhz,mousedf,ntol,xpol,configured_dphi_deg, &
+ mycall,mygrid,hiscall,hisgrid,mode_q65,f0,fqso,newdat,nagain,max_drift,ndop00,idec,cursor_fallback)
+ use decodes_mod, only: ldecoded
+ use q65_decode, only: nsnr0
+ integer, intent(in) :: nutc,nqd,nxant,nfcal,nfsample,ikhz,mousedf,ntol,mode_q65
+ integer, intent(in) :: newdat,nagain,max_drift,ndop00,configured_dphi_deg
+ real(real64), intent(in) :: fcenter,f0
+ real, intent(in) :: fqso
+ logical, intent(in) :: xpol
+ logical, optional, intent(in) :: cursor_fallback
+ character(len=12), intent(in) :: mycall,hiscall
+ character(len=6), intent(in) :: mygrid,hisgrid
+ integer, intent(out) :: idec
+ nsnr0 = -99
+ idec = -1
+ ! Model q65b's successful-bin guard, not its signal processing. This
+ ! observes whether the caller retained or discarded the Q65 history.
+ if (ldecoded(1)) return
+ ldecoded(1) = .true.
+ q65_successes = q65_successes + 1
+ nsnr0 = -10
+ idec = 1
+ end subroutine
+end module
+
+module display_mod
+ implicit none
+contains
+ subroutine display(nkeep, ftol)
+ integer, intent(in) :: nkeep
+ real, intent(in) :: ftol
+ end subroutine
+end module
+
+module sec0_mod
+ implicit none
+contains
+ subroutine sec0(mode, t)
+ integer, intent(in) :: mode
+ real, intent(out) :: t
+ ! The tests cover state transitions, not elapsed-time abort policy.
+ t = 0.0
+ end subroutine
+end module
diff --git a/tests/unit/map65/decode_history/test_map65_decode_history.f90 b/tests/unit/map65/decode_history/test_map65_decode_history.f90
new file mode 100644
index 00000000..eb5ce18c
--- /dev/null
+++ b/tests/unit/map65/decode_history/test_map65_decode_history.f90
@@ -0,0 +1,90 @@
+program test_map65_decode_history
+ use iso_fortran_env, only: real64
+ use npar_ptrs_mod, only: nfft_active, nsmax_active, t_start, manualDecodeFlag, active_input_generation
+ use datcom_ptrs_mod, only: ss_old, savg_old
+ use decodes_mod, only: nhsym1, nhsym2
+ use map65a_mod, only: map65a
+ use decode_history_observations
+ implicit none
+ real, allocatable :: samples(:,:)
+ integer :: unit, before_jt65, before_q65
+
+ ! Only the center bin has signal power; DSP stand-ins never read samples.
+ nfft_active = 1024
+ nsmax_active = 1
+ allocate(samples(4,nsmax_active), ss_old(4,322,nfft_active), savg_old(4,nfft_active))
+ samples = 0.0
+ ss_old = 1.0
+ savg_old = 1.0
+ savg_old(1,nfft_active/2+1) = 10.0
+ nhsym1 = 280
+ nhsym2 = 302
+ manualDecodeFlag = 0
+ do unit = 12, 27
+ open(unit, status='scratch')
+ enddo
+ close(23)
+
+ active_input_generation = 1
+ call run_pass(nhsym1, 0, 0)
+ call require(jt65_attempts == 1 .and. q65_successes == 1, 'early pass decodes both signals')
+ call run_pass(nhsym2, 0, 0)
+ call require(jt65_attempts == 1 .and. q65_successes == 1, 'final pass retains early successes')
+
+ jt65_attempts = 0
+ q65_successes = 0
+ call run_pass(nhsym2, 1, 1)
+ call require(all(phase_attempts == 1), 'each JT65 trial remains eligible after an earlier success')
+ call require(jt65_attempts == 13, 'JT65 runs once per trial, without replaying prior successes')
+ call require(q65_successes == 1, 'unchanged Q65 input is decoded once across phase trials')
+ call require(summary_count == 1 .and. fitted_phase == 90, 'later better trials determine the fitted phase')
+
+ ! A second calibration must not inherit quality scores from the first.
+ phase_has_signal = .false.
+ phase_has_signal(6) = .true.
+ phase_attempts = 0
+ call run_pass(nhsym2, 1, 1)
+ call require(all(phase_attempts == 1), 'unsuccessful trials remain eligible in a new calibration')
+ call require(summary_count == 2 .and. abs(fitted_phase) == 180, 'missing trials do not retain old quality scores')
+
+ before_jt65 = jt65_attempts
+ before_q65 = q65_successes
+ active_input_generation = 2
+ call run_pass(nhsym1, 0, 0)
+ call require(jt65_attempts == before_jt65+1 .and. q65_successes == before_q65+1, &
+ 'next receive period makes both frequencies eligible')
+ active_input_generation = 3
+ call run_pass(nhsym1, 0, 0)
+ call require(jt65_attempts == before_jt65+2 .and. q65_successes == before_q65+2, &
+ 'next early pass resets history even without a preceding final pass')
+ call run_pass(nhsym2, 0, 0)
+ call require(jt65_attempts == before_jt65+2 .and. q65_successes == before_q65+2, &
+ 'final pass retains successes after a skipped-period boundary')
+ print '(a)', 'MAP65 decode history tests passed.'
+
+contains
+ subroutine run_pass(half_symbols, again, find_phase)
+ integer, intent(in) :: half_symbols, again, find_phase
+ integer :: newdat, utc, done, ndphi, mcall3b, nsum, nsave
+ newdat = 1
+ utc = 1200 + int(active_input_generation)
+ done = 0
+ ndphi = find_phase
+ mcall3b = 0
+ nsum = 0
+ nsave = 0
+ call system_clock(t_start)
+ call map65a(samples,newdat,utc,144.0_real64,100,0,0,0,0,0,again,done,0,ndphi,0, &
+ -1270,20,mcall3b,nsum,nsave,0,'K1ABC ','FN42 ',0,3,0, &
+ 'W9XYZ ','EN50 ',half_symbols,96000,0,1,11,0)
+ end subroutine
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ endif
+ end subroutine
+end program
diff --git a/tests/unit/map65/test_map65_astro.f90 b/tests/unit/map65/test_map65_astro.f90
new file mode 100644
index 00000000..275106d7
--- /dev/null
+++ b/tests/unit/map65/test_map65_astro.f90
@@ -0,0 +1,62 @@
+program test_map65_astro
+ use iso_fortran_env, only: real64
+ use astro_mod, only: astro, nt144
+ implicit none
+
+ integer :: ntsky_144, ntsky_1296
+ real :: db_moon_144, degradation_144
+ real :: db_moon_1296, degradation_1296
+ real(real64) :: expected_tsky, expected_degradation
+
+ call run_astro(144, ntsky_144, db_moon_144, degradation_144)
+ call require(any(int(nt144) == ntsky_144), &
+ '144 MHz sky temperature comes from the lookup table')
+
+ call run_astro(1296, ntsky_1296, db_moon_1296, degradation_1296)
+ expected_tsky = (real(ntsky_144, real64) - 2.7_real64) * &
+ (144.0_real64 / 1296.0_real64)**2.6_real64 + 2.7_real64
+ call require(ntsky_1296 == nint(expected_tsky), &
+ 'sky temperature scales from 144 MHz to the selected band')
+
+ expected_degradation = -10.0_real64 * log10( &
+ (real(ntsky_144, real64) + 80.0_real64) / &
+ (13.0_real64 * (408.0_real64 / 144.0_real64)**2.6_real64 + 80.0_real64)) + &
+ real(db_moon_144, real64)
+ call require(abs(real(degradation_144, real64) - expected_degradation) < 1.0e-4_real64, &
+ 'degradation uses the cold-sky temperature for the selected band')
+
+ print '(a)', 'MAP65 Astro tests passed.'
+
+contains
+
+ subroutine run_astro(frequency_mhz, ntsky, db_moon, degradation)
+ integer, intent(in) :: frequency_mhz
+ integer, intent(out) :: ntsky
+ real, intent(out) :: db_moon, degradation
+ real :: az_sun, el_sun, az_moon, el_moon
+ real :: doppler00, doppler, ra_moon, dec_moon, hour_angle
+ real :: semidiameter, polarization_offset, nonreciprocal_loss
+ real :: day, longitude, latitude, local_sidereal_time
+
+ call astro(2025, 1, 15, 12.0, frequency_mhz, 'FN20rx', 2, 0.0, &
+ az_sun, el_sun, az_moon, el_moon, ntsky, doppler00, doppler, &
+ db_moon, ra_moon, dec_moon, hour_angle, degradation, semidiameter, &
+ polarization_offset, nonreciprocal_loss, day, longitude, latitude, &
+ local_sidereal_time)
+ call astro(2025, 1, 15, 12.0, frequency_mhz, 'FN20rx', 1, 0.0, &
+ az_sun, el_sun, az_moon, el_moon, ntsky, doppler00, doppler, &
+ db_moon, ra_moon, dec_moon, hour_angle, degradation, semidiameter, &
+ polarization_offset, nonreciprocal_loss, day, longitude, latitude, &
+ local_sidereal_time)
+ end subroutine run_astro
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ end if
+ end subroutine require
+end program test_map65_astro
diff --git a/tests/unit/map65/test_map65_decode_display_filter.cpp b/tests/unit/map65/test_map65_decode_display_filter.cpp
new file mode 100644
index 00000000..ad7ec1e1
--- /dev/null
+++ b/tests/unit/map65/test_map65_decode_display_filter.cpp
@@ -0,0 +1,94 @@
+#include "map65_decode_display_filter.h"
+
+#include <QtTest>
+
+namespace
+{
+QString jt65Line(int frequencyHz, int utc, QString const& message)
+{
+ QByteArray const text = message.leftJustified(22, ' ').toLatin1();
+ return QString::asprintf("%3d%5d%4d%6.4d%5.1f%5d # %-22s",
+ frequencyHz / 1000, frequencyHz % 1000, 0, utc,
+ 0.0, -20, text.constData());
+}
+
+QString q65Line(int frequencyHz, int utc, QString const& message)
+{
+ QByteArray const text = message.leftJustified(28, ' ').toLatin1();
+ return QString::asprintf("%3d%5d%4d%6.4d%5.1f%5d : %-28s",
+ frequencyHz / 1000, frequencyHz % 1000, 0, utc,
+ 0.0, -20, text.constData());
+}
+}
+
+class TestMap65DecodeDisplayFilter final : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void suppressesOnlyMatchingFinalDecode()
+ {
+ Map65DecodeDisplayFilter filter;
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> early\n"));
+ QVERIFY(filter.shouldDisplay(jt65Line(125000, 1234, "CQ K1ABC FN42")));
+ filter.completeEarlyPass();
+
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> final\n"));
+ QVERIFY(!filter.shouldDisplay(jt65Line(125020, 1234, "CQ K1ABC FN42")));
+ QVERIFY(filter.shouldDisplay(jt65Line(125021, 1234, "CQ K1ABC FN42")));
+ QVERIFY(filter.shouldDisplay(jt65Line(125000, 1235, "CQ K1ABC FN42")));
+ QVERIFY(filter.shouldDisplay(jt65Line(125000, 1234, "CQ K2XYZ EM00")));
+ QVERIFY(filter.shouldDisplay(q65Line(125000, 1234, "CQ K1ABC FN42")));
+ }
+
+ void displaysFinalOnlyDecode()
+ {
+ Map65DecodeDisplayFilter filter;
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> early"));
+ filter.completeEarlyPass();
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> final"));
+
+ QString const decode = q65Line(125000, 2, "W1AAA K2BBB EM00");
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.shouldDisplay(decode));
+ }
+
+ void manualDiskAndUnknownPassesFailOpen()
+ {
+ Map65DecodeDisplayFilter filter;
+ QString const decode = jt65Line(125000, 2, "CQ K1ABC FN42");
+
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> manual"));
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> disk"));
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> invalid"));
+ QVERIFY(filter.shouldDisplay(decode));
+ QVERIFY(filter.shouldDisplay("Signal too strong, or suspect data?"));
+
+ QString malformed = decode;
+ malformed.replace(28, 3, " ? ");
+ QVERIFY(filter.shouldDisplay(malformed));
+ }
+
+ void completedCycleDoesNotRetainDuplicates()
+ {
+ Map65DecodeDisplayFilter filter;
+ QString const decode = q65Line(125000, 2, "W1AAA K2BBB EM00");
+
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> early"));
+ QVERIFY(filter.shouldDisplay(decode));
+ filter.completeEarlyPass();
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> final"));
+ QVERIFY(!filter.shouldDisplay(decode));
+ filter.completeCycle();
+ QVERIFY(filter.handleControlLine("<Map65DecodePass> final"));
+ QVERIFY(filter.shouldDisplay(decode));
+ }
+};
+
+QTEST_APPLESS_MAIN(TestMap65DecodeDisplayFilter)
+
+#include "test_map65_decode_display_filter.moc"
diff --git a/tests/unit/map65/test_map65_decode_requests.f90 b/tests/unit/map65/test_map65_decode_requests.f90
new file mode 100644
index 00000000..e06c4c6d
--- /dev/null
+++ b/tests/unit/map65/test_map65_decode_requests.f90
@@ -0,0 +1,112 @@
+program test_map65_decode_requests
+ use iso_c_binding
+ use npar_ptrs_mod
+ implicit none
+
+ integer(c_int64_t) :: early_id, final_id, manual_id
+ character(kind=c_char) :: dx(12)
+
+ call set_nhsym(280)
+ call set_nagain(0)
+ call set_ndepth(1)
+ call set_fcenter(144.125_c_double)
+ dx = transfer('K1ABC ', dx)
+ call set_hiscall(dx)
+ early_id = publish_decode_request()
+ if (.not. claim_decode_request()) error stop 'early request missing'
+ if (active_request_id /= early_id .or. nhsym /= 280) error stop 'early identity changed'
+ if (claim_decode_request()) error stop 'early request repeated'
+
+ ! Publish the final pass while the early pass is still using its parameters.
+ call set_decoder_ready(0)
+ call set_nhsym(302)
+ call set_ndepth(3)
+ call set_fcenter(144.135_c_double)
+ dx = transfer('K2DEF ', dx)
+ call set_hiscall(dx)
+ final_id = publish_decode_request()
+ if (nhsym /= 280 .or. ndepth /= 1 .or. hiscall /= 'K1ABC') error stop 'active parameters changed'
+ if (abs(fcenter - 144.125_c_double) > 1.e-8_c_double) error stop 'active center frequency changed'
+ if (is_current_decode_request(early_id)) error stop 'stale early completion accepted'
+ newdat = 0
+ if (.not. claim_decode_request()) error stop 'pending final lost'
+ if (active_request_id /= final_id .or. nhsym /= 302 .or. newdat /= 1) error stop 'final identity changed'
+ if (ndepth /= 3 .or. hiscall /= 'K2DEF') error stop 'final parameters changed'
+ if (.not. is_current_decode_request(final_id)) error stop 'current final completion rejected'
+ if (claim_decode_request()) error stop 'final request repeated'
+
+ ! Both automatic triggers can arrive before the decoder claims either.
+ call set_nhsym(280)
+ early_id = publish_decode_request()
+ call set_nhsym(302)
+ final_id = publish_decode_request()
+ call set_decoder_ready(0)
+ if (claim_decode_request()) error stop 'unready request claimed'
+ call set_decoder_ready(1)
+ if (.not. claim_decode_request()) error stop 'queued early missing'
+ if (active_request_id /= early_id .or. nhsym /= 280) error stop 'queued early out of order'
+ if (.not. claim_decode_request()) error stop 'queued final missing'
+ if (active_request_id /= final_id .or. nhsym /= 302) error stop 'queued final out of order'
+ if (claim_decode_request()) error stop 'queue did not drain'
+
+ ! Completing a manual request cannot clear a newer automatic request.
+ call set_manual_decode_flag(1)
+ call set_nagain(1)
+ manual_id = publish_decode_request()
+ if (get_manual_decode_flag() /= 0) error stop 'manual flag not consumed'
+ if (.not. claim_decode_request()) error stop 'manual request missing'
+ if (manualDecodeFlag /= 1 .or. nagain /= 1) error stop 'manual parameters changed'
+ call set_nagain(0)
+ final_id = publish_decode_request()
+ if (manualDecodeFlag /= 1 .or. nagain /= 1) error stop 'pending update changed active manual'
+ manualDecodeFlag = 0
+ newdat = 0
+ if (is_current_decode_request(manual_id)) error stop 'stale manual completion accepted'
+ if (.not. claim_decode_request()) error stop 'final lost after manual completion'
+ if (active_request_id /= final_id .or. manualDecodeFlag /= 0 .or. nagain /= 0) error stop 'final inherited manual parameters'
+ if (claim_decode_request()) error stop 'manual sequence did not drain'
+
+ ! A final request waiting beyond rollover must not decode the next interval.
+ call set_ndiskdat(0)
+ call set_nagain(0)
+ final_id = publish_decode_request()
+ call advance_live_input_generation()
+ if (.not. claim_decode_request()) error stop 'expired final missing'
+ if (active_request_id /= final_id .or. .not. active_request_expired) error stop 'old final did not expire'
+ if (.not. is_current_decode_request(final_id)) error stop 'expired current request cannot clear busy'
+ early_id = publish_decode_request()
+ if (is_current_decode_request(final_id)) error stop 'old skipped completion accepted'
+ if (.not. claim_decode_request()) error stop 'current interval request missing'
+ if (active_request_id /= early_id .or. active_request_expired) error stop 'current interval request expired'
+ if (active_input_generation /= live_input_generation) error stop 'claimed input generation changed'
+
+ call set_nagain(1)
+ manual_id = publish_decode_request()
+ call advance_live_input_generation()
+ if (.not. claim_decode_request()) error stop 'manual repeat missing after rollover'
+ if (active_request_id /= manual_id .or. active_request_expired) error stop 'manual repeat expired on rollover'
+ call set_nagain(0)
+ call set_manual_decode_flag(1)
+ manual_id = publish_decode_request()
+ call advance_live_input_generation()
+ if (.not. claim_decode_request()) error stop 'freeze request missing after rollover'
+ if (active_request_id /= manual_id .or. active_request_expired) error stop 'freeze request expired on rollover'
+ call set_ndiskdat(1)
+ final_id = publish_decode_request()
+ call advance_live_input_generation()
+ if (.not. claim_decode_request()) error stop 'disk request missing after rollover'
+ if (active_request_id /= final_id .or. active_request_expired) error stop 'disk request expired on rollover'
+ call set_ndiskdat(0)
+
+ early_id = publish_decode_request()
+ final_id = publish_decode_request()
+ call cancel_pending_decode_requests()
+ if (claim_decode_request()) error stop 'canceled request claimed'
+ if (is_current_decode_request(final_id)) error stop 'canceled completion accepted'
+ final_id = publish_decode_request()
+ if (.not. claim_decode_request()) error stop 'request missing after cancel'
+ if (active_request_id /= final_id) error stop 'wrong request after cancel'
+ early_id = publish_decode_request()
+ call set_stop_m65(1)
+ if (get_stop_m65() /= 1 .or. claim_decode_request()) error stop 'shutdown did not discard requests'
+end program
diff --git a/tests/unit/map65/test_map65_deep_search_cache.f90 b/tests/unit/map65/test_map65_deep_search_cache.f90
new file mode 100644
index 00000000..6479bcad
--- /dev/null
+++ b/tests/unit/map65/test_map65_deep_search_cache.f90
@@ -0,0 +1,188 @@
+program test_map65_deep_search_cache
+ use decodes_mod, only: mcall3a
+ use deep65_mod, only: build_call3_candidates, testmsg, ncode, ntot
+ use encode65_mod, only: encode65
+ implicit none
+
+ character(len=12), parameter :: mycall = 'K1ABC', hiscall = 'W9XYZ', no_call = ''
+ character(len=6), parameter :: hisgrid = 'EN37'
+ integer :: fixture_unit, ios
+ logical :: fixture_owned = .false.
+
+ ! Run in a dedicated test directory; never overwrite an existing callsign database.
+ open(newunit=fixture_unit, file='CALL3.TXT', status='new', action='write', iostat=ios)
+ call require(ios == 0, 'create an isolated CALL3.TXT fixture')
+ fixture_owned = .true.
+ call write_fixture(fixture_unit, 'G4XYZ,IO91,NONE,')
+ close(fixture_unit)
+
+ call test_startup_transition
+ call test_mycall_transition
+ call test_hiscall_transition
+ call test_grid_transition
+ call test_eme_transition
+ call test_file_invalidation
+
+ call remove_fixture
+ print '(a)', 'MAP65 Deep Search cache tests passed.'
+
+contains
+
+ subroutine build_fresh(local_call, dx_call, dx_grid, eme_only)
+ character(len=12), intent(in) :: local_call, dx_call
+ character(len=6), intent(in) :: dx_grid
+ integer, intent(in) :: eme_only
+
+ mcall3a = 1
+ call build_call3_candidates(local_call, dx_call, dx_grid, eme_only)
+ call require(mcall3a == 0, 'building consumes file invalidation')
+ end subroutine build_fresh
+
+ subroutine test_startup_transition
+ call build_fresh(mycall, no_call, hisgrid, 0)
+ call require(.not. any(testmsg(1:ntot) == 'K1ABC W9XYZ R-01'), &
+ 'startup without a DX call has no directed report candidates')
+ call build_call3_candidates(mycall, hiscall, hisgrid, 0)
+ call require(ntot == 132, 'a supplied DX call adds all report variants and file candidates')
+ call require_message('K1ABC W9XYZ EN37')
+ call require_message('K1ABC W9XYZ -01')
+ call require_message('K1ABC W9XYZ R-30')
+ call require_message('K1ABC W9XYZ 73')
+ call require_message('CQ K2ABC FN20')
+ call require_message('CQ G4XYZ IO91')
+ call require_fresh_equivalent(mycall, hiscall, hisgrid, 0, 'startup DX entry')
+ call build_call3_candidates(mycall, hiscall, hisgrid, 0)
+ call require_fresh_equivalent(mycall, hiscall, hisgrid, 0, 'unchanged settings')
+ end subroutine test_startup_transition
+
+ subroutine test_mycall_transition
+ character(len=12), parameter :: changed_call = 'K3ABC'
+
+ call build_fresh(mycall, hiscall, hisgrid, 0)
+ call build_call3_candidates(changed_call, hiscall, hisgrid, 0)
+ call require_message('K3ABC W9XYZ EN37')
+ call require_message('K3ABC K2ABC FN20')
+ call require(.not. any(index(testmsg(1:ntot), 'K1ABC ') == 1), 'old MyCall candidates disappear')
+ call require_fresh_equivalent(changed_call, hiscall, hisgrid, 0, 'MyCall change')
+ end subroutine test_mycall_transition
+
+ subroutine test_hiscall_transition
+ character(len=12), parameter :: changed_call = 'W8XYZ'
+
+ call build_fresh(mycall, hiscall, hisgrid, 0)
+ call build_call3_candidates(mycall, changed_call, hisgrid, 0)
+ call require_message('K1ABC W8XYZ EN37')
+ call require_message('K1ABC W8XYZ R-01')
+ call require(.not. any(index(testmsg(1:ntot), 'W9XYZ') > 0), 'old DX call candidates disappear')
+ call require_fresh_equivalent(mycall, changed_call, hisgrid, 0, 'DX call change')
+ end subroutine test_hiscall_transition
+
+ subroutine test_grid_transition
+ character(len=6), parameter :: changed_grid = 'FN42'
+
+ call build_fresh(mycall, hiscall, hisgrid, 0)
+ call build_call3_candidates(mycall, hiscall, changed_grid, 0)
+ call require_message('K1ABC W9XYZ FN42')
+ call require_message('CQ W9XYZ FN42')
+ call require(.not. any(testmsg(1:ntot) == 'K1ABC W9XYZ EN37'), 'old DX grid candidate disappears')
+ call require_fresh_equivalent(mycall, hiscall, changed_grid, 0, 'DX grid change')
+ end subroutine test_grid_transition
+
+ subroutine test_eme_transition
+ call build_fresh(mycall, hiscall, hisgrid, 0)
+ call build_call3_candidates(mycall, hiscall, hisgrid, 1)
+ call require(ntot == 130, 'EME filtering removes only the non-EME file entry')
+ call require_message('K1ABC K2ABC FN20')
+ call require_message('K1ABC W9XYZ R-01')
+ call require(.not. any(index(testmsg(1:ntot), 'G4XYZ') > 0), 'non-EME candidates disappear')
+ call require_fresh_equivalent(mycall, hiscall, hisgrid, 1, 'enable EME filter')
+ call build_call3_candidates(mycall, hiscall, hisgrid, 0)
+ call require_message('CQ G4XYZ IO91')
+ call require_fresh_equivalent(mycall, hiscall, hisgrid, 0, 'disable EME filter')
+ end subroutine test_eme_transition
+
+ subroutine test_file_invalidation
+ call build_fresh(mycall, hiscall, hisgrid, 0)
+ close(23)
+ open(newunit=fixture_unit, file='CALL3.TXT', status='replace', action='write')
+ call write_fixture(fixture_unit, 'G3ABC,IO92,NONE,')
+ close(fixture_unit)
+
+ call build_call3_candidates(mycall, hiscall, hisgrid, 0)
+ call require_message('CQ G4XYZ IO91')
+ call require(.not. any(testmsg(1:ntot) == 'CQ G3ABC IO92'), &
+ 'unchanged settings reuse the cache until explicit file invalidation')
+ mcall3a = 1
+ call build_call3_candidates(mycall, hiscall, hisgrid, 0)
+ call require(mcall3a == 0, 'a file reload consumes its invalidation flag')
+ call require_message('CQ G3ABC IO92')
+ call require(.not. any(index(testmsg(1:ntot), 'G4XYZ') > 0), 'file reload removes deleted stations')
+ call require_fresh_equivalent(mycall, hiscall, hisgrid, 0, 'CALL3.TXT reload')
+ end subroutine test_file_invalidation
+
+ subroutine require_fresh_equivalent(local_call, dx_call, dx_grid, eme_only, description)
+ character(len=12), intent(in) :: local_call, dx_call
+ character(len=6), intent(in) :: dx_grid
+ integer, intent(in) :: eme_only
+ character(len=*), intent(in) :: description
+ character(len=22), allocatable :: cached_messages(:)
+ integer, allocatable :: cached_symbols(:, :)
+ integer :: cached_count
+
+ cached_count = ntot
+ cached_messages = testmsg(1:ntot)
+ cached_symbols = ncode(:, 1:ntot)
+ call build_fresh(local_call, dx_call, dx_grid, eme_only)
+ call require(ntot == cached_count, description//': cached and fresh candidate counts match')
+ call require(all(testmsg(1:ntot) == cached_messages), description//': cached and fresh messages match')
+ call require(all(ncode(:, 1:ntot) == cached_symbols), description//': cached and fresh encoded symbols match')
+ end subroutine require_fresh_equivalent
+
+ subroutine require_message(message)
+ character(len=*), intent(in) :: message
+ character(len=22) :: padded_message
+ integer :: i, expected_symbols(63)
+
+ padded_message = message
+ call encode65(padded_message, expected_symbols)
+ do i = 1, ntot
+ if (testmsg(i) /= message) cycle
+ call require(all(ncode(:, i) == expected_symbols), 'matching encoded symbols for '//message)
+ return
+ end do
+ call require(.false., 'expected candidate '//message)
+ end subroutine require_message
+
+ subroutine write_fixture(unit, terrestrial_entry)
+ integer, intent(in) :: unit
+ character(len=*), intent(in) :: terrestrial_entry
+
+ write(unit, '(a)') '// Controlled Deep Search candidates', 'K2ABC,FN20,EME,', terrestrial_entry, 'ZZZZ'
+ end subroutine write_fixture
+
+ subroutine remove_fixture
+ logical :: opened
+ integer :: unit, status
+
+ if (.not. fixture_owned) return
+ inquire(file='CALL3.TXT', opened=opened, number=unit, iostat=status)
+ if (status /= 0) return
+ if (.not. opened) then
+ open(newunit=unit, file='CALL3.TXT', status='old', iostat=status)
+ if (status /= 0) return
+ end if
+ close(unit, status='delete', iostat=status)
+ if (status == 0) fixture_owned = .false.
+ end subroutine remove_fixture
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ call remove_fixture
+ error stop 1
+ end if
+ end subroutine require
+end program test_map65_deep_search_cache
diff --git a/tests/unit/map65/test_map65_half_symbol_scheduler.cpp b/tests/unit/map65/test_map65_half_symbol_scheduler.cpp
new file mode 100644
index 00000000..984c37a8
--- /dev/null
+++ b/tests/unit/map65/test_map65_half_symbol_scheduler.cpp
@@ -0,0 +1,61 @@
+#include "half_symbol_scheduler.h"
+
+#include <QtTest/QtTest>
+
+class TestMap65HalfSymbolScheduler final : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void retries_busy_half_symbols ();
+ void catches_up_one_half_symbol_at_a_time ();
+ void resets_for_the_next_period ();
+};
+
+void TestMap65HalfSymbolScheduler::retries_busy_half_symbols ()
+{
+ Map65HalfSymbolScheduler scheduler;
+ std::atomic_bool busy {false};
+
+ QVERIFY (scheduler.claim_next (1, busy));
+ QCOMPARE (scheduler.scheduled_half_symbol (), 1);
+ QVERIFY (!scheduler.claim_next (2, busy));
+ QCOMPARE (scheduler.scheduled_half_symbol (), 1);
+
+ busy.store (false, std::memory_order_release);
+ QVERIFY (scheduler.claim_next (2, busy));
+ QCOMPARE (scheduler.scheduled_half_symbol (), 2);
+}
+
+void TestMap65HalfSymbolScheduler::catches_up_one_half_symbol_at_a_time ()
+{
+ Map65HalfSymbolScheduler scheduler;
+ std::atomic_bool busy {false};
+
+ for (int expected = 1; expected <= 5; ++expected)
+ {
+ QVERIFY (scheduler.claim_next (5, busy));
+ QCOMPARE (scheduler.scheduled_half_symbol (), expected);
+ busy.store (false, std::memory_order_release);
+ }
+
+ QVERIFY (!scheduler.claim_next (5, busy));
+ QVERIFY (!busy.load (std::memory_order_acquire));
+}
+
+void TestMap65HalfSymbolScheduler::resets_for_the_next_period ()
+{
+ Map65HalfSymbolScheduler scheduler;
+ std::atomic_bool busy {false};
+
+ QVERIFY (scheduler.claim_next (1, busy));
+ busy.store (false, std::memory_order_release);
+ scheduler.reset ();
+
+ QCOMPARE (scheduler.scheduled_half_symbol (), 0);
+ QVERIFY (scheduler.claim_next (1, busy));
+}
+
+QTEST_GUILESS_MAIN (TestMap65HalfSymbolScheduler)
+
+#include "test_map65_half_symbol_scheduler.moc"
diff --git a/tests/unit/map65/test_map65_q65_dphi.f90 b/tests/unit/map65/test_map65_q65_dphi.f90
new file mode 100644
index 00000000..a9c0527d
--- /dev/null
+++ b/tests/unit/map65/test_map65_q65_dphi.f90
@@ -0,0 +1,126 @@
+program test_map65_q65_dphi
+ use iso_fortran_env, only: int8, real32, real64
+ use datcom_ptrs_mod, only: dd, ss, savg
+ use decodes_mod, only: decodes_init
+ use filbig_mod, only: filbig, MAXFFT2
+ use ftninit_mod, only: ftninit
+ use gen_q65_cwave_mod, only: gen_q65_cwave
+ use npar_ptrs_mod, only: abort_decode, fcenter, idphi, manualDecodeFlag, ndepth, &
+ nfft_active, nsmax_active, set_runtime_params, t_start
+ use q65_decode, only: msg0, nsnr0
+ use q65b_mod, only: q65b
+ use symspec_mod, only: symspec
+ use timer_impl, only: init_timer, fini_timer
+ use wideband_sync, only: candidate, get_candidates, init_wideband_sync, &
+ MAX_CANDIDATES, nkhz_center
+ implicit none
+
+ integer, parameter :: sample_rate = 96000, fft_size = 32768
+ character(len=24), parameter :: message = 'W1AAA K2BBB EM00'
+ complex(real32), allocatable :: waveform(:), c4a(:), c4b(:)
+ real(real32), allocatable :: display_spectrum(:)
+ integer, allocatable :: seed(:)
+ type(candidate) :: candidates(MAX_CANDIDATES)
+ character(len=24) :: sent_message
+ integer(int8) :: lstrong(0:1023)
+ integer :: i, k, nwave, seed_size, ncand, selected, newdat, n4, idec
+ integer :: nb, nbslider, ihsym, nzap, nkh
+ real(real32) :: gainx, gainy, phasex, phasey, rejectx, rejecty, pxdb, pydb, slimit
+
+ call set_runtime_params(sample_rate, fft_size, 56 * sample_rate)
+ allocate(dd(4, nsmax_active), ss(4, 322, nfft_active), savg(4, nfft_active))
+ allocate(waveform(nsmax_active), display_spectrum(nfft_active))
+ allocate(c4a(MAXFFT2), c4b(MAXFFT2))
+ ss = 0.0
+ savg = 0.0
+ waveform = cmplx(0.0, 0.0)
+
+ call random_seed(size=seed_size)
+ allocate(seed(seed_size))
+ seed = 104729
+ call random_seed(put=seed)
+ call random_number(dd)
+ dd = 60.0 * (dd - 0.5)
+
+ ! The capture is centered at 48 kHz; transmission starts one second in.
+ call gen_q65_cwave(message, 48000 + 1270, 2, real(sample_rate, real64), &
+ sent_message, waveform, nwave)
+ call require(nwave > 0 .and. trim(sent_message) == trim(message), 'generate the Q65 message')
+ call require(sample_rate + nwave <= nsmax_active, 'waveform fits in the capture')
+ do i = 1, nwave
+ k = sample_rate + i
+ ! Equal signal amplitudes with a 180-degree receiver phase offset.
+ dd(1,k) = dd(1,k) + real(waveform(i))
+ dd(2,k) = dd(2,k) + aimag(waveform(i))
+ dd(3,k) = dd(3,k) - real(waveform(i))
+ dd(4,k) = dd(4,k) - aimag(waveform(i))
+ end do
+ dd = real(nint(dd), real32)
+ deallocate(waveform)
+
+ call init_timer()
+ call ftninit('.')
+ open(unit=19, status='scratch')
+ open(unit=20, status='scratch')
+ call decodes_init()
+ call init_wideband_sync()
+ abort_decode = .false.
+ manualDecodeFlag = 0
+ ndepth = 1
+ idphi = 180
+ fcenter = 144.125_real64
+ nkhz_center = 125
+
+ nb = 0
+ nbslider = 40
+ gainx = 1.0
+ gainy = 1.0
+ phasex = 0.0
+ phasey = 0.0
+ slimit = 0.0
+ ihsym = 0
+ nzap = 0
+ do i = 1, 302
+ k = fft_size + nint(real(i - 1, real64) * 2048.0_real64 * sample_rate / 11025.0_real64)
+ call symspec(k, 1, 1, nb, nbslider, idphi, 0, 0, gainx, gainy, &
+ phasex, phasey, rejectx, rejecty, pxdb, pydb, display_spectrum, &
+ nkh, ihsym, nzap, slimit, lstrong)
+ end do
+ call require(ihsym == 302, 'complete the symbol spectra')
+
+ call get_candidates(ss, savg, .true., ihsym, 48, 56, 0, 2, candidates, ncand)
+ selected = 0
+ do i = 1, ncand
+ if (candidates(i)%iflip /= 0) cycle
+ if (abs(1000.0 * candidates(i)%f - 49270.0) > 10.0) cycle
+ selected = i
+ exit
+ end do
+ call require(selected > 0, 'acquire the Q65 signal with calibrated spectra')
+
+ newdat = 1
+ call filbig(dd, nsmax_active, 1000.0_real64 * candidates(selected)%f, newdat, &
+ sample_rate, .true., c4a, c4b, n4)
+ call system_clock(t_start)
+ call q65b(1, 0, 0, fcenter, 0, sample_rate, nkhz_center, 0, 100, .true., idphi, &
+ 'N0CALL ', 'FN31 ', ' ', ' ', 2, &
+ real(candidates(selected)%f, real64), 1.270, newdat, 0, 0, 0, idec)
+
+ call require(.not. logical(abort_decode), 'decode within the time budget')
+ call require(nsnr0 > -99 .and. trim(msg0) == trim(message), &
+ 'recover the Q65 message despite opposite-phase receiver channels')
+ call fini_timer()
+ print '(a)', 'MAP65 Q65 Dphi test passed.'
+
+contains
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ end if
+ end subroutine require
+end program test_map65_q65_dphi
diff --git a/tests/unit/map65/test_map65_q65b_timeout.f90 b/tests/unit/map65/test_map65_q65b_timeout.f90
new file mode 100644
index 00000000..bf7b2c9c
--- /dev/null
+++ b/tests/unit/map65/test_map65_q65b_timeout.f90
@@ -0,0 +1,46 @@
+program test_map65_q65b_timeout
+ use iso_fortran_env, only: real64
+ use npar_ptrs_mod, only: abort_decode, t_start
+ use q65_decode, only: cq0, msg0, nfreq0, nsnr0, xdt0
+ use q65b_mod, only: q65b
+ implicit none
+
+ integer :: idec, now, rate
+
+ call system_clock(now, rate)
+ t_start = now - 41*rate
+ abort_decode = .false.
+ idec = 123
+ nsnr0 = 7
+ msg0 = 'STALE MESSAGE'
+ cq0 = 'q1 '
+ xdt0 = 2.5
+ nfreq0 = 1000
+
+ call q65b(1, 0, 0, 144.125_real64, 0, 96000, 125, 0, 100, .false., 0, &
+ 'K1ABC ', 'FN42 ', 'W9XYZ ', 'EN50 ', 2, 1000.0_real64, 125.0, &
+ 1, 0, 0, 0, idec)
+
+ if (.not. abort_decode) then
+ print '(a)', 'FAIL: expired decode budget sets the abort flag'
+ error stop 1
+ end if
+ call require(idec == -1, 'timeout returns a defined failure status')
+ call require(nsnr0 == -99, 'timeout clears stale Q65 SNR state')
+ call require(len_trim(msg0) == 0 .and. len_trim(cq0) == 0, &
+ 'timeout clears stale Q65 message state')
+ call require(xdt0 == 0.0 .and. nfreq0 == 0, 'timeout clears stale Q65 signal state')
+ print '(a)', 'MAP65 Q65 timeout test passed.'
+
+contains
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ end if
+ end subroutine require
+end program test_map65_q65b_timeout
diff --git a/tests/unit/map65/test_map65_result_selection.f90 b/tests/unit/map65/test_map65_result_selection.f90
new file mode 100644
index 00000000..dd76ea4c
--- /dev/null
+++ b/tests/unit/map65/test_map65_result_selection.f90
@@ -0,0 +1,96 @@
+program test_map65_result_selection
+ use trimlist_mod, only: select_unique_decodes
+ implicit none
+
+ integer, parameter :: MAXMSG = 1000
+ real :: sig(MAXMSG, 30)
+ character(len=22) :: msg(MAXMSG)
+ integer :: indx(MAXMSG), nz
+
+ call test_result_identity
+ call test_empty_and_full_lists
+ print '(a)', 'MAP65 result selection tests passed.'
+
+contains
+
+ subroutine test_result_identity
+ sig = 0.0
+ msg = ' '
+
+ call set_result(1, 1, 100.000, 0.20, 1, 'K1ABC W9XYZ FN42', 1.0)
+ call set_result(2, 1, 100.005, 0.25, 1, 'K1ABC W9XYZ FN42', 2.0)
+ call set_result(3, 1, 100.005, 0.20, 1, 'W1AAA K2BBB EM00')
+ call set_result(4, 1, 100.005, 0.50, 1, 'K1ABC W9XYZ FN42')
+ call set_result(5, 1, 100.005, 0.20, -1, 'K1ABC W9XYZ FN42')
+ call set_result(6, 1, 100.020, 0.20, 1, 'K1ABC W9XYZ FN42')
+ call set_result(7, 1, 100.005, 0.20, 1, ' ')
+ call set_result(8, 2, 100.005, 0.20, 1, 'K1ABC W9XYZ FN42')
+
+ call select_unique_decodes(sig, msg, 8, 0.010, 0.2, indx, nz)
+ call require(nz == 6, 'only a matching message and signal identity is deduplicated')
+ call require(selected_count('W1AAA K2BBB EM00', 1, 1) == 1, &
+ 'a different message at the same frequency survives')
+ call require(selected_count('K1ABC W9XYZ FN42', 1, -1) == 1, &
+ 'opposite-sync results survive')
+ call require(selected_count('K1ABC W9XYZ FN42', 2, 1) == 1, &
+ 'results from another UTC survive')
+ call require(any(indx(1:nz) == 2) .and. .not. any(indx(1:nz) == 1), &
+ 'the stronger duplicate supplies the displayed metrics')
+ end subroutine test_result_identity
+
+ subroutine test_empty_and_full_lists
+ integer :: i
+
+ sig = 0.0
+ msg = ' '
+ call select_unique_decodes(sig, msg, 0, 0.010, 0.2, indx, nz)
+ call require(nz == 0, 'an empty result list stays empty')
+
+ do i = 1, MAXMSG
+ sig(i, 2) = 1.0
+ sig(i, 3) = 0.020*i
+ sig(i, 5) = 0.2
+ sig(i, 7) = 1.0
+ write(msg(i), '("MSG",I4.4)') i
+ end do
+ call select_unique_decodes(sig, msg, MAXMSG, 0.010, 0.2, indx, nz)
+ call require(nz == MAXMSG, 'the maximum result list does not overrun selection storage')
+ end subroutine test_empty_and_full_lists
+
+ subroutine set_result(index, utc, frequency, dt, flip, message, strength)
+ integer, intent(in) :: index, utc, flip
+ real, intent(in) :: frequency, dt
+ character(len=*), intent(in) :: message
+ real, intent(in), optional :: strength
+
+ sig(index, 2) = utc
+ sig(index, 3) = frequency
+ sig(index, 5) = dt
+ sig(index, 7) = flip
+ if (present(strength)) sig(index, 8) = strength
+ msg(index) = message
+ end subroutine set_result
+
+ integer function selected_count(message, utc, flip)
+ character(len=*), intent(in) :: message
+ integer, intent(in) :: utc, flip
+ integer :: i, source
+
+ selected_count = 0
+ do i = 1, nz
+ source = indx(i)
+ if (msg(source) == message .and. nint(sig(source, 2)) == utc .and. &
+ nint(sig(source, 7)) == flip) selected_count = selected_count + 1
+ end do
+ end function selected_count
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ end if
+ end subroutine require
+end program test_map65_result_selection
diff --git a/tests/unit/map65/test_map65_runtime_paths.cpp b/tests/unit/map65/test_map65_runtime_paths.cpp
new file mode 100644
index 00000000..7cca6ca4
--- /dev/null
+++ b/tests/unit/map65/test_map65_runtime_paths.cpp
@@ -0,0 +1,225 @@
+#include "runtime_paths.h"
+
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QTemporaryDir>
+#include <QtTest>
+
+namespace
+{
+bool writeFile(QString const& path, QByteArray const& contents)
+{
+ QFile file {path};
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ return false;
+ }
+ return file.write(contents) == contents.size();
+}
+
+QByteArray readFile(QString const& path)
+{
+ QFile file {path};
+ if (!file.open(QIODevice::ReadOnly)) {
+ return {};
+ }
+ return file.readAll();
+}
+
+class CurrentDirectoryGuard
+{
+public:
+ explicit CurrentDirectoryGuard(QString const& path)
+ : previous_ {QDir::currentPath()}
+ , changed_ {QDir::setCurrent(path)}
+ {
+ }
+
+ ~CurrentDirectoryGuard()
+ {
+ if (changed_) {
+ QDir::setCurrent(previous_);
+ }
+ }
+
+ bool changed() const { return changed_; }
+
+private:
+ QString previous_;
+ bool changed_;
+};
+}
+
+class TestMap65RuntimePaths final : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void canonicalSourcePrecedesLegacyCandidates()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app/resources"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const canonical = dir.absoluteFilePath("installed/eclipse.txt");
+ QString const legacy = dir.absoluteFilePath("app/resources/eclipse.txt");
+ QVERIFY(writeFile(canonical, "canonical"));
+ QVERIFY(writeFile(legacy, "legacy"));
+
+ QCOMPARE(map65RuntimeSourceFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"), "eclipse.txt"),
+ QFileInfo {canonical}.absoluteFilePath());
+ }
+
+ void legacySourceRemainsAvailable()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app/resources"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const legacy = dir.absoluteFilePath("app/resources/eclipse.txt");
+ QVERIFY(writeFile(legacy, "legacy"));
+
+ QCOMPARE(map65RuntimeSourceFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"), "eclipse.txt"),
+ QFileInfo {legacy}.absoluteFilePath());
+ }
+
+ void writableEclipseCannotShadowPackagedData()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const canonical = dir.absoluteFilePath("installed/eclipse.txt");
+ QString const stale = dir.absoluteFilePath("writable/eclipse.txt");
+ QVERIFY(writeFile(canonical, "current package"));
+ QVERIFY(writeFile(stale, "stale copy"));
+ CurrentDirectoryGuard cwd {dir.absoluteFilePath("writable")};
+ QVERIFY(cwd.changed());
+
+ QCOMPARE(map65RuntimeSourceFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"), "eclipse.txt"),
+ QFileInfo {canonical}.absoluteFilePath());
+ QCOMPARE(readFile(stale), QByteArray {"stale copy"});
+ }
+
+ void writableDirectoryIsNotASourceFallback()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const stale = dir.absoluteFilePath("writable/unique-runtime-data.txt");
+ QVERIFY(writeFile(stale, "stale copy"));
+ CurrentDirectoryGuard cwd {dir.absoluteFilePath("writable")};
+ QVERIFY(cwd.changed());
+
+ QCOMPARE(map65RuntimeSourceFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"),
+ "unique-runtime-data.txt"),
+ dir.absoluteFilePath("installed/unique-runtime-data.txt"));
+ }
+
+ void writableDirectoryAliasIsNotASourceFallback()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const writable = dir.absoluteFilePath("writable");
+ QString const writableAlias = dir.absoluteFilePath("writable-alias");
+ if (!QFile::link(writable, writableAlias)) {
+ QSKIP("Directory links are unavailable");
+ }
+ QString const stale = QDir {writable}.absoluteFilePath("unique-runtime-data.txt");
+ QVERIFY(writeFile(stale, "stale copy"));
+ QString const aliasedStale =
+ QDir {writableAlias}.absoluteFilePath("unique-runtime-data.txt");
+ if (QFileInfo {aliasedStale}.canonicalFilePath()
+ != QFileInfo {stale}.canonicalFilePath()) {
+ QSKIP("Traversable directory links are unavailable");
+ }
+ CurrentDirectoryGuard cwd {writable};
+ QVERIFY(cwd.changed());
+
+ QCOMPARE(map65RuntimeSourceFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"), writableAlias,
+ "unique-runtime-data.txt"),
+ dir.absoluteFilePath("installed/unique-runtime-data.txt"));
+ }
+
+ void seedsMissingWritableFile()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QVERIFY(writeFile(dir.absoluteFilePath("installed/CALL3.TXT"), "packaged calls"));
+
+ QString const writable = ensureMap65RuntimeFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"),
+ "CALL3.TXT");
+ QCOMPARE(writable, dir.absoluteFilePath("writable/CALL3.TXT"));
+ QCOMPARE(readFile(writable), QByteArray {"packaged calls"});
+ }
+
+ void replacesEmptyWritableFile()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const writable = dir.absoluteFilePath("writable/CALL3.TXT");
+ QVERIFY(writeFile(dir.absoluteFilePath("installed/CALL3.TXT"), "packaged calls"));
+ QVERIFY(writeFile(writable, {}));
+
+ QCOMPARE(ensureMap65RuntimeFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"), "CALL3.TXT"),
+ writable);
+ QCOMPARE(readFile(writable), QByteArray {"packaged calls"});
+ }
+
+ void preservesNonemptyWritableFile()
+ {
+ QTemporaryDir root;
+ QVERIFY(root.isValid());
+ QDir dir {root.path()};
+ QVERIFY(dir.mkpath("app"));
+ QVERIFY(dir.mkpath("installed"));
+ QVERIFY(dir.mkpath("writable"));
+ QString const writable = dir.absoluteFilePath("writable/CALL3.TXT");
+ QVERIFY(writeFile(dir.absoluteFilePath("installed/CALL3.TXT"), "packaged calls"));
+ QVERIFY(writeFile(writable, "user calls"));
+
+ QCOMPARE(ensureMap65RuntimeFile(dir.absoluteFilePath("app"),
+ dir.absoluteFilePath("installed"),
+ dir.absoluteFilePath("writable"), "CALL3.TXT"),
+ writable);
+ QCOMPARE(readFile(writable), QByteArray {"user calls"});
+ }
+};
+
+QTEST_APPLESS_MAIN(TestMap65RuntimePaths)
+
+#include "test_map65_runtime_paths.moc"