Skip to content

Commit 9475dc0

Browse files
authored
bpo-46623: Skip two test_zlib tests on s390x (GH-31096)
Skip test_pair() and test_speech128() of test_zlib on s390x since they fail if zlib uses the s390x hardware accelerator.
1 parent c9c178f commit 9475dc0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Lib/test/test_zlib.py

+32
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
@@ -18,6 +19,35 @@
1819
hasattr(zlib.decompressobj(), "copy"),
1920
'requires Decompress.copy()')
2021

22+
# bpo-46623: On s390x, when a hardware accelerator is used, using different
23+
# ways to compress data with zlib can produce different compressed data.
24+
# Simplified test_pair() code:
25+
#
26+
# def func1(data):
27+
# return zlib.compress(data)
28+
#
29+
# def func2(data)
30+
# co = zlib.compressobj()
31+
# x1 = co.compress(data)
32+
# x2 = co.flush()
33+
# return x1 + x2
34+
#
35+
# On s390x if zlib uses a hardware accelerator, func1() creates a single
36+
# "final" compressed block whereas func2() produces 3 compressed blocks (the
37+
# last one is a final block). On other platforms with no accelerator, func1()
38+
# and func2() produce the same compressed data made of a single (final)
39+
# compressed block.
40+
#
41+
# Only the compressed data is different, the decompression returns the original
42+
# data:
43+
#
44+
# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data
45+
#
46+
# Make the assumption that s390x always has an accelerator to simplify the skip
47+
# condition. Windows doesn't have os.uname() but it doesn't support s390x.
48+
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
49+
'skipped on s390x')
50+
2151

2252
class VersionTestCase(unittest.TestCase):
2353

@@ -182,6 +212,7 @@ def test_keywords(self):
182212
bufsize=zlib.DEF_BUF_SIZE),
183213
HAMLET_SCENE)
184214

215+
@skip_on_s390x
185216
def test_speech128(self):
186217
# compress more data
187218
data = HAMLET_SCENE * 128
@@ -233,6 +264,7 @@ def test_64bit_compress(self, size):
233264

234265
class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
235266
# Test compression object
267+
@skip_on_s390x
236268
def test_pair(self):
237269
# straightforward compress/decompress objects
238270
datasrc = HAMLET_SCENE * 128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Skip test_pair() and test_speech128() of test_zlib on s390x since they fail
2+
if zlib uses the s390x hardware accelerator. Patch by Victor Stinner.

0 commit comments

Comments
 (0)