Fix Full Companion terminal diagnostics
This commit is contained in:
1 parent
e666bbc6a8
commit
4c93df9d57
7 files changed
+176
-9
No files matched your search
@@ -14,6 +14,7 @@ pio test -e native # all suites except KISS modem
|
||||
pio test -e native_kiss_modem # KISS modem suite
|
||||
pio test -e native -f test_webconfig_keys # a single suite
|
||||
python3 test/test_indicator_display_profile.py # Indicator RAM/scale contract
|
||||
python3 test/test_companion_terminal_profile.py # Companion CLI capability gates
|
||||
```
|
||||
|
||||
A green `[PASSED]` per suite means GoogleTest returned 0 (all assertions
|
||||
@@ -57,6 +58,7 @@ does not reflect the GoogleTest count -- run the built binary directly
|
||||
| `test_remote_cli_reply_cache` | `src/helpers/RemoteCliReplyCache.h`, `src/helpers/RemoteCliRequest.h`, `src/helpers/RemoteCliTimeout.h` | authenticated logical-request matching; bounded recent-reply history; backward-compatible retry identity; 300% response timeout; empty-response completion; on-air truncation and clearing |
|
||||
| `test_companion_frame_queue` | `src/helpers/CompanionFrameQueue.h`, `src/helpers/CompanionHardwareCommandCompat.h` | response/required/best-effort classification; reserved capacity; stable priority; safe eviction; message-waiting coalescing; command `0x42` framed-CLI disambiguation and deprecated hardware-alias mapping |
|
||||
| `test_companion_status_response` | `src/helpers/CompanionStatusResponse.h` | request-tag correlation and minimum status-response length, including rejection of the three-entry ACL payload that previously masqueraded as status |
|
||||
| `test_companion_terminal_diagnostics` | `src/helpers/CompanionTerminalDiagnostics.h` | bounded Full Companion ESP32 heap/PSRAM/offline-queue diagnostic formatting, including truthful no-PSRAM output |
|
||||
| `test_serial_mode_switch` | `src/helpers/ArduinoSerialInterface.cpp`, `src/helpers/MultiSerialInterface.h` | terminal/seeder control-sequence recognition, single-TTY logging transitions, and USB/TCP ownership; queued/atomic USB output under backpressure and short writes; partial-frame busy state; requester-affine replies, locked contact streams, and Bluetooth-only pairing routing |
|
||||
| `test_ble_tx_stall_watchdog` | `src/helpers/BleTxStallWatchdog.h` | exact BLE fragment progress; blocked-reply timeout; rollover-safe elapsed time; disconnect recovery retry and completion |
|
||||
| `test_ble_mota_control` | `src/helpers/BleMotaStream.h`, `CompanionMotaControl.h` | encrypted mOTA channel ring buffering, overflow fail-closed behavior, request gating, and strict rejection of injected or USB-ownership control commands |
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <helpers/CompanionTerminalDiagnostics.h>
|
||||
|
||||
TEST(CompanionTerminalDiagnostics, ReportsEveryEsp32MemoryField) {
|
||||
const mesh::CompanionMemoryDiagnostics diagnostics = {
|
||||
66244, 2516, 63428, 61004, 42812, 6442475, 8386055, 3, 512
|
||||
};
|
||||
char output[160] = {};
|
||||
|
||||
ASSERT_TRUE(mesh::formatCompanionMemoryDiagnostics(
|
||||
output, sizeof(output), diagnostics));
|
||||
EXPECT_STREQ(
|
||||
"Heap free=66244 min=2516 max=63428 int=61004/42812 "
|
||||
"PSRAM=6442475/8386055 queue=3/512",
|
||||
output);
|
||||
}
|
||||
|
||||
TEST(CompanionTerminalDiagnostics, TruthfullyReportsNoPsram) {
|
||||
const mesh::CompanionMemoryDiagnostics diagnostics = {
|
||||
104857, 98234, 90112, 104857, 90112, 0, 0, 0, 16
|
||||
};
|
||||
char output[160] = {};
|
||||
|
||||
ASSERT_TRUE(mesh::formatCompanionMemoryDiagnostics(
|
||||
output, sizeof(output), diagnostics));
|
||||
EXPECT_NE(nullptr, strstr(output, "PSRAM=0/0"));
|
||||
EXPECT_NE(nullptr, strstr(output, "queue=0/16"));
|
||||
}
|
||||
|
||||
TEST(CompanionTerminalDiagnostics, DetectsAReplyBufferThatIsTooSmall) {
|
||||
const mesh::CompanionMemoryDiagnostics diagnostics = {
|
||||
UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX,
|
||||
UINT32_MAX, UINT32_MAX, 512, 512
|
||||
};
|
||||
char output[24] = {};
|
||||
|
||||
EXPECT_FALSE(mesh::formatCompanionMemoryDiagnostics(
|
||||
output, sizeof(output), diagnostics));
|
||||
EXPECT_EQ('\0', output[sizeof(output) - 1]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
source = (root / "examples/companion_radio/MyMesh.cpp").read_text()
|
||||
features = (root / "examples/companion_radio/CompanionFeatures.h").read_text()
|
||||
|
||||
local_start = source.index("bool MyMesh::handleLocalControlCommand(")
|
||||
local_end = source.index("\n#if COMPANION_FEATURE_TEMP_RADIO\nvoid MyMesh::serviceTempRadio()", local_start)
|
||||
local = source[local_start:local_end]
|
||||
|
||||
assert local.count('strcmp(command, "board") == 0') == 1
|
||||
assert 'board.getManufacturerName()' in local
|
||||
assert re.search(
|
||||
r"#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS\s+"
|
||||
r'if \(strcmp\(command, "memory"\) == 0\).*?'
|
||||
r"formatCompanionMemoryDiagnostics.*?#endif",
|
||||
local,
|
||||
re.DOTALL,
|
||||
)
|
||||
assert "offline_queue_len" in local
|
||||
assert "getOfflineQueueCapacity()" in local
|
||||
|
||||
terminal_start = source.index("void MyMesh::handleTerminalCommand(")
|
||||
terminal_end = source.index("\nvoid MyMesh::enterCLIRescue()", terminal_start)
|
||||
terminal = source[terminal_start:terminal_end]
|
||||
assert 'terminalOutput().print(" board\\r\\n")' in terminal
|
||||
assert re.search(
|
||||
r"#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS\s+"
|
||||
r'terminalOutput\(\)\.print\(" memory\\r\\n"\);\s+#endif',
|
||||
terminal,
|
||||
)
|
||||
|
||||
# This compile-time contract prevents either the implementation or help entry
|
||||
# from leaking onto a non-ESP32 build merely because a recipe set the flag.
|
||||
assert re.search(
|
||||
r"#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS && !defined\(ESP32_PLATFORM\)\s+"
|
||||
r'#error "COMPANION_FEATURE_MEMORY_DIAGNOSTICS requires ESP32"',
|
||||
features,
|
||||
)
|
||||
|
||||
print("test_companion_terminal_profile: PASS")
|
||||
Reference in new issue
Block a user