Skip to content

Commit 9f3b9c4

Browse files
committed
Workaround: Fix test failures on Ubuntu jammy s390x.
This commit fixes the test failures on the zlib in Ubuntu jammy s390x. According to the <https://packages.ubuntu.com/jammy-updates/zlib1g> - `zlib_1.2.11.dfsg-2ubuntu9.2.debian.tar.xz`, the zlib deb package is applying the patch 410.patch (madler/zlib#410), and configured by `./configure --dfltcc` on Ubuntu jammy s390x. The `--dfltcc` is to enable the deflate algorithm in hardware. It produces a different (but still valid) compressed byte stream, and causes the test failures in ruby/zlib. As a workaround, set the environment variable `DFLTCC=0` disabling the implementation in zlib on s390x to the failing tests. Note we need to test in a child Ruby process with `assert_separately` to test on the `DFLTCC=0` set by the parent Ruby process.
1 parent 4284bd0 commit 9f3b9c4

File tree

1 file changed

+84
-64
lines changed

1 file changed

+84
-64
lines changed

test/zlib/test_zlib.rb

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
end
1313

1414
if defined? Zlib
15+
child_env = {}
16+
child_env['DFLTCC'] = '0' if RUBY_PLATFORM =~ /s390x/
17+
Zlib::CHILD_ENV = child_env.freeze
18+
1519
class TestZlibDeflate < Test::Unit::TestCase
1620
def test_initialize
1721
z = Zlib::Deflate.new
@@ -44,59 +48,63 @@ def test_deflate
4448
end
4549

4650
def test_deflate_chunked
47-
original = ''.dup
48-
chunks = []
49-
r = Random.new 0
50-
51-
z = Zlib::Deflate.new
52-
53-
2.times do
54-
input = r.bytes(20000)
55-
original << input
56-
z.deflate(input) do |chunk|
57-
chunks << chunk
51+
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
52+
original = ''.dup
53+
chunks = []
54+
r = Random.new 0
55+
56+
z = Zlib::Deflate.new
57+
58+
2.times do
59+
input = r.bytes(20000)
60+
original << input
61+
z.deflate(input) do |chunk|
62+
chunks << chunk
63+
end
5864
end
59-
end
6065
61-
assert_equal [16384, 16384],
62-
chunks.map { |chunk| chunk.length }
66+
assert_equal [16384, 16384],
67+
chunks.map { |chunk| chunk.length }
6368
64-
final = z.finish
69+
final = z.finish
6570
66-
assert_equal 7253, final.length
71+
assert_equal 7253, final.length
6772
68-
chunks << final
69-
all = chunks.join
73+
chunks << final
74+
all = chunks.join
7075
71-
inflated = Zlib.inflate all
76+
inflated = Zlib.inflate all
7277
73-
assert_equal original, inflated
78+
assert_equal original, inflated
79+
end;
7480
end
7581

7682
def test_deflate_chunked_break
77-
chunks = []
78-
r = Random.new 0
83+
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
84+
chunks = []
85+
r = Random.new 0
7986
80-
z = Zlib::Deflate.new
87+
z = Zlib::Deflate.new
8188
82-
input = r.bytes(20000)
83-
z.deflate(input) do |chunk|
84-
chunks << chunk
85-
break
86-
end
89+
input = r.bytes(20000)
90+
z.deflate(input) do |chunk|
91+
chunks << chunk
92+
break
93+
end
8794
88-
assert_equal [16384], chunks.map { |chunk| chunk.length }
95+
assert_equal [16384], chunks.map { |chunk| chunk.length }
8996
90-
final = z.finish
97+
final = z.finish
9198
92-
assert_equal 3632, final.length
99+
assert_equal 3632, final.length
93100
94-
all = chunks.join
95-
all << final
101+
all = chunks.join
102+
all << final
96103
97-
original = Zlib.inflate all
104+
original = Zlib.inflate all
98105
99-
assert_equal input, original
106+
assert_equal input, original
107+
end;
100108
end
101109

102110
def test_addstr
@@ -952,30 +960,32 @@ def test_unused
952960
end
953961

954962
def test_unused2
955-
zio = StringIO.new
963+
assert_separately([Zlib::CHILD_ENV, '-rzlib', '-rstringio'], <<~'end;')
964+
zio = StringIO.new
956965
957-
io = Zlib::GzipWriter.new zio
958-
io.write 'aaaa'
959-
io.finish
966+
io = Zlib::GzipWriter.new zio
967+
io.write 'aaaa'
968+
io.finish
960969
961-
io = Zlib::GzipWriter.new zio
962-
io.write 'bbbb'
963-
io.finish
970+
io = Zlib::GzipWriter.new zio
971+
io.write 'bbbb'
972+
io.finish
964973
965-
zio.rewind
974+
zio.rewind
966975
967-
io = Zlib::GzipReader.new zio
968-
assert_equal('aaaa', io.read)
969-
unused = io.unused
970-
assert_equal(24, unused.bytesize)
971-
io.finish
976+
io = Zlib::GzipReader.new zio
977+
assert_equal('aaaa', io.read)
978+
unused = io.unused
979+
assert_equal(24, unused.bytesize)
980+
io.finish
972981
973-
zio.pos -= unused.length
982+
zio.pos -= unused.length
974983
975-
io = Zlib::GzipReader.new zio
976-
assert_equal('bbbb', io.read)
977-
assert_equal(nil, io.unused)
978-
io.finish
984+
io = Zlib::GzipReader.new zio
985+
assert_equal('bbbb', io.read)
986+
assert_equal(nil, io.unused)
987+
io.finish
988+
end;
979989
end
980990

981991
def test_read
@@ -1402,36 +1412,46 @@ def test_deflate
14021412
end
14031413

14041414
def test_deflate_stream
1405-
r = Random.new 0
1415+
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
1416+
r = Random.new 0
14061417
1407-
deflated = ''.dup
1418+
deflated = ''.dup
14081419
1409-
Zlib.deflate(r.bytes(20000)) do |chunk|
1410-
deflated << chunk
1411-
end
1420+
Zlib.deflate(r.bytes(20000)) do |chunk|
1421+
deflated << chunk
1422+
end
14121423
1413-
assert_equal 20016, deflated.length
1424+
assert_equal 20016, deflated.length
1425+
end;
14141426
end
14151427

14161428
def test_gzip
1417-
actual = Zlib.gzip("foo".freeze)
1418-
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
1419-
actual[9] = "\xff" # replace OS
1420-
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
1421-
assert_equal expected, actual
1429+
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
1430+
actual = Zlib.gzip("foo".freeze)
1431+
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
1432+
actual[9] = "\xff" # replace OS
1433+
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
1434+
assert_equal expected, actual
1435+
end;
1436+
end
14221437

1438+
def test_gzip_level_0
14231439
actual = Zlib.gzip("foo".freeze, level: 0)
14241440
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14251441
actual[9] = "\xff" # replace OS
14261442
expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*")
14271443
assert_equal expected, actual
1444+
end
14281445

1446+
def test_gzip_level_9
14291447
actual = Zlib.gzip("foo".freeze, level: 9)
14301448
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14311449
actual[9] = "\xff" # replace OS
14321450
expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
14331451
assert_equal expected, actual
1452+
end
14341453

1454+
def test_gzip_level_9_filtered
14351455
actual = Zlib.gzip("foo".freeze, level: 9, strategy: Zlib::FILTERED)
14361456
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14371457
actual[9] = "\xff" # replace OS

0 commit comments

Comments
 (0)