|
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
|
@@ -32,6 +33,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
|
32 | 33 | ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
|
33 | 34 |
|
34 | 35 |
|
| 36 | +# bpo-46623: When a hardware accelerator is used (currently only on s390x), |
| 37 | +# using different ways to compress data with zlib can produce different |
| 38 | +# compressed data. |
| 39 | +# |
| 40 | +# To simplify the skip condition, make the assumption that s390x always has an |
| 41 | +# accelerator, and nothing else has it. |
| 42 | +# Windows doesn't have os.uname() but it doesn't support s390x. |
| 43 | +HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x' |
| 44 | + |
| 45 | + |
35 | 46 | class VersionTestCase(unittest.TestCase):
|
36 | 47 |
|
37 | 48 | def test_library_version(self):
|
@@ -199,7 +210,10 @@ def test_speech128(self):
|
199 | 210 | # compress more data
|
200 | 211 | data = HAMLET_SCENE * 128
|
201 | 212 | x = zlib.compress(data)
|
202 |
| - self.assertEqual(zlib.compress(bytearray(data)), x) |
| 213 | + # With hardware acceleration, the compressed bytes |
| 214 | + # might not be identical. |
| 215 | + if not HW_ACCELERATED: |
| 216 | + self.assertEqual(zlib.compress(bytearray(data)), x) |
203 | 217 | for ob in x, bytearray(x):
|
204 | 218 | self.assertEqual(zlib.decompress(ob), data)
|
205 | 219 |
|
@@ -256,7 +270,10 @@ def test_pair(self):
|
256 | 270 | x1 = co.compress(data)
|
257 | 271 | x2 = co.flush()
|
258 | 272 | self.assertRaises(zlib.error, co.flush) # second flush should not work
|
259 |
| - self.assertEqual(x1 + x2, datazip) |
| 273 | + # With hardware acceleration, the compressed bytes might not |
| 274 | + # be identical. |
| 275 | + if not HW_ACCELERATED: |
| 276 | + self.assertEqual(x1 + x2, datazip) |
260 | 277 | for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
|
261 | 278 | dco = zlib.decompressobj()
|
262 | 279 | y1 = dco.decompress(v1 + v2)
|
|
0 commit comments