pytest_usb_device_ncm.py 1.1 KB

12345678910111213141516171819202122232425
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: CC0-1.0
  3. import subprocess
  4. import time
  5. import pytest
  6. from pytest_embedded import Dut
  7. @pytest.mark.esp32s2
  8. @pytest.mark.usb_device
  9. def test_usb_device_ncm_example(dut: Dut) -> None:
  10. netif_mac = dut.expect(r'Network interface HW address: ([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})')
  11. netif_mac = netif_mac.group(1).decode('utf-8')
  12. dut.expect_exact('USB NCM and WiFi initialized and started')
  13. dut.expect_exact('Returned from app_main()')
  14. time.sleep(1) # Wait 1s for the network interface to appear
  15. out_bytes = subprocess.check_output('ifconfig', shell=True, timeout=5)
  16. out_str = out_bytes.decode('utf-8')
  17. print('expected network interface HW address: ', netif_mac)
  18. print('ifconfig command output:\n', out_str)
  19. if netif_mac in out_str:
  20. print("NCM device's MAC address {} was found in system network interfaces".format(netif_mac))
  21. else:
  22. raise AssertionError('NCM device not found in network interface list')