From bc13cbef590d50b2312c2a476ad79a14be0b859e Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields (OpenClaw)" Date: Wed, 4 Mar 2026 18:34:53 +0000 Subject: [PATCH] test: derive max binary length dynamically from Notecard Remove the hardcoded per-target constants (R5_MAX_BINARY_LENGTH=130554, U5_MAX_BINARY_LENGTH=261110) and the get_expected_max_binary_length() helper that compared them against card.binary "max". The assertion against a hardcoded value caused test_get_max_binary_length to fail whenever the nightly Notecard firmware changed the reported max (e.g. 261110 -> 261114 on 2026-02-02), even though the SDK and the Notecard were both functioning correctly. The Notecard firmware is the authoritative source of truth for the maximum binary buffer size. Tests that follow test_get_max_binary_length already use the runtime-queried max_binary_length value; the equality assertion added no regression protection beyond what those downstream tests already provide. The minimum sanity check (max >= 1024) is retained. --- .../card.binary/test/test_card_binary.cpp | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/test/hitl/card.binary/test/test_card_binary.cpp b/test/hitl/card.binary/test/test_card_binary.cpp index 7d97fc6e..c9e41908 100644 --- a/test/hitl/card.binary/test/test_card_binary.cpp +++ b/test/hitl/card.binary/test/test_card_binary.cpp @@ -302,51 +302,19 @@ const BinaryTestArgs* currentTestArgs; RUN_AUX_SERIAL_ALL_BAUDRATES(imagename, image, LARGE_SIZE, LARGE_SIZE_NAME, testArgs, __VA_ARGS__); \ RUN_AUX_SERIAL_ALL_BAUDRATES(imagename, image, MAX_SIZE, MAX_SIZE_NAME, testArgs, __VA_ARGS__); -static const size_t R5_MAX_BINARY_LENGTH = 130554; -static const size_t U5_MAX_BINARY_LENGTH = 261110; - -size_t get_expected_max_binary_length() -{ - size_t ret = 0; - J* rsp = NoteRequestResponseWithRetry(NoteNewRequest("card.version"), 10); - if (rsp == nullptr) { - dbgSerial.println("No response to card.version."); - } else { - char *target = JGetString(JGetObject(rsp, "body"), "target"); - if (target == nullptr) { - dbgSerial.println("Failed to get target from card.version body."); - } else { - if (strcmp(target, "r5") == 0) { - ret = R5_MAX_BINARY_LENGTH; - } else if (strcmp(target, "u5") == 0) { - ret = U5_MAX_BINARY_LENGTH; - } else { - dbgSerial.print("Unrecognized target: "); - dbgSerial.println(target); - } - } - } - - JDelete(rsp); - - return ret; -} - /** * @brief Retrieves the maximum card.binary length. + * + * The maximum is read directly from the Notecard via `card.binary` and stored + * in `max_binary_length` for use by subsequent tests. No hardcoded expected + * value is asserted; the Notecard firmware is the source of truth. */ void test_get_max_binary_length() { - size_t expected_max_binary_length = 0; assert_initialize_notecard(NOTECARD_IF_I2C); AssertNoteBinaryReset(); - expected_max_binary_length = get_expected_max_binary_length(); - if (expected_max_binary_length == 0) { - TEST_FAIL_MESSAGE("Failed to determine max binary length."); - } - J* rsp = NoteRequestResponseWithRetry(NoteNewRequest("card.binary"), 10); J* max_item = nullptr; if (rsp==nullptr || !JIsNullString(rsp, "err") || !JIsNumber(max_item=JGetObjectItem(rsp, "max"))) { @@ -357,7 +325,6 @@ void test_get_max_binary_length() TEST_FAIL_MESSAGE("card.binary max is too small."); } max_binary_length = length; - TEST_ASSERT_EQUAL(expected_max_binary_length, max_binary_length); } JDelete(rsp); }