From 866fc3447c7a685c6c04d6a03ee94083b8d0dd72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 10:16:18 +1100 Subject: [PATCH] tests/multi_bluetooth/ble_irq_calls.py: Enhance test to test recursion. Signed-off-by: Damien George --- tests/multi_bluetooth/ble_irq_calls.py | 18 ++++++++++++++++++ tests/multi_bluetooth/ble_irq_calls.py.exp | 1 + 2 files changed, 19 insertions(+) diff --git a/tests/multi_bluetooth/ble_irq_calls.py b/tests/multi_bluetooth/ble_irq_calls.py index c8c673daab..2717bd5f3d 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py +++ b/tests/multi_bluetooth/ble_irq_calls.py @@ -60,6 +60,22 @@ STATE_CHARACTERISTIC = ( 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 @@ -79,6 +95,8 @@ class Central: 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 diff --git a/tests/multi_bluetooth/ble_irq_calls.py.exp b/tests/multi_bluetooth/ble_irq_calls.py.exp index d655c507d3..993e6f79e8 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py.exp +++ b/tests/multi_bluetooth/ble_irq_calls.py.exp @@ -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