Skip to content

Commit bbe8756

Browse files
authored
[3.9] gh-125041: gh-90781: test_zlib: For s390x HW acceleration, skip checking the compressed bytes (GH-125042) (#125587)
This backports two commits: - GH-31096 skipped the tests unconditionally - GH-125042 skips only the possibly-failing assertion (cherry picked from commit d522856)
1 parent eb16397 commit bbe8756

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
@@ -2,6 +2,7 @@
22
from test import support
33
import binascii
44
import copy
5+
import os
56
import pickle
67
import random
78
import sys
@@ -30,6 +31,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
3031
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
3132

3233

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

3546
def test_library_version(self):
@@ -191,7 +202,10 @@ def test_speech128(self):
191202
# compress more data
192203
data = HAMLET_SCENE * 128
193204
x = zlib.compress(data)
194-
self.assertEqual(zlib.compress(bytearray(data)), x)
205+
# With hardware acceleration, the compressed bytes
206+
# might not be identical.
207+
if not HW_ACCELERATED:
208+
self.assertEqual(zlib.compress(bytearray(data)), x)
195209
for ob in x, bytearray(x):
196210
self.assertEqual(zlib.decompress(ob), data)
197211

@@ -248,7 +262,10 @@ def test_pair(self):
248262
x1 = co.compress(data)
249263
x2 = co.flush()
250264
self.assertRaises(zlib.error, co.flush) # second flush should not work
251-
self.assertEqual(x1 + x2, datazip)
265+
# With hardware acceleration, the compressed bytes might not
266+
# be identical.
267+
if not HW_ACCELERATED:
268+
self.assertEqual(x1 + x2, datazip)
252269
for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
253270
dco = zlib.decompressobj()
254271
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)