8000 [3.12] gh-125041: test_zlib: For s390x HW acceleration, only skip che… · python/cpython@cbd50a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbd50a4

Browse files
[3.12] gh-125041: test_zlib: For s390x HW acceleration, only skip checking the compressed bytes (GH-125042) (GH-125526)
(cherry picked from commit cc5a225) Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 90b1406 commit cbd50a4

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Lib/test/support/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,9 +2450,9 @@ def adjust_int_max_str_digits(max_digits):
24502450
else:
24512451
C_RECURSION_LIMIT = 10000
24522452

2453-
#Windows doesn't have os.uname() but it doesn't support s390x.
2454-
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
2455-
'skipped on s390x')
2453+
# Windows doesn't have os.uname() but it doesn't support s390x.
2454+
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
2455+
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
24562456

24572457
_BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({
24582458
# SRC_DIR/.git

Lib/test/test_zlib.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pickle
88
import random
99
import sys
10-
from test.support import bigmemtest, _1G, _4G, skip_on_s390x
10+
from test.support import bigmemtest, _1G, _4G, is_s390x
1111

1212

1313
zlib = import_helper.import_module('zlib')
@@ -34,8 +34,9 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
3434
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
3535

3636

37-
# bpo-46623: On s390x, when a hardware accelerator is used, using different
38-
# ways to compress data with zlib can produce different compressed data.
37+
# bpo-46623: When a hardware accelerator is used (currently only on s390x),
38+
# using different ways to compress data with zlib can produce different
39+
# compressed data.
3940
# Simplified test_pair() code:
4041
#
4142
# def func1(data):
@@ -58,8 +59,10 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
5859
#
5960
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
6061
#
61-
# Make the assumption that s390x always has an accelerator to simplify the skip
62-
# condition.
62+
# To simplify the skip condition, make the assumption that s390x always has an
63+
# accelerator, and nothing else has it.
64+
HW_ACCELERATED = is_s390x
65+
6366

6467
class VersionTestCase(unittest.TestCase):
6568

@@ -224,12 +227,14 @@ def test_keywords(self):
224227
bufsize=zlib.DEF_BUF_SIZE),
225228
HAMLET_SCENE)
226229

227-
@skip_on_s390x
228230
def test_speech128(self):
229231
# compress more data
230232
data = HAMLET_SCENE * 128
231233
x = zlib.compress(data)
232-
self.assertEqual(zlib.compress(bytearray(data)), x)
234+
# With hardware acceleration, the compressed bytes
235+
# might not be identical.
236+
if not HW_ACCELERATED:
237+
self.assertEqual(zlib.compress(bytearray(data)), x)
233238
for ob in x, bytearray(x):
234239
self.assertEqual(zlib.decompress(ob), data)
235240

@@ -276,7 +281,6 @@ def test_64bit_compress(self, size):
276281

277282
class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
278283
# Test compression object
279-
@skip_on_s390x
280284
def test_pair(self):
281285
# straightforward compress/decompress objects
282286
datasrc = HAMLET_SCENE * 128
@@ -287,7 +291,10 @@ def test_pair(self):
287291
x1 = co.compress(data)
288292
x2 = co.flush()
289293
self.assertRaises(zlib.error, co.flush) # second flush should not work
290-
self.assertEqual(x1 + x2, datazip)
294+
# With hardware acceleration, the compressed bytes might not
295+
# be identical.
296+
if not HW_ACCELERATED:
297+
self.assertEqual(x1 + x2, datazip)
291298
for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
292299
dco = zlib.decompressobj()
293300
y1 = dco.decompress(v1 + v2)
Lines changed: 3 additions & 0 deletions
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)
0