pytest_icmp_echo.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. import os
  4. import pytest
  5. from common_test_methods import get_env_config_variable
  6. from pytest_embedded import Dut
  7. def _run_test(dut: Dut) -> None:
  8. if dut.app.sdkconfig.get('EXAMPLE_PROVIDE_WIFI_CONSOLE_CMD') is True:
  9. dut.expect('esp>')
  10. env_name = 'wifi_ap'
  11. ap_ssid = get_env_config_variable(env_name, 'ap_ssid')
  12. ap_password = get_env_config_variable(env_name, 'ap_password')
  13. ap_channel = get_env_config_variable(env_name, 'ap_channel', default=0)
  14. dut.write(f'wifi_connect {ap_ssid} {ap_password} -n {ap_channel}')
  15. else:
  16. # for local test may config ssid/password from menuconfig
  17. pass
  18. dut.expect('Got IPv4 event:', timeout=30)
  19. ping_dest = os.getenv('EXAMPLE_ICMP_SERVER', 'ci.espressif.cn')
  20. dut.write('ping {} -c 5'.format(ping_dest))
  21. # expect at least two packets (there could be lost packets)
  22. ip = dut.expect(r'64 bytes from (\d+\.\d+\.\d+\.\d+) icmp_seq=\d ttl=\d+ time=\d+ ms')[1].decode()
  23. dut.expect(fr'64 bytes from {ip} icmp_seq=[2-5] ttl=\d+ time=')
  24. dut.expect(r'5 packets transmitted, [2-5] received, \d{1,3}% packet loss')
  25. dut.write('')
  26. dut.expect('esp>')
  27. @pytest.mark.esp32
  28. @pytest.mark.esp32c2
  29. @pytest.mark.esp32s2
  30. @pytest.mark.esp32c3
  31. @pytest.mark.esp32s3
  32. @pytest.mark.esp32c6
  33. @pytest.mark.wifi_ap
  34. def test_protocols_icmp_echo(dut: Dut) -> None:
  35. _run_test(dut)
  36. @pytest.mark.esp32c2
  37. @pytest.mark.wifi_ap
  38. @pytest.mark.xtal_26mhz
  39. @pytest.mark.parametrize(
  40. 'config, baud', [
  41. ('c2_xtal26m', '74880'),
  42. ], indirect=True
  43. )
  44. def test_protocols_icmp_echo_esp32c2_26mhz(dut: Dut) -> None:
  45. _run_test(dut)