From 229392a7fe557d051d7ce32491a948b1601c8062 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sat, 8 Jun 2024 15:59:03 +0200 Subject: [PATCH] test/zlibutil: update to match changes in zlibutil, increase reliability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following changes have been made: - The test has been adjusted to zlibutil's changed behavior. - The output of zlibutil isn’t checked against static data, instead it hands the compressed file to another decompressor. This was done because the exact output can change with updates to zlib itself (this appears to have happened in my case). - The new test works with random data, reducing the likelihood of false passes. - The new decompression test works with its own file for the same reason. --- scripts/test/zlibutil.sh | 50 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/scripts/test/zlibutil.sh b/scripts/test/zlibutil.sh index c29e5fd..326b983 100755 --- a/scripts/test/zlibutil.sh +++ b/scripts/test/zlibutil.sh @@ -1,26 +1,46 @@ #!/usr/bin/env bash echo "================================================================================" -echo -n "Testing \`zlibutil\`... " +echo "Testing \`zlibutil\`:" +echo "--------------------------------------------------------------------------------" +TMPDIR="$(mktemp -d -t fossvg-zlibutil-XXXXX)" +TMPDATA="$(dd if=/dev/urandom bs=33 count=1 2>/dev/null | base64)" -echo "abc" >> testfile +echo -n "Compression test... " -bin/tools/zlibutil -c testfile +echo -n "$TMPDATA" >> "$TMPDIR/compress" +zlibutil "$TMPDIR/compress" -if [ "$(bin/tools/arraydump --binary testfile.compressed)" = "{0b01111000, 0b10011100, 0b01001011, 0b01001100, 0b01001010, 0b11100110, 0b00000010, 0b00000000, 0b00000011, 0b01111110, 0b00000001, 0b00110001}" ]; then - echo -n "Compression Test: PASS... " +python3 <<< " +import zlib, sys +tmpfile = open('$TMPDIR/compress.zz', 'rb') +data = tmpfile.read() +tmpfile.close() +try: + if zlib.decompress(data)==b'$TMPDATA': + print('PASS') + else: + print('FAIL: Wrong data.') +except: + print('FAIL: Exception.') +" + +echo -n "Decompression test... " +#TODO: create a compressed file using another implementation (Python) +python3 <<< " +import zlib +tmpfile = open('$TMPDIR/decompress.zz', 'wb') +tmpfile.write(zlib.compress(b'$TMPDATA')) +tmpfile.close() +" + +zlibutil -d "$TMPDIR/decompress.zz" +if [ "$(cat "$TMPDIR/decompress")" = "$TMPDATA" ]; then + echo "PASS" else - echo -n "Compression Test: FAILED... " + echo "FAIL" fi -bin/tools/zlibutil -d testfile.compressed - -if [ "$(bin/tools/arraydump --binary testfile.compressed.uncompressed)" = "{0b01100001, 0b01100010, 0b01100011, 0b00001010}" ]; then - echo "Decompression Test: PASS" -else - echo "Decompression Test: FAILED" -fi - -rm testfile testfile.compressed testfile.compressed.uncompressed +rm -r "$TMPDIR" echo "================================================================================"