summaryrefslogtreecommitdiff
path: root/tests/unit/packjt77
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/packjt77
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'tests/unit/packjt77')
-rw-r--r--tests/unit/packjt77/CMakeLists.txt7
-rw-r--r--tests/unit/packjt77/test_packjt77_context_state.f90117
-rw-r--r--tests/unit/packjt77/test_packjt77_grammar_gate.f9049
-rw-r--r--tests/unit/packjt77/test_packjt77_hash_state.f9028
-rw-r--r--tests/unit/packjt77/test_packjt77_schema_decoder.f9034
-rw-r--r--tests/unit/packjt77/test_packjt77sdvar_invariants.f9011
6 files changed, 235 insertions, 11 deletions
diff --git a/tests/unit/packjt77/CMakeLists.txt b/tests/unit/packjt77/CMakeLists.txt
index 2ce41135..8f8904ef 100644
--- a/tests/unit/packjt77/CMakeLists.txt
+++ b/tests/unit/packjt77/CMakeLists.txt
@@ -70,6 +70,13 @@ wsjt_link_common_fortran (test_packjt77_hash_state)
add_test (NAME test_packjt77_hash_state COMMAND test_packjt77_hash_state)
+add_executable (test_packjt77_context_state
+ test_packjt77_context_state.f90)
+target_include_directories (test_packjt77_context_state PRIVATE ${CMAKE_BINARY_DIR})
+wsjt_link_common_fortran (test_packjt77_context_state)
+
+add_test (NAME test_packjt77_context_state COMMAND test_packjt77_context_state)
+
if (WSJT_BUILD_FORTRAN_OPENMP)
add_executable (test_packjt77_concurrent_unpack
test_packjt77_concurrent_unpack.f90)
diff --git a/tests/unit/packjt77/test_packjt77_context_state.f90 b/tests/unit/packjt77/test_packjt77_context_state.f90
new file mode 100644
index 00000000..3360cb87
--- /dev/null
+++ b/tests/unit/packjt77/test_packjt77_context_state.f90
@@ -0,0 +1,117 @@
+program test_packjt77_context_state
+ use packjt77
+ implicit none
+
+ type(pack77_state), target :: first, second
+ character(len=13), pointer :: saved_calls(:)
+ character(len=77) :: bits
+ character(len=37) :: message
+ character(len=37) :: input
+ character(len=13) :: call,resolved_call
+ integer :: i3,n3,status,n10,n12,n22
+ logical :: ok
+
+ calls10=''
+ calls12=''
+ calls22=''
+ ihash22=-1
+ nzhash=0
+ mycall13=''
+ dxcall13=''
+
+ call='W7ABC'
+ n10=-99
+ n12=-99
+ n22=-99
+ call save_hash_call_for_state(first,call,n10,n12,n22)
+ call initialize_pack77_state(second)
+ call require(first%calls12(n12).eq.call,'first state records the call')
+ call require(second%calls12(n12).eq.'','second state is independent')
+ call require(calls12(n12).eq.'','legacy store is independent')
+
+ input='PJ2/W1AW <W7ABC> RR73'
+ call pack77_for_state(first,input,i3,n3,bits, &
+ pack77_options(record_tx_hashes=.false.),status)
+ call require(status.eq.PACK77_STATUS_ENCODED,'explicit encode accepted')
+ call require(i3.eq.4.and.n3.eq.0,'explicit encode selected type 4')
+ call require(first%nzhash.eq.1.and.second%nzhash.eq.0.and.nzhash.eq.0, &
+ 'encode without TX recording preserves separate stores')
+
+ call unpack77_for_state(second,bits,1,message,ok)
+ call require(ok.and.trim(message).eq.'PJ2/W1AW <...> RR73', &
+ 'second state initially lacks the hashed call')
+
+ call unpack77_for_state(first,bits,1,message,ok)
+ call require(ok.and.trim(message).eq.'PJ2/W1AW <W7ABC> RR73', &
+ 'first state resolves the hashed call')
+ call unpack77_for_state(second,bits,1,message,ok)
+ call require(ok.and.trim(message).eq.'PJ2/W1AW <...> RR73', &
+ 'second state remains unresolved')
+ call unpack77(bits,1,message,ok)
+ call require(ok.and.trim(message).eq.'PJ2/W1AW <...> RR73', &
+ 'legacy decode remains unresolved')
+
+ call queue_hash_call_for_thread_for_state(second,call,2)
+ call require(second%calls12(n12).eq.'','thread fact waits for fold')
+ call fold_queued_calls_for_state(second,2)
+ call require(second%calls12(n12).eq.call,'thread fact folds into its state')
+ call require(calls12(n12).eq.'','thread fold does not mutate legacy store')
+
+ call prepare_configured_decode_for_state(second,'N0AAA','N0BBB')
+ call require(second%mycall13_configured_set,'configured call belongs to state')
+ call require(.not.first%mycall13_configured_set, &
+ 'other state configured call remains clear')
+ call require(mycall13.eq.'','legacy configured call remains clear')
+
+ n10=-99
+ n12=-99
+ n22=-99
+ call save_hash_call_for_state(first,'<...> ',n10,n12,n22)
+ call require(n10.eq.-99.and.n12.eq.-99.and.n22.eq.-99, &
+ 'ignored calls leave hash outputs untouched')
+
+ call pack77_for_state(second,'K1ABC W9XYZ FN42',i3,n3,bits,status=status)
+ call require(status.eq.PACK77_STATUS_ENCODED.and.i3.eq.1, &
+ 'explicit encode accepts an assumed-length message')
+ call require(nzhash.eq.0,'explicit encode leaves the legacy store untouched')
+
+ call prepare_configured_decode_for_state(first,'N0AAA','N0BBB')
+ call queue_hash_call_for_thread_for_state(first,call,2)
+ saved_calls=>first%calls12
+ call initialize_pack77_state(first)
+ call hash12_for_state(first,ihashcall(call,12),resolved_call)
+ call require(trim(resolved_call).eq.'<'//trim(call)//'>','initialization preserves learned calls')
+ call require(first%mycall13.eq.'N0AAA'.and.first%mycall13_configured_set, &
+ 'initialization preserves configured calls')
+ call require(first%nqueued_calls_by_thread(2).gt.0,'initialization preserves queued calls')
+
+ call reset_pack77_state(first)
+ call require(associated(saved_calls,first%calls12),'reset retains table storage and views')
+ call require(all(saved_calls.eq.''),'existing view observes the reset')
+ call require(lbound(first%calls10,1).eq.0.and.lbound(first%calls12,1).eq.0, &
+ 'reset preserves zero-based hash tables')
+ call hash12_for_state(first,ihashcall(call,12),resolved_call)
+ call require(trim(resolved_call).eq.'<...>','reset forgets learned calls')
+ call require(first%nzhash.eq.0.and.all(first%ihash22.eq.-1),'reset clears hash entries')
+ call require(first%mycall13.eq.''.and..not.first%mycall13_configured_set, &
+ 'reset clears configured calls')
+ call fold_queued_calls_for_state(first,2)
+ call require(all(first%calls12.eq.''),'reset discards queued calls before folding')
+ call hash12_for_state(second,ihashcall(call,12),resolved_call)
+ call require(trim(resolved_call).eq.'<'//trim(call)//'>','reset leaves other states unchanged')
+ call save_hash_call_for_state(first,call,n10,n12,n22)
+ call require(saved_calls(n12).eq.call,'reset storage remains usable through existing views')
+
+ print *, 'packjt77 explicit state isolation passed'
+
+contains
+
+ subroutine require(condition,label)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: label
+
+ if(condition) return
+ print *, 'FAIL: ',label
+ error stop 1
+ end subroutine require
+end program test_packjt77_context_state
diff --git a/tests/unit/packjt77/test_packjt77_grammar_gate.f90 b/tests/unit/packjt77/test_packjt77_grammar_gate.f90
index 2698baa1..94246c00 100644
--- a/tests/unit/packjt77/test_packjt77_grammar_gate.f90
+++ b/tests/unit/packjt77/test_packjt77_grammar_gate.f90
@@ -1,6 +1,8 @@
program test_packjt77_grammar_gate
- use packjt77_grammar, only: pack77_gate_messages_match
+ use packjt77_grammar, only: pack77_gate_messages_match, &
+ pack77_exact_free_text_ok,pack77_free_text_alphabet_ok, &
+ pack77_configured_type12_ok,pack77_configured_type4_ok
implicit none
integer :: ntests
@@ -38,11 +40,56 @@ program test_packjt77_grammar_gate
call expect_no_match('changed serial', &
'K1ABC FN42 37', 'K1ABC FN42 38', no_calls, 0)
+ call expect_text_and_configured_receive_rules()
+
write(*,1000) ntests
1000 format('packjt77 grammar gate tests passed: ',i0)
contains
+ subroutine expect_text_and_configured_receive_rules()
+ character(len=13) :: call_1,call_2
+ character(len=37) :: msg
+
+ call expect_rule('empty free text',pack77_exact_free_text_ok(''))
+ call expect_rule('13-character free text',pack77_exact_free_text_ok('ABCDEFGHIJKLM'))
+ call expect_rule('14-character free text rejected',.not.pack77_exact_free_text_ok('ABCDEFGHIJKLMN'))
+ call expect_rule('alphabet independent of length',pack77_free_text_alphabet_ok('ABCDEFGHIJKLMN'))
+ call expect_rule('free text punctuation',pack77_exact_free_text_ok('0123 +-./?'))
+ call expect_rule('lowercase requires normalization',.not.pack77_exact_free_text_ok('abc'))
+ call expect_rule('unsupported free text symbol',.not.pack77_free_text_alphabet_ok('ABC@'))
+
+ call_1='<K1ABC>'
+ call_2='W9XYZ/R'
+ call expect_rule('configured rover collision rejected', &
+ .not.pack77_configured_type12_ok(call_1,call_2,'FN42',0))
+ call expect_rule('configured rover acknowledgement allowed', &
+ pack77_configured_type12_ok(call_1,call_2,'FN42',1))
+ call expect_rule('configured rover RR73 allowed', &
+ pack77_configured_type12_ok(call_1,call_2,'RR73',0))
+
+ call_1='CQ'
+ call_2='PJ4/K1ABC'
+ msg='CQ PJ4/K1ABC'
+ call expect_rule('configured compound CQ allowed', &
+ pack77_configured_type4_ok(call_1,call_2,msg,0,1,0))
+ call_2='12/K1ABC'
+ msg='CQ 12/K1ABC'
+ call expect_rule('configured two-digit prefix rejected', &
+ .not.pack77_configured_type4_ok(call_1,call_2,msg,0,1,0))
+ end subroutine expect_text_and_configured_receive_rules
+
+ subroutine expect_rule(label,ok)
+ character(len=*), intent(in) :: label
+ logical, intent(in) :: ok
+
+ if(.not.ok) then
+ write(*,'(a)') trim(label)//' failed'
+ error stop 1
+ endif
+ ntests=ntests+1
+ end subroutine expect_rule
+
subroutine expect_match(label,input_msg,decoded_msg,staged_calls,nstaged)
character(len=*), intent(in) :: label,input_msg,decoded_msg
character(len=13), intent(in) :: staged_calls(:)
diff --git a/tests/unit/packjt77/test_packjt77_hash_state.f90 b/tests/unit/packjt77/test_packjt77_hash_state.f90
index b122ba46..346bc972 100644
--- a/tests/unit/packjt77/test_packjt77_hash_state.f90
+++ b/tests/unit/packjt77/test_packjt77_hash_state.f90
@@ -6,9 +6,21 @@ program test_packjt77_hash_state
implicit none
integer :: ntests
- external :: fillhashvar
- external :: ft8apsetvar
external :: genft8
+ interface
+ subroutine fillhashvar(numthreads,lfill,knowledge)
+ import :: pack77_state
+ integer, intent(in) :: numthreads
+ logical, intent(in) :: lfill
+ type(pack77_state), target, optional, intent(inout) :: knowledge
+ end subroutine
+ subroutine ft8apsetvar(lmycallstd,lhiscallstd,numthreads,knowledge)
+ import :: pack77_state
+ logical(1), intent(in) :: lmycallstd,lhiscallstd
+ integer :: numthreads
+ type(pack77_state), target, optional, intent(inout) :: knowledge
+ end subroutine
+ end interface
ntests=0
@@ -881,8 +893,11 @@ contains
subroutine expect_ft8apsetvar_does_not_record_template_hashes()
logical(1) :: lmycallstd, lhiscallstd
+ type(pack77_state), target :: knowledge
call clear_all_state('N0AAA','PJ2/W1AW')
+ knowledge%mycall13='N0AAA'
+ knowledge%dxcall13='PJ2/W1AW'
mycall='N0AAA '
hiscall='PJ2/W1AW '
mybcall='N0AAA '
@@ -892,8 +907,13 @@ contains
lmycallstd=.true.
lhiscallstd=.false.
- call ft8apsetvar(lmycallstd,lhiscallstd,1)
- call assert_shared_hash_tables_empty('ft8apsetvar template hashes')
+ call ft8apsetvar(lmycallstd,lhiscallstd,1,knowledge)
+ call assert_int('ft8apsetvar owned nzhash',0,knowledge%nzhash)
+ call assert_true('ft8apsetvar owned calls10',all(knowledge%calls10.eq.''))
+ call assert_true('ft8apsetvar owned calls12',all(knowledge%calls12.eq.''))
+ call assert_true('ft8apsetvar owned calls22',all(knowledge%calls22.eq.''))
+ call assert_true('ft8apsetvar owned recent calls',all(knowledge%recent_calls.eq.''))
+ call assert_shared_hash_tables_empty('ft8apsetvar legacy isolation')
ntests=ntests+1
end subroutine expect_ft8apsetvar_does_not_record_template_hashes
diff --git a/tests/unit/packjt77/test_packjt77_schema_decoder.f90 b/tests/unit/packjt77/test_packjt77_schema_decoder.f90
index 7c9816f5..3e837ed0 100644
--- a/tests/unit/packjt77/test_packjt77_schema_decoder.f90
+++ b/tests/unit/packjt77/test_packjt77_schema_decoder.f90
@@ -13,6 +13,7 @@ program test_packjt77_schema_decoder
call expect_type2_tag_decode()
call expect_invalid_binary_and_tag_fail()
call expect_type1_grid_boundary()
+ call expect_wspr_dispatch()
call expect_wspr_selector_padding_and_power_checks()
call expect_type5_grid_range_check()
call expect_type5_raw_invalid_serial_rejected()
@@ -121,6 +122,39 @@ contains
ntests=ntests+1
end subroutine expect_type1_grid_boundary
+ subroutine expect_wspr_dispatch()
+ character(len=77) :: c77
+ integer :: selector
+ integer, parameter :: expected(0:7)=[1,2,3,2,1,2,3,2]
+ type(pack77_wspr_type3_fields) :: type3_fields
+ logical :: ok
+
+ c77=repeat('0',77)
+ c77(72:77)='110000'
+ do selector=0,7
+ write(c77(48:50),'(b3.3)') selector
+ call assert_int('WSPR subtype selector',expected(selector), &
+ pack77_wspr_payload_type(c77))
+ call assert_int('WSPR prevalidated subtype selector',expected(selector), &
+ pack77_wspr_payload_type(c77,.true.))
+ enddo
+
+ c77(48:50)='110'
+ call decode_pack77_wspr_type3(c77,type3_fields,ok,.true.)
+ call assert_true('dispatched invalid WSPR selector rejected',.not.ok)
+
+ c77(48:50)='010'
+ c77(1:1)='x'
+ call assert_int('WSPR dispatch rejects nonbinary payload',0, &
+ pack77_wspr_payload_type(c77))
+ c77(1:1)='0'
+ c77(50:50)='x'
+ call assert_int('WSPR dispatch rejects nonbinary selector',0, &
+ pack77_wspr_payload_type(c77))
+
+ ntests=ntests+1
+ end subroutine expect_wspr_dispatch
+
subroutine expect_wspr_selector_padding_and_power_checks()
character(len=77) :: c77
type(pack77_wspr_type1_fields) :: type1_fields
diff --git a/tests/unit/packjt77/test_packjt77sdvar_invariants.f90 b/tests/unit/packjt77/test_packjt77sdvar_invariants.f90
index d0ffac93..643e9ff3 100644
--- a/tests/unit/packjt77/test_packjt77sdvar_invariants.f90
+++ b/tests/unit/packjt77/test_packjt77sdvar_invariants.f90
@@ -2,15 +2,14 @@ program test_packjt77sdvar_invariants
use packjt77
use packjt77_test_helpers
+ use ft8var_codec_context, only: ft8sdvar,ft8svar,tonesdvar
use ft8_mod1, only : idtone56_valid,idtone56,itone56,msg,lastrxmsg,mycall, &
hiscall,nlasttx,csyncsd_valid,csyncsdcq_valid
implicit none
integer :: ntests
+ logical(kind=1), parameter :: flag_false=.false.,flag_true=.true.
external :: genft8sdvar
- external :: ft8sdvar
- external :: ft8svar
- external :: tonesdvar
ntests=0
@@ -134,7 +133,7 @@ contains
decoded=''
lft8s=.false.
- call ft8svar(s8,0.0,itone,decoded,lft8s,1,.false.)
+ call ft8svar(s8,0.0,itone,decoded,lft8s,1,flag_false)
call assert_true('ft8svar last grid row valid',logical(idtone56_valid(53)))
call assert_text_equal('ft8svar last grid message', &
@@ -150,7 +149,7 @@ contains
csyncsd_valid=.true.
msgd='<PJ4/K1ABC> W9XYZ -01'
- call tonesdvar(msgd,.false.)
+ call tonesdvar(msgd,flag_false)
call assert_true('failed QSO template invalidates sync', &
.not.logical(csyncsd_valid))
@@ -164,7 +163,7 @@ contains
csyncsdcq_valid=.true.
msgd='CQ PJ4/K1ABC'
- call tonesdvar(msgd,.true.)
+ call tonesdvar(msgd,flag_true)
call assert_true('failed CQ template invalidates sync', &
.not.logical(csyncsdcq_valid))