[3.12] gh-125041: test_zlib: For s390x HW acceleration, only skip checking the compressed bytes (GH-125042) (GH-125526)

(cherry picked from commit cc5a225cdc)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-10-16 14:44:37 +02:00 committed by GitHub
parent 90b1406b88
commit cbd50a4bdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 12 deletions

View file

@ -2450,9 +2450,9 @@ else:
else: else:
C_RECURSION_LIMIT = 10000 C_RECURSION_LIMIT = 10000
#Windows doesn't have os.uname() but it doesn't support s390x. # 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', is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
'skipped on s390x') skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
_BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({ _BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({
# SRC_DIR/.git # SRC_DIR/.git

View file

@ -7,7 +7,7 @@ import os
import pickle import pickle
import random import random
import sys import sys
from test.support import bigmemtest, _1G, _4G, skip_on_s390x from test.support import bigmemtest, _1G, _4G, is_s390x
zlib = import_helper.import_module('zlib') zlib = import_helper.import_module('zlib')
@ -34,8 +34,9 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple() ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
# bpo-46623: On s390x, when a hardware accelerator is used, using different # bpo-46623: When a hardware accelerator is used (currently only on s390x),
# ways to compress data with zlib can produce different compressed data. # using different ways to compress data with zlib can produce different
# compressed data.
# Simplified test_pair() code: # Simplified test_pair() code:
# #
# def func1(data): # def func1(data):
@ -58,8 +59,10 @@ ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
# #
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data # zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
# #
# Make the assumption that s390x always has an accelerator to simplify the skip # To simplify the skip condition, make the assumption that s390x always has an
# condition. # accelerator, and nothing else has it.
HW_ACCELERATED = is_s390x
class VersionTestCase(unittest.TestCase): class VersionTestCase(unittest.TestCase):
@ -224,12 +227,14 @@ class CompressTestCase(BaseCompressTestCase, unittest.TestCase):
bufsize=zlib.DEF_BUF_SIZE), bufsize=zlib.DEF_BUF_SIZE),
HAMLET_SCENE) HAMLET_SCENE)
@skip_on_s390x
def test_speech128(self): def test_speech128(self):
# compress more data # compress more data
data = HAMLET_SCENE * 128 data = HAMLET_SCENE * 128
x = zlib.compress(data) 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): for ob in x, bytearray(x):
self.assertEqual(zlib.decompress(ob), data) self.assertEqual(zlib.decompress(ob), data)
@ -276,7 +281,6 @@ class CompressTestCase(BaseCompressTestCase, unittest.TestCase):
class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase): class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
# Test compression object # Test compression object
@skip_on_s390x
def test_pair(self): def test_pair(self):
# straightforward compress/decompress objects # straightforward compress/decompress objects
datasrc = HAMLET_SCENE * 128 datasrc = HAMLET_SCENE * 128
@ -287,7 +291,10 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
x1 = co.compress(data) x1 = co.compress(data)
x2 = co.flush() x2 = co.flush()
self.assertRaises(zlib.error, co.flush) # second flush should not work 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))): for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
dco = zlib.decompressobj() dco = zlib.decompressobj()
y1 = dco.decompress(v1 + v2) y1 = dco.decompress(v1 + v2)

View file

@ -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.