Omit unsupported tuning controls on integrated STM32WL radios

This commit is contained in:
mikecarper committed 2026-10-23 11:04:11 -07:00
1 parent 901a8c4cd5
commit c9de5c8350
7 files changed
+132 -1

No files matched your search

@@ -0,0 +1,37 @@
// Integrated STM32WL has no tunable transport or acknowledged fast retune
// cache. Its shared boot hook must not inspect an irrelevant saved record.
#define main existing_cli_main
#include "cli_test.cpp"
#undef main
int main() {
static_assert(MESH_RADIO_SWITCH_TUNING == 0, "Integrated STM32WL tuning must be absent");
MemoryFS fs;
Clock clock;
Radio radio;
const std::vector<uint8_t> record(24, 0x55);
fs.files["/radio_fast"] = record;
mesh::RadioProfileCLI::configureBootTuning(&fs, radio);
assert(fs.opened_paths.empty());
mesh::RadioProfileCLI cli;
cli.begin(&fs, &radio, &clock);
for (const auto& path : fs.opened_paths) assert(path.find("/radio_fast") != 0);
fs.opened_paths.clear();
cli.loop();
char reply[160];
for (const char* command : {"get radio.fast", "get radio.fast.spi", "get radio.fast.caps",
"set radio.fast on", "set radio.fast.spi 8"}) {
assert(!cli.handle(command, reply, sizeof(reply)));
}
assert(fs.opened_paths.empty());
assert(fs.files["/radio_fast"] == record);
assert(fs.files.size() == 1);
const auto capabilities = radio.switchTuningCapabilities();
assert(capabilities.flags == 0 && capabilities.spi_clocks == 0);
assert(!radio.configureBootSwitchTuning({}));
assert(radio.trySetSwitchTuning({}) == mesh::RadioParamApplyResult::FAILED);
// Existing radio2 configuration commands remain available.
assert(cli.handle("get radio2", reply, sizeof(reply)));
assert(!strncmp(reply, "> off", 5));
}
+59
View File
@@ -37,6 +37,65 @@ class RadioSwitchTuningCLITest(unittest.TestCase):
if role == 'simple_secure_chat':
self.assertLess(radio_init.start(), setup.index('fast_rng.begin('))
def test_capability_gate_only_defaults_off_for_integrated_stm32wl(self):
compiler = shutil.which('g++') or shutil.which('clang++')
self.assertIsNotNone(compiler)
for defines, expected in (((), 1), (('NRF52_PLATFORM',), 1), (('ESP32_PLATFORM',), 1),
(('RP2040_PLATFORM',), 1), (('STM32_PLATFORM',), 1),
(('STM32WLxx',), 1), (('STM32_PLATFORM', 'STM32WLxx'), 0),
(('STM32_PLATFORM', 'STM32WLxx', 'MESH_RADIO_SWITCH_TUNING=1'), 1)):
with self.subTest(defines=defines):
source = '#include <helpers/RadioSwitchTuning.h>\n'
source += f'static_assert(MESH_RADIO_SWITCH_TUNING == {expected}, "capability gate");\n'
built = subprocess.run([compiler, '-std=c++11', '-fsyntax-only', '-x', 'c++',
'-I', str(ROOT / 'src'), *['-D' + value for value in defines], '-'],
input=source, capture_output=True, text=True)
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
def test_integrated_stm32wl_omits_unsupported_controls_and_boot_storage_reads(self):
compiler = shutil.which('g++') or shutil.which('clang++')
self.assertIsNotNone(compiler)
with tempfile.TemporaryDirectory() as directory:
work = Path(directory)
helpers = work / 'helpers'
helpers.mkdir()
# Instrument the existing filesystem mock, rather than accepting
# an untouched file as proof that no startup read occurred.
mock = (ROOT / 'test/fixtures/radio_profiles/mocks/helpers/IdentityStore.h').read_text()
mock = mock.replace(' std::map<std::string, std::vector<uint8_t>> files;',
' std::map<std::string, std::vector<uint8_t>> files;\n'
' std::vector<std::string> opened_paths;')
mock = mock.replace(' File open(const char* path, const char* mode = "r", bool = false) {',
' File open(const char* path, const char* mode = "r", bool = false) {\n'
' opened_paths.push_back(path);')
mock = mock.replace(' File open(const char* path, const char* mode = "r", bool = false) {',
' File open(const char* path, int mode) { return open(path, mode ? "w" : "r"); }\n'
' File open(const char* path, const char* mode = "r", bool = false) {')
(helpers / 'IdentityStore.h').write_text(mock, encoding='ascii')
flags = [compiler, '-std=c++17', '-O2', '-Wall', '-Wextra', '-DSTM32_PLATFORM',
'-DSTM32WLxx', '-DLFS_ERR_NOENT=-2', '-I', str(work),
'-I', str(ROOT / 'test/fixtures/radio_profiles/mocks'),
'-I', str(ROOT / 'test/mocks'), '-I', str(ROOT / 'src')]
source = ROOT / 'src/helpers/RadioProfileCLI.cpp'
executable = work / 'unsupported'
built = subprocess.run(flags + [str(source), str(ROOT / 'test/fixtures/radio_profiles/'
'switch_tuning_unsupported_test.cpp'), '-o', str(executable)],
capture_output=True, text=True)
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
subprocess.run([str(executable)], check=True)
# Inspect real production objects. The inactive branch must omit
# both saved-file names and all parser/persistence entry points.
for enabled in (False, True):
obj = work / f'cli-{int(enabled)}.o'
override = ['-DMESH_RADIO_SWITCH_TUNING=1'] if enabled else []
subprocess.run(flags + override + ['-c', str(source), '-o', str(obj)],
check=True, capture_output=True, text=True)
raw = obj.read_bytes()
for marker in (b'/radio_fast', b'handleFastSettings', b'loadFastSettings',
b'saveFastSettings', b'validFastImage'):
self.assertEqual(marker in raw, enabled, marker)
self.assertIn(b'/radio_profiles', raw)
def test_saved_controls_and_failure_transactions(self):
compiler = shutil.which('g++') or shutil.which('clang++')
self.assertIsNotNone(compiler)