Home | History | Annotate | Line # | Download | only in mtree
t_mtree.sh revision 1.4.2.2
      1  1.4.2.2  yamt # $NetBSD: t_mtree.sh,v 1.4.2.2 2012/04/17 00:09:23 yamt Exp $
      2  1.4.2.2  yamt #
      3  1.4.2.2  yamt # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
      4  1.4.2.2  yamt # All rights reserved.
      5  1.4.2.2  yamt #
      6  1.4.2.2  yamt # Redistribution and use in source and binary forms, with or without
      7  1.4.2.2  yamt # modification, are permitted provided that the following conditions
      8  1.4.2.2  yamt # are met:
      9  1.4.2.2  yamt # 1. Redistributions of source code must retain the above copyright
     10  1.4.2.2  yamt #    notice, this list of conditions and the following disclaimer.
     11  1.4.2.2  yamt # 2. Redistributions in binary form must reproduce the above copyright
     12  1.4.2.2  yamt #    notice, this list of conditions and the following disclaimer in the
     13  1.4.2.2  yamt #    documentation and/or other materials provided with the distribution.
     14  1.4.2.2  yamt #
     15  1.4.2.2  yamt # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.4.2.2  yamt # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.4.2.2  yamt # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.4.2.2  yamt # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.4.2.2  yamt # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.4.2.2  yamt # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.4.2.2  yamt # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.4.2.2  yamt # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.4.2.2  yamt # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.4.2.2  yamt # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.4.2.2  yamt # POSSIBILITY OF SUCH DAMAGE.
     26  1.4.2.2  yamt #
     27  1.4.2.2  yamt 
     28  1.4.2.2  yamt # Postprocess mtree output, canonicalising portions that
     29  1.4.2.2  yamt # are expected to differ from one run to another.
     30  1.4.2.2  yamt #
     31  1.4.2.2  yamt h_postprocess()
     32  1.4.2.2  yamt {
     33  1.4.2.2  yamt 	sed -e '
     34  1.4.2.2  yamt 		/^#	   user: /s/:.*/: x/
     35  1.4.2.2  yamt 		/^#	machine: /s/:.*/: x/
     36  1.4.2.2  yamt 		/^#	   tree: /s/:.*/: x/
     37  1.4.2.2  yamt 		/^#	   date: /s/:.*/: x/
     38  1.4.2.2  yamt 		'
     39  1.4.2.2  yamt }
     40  1.4.2.2  yamt 
     41  1.4.2.2  yamt h_check()
     42  1.4.2.2  yamt {
     43  1.4.2.2  yamt         diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
     44  1.4.2.2  yamt }
     45  1.4.2.2  yamt 
     46  1.4.2.2  yamt atf_test_case create
     47  1.4.2.2  yamt create_head()
     48  1.4.2.2  yamt {
     49  1.4.2.2  yamt 	atf_set "descr" "Create a specfile describing a directory tree"
     50  1.4.2.2  yamt }
     51  1.4.2.2  yamt 
     52  1.4.2.2  yamt create_setup()
     53  1.4.2.2  yamt {
     54  1.4.2.2  yamt 	# create some directories
     55  1.4.2.2  yamt 	mkdir -p create/a/1 create/a/2 create/b
     56  1.4.2.2  yamt 	# create some files
     57  1.4.2.2  yamt 	for file in create/top.file.1 \
     58  1.4.2.2  yamt 		    create/a/a.file.1 \
     59  1.4.2.2  yamt 		    create/a/a.file.2 \
     60  1.4.2.2  yamt 		    create/a/1/a1.file.1 \
     61  1.4.2.2  yamt 		    create/b/b.file.1 \
     62  1.4.2.2  yamt 		    create/b/b.file.2
     63  1.4.2.2  yamt 	do
     64  1.4.2.2  yamt 		echo "$file" >$file
     65  1.4.2.2  yamt 	done
     66  1.4.2.2  yamt 	# hard link to file in same dir
     67  1.4.2.2  yamt 	ln create/b/b.file.1 create/b/b.hardlink.1
     68  1.4.2.2  yamt 	# hard link to file in another dir
     69  1.4.2.2  yamt 	ln create/b/b.file.2 create/a/a.hardlink.b2
     70  1.4.2.2  yamt 	# symlink to file
     71  1.4.2.2  yamt 	ln -s a.file.1 create/a.symlink.1
     72  1.4.2.2  yamt 	# symlink to dir
     73  1.4.2.2  yamt 	ln -s b create/top.symlink.b
     74  1.4.2.2  yamt 	# dangling symlink
     75  1.4.2.2  yamt 	ln -s nonexistent create/top.dangling
     76  1.4.2.2  yamt }
     77  1.4.2.2  yamt 
     78  1.4.2.2  yamt create_body()
     79  1.4.2.2  yamt {
     80  1.4.2.2  yamt 	create_setup
     81  1.4.2.2  yamt 
     82  1.4.2.2  yamt 	# run mtree and check output
     83  1.4.2.2  yamt 	( cd create && mtree -c -k type,nlink,link,size,sha256 ) >output.raw \
     84  1.4.2.2  yamt 	|| atf_fail "mtree exit status $?"
     85  1.4.2.2  yamt 	h_postprocess <output.raw >output
     86  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_create.out" output
     87  1.4.2.2  yamt }
     88  1.4.2.2  yamt 
     89  1.4.2.2  yamt atf_test_case check
     90  1.4.2.2  yamt check_head()
     91  1.4.2.2  yamt {
     92  1.4.2.2  yamt 	atf_set "descr" "Check a directory tree against a specfile"
     93  1.4.2.2  yamt }
     94  1.4.2.2  yamt 
     95  1.4.2.2  yamt check_body()
     96  1.4.2.2  yamt {
     97  1.4.2.2  yamt 	# we use the same directory tree and specfile as in the "create" test
     98  1.4.2.2  yamt 	create_setup
     99  1.4.2.2  yamt 
    100  1.4.2.2  yamt 	# run mtree and check output
    101  1.4.2.2  yamt 	( cd create && mtree ) <"$(atf_get_srcdir)/d_create.out" >output \
    102  1.4.2.2  yamt 	|| atf_fail "mtree exit status $?"
    103  1.4.2.2  yamt 	h_check /dev/null output
    104  1.4.2.2  yamt }
    105  1.4.2.2  yamt 
    106  1.4.2.2  yamt atf_test_case convert_C
    107  1.4.2.2  yamt convert_C_head()
    108  1.4.2.2  yamt {
    109  1.4.2.2  yamt 	atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
    110  1.4.2.2  yamt }
    111  1.4.2.2  yamt 
    112  1.4.2.2  yamt convert_C_body()
    113  1.4.2.2  yamt {
    114  1.4.2.2  yamt 	mtree -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
    115  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_convert_C.out" output
    116  1.4.2.2  yamt }
    117  1.4.2.2  yamt 
    118  1.4.2.2  yamt atf_test_case convert_C_S
    119  1.4.2.2  yamt convert_C_S_head()
    120  1.4.2.2  yamt {
    121  1.4.2.2  yamt 	atf_set "descr" "Convert a specfile to mtree -C format, sorted"
    122  1.4.2.2  yamt }
    123  1.4.2.2  yamt 
    124  1.4.2.2  yamt convert_C_S_body()
    125  1.4.2.2  yamt {
    126  1.4.2.2  yamt 	mtree -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
    127  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
    128  1.4.2.2  yamt }
    129  1.4.2.2  yamt 
    130  1.4.2.2  yamt atf_test_case convert_D
    131  1.4.2.2  yamt convert_D_head()
    132  1.4.2.2  yamt {
    133  1.4.2.2  yamt 	atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
    134  1.4.2.2  yamt }
    135  1.4.2.2  yamt 
    136  1.4.2.2  yamt convert_D_body()
    137  1.4.2.2  yamt {
    138  1.4.2.2  yamt 	mtree -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
    139  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_convert_D.out" output
    140  1.4.2.2  yamt }
    141  1.4.2.2  yamt 
    142  1.4.2.2  yamt atf_test_case convert_D_S
    143  1.4.2.2  yamt convert_D_S_head()
    144  1.4.2.2  yamt {
    145  1.4.2.2  yamt 	atf_set "descr" "Convert a specfile to mtree -D format, sorted"
    146  1.4.2.2  yamt }
    147  1.4.2.2  yamt 
    148  1.4.2.2  yamt convert_D_S_body()
    149  1.4.2.2  yamt {
    150  1.4.2.2  yamt 	mtree -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
    151  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
    152  1.4.2.2  yamt }
    153  1.4.2.2  yamt 
    154  1.4.2.2  yamt atf_test_case ignore
    155  1.4.2.2  yamt ignore_head()
    156  1.4.2.2  yamt {
    157  1.4.2.2  yamt 	atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
    158  1.4.2.2  yamt }
    159  1.4.2.2  yamt 
    160  1.4.2.2  yamt ignore_body()
    161  1.4.2.2  yamt {
    162  1.4.2.2  yamt 	mkdir newdir
    163  1.4.2.2  yamt 	mtree -c | mtree -Ck uid,gid,mode > mtree.spec
    164  1.4.2.2  yamt 	ln -s newdir otherdir
    165  1.4.2.2  yamt 
    166  1.4.2.2  yamt 	# This yields "extra: otherdir" even with -d.
    167  1.4.2.2  yamt 	# (PR bin/41061)
    168  1.4.2.2  yamt 	atf_check -s ignore -o empty -e empty -x "mtree -d < mtree.spec"
    169  1.4.2.2  yamt 
    170  1.4.2.2  yamt 	# Delete the symlink and re-verify.
    171  1.4.2.2  yamt 	#
    172  1.4.2.2  yamt 	rm otherdir
    173  1.4.2.2  yamt 	atf_check -s ignore -o empty -e empty -x "mtree -d < mtree.spec"
    174  1.4.2.2  yamt }
    175  1.4.2.2  yamt 
    176  1.4.2.2  yamt atf_test_case merge
    177  1.4.2.2  yamt merge_head()
    178  1.4.2.2  yamt {
    179  1.4.2.2  yamt 	atf_set "descr" "Merge records of different type"
    180  1.4.2.2  yamt }
    181  1.4.2.2  yamt 
    182  1.4.2.2  yamt merge_body()
    183  1.4.2.2  yamt {
    184  1.4.2.2  yamt 	mtree -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
    185  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
    186  1.4.2.2  yamt 	# same again, with sorting
    187  1.4.2.2  yamt 	mtree -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
    188  1.4.2.2  yamt 	h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
    189  1.4.2.2  yamt }
    190  1.4.2.2  yamt 
    191  1.4.2.2  yamt atf_test_case nonemptydir
    192  1.4.2.2  yamt nonemptydir_head()
    193  1.4.2.2  yamt {
    194  1.4.2.2  yamt 	atf_set "descr" "Test that new non-empty " \
    195  1.4.2.2  yamt 			"directories are recorded (PR bin/25693)"
    196  1.4.2.2  yamt }
    197  1.4.2.2  yamt 
    198  1.4.2.2  yamt nonemptydir_body()
    199  1.4.2.2  yamt {
    200  1.4.2.2  yamt 	mkdir testdir
    201  1.4.2.2  yamt 	cd testdir
    202  1.4.2.2  yamt 
    203  1.4.2.2  yamt 	mtree -c > mtree.spec
    204  1.4.2.2  yamt 
    205  1.4.2.2  yamt 	if [ ! -f mtree.spec ]; then
    206  1.4.2.2  yamt 		atf_fail "mtree failed"
    207  1.4.2.2  yamt 	fi
    208  1.4.2.2  yamt 
    209  1.4.2.2  yamt 	touch bar
    210  1.4.2.2  yamt 	atf_check -s ignore -o save:output -x "mtree -f mtree.spec"
    211  1.4.2.2  yamt 
    212  1.4.2.2  yamt 	if [ ! -n "$(egrep "extra: bar" output)" ]; then
    213  1.4.2.2  yamt 		atf_fail "mtree did not record changes (PR bin/25693)"
    214  1.4.2.2  yamt 	fi
    215  1.4.2.2  yamt }
    216  1.4.2.2  yamt 
    217  1.4.2.2  yamt atf_init_test_cases()
    218  1.4.2.2  yamt {
    219  1.4.2.2  yamt 	atf_add_test_case create
    220  1.4.2.2  yamt 	atf_add_test_case check
    221  1.4.2.2  yamt 	atf_add_test_case convert_C
    222  1.4.2.2  yamt 	atf_add_test_case convert_C_S
    223  1.4.2.2  yamt 	atf_add_test_case convert_D
    224  1.4.2.2  yamt 	atf_add_test_case convert_D_S
    225  1.4.2.2  yamt 	atf_add_test_case ignore
    226  1.4.2.2  yamt 	atf_add_test_case merge
    227  1.4.2.2  yamt 	atf_add_test_case nonemptydir
    228  1.4.2.2  yamt }
    229