t_mtree.sh revision 273928
1272343Sngie# $NetBSD: t_mtree.sh,v 1.6 2013/02/05 16:49:42 christos Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2009, 2012 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngie# Postprocess mtree output, canonicalising portions that 29272343Sngie# are expected to differ from one run to another. 30272343Sngie# 31272343Sngie 32272343Sngieh_postprocess() 33272343Sngie{ 34272343Sngie sed -e ' 35272343Sngie /^# user: /s/:.*/: x/ 36272343Sngie /^# machine: /s/:.*/: x/ 37272343Sngie /^# tree: /s/:.*/: x/ 38272343Sngie /^# date: /s/:.*/: x/ 39272343Sngie ' \ 40272343Sngie -e '/type=dir/s/ size=[0-9]*//' 41272343Sngie} 42272343Sngie 43272343Sngieh_check() 44272343Sngie{ 45272343Sngie diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ" 46272343Sngie} 47272343Sngie 48272343Sngie 49272343Sngieatf_test_case mtree_create 50272343Sngieatf_test_case netbsd6_create 51272343Sngiecreate_head() 52272343Sngie{ 53272343Sngie atf_set "descr" "Create a specfile describing a directory tree" 54272343Sngie} 55272343Sngie 56272343Sngiecreate_setup() 57272343Sngie{ 58272343Sngie # create some directories 59272343Sngie rm -fr create 60272343Sngie mkdir -p create/a/1 create/a/2 create/b 61272343Sngie # create some files 62272343Sngie for file in create/top.file.1 \ 63272343Sngie create/a/a.file.1 \ 64272343Sngie create/a/a.file.2 \ 65272343Sngie create/a/1/a1.file.1 \ 66272343Sngie create/b/b.file.1 \ 67272343Sngie create/b/b.file.2 68272343Sngie do 69272343Sngie echo "$file" >$file 70272343Sngie done 71272343Sngie # hard link to file in same dir 72272343Sngie ln create/b/b.file.1 create/b/b.hardlink.1 73272343Sngie # hard link to file in another dir 74272343Sngie ln create/b/b.file.2 create/a/a.hardlink.b2 75272343Sngie # symlink to file 76272343Sngie ln -s a.file.1 create/a.symlink.1 77272343Sngie # symlink to dir 78272343Sngie ln -s b create/top.symlink.b 79272343Sngie # dangling symlink 80272343Sngie ln -s nonexistent create/top.dangling 81272343Sngie} 82272343Sngie 83272343Sngiecreate_body() 84272343Sngie{ 85272343Sngie create_setup 86272343Sngie 87272343Sngie # run mtree and check output 88272343Sngie ( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \ 89272343Sngie || atf_fail "mtree exit status $?" 90272343Sngie h_postprocess <output.raw >output 91272343Sngie h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output 92272343Sngie} 93272343Sngie 94272343Sngiemtree_create_head() 95272343Sngie{ 96272343Sngie FLAVOR=mtree create_head 97272343Sngie} 98272343Sngienetbsd6_create_head() 99272343Sngie{ 100272343Sngie FLAVOR=netbsd6 create_head 101272343Sngie} 102272343Sngie 103272343Sngiemtree_create_body() 104272343Sngie{ 105272343Sngie FLAVOR=mtree create_body 106272343Sngie} 107272343Sngienetbsd6_create_body() 108272343Sngie{ 109272343Sngie FLAVOR=netbsd6 create_body 110272343Sngie} 111272343Sngie 112272343Sngie 113272343Sngieatf_test_case mtree_check 114272343Sngieatf_test_case netbsd6_check 115272343Sngiecheck_head() 116272343Sngie{ 117272343Sngie atf_set "descr" "Check a directory tree against a specfile" 118272343Sngie} 119272343Sngie 120272343Sngiecheck_body() 121272343Sngie{ 122272343Sngie # we use the same directory tree and specfile as in the "create" test 123272343Sngie create_setup 124272343Sngie 125272343Sngie # run mtree and check output 126272343Sngie ( cd create && mtree -F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \ 127272343Sngie || atf_fail "mtree exit status $?" 128272343Sngie h_check /dev/null output 129272343Sngie} 130272343Sngie 131272343Sngiemtree_check_head() 132272343Sngie{ 133272343Sngie FLAVOR=mtree check_head 134272343Sngie} 135272343Sngienetbsd6_check_head() 136272343Sngie{ 137272343Sngie FLAVOR=netbsd6 check_head 138272343Sngie} 139272343Sngie 140272343Sngiemtree_check_body() 141272343Sngie{ 142272343Sngie FLAVOR=mtree check_body 143272343Sngie} 144272343Sngienetbsd6_check_body() 145272343Sngie{ 146272343Sngie FLAVOR=netbsd6 check_body 147272343Sngie} 148272343Sngie 149272343Sngie 150272343Sngieatf_test_case mtree_convert_C 151272343Sngieatf_test_case netbsd6_convert_C 152272343Sngieconvert_C_head() 153272343Sngie{ 154272343Sngie atf_set "descr" "Convert a specfile to mtree -C format, unsorted" 155272343Sngie} 156272343Sngie 157272343Sngieconvert_C_body() 158272343Sngie{ 159272343Sngie mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output 160272343Sngie h_check "$(atf_get_srcdir)/d_convert_C.out" output 161272343Sngie} 162272343Sngie 163272343Sngiemtree_convert_C_head() 164272343Sngie{ 165272343Sngie FLAVOR=mtree convert_C_head 166272343Sngie} 167272343Sngienetbsd6_convert_C_head() 168272343Sngie{ 169272343Sngie FLAVOR=netbsd6 convert_C_head 170272343Sngie} 171272343Sngie 172272343Sngiemtree_convert_C_body() 173272343Sngie{ 174272343Sngie FLAVOR=mtree convert_C_body 175272343Sngie} 176272343Sngienetbsd6_convert_C_body() 177272343Sngie{ 178272343Sngie FLAVOR=netbsd6 convert_C_body 179272343Sngie} 180272343Sngie 181272343Sngie 182272343Sngieatf_test_case mtree_convert_C_S 183272343Sngieatf_test_case netbsd6_convert_C_S 184272343Sngieconvert_C_S_head() 185272343Sngie{ 186272343Sngie atf_set "descr" "Convert a specfile to mtree -C format, sorted" 187272343Sngie} 188272343Sngie 189272343Sngieconvert_C_S_body() 190272343Sngie{ 191272343Sngie mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output 192272343Sngie h_check "$(atf_get_srcdir)/d_convert_C_S.out" output 193272343Sngie} 194272343Sngie 195272343Sngiemtree_convert_C_S_head() 196272343Sngie{ 197272343Sngie FLAVOR=mtree convert_C_S_head 198272343Sngie} 199272343Sngienetbsd6_convert_C_S_head() 200272343Sngie{ 201272343Sngie FLAVOR=netbsd6 convert_C_S_head 202272343Sngie} 203272343Sngie 204272343Sngiemtree_convert_C_S_body() 205272343Sngie{ 206272343Sngie FLAVOR=mtree convert_C_S_body 207272343Sngie} 208272343Sngienetbsd6_convert_C_S_body() 209272343Sngie{ 210272343Sngie FLAVOR=netbsd6 convert_C_S_body 211272343Sngie} 212272343Sngie 213272343Sngie 214272343Sngieatf_test_case mtree_convert_D 215272343Sngieatf_test_case netbsd6_convert_D 216272343Sngieconvert_D_head() 217272343Sngie{ 218272343Sngie atf_set "descr" "Convert a specfile to mtree -D format, unsorted" 219272343Sngie} 220272343Sngie 221272343Sngieconvert_D_body() 222272343Sngie{ 223272343Sngie mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output 224272343Sngie h_check "$(atf_get_srcdir)/d_convert_D.out" output 225272343Sngie} 226272343Sngie 227272343Sngiemtree_convert_D_head() 228272343Sngie{ 229272343Sngie FLAVOR=mtree convert_D_head 230272343Sngie} 231272343Sngienetbsd6_convert_D_head() 232272343Sngie{ 233272343Sngie FLAVOR=netbsd6 convert_D_head 234272343Sngie} 235272343Sngie 236272343Sngiemtree_convert_D_body() 237272343Sngie{ 238272343Sngie FLAVOR=mtree convert_D_body 239272343Sngie} 240272343Sngienetbsd6_convert_D_body() 241272343Sngie{ 242272343Sngie FLAVOR=netbsd6 convert_D_body 243272343Sngie} 244272343Sngie 245272343Sngie 246272343Sngieatf_test_case mtree_convert_D_S 247272343Sngieatf_test_case netbsd6_convert_D_S 248272343Sngieconvert_D_S_head() 249272343Sngie{ 250272343Sngie atf_set "descr" "Convert a specfile to mtree -D format, sorted" 251272343Sngie} 252272343Sngie 253272343Sngieconvert_D_S_body() 254272343Sngie{ 255272343Sngie mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output 256272343Sngie h_check "$(atf_get_srcdir)/d_convert_D_S.out" output 257272343Sngie} 258272343Sngie 259272343Sngiemtree_convert_D_S_head() 260272343Sngie{ 261272343Sngie FLAVOR=mtree convert_D_S_head 262272343Sngie} 263272343Sngienetbsd6_convert_D_S_head() 264272343Sngie{ 265272343Sngie FLAVOR=netbsd6 convert_D_S_head 266272343Sngie} 267272343Sngie 268272343Sngiemtree_convert_D_S_body() 269272343Sngie{ 270272343Sngie FLAVOR=mtree convert_D_S_body 271272343Sngie} 272272343Sngienetbsd6_convert_D_S_body() 273272343Sngie{ 274272343Sngie FLAVOR=netbsd6 convert_D_S_body 275272343Sngie} 276272343Sngie 277272343Sngie 278272343Sngieatf_test_case mtree_ignore 279272343Sngieatf_test_case netbs6_ignore 280272343Sngieignore_head() 281272343Sngie{ 282272343Sngie atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)" 283272343Sngie} 284272343Sngie 285272343Sngieignore_body() 286272343Sngie{ 287273928Sjmmv # Kyua 0.11 and above point TMPDIR to our work directory and atf-check 288273928Sjmmv # generates a temporary file, which confuses mtree. Put the mtree files 289273928Sjmmv # into a subdirectory. 290273928Sjmmv # 291273928Sjmmv # See https://github.com/jmmv/kyua/issues/133 for details. 292273928Sjmmv mkdir root && cd root 293273928Sjmmv 294272343Sngie mkdir newdir 295272343Sngie mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec 296272343Sngie ln -s newdir otherdir 297272343Sngie 298272343Sngie # This yields "extra: otherdir" even with -d. 299272343Sngie # (PR bin/41061) 300272343Sngie atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec" 301272343Sngie 302272343Sngie # Delete the symlink and re-verify. 303272343Sngie # 304272343Sngie rm otherdir 305272343Sngie atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec" 306272343Sngie} 307272343Sngie 308272343Sngiemtree_ignore_head() 309272343Sngie{ 310272343Sngie FLAVOR=mtree ignore_head 311272343Sngie} 312272343Sngienetbsd6_ignore_head() 313272343Sngie{ 314272343Sngie FLAVOR=netbsd6 ignore_head 315272343Sngie} 316272343Sngie 317272343Sngiemtree_ignore_body() 318272343Sngie{ 319272343Sngie FLAVOR=mtree ignore_body 320272343Sngie} 321272343Sngienetbsd6_ignore_body() 322272343Sngie{ 323273928Sjmmv # Kyua 0.11 and above point TMPDIR to our work directory and atf-check 324273928Sjmmv # generates a temporary file, which confuses mtree. Put the mtree files 325273928Sjmmv # into a subdirectory. 326273928Sjmmv # 327273928Sjmmv # See https://github.com/jmmv/kyua/issues/133 for details. 328273928Sjmmv mkdir root && cd root 329273928Sjmmv 330272343Sngie FLAVOR=netbsd6 ignore_body 331272343Sngie} 332272343Sngie 333272343Sngie 334272343Sngieatf_test_case mtree_merge 335272343Sngieatf_test_case netbsd6_merge 336272343Sngiemerge_head() 337272343Sngie{ 338272343Sngie atf_set "descr" "Merge records of different type" 339272343Sngie} 340272343Sngie 341272343Sngiemerge_body() 342272343Sngie{ 343272343Sngie mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output 344272343Sngie h_check "$(atf_get_srcdir)/d_merge_C_M.out" output 345272343Sngie # same again, with sorting 346272343Sngie mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output 347272343Sngie h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output 348272343Sngie} 349272343Sngie 350272343Sngiemtree_merge_head() 351272343Sngie{ 352272343Sngie FLAVOR=mtree merge_head 353272343Sngie} 354272343Sngienetbsd6_merge_head() 355272343Sngie{ 356272343Sngie FLAVOR=netbsd6 merge_head 357272343Sngie} 358272343Sngie 359272343Sngiemtree_merge_body() 360272343Sngie{ 361272343Sngie FLAVOR=mtree merge_body 362272343Sngie} 363272343Sngienetbsd6_merge_body() 364272343Sngie{ 365272343Sngie FLAVOR=netbsd6 merge_body 366272343Sngie} 367272343Sngie 368272343Sngie 369272343Sngieatf_test_case mtree_nonemptydir 370272343Sngieatf_test_case netbsd6_nonemptydir 371272343Sngienonemptydir_head() 372272343Sngie{ 373272343Sngie atf_set "descr" "Test that new non-empty " \ 374272343Sngie "directories are recorded (PR bin/25693)" 375272343Sngie} 376272343Sngie 377272343Sngienonemptydir_body() 378272343Sngie{ 379272343Sngie mkdir testdir 380272343Sngie cd testdir 381272343Sngie 382272343Sngie mtree -F ${FLAVOR} -c > mtree.spec 383272343Sngie 384272343Sngie if [ ! -f mtree.spec ]; then 385272343Sngie atf_fail "mtree failed" 386272343Sngie fi 387272343Sngie 388272343Sngie touch bar 389272343Sngie atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec" 390272343Sngie 391272343Sngie if [ ! -n "$(egrep "extra: bar" output)" ]; then 392272343Sngie atf_fail "mtree did not record changes (PR bin/25693)" 393272343Sngie fi 394272343Sngie} 395272343Sngie 396272343Sngiemtree_nonemptydir_head() 397272343Sngie{ 398272343Sngie FLAVOR=mtree nonemptydir_head 399272343Sngie} 400272343Sngienetbsd6_nonemptydir_head() 401272343Sngie{ 402272343Sngie FLAVOR=netbsd6 nonemptydir_head 403272343Sngie} 404272343Sngie 405272343Sngiemtree_nonemptydir_body() 406272343Sngie{ 407272343Sngie FLAVOR=mtree nonemptydir_body 408272343Sngie} 409272343Sngienetbsd6_nonemptydir_body() 410272343Sngie{ 411272343Sngie FLAVOR=netbsd6 nonemptydir_body 412272343Sngie} 413272343Sngie 414272343Sngie 415272343Sngieatf_init_test_cases() 416272343Sngie{ 417272343Sngie atf_add_test_case mtree_create 418272343Sngie atf_add_test_case mtree_check 419272343Sngie atf_add_test_case mtree_convert_C 420272343Sngie atf_add_test_case mtree_convert_C_S 421272343Sngie atf_add_test_case mtree_convert_D 422272343Sngie atf_add_test_case mtree_convert_D_S 423272343Sngie atf_add_test_case mtree_ignore 424272343Sngie atf_add_test_case mtree_merge 425272343Sngie atf_add_test_case mtree_nonemptydir 426272343Sngie 427272343Sngie atf_add_test_case netbsd6_create 428272343Sngie atf_add_test_case netbsd6_check 429272343Sngie atf_add_test_case netbsd6_convert_C 430272343Sngie atf_add_test_case netbsd6_convert_C_S 431272343Sngie atf_add_test_case netbsd6_convert_D 432272343Sngie atf_add_test_case netbsd6_convert_D_S 433272343Sngie atf_add_test_case netbsd6_ignore 434272343Sngie atf_add_test_case netbsd6_merge 435272343Sngie atf_add_test_case netbsd6_nonemptydir 436272343Sngie} 437