• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) International Business Machines Corp., 2001
4# Author: Manoj Iyer <manjo@mail.utexas.edu>
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. tst_test.sh
18
19creat_dirnfiles()
20{
21	local numdirs=$2
22	local numfiles=$3
23	local dirname=$4
24	local dircnt=0
25	local fcnt=0
26
27	tst_res TINFO "Test #$1: Creating $numdirs directories"
28	tst_res TINFO "Test #$1: filling each dir with $numfiles files"
29	while [ $dircnt -lt $numdirs ]; do
30		dirname=$dirname/d.$dircnt
31		ROD_SILENT mkdir -p $dirname
32
33		fcnt=0
34		while [ $fcnt -lt $numfiles ]; do
35			ROD_SILENT touch $dirname/f.$fcnt
36			fcnt=$(($fcnt+1))
37		done
38		dircnt=$(($dircnt+1))
39	done
40}
41
42creat_expout()
43{
44	local numdir=$1
45	local numfile=$2
46	local dirname=$3
47	local ext=$4
48	local dircnt=0
49	local fcnt=0
50
51	echo "$dirname:"  1> tst_gzip.exp
52	echo "d.$dircnt"  1>> tst_gzip.exp
53	while [ $dircnt -lt $numdirs ]; do
54		dirname=$dirname/d.$dircnt
55		dircnt=$(($dircnt+1))
56		echo "$dirname:"  1>> tst_gzip.exp
57		if [ $dircnt -lt $numdirs ]; then
58			echo "d.$dircnt"  1>> tst_gzip.exp
59		fi
60		fcnt=0
61		while [ $fcnt -lt $numfiles ]; do
62			echo "f.$fcnt$ext " 1>> tst_gzip.exp
63			fcnt=$(($fcnt+1))
64		done
65		printf "\n\n" 1>> tst_gzip.exp
66	done
67}
68
69test1()
70{
71	numdirs=10
72	numfiles=10
73	dircnt=0
74	fcnt=0
75
76	ROD_SILENT mkdir tst_gzip.tmp
77
78	tst_res TINFO "Test #1: gzip -r will recursively compress contents" \
79			"of directory"
80
81	creat_dirnfiles 1 $numdirs $numfiles tst_gzip.tmp
82
83	gzip -r tst_gzip.tmp > tst_gzip.err 2>&1
84	if [ $? -ne 0 ]; then
85		cat tst_gzip.err
86		tst_brk TFAIL "Test #1: gzip -r failed"
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
152tst_run
153