Skip to content

Commit

Permalink
tests/multi_bluetooth/ble_irq_calls.py: Enhance test to test recursion.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Feb 15, 2024
1 parent cd66aa0 commit 866fc34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/multi_bluetooth/ble_irq_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@
ACCESSORY_SERVICE = (ACCESSORY_UUID, (STATE_CHARACTERISTIC,))


def recursive_function():
recursive_function()


def test_deep_calls(n):
if n > 0:
# Test that a few nested calls will succeed.
test_deep_calls(n - 1)
else:
# Test that a Python stack overflow is detected.
try:
recursive_function()
except RuntimeError:
print("test_deep_calls finished")


class Central:
def __init__(self):
self.done = False
Expand All @@ -79,6 +95,8 @@ def _ble_event_handler(self, event, data):
conn_handle, _, _ = data
self._conn_handle = conn_handle
ble.gattc_discover_services(self._conn_handle, ACCESSORY_UUID)
# Test deep Python calls from within this BLE IRQ handler.
test_deep_calls(5)

elif event == _IRQ_PERIPHERAL_DISCONNECT:
conn_handle, _, addr = data
Expand Down
1 change: 1 addition & 0 deletions tests/multi_bluetooth/ble_irq_calls.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _IRQ_CENTRAL_DISCONNECT
--- instance1 ---
central start
_IRQ_PERIPHERAL_CONNECT
test_deep_calls finished
_IRQ_GATTC_SERVICE_RESULT
service found: 3 UUID('a5a5a5a5-ffff-9999-1111-5a5a5a5a5a5a')
_IRQ_GATTC_SERVICE_DONE
Expand Down

0 comments on commit 866fc34

Please sign in to comment.