From 9aa23a4320170e1ee1c921b6965811827f8d5bde Mon Sep 17 00:00:00 2001 From: Chen Yudong Date: Thu, 20 Jul 2023 22:06:03 +0800 Subject: [PATCH] ci(wifi): add more wifi runners sockets: add ipv6 only test --- .gitlab/ci/rules.yml | 30 ++++++++ .gitlab/ci/target-test.yml | 66 ++++++++++++++++ examples/protocols/.build-test-rules.yml | 23 ++---- .../protocols/icmp_echo/pytest_icmp_echo.py | 50 ++++++++---- examples/protocols/icmp_echo/sdkconfig.ci | 0 .../icmp_echo/sdkconfig.ci.c2_xtal26m | 2 + .../sockets/tcp_client/pytest_tcp_client.py | 6 ++ .../sockets/tcp_server/pytest_tcp_server.py | 77 ++++++++++++++++++- .../tcp_server/sdkconfig.ci.c2_xtal26m | 5 ++ ...{sdkconfig.ci.1 => sdkconfig.ci.ipv4_only} | 0 .../sockets/udp_client/pytest_udp_client.py | 6 ++ .../sockets/udp_server/pytest_udp_server.py | 6 ++ 12 files changed, 236 insertions(+), 35 deletions(-) create mode 100644 examples/protocols/icmp_echo/sdkconfig.ci create mode 100644 examples/protocols/icmp_echo/sdkconfig.ci.c2_xtal26m create mode 100644 examples/protocols/sockets/tcp_server/sdkconfig.ci.c2_xtal26m rename examples/protocols/sockets/tcp_server/{sdkconfig.ci.1 => sdkconfig.ci.ipv4_only} (100%) diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index 0246b5d992..a044fa637a 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -2579,6 +2579,21 @@ - <<: *if-dev-push changes: *patterns-target_test-adc +.rules:test:example_test-esp32c6-wifi: + rules: + - <<: *if-revert-branch + when: never + - <<: *if-protected + - <<: *if-label-build-only + when: never + - <<: *if-label-example_test + - <<: *if-label-example_test_esp32c6 + - <<: *if-label-target_test + - <<: *if-dev-push + changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-wifi + .rules:test:example_test-esp32h2: rules: - <<: *if-revert-branch @@ -2661,6 +2676,21 @@ - <<: *if-dev-push changes: *patterns-example_test-usb +.rules:test:example_test-esp32s2-wifi: + rules: + - <<: *if-revert-branch + when: never + - <<: *if-protected + - <<: *if-label-build-only + when: never + - <<: *if-label-example_test + - <<: *if-label-example_test_esp32s2 + - <<: *if-label-target_test + - <<: *if-dev-push + changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-wifi + .rules:test:example_test-esp32s3: rules: - <<: *if-revert-branch diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 877accfff4..9d199a24d4 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -298,6 +298,38 @@ pytest_examples_esp32s3_wifi_ap: - build_pytest_examples_esp32s3 tags: [ esp32s3, wifi_ap ] +pytest_examples_esp32s2_wifi_ap: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32s2-wifi + needs: + - build_pytest_examples_esp32s2 + tags: [ esp32s2, wifi_ap ] + +pytest_examples_esp32c2_wifi_ap: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c2-wifi + needs: + - build_pytest_examples_esp32c2 + tags: [ esp32c2, wifi_ap, xtal_40mhz ] + +pytest_examples_esp32c2_26m_wifi_ap: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c2-wifi + needs: + - build_pytest_examples_esp32c2 + tags: [ esp32c2, wifi_ap, xtal_26mhz ] + +pytest_examples_esp32c6_wifi_ap: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c6-wifi + needs: + - build_pytest_examples_esp32c6 + tags: [ esp32c6, wifi_ap ] + pytest_examples_esp32_wifi_router: extends: - .pytest_examples_dir_template @@ -321,6 +353,40 @@ pytest_examples_esp32s3_wifi_router: needs: - build_pytest_examples_esp32s3 tags: [ esp32s3, wifi_router ] + +pytest_examples_esp32s2_wifi_router: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32s2-wifi + needs: + - build_pytest_examples_esp32s2 + tags: [ esp32s2, wifi_router ] + +pytest_examples_esp32c2_wifi_router: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c2-wifi + needs: + - build_pytest_examples_esp32c2 + tags: [ esp32c2, wifi_router, xtal_40mhz ] + +pytest_examples_esp32c2_26m_wifi_router: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c2-wifi + needs: + - build_pytest_examples_esp32c2 + tags: [ esp32c2, wifi_router, xtal_26mhz ] + +pytest_examples_esp32c6_wifi_router: + extends: + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c6-wifi + needs: + - build_pytest_examples_esp32c6 + tags: [ esp32c6, wifi_router ] + + pytest_examples_esp32_wifi_iperf: extends: - .pytest_examples_dir_template diff --git a/examples/protocols/.build-test-rules.yml b/examples/protocols/.build-test-rules.yml index 8d680a8605..fe3b16e06f 100644 --- a/examples/protocols/.build-test-rules.yml +++ b/examples/protocols/.build-test-rules.yml @@ -78,9 +78,7 @@ examples/protocols/https_x509_bundle: examples/protocols/icmp_echo: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - temporary: true - reason: lack of runners + - if: SOC_WIFI_SUPPORTED != 1 examples/protocols/l2tap: disable_test: @@ -136,7 +134,6 @@ examples/protocols/sntp: temporary: true reason: the other targets are not tested yet - examples/protocols/sockets/non_blocking: disable_test: - if: IDF_TARGET != "esp32" @@ -145,31 +142,21 @@ examples/protocols/sockets/non_blocking: examples/protocols/sockets/tcp_client: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - temporary: true - reason: lack of runners + - if: SOC_WIFI_SUPPORTED != 1 enable: - if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux" - examples/protocols/sockets/tcp_server: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - temporary: true - reason: lack of runners - + - if: SOC_WIFI_SUPPORTED != 1 examples/protocols/sockets/udp_client: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - temporary: true - reason: lack of runners + - if: SOC_WIFI_SUPPORTED != 1 examples/protocols/sockets/udp_server: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - temporary: true - reason: lack of runners + - if: SOC_WIFI_SUPPORTED != 1 examples/protocols/static_ip: disable: diff --git a/examples/protocols/icmp_echo/pytest_icmp_echo.py b/examples/protocols/icmp_echo/pytest_icmp_echo.py index ccd331f2f4..cd00ff645e 100644 --- a/examples/protocols/icmp_echo/pytest_icmp_echo.py +++ b/examples/protocols/icmp_echo/pytest_icmp_echo.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import os @@ -8,21 +8,18 @@ from common_test_methods import get_env_config_variable from pytest_embedded import Dut -@pytest.mark.esp32 -@pytest.mark.esp32c3 -@pytest.mark.esp32s3 -@pytest.mark.wifi_ap -def test_protocols_icmp_echo(dut: Dut) -> None: - # get env config - sdkconfig_ssid = dut.app.sdkconfig.get('CONFIG_EXAMPLE_WIFI_SSID') - sdkconfig_pwd = dut.app.sdkconfig.get('CONFIG_EXAMPLE_WIFI_SSID') - env_name = 'wifi_ap' - ap_ssid = get_env_config_variable(env_name, 'ap_ssid', default=sdkconfig_ssid) - ap_password = get_env_config_variable(env_name, 'ap_password', default=sdkconfig_pwd) - ap_channel = get_env_config_variable(env_name, 'ap_channel', default=0) +def _run_test(dut: Dut) -> None: + if dut.app.sdkconfig.get('EXAMPLE_PROVIDE_WIFI_CONSOLE_CMD') is True: + dut.expect('esp>') + env_name = 'wifi_ap' + ap_ssid = get_env_config_variable(env_name, 'ap_ssid') + ap_password = get_env_config_variable(env_name, 'ap_password') + ap_channel = get_env_config_variable(env_name, 'ap_channel', default=0) + dut.write(f'wifi_connect {ap_ssid} {ap_password} -n {ap_channel}') + else: + # for local test may config ssid/password from menuconfig + pass - dut.expect('esp>') - dut.write(f'wifi_connect {ap_ssid} {ap_password} -n {ap_channel}') dut.expect('Got IPv4 event:', timeout=30) ping_dest = os.getenv('EXAMPLE_ICMP_SERVER', 'ci.espressif.cn') @@ -35,3 +32,26 @@ def test_protocols_icmp_echo(dut: Dut) -> None: dut.expect(r'5 packets transmitted, [2-5] received, \d{1,3}% packet loss') dut.write('') dut.expect('esp>') + + +@pytest.mark.esp32 +@pytest.mark.esp32c2 +@pytest.mark.esp32s2 +@pytest.mark.esp32c3 +@pytest.mark.esp32s3 +@pytest.mark.esp32c6 +@pytest.mark.wifi_ap +def test_protocols_icmp_echo(dut: Dut) -> None: + _run_test(dut) + + +@pytest.mark.esp32c2 +@pytest.mark.wifi_ap +@pytest.mark.xtal_26mhz +@pytest.mark.parametrize( + 'config, baud', [ + ('c2_xtal26m', '74880'), + ], indirect=True +) +def test_protocols_icmp_echo_esp32c2_26mhz(dut: Dut) -> None: + _run_test(dut) diff --git a/examples/protocols/icmp_echo/sdkconfig.ci b/examples/protocols/icmp_echo/sdkconfig.ci new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/protocols/icmp_echo/sdkconfig.ci.c2_xtal26m b/examples/protocols/icmp_echo/sdkconfig.ci.c2_xtal26m new file mode 100644 index 0000000000..172f022b67 --- /dev/null +++ b/examples/protocols/icmp_echo/sdkconfig.ci.c2_xtal26m @@ -0,0 +1,2 @@ +CONFIG_IDF_TARGET="esp32c2" +CONFIG_XTAL_FREQ_26=y diff --git a/examples/protocols/sockets/tcp_client/pytest_tcp_client.py b/examples/protocols/sockets/tcp_client/pytest_tcp_client.py index 6eaf0ba533..fa297269a5 100644 --- a/examples/protocols/sockets/tcp_client/pytest_tcp_client.py +++ b/examples/protocols/sockets/tcp_client/pytest_tcp_client.py @@ -22,8 +22,11 @@ PORT = 3333 @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_tcp_client_ipv4(dut: Dut) -> None: # Parse IP address of STA @@ -46,8 +49,11 @@ def test_examples_tcp_client_ipv4(dut: Dut) -> None: @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_tcp_client_ipv6(dut: Dut) -> None: # Parse IP address of STA diff --git a/examples/protocols/sockets/tcp_server/pytest_tcp_server.py b/examples/protocols/sockets/tcp_server/pytest_tcp_server.py index 0dd265101a..546dfc3dd7 100644 --- a/examples/protocols/sockets/tcp_server/pytest_tcp_server.py +++ b/examples/protocols/sockets/tcp_server/pytest_tcp_server.py @@ -4,6 +4,7 @@ import logging import time +import netifaces import pytest from common_test_methods import get_env_config_variable, get_my_interface_by_dest_ip from pytest_embedded import Dut @@ -22,8 +23,11 @@ MESSAGE = 'Data to ESP' @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_tcp_server_ipv4(dut: Dut) -> None: # Parse IP address of STA @@ -35,7 +39,35 @@ def test_examples_tcp_server_ipv4(dut: Dut) -> None: ap_password = get_env_config_variable(env_name, 'ap_password') dut.write(f'{ap_ssid} {ap_password}') ipv4 = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode() - print(f'Connected with IPv4={ipv4}') + logging.info(f'Connected with IPv4={ipv4}') + time.sleep(1) + + # test IPv4 + received = tcp_client(ipv4, PORT, MESSAGE) + if not received == MESSAGE: + raise + dut.expect(MESSAGE) + + +@pytest.mark.esp32c2 +@pytest.mark.wifi_router +@pytest.mark.xtal_26mhz +@pytest.mark.parametrize( + 'config, baud', [ + ('c2_xtal26m', '74880'), + ], indirect=True +) +def test_examples_tcp_server_ipv4_esp32c2_26mhz(dut: Dut) -> None: + # Parse IP address of STA + logging.info('Waiting to connect with AP') + if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True: + dut.expect('Please input ssid password:') + env_name = 'wifi_router' + ap_ssid = get_env_config_variable(env_name, 'ap_ssid') + ap_password = get_env_config_variable(env_name, 'ap_password') + dut.write(f'{ap_ssid} {ap_password}') + ipv4 = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode() + logging.info(f'Connected with IPv4={ipv4}') time.sleep(1) # test IPv4 @@ -46,8 +78,11 @@ def test_examples_tcp_server_ipv4(dut: Dut) -> None: @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_tcp_server_ipv6(dut: Dut) -> None: # Parse IP address of STA @@ -62,7 +97,7 @@ def test_examples_tcp_server_ipv6(dut: Dut) -> None: # expect all 8 octets from IPv6 (assumes it's printed in the long form) ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) ipv6 = dut.expect(ipv6_r, timeout=30)[0].decode() - print(f'Connected with IPv4={ipv4} and IPv6={ipv6}') + logging.info(f'Connected with IPv4={ipv4} and IPv6={ipv6}') time.sleep(1) interface = get_my_interface_by_dest_ip(ipv4) @@ -71,3 +106,41 @@ def test_examples_tcp_server_ipv6(dut: Dut) -> None: if not received == MESSAGE: raise dut.expect(MESSAGE) + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 +@pytest.mark.esp32c3 +@pytest.mark.esp32s3 +@pytest.mark.esp32c6 +@pytest.mark.wifi_router +def test_examples_tcp_server_ipv6_only(dut: Dut) -> None: + # Parse IP address of STA + logging.info('Waiting to connect with AP') + if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True: + dut.expect('Please input ssid password:') + env_name = 'wifi_router' + ap_ssid = get_env_config_variable(env_name, 'ap_ssid') + ap_password = get_env_config_variable(env_name, 'ap_password') + dut.write(f'{ap_ssid} {ap_password}') + # expect all 8 octets from IPv6 (assumes it's printed in the long form) + ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) + ipv6 = dut.expect(ipv6_r, timeout=30)[0].decode() + logging.info(f'Connected AP with IPv6={ipv6}') + time.sleep(5) + + # test IPv6, try all interfaces + for interface in netifaces.interfaces(): + try: + logging.info(f'[{interface}] Connect to tcp_server {ipv6}%{interface}') + received = tcp_client(f'{ipv6}%{interface}', PORT, MESSAGE) + except Exception: + # wrong interface + continue + if not received == MESSAGE: + raise AssertionError(f'Wrong data received ({received}/{MESSAGE})') + dut.expect(MESSAGE) + break + else: + raise AssertionError(f'Can not connect to tcp_server: {ipv6}') diff --git a/examples/protocols/sockets/tcp_server/sdkconfig.ci.c2_xtal26m b/examples/protocols/sockets/tcp_server/sdkconfig.ci.c2_xtal26m new file mode 100644 index 0000000000..8ae9b690a2 --- /dev/null +++ b/examples/protocols/sockets/tcp_server/sdkconfig.ci.c2_xtal26m @@ -0,0 +1,5 @@ +CONFIG_IDF_TARGET="esp32c2" +CONFIG_XTAL_FREQ_26=y +CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y +CONFIG_EXAMPLE_IPV4=y +CONFIG_EXAMPLE_IPV6=y diff --git a/examples/protocols/sockets/tcp_server/sdkconfig.ci.1 b/examples/protocols/sockets/tcp_server/sdkconfig.ci.ipv4_only similarity index 100% rename from examples/protocols/sockets/tcp_server/sdkconfig.ci.1 rename to examples/protocols/sockets/tcp_server/sdkconfig.ci.ipv4_only diff --git a/examples/protocols/sockets/udp_client/pytest_udp_client.py b/examples/protocols/sockets/udp_client/pytest_udp_client.py index 1701690572..6c14c88d7c 100644 --- a/examples/protocols/sockets/udp_client/pytest_udp_client.py +++ b/examples/protocols/sockets/udp_client/pytest_udp_client.py @@ -24,8 +24,11 @@ MAX_RETRIES = 3 @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_udp_client_ipv4(dut: Dut) -> None: # Parse IP address of STA @@ -55,8 +58,11 @@ def test_examples_udp_client_ipv4(dut: Dut) -> None: @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_udp_client_ipv6(dut: Dut) -> None: # Parse IP address of STA diff --git a/examples/protocols/sockets/udp_server/pytest_udp_server.py b/examples/protocols/sockets/udp_server/pytest_udp_server.py index 623a3d3a58..52ddcc775c 100644 --- a/examples/protocols/sockets/udp_server/pytest_udp_server.py +++ b/examples/protocols/sockets/udp_server/pytest_udp_server.py @@ -22,8 +22,11 @@ MAX_RETRIES = 3 @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_udp_server_ipv4(dut: Dut) -> None: # Parse IP address of STA @@ -50,8 +53,11 @@ def test_examples_udp_server_ipv4(dut: Dut) -> None: @pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32c2 @pytest.mark.esp32c3 @pytest.mark.esp32s3 +@pytest.mark.esp32c6 @pytest.mark.wifi_router def test_examples_udp_server_ipv6(dut: Dut) -> None: # Parse IP address of STA