From b31b772e668f54ff2fb56109ad7f6101d628340b Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 29 Oct 2026 22:16:46 +0100 Subject: [PATCH] Delay remote ACK delivery independently in the BLE fixture --- lib/ble/tests/test_ble_transport.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ble/tests/test_ble_transport.c b/lib/ble/tests/test_ble_transport.c index b1630b02..046483c6 100644 --- a/lib/ble/tests/test_ble_transport.c +++ b/lib/ble/tests/test_ble_transport.c @@ -9,7 +9,7 @@ #define CHECK(v) do { if (!(v)) { fprintf(stderr, "FAIL line=%d: %s\n", __LINE__, #v); exit(1); } } while (0) struct fake_link { ble_link_id id, other; struct ble_backend* peer; uint8_t data[512]; size_t len; int pending; - enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id, ack_delivered; + enum ble_wire_channel channel; uint64_t ack_at; uint16_t ack_id, ack_delivered; int ack_held; }; struct ble_backend { struct ble_transport* owner; struct UASYNC* ua; void* task; int index, started; struct fake_link links[16]; }; static struct ble_backend* backends[3]; @@ -63,13 +63,18 @@ static void run(void* arg) { if (!b->started) { b->started = 1; ble_backend_status(b->owner, 1, "fake ready"); } for (int i = 0; i < 16; i++) { struct fake_link* f = &b->links[i]; if (!f->id) continue; + if (!hold_ack && f->ack_held) { + uint8_t ack[2] = {f->ack_id >> 8, f->ack_id}; f->ack_held = 0; f->ack_delivered = f->ack_id; + if (f->peer && slot(f->peer, f->other)) ble_backend_received(f->peer->owner, f->other, BLE_WIRE_ACK, ack, 2); + } if (!f->len) { f->len = 1; ble_backend_opened(b->owner, f->id, mtu); } - if (!f->pending || hold || (hold_ack && f->channel == BLE_WIRE_ACK)) continue; + if (!f->pending || hold) continue; ble_link_id id = f->id, other = f->other; struct ble_backend* peer = f->peer; uint8_t data[512]; size_t len = f->len; memcpy(data, f->data, len); f->pending = 0; int dropped = f->channel != BLE_WIRE_ACK && data[f->channel == BLE_WIRE_DATA ? 2 : 0] == 3 && drop && --drop == 0; - if (!dropped && peer && slot(peer, other)) { + if (hold_ack && f->channel == BLE_WIRE_ACK) f->ack_held = 1; + else if (!dropped && peer && slot(peer, other)) { if (f->channel == BLE_WIRE_ACK) f->ack_delivered = f->ack_id; ble_backend_received(peer->owner, other, f->channel, data, len); }