test suite reviews and discussions
 help / color / mirror / Atom feed
From: Hongbo Li <hongbox.li@intel.com>
To: dts@dpdk.org
Cc: Hongbo Li <hongbox.li@intel.com>
Subject: [dts][PATCH V1] tests/TestSuite_ice_iavf_fdir:ensure that the environment can be cleaned up after an exception occurs in the case
Date: Mon, 14 Nov 2022 07:27:04 +0000	[thread overview]
Message-ID: <20221114072704.124179-1-hongbox.li@intel.com> (raw)

1.If testcase throws an exception, the vf will not be cleaned, and cause other cases to fail.
2.By adding finally statements, the case will clean up the test environment whether it passes or not.

Signed-off-by: Hongbo Li <hongbox.li@intel.com>
---
 tests/TestSuite_ice_iavf_fdir.py | 297 ++++++++++++++++---------------
 1 file changed, 149 insertions(+), 148 deletions(-)

diff --git a/tests/TestSuite_ice_iavf_fdir.py b/tests/TestSuite_ice_iavf_fdir.py
index d6ca832a..453b36cb 100644
--- a/tests/TestSuite_ice_iavf_fdir.py
+++ b/tests/TestSuite_ice_iavf_fdir.py
@@ -10283,166 +10283,167 @@ class TestICEIAVFFdir(TestCase):
         self.session_third.send_expect("ifconfig %s up" % self.pf1_intf, "# ", 15)
         time.sleep(1)
 
-        # send matched packets
-        self.tester.scapy_append(
-            'sendp([%s], iface="%s")' % (pkts["pf"][0], self.tester_iface0)
-        )
-        self.tester.scapy_append(
-            'sendp([%s], iface="%s")' % (pkts["pf"][1], self.tester_iface1)
-        )
-        self.tester.scapy_execute()
-        time.sleep(1)
-
-        out_pf0 = self.session_third.send_expect("ethtool -S %s" % self.pf0_intf, "# ")
-        self.verify(
-            "rx_queue_1_packets: 1" in out_pf0,
-            "the packet is not redirected to expected queue of pf0",
-        )
-        out_pf1 = self.session_third.send_expect("ethtool -S %s" % self.pf1_intf, "# ")
-        self.verify("rx_dropped: 1" in out_pf1, "the packet is not dropped pf1")
-
-        out_vf00 = self.send_pkts_getouput(pkts["matched"][0])
-        rfc.check_iavf_fdir_mark(
-            out_vf00, pkt_num=1, check_param={"port_id": 0, "queue": [2, 3]}, stats=True
-        )
-        out_vf01 = self.send_pkts_getouput(pkts["matched"][1])
-        rfc.check_iavf_fdir_mark(
-            out_vf01,
-            pkt_num=1,
-            check_param={"port_id": 1, "queue": 6, "mark_id": 0},
-            stats=True,
-        )
-
-        self.send_packets(pkts["matched"][2], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf10 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf10,
-            pkt_num=1,
-            check_param={"port_id": 0, "queue": 6, "mark_id": 1},
-            stats=True,
-        )
+        try:
+            # send matched packets
+            self.tester.scapy_append(
+                'sendp([%s], iface="%s")' % (pkts["pf"][0], self.tester_iface0)
+            )
+            self.tester.scapy_append(
+                'sendp([%s], iface="%s")' % (pkts["pf"][1], self.tester_iface1)
+            )
+            self.tester.scapy_execute()
+            time.sleep(1)
 
-        self.send_packets(pkts["matched"][3], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf11 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=True
-        )
+            out_pf0 = self.session_third.send_expect("ethtool -S %s" % self.pf0_intf, "# ")
+            self.verify(
+                "rx_queue_1_packets: 1" in out_pf0,
+                "the packet is not redirected to expected queue of pf0",
+            )
+            out_pf1 = self.session_third.send_expect("ethtool -S %s" % self.pf1_intf, "# ")
+            self.verify("rx_dropped: 1" in out_pf1, "the packet is not dropped pf1")
 
