Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround: Fix test failures on Ubuntu jammy s390x. #63

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist: jammy
language: ruby
matrix:
include:
- arch: s390x
148 changes: 84 additions & 64 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
end

if defined? Zlib
child_env = {}
child_env['DFLTCC'] = '0' if RUBY_PLATFORM =~ /s390x/
Zlib::CHILD_ENV = child_env.freeze

class TestZlibDeflate < Test::Unit::TestCase
def test_initialize
z = Zlib::Deflate.new
Expand Down Expand Up @@ -44,59 +48,63 @@ def test_deflate
end

def test_deflate_chunked
original = ''.dup
chunks = []
r = Random.new 0

z = Zlib::Deflate.new

2.times do
input = r.bytes(20000)
original << input
z.deflate(input) do |chunk|
chunks << chunk
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
original = ''.dup
chunks = []
r = Random.new 0

z = Zlib::Deflate.new

2.times do
input = r.bytes(20000)
original << input
z.deflate(input) do |chunk|
chunks << chunk
end
end
end

assert_equal [16384, 16384],
chunks.map { |chunk| chunk.length }
assert_equal [16384, 16384],
chunks.map { |chunk| chunk.length }

final = z.finish
final = z.finish

assert_equal 7253, final.length
assert_equal 7253, final.length

chunks << final
all = chunks.join
chunks << final
all = chunks.join

inflated = Zlib.inflate all
inflated = Zlib.inflate all

assert_equal original, inflated
assert_equal original, inflated
end;
end

def test_deflate_chunked_break
chunks = []
r = Random.new 0
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
chunks = []
r = Random.new 0

z = Zlib::Deflate.new
z = Zlib::Deflate.new

input = r.bytes(20000)
z.deflate(input) do |chunk|
chunks << chunk
break
end
input = r.bytes(20000)
z.deflate(input) do |chunk|
chunks << chunk
break
end

assert_equal [16384], chunks.map { |chunk| chunk.length }
assert_equal [16384], chunks.map { |chunk| chunk.length }

final = z.finish
final = z.finish

assert_equal 3632, final.length
assert_equal 3632, final.length

all = chunks.join
all << final
all = chunks.join
all << final

original = Zlib.inflate all
original = Zlib.inflate all

assert_equal input, original
assert_equal input, original
end;
end

def test_addstr
Expand Down Expand Up @@ -952,30 +960,32 @@ def test_unused
end

def test_unused2
zio = StringIO.new
assert_separately([Zlib::CHILD_ENV, '-rzlib', '-rstringio'], <<~'end;')
zio = StringIO.new

io = Zlib::GzipWriter.new zio
io.write 'aaaa'
io.finish
io = Zlib::GzipWriter.new zio
io.write 'aaaa'
io.finish

io = Zlib::GzipWriter.new zio
io.write 'bbbb'
io.finish
io = Zlib::GzipWriter.new zio
io.write 'bbbb'
io.finish

zio.rewind
zio.rewind

io = Zlib::GzipReader.new zio
assert_equal('aaaa', io.read)
unused = io.unused
assert_equal(24, unused.bytesize)
io.finish
io = Zlib::GzipReader.new zio
assert_equal('aaaa', io.read)
unused = io.unused
assert_equal(24, unused.bytesize)
io.finish

zio.pos -= unused.length
zio.pos -= unused.length

io = Zlib::GzipReader.new zio
assert_equal('bbbb', io.read)
assert_equal(nil, io.unused)
io.finish
io = Zlib::GzipReader.new zio
assert_equal('bbbb', io.read)
assert_equal(nil, io.unused)
io.finish
end;
end

def test_read
Expand Down Expand Up @@ -1402,36 +1412,46 @@ def test_deflate
end

def test_deflate_stream
r = Random.new 0
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
r = Random.new 0

deflated = ''.dup
deflated = ''.dup

Zlib.deflate(r.bytes(20000)) do |chunk|
deflated << chunk
end
Zlib.deflate(r.bytes(20000)) do |chunk|
deflated << chunk
end

assert_equal 20016, deflated.length
assert_equal 20016, deflated.length
end;
end

def test_gzip
actual = Zlib.gzip("foo".freeze)
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
actual[9] = "\xff" # replace OS
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
assert_equal expected, actual
assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;')
actual = Zlib.gzip("foo".freeze)
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
actual[9] = "\xff" # replace OS
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
assert_equal expected, actual
end;
end

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

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

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