Home | History | Annotate | Line # | Download | only in mtree
t_mtree.sh revision 1.6
      1  1.6  christos # $NetBSD: t_mtree.sh,v 1.6 2013/02/05 16:49:42 christos Exp $
      2  1.1    jruoho #
      3  1.3    jruoho # Copyright (c) 2009, 2012 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.5  christos 
     32  1.1    jruoho h_postprocess()
     33  1.1    jruoho {
     34  1.1    jruoho 	sed -e '
     35  1.1    jruoho 		/^#	   user: /s/:.*/: x/
     36  1.1    jruoho 		/^#	machine: /s/:.*/: x/
     37  1.1    jruoho 		/^#	   tree: /s/:.*/: x/
     38  1.1    jruoho 		/^#	   date: /s/:.*/: x/
     39  1.6  christos 		' \
     40  1.6  christos 	    -e '/type=dir/s/ size=[0-9]*//'
     41  1.1    jruoho }
     42  1.1    jruoho 
     43  1.1    jruoho h_check()
     44  1.1    jruoho {
     45  1.1    jruoho         diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
     46  1.1    jruoho }
     47  1.1    jruoho 
     48  1.5  christos 
     49  1.5  christos atf_test_case mtree_create
     50  1.5  christos atf_test_case netbsd6_create
     51  1.1    jruoho create_head()
     52  1.1    jruoho {
     53  1.1    jruoho 	atf_set "descr" "Create a specfile describing a directory tree"
     54  1.1    jruoho }
     55  1.3    jruoho 
     56  1.1    jruoho create_setup()
     57  1.1    jruoho {
     58  1.1    jruoho 	# create some directories
     59  1.5  christos 	rm -fr create
     60  1.1    jruoho 	mkdir -p create/a/1 create/a/2 create/b
     61  1.1    jruoho 	# create some files
     62  1.1    jruoho 	for file in create/top.file.1 \
     63  1.1    jruoho 		    create/a/a.file.1 \
     64  1.1    jruoho 		    create/a/a.file.2 \
     65  1.1    jruoho 		    create/a/1/a1.file.1 \
     66  1.1    jruoho 		    create/b/b.file.1 \
     67  1.1    jruoho 		    create/b/b.file.2
     68  1.1    jruoho 	do
     69  1.1    jruoho 		echo "$file" >$file
     70  1.1    jruoho 	done
     71  1.1    jruoho 	# hard link to file in same dir
     72  1.1    jruoho 	ln create/b/b.file.1 create/b/b.hardlink.1
     73  1.1    jruoho 	# hard link to file in another dir
     74  1.1    jruoho 	ln create/b/b.file.2 create/a/a.hardlink.b2
     75  1.1    jruoho 	# symlink to file
     76  1.1    jruoho 	ln -s a.file.1 create/a.symlink.1
     77  1.1    jruoho 	# symlink to dir
     78  1.1    jruoho 	ln -s b create/top.symlink.b
     79  1.1    jruoho 	# dangling symlink
     80  1.1    jruoho 	ln -s nonexistent create/top.dangling
     81  1.1    jruoho }
     82  1.3    jruoho 
     83  1.1    jruoho create_body()
     84  1.1    jruoho {
     85  1.1    jruoho 	create_setup
     86  1.1    jruoho 
     87  1.1    jruoho 	# run mtree and check output
     88  1.5  christos 	( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \
     89  1.1    jruoho 	|| atf_fail "mtree exit status $?"
     90  1.1    jruoho 	h_postprocess <output.raw >output
     91  1.5  christos 	h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
     92  1.5  christos }
     93  1.5  christos 
     94  1.5  christos mtree_create_head() 
     95  1.5  christos {
     96  1.5  christos 	FLAVOR=mtree create_head
     97  1.5  christos }
     98  1.5  christos netbsd6_create_head() 
     99  1.5  christos {
    100  1.5  christos 	FLAVOR=netbsd6 create_head
    101  1.1    jruoho }
    102  1.1    jruoho 
    103  1.5  christos mtree_create_body() 
    104  1.5  christos {
    105  1.5  christos 	FLAVOR=mtree create_body
    106  1.5  christos }
    107  1.5  christos netbsd6_create_body() 
    108  1.5  christos {
    109  1.5  christos 	FLAVOR=netbsd6 create_body
    110  1.5  christos }
    111  1.5  christos 
    112  1.5  christos 
    113  1.5  christos atf_test_case mtree_check
    114  1.5  christos atf_test_case netbsd6_check
    115  1.1    jruoho check_head()
    116  1.1    jruoho {
    117  1.1    jruoho 	atf_set "descr" "Check a directory tree against a specfile"
    118  1.1    jruoho }
    119  1.3    jruoho 
    120  1.1    jruoho check_body()
    121  1.1    jruoho {
    122  1.1    jruoho 	# we use the same directory tree and specfile as in the "create" test
    123  1.1    jruoho 	create_setup
    124  1.1    jruoho 
    125  1.1    jruoho 	# run mtree and check output
    126  1.5  christos 	( cd create && mtree -F ${FLAVOR}  ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
    127  1.1    jruoho 	|| atf_fail "mtree exit status $?"
    128  1.1    jruoho 	h_check /dev/null output
    129  1.1    jruoho }
    130  1.1    jruoho 
    131  1.5  christos mtree_check_head() 
    132  1.5  christos {
    133  1.5  christos 	FLAVOR=mtree check_head
    134  1.5  christos }
    135  1.5  christos netbsd6_check_head() 
    136  1.5  christos {
    137  1.5  christos 	FLAVOR=netbsd6 check_head
    138  1.5  christos }
    139  1.5  christos 
    140  1.5  christos mtree_check_body() 
    141  1.5  christos {
    142  1.5  christos 	FLAVOR=mtree check_body
    143  1.5  christos }
    144  1.5  christos netbsd6_check_body() 
    145  1.5  christos {
    146  1.5  christos 	FLAVOR=netbsd6 check_body
    147  1.5  christos }
    148  1.5  christos 
    149  1.5  christos 
    150  1.5  christos atf_test_case mtree_convert_C
    151  1.5  christos atf_test_case netbsd6_convert_C
    152  1.1    jruoho convert_C_head()
    153  1.1    jruoho {
    154  1.1    jruoho 	atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
    155  1.1    jruoho }
    156  1.3    jruoho 
    157  1.1    jruoho convert_C_body()
    158  1.1    jruoho {
    159  1.5  christos 	mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
    160  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_convert_C.out" output
    161  1.1    jruoho }
    162  1.1    jruoho 
    163  1.5  christos mtree_convert_C_head() 
    164  1.5  christos {
    165  1.5  christos 	FLAVOR=mtree convert_C_head
    166  1.5  christos }
    167  1.5  christos netbsd6_convert_C_head() 
    168  1.5  christos {
    169  1.5  christos 	FLAVOR=netbsd6 convert_C_head
    170  1.5  christos }
    171  1.5  christos 
    172  1.5  christos mtree_convert_C_body() 
    173  1.5  christos {
    174  1.5  christos 	FLAVOR=mtree convert_C_body
    175  1.5  christos }
    176  1.5  christos netbsd6_convert_C_body() 
    177  1.5  christos {
    178  1.5  christos 	FLAVOR=netbsd6 convert_C_body
    179  1.5  christos }
    180  1.5  christos 
    181  1.5  christos 
    182  1.5  christos atf_test_case mtree_convert_C_S
    183  1.5  christos atf_test_case netbsd6_convert_C_S
    184  1.1    jruoho convert_C_S_head()
    185  1.1    jruoho {
    186  1.1    jruoho 	atf_set "descr" "Convert a specfile to mtree -C format, sorted"
    187  1.1    jruoho }
    188  1.3    jruoho 
    189  1.1    jruoho convert_C_S_body()
    190  1.1    jruoho {
    191  1.5  christos 	mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
    192  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
    193  1.1    jruoho }
    194  1.1    jruoho 
    195  1.5  christos mtree_convert_C_S_head() 
    196  1.5  christos {
    197  1.5  christos 	FLAVOR=mtree convert_C_S_head
    198  1.5  christos }
    199  1.5  christos netbsd6_convert_C_S_head() 
    200  1.5  christos {
    201  1.5  christos 	FLAVOR=netbsd6 convert_C_S_head
    202  1.5  christos }
    203  1.5  christos 
    204  1.5  christos mtree_convert_C_S_body() 
    205  1.5  christos {
    206  1.5  christos 	FLAVOR=mtree convert_C_S_body
    207  1.5  christos }
    208  1.5  christos netbsd6_convert_C_S_body() 
    209  1.5  christos {
    210  1.5  christos 	FLAVOR=netbsd6 convert_C_S_body
    211  1.5  christos }
    212  1.5  christos 
    213  1.5  christos 
    214  1.5  christos atf_test_case mtree_convert_D
    215  1.5  christos atf_test_case netbsd6_convert_D
    216  1.1    jruoho convert_D_head()
    217  1.1    jruoho {
    218  1.1    jruoho 	atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
    219  1.1    jruoho }
    220  1.3    jruoho 
    221  1.1    jruoho convert_D_body()
    222  1.1    jruoho {
    223  1.5  christos 	mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
    224  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_convert_D.out" output
    225  1.1    jruoho }
    226  1.1    jruoho 
    227  1.5  christos mtree_convert_D_head() 
    228  1.5  christos {
    229  1.5  christos 	FLAVOR=mtree convert_D_head
    230  1.5  christos }
    231  1.5  christos netbsd6_convert_D_head() 
    232  1.5  christos {
    233  1.5  christos 	FLAVOR=netbsd6 convert_D_head
    234  1.5  christos }
    235  1.5  christos 
    236  1.5  christos mtree_convert_D_body() 
    237  1.5  christos {
    238  1.5  christos 	FLAVOR=mtree convert_D_body
    239  1.5  christos }
    240  1.5  christos netbsd6_convert_D_body() 
    241  1.5  christos {
    242  1.5  christos 	FLAVOR=netbsd6 convert_D_body
    243  1.5  christos }
    244  1.5  christos 
    245  1.5  christos 
    246  1.5  christos atf_test_case mtree_convert_D_S
    247  1.5  christos atf_test_case netbsd6_convert_D_S
    248  1.1    jruoho convert_D_S_head()
    249  1.1    jruoho {
    250  1.1    jruoho 	atf_set "descr" "Convert a specfile to mtree -D format, sorted"
    251  1.1    jruoho }
    252  1.3    jruoho 
    253  1.1    jruoho convert_D_S_body()
    254  1.1    jruoho {
    255  1.5  christos 	mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
    256  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
    257  1.1    jruoho }
    258  1.1    jruoho 
    259  1.5  christos mtree_convert_D_S_head() 
    260  1.5  christos {
    261  1.5  christos 	FLAVOR=mtree convert_D_S_head
    262  1.5  christos }
    263  1.5  christos netbsd6_convert_D_S_head() 
    264  1.5  christos {
    265  1.5  christos 	FLAVOR=netbsd6 convert_D_S_head
    266  1.5  christos }
    267  1.5  christos 
    268  1.5  christos mtree_convert_D_S_body() 
    269  1.5  christos {
    270  1.5  christos 	FLAVOR=mtree convert_D_S_body
    271  1.5  christos }
    272  1.5  christos netbsd6_convert_D_S_body() 
    273  1.5  christos {
    274  1.5  christos 	FLAVOR=netbsd6 convert_D_S_body
    275  1.5  christos }
    276  1.5  christos 
    277  1.5  christos 
    278  1.5  christos atf_test_case mtree_ignore
    279  1.5  christos atf_test_case netbs6_ignore
    280  1.3    jruoho ignore_head()
    281  1.3    jruoho {
    282  1.3    jruoho 	atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
    283  1.3    jruoho }
    284  1.3    jruoho 
    285  1.3    jruoho ignore_body()
    286  1.3    jruoho {
    287  1.3    jruoho 	mkdir newdir
    288  1.5  christos 	mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
    289  1.3    jruoho 	ln -s newdir otherdir
    290  1.3    jruoho 
    291  1.3    jruoho 	# This yields "extra: otherdir" even with -d.
    292  1.4  christos 	# (PR bin/41061)
    293  1.5  christos 	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
    294  1.3    jruoho 
    295  1.3    jruoho 	# Delete the symlink and re-verify.
    296  1.3    jruoho 	#
    297  1.3    jruoho 	rm otherdir
    298  1.5  christos 	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
    299  1.5  christos }
    300  1.5  christos 
    301  1.5  christos mtree_ignore_head() 
    302  1.5  christos {
    303  1.5  christos 	FLAVOR=mtree ignore_head
    304  1.5  christos }
    305  1.5  christos netbsd6_ignore_head() 
    306  1.5  christos {
    307  1.5  christos 	FLAVOR=netbsd6 ignore_head
    308  1.5  christos }
    309  1.5  christos 
    310  1.5  christos mtree_ignore_body() 
    311  1.5  christos {
    312  1.5  christos 	FLAVOR=mtree ignore_body
    313  1.5  christos }
    314  1.5  christos netbsd6_ignore_body() 
    315  1.5  christos {
    316  1.5  christos 	FLAVOR=netbsd6 ignore_body
    317  1.3    jruoho }
    318  1.3    jruoho 
    319  1.5  christos 
    320  1.5  christos atf_test_case mtree_merge
    321  1.5  christos atf_test_case netbsd6_merge
    322  1.1    jruoho merge_head()
    323  1.1    jruoho {
    324  1.1    jruoho 	atf_set "descr" "Merge records of different type"
    325  1.1    jruoho }
    326  1.3    jruoho 
    327  1.1    jruoho merge_body()
    328  1.1    jruoho {
    329  1.5  christos 	mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
    330  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
    331  1.1    jruoho 	# same again, with sorting
    332  1.5  christos 	mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
    333  1.1    jruoho 	h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
    334  1.1    jruoho }
    335  1.1    jruoho 
    336  1.5  christos mtree_merge_head() 
    337  1.5  christos {
    338  1.5  christos 	FLAVOR=mtree merge_head
    339  1.5  christos }
    340  1.5  christos netbsd6_merge_head() 
    341  1.5  christos {
    342  1.5  christos 	FLAVOR=netbsd6 merge_head
    343  1.5  christos }
    344  1.5  christos 
    345  1.5  christos mtree_merge_body() 
    346  1.5  christos {
    347  1.5  christos 	FLAVOR=mtree merge_body
    348  1.5  christos }
    349  1.5  christos netbsd6_merge_body() 
    350  1.5  christos {
    351  1.5  christos 	FLAVOR=netbsd6 merge_body
    352  1.5  christos }
    353  1.5  christos 
    354  1.5  christos 
    355  1.5  christos atf_test_case mtree_nonemptydir
    356  1.5  christos atf_test_case netbsd6_nonemptydir
    357  1.3    jruoho nonemptydir_head()
    358  1.3    jruoho {
    359  1.2    jruoho 	atf_set "descr" "Test that new non-empty " \
    360  1.2    jruoho 			"directories are recorded (PR bin/25693)"
    361  1.2    jruoho }
    362  1.2    jruoho 
    363  1.3    jruoho nonemptydir_body()
    364  1.3    jruoho {
    365  1.2    jruoho 	mkdir testdir
    366  1.2    jruoho 	cd testdir
    367  1.2    jruoho 
    368  1.5  christos 	mtree -F ${FLAVOR} -c > mtree.spec
    369  1.2    jruoho 
    370  1.2    jruoho 	if [ ! -f mtree.spec ]; then
    371  1.2    jruoho 		atf_fail "mtree failed"
    372  1.2    jruoho 	fi
    373  1.2    jruoho 
    374  1.2    jruoho 	touch bar
    375  1.5  christos 	atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"
    376  1.2    jruoho 
    377  1.2    jruoho 	if [ ! -n "$(egrep "extra: bar" output)" ]; then
    378  1.2    jruoho 		atf_fail "mtree did not record changes (PR bin/25693)"
    379  1.2    jruoho 	fi
    380  1.2    jruoho }
    381  1.2    jruoho 
    382  1.5  christos mtree_nonemptydir_head() 
    383  1.5  christos {
    384  1.5  christos 	FLAVOR=mtree nonemptydir_head
    385  1.5  christos }
    386  1.5  christos netbsd6_nonemptydir_head() 
    387  1.5  christos {
    388  1.5  christos 	FLAVOR=netbsd6 nonemptydir_head
    389  1.5  christos }
    390  1.5  christos 
    391  1.5  christos mtree_nonemptydir_body() 
    392  1.5  christos {
    393  1.5  christos 	FLAVOR=mtree nonemptydir_body
    394  1.5  christos }
    395  1.5  christos netbsd6_nonemptydir_body() 
    396  1.5  christos {
    397  1.5  christos 	FLAVOR=netbsd6 nonemptydir_body
    398  1.5  christos }
    399  1.5  christos 
    400  1.5  christos 
    401  1.1    jruoho atf_init_test_cases()
    402  1.1    jruoho {
    403  1.5  christos 	atf_add_test_case mtree_create
    404  1.5  christos 	atf_add_test_case mtree_check
    405  1.5  christos 	atf_add_test_case mtree_convert_C
    406  1.5  christos 	atf_add_test_case mtree_convert_C_S
    407  1.5  christos 	atf_add_test_case mtree_convert_D
    408  1.5  christos 	atf_add_test_case mtree_convert_D_S
    409  1.5  christos 	atf_add_test_case mtree_ignore
    410  1.5  christos 	atf_add_test_case mtree_merge
    411  1.5  christos 	atf_add_test_case mtree_nonemptydir
    412  1.5  christos 
    413  1.5  christos 	atf_add_test_case netbsd6_create
    414  1.5  christos 	atf_add_test_case netbsd6_check
    415  1.5  christos 	atf_add_test_case netbsd6_convert_C
    416  1.5  christos 	atf_add_test_case netbsd6_convert_C_S
    417  1.5  christos 	atf_add_test_case netbsd6_convert_D
    418  1.5  christos 	atf_add_test_case netbsd6_convert_D_S
    419  1.5  christos 	atf_add_test_case netbsd6_ignore
    420  1.5  christos 	atf_add_test_case netbsd6_merge
    421  1.5  christos 	atf_add_test_case netbsd6_nonemptydir
    422  1.1    jruoho }
    423