-        # send mismatched packets
-        out_vf00 = self.send_pkts_getouput(pkts["mismatched"][0])
-        rfc.check_iavf_fdir_mark(
-            out_vf00,
-            pkt_num=1,
-            check_param={"port_id": 0, "queue": [2, 3]},
-            stats=False,
-        )
-        out_vf01 = self.send_pkts_getouput(pkts["mismatched"][1])
-        rfc.check_iavf_fdir_mark(
-            out_vf01,
-            pkt_num=1,
-            check_param={"port_id": 1, "queue": 6, "mark_id": 0},
-            stats=False,
-        )
+            out_vf00 = self.send_pkts_getouput(pkts["matched"][0])
+            rfc.check_iavf_fdir_mark(
+                out_vf00, pkt_num=1, check_param={"port_id": 0, "queue": [2, 3]}, stats=True
+            )
+            out_vf01 = self.send_pkts_getouput(pkts["matched"][1])
+            rfc.check_iavf_fdir_mark(
+                out_vf01,
+                pkt_num=1,
+                check_param={"port_id": 1, "queue": 6, "mark_id": 0},
+                stats=True,
+            )
 
-        self.send_packets(pkts["mismatched"][2], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf10 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf10,
-            pkt_num=1,
-            check_param={"port_id": 0, "queue": 6, "mark_id": 1},
-            stats=False,
-        )
+            self.send_packets(pkts["matched"][2], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf10 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf10,
+                pkt_num=1,
+                check_param={"port_id": 0, "queue": 6, "mark_id": 1},
+                stats=True,
+            )
 
-        self.send_packets(pkts["mismatched"][3], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf11 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=False
-        )
+            self.send_packets(pkts["matched"][3], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf11 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=True
+            )
 
-        # flush all the rules
-        self.dut.send_expect("flow flush 0", "testpmd> ")
-        self.dut.send_expect("flow flush 1", "testpmd> ")
-        self.session_secondary.send_expect("flow flush 0", "testpmd> ")
-        self.session_secondary.send_expect("flow flush 1", "testpmd> ")
+            # send mismatched packets
+            out_vf00 = self.send_pkts_getouput(pkts["mismatched"][0])
+            rfc.check_iavf_fdir_mark(
+                out_vf00,
+                pkt_num=1,
+                check_param={"port_id": 0, "queue": [2, 3]},
+                stats=False,
+            )
+            out_vf01 = self.send_pkts_getouput(pkts["mismatched"][1])
+            rfc.check_iavf_fdir_mark(
+                out_vf01,
+                pkt_num=1,
+                check_param={"port_id": 1, "queue": 6, "mark_id": 0},
+                stats=False,
+            )
 
-        self.session_third.send_expect(
-            "ethtool -N %s delete %d" % (self.pf0_intf, int(m0.group(1))), "# "
-        )
-        self.session_third.send_expect(
-            "ethtool -N %s delete %d" % (self.pf1_intf, int(m1.group(1))), "# "
-        )
-        self.session_third.send_expect(
-            "ethtool -n %s" % (self.pf0_intf), "Total 0 rules"
-        )
-        self.session_third.send_expect(
-            "ethtool -n %s" % (self.pf1_intf), "Total 0 rules"
-        )
+            self.send_packets(pkts["mismatched"][2], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf10 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf10,
+                pkt_num=1,
+                check_param={"port_id": 0, "queue": 6, "mark_id": 1},
+                stats=False,
+            )
 
-        # send matched packets
-        self.tester.scapy_append(
-            'sendp([%s], iface="%s")' % (pkts["pf"][0], self.tester_iface0)
-        )
-        self.tester.scapy_append(
-            'sendp([%s], iface="%s")' % (pkts["pf"][1], self.tester_iface1)
-        )
-        self.tester.scapy_execute()
+            self.send_packets(pkts["mismatched"][3], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf11 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=False
+            )
 
-        out_pf0 = self.session_third.send_expect("ethtool -S %s" % self.pf0_intf, "# ")
-        self.verify("rx_queue_1_packets: 1" in out_pf0, "the rule is not destroyed")
-        out_pf1 = self.session_third.send_expect("ethtool -S %s" % self.pf1_intf, "# ")
-        self.verify("rx_dropped: 1" in out_pf1, "the packet is dropped by pf1")
+            # flush all the rules
+            self.dut.send_expect("flow flush 0", "testpmd> ")
+            self.dut.send_expect("flow flush 1", "testpmd> ")
+            self.session_secondary.send_expect("flow flush 0", "testpmd> ")
+            self.session_secondary.send_expect("flow flush 1", "testpmd> ")
 
