Skip to content

Commit

Permalink
pythongh-125041: test_zlib: For s390x HW acceleration, only skip chec…
Browse files Browse the repository at this point in the history
…king the compressed bytes (python#125042)

(cherry picked from commit cc5a225)
  • Loading branch information
encukou committed Oct 16, 2024
1 parent 8b275e7 commit 2819ae2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Lib/test/test_zlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()


# bpo-46623: On s390x, when a hardware accelerator is used, using different
# ways to compress data with zlib can produce different compressed data.
# bpo-46623: When a hardware accelerator is used (currently only on s390x),
# using different ways to compress data with zlib can produce different
# compressed data.
# Simplified test_pair() code:
#
# def func1(data):
Expand All @@ -58,10 +59,10 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
#
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
#
# Make the assumption that s390x always has an accelerator to simplify the skip
# condition. Windows doesn't have os.uname() but it doesn't support s390x.
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
'skipped on s390x')
# To simplify the skip condition, make the assumption that s390x always has an
# accelerator, and nothing else has it.
# Windows doesn't have os.uname() but it doesn't support s390x.
HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x'


class VersionTestCase(unittest.TestCase):
Expand Down Expand Up @@ -227,12 +228,14 @@ def test_keywords(self):
bufsize=zlib.DEF_BUF_SIZE),
HAMLET_SCENE)

@skip_on_s390x
def test_speech128(self):
# compress more data
data = HAMLET_SCENE * 128
x = zlib.compress(data)
self.assertEqual(zlib.compress(bytearray(data)), x)
# With hardware acceleration, the compressed bytes
# might not be identical.
if not HW_ACCELERATED:
self.assertEqual(zlib.compress(bytearray(data)), x)
for ob in x, bytearray(x):
self.assertEqual(zlib.decompress(ob), data)

Expand Down Expand Up @@ -279,7 +282,6 @@ def test_64bit_compress(self, size):

class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
# Test compression object
@skip_on_s390x
def test_pair(self):
# straightforward compress/decompress objects
datasrc = HAMLET_SCENE * 128
Expand All @@ -290,7 +292,10 @@ def test_pair(self):
x1 = co.compress(data)
x2 = co.flush()
self.assertRaises(zlib.error, co.flush) # second flush should not work
self.assertEqual(x1 + x2, datazip)
# With hardware acceleration, the compressed bytes might not
# be identical.
if not HW_ACCELERATED:
self.assertEqual(x1 + x2, datazip)
for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
dco = zlib.decompressobj()
y1 = dco.decompress(v1 + v2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Re-enable skipped tests for :mod:`zlib` on the s390x architecture: only skip
checks of the compressed bytes, which can be different between zlib's
software implementation and the hardware-accelerated implementation.

0 comments on commit 2819ae2

Please sign in to comment.