From f40acc98a93a2f40c56962d1f79fbaff65571e3f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 3 Feb 2022 09:42:07 +0100 Subject: [PATCH 1/3] bpo-46623: Skip two test_zlib tests on s390x Skip test_pair() and test_speech128() of test_zlib on s390x since they fail if zlib uses the s390x hardware accelerator. --- Lib/test/test_zlib.py | 32 +++++++++++++++++++ .../2022-02-03-09-45-26.bpo-46623.vxzuhV.rst | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2022-02-03-09-45-26.bpo-46623.vxzuhV.rst diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 04fb4d93de45e1..50d214da85a72b 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -3,6 +3,7 @@ from test.support import import_helper import binascii import copy +import os import pickle import random import sys @@ -18,6 +19,35 @@ hasattr(zlib.decompressobj(), "copy"), 'requires Decompress.copy()') +# bpo-46623: On s390x, when a hardware accelerator is used, using different +# ways to compress data with zlib can produce different compressed data. +# Simplified test_pair() code: +# +# def func1(datasrc): +# return zlib.compress(datasrc) +# +# def func2(datasrc) +# co = zlib.compressobj() +# x1 = co.compress(data) +# x2 = co.flush() +# return x1 + x2 +# +# On s390x if zlib uses a hardware accelerator, func1() creates a single +# "final" compressed block whereas func2() produces 3 compressed blocks (the +# last one is a final block). On other platforms with no accelerator, func1() +# and func2() produce the same compressed data made of a single (final) +# compressed block. +# +# Only the compressed data is different, the decompression returns the original +# data: +# +# zlib.decompress(func1()) == zlib.decompress(func2()) == datasrc +# +# Make the assumption that s390x always has an accelerator to simplify the +# skip condition. +skip_on_s390x = unittest.skipIf(os.uname().machine == 's390x', + 'skipped on s390x') + class VersionTestCase(unittest.TestCase): @@ -182,6 +212,7 @@ def test_keywords(self): bufsize=zlib.DEF_BUF_SIZE), HAMLET_SCENE) + @skip_on_s390x def test_speech128(self): # compress more data data = HAMLET_SCENE * 128 @@ -233,6 +264,7 @@ def test_64bit_compress(self, size): class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase): # Test compression object + @skip_on_s390x def test_pair(self): # straightforward compress/decompress objects datasrc = HAMLET_SCENE * 128 diff --git a/Misc/NEWS.d/next/Tests/2022-02-03-09-45-26.bpo-46623.vxzuhV.rst b/Misc/NEWS.d/next/Tests/2022-02-03-09-45-26.bpo-46623.vxzuhV.rst new file mode 100644 index 00000000000000..be085c067a3763 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-02-03-09-45-26.bpo-46623.vxzuhV.rst @@ -0,0 +1,2 @@ +Skip test_pair() and test_speech128() of test_zlib on s390x since they fail +if zlib uses the s390x hardware accelerator. Patch by Victor Stinner. From 370ab52a1e2ffa1766c1c844b5d429861f9fb35a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 3 Feb 2022 10:54:26 +0100 Subject: [PATCH 2/3] Windows doesn't have os.uname() --- Lib/test/test_zlib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 50d214da85a72b..3469214dcd04f8 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -44,8 +44,8 @@ # zlib.decompress(func1()) == zlib.decompress(func2()) == datasrc # # Make the assumption that s390x always has an accelerator to simplify the -# skip condition. -skip_on_s390x = unittest.skipIf(os.uname().machine == 's390x', +# skip condition. Don't skip on Windows which doesn't have os.uname(). +skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x', 'skipped on s390x') From 2ba7379c434562c038db68c77fe39100d90fb5f7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 24 Feb 2022 00:27:23 +0100 Subject: [PATCH 3/3] Fix the comment --- Lib/test/test_zlib.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 3469214dcd04f8..f20aad051da960 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -23,10 +23,10 @@ # ways to compress data with zlib can produce different compressed data. # Simplified test_pair() code: # -# def func1(datasrc): -# return zlib.compress(datasrc) +# def func1(data): +# return zlib.compress(data) # -# def func2(datasrc) +# def func2(data) # co = zlib.compressobj() # x1 = co.compress(data) # x2 = co.flush() @@ -41,10 +41,10 @@ # Only the compressed data is different, the decompression returns the original # data: # -# zlib.decompress(func1()) == zlib.decompress(func2()) == datasrc +# zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data # -# Make the assumption that s390x always has an accelerator to simplify the -# skip condition. Don't skip on Windows which doesn't have os.uname(). +# Make the assumption that s390x always has an accelerator to simplify the skip +# condition. Windows doesn't have os.uname() but it doesn't support s390x. skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x', 'skipped on s390x')