-        # send mismatched packets
-        out_vf00 = self.send_pkts_getouput(pkts["matched"][0])
-        rfc.check_iavf_fdir_mark(
-            out_vf00,
-            pkt_num=1,
-            check_param={"port_id": 0, "queue": [2, 3]},
-            stats=False,
-        )
-        out_vf01 = self.send_pkts_getouput(pkts["matched"][1])
-        rfc.check_iavf_fdir_mark(
-            out_vf01,
-            pkt_num=1,
-            check_param={"port_id": 1, "queue": 6, "mark_id": 0},
-            stats=False,
-        )
+            self.session_third.send_expect(
+                "ethtool -N %s delete %d" % (self.pf0_intf, int(m0.group(1))), "# "
+            )
+            self.session_third.send_expect(
+                "ethtool -N %s delete %d" % (self.pf1_intf, int(m1.group(1))), "# "
+            )
+            self.session_third.send_expect(
+                "ethtool -n %s" % (self.pf0_intf), "Total 0 rules"
+            )
+            self.session_third.send_expect(
+                "ethtool -n %s" % (self.pf1_intf), "Total 0 rules"
+            )
 
-        self.send_packets(pkts["matched"][2], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf10 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf10,
-            pkt_num=1,
-            check_param={"port_id": 0, "queue": 6, "mark_id": 1},
-            stats=False,
-        )
+            # send matched packets
+            self.tester.scapy_append(
+                'sendp([%s], iface="%s")' % (pkts["pf"][0], self.tester_iface0)
+            )
+            self.tester.scapy_append(
+                'sendp([%s], iface="%s")' % (pkts["pf"][1], self.tester_iface1)
+            )
+            self.tester.scapy_execute()
+
+            out_pf0 = self.session_third.send_expect("ethtool -S %s" % self.pf0_intf, "# ")
+            self.verify("rx_queue_1_packets: 1" in out_pf0, "the rule is not destroyed")
+            out_pf1 = self.session_third.send_expect("ethtool -S %s" % self.pf1_intf, "# ")
+            self.verify("rx_dropped: 1" in out_pf1, "the packet is dropped by pf1")
+
+            # send mismatched packets
+            out_vf00 = self.send_pkts_getouput(pkts["matched"][0])
+            rfc.check_iavf_fdir_mark(
+                out_vf00,
+                pkt_num=1,
+                check_param={"port_id": 0, "queue": [2, 3]},
+                stats=False,
+            )
+            out_vf01 = self.send_pkts_getouput(pkts["matched"][1])
+            rfc.check_iavf_fdir_mark(
+                out_vf01,
+                pkt_num=1,
+                check_param={"port_id": 1, "queue": 6, "mark_id": 0},
+                stats=False,
+            )
 
-        self.send_packets(pkts["matched"][3], pf_id=1)
-        out_info = self.session_secondary.get_session_before(timeout=2)
-        out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
-        out_vf11 = out_info + out_pkt
-        self.session_secondary.send_expect("start", "testpmd> ")
-        rfc.check_iavf_fdir_mark(
-            out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=False
-        )
+            self.send_packets(pkts["matched"][2], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf10 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf10,
+                pkt_num=1,
+                check_param={"port_id": 0, "queue": 6, "mark_id": 1},
+                stats=False,
+            )
 
-        self.dut.close_session(self.session_secondary)
-        self.dut.close_session(self.session_third)
+            self.send_packets(pkts["matched"][3], pf_id=1)
+            out_info = self.session_secondary.get_session_before(timeout=2)
+            out_pkt = self.session_secondary.send_expect("stop", "testpmd> ")
+            out_vf11 = out_info + out_pkt
+            self.session_secondary.send_expect("start", "testpmd> ")
+            rfc.check_iavf_fdir_mark(
+                out_vf11, pkt_num=1, check_param={"port_id": 1, "drop": 1}, stats=False
+            )
+        finally:
+            self.dut.close_session(self.session_secondary)
+            self.dut.close_session(self.session_third)
 
     @skip_unsupported_pkg(["os default", "wireless"])
     def test_maxnum_128_profiles(self):
-- 
2.25.1


                 reply	other threads:[~2022-11-14  8:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221114072704.124179-1-hongbox.li@intel.com \
    --to=hongbox.li@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).