|
2 | 2 | fromtestimportsupport
|
3 | 3 | importbinascii
|
4 | 4 | importcopy
|
| 5 | +importos |
5 | 6 | importpickle
|
6 | 7 | importrandom
|
7 | 8 | importsys
|
@@ -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')andos.uname().machine=='s390x' |
| 42 | + |
| 43 | + |
33 | 44 | classVersionTestCase(unittest.TestCase):
|
34 | 45 |
|
35 | 46 | deftest_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 | +ifnotHW_ACCELERATED: |
| 208 | +self.assertEqual(zlib.compress(bytearray(data)),x) |
195 | 209 | forobinx,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 | +ifnotHW_ACCELERATED: |
| 268 | +self.assertEqual(x1+x2,datazip) |
252 | 269 | forv1,v2in ((x1,x2), (bytearray(x1),bytearray(x2))):
|
253 | 270 | dco=zlib.decompressobj()
|
254 | 271 | y1=dco.decompress(v1+v2)
|
|