|
1 | 1 | import unittest
|
2 | 2 | from test import support
|
3 | 3 | import binascii
|
| 4 | +import os |
4 | 5 | import pickle
|
5 | 6 | import random
|
6 | 7 | import sys
|
|
15 | 16 | hasattr(zlib.decompressobj(), "copy"),
|
16 | 17 | 'requires Decompress.copy()')
|
17 | 18 |
|
| 19 | +# bpo-46623: On s390x, when a hardware accelerator is used, using different |
| 20 | +# ways to compress data with zlib can produce different compressed data. |
| 21 | +# Simplified test_pair() code: |
| 22 | +# |
| 23 | +# def func1(data): |
| 24 | +# return zlib.compress(data) |
| 25 | +# |
| 26 | +# def func2(data) |
| 27 | +# co = zlib.compressobj() |
| 28 | +# x1 = co.compress(data) |
| 29 | +# x2 = co.flush() |
| 30 | +# return x1 + x2 |
| 31 | +# |
| 32 | +# On s390x if zlib uses a hardware accelerator, func1() creates a single |
| 33 | +# "final" compressed block whereas func2() produces 3 compressed blocks (the |
| 34 | +# last one is a final block). On other platforms with no accelerator, func1() |
| 35 | +# and func2() produce the same compressed data made of a single (final) |
| 36 | +# compressed block. |
| 37 | +# |
| 38 | +# Only the compressed data is different, the decompression returns the original |
| 39 | +# data: |
| 40 | +# |
| 41 | +# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data |
| 42 | +# |
| 43 | +# Make the assumption that s390x always has an accelerator to simplify the skip |
| 44 | +# condition. Windows doesn't have os.uname() but it doesn't support s390x. |
| 45 | +skip_on_s390x = unittest.skipIf( |
| 46 | + hasattr(os, 'uname') and |
| 47 | + os.uname().machine in ['s390x', 's390'], |
| 48 | + 'skipped on s390x') |
| 49 | + |
18 | 50 |
|
19 | 51 | class VersionTestCase(unittest.TestCase):
|
20 | 52 |
|
@@ -174,6 +206,7 @@ def test_keywords(self):
|
174 | 206 | bufsize=zlib.DEF_BUF_SIZE),
|
175 | 207 | HAMLET_SCENE)
|
176 | 208 |
|
| 209 | + @skip_on_s390x |
177 | 210 | def test_speech128(self):
|
178 | 211 | # compress more data
|
179 | 212 | data = HAMLET_SCENE * 128
|
@@ -225,6 +258,7 @@ def test_64bit_compress(self, size):
|
225 | 258 |
|
226 | 259 | class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
|
227 | 260 | # Test compression object
|
| 261 | + @skip_on_s390x |
228 | 262 | def test_pair(self):
|
229 | 263 | # straightforward compress/decompress objects
|
230 | 264 | datasrc = HAMLET_SCENE * 128
|
|
0 commit comments