1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) International Business Machines Corp., 2001 4# Author: Manoj Iyer <[email protected]> 5# 6# Test basic functionality of gzip and gunzip command 7# Test #1: Test that gzip -r will travel directories and 8# compress all the files available. 9# 10# Test #2: Test that gunzip -r will travel directories and 11# uncompress all the files available. 12 13TST_CNT=2 14TST_TESTFUNC=test 15TST_NEEDS_TMPDIR=1 16TST_NEEDS_CMDS="gzip gunzip" 17 18creat_dirnfiles() 19{ 20 local numdirs=$2 21 local numfiles=$3 22 local dirname=$4 23 local dircnt=0 24 local fcnt=0 25 26 tst_res TINFO "Test #$1: Creating $numdirs directories" 27 tst_res TINFO "Test #$1: filling each dir with $numfiles files" 28 while [ $dircnt -lt $numdirs ]; do 29 dirname=$dirname/d.$dircnt 30 ROD_SILENT mkdir -p $dirname 31 32 fcnt=0 33 while [ $fcnt -lt $numfiles ]; do 34 ROD_SILENT touch $dirname/f.$fcnt 35 fcnt=$(($fcnt+1)) 36 done 37 dircnt=$(($dircnt+1)) 38 done 39} 40 41creat_expout() 42{ 43 local numdir=$1 44 local numfile=$2 45 local dirname=$3 46 local ext=$4 47 local dircnt=0 48 local fcnt=0 49 50 echo "$dirname:" 1> tst_gzip.exp 51 echo "d.$dircnt" 1>> tst_gzip.exp 52 while [ $dircnt -lt $numdirs ]; do 53 dirname=$dirname/d.$dircnt 54 dircnt=$(($dircnt+1)) 55 echo "$dirname:" 1>> tst_gzip.exp 56 if [ $dircnt -lt $numdirs ]; then 57 echo "d.$dircnt" 1>> tst_gzip.exp 58 fi 59 fcnt=0 60 while [ $fcnt -lt $numfiles ]; do 61 echo "f.$fcnt$ext " 1>> tst_gzip.exp 62 fcnt=$(($fcnt+1)) 63 done 64 printf "\n\n" 1>> tst_gzip.exp 65 done 66} 67 68test1() 69{ 70 numdirs=10 71 numfiles=10 72 dircnt=0 73 fcnt=0 74 75 ROD_SILENT mkdir tst_gzip.tmp 76 77 tst_res TINFO "Test #1: gzip -r will recursively compress contents" \ 78 "of directory" 79 80 creat_dirnfiles 1 $numdirs $numfiles tst_gzip.tmp 81 82 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 83 if [ $? -ne 0 ]; then 84 cat tst_gzip.err 85 tst_res TFAIL "Test #1: gzip -r failed" 86 return 87 fi 88 89 tst_res TINFO "Test #1: creating output file" 90 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 91 92 tst_res TINFO "Test #1: creating expected output file" 93 creat_expout $numdirs $numfiles tst_gzip.tmp .gz 94 95 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 96 if [ $? -ne 0 ]; then 97 cat tst_gzip.err 98 tst_res TFAIL "Test #1: gzip failed" 99 else 100 tst_res TPASS "Test #1: gzip -r success" 101 fi 102 103 ROD_SILENT rm -rf tst_gzip.tmp/ 104} 105 106test2() 107{ 108 numdirs=10 109 numfiles=10 110 dircnt=0 111 fcnt=0 112 113 ROD_SILENT mkdir tst_gzip.tmp 114 115 tst_res TINFO "Test #2: gunzip -r will recursively uncompress" \ 116 "contents of directory" 117 118 creat_dirnfiles 2 $numdirs $numfiles tst_gzip.tmp 119 120 gzip -r tst_gzip.tmp > tst_gzip.err 2>&1 121 if [ $? -ne 0 ]; then 122 cat tst_gzip.err 123 tst_brk TBROK "Test #2: compressing directory tst_gzip.tmp" \ 124 "failed" 125 fi 126 127 gunzip -r tst_gzip.tmp > tst_gzip.err 2>&1 128 if [ $? -ne 0 ]; then 129 cat tst_gzip.err 130 tst_brk TBROK "Test #2: uncompressing directory" \ 131 " tst_gzip.tmp failed" 132 fi 133 134 tst_res TINFO "Test #2: creating output file" 135 ls -R tst_gzip.tmp > tst_gzip.out 2>&1 136 137 tst_res TINFO "Test #2: creating expected output file" 138 creat_expout $numdirs $numfiles tst_gzip.tmp 139 140 tst_res TINFO "Test #2: comparing expected out and actual output file" 141 diff -w -B tst_gzip.out tst_gzip.exp > tst_gzip.err 2>&1 142 if [ $? -ne 0 ]; then 143 cat tst_gzip.err 144 tst_res TFAIL "Test #2: gunzip failed" 145 else 146 tst_res TPASS "Test #2: gunzip -r success" 147 fi 148 149 ROD_SILENT rm -rf tst_gzip.tmp/ 150} 151 152. tst_test.sh 153tst_run 154