Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions test/hitl/card.binary/test/test_card_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand All @@ -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);
}
Expand Down
Loading