From 5c3bc247cb3caf3ea4fd5c1c75a111421cebd4ca Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 1 Dec 2021 11:32:50 +0800 Subject: [PATCH] test: use pytest for examples/custom_bootloader --- .gitlab/ci/build.yml | 7 ++++++ .gitlab/ci/target-test.yml | 13 +++++++++++ .../bootloader_hooks/example_test.py | 18 --------------- .../pytest_custom_bootloader_hooks.py | 15 ++++++++++++ .../bootloader_override/example_test.py | 23 ------------------- .../pytest_custom_bootloader_override.py | 21 +++++++++++++++++ pytest.ini | 2 ++ 7 files changed, 58 insertions(+), 41 deletions(-) delete mode 100644 examples/custom_bootloader/bootloader_hooks/example_test.py create mode 100644 examples/custom_bootloader/bootloader_hooks/pytest_custom_bootloader_hooks.py delete mode 100644 examples/custom_bootloader/bootloader_override/example_test.py create mode 100644 examples/custom_bootloader/bootloader_override/pytest_custom_bootloader_override.py diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml index 8b4121ac47..5ad9cc4c96 100644 --- a/.gitlab/ci/build.yml +++ b/.gitlab/ci/build.yml @@ -39,6 +39,13 @@ build_examples_pytest_esp32: script: - python tools/ci/build_pytest_apps.py --all-pytest-apps --under-dir examples --target esp32 --size-info $SIZE_INFO_LOCATION -vv +build_examples_pytest_esp32s2: + extends: + - .build_pytest_template + - .rules:build:example_test-esp32s2 + script: + - python tools/ci/build_pytest_apps.py --all-pytest-apps --under-dir examples --target esp32s2 --size-info $SIZE_INFO_LOCATION -vv + build_examples_pytest_esp32c3: extends: - .build_pytest_template diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 7723ff6668..e261620c08 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -28,6 +28,19 @@ example_test_pytest_esp32_generic: - ESP32 - Example_GENERIC +example_test_pytest_esp32s2_generic: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32s2 + needs: + - build_examples_pytest_esp32s2 + variables: + TARGET_MARKER: esp32s2 + ENV_MARKER: generic + tags: + - ESP32S2 + - Example_GENERIC + example_test_pytest_esp32c3_generic: extends: - .pytest_examples_dir_template diff --git a/examples/custom_bootloader/bootloader_hooks/example_test.py b/examples/custom_bootloader/bootloader_hooks/example_test.py deleted file mode 100644 index 9e7061c4e0..0000000000 --- a/examples/custom_bootloader/bootloader_hooks/example_test.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import print_function - -import ttfw_idf - - -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32s2', 'esp32c3']) -def test_custom_bootloader_hooks_example(env, _): # type: ignore - # Test with default build configurations - dut = env.get_dut('main', 'examples/custom_bootloader/bootloader_hooks') - dut.start_app() - - # Expect to read both hooks messages - dut.expect('This hook is called BEFORE bootloader initialization') - dut.expect('This hook is called AFTER bootloader initialization') - - -if __name__ == '__main__': - test_custom_bootloader_hooks_example() diff --git a/examples/custom_bootloader/bootloader_hooks/pytest_custom_bootloader_hooks.py b/examples/custom_bootloader/bootloader_hooks/pytest_custom_bootloader_hooks.py new file mode 100644 index 0000000000..f66bef07af --- /dev/null +++ b/examples/custom_bootloader/bootloader_hooks/pytest_custom_bootloader_hooks.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded.dut import Dut + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c3 +@pytest.mark.generic +def test_custom_bootloader_hooks_example(dut: Dut) -> None: + # Expect to read both hooks messages + dut.expect_exact('This hook is called BEFORE bootloader initialization') + dut.expect_exact('This hook is called AFTER bootloader initialization') diff --git a/examples/custom_bootloader/bootloader_override/example_test.py b/examples/custom_bootloader/bootloader_override/example_test.py deleted file mode 100644 index 104a828498..0000000000 --- a/examples/custom_bootloader/bootloader_override/example_test.py +++ /dev/null @@ -1,23 +0,0 @@ -from __future__ import print_function - -import ttfw_idf - - -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32s2', 'esp32c3']) -def test_custom_bootloader_impl_example(env, _): # type: ignore - # Test with default build configurations - dut = env.get_dut('main', 'examples/custom_bootloader/bootloader_override') - dut.start_app() - - # Expect to read a message from the custom bootloader - # This message is defined in the Kconfig file, retrieve it while deleting - # leading and trailing quotes (") - welcome_message = dut.app.get_sdkconfig()['CONFIG_EXAMPLE_BOOTLOADER_WELCOME_MESSAGE'].strip("\"") - dut.expect(welcome_message) - - # Expect to read a message from the user application - dut.expect('Application started!') - - -if __name__ == '__main__': - test_custom_bootloader_impl_example() diff --git a/examples/custom_bootloader/bootloader_override/pytest_custom_bootloader_override.py b/examples/custom_bootloader/bootloader_override/pytest_custom_bootloader_override.py new file mode 100644 index 0000000000..c851f1050f --- /dev/null +++ b/examples/custom_bootloader/bootloader_override/pytest_custom_bootloader_override.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded.dut import Dut +from pytest_embedded_idf.app import IdfApp + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c3 +@pytest.mark.generic +def test_custom_bootloader_impl_example(app: IdfApp, dut: Dut) -> None: + # Expect to read a message from the custom bootloader + # This message is defined in the Kconfig file, retrieve it while deleting + # leading and trailing quotes (") + welcome_message = app.sdkconfig['EXAMPLE_BOOTLOADER_WELCOME_MESSAGE'] + dut.expect_exact(welcome_message) + + # Expect to read a message from the user application + dut.expect_exact('Application started!') diff --git a/pytest.ini b/pytest.ini index e0793f2874..dc4d57cf97 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,6 +2,7 @@ # only the files with prefix `pytest_` would be recognized as pytest test scripts. python_files = pytest_*.py +# ignore PytestExperimentalApiWarning for record_xml_attribute addopts = --embedded-services esp,idf -W ignore::_pytest.warning_types.PytestExperimentalApiWarning @@ -9,6 +10,7 @@ addopts = markers = esp32: support esp32 target esp32s2: support esp32s2 target + esp32s3: support esp32s3 target esp32c3: support esp32c3 target generic: tests should be run on generic runners