From 0f0c6211bf9265b616fc66d3dc4c6ad3b39f73b070024b1038fbcd9bda496099 Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Fri, 8 Oct 2021 06:54:26 +0000 Subject: [PATCH] - Update skip-BE-tests.patch so that it actually fixes things, instead of just skipping tests (gh#kbandla/dpkt#615). OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-dpkt?expand=0&rev=26 --- python-dpkt.changes | 6 ++ python-dpkt.spec | 2 +- skip-BE-tests.patch | 137 +++++++++++++++++++++++++++++++------------- 3 files changed, 104 insertions(+), 41 deletions(-) diff --git a/python-dpkt.changes b/python-dpkt.changes index 9d5c50c..d41bd36 100644 --- a/python-dpkt.changes +++ b/python-dpkt.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Oct 8 06:53:28 UTC 2021 - Matej Cepl + +- Update skip-BE-tests.patch so that it actually fixes things, + instead of just skipping tests (gh#kbandla/dpkt#615). + ------------------------------------------------------------------- Thu Oct 7 10:42:16 UTC 2021 - Matej Cepl diff --git a/python-dpkt.spec b/python-dpkt.spec index 3e0f979..063959f 100644 --- a/python-dpkt.spec +++ b/python-dpkt.spec @@ -26,7 +26,7 @@ Group: Development/Libraries/Python URL: https://github.com/kbandla/dpkt Source: https://github.com/kbandla/dpkt/archive/v%{version}.tar.gz # PATCH-FIX-UPSTREAM skip-BE-tests.patch gh#kbandla/dpkt#505 mcepl@suse.com -# Skip tests failing on BE architectures +# Adjust tests to work on BE machines, gh#kbandla/dpkt#615 Patch0: skip-BE-tests.patch BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} diff --git a/skip-BE-tests.patch b/skip-BE-tests.patch index f11c370..be6d420 100644 --- a/skip-BE-tests.patch +++ b/skip-BE-tests.patch @@ -1,73 +1,130 @@ --- - dpkt/loopback.py | 8 ++++++++ - dpkt/pcapng.py | 7 +++++++ - 2 files changed, 15 insertions(+) + dpkt/loopback.py | 24 +++++++++++++++++------- + dpkt/pcapng.py | 18 ++++++++++-------- + 2 files changed, 27 insertions(+), 15 deletions(-) --- a/dpkt/loopback.py +++ b/dpkt/loopback.py -@@ -3,6 +3,9 @@ +@@ -1,6 +1,9 @@ + # $Id: loopback.py 38 2007-03-17 03:33:16Z dugsong $ + # -*- coding: utf-8 -*- """Platform-dependent loopback header.""" ++ ++# https://wiki.wireshark.org/NullLoopback ++ from __future__ import absolute_import -+import sys -+from unittest import SkipTest -+ from . import dpkt - from . import ethernet - from . import ip -@@ -39,6 +42,8 @@ class Loopback(dpkt.Packet): +@@ -24,17 +27,23 @@ class Loopback(dpkt.Packet): + + def unpack(self, buf): + dpkt.Packet.unpack(self, buf) +- if self.family == 2: +- self.data = ip.IP(self.data) +- +- elif self.family == 0x02000000: ++ if self.family in (0x02, 0x02000000): + self.family = 2 + self.data = ip.IP(self.data) + +- elif self.family in (24, 28, 30): ++ elif self.family in (0x18, 0x18000000): ++ self.family = 24 + self.data = ip6.IP6(self.data) + +- elif self.family > 1500: ++ elif self.family in (0x1c, 0x1c000000): ++ self.family = 28 ++ self.data = ip6.IP6(self.data) ++ ++ elif self.family in (0x1e, 0x1e000000): ++ self.family = 30 ++ self.data = ip6.IP6(self.data) ++ ++ else: + self.data = ethernet.Ethernet(self.data) - def test_ethernet_unpack(): -+ if sys.byteorder == 'big': -+ raise SkipTest('This test is known to fail on big endian processors. gh#kbandla/dpkt#505') - buf = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x08\x00' +@@ -43,7 +52,7 @@ def test_ethernet_unpack(): hdr = b'\x00\x02\x00\x02' -@@ -61,6 +66,9 @@ def test_ip_unpack(): + lo = Loopback(hdr + buf) +- assert lo.family == 33554944 ++ assert lo.family in (0x02000200, 0x00020002) # little endian, big endian + assert isinstance(lo.data, ethernet.Ethernet) + assert lo.data.src == b'\x07\x08\t\n\x0b\x0c' + assert lo.data.dst == b'\x01\x02\x03\x04\x05\x06' +@@ -61,6 +70,7 @@ def test_ip_unpack(): def test_ip6_unpack(): -+ if sys.byteorder == 'big': -+ raise SkipTest('This test is known to fail on big endian processors. gh#kbandla/dpkt#505') + import struct buf = (b'\x60\x00\x00\x00\x00\x14\x06\x38\x26\x07\xf8\xb0\x40\x0c\x0c\x03\x00\x00\x00\x00\x00\x00' b'\x00\x1a\x20\x01\x04\x70\xe5\xbf\xde\xad\x49\x57\x21\x74\xe8\x2c\x48\x87') --- a/dpkt/pcapng.py +++ b/dpkt/pcapng.py -@@ -9,6 +9,7 @@ from __future__ import absolute_import - from struct import pack as struct_pack, unpack as struct_unpack - from time import time - import sys -+from unittest import SkipTest +@@ -888,6 +888,10 @@ def define_testdata(): + def shb_idb_epb_be(self): + return self.valid_shb_be, self.valid_idb_be, self.valid_epb_be - from . import dpkt - from .compat import BytesIO, intround -@@ -1118,6 +1119,8 @@ def test_idb_opt_err(): ++ @property ++ def shb_idb_epb(self): ++ return self.shb_idb_epb_le if sys.byteorder == 'little' else self.shb_idb_epb_be ++ + return TestData() - def test_custom_read_write(): - """Test a full pcapng file with 1 ICMP packet""" -+ if sys.byteorder == 'big': -+ raise SkipTest('This test is known to fail on big endian processors. gh#kbandla/dpkt#505') - buf = define_testdata().valid_pcapng - fobj = BytesIO(buf) -@@ -1162,6 +1165,8 @@ def test_custom_read_write(): +@@ -1138,14 +1142,12 @@ def test_custom_read_write(): + fobj.close() + # test pcapng customized writing +- if sys.byteorder == 'little': +- shb, idb, epb = define_testdata().shb_idb_epb_le +- else: +- shb, idb, epb = define_testdata().shb_idb_epb_be ++ shb, idb, epb = define_testdata().shb_idb_epb + + fobj = BytesIO() + writer = Writer(fobj, shb=shb, idb=idb) + writer.writepkt(epb, ts=1442984653.210838) ++ # .valid_pcapng buf was collected on a little endian system + assert fobj.getvalue() == buf + fobj.close() + +@@ -1163,7 +1165,7 @@ def test_custom_read_write(): def test_multi_idb_writer(): """Test writing multiple interface description blocks into pcapng and read it""" -+ if sys.byteorder == 'big': -+ raise SkipTest('This test is known to fail on big endian processors. gh#kbandla/dpkt#505') fobj = BytesIO() - shb, idb, epb = define_testdata().shb_idb_epb_le +- shb, idb, epb = define_testdata().shb_idb_epb_le ++ shb, idb, epb = define_testdata().shb_idb_epb -@@ -1189,6 +1194,8 @@ def test_writer_validate_instance(): - @pre_test + writer = Writer(fobj, shb=shb, idb=[idb, idb]) + writer.writepkt(epb) +@@ -1190,7 +1192,7 @@ def test_writer_validate_instance(): def test_writepkt_epb_ts(): """writepkt should assign ts_high/low for epb if they are 0""" -+ if sys.byteorder == 'big': -+ raise SkipTest('This test is known to fail on big endian processors. gh#kbandla/dpkt#505') global time - shb, idb, epb = define_testdata().shb_idb_epb_le +- shb, idb, epb = define_testdata().shb_idb_epb_le ++ shb, idb, epb = define_testdata().shb_idb_epb writer = Writer(fobj, shb=shb, idb=idb) # noqa + epb.ts_high = epb.ts_low = 0 + ts = 1454725786.526401 +@@ -1296,7 +1298,7 @@ def test_pcapng_block_unpack(): + + def test_epb_unpack(): + """EnhancedPacketBlock can only unpack data >64 bytes, the length of their header""" +- shb, idb, epb = define_testdata().shb_idb_epb_be ++ shb, idb, epb = define_testdata().shb_idb_epb + buf = b'quite-long-but-not-long-enough-at-least-32' + try: + epb.unpack(buf) +@@ -1306,7 +1308,7 @@ def test_epb_unpack(): + + def test_epb_unpack_length_mismatch(): + """Force calculated len to be 0 when unpacking epb, this should fail when unpacking""" +- shb, idb, epb = define_testdata().shb_idb_epb_be ++ shb, idb, epb = define_testdata().shb_idb_epb + + unpackme = bytes(epb) + unpackme = unpackme[:-4] + b'\x00' * 4