[V1,2/2] tests/tso: modify get_chksum_value_and_verify to improve the performance

Message ID 20220823055939.4186198-3-ke1.xu@intel.com (mailing list archive)
State Accepted
Headers
Series tests/tso: modify get_chksum_value_and_verify to fix a checksum-verify error and improve the performance |

Checks

Context Check Description
ci/Intel-dts-format-test success Testing OK
ci/Intel-dts-pylama-test success Testing OK
ci/Intel-dts-suite-test success Testing OK

Commit Message

Ke Xu Aug. 23, 2022, 5:59 a.m. UTC
  Function "get_chksum_value_and_verify" in test suite TSO case test_tso_tunneling
 is of low efficiency. Methods are wrongly used.

Duplicated call to method "packet.read_pcapfile" in this function will lengthen
 the packet sequence stored in "packet.pktgen.pkts", consuming more time when
 save pcap file. Duplicated call to method "packet.save_pcapfile" is also time
 consuming.

Method "pks.show" and "self.pks1[i].show" is not used as expected. "*.show" is
 used to print the packet object, not intended to return a string. Current code
 is actually getting a method object and using "str(*)" method to turn a method
 object to a string, this may fail when "*.show" method is updated. The packet
 information printing here is equivilant to "repr(pks)".

Signed-off-by: Ke Xu <ke1.xu@intel.com>
---
 tests/TestSuite_tso.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
  

Comments

Tu, Lijuan Sept. 2, 2022, 1:57 a.m. UTC | #1
On Tue, 23 Aug 2022 05:59:39 +0000, Ke Xu <ke1.xu@intel.com> wrote:
> Function "get_chksum_value_and_verify" in test suite TSO case test_tso_tunneling
>  is of low efficiency. Methods are wrongly used.
> 
> Duplicated call to method "packet.read_pcapfile" in this function will lengthen
>  the packet sequence stored in "packet.pktgen.pkts", consuming more time when
>  save pcap file. Duplicated call to method "packet.save_pcapfile" is also time
>  consuming.
> 
> Method "pks.show" and "self.pks1[i].show" is not used as expected. "*.show" is
>  used to print the packet object, not intended to return a string. Current code
>  is actually getting a method object and using "str(*)" method to turn a method
>  object to a string, this may fail when "*.show" method is updated. The packet
>  information printing here is equivilant to "repr(pks)".
> 
> Signed-off-by: Ke Xu <ke1.xu@intel.com>

Acked-by: Lijuan Tu <lijuan.tu@intel.com>
Series applied, thanks
  

Patch

diff --git a/tests/TestSuite_tso.py b/tests/TestSuite_tso.py
index ef63b7cf..a7d74ca3 100644
--- a/tests/TestSuite_tso.py
+++ b/tests/TestSuite_tso.py
@@ -147,22 +147,27 @@  class TestTSO(TestCase):
         self.pks = packet.read_pcapfile(dump_pcap, self.tester)
         for i in range(len(self.pks)):
             pks = self.pks[i]
-            out = pks.show
-            chksum_list = re.findall(r"chksum=(0x\w+)", str(out))
+            out = repr(pks)
+            chksum_list = re.findall(r"chksum=(0x\w+)", out)
             pks["IP"].chksum = None
-            if "VXLAN" in str(out):
+            if "VXLAN" in out:
                 pks["UDP"].chksum = None
                 pks["VXLAN"]["IP"].chksum = None
                 pks["VXLAN"]["TCP"].chksum = None
-            elif "GRE" in str(out):
+            elif "GRE" in out:
                 pks["GRE"]["IP"].chksum = None
                 pks["GRE"]["TCP"].chksum = None
-            packet.save_pcapfile(self.tester, filename=save_file)
-            self.pks1 = Packet().read_pcapfile(save_file, self.tester)
-            out1 = self.pks1[i].show
-            chksum_list1 = re.findall(r"chksum=(0x\w+)", str(out1))
-            self.tester.send_expect("rm -rf %s" % save_file, "#")
-            if self.nic in Nic_list and "VXLAN" in str(out):
+        packet.save_pcapfile(self.tester, filename=save_file)
+        self.pks = Packet().read_pcapfile(dump_pcap, self.tester)
+        self.pks1 = Packet().read_pcapfile(save_file, self.tester)
+        self.tester.send_expect("rm -rf %s" % save_file, "#")
+        for i in range(len(self.pks1)):
+            pks = self.pks[i]
+            out = repr(pks)
+            chksum_list = re.findall(r"chksum=(0x\w+)", out)
+            out1 = repr(self.pks1[i])
+            chksum_list1 = re.findall(r"chksum=(0x\w+)", out1)
+            if self.nic in Nic_list and "VXLAN" in out:
                 self.verify(
                     chksum_list[0] == chksum_list1[0]
                     and chksum_list[2] == chksum_list1[2]