|
3 | 3 | from test.support import import_helper
|
4 | 4 | import binascii
|
5 | 5 | import copy
|
| 6 | +import os |
6 | 7 | import pickle
|
7 | 8 | import random
|
8 | 9 | import sys
|
|
18 | 19 | hasattr(zlib.decompressobj(), "copy"),
|
19 | 20 | 'requires Decompress.copy()')
|
20 | 21 |
|
| 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 | + |
21 | 51 |
|
22 | 52 | class VersionTestCase(unittest.TestCase):
|
23 | 53 |
|
@@ -184,6 +214,7 @@ def test_keywords(self):
|
184 | 214 | bufsize=zlib.DEF_BUF_SIZE),
|
185 | 215 | HAMLET_SCENE)
|
186 | 216 |
|
| 217 | + @skip_on_s390x |
187 | 218 | def test_speech128(self):
|
188 | 219 | # compress more data
|
189 | 220 | data = HAMLET_SCENE * 128
|
@@ -237,6 +268,7 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
|
237 | 268 | # TODO: RUSTPYTHON
|
238 | 269 | @unittest.expectedFailure
|
239 | 270 | # Test compression object
|
| 271 | + @skip_on_s390x |
240 | 272 | def test_pair(self):
|
241 | 273 | # straightforward compress/decompress objects
|
242 | 274 | datasrc = HAMLET_SCENE * 128
|
@@ -853,6 +885,13 @@ def test_wbits(self):
|
853 | 885 | dco = zlib.decompressobj(32 + 15)
|
854 | 886 | self.assertEqual(dco.decompress(gzip), HAMLET_SCENE)
|
855 | 887 |
|
| 888 | + for wbits in (-15, 15, 31): |
| 889 | + with self.subTest(wbits=wbits): |
| 890 | + expected = HAMLET_SCENE |
| 891 | + actual = zlib.decompress( |
| 892 | + zlib.compress(HAMLET_SCENE, wbits=wbits), wbits=wbits |
| 893 | + ) |
| 894 | + self.assertEqual(expected, actual) |
856 | 895 |
|
857 | 896 | def choose_lines(source, number, seed=None, generator=random):
|
858 | 897 | """Return a list of number lines randomly chosen from the source"""
|
|
0 commit comments