Home | History | Annotate | Line # | Download | only in mtree
t_mtree.sh revision 1.6.12.1
      1  1.6.12.1  pgoyette # $NetBSD: t_mtree.sh,v 1.6.12.1 2017/03/20 06:58:02 pgoyette 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.6.12.1  pgoyette 	# Kyua 0.11 and above point TMPDIR to our work directory and atf-check
    288  1.6.12.1  pgoyette 	# generates a temporary file, which confuses mtree.  Put the mtree files
    289  1.6.12.1  pgoyette 	# into a subdirectory.
    290  1.6.12.1  pgoyette 	#
    291  1.6.12.1  pgoyette 	# See https://github.com/jmmv/kyua/issues/133 for details.
    292  1.6.12.1  pgoyette 	mkdir root && cd root
    293  1.6.12.1  pgoyette 
    294       1.3    jruoho 	mkdir newdir
    295       1.5  christos 	mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
    296       1.3    jruoho 	ln -s newdir otherdir
    297       1.3    jruoho 
    298       1.3    jruoho 	# This yields "extra: otherdir" even with -d.
    299       1.4  christos 	# (PR bin/41061)
    300       1.5  christos 	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
    301       1.3    jruoho 
    302       1.3    jruoho 	# Delete the symlink and re-verify.
    303       1.3    jruoho 	#
    304       1.3    jruoho 	rm otherdir
    305       1.5  christos 	atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
    306       1.5  christos }
    307       1.5  christos 
    308       1.5  christos mtree_ignore_head() 
    309       1.5  christos {
    310       1.5  christos 	FLAVOR=mtree ignore_head
    311       1.5  christos }
    312       1.5  christos netbsd6_ignore_head() 
    313       1.5  christos {
    314       1.5  christos 	FLAVOR=netbsd6 ignore_head
    315       1.5  christos }
    316       1.5  christos 
    317       1.5  christos mtree_ignore_body() 
    318       1.5  christos {
    319       1.5  christos 	FLAVOR=mtree ignore_body
    320       1.5  christos }
    321       1.5  christos netbsd6_ignore_body() 
    322       1.5  christos {
    323  1.6.12.1  pgoyette 	# Kyua 0.11 and above point TMPDIR to our work directory and atf-check
    324  1.6.12.1  pgoyette 	# generates a temporary file, which confuses mtree.  Put the mtree files
    325  1.6.12.1  pgoyette 	# into a subdirectory.
    326  1.6.12.1  pgoyette 	#
    327  1.6.12.1  pgoyette 	# See https://github.com/jmmv/kyua/issues/133 for details.
    328  1.6.12.1  pgoyette 	mkdir root && cd root
    329  1.6.12.1  pgoyette 
    330       1.5  christos 	FLAVOR=netbsd6 ignore_body
    331       1.3    jruoho }
    332       1.3    jruoho 
    333       1.5  christos 
    334       1.5  christos atf_test_case mtree_merge
    335       1.5  christos atf_test_case netbsd6_merge
    336       1.1    jruoho merge_head()
    337       1.1    jruoho {
    338       1.1    jruoho 	atf_set "descr" "Merge records of different type"
    339       1.1    jruoho }
    340       1.3    jruoho 
    341       1.1    jruoho merge_body()
    342       1.1    jruoho {
    343       1.5  christos 	mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
    344       1.1    jruoho 	h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
    345       1.1    jruoho 	# same again, with sorting
    346       1.5  christos 	mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
    347       1.1    jruoho 	h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
    348       1.1    jruoho }
    349       1.1    jruoho 
    350       1.5  christos mtree_merge_head() 
    351       1.5  christos {
    352       1.5  christos 	FLAVOR=mtree merge_head
    353       1.5  christos }
    354       1.5  christos netbsd6_merge_head() 
    355       1.5  christos {
    356       1.5  christos 	FLAVOR=netbsd6 merge_head
    357       1.5  christos }
    358       1.5  christos 
    359       1.5  christos mtree_merge_body() 
    360       1.5  christos {
    361       1.5  christos 	FLAVOR=mtree merge_body
    362       1.5  christos }
    363       1.5  christos netbsd6_merge_body() 
    364       1.5  christos {
    365       1.5  christos 	FLAVOR=netbsd6 merge_body
    366       1.5  christos }
    367       1.5  christos 
    368       1.5  christos 
    369       1.5  christos atf_test_case mtree_nonemptydir
    370       1.5  christos atf_test_case netbsd6_nonemptydir
    371       1.3    jruoho nonemptydir_head()
    372       1.3    jruoho {
    373       1.2    jruoho 	atf_set "descr" "Test that new non-empty " \
    374       1.2    jruoho 			"directories are recorded (PR bin/25693)"
    375       1.2    jruoho }
    376       1.2    jruoho 
    377       1.3    jruoho nonemptydir_body()
    378       1.3    jruoho {
    379       1.2    jruoho 	mkdir testdir
    380       1.2    jruoho 	cd testdir
    381       1.2    jruoho 
    382       1.5  christos 	mtree -F ${FLAVOR} -c > mtree.spec
    383       1.2    jruoho 
    384       1.2    jruoho 	if [ ! -f mtree.spec ]; then
    385       1.2    jruoho 		atf_fail "mtree failed"
    386       1.2    jruoho 	fi
    387       1.2    jruoho 
    388       1.2    jruoho 	touch bar
    389       1.5  christos 	atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"
    390       1.2    jruoho 
    391       1.2    jruoho 	if [ ! -n "$(egrep "extra: bar" output)" ]; then
    392       1.2    jruoho 		atf_fail "mtree did not record changes (PR bin/25693)"
    393       1.2    jruoho 	fi
    394       1.2    jruoho }
    395       1.2    jruoho 
    396       1.5  christos mtree_nonemptydir_head() 
    397       1.5  christos {
    398       1.5  christos 	FLAVOR=mtree nonemptydir_head
    399       1.5  christos }
    400       1.5  christos netbsd6_nonemptydir_head() 
    401       1.5  christos {
    402       1.5  christos 	FLAVOR=netbsd6 nonemptydir_head
    403       1.5  christos }
    404       1.5  christos 
    405       1.5  christos mtree_nonemptydir_body() 
    406       1.5  christos {
    407       1.5  christos 	FLAVOR=mtree nonemptydir_body
    408       1.5  christos }
    409       1.5  christos netbsd6_nonemptydir_body() 
    410       1.5  christos {
    411       1.5  christos 	FLAVOR=netbsd6 nonemptydir_body
    412       1.5  christos }
    413       1.5  christos 
    414       1.5  christos 
    415       1.1    jruoho atf_init_test_cases()
    416       1.1    jruoho {
    417       1.5  christos 	atf_add_test_case mtree_create
    418       1.5  christos 	atf_add_test_case mtree_check
    419       1.5  christos 	atf_add_test_case mtree_convert_C
    420       1.5  christos 	atf_add_test_case mtree_convert_C_S
    421       1.5  christos 	atf_add_test_case mtree_convert_D
    422       1.5  christos 	atf_add_test_case mtree_convert_D_S
    423       1.5  christos 	atf_add_test_case mtree_ignore
    424       1.5  christos 	atf_add_test_case mtree_merge
    425       1.5  christos 	atf_add_test_case mtree_nonemptydir
    426       1.5  christos 
    427       1.5  christos 	atf_add_test_case netbsd6_create
    428       1.5  christos 	atf_add_test_case netbsd6_check
    429       1.5  christos 	atf_add_test_case netbsd6_convert_C
    430       1.5  christos 	atf_add_test_case netbsd6_convert_C_S
    431       1.5  christos 	atf_add_test_case netbsd6_convert_D
    432       1.5  christos 	atf_add_test_case netbsd6_convert_D_S
    433       1.5  christos 	atf_add_test_case netbsd6_ignore
    434       1.5  christos 	atf_add_test_case netbsd6_merge
    435       1.5  christos 	atf_add_test_case netbsd6_nonemptydir
    436       1.1    jruoho }
    437