From ff2481f6dba86d1327581cf9522e50439677d0e0 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Sat, 21 Nov 2026 12:45:51 -0500 Subject: [PATCH] add modem frame pacing tests for DMR, P25, and NXDN; preserve full P25 frame lengths when checking available modem space; account for tagged NXDN frame length when gating writes; --- src/host/Host.DMR.cpp | 6 +-- src/host/Host.NXDN.cpp | 4 +- src/host/Host.P25.cpp | 4 +- src/host/modem/Modem.cpp | 2 +- src/host/modem/Modem.h | 6 +++ tests/dmr/HostControl_Tests.cpp | 31 ++++++++++++++++ tests/host/HostTestHooks.cpp | 53 +++++++++++++++++++++++++++ tests/host/HostTestHooks.h | 46 +++++++++++++++++++++++ tests/nxdn/HostControl_Tests.cpp | 24 ++++++++++++ tests/p25/HostControl_Tests.cpp | 63 ++++++++++++++++++++++++++++++++ 10 files changed, 231 insertions(+), 8 deletions(-) diff --git a/src/host/Host.DMR.cpp b/src/host/Host.DMR.cpp index 54cac4a4..31373d6c 100644 --- a/src/host/Host.DMR.cpp +++ b/src/host/Host.DMR.cpp @@ -4,7 +4,7 @@ * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * -* Copyright (C) 2017-2024 Bryan Biedenkapp, N2PLL +* Copyright (C) 2017-2026 Bryan Biedenkapp, N2PLL * */ #include "Defines.h" @@ -95,7 +95,7 @@ void* Host::threadDMRReader1(void* arg) }; if (host->m_dmr != nullptr) { - uint8_t nextLen = host->m_modem->peekDMRFrame1Length(); + uint32_t nextLen = host->m_modem->peekDMRFrame1Length(); if (nextLen > 0U) { // read DMR slot 1 frames from the modem, and if there is any // write those frames to the DMR controller @@ -381,7 +381,7 @@ void* Host::threadDMRReader2(void* arg) }; if (host->m_dmr != nullptr) { - uint8_t nextLen = host->m_modem->peekDMRFrame2Length(); + uint32_t nextLen = host->m_modem->peekDMRFrame2Length(); if (nextLen > 0U) { // read DMR slot 2 frames from the modem, and if there is any // write those frames to the DMR controller diff --git a/src/host/Host.NXDN.cpp b/src/host/Host.NXDN.cpp index a165d631..b2d0c882 100644 --- a/src/host/Host.NXDN.cpp +++ b/src/host/Host.NXDN.cpp @@ -4,7 +4,7 @@ * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * -* Copyright (C) 2017-2024 Bryan Biedenkapp, N2PLL +* Copyright (C) 2017-2026 Bryan Biedenkapp, N2PLL * */ #include "Defines.h" @@ -75,7 +75,7 @@ void* Host::threadNXDNReader(void* arg) }; if (host->m_nxdn != nullptr) { - uint8_t nextLen = host->m_modem->peekNXDNFrameLength(); + uint32_t nextLen = host->m_modem->peekNXDNFrameLength(); if (nextLen > 0U) { uint32_t len = host->m_modem->readNXDNFrame(data); if (len > 0U) { diff --git a/src/host/Host.P25.cpp b/src/host/Host.P25.cpp index 6fc74793..9eafa484 100644 --- a/src/host/Host.P25.cpp +++ b/src/host/Host.P25.cpp @@ -79,7 +79,7 @@ void* Host::threadP25Reader(void* arg) // read P25 frames from modem, and if there are frames // write those frames to the P25 controller if (host->m_p25 != nullptr) { - uint8_t nextLen = host->m_modem->peekP25FrameLength(); + uint32_t nextLen = host->m_modem->peekP25FrameLength(); if (nextLen > 0U) { uint32_t len = host->m_modem->readP25Frame(data); if (len > 0U) { @@ -244,7 +244,7 @@ void* Host::threadP25Writer(void* arg) // if there is read frames from the P25 controller and write it // to the modem if (host->m_p25 != nullptr) { - uint8_t nextLen = host->m_p25->peekFrameLength(); + uint32_t nextLen = host->m_p25->peekFrameLength(); if (host->m_p25CtrlChannel) { if (host->m_p25DedicatedTxTestTimer.hasExpired() && !host->m_p25DedicatedTxTestTimer.isPaused()) { host->m_p25DedicatedTxTestTimer.pause(); diff --git a/src/host/modem/Modem.cpp b/src/host/modem/Modem.cpp index 76ece249..81767bec 100644 --- a/src/host/modem/Modem.cpp +++ b/src/host/modem/Modem.cpp @@ -1432,7 +1432,7 @@ bool Modem::hasP25P2Space2() const bool Modem::hasNXDNSpace() const { - return m_nxdnSpace >= NXDDEF::NXDN_FRAME_LENGTH_BYTES; + return m_nxdnSpace >= (NXDDEF::NXDN_FRAME_LENGTH_BYTES + 2U); } /* Helper to test if the modem is a hotspot. */ diff --git a/src/host/modem/Modem.h b/src/host/modem/Modem.h index 51217470..9c3653dd 100644 --- a/src/host/modem/Modem.h +++ b/src/host/modem/Modem.h @@ -76,6 +76,9 @@ class HOST_SW_API Host; class HOST_SW_API HostCal; namespace host_restapi { class HOST_SW_API RESTAPI; } +#if defined(CATCH2_TEST_COMPILATION) +class HostTestHooks; +#endif class HOST_SW_API HostSetup; #if defined(ENABLE_SETUP_TUI) @@ -787,6 +790,9 @@ namespace modem friend class ::Host; friend class ::HostCal; friend class ::host_restapi::RESTAPI; +#if defined(CATCH2_TEST_COMPILATION) + friend class ::HostTestHooks; +#endif friend class ::HostSetup; #if defined(ENABLE_SETUP_TUI) diff --git a/tests/dmr/HostControl_Tests.cpp b/tests/dmr/HostControl_Tests.cpp index 5ce99513..d0d9baef 100644 --- a/tests/dmr/HostControl_Tests.cpp +++ b/tests/dmr/HostControl_Tests.cpp @@ -1033,6 +1033,37 @@ TEST_CASE("DMR grant authority follows configuration and FNE availability", REQUIRE(localSlot->isGrantAuthoritative()); } +TEST_CASE("DMR frames wait for complete modem space", "[dmr][host][control][queue][pacing]") +{ + const uint32_t frameLength = dmr::defines::DMR_FRAME_LENGTH_BYTES + 2U; + uint8_t frame[dmr::defines::DMR_FRAME_LENGTH_BYTES + 2U] = { 0U }; + frame[0U] = modem::TAG_DATA; + + for (uint32_t slotNo = 1U; slotNo <= 2U; slotNo++) { + DYNAMIC_SECTION("slot " << slotNo) { + DMRHostHarness harness; + HostTestHooks::dmrAddFrame(*harness.m_control, slotNo, frame); + REQUIRE(harness.m_control->peekFrameLength(slotNo) == frameLength); + + HostTestHooks::modemSetDMRSpace(harness.m_modem, slotNo, frameLength - 1U); + const bool insufficient = slotNo == 1U ? harness.m_modem.hasDMRSpace1() : harness.m_modem.hasDMRSpace2(); + REQUIRE_FALSE(insufficient); + CHECK(harness.m_control->peekFrameLength(slotNo) == frameLength); + + HostTestHooks::modemSetDMRSpace(harness.m_modem, slotNo, frameLength); + const bool sufficient = slotNo == 1U ? harness.m_modem.hasDMRSpace1() : harness.m_modem.hasDMRSpace2(); + REQUIRE(sufficient); + + uint8_t out[dmr::defines::DMR_FRAME_LENGTH_BYTES + 2U] = { 0U }; + REQUIRE(harness.m_control->getFrame(slotNo, out) == frameLength); + const bool written = slotNo == 1U ? harness.m_modem.writeDMRFrame1(out, frameLength) : harness.m_modem.writeDMRFrame2(out, frameLength); + REQUIRE(written); + CHECK(harness.m_control->peekFrameLength(slotNo) == 0U); + CHECK((slotNo == 1U ? harness.m_modem.getDMRSpace1() : harness.m_modem.getDMRSpace2()) == 0U); + } + } +} + TEST_CASE("DMR FNE grant responses are rebuilt with local channel assignments", "[dmr][host][control][grant-response]") { diff --git a/tests/host/HostTestHooks.cpp b/tests/host/HostTestHooks.cpp index 855e1d1c..d2f6da09 100644 --- a/tests/host/HostTestHooks.cpp +++ b/tests/host/HostTestHooks.cpp @@ -594,6 +594,59 @@ void HostTestHooks::p25ClockU2U(p25::Control& control, uint32_t ms) control.m_control->clock(ms); } +/* Queues a tagged DMR frame for transmission to the modem. */ + +void HostTestHooks::dmrAddFrame(dmr::Control& control, uint32_t slotNo, const uint8_t* data) +{ + dmr::Slot* slot = slotNo == 1U ? control.m_slot1 : control.m_slot2; + slot->addFrame(data); +} + +/* Queues a tagged P25 frame for transmission to the modem. */ + +bool HostTestHooks::p25AddFrame(p25::Control& control, const uint8_t* data, uint32_t length) +{ + return control.addFrame(data, length); +} + +/* Queues a tagged NXDN frame for transmission to the modem. */ + +void HostTestHooks::nxdnAddFrame(nxdn::Control& control, const uint8_t* data) +{ + control.addFrame(data); +} + +/* Sets the modem's reported DMR ring buffer space. */ + +void HostTestHooks::modemSetDMRSpace(modem::Modem& modem, uint32_t slotNo, uint32_t space) +{ + if (slotNo == 1U) + modem.m_dmrSpace1 = space; + else + modem.m_dmrSpace2 = space; +} + +/* Sets the modem's reported P25 ring buffer space. */ + +void HostTestHooks::modemSetP25Space(modem::Modem& modem, uint32_t space) +{ + modem.m_p25Space = space; +} + +/* Sets the modem's reported NXDN ring buffer space. */ + +void HostTestHooks::modemSetNXDNSpace(modem::Modem& modem, uint32_t space) +{ + modem.m_nxdnSpace = space; +} + +/* Sets the modem protocol version reported by the test fixture. */ + +void HostTestHooks::modemSetProtocolVersion(modem::Modem& modem, uint8_t version) +{ + modem.m_protoVer = version; +} + /* Stores an MFID transaction for a control-signaling test. */ void HostTestHooks::p25StoreMFId(p25::Control& control, uint32_t srcId, uint32_t dstId, diff --git a/tests/host/HostTestHooks.h b/tests/host/HostTestHooks.h index 2ac4da7f..c5e7315f 100644 --- a/tests/host/HostTestHooks.h +++ b/tests/host/HostTestHooks.h @@ -388,6 +388,52 @@ public: * @param ms Elapsed milliseconds. */ static void p25ClockU2U(p25::Control& control, uint32_t ms); + /** + * @brief Queues a tagged DMR frame for transmission to the modem. + * @param control DMR control instance. + * @param slotNo DMR slot number (1 or 2). + * @param[in] data Tagged frame data. + */ + static void dmrAddFrame(dmr::Control& control, uint32_t slotNo, const uint8_t* data); + /** + * @brief Queues a tagged P25 frame for transmission to the modem. + * @param control P25 control instance. + * @param[in] data Tagged frame data. + * @param length Length of the tagged frame in bytes. + * @returns bool True if the frame was queued; otherwise, false. + */ + static bool p25AddFrame(p25::Control& control, const uint8_t* data, uint32_t length); + /** + * @brief Queues a tagged NXDN frame for transmission to the modem. + * @param control NXDN control instance. + * @param[in] data Tagged frame data. + */ + static void nxdnAddFrame(nxdn::Control& control, const uint8_t* data); + /** + * @brief Sets the modem's reported DMR ring buffer space. + * @param modem Modem instance. + * @param slotNo DMR slot number (1 or 2). + * @param space Reported DMR space in bytes. + */ + static void modemSetDMRSpace(modem::Modem& modem, uint32_t slotNo, uint32_t space); + /** + * @brief Sets the modem's reported P25 ring buffer space. + * @param modem Modem instance. + * @param space Reported P25 space in bytes. + */ + static void modemSetP25Space(modem::Modem& modem, uint32_t space); + /** + * @brief Sets the modem's reported NXDN ring buffer space. + * @param modem Modem instance. + * @param space Reported NXDN space in bytes. + */ + static void modemSetNXDNSpace(modem::Modem& modem, uint32_t space); + /** + * @brief Sets the modem protocol version reported by the test fixture. + * @param modem Modem instance. + * @param version Modem protocol version. + */ + static void modemSetProtocolVersion(modem::Modem& modem, uint8_t version); /** * @brief Stores an MFID transaction for P25 control-signaling tests. */ diff --git a/tests/nxdn/HostControl_Tests.cpp b/tests/nxdn/HostControl_Tests.cpp index 6308cfcb..2714b3be 100644 --- a/tests/nxdn/HostControl_Tests.cpp +++ b/tests/nxdn/HostControl_Tests.cpp @@ -1066,3 +1066,27 @@ TEST_CASE("NXDN grant authority follows configuration and FNE availability", local.network()->activateForTest(); REQUIRE(local.m_control->isGrantAuthoritative()); } + +TEST_CASE("NXDN frames wait for complete modem space", "[nxdn][host][control][queue][pacing]") +{ + NXDNHostHarness harness; + const uint32_t frameLength = nxdn::defines::NXDN_FRAME_LENGTH_BYTES + 2U; + uint8_t frame[nxdn::defines::NXDN_FRAME_LENGTH_BYTES + 2U] = { 0U }; + frame[0U] = modem::TAG_DATA; + + HostTestHooks::nxdnAddFrame(*harness.m_control, frame); + REQUIRE(harness.m_control->peekFrameLength() == frameLength); + + HostTestHooks::modemSetNXDNSpace(harness.m_modem, frameLength - 1U); + REQUIRE_FALSE(harness.m_modem.hasNXDNSpace()); + CHECK(harness.m_control->peekFrameLength() == frameLength); + + HostTestHooks::modemSetNXDNSpace(harness.m_modem, frameLength); + REQUIRE(harness.m_modem.hasNXDNSpace()); + + uint8_t out[nxdn::defines::NXDN_FRAME_LENGTH_BYTES + 2U] = { 0U }; + REQUIRE(harness.m_control->getFrame(out) == frameLength); + REQUIRE(harness.m_modem.writeNXDNFrame(out, frameLength)); + CHECK(harness.m_control->peekFrameLength() == 0U); + CHECK(harness.m_modem.getNXDNSpace() == 0U); +} diff --git a/tests/p25/HostControl_Tests.cpp b/tests/p25/HostControl_Tests.cpp index 6d3f6218..b7e07155 100644 --- a/tests/p25/HostControl_Tests.cpp +++ b/tests/p25/HostControl_Tests.cpp @@ -2183,3 +2183,66 @@ TEST_CASE("P25 grant authority follows configuration and FNE availability", local.network()->activateForTest(); REQUIRE(local.m_control->isGrantAuthoritative()); } + +TEST_CASE("P25 frame types wait for their complete variable-length modem space", "[p25][host][control][queue][pacing]") +{ + using namespace p25::defines; + + struct FrameLengthCase { + const char* name; + uint32_t length; + }; + + const uint32_t minimumPDUBytes = + ((P25_PREAMBLE_LENGTH_BITS + P25_PDU_FEC_LENGTH_BITS + 7U) / 8U) + 2U; + const FrameLengthCase cases[] = { + { "TDU", P25_TDU_FRAME_LENGTH_BYTES + 2U }, + { "null control fill", 25U + 2U }, + { "TSDU", P25_TSDU_FRAME_LENGTH_BYTES + 2U }, + { "TDULC", P25_TDULC_FRAME_LENGTH_BYTES + 2U }, + { "double TSDU", P25_TSDU_DOUBLE_FRAME_LENGTH_BYTES + 2U }, + { "triple TSDU", P25_TSDU_TRIPLE_FRAME_LENGTH_BYTES + 2U }, + { "HDU", P25_HDU_FRAME_LENGTH_BYTES + 2U }, + { "LDU1 or LDU2", P25_LDU_FRAME_LENGTH_BYTES + 2U }, + { "minimum PDU", minimumPDUBytes }, + { "last short modem frame", 251U }, + { "first long modem frame", 252U }, + { "last 8-bit length", 255U }, + { "first length above 255", 256U }, + { "14-block confirmed PDU", 395U }, + { "maximum PDU", P25_PDU_FRAME_LENGTH_BYTES + 2U } + }; + + for (const FrameLengthCase& testCase : cases) { + DYNAMIC_SECTION(testCase.name << " (" << testCase.length << " bytes)") { + P25HostHarness harness(false, false, 0U, 1U, false, false, true); + HostTestHooks::modemSetProtocolVersion(harness.m_modem, 4U); + + std::vector frame(testCase.length, 0U); + frame[0U] = modem::TAG_DATA; + for (uint32_t i = 2U; i < testCase.length; i++) + frame[i] = (uint8_t)i; + + REQUIRE(HostTestHooks::p25AddFrame(*harness.m_control, frame.data(), testCase.length)); + + HostTestHooks::modemSetP25Space(harness.m_modem, testCase.length - 1U); + uint32_t nextLen = harness.m_control->peekFrameLength(); + REQUIRE(nextLen == testCase.length); + REQUIRE_FALSE(harness.m_modem.hasP25Space(nextLen)); + REQUIRE_FALSE(harness.m_modem.writeP25Frame(frame.data(), testCase.length)); + CHECK(harness.m_control->peekFrameLength() == testCase.length); + + HostTestHooks::modemSetP25Space(harness.m_modem, testCase.length); + nextLen = harness.m_control->peekFrameLength(); + REQUIRE(nextLen == testCase.length); + REQUIRE(harness.m_modem.hasP25Space(nextLen)); + + std::vector out(P25_PDU_FRAME_LENGTH_BYTES + 2U, 0U); + REQUIRE(harness.m_control->getFrame(out.data()) == testCase.length); + REQUIRE(::memcmp(out.data(), frame.data(), testCase.length) == 0); + REQUIRE(harness.m_modem.writeP25Frame(out.data(), testCase.length)); + CHECK(harness.m_modem.getP25Space() == 0U); + CHECK(harness.m_control->peekFrameLength() == 0U); + } + } +}