Skip to content

Commit 3c63d80

Browse files
authored
[3.10] gh-125041: gh-90781: test_zlib: For s390x HW acceleration, skip checking the compressed bytes (GH-125042) (#125585)
gh-125041: gh-90781: test_zlib: For s390x HW acceleration, skip checking the compressed bytes (GH-125042) This backports two commits: - GH-31096 skipped the tests unconditionally - GH-125042 skips only the possibly-failing assertion (cherry picked from commit cc5a225)
1 parent 6bbaab8 commit 3c63d80

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Lib/test/test_zlib.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from test.support import import_helper
44
import binascii
55
import copy
6+
import os
67
import pickle
78
import random
89
import sys
@@ -32,6 +33,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
3233
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
3334

3435

36+
# bpo-46623: When a hardware accelerator is used (currently only on s390x),
37+
# using different ways to compress data with zlib can produce different
38+
# compressed data.
39+
#
40+
# To simplify the skip condition, make the assumption that s390x always has an
41+
# accelerator, and nothing else has it.
42+
# Windows doesn't have os.uname() but it doesn't support s390x.
43+
HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x'
44+
45+
3546
class VersionTestCase(unittest.TestCase):
3647

3748
def test_library_version(self):
@@ -199,7 +210,10 @@ def test_speech128(self):
199210
# compress more data
200211
data = HAMLET_SCENE * 128
201212
x = zlib.compress(data)
202-
self.assertEqual(zlib.compress(bytearray(data)), x)
213+
# With hardware acceleration, the compressed bytes
214+
# might not be identical.
215+
if not HW_ACCELERATED:
216+
self.assertEqual(zlib.compress(bytearray(data)), x)
203217
for ob in x, bytearray(x):
204218
self.assertEqual(zlib.decompress(ob), data)
205219

@@ -256,7 +270,10 @@ def test_pair(self):
256270
x1 = co.compress(data)
257271
x2 = co.flush()
258272
self.assertRaises(zlib.error, co.flush) # second flush should not work
259-
self.assertEqual(x1 + x2, datazip)
273+
# With hardware acceleration, the compressed bytes might not
274+
# be identical.
275+
if not HW_ACCELERATED:
276+
self.assertEqual(x1 + x2, datazip)
260277
for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
261278
dco = zlib.decompressobj()
262279
y1 = dco.decompress(v1 + v2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Re-enable skipped tests for :mod:`zlib` on the s390x architecture: only skip
2+
checks of the compressed bytes, which can be different between zlib's
3+
software implementation and the hardware-accelerated implementation.

0 commit comments

Comments
 (0)