diff --git a/examples/system/.build-test-rules.yml b/examples/system/.build-test-rules.yml index 77122a71d3..71511c74a8 100644 --- a/examples/system/.build-test-rules.yml +++ b/examples/system/.build-test-rules.yml @@ -52,16 +52,6 @@ examples/system/efuse: temporary: true reason: lack of runners -examples/system/esp_event/default_event_loop: - disable: - - if: IDF_TARGET == "esp32c2" - temporary: true - reason: target esp32c2 is not supported yet - disable_test: - - if: IDF_TARGET in ["esp32s2", "esp32s3"] - temporary: true - reason: lack of runners - examples/system/esp_timer: disable_test: - if: IDF_TARGET == "esp32c2" diff --git a/examples/system/esp_event/default_event_loop/README.md b/examples/system/esp_event/default_event_loop/README.md index 7891375321..59b20dc012 100644 --- a/examples/system/esp_event/default_event_loop/README.md +++ b/examples/system/esp_event/default_event_loop/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Default Event Loop Example diff --git a/examples/system/esp_event/default_event_loop/example_test.py b/examples/system/esp_event/default_event_loop/example_test.py deleted file mode 100644 index e53e13a6ef..0000000000 --- a/examples/system/esp_event/default_event_loop/example_test.py +++ /dev/null @@ -1,93 +0,0 @@ -from __future__ import print_function - -import ttfw_idf - -# Timer events -TIMER_EVENT_LIMIT = 3 - -TIMER_EXPIRY_HANDLING = 'TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed {} out of ' + str(TIMER_EVENT_LIMIT) + ' times' - -# Task events -TASK_ITERATION_LIMIT = 5 -TASK_UNREGISTRATION_LIMIT = 3 - -TASK_ITERATION_POST = 'TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, {} out of ' + str(TASK_ITERATION_LIMIT) -TASK_ITERATION_HANDLING = 'TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed {} times' - - -def _test_timer_events(dut): - dut.start_app() - - print('Checking timer events posting and handling') - - dut.expect('setting up') - dut.expect('starting event sources') - - print('Finished setup') - - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop') - print('Posted timer started event') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler') - print('Handled timer started event') - - for expiries in range(1, TIMER_EVENT_LIMIT + 1): - dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop') - print('Posted timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT)) - - if expiries >= TIMER_EVENT_LIMIT: - dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop') - print('Posted timer stopped event') - - dut.expect(TIMER_EXPIRY_HANDLING.format(expiries)) - dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler') - dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler') - - print('Handled timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT)) - - dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler') - dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source') - print('Handled timer stopped event') - - -def _test_iteration_events(dut): - dut.start_app() - - print('Checking iteration events posting and handling') - dut.expect('setting up') - dut.expect('starting event sources') - print('Finished setup') - - for iteration in range(1, TASK_ITERATION_LIMIT + 1): - dut.expect(TASK_ITERATION_POST.format(iteration)) - print('Posted iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) - - if iteration < TASK_UNREGISTRATION_LIMIT: - dut.expect(TASK_ITERATION_HANDLING.format(iteration)) - dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler') - elif iteration == TASK_UNREGISTRATION_LIMIT: - dut.expect_all('TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler', - 'TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler') - print('Unregistered handler at iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) - else: - dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler') - - print('Handled iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) - - dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source') - print('Deleted task event source') - - -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3']) -def test_default_event_loop_example(env, extra_data): - dut = env.get_dut('default_event_loop', 'examples/system/esp_event/default_event_loop') - - _test_iteration_events(dut) - _test_timer_events(dut) - - -if __name__ == '__main__': - test_default_event_loop_example() diff --git a/examples/system/esp_event/default_event_loop/pytest_esp_event_default.py b/examples/system/esp_event/default_event_loop/pytest_esp_event_default.py new file mode 100644 index 0000000000..507a4ba083 --- /dev/null +++ b/examples/system/esp_event/default_event_loop/pytest_esp_event_default.py @@ -0,0 +1,84 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import logging + +import pytest +from pytest_embedded import Dut + +# Timer events +TIMER_EVENT_LIMIT = 3 + +TIMER_EXPIRY_HANDLING = 'TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed {} out of ' + str(TIMER_EVENT_LIMIT) + ' times' + +# Task events +TASK_ITERATION_LIMIT = 5 +TASK_UNREGISTRATION_LIMIT = 3 + +TASK_ITERATION_POST = 'TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, {} out of ' + str(TASK_ITERATION_LIMIT) +TASK_ITERATION_HANDLING = 'TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed {} times' + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_default_event_loop_example_iteration_events(dut: Dut) -> None: + logging.info('Checking iteration events posting and handling') + dut.expect_exact('setting up') + dut.expect_exact('starting event sources') + logging.info('Finished setup') + + for iteration in range(1, TASK_ITERATION_LIMIT + 1): + dut.expect_exact(TASK_ITERATION_POST.format(iteration)) + logging.info('Posted iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) + + if iteration < TASK_UNREGISTRATION_LIMIT: + dut.expect_exact(TASK_ITERATION_HANDLING.format(iteration)) + dut.expect_exact('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler') + elif iteration == TASK_UNREGISTRATION_LIMIT: + dut.expect(['TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler', + 'TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler'], expect_all=True) + logging.info('Unregistered handler at iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) + else: + dut.expect_exact('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler') + + logging.info('Handled iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT)) + + dut.expect_exact('TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source') + logging.info('Deleted task event source') + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_default_event_loop_example_timer_events(dut: Dut) -> None: + logging.info('Checking timer events posting and handling') + + dut.expect_exact('setting up') + dut.expect_exact('starting event sources') + + logging.info('Finished setup') + + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop') + logging.info('Posted timer started event') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler') + logging.info('Handled timer started event') + + for expiries in range(1, TIMER_EVENT_LIMIT + 1): + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop') + logging.info('Posted timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT)) + + if expiries >= TIMER_EVENT_LIMIT: + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop') + logging.info('Posted timer stopped event') + + dut.expect_exact(TIMER_EXPIRY_HANDLING.format(expiries)) + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler') + + logging.info('Handled timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT)) + + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler') + dut.expect_exact('TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source') + logging.info('Handled timer stopped event') diff --git a/examples/system/select/example_test.py b/examples/system/select/pytest_select.py similarity index 50% rename from examples/system/select/example_test.py rename to examples/system/select/pytest_select.py index 1feff1e6c8..c09a176db1 100644 --- a/examples/system/select/example_test.py +++ b/examples/system/select/pytest_select.py @@ -1,39 +1,36 @@ -from __future__ import unicode_literals - +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import logging import os +from typing import List -import ttfw_idf -from tiny_test_fw import Utility +import pytest +from pytest_embedded import Dut -def get_socket_msgs(i): +def get_socket_msgs(i: int) -> List[str]: msg = 'Socket message S{}'.format(i) return ['uart_select_example: {} bytes were written to socket: {}'.format(len(msg), msg), 'uart_select_example: {} bytes were received through socket: {}'.format(len(msg), msg)] -def get_uart_msgs(i): +def get_uart_msgs(i: int) -> List[str]: msg = 'UART message U{}'.format(i) return ['uart_select_example: {} bytes were sent to UART1: {}'.format(len(msg), msg), 'uart_select_example: {} bytes were received through UART1: {}'.format(len(msg), msg)] -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3']) -def test_examples_select(env, extra_data): +@pytest.mark.esp32 +@pytest.mark.esp32c3 +@pytest.mark.generic +def test_examples_select(dut: Dut) -> None: - dut = env.get_dut('select', 'examples/system/select') - dut.start_app() - - dut.expect('cpu_start: Starting scheduler', timeout=30) + dut.expect_exact('cpu_start: Starting scheduler', timeout=30) exp_list = [] for i in range(1, 10): exp_list += get_socket_msgs(i) exp_list += get_uart_msgs(i) - Utility.console_log('Expecting:{}{}'.format(os.linesep, os.linesep.join(exp_list))) - dut.expect_all(*exp_list, timeout=60) - - -if __name__ == '__main__': - test_examples_select() + logging.info('Expecting:{}{}'.format(os.linesep, os.linesep.join(exp_list))) + dut.expect(exp_list, timeout=60, expect_all=True)