CI: update example sniffer test case
@@ -5,18 +5,11 @@ import pytest
from pytest_embedded import Dut
-@pytest.mark.esp32
-@pytest.mark.wifi_ap
-@pytest.mark.parametrize('config', [
- 'mem',
-], indirect=True)
-def test_examples_simple_sniffer(dut: Dut) -> None:
- sniffer_num = 9
- dut.expect('sniffer>')
+def _sniffer_packets_check(dut: Dut, packet_num: int) -> None:
dut.write('pcap --open -f simple-sniffer')
dut.expect('cmd_pcap: open file successfully')
- dut.write(f'sniffer -i wlan -c 2 -n {sniffer_num}')
- dut.expect(f'cmd_sniffer: {sniffer_num} packages will be captured')
+ dut.write(f'sniffer -i wlan -c 2 -n {packet_num}')
+ dut.expect(f'cmd_sniffer: {packet_num} packages will be captured')
dut.expect('cmd_sniffer: start WiFi promiscuous ok')
dut.expect('cmd_sniffer: stop promiscuous ok')
dut.write('pcap --summary -f simple-sniffer')
@@ -27,8 +20,7 @@ def test_examples_simple_sniffer(dut: Dut) -> None:
dut.expect(r'Minor Version: [0-9]+')
dut.expect(r'SnapLen: [0-9]+')
dut.expect(r'LinkType: [0-9]+')
- # Allow "save captured packet failed" twice
- for i in range(0, sniffer_num - 2):
+ for i in range(0, packet_num):
dut.expect(f'Packet {i}:')
dut.expect(r'Timestamp \(Seconds\): [0-9]+')
dut.expect(r'Timestamp \(Microseconds\): [0-9]+')
@@ -38,10 +30,21 @@ def test_examples_simple_sniffer(dut: Dut) -> None:
dut.expect(r'Frame Subtype:\s+\w+')
dut.expect(r'Destination:\s+\w+')
dut.expect(r'Source:\s+\w+')
- dut.expect(r'Pcap packet Number: [7-9]')
+ dut.expect(f'Pcap packet Number: {packet_num}')
dut.write('pcap --close -f simple-sniffer')
dut.expect('cmd_pcap: free memory successfully')
dut.expect('cmd_pcap: .pcap file close done')
+
+@pytest.mark.esp32
+@pytest.mark.wifi_ap
+@pytest.mark.parametrize('config', [
+ 'mem',
+], indirect=True)
+def test_examples_simple_sniffer(dut: Dut) -> None:
+ dut.expect('sniffer>')
+ # Sniffer multiple times with few packets
+ for _ in range(3):
+ _sniffer_packets_check(dut, 5)
dut.write('')
dut.expect('sniffer>')
