Skip to content

Commit f132c58

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 f132c58

File tree

1 file changed

+97
-70
lines changed

1 file changed

+97
-70
lines changed

test/zlib/test_zlib.rb

Lines changed: 97 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
end
1313

1414
if defined? Zlib
15-
class TestZlibDeflate < Test::Unit::TestCase
15+
class Zlib::TestCase < Test::Unit::TestCase
16+
def child_env
17+
return @child_env unless @child_env.nil?
18+
19+
child_env = {}
20+
child_env['DFLTCC'] = '0' if RUBY_PLATFORM =~ /s390x/
21+
@child_env = child_env
22+
@child_env
23+
end
24+
end
25+
26+
class TestZlibDeflate < Zlib::TestCase
1627
def test_initialize
1728
z = Zlib::Deflate.new
1829
s = z.deflate("foo", Zlib::FINISH)
@@ -44,59 +55,63 @@ def test_deflate
4455
end
4556

4657
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
58+
assert_separately([child_env, '-rzlib'], <<~'end;')
59+
original = ''.dup
60+
chunks = []
61+
r = Random.new 0
62+
63+
z = Zlib::Deflate.new
64+
65+
2.times do
66+
input = r.bytes(20000)
67+
original << input
68+
z.deflate(input) do |chunk|
69+
chunks << chunk
70+
end
5871
end
59-
end
6072
61-
assert_equal [16384, 16384],
62-
chunks.map { |chunk| chunk.length }
73+
assert_equal [16384, 16384],
74+
chunks.map { |chunk| chunk.length }
6375
64-
final = z.finish
76+
final = z.finish
6577
66-
assert_equal 7253, final.length
78+
assert_equal 7253, final.length
6779
68-
chunks << final
69-
all = chunks.join
80+
chunks << final
81+
all = chunks.join
7082
71-
inflated = Zlib.inflate all
83+
inflated = Zlib.inflate all
7284
73-
assert_equal original, inflated
85+
assert_equal original, inflated
86+
end;
7487
end
7588

7689
def test_deflate_chunked_break
77-
chunks = []
78-
r = Random.new 0
90+
assert_separately([child_env, '-rzlib'], <<~'end;')
91+
chunks = []
92+
r = Random.new 0
7993
80-
z = Zlib::Deflate.new
94+
z = Zlib::Deflate.new
8195
82-
input = r.bytes(20000)
83-
z.deflate(input) do |chunk|
84-
chunks << chunk
85-
break
86-
end
96+
input = r.bytes(20000)
97+
z.deflate(input) do |chunk|
98+
chunks << chunk
99+
break
100+
end
87101
88-
assert_equal [16384], chunks.map { |chunk| chunk.length }
102+
assert_equal [16384], chunks.map { |chunk| chunk.length }
89103
90-
final = z.finish
104+
final = z.finish
91105
92-
assert_equal 3632, final.length
106+
assert_equal 3632, final.length
93107
94-
all = chunks.join
95-
all << final
108+
all = chunks.join
109+
all << final
96110
97-
original = Zlib.inflate all
111+
original = Zlib.inflate all
98112
99-
assert_equal input, original
113+
assert_equal input, original
114+
end;
100115
end
101116

102117
def test_addstr
@@ -247,7 +262,7 @@ def test_close
247262
end
248263
end
249264

250-
class TestZlibInflate < Test::Unit::TestCase
265+
class TestZlibInflate < Zlib::TestCase
251266
def test_class_inflate_dictionary
252267
assert_raise(Zlib::NeedDict) do
253268
Zlib::Inflate.inflate([0x08,0x3C,0x0,0x0,0x0,0x0].pack("c*"))
@@ -574,7 +589,7 @@ def test_recursive_inflate
574589
end
575590
end
576591

577-
class TestZlibGzipFile < Test::Unit::TestCase
592+
class TestZlibGzipFile < Zlib::TestCase
578593
def test_gzip_reader_zcat
579594
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
580595
t.binmode
@@ -829,7 +844,7 @@ def test_path_tmpfile
829844
end
830845
end
831846

