subrata_modak | c864960 | 2008-08-27 11:29:55 +0000 | [diff] [blame] | 1 | #!/bin/sh |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 2 | ################################################################################ |
| 3 | ## ## |
| 4 | ## Copyright (c) International Business Machines Corp., 2001 ## |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 5 | ## Author: Manoj Iyer, manjo@mail.utexas.edu ## |
| 6 | ## Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> ## |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 7 | ## ## |
| 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 Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 19 | ## 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_modak | a1fd64b | 2007-04-11 11:24:49 +0000 | [diff] [blame] | 21 | ## ## |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 22 | ################################################################################ |
| 23 | # |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 24 | # Creates, lists and extracts an plain, gzip and bzip tar archive. |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 25 | # |
iyermanoj | 59df7843 | 2002-12-18 20:16:28 +0000 | [diff] [blame] | 26 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 27 | TST_CNT=6 |
| 28 | TST_TESTFUNC=do_test |
| 29 | TST_NEEDS_TMPDIR=1 |
| 30 | . tst_test.sh |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 31 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 32 | TAR_FILES="file1 file2 file3" |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 33 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 34 | check_listing() |
| 35 | { |
| 36 | local i |
| 37 | local verbose=$1 |
| 38 | shift |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 39 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 40 | if [ -z "$verbose" ]; then |
| 41 | if [ -s tar.out ]; then |
| 42 | tst_res TFAIL "Tar produced unexpected output" |
| 43 | cat tar.out |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 44 | else |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 45 | tst_res TPASS "Tar produced no output" |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 46 | fi |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 47 | |
| 48 | return |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 49 | fi |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 50 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 51 | 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 |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 56 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 57 | 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 |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 63 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 64 | tst_res TPASS "Listing in tar.out is correct" |
| 65 | } |
iyermanoj | fcac63f | 2002-12-18 00:22:29 +0000 | [diff] [blame] | 66 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame] | 67 | check_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 | |
| 77 | check_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 | |
| 90 | check_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 | |
| 102 | test_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 | |
| 140 | do_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 | |
| 152 | tst_run |