Blame tests/p_gzip/20-gzip-test

iaind 56c8c8
#!/bin/bash
iaind 56c8c8
# Author: Athmane Madjoudj <athmanem@gmail.com>
iaind 56c8c8
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
iaind 56c8c8
# Author: Iain Douglas <centos@1n6.org.uk>
Rene Diepstraten 85cde8
# Author: Rene Diepstraten <rene@renediepstraten.nl>
iaind 56c8c8
iaind 56c8c8
function ExitFail {
iaind 56c8c8
    t_Log "FAIL"
iaind 56c8c8
    exit $FAIL
iaind 56c8c8
}
iaind 56c8c8
iaind 56c8c8
function cleanup {
iaind 56c8c8
rm $FILE* &>/dev/null
iaind 56c8c8
rm /var/tmp/gziptest/* &>/dev/null
iaind 56c8c8
rmdir /var/tmp/gziptest &>/dev/null
iaind 56c8c8
}
iaind 56c8c8
iaind 56c8c8
t_Log "Running $0 - run a file through gzip,zcat and gunzip test."
iaind 56c8c8
iaind 56c8c8
# create file
iaind 56c8c8
FILE=/var/tmp/gzip-test.txt
iaind 56c8c8
iaind 56c8c8
# Just in case earlier runs failed
iaind 56c8c8
cleanup
iaind 56c8c8
# Use the provided file as it has known contents and known name/timestamp
iaind 56c8c8
# information.
iaind 56c8c8
iaind 56c8c8
cp ./tests/p_gzip/gzip-test.txt.gz  /var/tmp
iaind 56c8c8
iaind 56c8c8
#run file through gunzip
iaind 56c8c8
t_Log "Test basic gunzip"
iaind 56c8c8
gunzip $FILE.gz
iaind 56c8c8
#checking file contents
iaind 56c8c8
grep -q 'gzip-test of single file' $FILE || ExitFail
iaind 56c8c8
iaind 56c8c8
# run file through gzip
iaind 56c8c8
t_Log "Test basic gzip"
iaind 56c8c8
gzip $FILE || ExitFail
iaind 56c8c8
iaind 56c8c8
#just to make sure
iaind 56c8c8
/bin/rm -rf $FILE
iaind 56c8c8
iaind 56c8c8
#run file through zcat
iaind 56c8c8
t_Log "Test basic zcat"
iaind 56c8c8
zcat $FILE.gz | grep -q 'gzip-test of single file' || ExitFail
iaind 56c8c8
iaind 56c8c8
# Basic tests complete - go a little deeper.
iaind 56c8c8
iaind 56c8c8
# Check that we cannot overwrite an existing file
iaind 56c8c8
t_Log "Check files will not be overwritten"
iaind 56c8c8
touch $FILE
iaind 56c8c8
echo | gunzip $FILE  &>/dev/null
iaind 56c8c8
[ $? -ne 2 ]  && ExitFail
iaind 56c8c8
iaind 56c8c8
echo | gzip $FILE  &>/dev/null
iaind 56c8c8
[ $? -ne 2 ]  && ExitFail
iaind 56c8c8
iaind 56c8c8
# Check that we can force files to be overwritten
iaind 56c8c8
t_Log "Check force overwrite"
iaind 56c8c8
gunzip -f $FILE.gz  || ExitFail
iaind 56c8c8
touch $FILE.gz
iaind 56c8c8
gzip -f $FILE || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check that -a is ignored 
iaind 56c8c8
t_Log "Check -a is ignored as we're on CentOS"
Christoph Galuschka edd017
if [ $centos_ver == '5' ]
Christoph Galuschka edd017
  then
Christoph Galuschka edd017
  gunzip -a $FILE.gz 2>&1 | head -n 1 | grep  -q 'gunzip: option --ascii ignored on this system' || ExitFail
Pablo Greco edbc89
elif [[ $centos_ver =~ ^(6|7|8)$ ]]
Christoph Galuschka edd017
  then
Christoph Galuschka edd017
  gunzip -a $FILE.gz 2>&1 | head -n 1 | grep  -q 'gzip: option --ascii ignored on this system' || ExitFail
Christoph Galuschka edd017
fi
iaind 56c8c8
iaind 56c8c8
# Check -c writes to stdout
iaind 56c8c8
t_Log "check -c writes to stdout"
iaind 56c8c8
iaind 56c8c8
gzip -c $FILE | gunzip | grep -q 'gzip-test of single file' || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check the correct info is listed for -l the output is
iaind 56c8c8
#         compressed        uncompressed  ratio uncompressed_name
iaind 56c8c8
#                 59                  25  24.0% /var/tmp/gzip-test.txt
iaind 56c8c8
#
iaind 56c8c8
# The md5sum is 4cbaba004a815915904bd524ede5edec
dc4d19
#
dc4d19
# The 32-bit gzip behaves differently:
dc4d19
# 
dc4d19
#         compressed        uncompressed  ratio uncompressed_name
dc4d19
#                 59                  25  -8.0% /var/tmp/gzip-test.txt
dc4d19
#
dc4d19
# The md5sum is caf6dee7a56022a840316520134967a4
dc4d19
iaind 56c8c8
t_Log "Check the output of -l"
iaind 56c8c8
gzip $FILE
iaind 56c8c8
mdhash=$(gzip -l $FILE.gz | md5sum | cut -f1 -d' ')
dc4d19
[ "$mdhash" == "4cbaba004a815915904bd524ede5edec" -o "$mdhash" == "caf6dee7a56022a840316520134967a4" ] || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check that -q works which removes the header information from -l
iaind 56c8c8
t_Log "Check -q reduced the output verbosity"
iaind 56c8c8
gzip -ql $FILE | grep -qv "ratio" || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check -v gives us more information - we shouls see the files
iaind 56c8c8
# CRC which is d14bbb86
iaind 56c8c8
t_Log "Check -v increases verbosity"
iaind 56c8c8
gzip -lv $FILE | grep -q "d14bbb86" || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check -n and -N work correctly. The original datestamp on the
iaind 56c8c8
# test file is '2010-11-22 13:11' gzip-test.txt
iaind 56c8c8
# At this point we shouldn't see the original timestamp if the default 
iaind 56c8c8
# -n to gunzip and -N to gzip are working.
iaind 56c8c8
iaind 56c8c8
t_Log "check -n and -N work correctly"
iaind 56c8c8
TZ_SAVE=$TZ
Iain Douglas e1d3b8
export TZ=UTC
iaind 56c8c8
gunzip $FILE.gz
iaind 56c8c8
ls -l --time-style=+"%F %R" $FILE | grep -q '2010-11-22 13:11' &&  ExitFail
iaind 56c8c8
iaind 56c8c8
# Reset the test file with a different name
iaind 56c8c8
# the file should gunzup as gzip-test.1
iaind 56c8c8
cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.1.gz
iaind 56c8c8
gunzip $FILE.1.gz
iaind 56c8c8
[ -e "$FILE.1" ] || ExitFail
iaind 56c8c8
iaind 56c8c8
# Reset the test file with a different name
iaind 56c8c8
cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.1.gz
iaind 56c8c8
iaind 56c8c8
# The file should gunzip with it's original name and timestamp.
iaind 56c8c8
gunzip -f -N $FILE.1.gz
Christoph Galuschka f0d9f1
ls -l $FILE --time-style=+"%F %R" | grep  -q '2010-11-22 13:11' || ExitFail
Iain Douglas e1d3b8
export TZ=$TZ_SAVE
iaind 56c8c8
# Check that -t works and detects a damaged file
iaind 56c8c8
t_Log "Check -t can detect a corrupt file"
iaind 56c8c8
gzip $FILE
iaind 56c8c8
echo -ne \\x34 | dd conv=notrunc bs=1 count=1 seek=27  of=$FILE.gz &>/dev/null
iaind 56c8c8
gzip -t $FILE.gz 2>&1 | grep -qv "data--crc error" || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check we can use a custon suffix .iain will do ;)
iaind 56c8c8
t_Log "Check that a custom suffix can be used -S"
iaind 56c8c8
cp ./tests/p_gzip/gzip-test.txt.gz /var/tmp/gzip-test.txt.gz
iaind 56c8c8
gunzip $FILE.gz
iaind 56c8c8
gzip -S .iain $FILE
iaind 56c8c8
[ -e $FILE.iain ] || ExitFail
iaind 56c8c8
gunzip -S .iain $FILE || ExitFail
iaind 56c8c8
iaind 56c8c8
# Check that -r works - create a directory, populate it then just pass
iaind 56c8c8
# the dirname to gzip - it should zip all the files.
iaind 56c8c8
iaind 56c8c8
t_Log "Check that -r works "
iaind 56c8c8
mkdir /var/tmp/gziptest
iaind 56c8c8
touch /var/tmp/gziptest/a
iaind 56c8c8
touch /var/tmp/gziptest/b
iaind 56c8c8
gzip -r /var/tmp/gziptest
iaind 56c8c8
[ "$(ls /var/tmp/gziptest/*.gz | wc -l)" -eq "2" ] || ExitFail
iaind 56c8c8
iaind 56c8c8
# Text the different compression levels
iaind 56c8c8
t_Log "Check different compression levels"
iaind 56c8c8
gzip -1 $FILE.1   # 61 bytes
iaind 56c8c8
gzip -9 $FILE     # 59 bytes
iaind 56c8c8
[ "$(stat -c %s $FILE.gz)" -ne "$(stat -c %s $FILE.1.gz)" ] || ExitFail
iaind 56c8c8
iaind 56c8c8
# Multiple input files 
iaind 56c8c8
t_Log "Multiple input files on the command line"
iaind 56c8c8
# Multiple files on one command line
iaind 56c8c8
gunzip $FILE.1.gz $FILE || ExitFail
iaind 56c8c8
iaind 56c8c8
# Don't specify the .gz extension
iaind 56c8c8
t_Log "No file extension supplied for gunzip"
iaind 56c8c8
gzip $FILE $FILE.1  || ExitFail
iaind 56c8c8
iaind 56c8c8
# Compress the file then get gunzip to uncompress it, the file needs
iaind 56c8c8
# to be larger for compress to work
iaind 56c8c8
t_Log "Check gunzip can handle .Z files"
iaind 56c8c8
gunzip $FILE 
iaind 56c8c8
ls -l /var/tmp >>$FILE
iaind 56c8c8
compress $FILE || ExitFail
iaind 56c8c8
gunzip $FILE.Z || ExitFail
iaind 56c8c8
iaind 56c8c8
# Zip the file then get gunzip to uncompress it.
iaind 56c8c8
t_Log "Check gunzip can handle .zip files"
iaind 56c8c8
zip $FILE.zip $FILE  &>/dev/null || ExitFail
iaind 56c8c8
gunzip -f  -S .zip $FILE.zip  || ExitFail
iaind 56c8c8
iaind 56c8c8
# Handle .tgz correctly
iaind 56c8c8
t_Log "Check gunzip creates a .tar file from .tgz"
iaind 56c8c8
tar -czf $FILE.tgz $FILE &>/dev/null
iaind 56c8c8
gunzip $FILE.tgz
iaind 56c8c8
[ -e $FILE.tar ] 
iaind 56c8c8
t_CheckExitStatus $?
iaind 56c8c8
iaind 56c8c8
#tar the file rename it to .tgz 
iaind 56c8c8
#reversing changes
iaind 56c8c8
cleanup