832-
class TestZlibGzipReader < Test::Unit::TestCase
847+
class TestZlibGzipReader < Zlib::TestCase
833848
D0 = "\037\213\010\000S`\017A\000\003\003\000\000\000\000\000\000\000\000\000"
834849
def test_read0
835850
assert_equal("", Zlib::GzipReader.new(StringIO.new(D0)).read(0))
@@ -952,30 +967,32 @@ def test_unused
952967
end
953968

954969
def test_unused2
955-
zio = StringIO.new
970+
assert_separately([child_env, '-rzlib', '-rstringio'], <<~'end;')
971+
zio = StringIO.new
956972
957-
io = Zlib::GzipWriter.new zio
958-
io.write 'aaaa'
959-
io.finish
973+
io = Zlib::GzipWriter.new zio
974+
io.write 'aaaa'
975+
io.finish
960976
961-
io = Zlib::GzipWriter.new zio
962-
io.write 'bbbb'
963-
io.finish
977+
io = Zlib::GzipWriter.new zio
978+
io.write 'bbbb'
979+
io.finish
964980
965-
zio.rewind
981+
zio.rewind
966982
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
983+
io = Zlib::GzipReader.new zio
984+
assert_equal('aaaa', io.read)
985+
unused = io.unused
986+
assert_equal(24, unused.bytesize)
987+
io.finish
972988
973-
zio.pos -= unused.length
989+
zio.pos -= unused.length
974990
975-
io = Zlib::GzipReader.new zio
976-
assert_equal('bbbb', io.read)
977-
assert_equal(nil, io.unused)
978-
io.finish
991+
io = Zlib::GzipReader.new zio
992+
assert_equal('bbbb', io.read)
993+
assert_equal(nil, io.unused)
994+
io.finish
995+
end;
979996
end
980997

981998
def test_read
@@ -1207,7 +1224,7 @@ def test_double_close
12071224

12081225
end
12091226

1210-
class TestZlibGzipWriter < Test::Unit::TestCase
1227+
class TestZlibGzipWriter < Zlib::TestCase
12111228
def test_invalid_new
12121229
assert_raise(NoMethodError, "[ruby-dev:23228]") { Zlib::GzipWriter.new(nil).close }
12131230
assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(true).close }
@@ -1301,7 +1318,7 @@ def ary.write(*args)
13011318
end
13021319
end
13031320

1304-
class TestZlib < Test::Unit::TestCase
1321+
class TestZlib < Zlib::TestCase
13051322
def test_version
13061323
assert_instance_of(String, Zlib.zlib_version)
13071324
end
@@ -1402,36 +1419,46 @@ def test_deflate
14021419
end
14031420

14041421
def test_deflate_stream
1405-
r = Random.new 0
1422+
assert_separately([child_env, '-rzlib'], <<~'end;')
1423+
r = Random.new 0
14061424
1407-
deflated = ''.dup
1425+
deflated = ''.dup
14081426
1409-
Zlib.deflate(r.bytes(20000)) do |chunk|
1410-
deflated << chunk
1411-
end
1427+
Zlib.deflate(r.bytes(20000)) do |chunk|
1428+
deflated << chunk
1429+
end
14121430
1413-
assert_equal 20016, deflated.length
1431+
assert_equal 20016, deflated.length
1432+
end;
14141433
end
14151434

14161435
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
1436+
assert_separately([child_env, '-rzlib'], <<~'end;')
1437+
actual = Zlib.gzip("foo".freeze)
1438+
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
1439+
actual[9] = "\xff" # replace OS
1440+
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
1441+
assert_equal expected, actual
1442+
end;
1443+
end
14221444

1445+
def test_gzip_level_0
14231446
actual = Zlib.gzip("foo".freeze, level: 0)
14241447
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14251448
actual[9] = "\xff" # replace OS
14261449
expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*")
14271450
assert_equal expected, actual
1451+
end
14281452

1453+
def test_gzip_level_9
14291454
actual = Zlib.gzip("foo".freeze, level: 9)
14301455
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14311456
actual[9] = "\xff" # replace OS
14321457
expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
14331458
assert_equal expected, actual
1459+
end
14341460

1461+
def test_gzip_level_9_filtered
14351462
actual = Zlib.gzip("foo".freeze, level: 9, strategy: Zlib::FILTERED)
14361463
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
14371464
actual[9] = "\xff" # replace OS

0 commit comments

Comments
 (0)