mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-01 06:27:29 +00:00
test: format all test scripts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import contextlib
|
||||
import logging
|
||||
@@ -11,6 +11,7 @@ from typing import Iterator
|
||||
|
||||
import pytest
|
||||
from pytest_embedded_idf import IdfDut
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
from scapy.all import Ether
|
||||
from scapy.all import raw
|
||||
|
||||
@@ -45,7 +46,7 @@ class EthTestIntf(object):
|
||||
logging.info('Use %s for testing', self.target_if)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def configure_eth_if(self, eth_type:int=0) -> Iterator[socket.socket]:
|
||||
def configure_eth_if(self, eth_type: int = 0) -> Iterator[socket.socket]:
|
||||
if eth_type == 0:
|
||||
eth_type = self.eth_type
|
||||
so = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(eth_type))
|
||||
@@ -60,14 +61,14 @@ class EthTestIntf(object):
|
||||
so.settimeout(10)
|
||||
payload = bytearray(1010)
|
||||
for i, _ in enumerate(payload):
|
||||
payload[i] = i & 0xff
|
||||
payload[i] = i & 0xFF
|
||||
eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=self.eth_type) / raw(payload)
|
||||
try:
|
||||
so.send(raw(eth_frame))
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
def recv_resp_poke(self, mac:str, i:int=0) -> None:
|
||||
def recv_resp_poke(self, mac: str, i: int = 0) -> None:
|
||||
eth_type_ctrl = self.eth_type + 1
|
||||
with self.configure_eth_if(eth_type_ctrl) as so:
|
||||
so.settimeout(30)
|
||||
@@ -76,13 +77,13 @@ class EthTestIntf(object):
|
||||
eth_frame = Ether(so.recv(60))
|
||||
except Exception as e:
|
||||
raise e
|
||||
if mac == eth_frame.src and eth_frame.load[0] == 0xfa:
|
||||
if mac == eth_frame.src and eth_frame.load[0] == 0xFA:
|
||||
if eth_frame.load[1] != i:
|
||||
raise RuntimeError('Missed Poke Packet')
|
||||
logging.info('Poke Packet received...')
|
||||
eth_frame.dst = eth_frame.src
|
||||
eth_frame.src = so.getsockname()[4]
|
||||
eth_frame.load = bytes.fromhex('fb') # POKE_RESP code
|
||||
eth_frame.load = bytes.fromhex('fb') # POKE_RESP code
|
||||
so.send(raw(eth_frame))
|
||||
break
|
||||
else:
|
||||
@@ -92,9 +93,9 @@ class EthTestIntf(object):
|
||||
else:
|
||||
raise RuntimeError('No Poke Packet!')
|
||||
|
||||
def traffic_gen(self, mac: str, pipe_rcv:connection.Connection) -> None:
|
||||
def traffic_gen(self, mac: str, pipe_rcv: connection.Connection) -> None:
|
||||
with self.configure_eth_if() as so:
|
||||
payload = bytes.fromhex('ff') # DUMMY_TRAFFIC code
|
||||
payload = bytes.fromhex('ff') # DUMMY_TRAFFIC code
|
||||
payload += bytes(1485)
|
||||
eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=self.eth_type) / raw(payload)
|
||||
try:
|
||||
@@ -103,7 +104,7 @@ class EthTestIntf(object):
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
def eth_loopback(self, mac: str, pipe_rcv:connection.Connection) -> None:
|
||||
def eth_loopback(self, mac: str, pipe_rcv: connection.Connection) -> None:
|
||||
with self.configure_eth_if(self.eth_type) as so:
|
||||
so.settimeout(30)
|
||||
try:
|
||||
@@ -158,7 +159,7 @@ def ethernet_l2_test(dut: IdfDut) -> None:
|
||||
raise RuntimeError('No broadcast received from expected DUT MAC addr')
|
||||
|
||||
for i in range(0, 1010):
|
||||
if eth_frame.load[i] != i & 0xff:
|
||||
if eth_frame.load[i] != i & 0xFF:
|
||||
raise RuntimeError('Packet content mismatch')
|
||||
dut.expect_unity_test_output()
|
||||
|
||||
@@ -172,7 +173,9 @@ def ethernet_l2_test(dut: IdfDut) -> None:
|
||||
# (there might be slight delay due to the RSTP execution)
|
||||
target_if.recv_resp_poke(mac=dut_mac)
|
||||
target_if.send_eth_packet('ff:ff:ff:ff:ff:ff') # broadcast frame
|
||||
target_if.send_eth_packet('01:00:5e:00:00:00') # IPv4 multicast frame (some SPI Eth modules filter multicast other than IP)
|
||||
target_if.send_eth_packet(
|
||||
'01:00:5e:00:00:00'
|
||||
) # IPv4 multicast frame (some SPI Eth modules filter multicast other than IP)
|
||||
target_if.send_eth_packet(mac=dut_mac) # unicast frame
|
||||
dut.expect_unity_test_output(extra_before=res.group(1))
|
||||
|
||||
@@ -191,7 +194,13 @@ def ethernet_l2_test(dut: IdfDut) -> None:
|
||||
target_if.recv_resp_poke(dut_mac, rx_i)
|
||||
# Start/stop under heavy Rx traffic
|
||||
pipe_rcv, pipe_send = Pipe(False)
|
||||
tx_proc = Process(target=target_if.traffic_gen, args=(dut_mac, pipe_rcv, ))
|
||||
tx_proc = Process(
|
||||
target=target_if.traffic_gen,
|
||||
args=(
|
||||
dut_mac,
|
||||
pipe_rcv,
|
||||
),
|
||||
)
|
||||
tx_proc.start()
|
||||
dut.expect_exact('Ethernet Stopped')
|
||||
pipe_send.send(0) # just send some dummy data
|
||||
@@ -219,7 +228,13 @@ def ethernet_heap_alloc_test(dut: IdfDut) -> None:
|
||||
)
|
||||
dut_mac = res.group(1).decode('utf-8')
|
||||
pipe_rcv, pipe_send = Pipe(False)
|
||||
loopback_proc = Process(target=target_if.eth_loopback, args=(dut_mac, pipe_rcv, ))
|
||||
loopback_proc = Process(
|
||||
target=target_if.eth_loopback,
|
||||
args=(
|
||||
dut_mac,
|
||||
pipe_rcv,
|
||||
),
|
||||
)
|
||||
loopback_proc.start()
|
||||
|
||||
target_if.recv_resp_poke(mac=dut_mac)
|
||||
@@ -233,55 +248,67 @@ def ethernet_heap_alloc_test(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- IP101 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.ethernet
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ip101',
|
||||
'release_ip101',
|
||||
'single_core_ip101'
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize('config', ['default_ip101', 'release_ip101', 'single_core_ip101'], indirect=True)
|
||||
@pytest.mark.flaky(reruns=3, reruns_delay=5)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_ethernet(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.ethernet
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ip101',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ip101',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_emac(dut: IdfDut) -> None:
|
||||
ethernet_int_emac_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
ethernet_heap_alloc_test(dut)
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_ip101
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ip101',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ip101',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_ip101(dut: IdfDut) -> None:
|
||||
ethernet_l2_test(dut)
|
||||
|
||||
|
||||
# ----------- IP101 ESP32P4 -----------
|
||||
@pytest.mark.esp32p4
|
||||
@pytest.mark.eth_ip101
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ip101_esp32p4',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ip101_esp32p4',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
|
||||
def test_esp32p4_ethernet(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
ethernet_l2_test(dut)
|
||||
|
||||
|
||||
@pytest.mark.esp32p4
|
||||
@pytest.mark.eth_ip101
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ip101_esp32p4',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ip101_esp32p4',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32p4'], indirect=['target'])
|
||||
def test_esp32p4_emac(dut: IdfDut) -> None:
|
||||
ethernet_int_emac_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -289,11 +316,15 @@ def test_esp32p4_emac(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- LAN8720 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_lan8720
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_lan8720',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_lan8720',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_lan8720(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -301,11 +332,15 @@ def test_esp_eth_lan8720(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- RTL8201 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_rtl8201
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_rtl8201',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_rtl8201',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_rtl8201(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -313,11 +348,15 @@ def test_esp_eth_rtl8201(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- KSZ8041 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_ksz8041
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ksz8041',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ksz8041',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_ksz8041(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -325,11 +364,15 @@ def test_esp_eth_ksz8041(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- DP83848 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_dp83848
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_dp83848',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_dp83848',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_dp83848(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -337,12 +380,16 @@ def test_esp_eth_dp83848(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- W5500 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_w5500
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_w5500',
|
||||
'poll_w5500',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_w5500',
|
||||
'poll_w5500',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_w5500(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -352,12 +399,16 @@ def test_esp_eth_w5500(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- KSZ8851SNL -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_ksz8851snl
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_ksz8851snl',
|
||||
'poll_ksz8851snl',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_ksz8851snl',
|
||||
'poll_ksz8851snl',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_ksz8851snl(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
@@ -367,12 +418,16 @@ def test_esp_eth_ksz8851snl(dut: IdfDut) -> None:
|
||||
|
||||
|
||||
# ----------- DM9051 -----------
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.eth_dm9051
|
||||
@pytest.mark.parametrize('config', [
|
||||
'default_dm9051',
|
||||
'poll_dm9051',
|
||||
], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default_dm9051',
|
||||
'poll_dm9051',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_esp_eth_dm9051(dut: IdfDut) -> None:
|
||||
ethernet_test(dut)
|
||||
dut.serial.hard_reset()
|
||||
|
Reference in New Issue
Block a user