8000 tests/multi_bluetooth: Improve event ordering handling. · micropython/micropython@44e5a86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44e5a86

Browse files
committed
tests/multi_bluetooth: Improve event ordering handling.
For _IRQ_GATTC_READ_DONE, we should wait for it to ensure that we receive it before we sent the write (this prevents an ordering race with the "gattc_write" vs the "_IRQ_GATTC_READ_DONE" line). For _IRQ_GATTC_WRITE_DONE, don't print it out because we wait for it anyway (so it will be confirmed to have been generated), and it can race with the concurrent notify or indicate event. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 80458e7 commit 44e5a86

File tree

7 files changed

+15
-4
lines changed

7 files changed

+15
-4
lines changed

tests/multi_bluetooth/ble_characteristic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def irq(event, data):
6565
elif event == _IRQ_GATTC_READ_DONE:
6666
print("_IRQ_GATTC_READ_DONE", data[-1])
6767
elif event == _IRQ_GATTC_WRITE_DONE:
68-
print("_IRQ_GATTC_WRITE_DONE", data[-1])
68+
if data[-1] != 0:
69+
# Don't print successful write done, we wait for this event anyway
70+
# (so it's definitely getting captured), and it may appear out of
71+
# order with the notify/indicate that arrives at the same time.
72+
print("_IRQ_GATTC_WRITE_DONE", data[-1])
6973
elif event == _IRQ_GATTC_NOTIFY:
7074
print("_IRQ_GATTC_NOTIFY", bytes(data[-1]))
7175
elif event == _IRQ_GATTC_INDICATE:
@@ -164,6 +168,7 @@ def instance1():
164168
print("gattc_read")
165169
ble.gattc_read(conn_handle, value_handle)
166170
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
171+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
167172

168173
# Write to the characteristic, which will trigger a notification.
169174
print("gattc_write")
@@ -174,6 +179,7 @@ def instance1():
174179
print("gattc_read") # Read the new value set immediately before notification.
175180
ble.gattc_read(conn_handle, value_handle)
176181
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
182+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
177183

178184
# Write to the characteristic, which will trigger a value-included notification.
179185
print("gattc_write")
@@ -184,6 +190,7 @@ def instance1():
184190
print("gattc_read") # Read value should be unchanged.
185191
ble.gattc_read(conn_handle, value_handle)
186192
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
193+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
187194

188195
# Write to the characteristic, which will trigger an indication.
189196
print("gattc_write")
@@ -194,6 +201,7 @@ def instance1():
194201
print("gattc_read") # Read the new value set immediately before indication.
195202
ble.gattc_read(conn_handle, value_handle)
196203
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
204+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
197205

198206
# Write-without-response, which will trigger another notification with that value.
199207
ble.gattc_write(conn_handle, value_handle, "central3", 0)

tests/multi_bluetooth/ble_characteristic.py.exp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ gattc_read
2222
_IRQ_GATTC_READ_RESULT b'periph0'
2323
_IRQ_GATTC_READ_DONE 0
2424
gattc_write
25-
_IRQ_GATTC_WRITE_DONE 0
2625
_IRQ_GATTC_NOTIFY b'periph1'
2726
gattc_read
2827
_IRQ_GATTC_READ_RESULT b'periph1'
2928
_IRQ_GATTC_READ_DONE 0
3029
gattc_write
31-
_IRQ_GATTC_WRITE_DONE 0
3230
_IRQ_GATTC_NOTIFY b'periph2'
3331
gattc_read
3432
_IRQ_GATTC_READ_RESULT b'central1'
3533
_IRQ_GATTC_READ_DONE 0
3634
gattc_write
37-
_IRQ_GATTC_WRITE_DONE 0
3835
_IRQ_GATTC_INDICATE b'periph3'
3936
gattc_read
4037
_IRQ_GATTC_READ_RESULT b'periph3'

tests/multi_bluetooth/ble_descriptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ def instance1():
151151
print("gattc_read characteristic")
152152
ble.gattc_read(conn_handle, value_handle)
153153
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
154+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
154155

155156
# Issue read of descriptor, should get initial value.
156157
print("gattc_read descriptor")
157158
ble.gattc_read(conn_handle, desc_handle)
158159
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
160+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
159161

160162
# Write-with-response to the characteristic.
161163
print("gattc_write characteristic")

tests/multi_bluetooth/ble_gap_device_name.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def instance1():
110110
print("gattc_read")
111111
ble.gattc_read(conn_handle, value_handle)
112112
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
113+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
113114

114115
# Disconnect from peripheral.
115116
print("gap_disconnect:", ble.gap_disconnect(conn_handle))

tests/multi_bluetooth/ble_gap_pair.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def instance1():
119119
print("gattc_read")
120120
ble.gattc_read(conn_handle, value_handle)
121121
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
122+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
122123

123124
# Disconnect from the peripheral.
124125
print("gap_disconnect:", ble.gap_disconnect(conn_handle))

tests/multi_bluetooth/ble_gap_pair_bond.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def instance1():
124124
print("gattc_read")
125125
ble.gattc_read(conn_handle, value_handle)
126126
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
127+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
127128

128129
# Disconnect from the peripheral.
129130
print("gap_disconnect:", ble.gap_disconnect(conn_handle))

tests/multi_bluetooth/ble_subscribe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def instance1():
191191
print("gattc_read")
192192
ble.gattc_read(conn_handle, value_handle)
193193
wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)
194+
wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)
194195

195196
# While the four states are active, all incoming notifications
196197
# and indications will be printed by the event handler. We

0 commit comments

Comments
 (0)
0