1# 2# Copyright 2015 EMC Corp. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# * Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# * 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 COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# $FreeBSD$ 28# 29 30# A note on specs: 31# - A copy of the ISO-9660 spec can be found here: 32# https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf 33# - Any references to `rockridge` are referring to the `Rock Ridge` extensions 34# of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found 35# here: 36# http://www.ymi.com/ymi/sites/default/files/pdf/Rockridge.pdf 37 38MAKEFS="makefs -t cd9660" 39MOUNT="mount_cd9660" 40 41. "$(dirname "$0")/makefs_tests_common.sh" 42 43common_cleanup() 44{ 45 if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then 46 echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" 47 return 48 fi 49 50 umount -f /dev/$test_md_device || : 51 mdconfig -d -u $test_md_device || : 52} 53 54check_base_iso9660_image_contents() 55{ 56 # Symlinks are treated like files when rockridge support isn't 57 # specified 58 check_image_contents "$@" -X c 59 60 atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c 61 atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c 62} 63 64check_cd9660_support() { 65 kldstat -m cd9660 || \ 66 atf_skip "Requires cd9660 filesystem support to be present in the kernel" 67} 68 69atf_test_case D_flag cleanup 70D_flag_body() 71{ 72 atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839" 73 74 create_test_inputs 75 76 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 77 mtree -cp $TEST_INPUTS_DIR 78 atf_check -e empty -o not-empty -s exit:0 \ 79 $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 80 81 atf_check -e empty -o empty -s exit:0 \ 82 cp $TEST_SPEC_FILE spec2.mtree 83 atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \ 84 cat $TEST_SPEC_FILE spec2.mtree 85 86 atf_check -e empty -o not-empty -s not-exit:0 \ 87 $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 88 atf_check -e empty -o not-empty -s exit:0 \ 89 $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 90} 91D_flag_cleanup() 92{ 93 common_cleanup 94} 95 96atf_test_case F_flag cleanup 97F_flag_body() 98{ 99 create_test_inputs 100 101 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 102 mtree -cp $TEST_INPUTS_DIR 103 104 atf_check -e empty -o empty -s exit:0 \ 105 $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 106 107 check_cd9660_support 108 mount_image 109 check_base_iso9660_image_contents 110} 111F_flag_cleanup() 112{ 113 common_cleanup 114} 115 116atf_test_case from_mtree_spec_file cleanup 117from_mtree_spec_file_body() 118{ 119 create_test_inputs 120 121 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 122 mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 123 cd $TEST_INPUTS_DIR 124 atf_check -e empty -o empty -s exit:0 \ 125 $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE 126 cd - 127 128 check_cd9660_support 129 mount_image 130 check_base_iso9660_image_contents 131} 132from_mtree_spec_file_cleanup() 133{ 134 common_cleanup 135} 136 137atf_test_case from_multiple_dirs cleanup 138from_multiple_dirs_body() 139{ 140 test_inputs_dir2=$TMPDIR/inputs2 141 142 create_test_inputs 143 144 atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2 145 atf_check -e empty -o empty -s exit:0 \ 146 touch $test_inputs_dir2/multiple_dirs_test_file 147 148 atf_check -e empty -o empty -s exit:0 \ 149 $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 150 151 check_cd9660_support 152 mount_image 153 check_base_iso9660_image_contents -d $test_inputs_dir2 154} 155from_multiple_dirs_cleanup() 156{ 157 common_cleanup 158} 159 160atf_test_case from_single_dir cleanup 161from_single_dir_body() 162{ 163 create_test_inputs 164 165 atf_check -e empty -o empty -s exit:0 \ 166 $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR 167 168 check_cd9660_support 169 mount_image 170 check_base_iso9660_image_contents 171} 172from_single_dir_cleanup() 173{ 174 common_cleanup 175} 176 177atf_test_case o_flag_allow_deep_trees cleanup 178o_flag_allow_deep_trees_body() 179{ 180 create_test_inputs 181 182 # Make sure the "more than 8 levels deep" requirement is met. 183 atf_check -e empty -o empty -s exit:0 \ 184 mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j 185 186 atf_check -e empty -o empty -s exit:0 \ 187 $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR 188 189 check_cd9660_support 190 mount_image 191 check_base_iso9660_image_contents 192} 193o_flag_allow_deep_trees_cleanup() 194{ 195 common_cleanup 196} 197 198atf_test_case o_flag_allow_max_name cleanup 199o_flag_allow_max_name_body() 200{ 201 atf_expect_fail "-o allow-max-name doesn't appear to be implemented on FreeBSD's copy of makefs [yet]" 202 203 create_test_inputs 204 205 long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37) 206 207 # Make sure the "37 char name" limit requirement is met. 208 atf_check -e empty -o empty -s exit:0 touch $long_path 209 210 atf_check -e empty -o empty -s exit:0 \ 211 $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR 212 213 check_cd9660_support 214 mount_image 215 check_base_iso9660_image_contents 216} 217o_flag_allow_max_name_cleanup() 218{ 219 common_cleanup 220} 221 222atf_test_case o_flag_isolevel_1 cleanup 223o_flag_isolevel_1_body() 224{ 225 atf_expect_fail "this testcase needs work; the filenames generated seem incorrect/corrupt" 226 227 create_test_inputs 228 229 atf_check -e empty -o empty -s exit:0 \ 230 $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR 231 232 check_cd9660_support 233 mount_image 234 check_base_iso9660_image_contents 235} 236o_flag_isolevel_1_cleanup() 237{ 238 common_cleanup 239} 240 241atf_test_case o_flag_isolevel_2 cleanup 242o_flag_isolevel_2_body() 243{ 244 create_test_inputs 245 246 atf_check -e empty -o empty -s exit:0 \ 247 $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR 248 249 check_cd9660_support 250 mount_image 251 check_base_iso9660_image_contents 252} 253o_flag_isolevel_2_cleanup() 254{ 255 common_cleanup 256} 257 258atf_test_case o_flag_isolevel_3 cleanup 259o_flag_isolevel_3_body() 260{ 261 create_test_inputs 262 263 # XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645 264 if true; then 265 atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' -o empty -s not-exit:0 \ 266 $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR 267 else 268 atf_check -e empty -o empty -s exit:0 \ 269 $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR 270 271 check_cd9660_support 272 mount_image 273 check_base_iso9660_image_contents 274 fi 275} 276o_flag_isolevel_3_cleanup() 277{ 278 common_cleanup 279} 280 281atf_test_case o_flag_preparer 282o_flag_preparer_head() 283{ 284 atf_set "require.progs" "strings" 285} 286o_flag_preparer_body() 287{ 288 create_test_dirs 289 290 preparer='My Very First ISO' 291 preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')" 292 293 atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file 294 atf_check -e empty -o empty -s exit:0 \ 295 $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR 296 atf_check -e empty -o match:"$preparer_uppercase" -s exit:0 \ 297 strings $TEST_IMAGE 298} 299 300atf_test_case o_flag_publisher 301o_flag_publisher_head() 302{ 303 atf_set "require.progs" "strings" 304} 305o_flag_publisher_body() 306{ 307 create_test_dirs 308 309 publisher='My Super Awesome Publishing Company LTD' 310 publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')" 311 312 atf_check -e empty -o empty -s exit:0 touch $TEST_INPUTS_DIR/dummy_file 313 atf_check -e empty -o empty -s exit:0 \ 314 $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR 315 atf_check -e empty -o match:"$publisher_uppercase" -s exit:0 \ 316 strings $TEST_IMAGE 317} 318 319atf_test_case o_flag_rockridge cleanup 320o_flag_rockridge_body() 321{ 322 create_test_dirs 323 324 # Make sure the "more than 8 levels deep" requirement is met. 325 atf_check -e empty -o empty -s exit:0 \ 326 mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j 327 328 # Make sure the "pathname larger than 255 chars" requirement is met. 329 # 330 # $long_path's needs to be nested in a directory, as creating it 331 # outright as a 256 char filename via touch will fail with ENAMETOOLONG 332 long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4) 333 atf_check -e empty -o empty -s exit:0 mkdir -p "$(dirname $long_path)" 334 atf_check -e empty -o empty -s exit:0 touch "$long_path" 335 336 atf_check -e empty -o empty -s exit:0 \ 337 $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR 338 339 check_cd9660_support 340 mount_image 341 check_image_contents -X .rr_moved 342 343 # .rr_moved is a special directory created when you have deep directory 344 # trees with rock ridge extensions on 345 atf_check -e empty -o empty -s exit:0 \ 346 test -d $TEST_MOUNT_DIR/.rr_moved 347} 348o_flag_rockridge_cleanup() 349{ 350 common_cleanup 351} 352 353atf_test_case o_flag_rockridge_dev_nodes cleanup 354o_flag_rockridge_dev_nodes_head() 355{ 356 atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)" 357} 358o_flag_rockridge_dev_nodes_body() 359{ 360 create_test_dirs 361 362 (tar -cvf - -C /dev null && touch .tar_ok) | \ 363 atf_check -e not-empty -o empty -s exit:0 tar -xvf - -C "$TEST_INPUTS_DIR" 364 365 atf_check -e empty -o empty -s exit:0 test -c $TEST_INPUTS_DIR/null 366 atf_check -e empty -o empty -s exit:0 test -f .tar_ok 367 368 atf_check -e empty -o empty -s exit:0 \ 369 $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR 370 371 check_cd9660_support 372 mount_image 373 check_image_contents 374} 375o_flag_rockridge_dev_nodes_cleanup() 376{ 377 common_cleanup 378} 379 380atf_init_test_cases() 381{ 382 atf_add_test_case D_flag 383 atf_add_test_case F_flag 384 385 atf_add_test_case from_mtree_spec_file 386 atf_add_test_case from_multiple_dirs 387 atf_add_test_case from_single_dir 388 389 atf_add_test_case o_flag_allow_deep_trees 390 atf_add_test_case o_flag_allow_max_name 391 atf_add_test_case o_flag_isolevel_1 392 atf_add_test_case o_flag_isolevel_2 393 atf_add_test_case o_flag_isolevel_3 394 atf_add_test_case o_flag_preparer 395 atf_add_test_case o_flag_publisher 396 atf_add_test_case o_flag_rockridge 397 atf_add_test_case o_flag_rockridge_dev_nodes 398} 399