1289694Sngie# 2289694Sngie# Copyright 2015 EMC Corp. 3289694Sngie# All rights reserved. 4289694Sngie# 5289694Sngie# Redistribution and use in source and binary forms, with or without 6289694Sngie# modification, are permitted provided that the following conditions are 7289694Sngie# met: 8289694Sngie# 9289694Sngie# * Redistributions of source code must retain the above copyright 10289694Sngie# notice, this list of conditions and the following disclaimer. 11289694Sngie# * Redistributions in binary form must reproduce the above copyright 12289694Sngie# notice, this list of conditions and the following disclaimer in the 13289694Sngie# documentation and/or other materials provided with the distribution. 14289694Sngie# 15289694Sngie# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16289694Sngie# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17289694Sngie# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18289694Sngie# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19289694Sngie# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20289694Sngie# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21289694Sngie# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22289694Sngie# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23289694Sngie# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24289694Sngie# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25289694Sngie# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26289694Sngie# 27289694Sngie# $FreeBSD: stable/11/usr.sbin/makefs/tests/makefs_cd9660_tests.sh 322690 2017-08-19 01:45:02Z ngie $ 28289694Sngie# 29289694Sngie 30289897Sngie# A note on specs: 31289897Sngie# - A copy of the ISO-9660 spec can be found here: 32289897Sngie# http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf 33289897Sngie# - Any references to `rockridge` are referring to the `Rock Ridge` extensions 34289897Sngie# of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found 35289897Sngie# here: 36289897Sngie# http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf 37289694Sngie 38289694SngieMAKEFS="makefs -t cd9660" 39289897SngieMOUNT="mount_cd9660" 40289694Sngie 41289897Sngie. "$(dirname "$0")/makefs_tests_common.sh" 42289897Sngie 43289897Sngiecommon_cleanup() 44289694Sngie{ 45289897Sngie if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then 46289897Sngie echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" 47289897Sngie return 48289897Sngie fi 49289897Sngie 50289897Sngie umount -f /dev/$test_md_device || : 51289897Sngie mdconfig -d -u $test_md_device || : 52289897Sngie} 53289897Sngie 54289897Sngiecheck_base_iso9660_image_contents() 55289897Sngie{ 56289897Sngie # Symlinks are treated like files when rockridge support isn't 57289897Sngie # specified 58289897Sngie check_image_contents "$@" -X c 59289897Sngie 60289897Sngie atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c 61289897Sngie atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c 62289897Sngie} 63289897Sngie 64289897Sngieatf_test_case D_flag cleanup 65289897SngieD_flag_body() 66289897Sngie{ 67289897Sngie atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839" 68289897Sngie 69289694Sngie create_test_inputs 70289694Sngie 71289897Sngie atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 72289897Sngie mtree -cp $TEST_INPUTS_DIR 73289897Sngie atf_check -e empty -o not-empty -s exit:0 \ 74289897Sngie $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 75289897Sngie 76289694Sngie atf_check -e empty -o empty -s exit:0 \ 77289897Sngie cp $TEST_SPEC_FILE spec2.mtree 78289897Sngie atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \ 79289897Sngie cat $TEST_SPEC_FILE spec2.mtree 80289897Sngie 81289897Sngie atf_check -e empty -o not-empty -s not-exit:0 \ 82289897Sngie $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 83289897Sngie atf_check -e empty -o not-empty -s exit:0 \ 84289897Sngie $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 85289897Sngie} 86289897SngieD_flag_cleanup() 87289897Sngie{ 88289897Sngie common_cleanup 89289897Sngie} 90289897Sngie 91289897Sngieatf_test_case F_flag cleanup 92289897SngieF_flag_body() 93289897Sngie{ 94289897Sngie create_test_inputs 95289897Sngie 96289897Sngie atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 97289897Sngie mtree -cp $TEST_INPUTS_DIR 98289897Sngie 99289897Sngie atf_check -e empty -o empty -s exit:0 \ 100289897Sngie $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 101289897Sngie 102289897Sngie mount_image 103289897Sngie check_base_iso9660_image_contents 104289897Sngie} 105289897SngieF_flag_cleanup() 106289897Sngie{ 107289897Sngie common_cleanup 108289897Sngie} 109289897Sngie 110289897Sngieatf_test_case from_mtree_spec_file cleanup 111289897Sngiefrom_mtree_spec_file_body() 112289897Sngie{ 113289897Sngie create_test_inputs 114289897Sngie 115289897Sngie atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 116290267Sngie mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 117289897Sngie cd $TEST_INPUTS_DIR 118289897Sngie atf_check -e empty -o empty -s exit:0 \ 119289897Sngie $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE 120289897Sngie cd - 121289897Sngie 122289897Sngie mount_image 123289897Sngie check_base_iso9660_image_contents 124289897Sngie} 125289897Sngiefrom_mtree_spec_file_cleanup() 126289897Sngie{ 127289897Sngie common_cleanup 128289897Sngie} 129289897Sngie 130289897Sngieatf_test_case from_multiple_dirs cleanup 131289897Sngiefrom_multiple_dirs_body() 132289897Sngie{ 133289897Sngie test_inputs_dir2=$TMPDIR/inputs2 134289897Sngie 135289897Sngie create_test_inputs 136289897Sngie 137289897Sngie atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2 138289897Sngie atf_check -e empty -o empty -s exit:0 \ 139289897Sngie touch $test_inputs_dir2/multiple_dirs_test_file 140289897Sngie 141289897Sngie atf_check -e empty -o empty -s exit:0 \ 142289897Sngie $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 143289897Sngie 144289897Sngie mount_image 145289897Sngie check_base_iso9660_image_contents -d $test_inputs_dir2 146289897Sngie} 147289897Sngiefrom_multiple_dirs_cleanup() 148289897Sngie{ 149289897Sngie common_cleanup 150289897Sngie} 151289897Sngie 152289897Sngieatf_test_case from_single_dir cleanup 153289897Sngiefrom_single_dir_body() 154289897Sngie{ 155289897Sngie create_test_inputs 156289897Sngie 157289897Sngie atf_check -e empty -o empty -s exit:0 \ 158289694Sngie $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR 159289897Sngie 160289897Sngie mount_image 161289897Sngie check_base_iso9660_image_contents 162289897Sngie} 163289897Sngiefrom_single_dir_cleanup() 164289897Sngie{ 165289897Sngie common_cleanup 166289897Sngie} 167289897Sngie 168289897Sngieatf_test_case o_flag_allow_deep_trees cleanup 169289897Sngieo_flag_allow_deep_trees_body() 170289897Sngie{ 171289897Sngie create_test_inputs 172289897Sngie 173289897Sngie # Make sure the "more than 8 levels deep" requirement is met. 174289694Sngie atf_check -e empty -o empty -s exit:0 \ 175289897Sngie mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j 176289897Sngie 177289743Sngie atf_check -e empty -o empty -s exit:0 \ 178289897Sngie $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR 179289897Sngie 180289897Sngie mount_image 181289897Sngie check_base_iso9660_image_contents 182289694Sngie} 183289897Sngieo_flag_allow_deep_trees_cleanup() 184289694Sngie{ 185289897Sngie common_cleanup 186289897Sngie} 187289694Sngie 188289897Sngieatf_test_case o_flag_allow_max_name cleanup 189289897Sngieo_flag_allow_max_name_body() 190289897Sngie{ 191289897Sngie atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]" 192289897Sngie 193289897Sngie create_test_inputs 194289897Sngie 195289897Sngie long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37) 196289897Sngie 197289897Sngie # Make sure the "37 char name" limit requirement is met. 198289897Sngie atf_check -e empty -o empty -s exit:0 touch $long_path 199289897Sngie 200289897Sngie atf_check -e empty -o empty -s exit:0 \ 201289897Sngie $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR 202289897Sngie 203289897Sngie mount_image 204289897Sngie check_base_iso9660_image_contents 205289694Sngie} 206289897Sngieo_flag_allow_max_name_cleanup() 207289897Sngie{ 208289897Sngie common_cleanup 209289897Sngie} 210289694Sngie 211290265Sngieatf_test_case o_flag_isolevel_1 cleanup 212290265Sngieo_flag_isolevel_1_body() 213290265Sngie{ 214290265Sngie atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt" 215290265Sngie 216290265Sngie create_test_inputs 217290265Sngie 218290265Sngie atf_check -e empty -o empty -s exit:0 \ 219290265Sngie $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR 220290265Sngie 221290265Sngie mount_image 222290265Sngie check_base_iso9660_image_contents 223290265Sngie} 224290265Sngieo_flag_isolevel_1_cleanup() 225290265Sngie{ 226290265Sngie common_cleanup 227290265Sngie} 228290265Sngie 229290265Sngieatf_test_case o_flag_isolevel_2 cleanup 230290265Sngieo_flag_isolevel_2_body() 231290265Sngie{ 232290265Sngie create_test_inputs 233290265Sngie 234290265Sngie atf_check -e empty -o empty -s exit:0 \ 235290265Sngie $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR 236290265Sngie 237290265Sngie mount_image 238290265Sngie check_base_iso9660_image_contents 239290265Sngie} 240290265Sngieo_flag_isolevel_2_cleanup() 241290265Sngie{ 242290265Sngie common_cleanup 243290265Sngie} 244290265Sngie 245290265Sngieatf_test_case o_flag_isolevel_3 cleanup 246290265Sngieo_flag_isolevel_3_body() 247290265Sngie{ 248290265Sngie create_test_inputs 249290265Sngie 250290265Sngie # XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645 251290265Sngie if true; then 252290265Sngie atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \ 253290265Sngie $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR 254290265Sngie else 255290265Sngie atf_check -e empty -o empty -s exit:0 \ 256290265Sngie $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR 257290265Sngie mount_image 258290265Sngie check_base_iso9660_image_contents 259290265Sngie fi 260290265Sngie} 261290265Sngieo_flag_isolevel_3_cleanup() 262290265Sngie{ 263290265Sngie common_cleanup 264290265Sngie} 265290265Sngie 266289897Sngieatf_test_case o_flag_preparer 267322690Sngieo_flag_preparer_head() 268322690Sngie{ 269322690Sngie atf_set "require.progs" "strings" 270322690Sngie} 271289897Sngieo_flag_preparer_body() 272289897Sngie{ 273289897Sngie create_test_dirs 274289897Sngie 275289897Sngie preparer='My Very First ISO' 276289897Sngie preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')" 277289897Sngie 278289897Sngie atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file 279289897Sngie atf_check -e empty -o empty -s exit:0 \ 280289897Sngie $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR 281289897Sngie atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \ 282289897Sngie strings $TEST_IMAGE 283289897Sngie} 284289897Sngie 285289897Sngieatf_test_case o_flag_publisher 286322690Sngieo_flag_publisher_head() 287322690Sngie{ 288322690Sngie atf_set "require.progs" "strings" 289322690Sngie} 290289897Sngieo_flag_publisher_body() 291289897Sngie{ 292289897Sngie create_test_dirs 293289897Sngie 294289897Sngie publisher='My Super Awesome Publishing Company LTD' 295289897Sngie publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')" 296289897Sngie 297289897Sngie atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file 298289897Sngie atf_check -e empty -o empty -s exit:0 \ 299289897Sngie $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR 300289897Sngie atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \ 301289897Sngie strings $TEST_IMAGE 302289897Sngie} 303289897Sngie 304289897Sngieatf_test_case o_flag_rockridge cleanup 305289897Sngieo_flag_rockridge_body() 306289897Sngie{ 307289897Sngie create_test_dirs 308289897Sngie 309289897Sngie # Make sure the "more than 8 levels deep" requirement is met. 310289897Sngie atf_check -e empty -o empty -s exit:0 \ 311289897Sngie mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j 312289897Sngie 313289897Sngie # Make sure the "pathname larger than 255 chars" requirement is met. 314289897Sngie # 315289897Sngie # $long_path's needs to be nested in a directory, as creating it 316289897Sngie # outright as a 256 char filename via touch will fail with ENAMETOOLONG 317289897Sngie long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4) 318289897Sngie atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)" 319289897Sngie atf_check -e empty -o empty -s exit:0 touch "$long_path" 320289897Sngie 321289897Sngie atf_check -e empty -o empty -s exit:0 \ 322289897Sngie $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR 323289897Sngie 324289897Sngie mount_image 325289897Sngie check_image_contents -X .rr_moved 326289897Sngie 327289897Sngie # .rr_moved is a special directory created when you have deep directory 328289897Sngie # trees with rock ridge extensions on 329289897Sngie atf_check -e empty -o empty -s exit:0 \ 330289897Sngie test -d $TEST_MOUNT_DIR/.rr_moved 331289897Sngie} 332289897Sngieo_flag_rockridge_cleanup() 333289897Sngie{ 334289897Sngie common_cleanup 335289897Sngie} 336289897Sngie 337289902Sngieatf_test_case o_flag_rockridge_dev_nodes cleanup 338289902Sngieo_flag_rockridge_dev_nodes_head() 339289902Sngie{ 340289902Sngie atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)" 341289902Sngie} 342289902Sngieo_flag_rockridge_dev_nodes_body() 343289902Sngie{ 344289902Sngie create_test_dirs 345289902Sngie 346289902Sngie (tar -cvf - -C /dev null && touch .tar_ok) | \ 347289902Sngie atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR" 348289902Sngie 349289902Sngie atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null 350289902Sngie atf_check -e empty -o empty -s exit:0 test -f .tar_ok 351289902Sngie 352289902Sngie atf_check -e empty -o empty -s exit:0 \ 353289902Sngie $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR 354289902Sngie 355289902Sngie mount_image 356289902Sngie check_image_contents 357289902Sngie} 358289902Sngieo_flag_rockridge_dev_nodes_cleanup() 359289902Sngie{ 360289902Sngie common_cleanup 361289902Sngie} 362289902Sngie 363289694Sngieatf_init_test_cases() 364289694Sngie{ 365289897Sngie atf_add_test_case D_flag 366289897Sngie atf_add_test_case F_flag 367289694Sngie 368289897Sngie atf_add_test_case from_mtree_spec_file 369289897Sngie atf_add_test_case from_multiple_dirs 370289897Sngie atf_add_test_case from_single_dir 371289897Sngie 372289897Sngie atf_add_test_case o_flag_allow_deep_trees 373289897Sngie atf_add_test_case o_flag_allow_max_name 374290265Sngie atf_add_test_case o_flag_isolevel_1 375290265Sngie atf_add_test_case o_flag_isolevel_2 376290265Sngie atf_add_test_case o_flag_isolevel_3 377289897Sngie atf_add_test_case o_flag_preparer 378289897Sngie atf_add_test_case o_flag_publisher 379289897Sngie atf_add_test_case o_flag_rockridge 380289902Sngie atf_add_test_case o_flag_rockridge_dev_nodes 381289694Sngie} 382