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_ID="tar01" |
| 28 | TST_CNT=6 |
| 29 | TST_TESTFUNC=do_test |
| 30 | TST_NEEDS_TMPDIR=1 |
| 31 | . tst_test.sh |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 32 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 33 | TAR_FILES="file1 file2 file3" |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 34 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 35 | check_listing() |
| 36 | { |
| 37 | local i |
| 38 | local verbose=$1 |
| 39 | shift |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 40 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 41 | if [ -z "$verbose" ]; then |
| 42 | if [ -s tar.out ]; then |
| 43 | tst_res TFAIL "Tar produced unexpected output" |
| 44 | cat tar.out |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 45 | else |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 46 | tst_res TPASS "Tar produced no output" |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 47 | fi |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 48 | |
| 49 | return |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 50 | fi |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 51 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 52 | if [ $(wc -l < tar.out) != $# ]; then |
| 53 | tst_res TFAIL "Unexpected number of lines in tar.out" |
| 54 | cat tar.out |
| 55 | return |
| 56 | fi |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 57 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 58 | for i in $@; do |
| 59 | if ! grep -q $i tar.out; then |
| 60 | tst_res TFAIL "File $i missing in listing" |
| 61 | return |
| 62 | fi |
| 63 | done |
iyermanoj | 8117f0c | 2002-12-18 00:07:37 +0000 | [diff] [blame] | 64 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 65 | tst_res TPASS "Listing in tar.out is correct" |
| 66 | } |
iyermanoj | fcac63f | 2002-12-18 00:22:29 +0000 | [diff] [blame] | 67 | |
Cyril Hrubis | cb00879 | 2016-10-24 15:23:52 +0200 | [diff] [blame^] | 68 | check_content() |
| 69 | { |
| 70 | local fname="$1" |
| 71 | local verbose="$2" |
| 72 | shift 2 |
| 73 | |
| 74 | EXPECT_PASS tar t${verbose}f "$fname" \> tar.out |
| 75 | check_listing v $@ |
| 76 | } |
| 77 | |
| 78 | check_files() |
| 79 | { |
| 80 | for i in $@; do |
| 81 | if ! [ -f $i ]; then |
| 82 | tst_res TFAIL "Missing file $i in extracted archive" |
| 83 | cat tar.out |
| 84 | return |
| 85 | fi |
| 86 | done |
| 87 | |
| 88 | tst_res TPASS "Files were uncompressed correctly" |
| 89 | } |
| 90 | |
| 91 | check_extraction() |
| 92 | { |
| 93 | local fname="$1" |
| 94 | local verbose="$2" |
| 95 | shift 2 |
| 96 | |
| 97 | EXPECT_PASS tar x${verbose}f $fname \> tar.out |
| 98 | check_listing "${verbose}" $@ |
| 99 | check_files $@ |
| 100 | ROD rm $@ |
| 101 | } |
| 102 | |
| 103 | test_tar() |
| 104 | { |
| 105 | local comp="$1" |
| 106 | local verbose="$2" |
| 107 | local fname="$3" |
| 108 | local i |
| 109 | |
| 110 | # Create archive |
| 111 | ROD touch $TAR_FILES |
| 112 | EXPECT_PASS tar c${verbose}f$comp $fname $TAR_FILES \> tar.out |
| 113 | check_listing "$verbose" $TAR_FILES |
| 114 | |
| 115 | # Diff filesystem against the archive, should be the same at this point |
| 116 | EXPECT_PASS tar d${verbose}f $fname \> tar.out |
| 117 | check_listing "$verbose" $TAR_FILES |
| 118 | |
| 119 | ROD rm $TAR_FILES |
| 120 | |
| 121 | # Check content listing |
| 122 | check_content $fname "$verbose" $TAR_FILES |
| 123 | |
| 124 | # Check decompression |
| 125 | check_extraction $fname "$verbose" $TAR_FILES |
| 126 | |
| 127 | # Append to an archive, only possible for uncompressed archive |
| 128 | if [ -z "$comp" ]; then |
| 129 | ROD touch file4 |
| 130 | EXPECT_PASS tar r${verbose}f $fname file4 \> tar.out |
| 131 | check_listing "$verbose" file4 |
| 132 | check_content $fname "$verbose" $TAR_FILES file4 |
| 133 | ROD rm file4 |
| 134 | |
| 135 | check_extraction $fname "$verbose" $TAR_FILES file4 |
| 136 | fi |
| 137 | |
| 138 | ROD rm $fname |
| 139 | } |
| 140 | |
| 141 | do_test() |
| 142 | { |
| 143 | case $1 in |
| 144 | 1) test_tar "" "v" "test.tar";; |
| 145 | 2) test_tar "z" "v" "test.tar.gz";; |
| 146 | 3) test_tar "j" "v" "test.tar.bz2";; |
| 147 | 4) test_tar "" "" "test.tar";; |
| 148 | 5) test_tar "z" "" "test.tar.gz";; |
| 149 | 6) test_tar "j" "" "test.tar.bz2";; |
| 150 | esac |
| 151 | } |
| 152 | |
| 153 | tst_run |