|
2 | 2 | from test import support |
3 | 3 | import binascii |
4 | 4 | import copy |
| 5 | +import os |
5 | 6 | import pickle |
6 | 7 | import random |
7 | 8 | import sys |
@@ -30,6 +31,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION): |
30 | 31 | ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple() |
31 | 32 |
|
32 | 33 |
|
| 34 | +# bpo-46623: When a hardware accelerator is used (currently only on s390x), |
| 35 | +# using different ways to compress data with zlib can produce different |
| 36 | +# compressed data. |
| 37 | +# |
| 38 | +# To simplify the skip condition, make the assumption that s390x always has an |
| 39 | +# accelerator, and nothing else has it. |
| 40 | +# Windows doesn't have os.uname() but it doesn't support s390x. |
| 41 | +HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x' |
| 42 | + |
| 43 | + |
33 | 44 | class VersionTestCase(unittest.TestCase): |
34 | 45 |
|
35 | 46 | def test_library_version(self): |
@@ -191,7 +202,10 @@ def test_speech128(self): |
191 | 202 | # compress more data |
192 | 203 | data = HAMLET_SCENE * 128 |
193 | 204 | x = zlib.compress(data) |
194 | | - self.assertEqual(zlib.compress(bytearray(data)), x) |
| 205 | + # With hardware acceleration, the compressed bytes |
| 206 | + # might not be identical. |
| 207 | + if not HW_ACCELERATED: |
| 208 | + self.assertEqual(zlib.compress(bytearray(data)), x) |
195 | 209 | for ob in x, bytearray(x): |
196 | 210 | self.assertEqual(zlib.decompress(ob), data) |
197 | 211 |
|
@@ -248,7 +262,10 @@ def test_pair(self): |
248 | 262 | x1 = co.compress(data) |
249 | 263 | x2 = co.flush() |
250 | 264 | self.assertRaises(zlib.error, co.flush) # second flush should not work |
251 | | - self.assertEqual(x1 + x2, datazip) |
| 265 | + # With hardware acceleration, the compressed bytes might not |
| 266 | + # be identical. |
| 267 | + if not HW_ACCELERATED: |
| 268 | + self.assertEqual(x1 + x2, datazip) |
252 | 269 | for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))): |
253 | 270 | dco = zlib.decompressobj() |
254 | 271 | y1 = dco.decompress(v1 + v2) |
|
0 commit comments