The branch main has been updated by melifaro:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f3065e767def62d9b593dd7528c0eb121a7e1439

commit f3065e767def62d9b593dd7528c0eb121a7e1439
Author:     Alexander V. Chernikov <melif...@freebsd.org>
AuthorDate: 2023-05-15 10:44:20 +0000
Commit:     Alexander V. Chernikov <melif...@freebsd.org>
CommitDate: 2023-05-15 10:44:20 +0000

    testing: add support for using custom interfaces in pytest framework.
    
    MFC after:      2 weeks
---
 tests/atf_python/sys/net/vnet.py        | 21 +++++++++++++++------
 tests/atf_python/sys/netlink/netlink.py |  9 ++++++++-
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py
index c0e0a24f6687..a2884b0d7ce2 100644
--- a/tests/atf_python/sys/net/vnet.py
+++ b/tests/atf_python/sys/net/vnet.py
@@ -151,7 +151,7 @@ class VnetInterface(object):
 
 class IfaceFactory(object):
     INTERFACES_FNAME = "created_ifaces.lst"
-    AUTODELETE_TYPES = ("epair", "lo", "tap", "tun")
+    AUTODELETE_TYPES = ("epair", "gif", "gre", "lo", "tap", "tun")
 
     def __init__(self):
         self.file_name = self.INTERFACES_FNAME
@@ -386,8 +386,9 @@ class VnetTestTemplate(BaseTest):
         vnet_factory = VnetFactory(topology_id)
         for obj_name, obj_data in topo.items():
             if obj_name.startswith("if"):
-                epair_ifaces = iface_factory.create_iface(obj_name, "epair")
-                smap = SingleInterfaceMap(epair_ifaces, [])
+                iface_type = obj_data.get("type", "epair")
+                ifaces = iface_factory.create_iface(obj_name, iface_type)
+                smap = SingleInterfaceMap(ifaces, [])
                 iface_map[obj_name] = smap
         for obj_name, obj_data in topo.items():
             if obj_name.startswith("vnet"):
@@ -494,17 +495,25 @@ class VnetTestTemplate(BaseTest):
 class SingleVnetTestTemplate(VnetTestTemplate):
     IPV6_PREFIXES: List[str] = []
     IPV4_PREFIXES: List[str] = []
+    IFTYPE = "epair"
 
-    def setup_method(self, method):
+    def _setup_default_topology(self):
         topology = copy.deepcopy(
             {
                 "vnet1": {"ifaces": ["if1"]},
-                "if1": {"prefixes4": [], "prefixes6": []},
+                "if1": {"type": self.IFTYPE, "prefixes4": [], "prefixes6": []},
             }
         )
         for prefix in self.IPV6_PREFIXES:
             topology["if1"]["prefixes6"].append((prefix,))
         for prefix in self.IPV4_PREFIXES:
             topology["if1"]["prefixes4"].append((prefix,))
-        self.TOPOLOGY = topology
+        return topology
+
+    def setup_method(self, method):
+        if not getattr(self, "TOPOLOGY", None):
+            self.TOPOLOGY = self._setup_default_topology()
+        else:
+            names = self.TOPOLOGY.keys()
+            assert len([n for n in names if n.startswith("vnet")]) == 1
         super().setup_method(method)
diff --git a/tests/atf_python/sys/netlink/netlink.py 
b/tests/atf_python/sys/netlink/netlink.py
index 4bdefc2d5014..9b5906815489 100644
--- a/tests/atf_python/sys/netlink/netlink.py
+++ b/tests/atf_python/sys/netlink/netlink.py
@@ -302,7 +302,7 @@ class Nlsock:
         hdr = Nlmsghdr(
             nlmsg_type=NlConst.GENL_ID_CTRL,
             nlmsg_flags=NlmBaseFlags.NLM_F_REQUEST.value,
-            nlmsg_seq = self.helper.get_seq(),
+            nlmsg_seq=self.helper.get_seq(),
         )
         ghdr = GenlMsgHdr(cmd=GenlCtrlMsgType.CTRL_CMD_GETFAMILY.value)
         nla = NlAttrStr(GenlCtrlAttrType.CTRL_ATTR_FAMILY_NAME, family_name)
@@ -342,6 +342,13 @@ class Nlsock:
         self._data = self._data[hdr.nlmsg_len:]
         return self.parse_message(raw_msg)
 
+    def get_reply(self, tx_msg):
+        self.write_message(tx_msg)
+        while True:
+            rx_msg = self.read_message()
+            if tx_msg.nl_hdr.nlmsg_seq == rx_msg.nl_hdr.nlmsg_seq:
+                return rx_msg
+
 
 class NetlinkMultipartIterator(object):
     def __init__(self, obj, seq_number: int, msg_type):

Reply via email to