blob: 7ac18a4e523c7702e84bc2b7fee527f663692d60 [file] [log] [blame]
subrata_modakc8649602008-08-27 11:29:55 +00001#!/bin/sh
iyermanoj8117f0c2002-12-18 00:07:37 +00002################################################################################
3## ##
4## Copyright (c) International Business Machines Corp., 2001 ##
Cyril Hrubiscb008792016-10-24 15:23:52 +02005## Author: Manoj Iyer, manjo@mail.utexas.edu ##
6## Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> ##
iyermanoj8117f0c2002-12-18 00:07:37 +00007## ##
8## This program is free software; you can redistribute it and#or modify ##
9## it under the terms of the GNU General Public License as published by ##
10## the Free Software Foundation; either version 2 of the License, or ##
11## (at your option) any later version. ##
12## ##
13## This program is distributed in the hope that it will be useful, but ##
14## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
15## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
16## for more details. ##
17## ##
18## You should have received a copy of the GNU General Public License ##
Cyril Hrubiscb008792016-10-24 15:23:52 +020019## along with this program; if not, write to the Free Software Foundation, ##
20## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
subrata_modaka1fd64b2007-04-11 11:24:49 +000021## ##
iyermanoj8117f0c2002-12-18 00:07:37 +000022################################################################################
23#
Cyril Hrubiscb008792016-10-24 15:23:52 +020024# Creates, lists and extracts an plain, gzip and bzip tar archive.
iyermanoj8117f0c2002-12-18 00:07:37 +000025#
iyermanoj59df78432002-12-18 20:16:28 +000026
Cyril Hrubiscb008792016-10-24 15:23:52 +020027TST_CNT=6
28TST_TESTFUNC=do_test
29TST_NEEDS_TMPDIR=1
30. tst_test.sh
iyermanoj8117f0c2002-12-18 00:07:37 +000031
Cyril Hrubiscb008792016-10-24 15:23:52 +020032TAR_FILES="file1 file2 file3"
iyermanoj8117f0c2002-12-18 00:07:37 +000033
Cyril Hrubiscb008792016-10-24 15:23:52 +020034check_listing()
35{
36 local i
37 local verbose=$1
38 shift
iyermanoj8117f0c2002-12-18 00:07:37 +000039
Cyril Hrubiscb008792016-10-24 15:23:52 +020040 if [ -z "$verbose" ]; then
41 if [ -s tar.out ]; then
42 tst_res TFAIL "Tar produced unexpected output"
43 cat tar.out
iyermanoj8117f0c2002-12-18 00:07:37 +000044 else
Cyril Hrubiscb008792016-10-24 15:23:52 +020045 tst_res TPASS "Tar produced no output"
iyermanoj8117f0c2002-12-18 00:07:37 +000046 fi
Cyril Hrubiscb008792016-10-24 15:23:52 +020047
48 return
iyermanoj8117f0c2002-12-18 00:07:37 +000049 fi
iyermanoj8117f0c2002-12-18 00:07:37 +000050
Cyril Hrubiscb008792016-10-24 15:23:52 +020051 if [ $(wc -l < tar.out) != $# ]; then
52 tst_res TFAIL "Unexpected number of lines in tar.out"
53 cat tar.out
54 return
55 fi
iyermanoj8117f0c2002-12-18 00:07:37 +000056
Cyril Hrubiscb008792016-10-24 15:23:52 +020057 for i in $@; do
58 if ! grep -q $i tar.out; then
59 tst_res TFAIL "File $i missing in listing"
60 return
61 fi
62 done
iyermanoj8117f0c2002-12-18 00:07:37 +000063
Cyril Hrubiscb008792016-10-24 15:23:52 +020064 tst_res TPASS "Listing in tar.out is correct"
65}
iyermanojfcac63f2002-12-18 00:22:29 +000066
Cyril Hrubiscb008792016-10-24 15:23:52 +020067check_content()
68{
69 local fname="$1"
70 local verbose="$2"
71 shift 2
72
73 EXPECT_PASS tar t${verbose}f "$fname" \> tar.out
74 check_listing v $@
75}
76
77check_files()
78{
79 for i in $@; do
80 if ! [ -f $i ]; then
81 tst_res TFAIL "Missing file $i in extracted archive"
82 cat tar.out
83 return
84 fi
85 done
86
87 tst_res TPASS "Files were uncompressed correctly"
88}
89
90check_extraction()
91{
92 local fname="$1"
93 local verbose="$2"
94 shift 2
95
96 EXPECT_PASS tar x${verbose}f $fname \> tar.out
97 check_listing "${verbose}" $@
98 check_files $@
99 ROD rm $@
100}
101
102test_tar()
103{
104 local comp="$1"
105 local verbose="$2"
106 local fname="$3"
107 local i
108
109 # Create archive
110 ROD touch $TAR_FILES
111 EXPECT_PASS tar c${verbose}f$comp $fname $TAR_FILES \> tar.out
112 check_listing "$verbose" $TAR_FILES
113
114 # Diff filesystem against the archive, should be the same at this point
115 EXPECT_PASS tar d${verbose}f $fname \> tar.out
116 check_listing "$verbose" $TAR_FILES
117
118 ROD rm $TAR_FILES
119
120 # Check content listing
121 check_content $fname "$verbose" $TAR_FILES
122
123 # Check decompression
124 check_extraction $fname "$verbose" $TAR_FILES
125
126 # Append to an archive, only possible for uncompressed archive
127 if [ -z "$comp" ]; then
128 ROD touch file4
129 EXPECT_PASS tar r${verbose}f $fname file4 \> tar.out
130 check_listing "$verbose" file4
131 check_content $fname "$verbose" $TAR_FILES file4
132 ROD rm file4
133
134 check_extraction $fname "$verbose" $TAR_FILES file4
135 fi
136
137 ROD rm $fname
138}
139
140do_test()
141{
142 case $1 in
143 1) test_tar "" "v" "test.tar";;
144 2) test_tar "z" "v" "test.tar.gz";;
145 3) test_tar "j" "v" "test.tar.bz2";;
146 4) test_tar "" "" "test.tar";;
147 5) test_tar "z" "" "test.tar.gz";;
148 6) test_tar "j" "" "test.tar.bz2";;
149 esac
150}
151
152tst_run