Refresh host fixtures for current Companion and USB interfaces

Declare fixture feature boundaries and SDK mocks explicitly, retain USB recovery ownership checks, and recognize the unified V4 display and read-only diagnostics in contract tests.
This commit is contained in:
mikecarper committed 2026-10-27 08:17:24 -07:00
1 parent c650278fa7
commit 0cba0c3afa
12 files changed
+57 -8

No files matched your search

@@ -17,6 +17,9 @@
#include <helpers/TracePathHelpers.h>
#include <helpers/TxtDataHelpers.h>
// This fixture models correlated RF replies. Direct USB OTA administration
// has a separate fixture and is disabled for every consumer of this harness.
#define COMPANION_FEATURE_DIRECT_OTA_ADMIN 0
#define MESH_DEBUG_PRINTLN(...) ((void)0)
#include "production_constants.inc"
#include "production_stream.inc"
+1
View File
@@ -109,6 +109,7 @@ bool profileIdleSleepAllowed() {
&& (!the_mesh.isDualRadioActive() || (profileIdleQueryAllowed() && the_mesh.profile_idle_allowed));
}
void serviceCommandInterfaces() { ++command_services; }
bool serviceCompanionHostKissUsb() { return false; }
void serviceUsbLoggingOnlySession() { ++usb_services; }
void serviceUsbTerminalHostSessionReset() { ++usb_services; }
void serviceUsbAsciiSessionDefault() { ++usb_services; }
+2
View File
@@ -141,6 +141,7 @@ struct RadioLibWrapper : mesh::Radio {
uint32_t rssi_latency=0;
unsigned rssi_reads=0;
bool _params_valid=true, _rx_ps_armed=true, _rx_hold_continuous=false;
bool _primary_receive_preempt=false;
bool _rx_boosted_gain_valid=false, _cur_rx_boosted_gain=false, _rx_boosted_gain_applied=false;
bool rx_gain_apply_ok=true, physical_rx_gain=false;
unsigned rx_gain_applies=0,rx_gain_order=0;
@@ -212,6 +213,7 @@ struct RadioLibWrapper : mesh::Radio {
#endif
virtual bool supportsRadioDeepInit() const { return deep_supported; }
uint8_t beginReconfigure();
void noteReconfigureAdmission(const char*, int16_t) {}
void endReconfigure(bool resume) { if (resume) startRecv(); }
bool isChipBusy() { return busy; }
bool isReceivingPacket() { return packet; }
+2
View File
@@ -269,9 +269,11 @@ namespace mesh { struct Utils {
'flash.health', # Read-only flash health diagnostics
'key.backup.transport', # Identity-backup transport capability
'mqtt', 'mqtt.running', # MQTT connection status
'ota.direct', # Direct USB OTA session diagnostics
'password', 'prv.key', # Local secret/identity reads
'public.key', # Read-only public identity
'pwrmgt.bootreason', 'role', # Boot/build facts
'radio.apply', # Pending/applied radio diagnostics
'radio.rxps.config', # Detail view of radio.rxps
'tx.status', # HIL-only applied-power verification
'wifi.status', 'wifi.ip', # Live WiFi link state
+8
View File
@@ -54,6 +54,14 @@ class CompanionOtaIncludeTest(unittest.TestCase):
(directory / "MyMesh.h").write_text(
'#pragma once\n#include "CompanionFeatures.h"\n'
)
# Host KISS declares its filesystem boundary in Full images. Keep
# that SDK type visible without pulling a board filesystem into
# this include-only test of the real OTA headers.
identity = directory / "helpers/IdentityStore.h"
identity.write_text(
"#pragma once\nclass IncludeTestFilesystem;\n"
"#define FILESYSTEM IncludeTestFilesystem\n"
)
if not (usb or ble):
# Prove that small/non-OTA images do not gain these dependencies.
for header in ("MotaSourceSerial.h", "OtaContext.h"):
+1
View File
@@ -68,6 +68,7 @@ static constexpr unsigned USB_HOST_LOSS_EDGE_MS = 100, USB_HOST_LOSS_GRACE_MS =
struct Stream {
int pending = 0;
int available() const { return pending; }
int peek() const { return pending > 0 ? 'x' : -1; }
int read() { return pending-- > 0 ? 'x' : -1; }
void print(const char*) {}
} usb_stream;
+5 -1
View File
@@ -21,6 +21,9 @@ class OtaFolderReadyTest(unittest.TestCase):
self.assertIsNotNone(match)
defines.append("#define " + name + " " + match[1])
source = (ROOT / "test/fixtures/ota_folder_ready.cpp").read_text(encoding="ascii")
# This folder-readiness fixture has no competing raw USB host session.
# Keep the real Arduino declaration visible to MotaSourceSerial.cpp.
source += "\nnamespace mesh { bool isUsbBinaryStreamOwned() { return false; } }\n"
source = source.replace("// @PRODUCTION_DEFINES@", "\n".join(defines))
ready = extract_braced(production, "if (ota::ota_ctx().manager.takeSourceReadyAnnouncement())")
source = source.replace("// @PRODUCTION_READY@", "" if missing_ready_trigger else ready)
@@ -38,7 +41,8 @@ class OtaFolderReadyTest(unittest.TestCase):
with self.subTest(definitions=definitions):
sources = ("OtaManager.cpp", "OtaProtocol.cpp", "MotaContainer.cpp", "MerkleTree.cpp", "MotaSourceSerial.cpp")
result = subprocess.run([compiler, "-std=c++17", "-O1", *sanitizers,
"-DENABLE_OTA=1", "-DOTA_SEEDER_ONLY=1", *["-D" + value for value in definitions],
"-DARDUINO=10819", "-DENABLE_OTA=1", "-DOTA_SEEDER_ONLY=1",
*["-D" + value for value in definitions],
"-I", str(ROOT / "src"), "-I", str(ROOT / "test/mocks"), str(cpp),
*[str(ROOT / "src/helpers/ota" / name) for name in sources],
str(ROOT / "src/Utils.cpp"), "-o", str(executable)], capture_output=True, text=True, timeout=90)
+3 -1
View File
@@ -73,6 +73,8 @@ static_assert(OTA_PROOFGEN_SCRATCH / 4 == 4095, "odd byte limit lost usable leaf
#include <helpers/ota/MotaSeederProto.h>
#include <helpers/ota/OtaByteIO.h>
using namespace mesh::ota;
// This serial-source capacity test has no competing USB stream owner.
namespace mesh { bool isUsbBinaryStreamOwned() { return false; } }
@FAKE@
class MtuSource : public SerialMotaSource {
public:
@@ -110,7 +112,7 @@ int main() {
built = subprocess.run([
os.environ.get("CXX", "g++"), "-std=c++17",
"-fsanitize=address,undefined", "-fno-sanitize-recover=all", "-fno-pie", "-no-pie",
"-DESP32_PLATFORM=1", "-DCOMPANION_RADIO_FULL=1",
"-DARDUINO=10819", "-DESP32_PLATFORM=1", "-DCOMPANION_RADIO_FULL=1",
"-I", str(ROOT / "src"), "-I", str(ROOT / "test/mocks"), str(source),
str(ROOT / "src/helpers/ota/MotaSourceSerial.cpp"), "-o", str(binary),
], capture_output=True, text=True, timeout=60)
@@ -171,6 +171,7 @@ class RP2040ApplicationCapabilityTests(unittest.TestCase):
set -euo pipefail
source build.sh
pio() { echo 'PlatformIO must not run' >&2; return 99; }
PIO_CONFIG_JSON='[]'
PIO_BUILD_DIR_OVERRIDE=@BUILD@
OUTPUT_DIR=@OUTPUT@
BUILD_PROFILE_FOR_TARGET=auto
+5 -3
View File
@@ -54,6 +54,7 @@ class T096MessageFooterProfileTest(unittest.TestCase):
for display_class in (
"SH1106Display",
"SSD1306Display",
"HeltecV4Display",
"ST7735Display",
"U8g2Display",
):
@@ -103,6 +104,7 @@ class T096MessageFooterProfileTest(unittest.TestCase):
for display_class in (
"SH1106Display",
"SSD1306Display",
"HeltecV4Display",
"ST7735Display",
"U8g2Display",
):
@@ -127,7 +129,7 @@ class T096MessageFooterProfileTest(unittest.TestCase):
self.assertNotIn("MESHCORE_HAS_REAL_DISPLAY", null_macros)
self.assertNotIn("MESHCORE_HAS_SMALL_DISPLAY", null_macros)
def test_v4_oled_is_compact_but_v4_tft_is_not(self):
def test_v4_display_aliases_share_the_unified_compact_driver(self):
profile = V4_PROFILE.read_text(encoding="utf-8")
usb = profile.split(
"[env:heltec_v4_companion_radio_usb_femon]", 1
@@ -136,9 +138,9 @@ class T096MessageFooterProfileTest(unittest.TestCase):
"[env:heltec_v4_tft_companion_radio_usb_femon]", 1
)[1].split("[", 1)[0]
self.assertIn("extends = heltec_v4_oled", usb)
self.assertIn("DISPLAY_CLASS=SSD1306Display", usb)
self.assertIn("DISPLAY_CLASS=HeltecV4Display", usb)
self.assertIn("extends = heltec_v4_tft", tft_usb)
self.assertIn("DISPLAY_CLASS=ST7789LCDDisplay", tft_usb)
self.assertIn("DISPLAY_CLASS=HeltecV4Display", tft_usb)
if __name__ == "__main__":
+14 -3
View File
@@ -43,13 +43,24 @@ class HwcdcLoggingWatchdogTests(unittest.TestCase):
cls.companion_methods = "\n".join(body(companion, signature) for signature in (
"static void clearUsbTerminalLine()", "static void cancelUsbSerialOperations()",
"static void resetUsbTerminalHostSession()", "static void serviceUsbTerminalHostSessionReset()"))
cls.ordinary_methods = ""
# There is no functional text backlog in the peripheral fake. Keep
# the actual role calls and subsequent session-completion gate below.
cls.ordinary_methods = "namespace mesh { void serviceUsbTerminalPort() {} }\n"
for role in ("simple_repeater", "simple_room_server", "simple_sensor"):
text = (ROOT / "examples" / role / "main.cpp").read_text()
start = text.index(" if (mesh::takeUsbTerminalSessionReset())")
# The reset body now contains nested feature guards. Extract the
# complete compound statement, preserving every guarded operation.
reset = body(text, " if (mesh::takeUsbTerminalSessionReset())")
start = text.index(" if (usb_ready) mesh::serviceUsbTerminalPort();")
stop = text.index("\n#endif", start)
completion = text[start:stop]
# This separate block follows optional KISS admission in the real
# loop. Do not silently truncate it if nested guards are added.
assert "#if" not in completion
assert "mesh::tryCompleteUsbTerminalSessionReset()" in completion
cls.ordinary_methods += ("static void service_" + role + "() {\n"
" bool usb_ready = true;\n" + text[start:stop] + "\n (void)usb_ready;\n}\n")
" bool usb_ready = true;\n" + reset + "\n" + completion
+ "\n (void)usb_ready;\n}\n")
cls.binaries = {(backport, ota): cls.compile_backend(backport, ota)
for backport in (0, 1) for ota in (False, True)}
+12
View File
@@ -30,6 +30,10 @@ namespace mesh {
struct Status {bool reader_connected=true, stalled=false;};
static Status status;
Status usbLoggingStatus(){return status;}
namespace hostkiss {
static bool usb_active=false;
bool usbActive(){return usb_active;}
}
}
struct Store {
bool dirty=false;
@@ -91,6 +95,7 @@ bool isUsbTerminalDataConnected(){return usb_connected;}
void reset(){
board=Board{};radio_driver=RadioDriver{};mesh::status=mesh::Status{};
mesh::hostkiss::usb_active=false;
the_mesh=RoleMesh{};
// Assignment copies the fixture's dependency pointers; point them back at
// the live fixture objects, not the temporary used to reset scalar state.
@@ -243,6 +248,13 @@ class UsbLoggingWatchdogRoleTests(unittest.TestCase):
the_mesh._serial=&the_mesh.serial;
'''
companion_checks = r'''
// A host KISS session owns the same physical USB transport regardless of
// the logging reader, terminal feature or ordinary Companion USB mode.
for(unsigned state=0;state<3;++state){
reset();mesh::status.reader_connected=state!=1;mesh::status.stalled=state==2;
mesh::hostkiss::usb_active=true;assert(!usbLoggingRecoverySafe(nullptr));
mesh::hostkiss::usb_active=false;assert(usbLoggingRecoverySafe(nullptr));
}
#if defined(ENABLE_USB_INTERFACE)
// A live binary client or buffered protocol transaction is always protected,
// even if the dedicated logging CDC is disconnected or its output is stuck.