summaryrefslogtreecommitdiff
path: root/tests/unit/q65
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/q65
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'tests/unit/q65')
-rw-r--r--tests/unit/q65/CMakeLists.txt16
-rw-r--r--tests/unit/q65/test_map65_wideband_sync_rows.f90132
-rw-r--r--tests/unit/q65/test_q65_caller_display.f90123
-rw-r--r--tests/unit/q65/test_q65_callers.f90163
-rw-r--r--tests/unit/q65/test_q65_decode_pipeline.f90138
-rw-r--r--tests/unit/q65/test_q65_llh_contracts.c70
6 files changed, 628 insertions, 14 deletions
diff --git a/tests/unit/q65/CMakeLists.txt b/tests/unit/q65/CMakeLists.txt
index 698ea12d..71c8223b 100644
--- a/tests/unit/q65/CMakeLists.txt
+++ b/tests/unit/q65/CMakeLists.txt
@@ -1,6 +1,5 @@
-add_executable (test_q65_workspace
- test_q65_workspace.f90
- ${CMAKE_SOURCE_DIR}/lib/qra/q65/q65_workspace.f90)
+add_executable (test_q65_workspace test_q65_workspace.f90)
+wsjt_link_common_fortran (test_q65_workspace)
add_test (NAME test_q65_workspace COMMAND test_q65_workspace)
@@ -21,7 +20,8 @@ add_test (NAME test_q65_decode_pipeline COMMAND test_q65_decode_pipeline)
set_tests_properties (test_q65_decode_pipeline PROPERTIES
COST 10
# Allow for hosted ARM emulation without leaving the test unbounded.
- TIMEOUT 180)
+ # The full-period spectra and drift cases added about a third to the runtime.
+ TIMEOUT 360)
if (WSJT_ENABLE_TSAN)
set_tests_properties (test_q65_decode_pipeline PROPERTIES
ENVIRONMENT "TSAN_OPTIONS=${wsjt_tsan_fortran_options}")
@@ -33,3 +33,11 @@ target_include_directories (test_q65_llh_contracts PRIVATE
${CMAKE_SOURCE_DIR}/lib/qra/q65)
target_link_libraries (test_q65_llh_contracts PRIVATE wsjt_cxx)
add_test (NAME test_q65_llh_contracts COMMAND test_q65_llh_contracts)
+
+add_executable (test_q65_callers test_q65_callers.f90)
+wsjt_link_common_fortran (test_q65_callers)
+add_test (NAME test_q65_callers COMMAND test_q65_callers)
+
+add_executable (test_q65_caller_display test_q65_caller_display.f90)
+wsjt_link_common_fortran (test_q65_caller_display)
+add_test (NAME test_q65_caller_display COMMAND test_q65_caller_display)
diff --git a/tests/unit/q65/test_map65_wideband_sync_rows.f90 b/tests/unit/q65/test_map65_wideband_sync_rows.f90
index 143f0c3a..185bd96f 100644
--- a/tests/unit/q65/test_map65_wideband_sync_rows.f90
+++ b/tests/unit/q65/test_map65_wideband_sync_rows.f90
@@ -105,4 +105,136 @@ program test_map65_wideband_sync_rows
call get_candidates(ss,savg,.true.,jz,1,2,0,1,candidates,ncand)
if (sync(target_bin)%ccfmax /= ccf_before) &
error stop 'invalid covariance did not preserve the legacy Q65 score'
+
+ call test_candidate_search()
+
+contains
+
+ subroutine reset_search_floor()
+ integer :: bin,row
+ ss(:,1:jz,ia:ib)=1.0
+ savg(:,ia:ib)=real(jz)
+ do bin=ia,ib
+ do row=1,jz
+ ss(1,row,bin)=1.0+0.002*real(mod(17*row+13*bin,23))
+ enddo
+ savg(1,bin)=sum(ss(1,1:jz,bin))
+ enddo
+ end subroutine reset_search_floor
+
+ subroutine add_search_sync(bin,level)
+ integer, intent(in) :: bin
+ real, intent(in) :: level
+ integer :: symbol,row,offset
+ do symbol=1,size(expanded_sync)
+ row=expanded_sync(symbol)+lag
+ do offset=0,2
+ if(row+offset<=jz) ss(1,row+offset,bin)=ss(1,row+offset,bin)+level
+ enddo
+ enddo
+ savg(1,bin)=sum(ss(1,1:jz,bin))
+ end subroutine add_search_sync
+
+ subroutine add_jt65_sync(bin,ooo)
+ integer, intent(in) :: bin
+ logical, intent(in) :: ooo
+ integer, parameter :: standard_symbols(63) = [ &
+ 1,4,5,9,10,11,12,13,14,16,18,22,24,25,28,32, &
+ 33,34,37,38,39,40,42,43,45,46,47,48,52,53,55,57, &
+ 59,60,63,64,66,68,70,73,80,81,89,90,92,95,97,98, &
+ 100,102,104,107,108,111,114,119,120,121,122,123,124,125,126]
+ integer :: symbol,row
+ do symbol=1,126
+ if(ooo .eqv. any(standard_symbols==symbol)) cycle
+ row=2*(symbol-1)+1+lag
+ ss(1,row:row+1,bin)=ss(1,row:row+1,bin)+50.0
+ enddo
+ savg(1,bin)=sum(ss(1,1:jz,bin))
+ end subroutine add_jt65_sync
+
+ subroutine assert_one_at(bin,description)
+ integer, intent(in) :: bin
+ character(len=*), intent(in) :: description
+ integer :: index
+ logical :: matches
+ matches=.false.
+ do index=1,ncand
+ if(candidates(index)%iflip==0 .and. &
+ abs(candidates(index)%f-0.001*(bin-1)*df)<0.0005*df .and. &
+ abs(candidates(index)%xdt-(lag*2048.0/11025.0-1.0))<0.001) matches=.true.
+ enddo
+ if(.not.matches) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ endif
+ end subroutine assert_one_at
+
+ subroutine test_candidate_search()
+ type(candidate) :: first
+ integer :: first_count, second_bin
+
+ second_bin=target_bin+120
+ call reset_search_floor()
+ call add_search_sync(target_bin,50.0)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=1) error stop 'one MAP65 Q65 sync candidate was not isolated'
+ call assert_one_at(target_bin,'one MAP65 Q65 candidate frequency and time')
+ first_count=ncand
+ first=candidates(1)
+
+ call reset_search_floor()
+ call add_search_sync(second_bin,50.0)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=1) error stop 'alternate MAP65 candidate was not isolated'
+ call assert_one_at(second_bin,'alternate MAP65 candidate frequency and time')
+
+ call reset_search_floor()
+ call add_search_sync(target_bin,50.0)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=first_count .or. candidates(1)%f/=first%f .or. &
+ candidates(1)%xdt/=first%xdt .or. candidates(1)%snr/=first%snr .or. &
+ candidates(1)%iflip/=first%iflip) error stop 'MAP65 A-B-A candidate changed'
+
+ ss(2:4,1:jz,ia:ib)=1.0e20
+ savg(2:4,ia:ib)=1.0e20
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=first_count .or. candidates(1)%f/=first%f .or. &
+ candidates(1)%snr/=first%snr) error stop 'inactive MAP65 polarization affected search'
+
+ call reset_search_floor()
+ call add_search_sync(target_bin,50.0)
+ call add_search_sync(second_bin,45.0)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=2) error stop 'separated MAP65 Q65 signals did not survive'
+
+ call reset_search_floor()
+ call add_search_sync(target_bin,50.0)
+ call add_search_sync(target_bin+2,20.0)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=1) error stop 'nearby MAP65 peaks did not collapse to one candidate'
+ call assert_one_at(target_bin,'stronger MAP65 nearby peak survived')
+
+ call reset_search_floor()
+ ss(1,1:jz,target_bin)=ss(1,1:jz,target_bin)+80.0
+ savg(1,target_bin)=sum(ss(1,1:jz,target_bin))
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(ncand/=0) error stop 'continuous MAP65 carrier entered the Q65 candidate list'
+
+ call reset_search_floor()
+ call add_jt65_sync(second_bin,.false.)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(sync(second_bin)%iflip/=1) error stop 'standard JT65 sync fixture was not recognized'
+ if(ncand/=0) error stop 'standard JT65 sync entered Q65-only search'
+
+ call reset_search_floor()
+ call add_jt65_sync(second_bin,.true.)
+ call get_candidates(ss,savg,.false.,jz,1,2,0,1,candidates,ncand)
+ if(sync(second_bin)%iflip/=-1) error stop 'OOO JT65 sync fixture was not recognized'
+ if(ncand/=0) error stop 'OOO JT65 sync entered Q65-only search'
+
+ call reset_search_floor()
+ call add_search_sync(target_bin,50.0)
+ call get_candidates(ss,savg,.false.,jz,2,3,0,1,candidates,ncand)
+ if(ncand/=0) error stop 'MAP65 candidate outside search band was admitted'
+ end subroutine test_candidate_search
end program test_map65_wideband_sync_rows
diff --git a/tests/unit/q65/test_q65_caller_display.f90 b/tests/unit/q65/test_q65_caller_display.f90
new file mode 100644
index 00000000..87e54590
--- /dev/null
+++ b/tests/unit/q65/test_q65_caller_display.f90
@@ -0,0 +1,123 @@
+program test_q65_caller_display
+ use types, only: q3list
+ use q65_callers
+ use, intrinsic :: iso_fortran_env, only: int8
+ implicit none
+
+ type(q3list) :: callers(Q65_MAX_CALLERS),loaded(Q65_MAX_CALLERS)
+ character(len=Q65_ROW_WIDTH) :: rows(Q65_MAX_CALLERS)
+ character(len=256) :: ephemeris
+ character(len=*), parameter :: path='caller-display-history.dat'
+ character(len=*), parameter :: other='caller-display-removal.dat'
+ character(len=*), parameter :: malformed='caller-display-malformed.dat'
+ integer(int8), allocatable :: before(:),after(:)
+ integer :: i,now,count,status,unit
+ logical*1 :: disk_data
+
+ ephemeris='missing-caller-display-ephemeris'
+ call jpl_setup(ephemeris)
+ now=time()
+ do i=1,Q65_MAX_CALLERS
+ write(callers(i)%call,'(a1,i5.5)') 'K',i
+ callers(i)%grid='FN42'
+ callers(i)%nsec=now
+ callers(i)%nfreq=1500-i
+ callers(i)%moonel=99
+ enddo
+ callers(1)%nsec=now-90000
+ call q65_save_callers(path,callers,Q65_MAX_CALLERS,status)
+ call require(status.eq.0,'save mixed-age history')
+ call read_bytes(path,before)
+
+ disk_data=.true.
+ call get_q3list(path,disk_data,Q65_MAX_CALLERS,count,rows)
+ call require(count.eq.Q65_MAX_CALLERS-1,'display excludes expired callers')
+ call require(rows(1)(12:17).eq.callers(Q65_MAX_CALLERS)%call, &
+ 'display sorts callers by frequency')
+ call require(rows(count)(12:17).eq.callers(2)%call,'display retains every fresh caller')
+ call require(iachar(rows(count)(Q65_ROW_WIDTH:Q65_ROW_WIDTH)).eq.0,'row terminator')
+ call require_unchanged(path,before,'disk display preserves history bytes')
+
+ disk_data=.false.
+ call get_q3list(path,disk_data,Q65_MAX_CALLERS,count,rows)
+ call require_unchanged(path,before,'live visibility filtering preserves history bytes')
+ disk_data=.true.
+ rows='untouched'
+ call get_q3list(path,disk_data,2,count,rows)
+ call require(count.eq.2,'display respects output capacity')
+ call require(all(rows(3:).eq.'untouched'),'display does not write beyond capacity')
+ call require(rows(1)(12:17).eq.callers(Q65_MAX_CALLERS)%call, &
+ 'bounded display preserves frequency ordering')
+ rows='untouched'
+ call get_q3list(path,disk_data,0,count,rows)
+ call require(count.eq.0 .and. all(rows.eq.'untouched'),'zero capacity leaves output untouched')
+
+ callers(1)%nsec=now
+ call q65_save_callers(path,callers,Q65_MAX_CALLERS,status)
+ call require(status.eq.0,'save full history')
+ call read_bytes(path,before)
+ call get_q3list(path,disk_data,Q65_MAX_CALLERS,count,rows)
+ call require(count.eq.Q65_MAX_CALLERS,'display includes full caller capacity')
+ call require_unchanged(path,before,'full display preserves history bytes')
+
+ loaded=q3list('','',0,0,0)
+ loaded(1)=q3list('K1ABC','FN42',now,1500,0)
+ call q65_save_callers(other,loaded,1,status)
+ call require(status.eq.0,'save separate removal history')
+ call rm_q3list(other,'K1ABC')
+ call q65_load_callers(other,loaded,count,status)
+ call require(status.eq.0 .and. count.eq.0,'remove final caller using explicit path')
+ call require_unchanged(path,before,'removal leaves previously displayed history untouched')
+
+ open(newunit=unit,file=malformed,form='unformatted',status='replace')
+ write(unit) Q65_MAX_CALLERS+1
+ close(unit)
+ call read_bytes(malformed,before)
+ call get_q3list(malformed,disk_data,Q65_MAX_CALLERS,count,rows)
+ call require(count.eq.0,'malformed history displays empty')
+ call rm_q3list(malformed,'K1ABC')
+ call require_unchanged(malformed,before,'failed load never overwrites malformed history')
+
+ call delete_file(path)
+ call delete_file(other)
+ call delete_file(malformed)
+ deallocate(before,after)
+ print *, 'PASS Q65 caller display and removal'
+
+contains
+
+ subroutine require(condition,message)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: message
+ if(.not.condition) then
+ print *, 'FAIL: '//message
+ stop 1
+ endif
+ end subroutine require
+
+ subroutine read_bytes(filename,bytes)
+ character(len=*), intent(in) :: filename
+ integer(int8), allocatable, intent(out) :: bytes(:)
+ integer :: n,u
+ inquire(file=filename,size=n)
+ allocate(bytes(n))
+ open(newunit=u,file=filename,status='old',access='stream',form='unformatted',action='read')
+ read(u) bytes
+ close(u)
+ end subroutine read_bytes
+
+ subroutine require_unchanged(filename,expected,message)
+ character(len=*), intent(in) :: filename,message
+ integer(int8), intent(in) :: expected(:)
+ call read_bytes(filename,after)
+ call require(size(after).eq.size(expected),message)
+ call require(all(after.eq.expected),message)
+ end subroutine require_unchanged
+
+ subroutine delete_file(filename)
+ character(len=*), intent(in) :: filename
+ integer :: u
+ open(newunit=u,file=filename,status='old')
+ close(u,status='delete')
+ end subroutine delete_file
+end program test_q65_caller_display
diff --git a/tests/unit/q65/test_q65_callers.f90 b/tests/unit/q65/test_q65_callers.f90
new file mode 100644
index 00000000..935337b0
--- /dev/null
+++ b/tests/unit/q65/test_q65_callers.f90
@@ -0,0 +1,163 @@
+program test_q65_callers
+ use types, only: q3list
+ use q65_callers
+ use, intrinsic :: iso_fortran_env, only: int16
+ implicit none
+ integer, parameter :: now=1000000
+ character(len=*), parameter :: filename='test_q65_callers.dat'
+ type(q3list) :: callers(Q65_MAX_CALLERS),loaded(Q65_MAX_CALLERS)
+ integer :: count,status,n,unit,i
+ character(len=6) :: callsign
+
+ call remove_file()
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.eq.0 .and. n.eq.0,'missing history is empty')
+ call expect(all(loaded%call.eq.'') .and. all(loaded%nsec.eq.0),'empty history is initialized')
+ call check_expiry()
+ call check_capacity()
+ call check_persistence()
+ call remove_file()
+ print *, 'Q65 caller history tests passed'
+
+contains
+
+ subroutine expect(condition,message)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: message
+ if(condition) return
+ print *, message
+ error stop 1
+ end subroutine expect
+
+ subroutine check_expiry()
+ callers=q3list('','',0,0,0)
+ callers(1)=q3list('K1AAA','FN42',now-86401,1000,0)
+ callers(2)=q3list('K1BBB','FN42',now-86401,1100,0)
+ callers(3)=q3list('K1CCC','FN42',now,1200,0)
+ count=3
+ call q65_expire_callers(callers,count,now)
+ call expect(count.eq.1 .and. callers(1)%call.eq.'K1CCC','adjacent expired entries are removed')
+ call q65_expire_callers(callers,count,now)
+ call expect(count.eq.1 .and. callers(1)%call.eq.'K1CCC','expiry is idempotent')
+ callers(1)=q3list('K1AAA','FN42',now-86401,1000,0)
+ callers(2)=q3list('K1BBB','FN42',now,1100,0)
+ callers(3)=q3list('K1CCC','FN42',now-86401,1200,0)
+ count=3
+ call q65_expire_callers(callers,count,now)
+ call expect(count.eq.1 .and. callers(1)%call.eq.'K1BBB','fresh caller survives expired neighbors')
+ callers(1)=q3list('K1AAA','FN42',now-86400,1000,0)
+ callers(2)=q3list('K1BBB','FN42',now+1,1100,0)
+ count=2
+ call q65_expire_callers(callers,count,now)
+ call expect(count.eq.2,'24-hour boundary and future timestamps are retained')
+ call q65_expire_callers(callers,count,now+86402)
+ call expect(count.eq.0 .and. all(callers%call.eq.''),'all-expired history is empty')
+ end subroutine check_expiry
+
+ subroutine check_capacity()
+ callers=q3list('','',0,0,0)
+ count=0
+ do i=1,Q65_MAX_CALLERS
+ write(callsign,'(a2,i4.4)') 'K1',i
+ call q65_record_caller(callers,count,1000+i,'K1ABC '//callsign//' FN42',now+i)
+ enddo
+ call expect(count.eq.Q65_MAX_CALLERS,'history reaches full capacity')
+ call q65_record_caller(callers,count,2000,'K1ABC K10001 R EM10',now+100)
+ call expect(count.eq.Q65_MAX_CALLERS .and. callers(1)%nsec.eq.now+100,'refresh does not add a caller')
+ call expect(callers(1)%grid.eq.'FN42' .and. callers(1)%nfreq.eq.2000,'refresh preserves grid and updates frequency')
+ call q65_record_caller(callers,count,2100,'K1ABC K19999 FN42',now+101)
+ call expect(count.eq.Q65_MAX_CALLERS,'overflow retains capacity')
+ call expect(callers(1)%call.eq.'K10001' .and. callers(2)%call.eq.'K10003', &
+ 'least recently heard caller is evicted after refresh')
+ call expect(callers(count)%call.eq.'K19999','new caller enters full history')
+ call q65_save_callers(filename,callers,count,status)
+ call expect(status.eq.0,'full history saves')
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.eq.0 .and. n.eq.count,'full history reloads')
+ call expect(all(loaded%call.eq.callers%call) .and. all(loaded%nsec.eq.callers%nsec), &
+ 'eviction and refresh survive reload')
+
+ callers%nsec=now
+ call q65_record_caller(callers,count,2200,'K1ABC K18888 FN42',now+1)
+ call expect(callers(1)%call.eq.'K10003','equal timestamps evict first stored caller')
+ call q65_record_caller(callers,count,2300,'K1ABC K17777/P FN42',now+2)
+ call expect(.not.any(callers%call.eq.'K17777'),'compound calls are ignored')
+ call q65_record_caller(callers,count,2300,'K1ABC K17777 RR73',now+2)
+ call expect(.not.any(callers%call.eq.'K17777'),'RR73 does not introduce a caller')
+ call q65_remove_caller(callers,count,'K18888')
+ call expect(count.eq.Q65_MAX_CALLERS-1,'final caller can be removed at capacity')
+ call q65_remove_caller(callers,count,'K18888')
+ call expect(count.eq.Q65_MAX_CALLERS-1,'absent caller removal is harmless')
+ do while(count.gt.0)
+ callsign=callers(1)%call
+ call q65_remove_caller(callers,count,callsign)
+ enddo
+ call q65_save_callers(filename,callers,count,status)
+ call expect(status.eq.0,'empty history saves')
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.eq.0 .and. n.eq.0,'empty history reloads')
+
+ callers(1)=q3list('K1OLD','FN42',now-86401,1000,0)
+ count=1
+ call q65_record_caller(callers,count,1500,'K1ABC K1NEW FN42',now)
+ call expect(count.eq.1 .and. callers(1)%call.eq.'K1NEW','recording expires old callers first')
+ end subroutine check_capacity
+
+ subroutine check_persistence()
+ integer :: legacy_count,saved_count
+
+ callers=q3list('K1ABC','FN42',now,1500,0)
+ do legacy_count=40,50,10
+ open(newunit=unit,file=filename,status='replace',form='unformatted')
+ write(unit) legacy_count
+ write(unit) callers(1:legacy_count)
+ close(unit)
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.eq.0 .and. n.eq.legacy_count,'legacy binary history loads')
+ call expect(all(loaded(1:n)%call.eq.'K1ABC'),'legacy caller records are preserved')
+ enddo
+
+ do saved_count=-1,Q65_MAX_CALLERS+1,Q65_MAX_CALLERS+2
+ open(newunit=unit,file=filename,status='replace',form='unformatted')
+ write(unit) saved_count
+ close(unit)
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.ne.0 .and. n.eq.0 .and. all(loaded%call.eq.''),'invalid count is rejected safely')
+ open(newunit=unit,file=filename,status='old',form='unformatted')
+ read(unit) legacy_count
+ close(unit)
+ call expect(legacy_count.eq.saved_count,'failed load leaves malformed file unchanged')
+ enddo
+
+ open(newunit=unit,file=filename,status='replace',form='unformatted')
+ write(unit) 2
+ write(unit) callers(1:1)
+ close(unit)
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.ne.0 .and. n.eq.0 .and. all(loaded%nsec.eq.0),'short caller record is rejected safely')
+ call q65_save_callers(filename,callers,Q65_MAX_CALLERS+1,status)
+ call expect(status.ne.0,'over-capacity save is rejected')
+ open(newunit=unit,file=filename,status='old',form='unformatted')
+ read(unit) saved_count
+ close(unit)
+ call expect(saved_count.eq.2,'rejected save does not replace existing file')
+
+ open(newunit=unit,file=filename,status='replace',form='unformatted')
+ close(unit)
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.eq.0 .and. n.eq.0,'legacy empty file is a normal empty history')
+ open(newunit=unit,file=filename,status='replace',form='unformatted',access='stream')
+ write(unit) 1_int16
+ close(unit)
+ call q65_load_callers(filename,loaded,n,status)
+ call expect(status.ne.0 .and. n.eq.0,'truncated count is rejected safely')
+ end subroutine check_persistence
+
+ subroutine remove_file()
+ logical :: exists
+ inquire(file=filename,exist=exists)
+ if(.not.exists) return
+ open(newunit=unit,file=filename,status='old')
+ close(unit,status='delete')
+ end subroutine remove_file
+end program test_q65_callers
diff --git a/tests/unit/q65/test_q65_decode_pipeline.f90 b/tests/unit/q65/test_q65_decode_pipeline.f90
index 84b34dc0..a4c93c7f 100644
--- a/tests/unit/q65/test_q65_decode_pipeline.f90
+++ b/tests/unit/q65/test_q65_decode_pipeline.f90
@@ -44,6 +44,7 @@ program test_q65_decode_pipeline
use q65_decode, only: q65_decoder,cq0,msg0,nsnr0,nfreq0,xdt0
use q65_test_fixture, only: make_q65_wave,q65_nsamples,q65_ntrperiod
use types, only: q3list
+ use q65_callers, only: Q65_MAX_CALLERS,Q65_MAX_CODEWORDS
implicit none
integer(int16), allocatable :: iwave(:)
@@ -74,6 +75,14 @@ program test_q65_decode_pipeline
call run_direct_decode(decoder,iwave,nsubmode,1,want_iflagdec=0)
enddo
+ iwave=0_int16
+ call run_direct_decode(decoder,iwave,0,0,ntrperiod=30)
+ if(decoder%state%jz0.ne.(30*12000-30*120)/(30*120/8)+1) then
+ error stop 'Q65 spectra do not cover every complete input window'
+ endif
+
+ call check_q65_drift_compensation()
+
! The direct decoder loop owns exhaustive submode coverage. MAP65 is a thin
! handoff, so exercise both ends of its forwarded submode range.
do isubmode=1,size(map65_submodes)
@@ -87,16 +96,67 @@ program test_q65_decode_pipeline
iwave=0_int16
call run_map65_decode(iwave,0,.false.)
+ call decoder%destroy()
+ deallocate(iwave)
write(*,'(a)') 'Q65 raw decoder and MAP65 handoff tests passed'
contains
+ subroutine check_q65_drift_compensation()
+ use q65, only: q65_dec0,q65_select,q65_work,q65_state, &
+ s1a,s1w,iseq,iz0,j0,NSTEP,df,ncw,max_drift,drift
+ type(q65_state), pointer :: previous_state
+ integer, parameter :: drift_cases(3)=[-50,0,50]
+ integer :: case_number,want_drift,k,i,j,peak_min,peak_max,dat4(13),idec
+ real :: xdt,f0,snr1,width,snr2
+
+ iwave=0_int16
+ call run_direct_decode(decoder,iwave,0,0)
+ previous_state=>q65_work
+ call q65_select(decoder%state)
+ ncw=0
+ max_drift=50
+ do case_number=1,size(drift_cases)
+ want_drift=drift_cases(case_number)
+ s1a(:,:,iseq)=0.0
+ do k=1,85
+ j=j0+NSTEP*(k-1)+1
+ i=nint(1000.0/df)+nint(real(want_drift)*(k-43)/85.0)
+ s1a(i,j,iseq)=100.0
+ enddo
+ if(associated(s1w)) deallocate(s1w)
+ nullify(q65_work%s1w)
+ ! Averaged spectra without list candidates reach stage 5 without an earlier decode.
+ call q65_dec0(1,iwave,q65_ntrperiod,1000,20,lclearave,2.5, &
+ xdt,f0,snr1,width,dat4,snr2,idec,5)
+ ! Integer bin rounding makes zero drift indistinguishable from a one-bin sweep.
+ if(abs(nint(drift/df)-want_drift).gt.1) then
+ error stop 'Q65 synchronization missed the planted drift'
+ endif
+ if(.not.associated(s1w)) error stop 'Q65 stage-5 drift compensation did not run'
+ peak_min=iz0
+ peak_max=1
+ do k=1,85
+ j=j0+NSTEP*(k-1)+1
+ if(maxval(s1w(:,j)).lt.99.0) error stop 'Q65 drift compensation lost a symbol'
+ i=maxloc(s1w(:,j),dim=1)
+ peak_min=min(peak_min,i)
+ peak_max=max(peak_max,i)
+ enddo
+ if(peak_max-peak_min.gt.1) then
+ error stop 'Q65 drift compensation depends on the receive horizon'
+ endif
+ enddo
+ call q65_select(previous_state)
+ lclearave=.true.
+ end subroutine check_q65_drift_compensation
+
subroutine check_q65_ap_flag_masks()
integer :: apsym0(58),apmask(78),apsymbols(78),iaptype
- integer :: codewords(63,411),ncw,j
+ integer :: codewords(63,Q65_MAX_CODEWORDS),ncw,j
character(len=12) :: list_mycall,list_hiscall
character(len=6) :: list_hisgrid
- type(q3list) :: callers(50)
+ type(q3list) :: callers(Q65_MAX_CALLERS)
apsym0=0
call q65_ap(5,1,0,.false.,.false.,iaptype,apsym0,apmask,apsymbols)
@@ -112,19 +172,75 @@ contains
list_mycall='K1ABC'
list_hiscall='W9XYZ'
list_hisgrid='FN42'
- do j=1,40
- write(callers(j)%call,'(a2,i4.4)') 'K1',j
+ do j=1,Q65_MAX_CALLERS
+ callers(j)%call='K1'//achar(65+(j-1)/26)//achar(65+mod(j-1,26))//'A'
callers(j)%grid='FN42'
enddo
- call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers,40,codewords,ncw)
- if(ncw.ne.411) error stop 'Q65 Pileup full AP list truncated at 40 callers'
+ call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers, &
+ Q65_MAX_CALLERS,codewords,ncw)
+ if(ncw.ne.511) error stop 'Q65 Pileup full AP list omitted a stored or current caller'
+ if(any(codewords(:,1).ne.0)) error stop 'Q65 Pileup all-zero candidate changed'
+ call check_caller_codewords(codewords(:,ncw-19:ncw-10),list_mycall, &
+ callers(Q65_MAX_CALLERS)%call,callers(Q65_MAX_CALLERS)%grid)
+ call check_caller_codewords(codewords(:,ncw-9:ncw),list_mycall, &
+ list_hiscall,list_hisgrid)
+
+ list_hiscall=callers(Q65_MAX_CALLERS)%call
+ call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers, &
+ Q65_MAX_CALLERS,codewords,ncw)
+ if(ncw.ne.501) error stop 'Q65 Pileup duplicated a stored current caller'
+ call check_caller_codewords(codewords(:,ncw-9:ncw),list_mycall, &
+ callers(Q65_MAX_CALLERS)%call,callers(Q65_MAX_CALLERS)%grid)
+
+ list_hiscall=' '
+ call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers, &
+ Q65_MAX_CALLERS,codewords,ncw)
+ if(ncw.ne.501) error stop 'Q65 Pileup added an invalid current caller'
+ call check_caller_codewords(codewords(:,ncw-9:ncw),list_mycall, &
+ callers(Q65_MAX_CALLERS)%call,callers(Q65_MAX_CALLERS)%grid)
+
+ call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers,-1,codewords,ncw)
+ if(ncw.ne.0) error stop 'Q65 Pileup accepted a negative caller count'
+ call q65_set_list2(list_mycall,list_hiscall,list_hisgrid,callers, &
+ Q65_MAX_CALLERS+1,codewords,ncw)
+ if(ncw.ne.0) error stop 'Q65 Pileup accepted an oversized caller count'
end subroutine check_q65_ap_flag_masks
- subroutine run_direct_decode(decoder,samples,nsubmode,want_callback,want_iflagdec)
+ subroutine check_caller_codewords(codewords,mycall,dxcall,grid)
+ integer, intent(in) :: codewords(63,10)
+ character(len=*), intent(in) :: mycall,dxcall,grid
+ integer, parameter :: sync_positions(22)=[ &
+ 1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85]
+ character(len=6) :: tails(5)
+ character(len=37) :: message,msgsent
+ integer :: tones(85),expected(63),kind,flag,i3,n3,j,k,column
+
+ tails=[character(len=6) :: grid(1:4),'R '//grid(1:4),'RRR','RR73','73']
+ do kind=1,size(tails)
+ message=trim(mycall)//' '//trim(dxcall)//' '//trim(tails(kind))
+ do flag=0,1
+ call genq65(message,0,msgsent,tones,i3,n3,flag)
+ if(msgsent.ne.message) error stop 'Q65 Pileup test message failed to encode'
+ j=0
+ do k=1,size(tones)
+ if(any(sync_positions.eq.k)) cycle
+ j=j+1
+ expected(j)=tones(k)-1
+ enddo
+ column=2*(kind-1)+flag+1
+ if(any(codewords(:,column).ne.expected)) then
+ error stop 'Q65 Pileup lost a message form or flag at the caller boundary'
+ endif
+ enddo
+ enddo
+ end subroutine check_caller_codewords
+
+ subroutine run_direct_decode(decoder,samples,nsubmode,want_callback,want_iflagdec,ntrperiod)
type(q65_decoder), intent(inout) :: decoder
integer(int16), intent(in) :: samples(:)
integer, intent(in) :: nsubmode,want_callback
- integer, intent(in), optional :: want_iflagdec
+ integer, intent(in), optional :: want_iflagdec,ntrperiod
+ integer :: decode_period
logical :: want_success
callback_count=0
@@ -139,7 +255,9 @@ contains
callback_freq=0.0
callback_iflagdec=-1
want_success=want_callback.ne.0
- call decoder%decode(capture_callback,samples,1,100,q65_ntrperiod,nsubmode, &
+ decode_period=q65_ntrperiod
+ if(present(ntrperiod)) decode_period=ntrperiod
+ call decoder%decode(capture_callback,samples,1,100,decode_period,nsubmode, &
1000,150,3,850,1150,lclearave,single_decode,lagain,0,lnewdat,2.5, &
mycall,hiscall,hisgrid,0,0,.false.,lapcqonly,navg0,nqf)
if(want_success) then
@@ -147,7 +265,7 @@ contains
if(trim(callback_message).ne.'K1ABC W9XYZ FN42') then
error stop 'direct Q65 decoder returned the wrong message'
endif
- if(callback_idec.lt.0 .or. callback_ntrperiod.ne.q65_ntrperiod) then
+ if(callback_idec.lt.0 .or. callback_ntrperiod.ne.decode_period) then
error stop 'direct Q65 callback metadata changed'
endif
if(abs(callback_freq-1000.0).gt.8.0) error stop 'direct Q65 frequency changed'
diff --git a/tests/unit/q65/test_q65_llh_contracts.c b/tests/unit/q65/test_q65_llh_contracts.c
index 888674bd..d99883e9 100644
--- a/tests/unit/q65/test_q65_llh_contracts.c
+++ b/tests/unit/q65/test_q65_llh_contracts.c
@@ -1,8 +1,10 @@
#include "q65.h"
+#include "qra15_65_64_irr_e23.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
static void require (int condition, char const * message)
{
@@ -13,6 +15,73 @@ static void require (int condition, char const * message)
}
}
+static void set_candidate_probabilities (float * intrinsics, int const * codeword,
+ float probability)
+{
+ for (int symbol = 0; symbol < 63; ++symbol)
+ {
+ for (int tone = 0; tone < 64; ++tone)
+ intrinsics[symbol * 64 + tone] = (1.0f - probability) / 63.0f;
+ intrinsics[symbol * 64 + codeword[symbol]] = probability;
+ }
+}
+
+static void check_full_ap_list (void)
+{
+ q65_codec_ds codec;
+ int (*codewords)[63] = calloc (Q65_FULLAPLIST_SIZE, sizeof *codewords);
+ float intrinsics[63 * 64];
+ int decoded[63], message[13], expected[13] = {0};
+
+ require (codewords != NULL, "full AP list allocation failed");
+ require (q65_init (&codec, &qra15_65_64_irr_e23) >= 0,
+ "Q65 codec initialization failed");
+ require (Q65_FULLAPLIST_SIZE == 511, "Q65 full AP list capacity changed");
+ for (int index = 0; index < Q65_FULLAPLIST_SIZE; ++index)
+ {
+ expected[0] = index % 64;
+ expected[1] = index / 64;
+ require (q65_encode (&codec, codewords[index], expected) >= 0,
+ "full AP candidate encoding failed");
+ }
+
+ int last = Q65_FULLAPLIST_SIZE - 1;
+ set_candidate_probabilities (intrinsics, codewords[last], 0.9f);
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], Q65_FULLAPLIST_SIZE) == last,
+ "full AP decoder did not reach the final current-DX candidate");
+ require (memcmp (decoded, codewords[last], sizeof decoded) == 0 &&
+ memcmp (message, expected, sizeof message) == 0,
+ "full AP decoder returned the wrong final candidate payload");
+
+ int last_stored = last - 10;
+ set_candidate_probabilities (intrinsics, codewords[last_stored], 0.9f);
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], Q65_FULLAPLIST_SIZE) == last_stored,
+ "full AP decoder did not reach the final stored-caller candidate");
+
+ for (int index = 0; index < 63 * 64; ++index)
+ intrinsics[index] = 1.0f / 64.0f;
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], Q65_FULLAPLIST_SIZE) == Q65_DECODE_FAILED,
+ "full AP decoder accepted uniform evidence at maximum capacity");
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], Q65_FULLAPLIST_SIZE + 1) == Q65_DECODE_INVPARAMS,
+ "full AP decoder accepted a list beyond capacity");
+
+ // This likelihood lies between the admission thresholds for 411 and 511 entries.
+ set_candidate_probabilities (intrinsics, codewords[0], expf (-255.0f / 63.0f));
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], 411) == 0,
+ "full AP decoder rejected the smaller-list boundary fixture");
+ require (q65_decode_fullaplist (&codec, decoded, message, intrinsics,
+ codewords[0], Q65_FULLAPLIST_SIZE) == Q65_DECODE_FAILED,
+ "growing the full AP list failed to tighten admission");
+
+ q65_free (&codec);
+ free (codewords);
+}
+
int main (void)
{
float intrinsics[64] = {0};
@@ -38,5 +107,6 @@ int main (void)
require (isinf (llh) && llh < 0.0f,
"out-of-range codeword symbol left LLH undefined");
+ check_full_ap_list ();
return 0;
}