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