Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BLE controller test #3097

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
20 changes: 19 additions & 1 deletion hil-test/tests/esp_wifi_ble_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {
// so if we don't get the expected response we'll timeout and fail
let mut buf = [0u8; 255];
loop {
let len = connector.read(&mut buf).unwrap();
let len = read_packet(&mut connector, &mut buf);
if len == 7 {
assert_eq!(buf[0], 4, "Expected packet type = 4 (EVENT)");
assert_eq!(buf[1], 14, "Expected event code = 14 (COMMAND_COMPLETE)");
Expand All @@ -91,3 +91,21 @@ mod tests {
}
}
}

fn read_packet(connector: &mut BleConnector, buf: &mut [u8]) -> usize {
// Read header
read_all(connector, &mut buf[..3]);

// Read payload
let payload_len = buf[2] as usize;
read_all(connector, &mut buf[3..][..payload_len]);

3 + payload_len
}

fn read_all(connector: &mut BleConnector, mut buf: &mut [u8]) {
while !buf.is_empty() {
let len = connector.read(buf).unwrap();
buf = &mut buf[len..];
}
}