|
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 |
|
@@ -182,6 +212,7 @@ def test_keywords(self):
|
182 | 212 | bufsize=zlib.DEF_BUF_SIZE),
|
183 | 213 | HAMLET_SCENE)
|
184 | 214 |
|
| 215 | + @skip_on_s390x |
185 | 216 | def test_speech128(self):
|
186 | 217 | # compress more data
|
187 | 218 | data = HAMLET_SCENE * 128
|
@@ -233,6 +264,7 @@ def test_64bit_compress(self, size):
|
233 | 264 |
|
234 | 265 | class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
|
235 | 266 | # Test compression object
|
| 267 | + @skip_on_s390x |
236 | 268 | def test_pair(self):
|
237 | 269 | # straightforward compress/decompress objects
|
238 | 270 | datasrc = HAMLET_SCENE * 128
|
|
0 commit comments