git: 63cc817adde5 - main - pf tests: deduplicate DelayedSend
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 28 May 2025 21:55:51 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=63cc817adde5aec0f6446e44c1eee0a7d5908dfd
commit 63cc817adde5aec0f6446e44c1eee0a7d5908dfd
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-05-26 13:34:06 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-05-28 21:40:37 +0000
pf tests: deduplicate DelayedSend
We had a few copies of the DelayedSend class around.
Introduce a python utils file (utils.py), move DelayedSend into that and use it
in each test that wants it.
Sponsored by: Rubicon Communications, LLC ("Netgate")
---
tests/sys/netpfil/pf/Makefile | 3 ++-
tests/sys/netpfil/pf/frag6.py | 15 +--------------
tests/sys/netpfil/pf/nat64.py | 15 +--------------
tests/sys/netpfil/pf/nat66.py | 15 +--------------
tests/sys/netpfil/pf/tcp.py | 17 +----------------
tests/sys/netpfil/pf/utils.py | 41 +++++++++++++++++++++++++++++++++++++++++
6 files changed, 47 insertions(+), 59 deletions(-)
diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile
index b6c7a2703b7a..d70631a9de53 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -81,7 +81,8 @@ ${PACKAGE}FILES+= \
pft_ether.py \
pft_read_ipfix.py \
rdr-srcport.py \
- utils.subr
+ utils.subr \
+ utils.py
${PACKAGE}FILESMODE_bsnmpd.conf= 0555
${PACKAGE}FILESMODE_CVE-2019-5597.py= 0555
diff --git a/tests/sys/netpfil/pf/frag6.py b/tests/sys/netpfil/pf/frag6.py
index de14fec528fd..0ed980f96fdd 100644
--- a/tests/sys/netpfil/pf/frag6.py
+++ b/tests/sys/netpfil/pf/frag6.py
@@ -1,24 +1,11 @@
import pytest
import logging
-import threading
-import time
import random
logging.getLogger("scapy").setLevel(logging.CRITICAL)
+from utils import DelayedSend
from atf_python.sys.net.tools import ToolsHelper
from atf_python.sys.net.vnet import VnetTestTemplate
-class DelayedSend(threading.Thread):
- def __init__(self, packet):
- threading.Thread.__init__(self)
- self._packet = packet
-
- self.start()
-
- def run(self):
- import scapy.all as sp
- time.sleep(1)
- sp.send(self._packet)
-
class TestFrag6(VnetTestTemplate):
REQUIRED_MODULES = ["pf", "dummymbuf"]
TOPOLOGY = {
diff --git a/tests/sys/netpfil/pf/nat64.py b/tests/sys/netpfil/pf/nat64.py
index e64b7bbd573b..32fd8f4245a1 100644
--- a/tests/sys/netpfil/pf/nat64.py
+++ b/tests/sys/netpfil/pf/nat64.py
@@ -28,23 +28,10 @@ import pytest
import selectors
import socket
import sys
-import threading
-import time
+from utils import DelayedSend
from atf_python.sys.net.tools import ToolsHelper
from atf_python.sys.net.vnet import VnetTestTemplate
-class DelayedSend(threading.Thread):
- def __init__(self, packet):
- threading.Thread.__init__(self)
- self._packet = packet
-
- self.start()
-
- def run(self):
- import scapy.all as sp
- time.sleep(1)
- sp.send(self._packet)
-
class TestNAT64(VnetTestTemplate):
REQUIRED_MODULES = [ "pf" ]
TOPOLOGY = {
diff --git a/tests/sys/netpfil/pf/nat66.py b/tests/sys/netpfil/pf/nat66.py
index f93512b5b99c..16b4ef3dd02b 100644
--- a/tests/sys/netpfil/pf/nat66.py
+++ b/tests/sys/netpfil/pf/nat66.py
@@ -29,23 +29,10 @@ import ipaddress
import pytest
import re
import socket
-import threading
-import time
+from utils import DelayedSend
from atf_python.sys.net.tools import ToolsHelper
from atf_python.sys.net.vnet import VnetTestTemplate
-class DelayedSend(threading.Thread):
- def __init__(self, packet):
- threading.Thread.__init__(self)
- self._packet = packet
-
- self.start()
-
- def run(self):
- import scapy.all as sp
- time.sleep(1)
- sp.send(self._packet)
-
class TestNAT66(VnetTestTemplate):
REQUIRED_MODULES = [ "pf" ]
TOPOLOGY = {
diff --git a/tests/sys/netpfil/pf/tcp.py b/tests/sys/netpfil/pf/tcp.py
index 49a9ef4e0e66..53e0658f419c 100644
--- a/tests/sys/netpfil/pf/tcp.py
+++ b/tests/sys/netpfil/pf/tcp.py
@@ -29,23 +29,10 @@ import pytest
import random
import socket
import selectors
-import threading
-import time
+from utils import DelayedSend
from atf_python.sys.net.tools import ToolsHelper
from atf_python.sys.net.vnet import VnetTestTemplate
-class DelayedSend(threading.Thread):
- def __init__(self, packet):
- threading.Thread.__init__(self)
- self._packet = packet
-
- self.start()
-
- def run(self):
- import scapy.all as sp
- time.sleep(1)
- sp.send(self._packet)
-
class TCPClient:
def __init__(self, src, dst, sport, dport, sp):
self.src = src
@@ -136,8 +123,6 @@ class TestTcp(VnetTestTemplate):
# Import in the correct vnet, so at to not confuse Scapy
import scapy.all as sp
- #time.sleep(30)
-
a = TCPClient("192.0.2.3", "192.0.2.2", 1234, 1234, sp)
a.connect()
a.send(b"foo")
diff --git a/tests/sys/netpfil/pf/utils.py b/tests/sys/netpfil/pf/utils.py
new file mode 100644
index 000000000000..3cd8278f7cf7
--- /dev/null
+++ b/tests/sys/netpfil/pf/utils.py
@@ -0,0 +1,41 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2025 Rubicon Communications, LLC (Netgate)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+import threading
+import time
+
+class DelayedSend(threading.Thread):
+ def __init__(self, packet):
+ threading.Thread.__init__(self)
+ self._packet = packet
+
+ self.start()
+
+ def run(self):
+ import scapy.all as sp
+ time.sleep(1)
+ sp.send(self._packet)
+