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