Files
MeshCore/test/test_radio_profile_clock.py
T
mikecarper ddf625e9d0 Fix packet, delivery, clock and radio stability regressions
Reject truncated anonymous reply paths and advert metadata before copying,
while preserving timestamp-only empty-password logins. Limit room posting to
read-write/admin ACL roles, retain inbox frames until the requesting transport
accepts them, and lock raw LittleFS traversal against concurrent writes.

Separate ISR event generations from main-loop radio state. Confirm RX/TX IRQs,
detach concrete wrapper callbacks safely, and discard inconsistent LR2021 FIFO
snapshots before rearming. Preserve bridge RX frames through packet-pool
exhaustion and bound ESP-NOW retries and missing-callback recovery. Screen RTC
register layouts without losing DS1307 startup, and ignore poisoned future
contact timestamps during clock bootstrap.

Keep the nRF52 loop stack at 8 KiB while reducing the OTA listing call chain
from 7,832 to 6,056 static bytes. Retain all target names through lossless Full
Companion compression and the canonical size optimizer. Preserve constrained
STM32 filesystems and bind corrected ESP32 UART/OLED budgets to source size
assertions. Document the separately measured preexisting W12 package limits.

Adapted for this branch from meshcore-dev/MeshCore PRs #3521, #3340, #3362,
#2062, #3503, #3038, #3534, #3544 and #3512.

Validation: 1,829 native tests; sanitized parser, inbox, LittleFS, ACL, clock,
RTC, IRQ/FIFO and bridge fault tests; 332 additional Companion cases; real
RAK4631 Full and both repeater profiles, G2 Full/standard, V3 Full and both
constrained STM32 release recipes. Radio-family compile coverage continues
separately; W12 full/portable package guards remain enforced.
2026-10-09 19:56:08 -07:00

75 lines
2.7 KiB
Python

"""Exercise the production profile clock on and off both nRF52 and other boards."""
from pathlib import Path
import os
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SOURCE = (ROOT / "src/helpers/radiolib/RadioLibWrappers.cpp").read_text()
CLOCK = "static void syncProfileClock(bool dual_profile) {" + SOURCE.split(
"static void syncProfileClock(bool dual_profile) {", 1
)[1].split("\nstatic\n#if defined(ESP8266)", 1)[0]
HARNESS = r'''
#include <cassert>
#include <cstdint>
struct FakeRtc {
uint32_t TASKS_STOP = 0, PRESCALER = 9, TASKS_CLEAR = 0, TASKS_START = 0;
uint32_t COUNTER = 0;
} rtc;
#define NRF_RTC2 (&rtc)
uint32_t micros() { return 1234; }
@CLOCK@
int main() {
assert(profileTimestamp(false) == 1234);
assert(rtc.TASKS_START == 0 && rtc.TASKS_STOP == 0);
assert(profileElapsedUs(12, 42, false) == 30);
#if defined(NRF52_PLATFORM)
rtc.COUNTER = 100;
assert(profileTimestamp(true) == 100);
assert(rtc.TASKS_STOP == 1 && rtc.PRESCALER == 0);
assert(rtc.TASKS_CLEAR == 1 && rtc.TASKS_START == 1);
rtc.TASKS_CLEAR = rtc.TASKS_START = rtc.TASKS_STOP = 0;
assert(profileTimestamp(true) == 100);
assert(rtc.TASKS_CLEAR == 0 && rtc.TASKS_START == 0 && rtc.TASKS_STOP == 0);
assert(profileElapsedUs(0, 32768, true) == 1000000);
assert(profileElapsedUs(0x00fffff0, 0x10, true) == 977);
syncProfileClock(false);
assert(rtc.TASKS_STOP == 1 && profileTimestamp(false) == 1234);
rtc.TASKS_CLEAR = rtc.TASKS_START = rtc.TASKS_STOP = 0;
syncProfileClock(false);
assert(rtc.TASKS_CLEAR == 0 && rtc.TASKS_START == 0 && rtc.TASKS_STOP == 0);
rtc.COUNTER = 200;
assert(profileTimestamp(true) == 200);
assert(rtc.TASKS_CLEAR == 1 && rtc.TASKS_START == 1);
#else
assert(profileTimestamp(true) == 1234);
assert(profileElapsedUs(12, 42, true) == 30);
assert(rtc.TASKS_START == 0 && rtc.TASKS_STOP == 0);
#endif
}
'''
class ProfileClockTest(unittest.TestCase):
def test_clock_selection_and_lifecycle(self):
with tempfile.TemporaryDirectory() as folder:
cpp = Path(folder) / "test.cpp"
exe = Path(folder) / "test.exe"
cpp.write_text(HARNESS.replace("@CLOCK@", CLOCK))
for defines in ([], ["-DNRF52_PLATFORM=1"]):
result = subprocess.run(
[os.environ.get("CXX", "g++"), "-std=c++17", "-Wall", "-Wextra",
"-Werror", *defines, str(cpp), "-o", str(exe)],
capture_output=True, text=True,
)
self.assertEqual(result.returncode, 0, result.stderr)
result = subprocess.run([str(exe)], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
if __name__ == "__main__":
unittest.main()