]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] gh-125041: gh-90781: test_zlib: For s390x HW acceleration, skip checking the...
authorPetr Viktorin <encukou@gmail.com>
Mon, 28 Oct 2024 12:50:42 +0000 (13:50 +0100)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2024 12:50:42 +0000 (13:50 +0100)
This backports two commits:

- GH-31096 skipped the tests unconditionally
- GH-125042 skips only the possibly-failing assertion

(cherry picked from commit d522856)

Lib/test/test_zlib.py
Misc/NEWS.d/next/Tests/2024-10-07-14-13-38.gh-issue-125041.PKLWDf.rst [new file with mode: 0644]

index aa7943fc28a38acaf19d5186517d354da2e4b6da..938f34001aee231eea770c197a0987b50b8c4680 100644 (file)
@@ -2,6 +2,7 @@ import unittest
 from test import support
 import binascii
 import copy
+import os
 import pickle
 import random
 import sys
@@ -30,6 +31,16 @@ def _zlib_runtime_version_tuple(zlib_version=zlib.ZLIB_RUNTIME_VERSION):
 ZLIB_RUNTIME_VERSION_TUPLE = _zlib_runtime_version_tuple()
 
 
+# bpo-46623: When a hardware accelerator is used (currently only on s390x),
+# using different ways to compress data with zlib can produce different
+# compressed data.
+#
+# To simplify the skip condition, make the assumption that s390x always has an
+# accelerator, and nothing else has it.
+# Windows doesn't have os.uname() but it doesn't support s390x.
+HW_ACCELERATED = hasattr(os, 'uname') and os.uname().machine == 's390x'
+
+
 class VersionTestCase(unittest.TestCase):
 
     def test_library_version(self):
@@ -191,7 +202,10 @@ class CompressTestCase(BaseCompressTestCase, unittest.TestCase):
         # compress more data
         data = HAMLET_SCENE * 128
         x = zlib.compress(data)
-        self.assertEqual(zlib.compress(bytearray(data)), x)
+        # With hardware acceleration, the compressed bytes
+        # might not be identical.
+        if not HW_ACCELERATED:
+            self.assertEqual(zlib.compress(bytearray(data)), x)
         for ob in x, bytearray(x):
             self.assertEqual(zlib.decompress(ob), data)
 
@@ -248,7 +262,10 @@ class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
             x1 = co.compress(data)
             x2 = co.flush()
             self.assertRaises(zlib.error, co.flush) # second flush should not work
-            self.assertEqual(x1 + x2, datazip)
+            # With hardware acceleration, the compressed bytes might not
+            # be identical.
+            if not HW_ACCELERATED:
+                self.assertEqual(x1 + x2, datazip)
         for v1, v2 in ((x1, x2), (bytearray(x1), bytearray(x2))):
             dco = zlib.decompressobj()
             y1 = dco.decompress(v1 + v2)
diff --git a/Misc/NEWS.d/next/Tests/2024-10-07-14-13-38.gh-issue-125041.PKLWDf.rst b/Misc/NEWS.d/next/Tests/2024-10-07-14-13-38.gh-issue-125041.PKLWDf.rst
new file mode 100644 (file)
index 0000000..c7181eb
--- /dev/null
@@ -0,0 +1,3 @@
+Re-enable skipped tests for :mod:`zlib` on the s390x architecture: only skip
+checks of the compressed bytes, which can be different between zlib's
+software implementation and the hardware-accelerated implementation.