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# 28 29MAKEFS="makefs -t ffs" 30MOUNT="mount" 31 32. "$(dirname "$0")/makefs_tests_common.sh" 33 34TEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output 35 36common_cleanup() 37{ 38 if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then 39 echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" 40 return 41 fi 42 43 umount -f /dev/$test_md_device || : 44 mdconfig -d -u $test_md_device || : 45} 46 47check_ffs_image_contents() 48{ 49 atf_check -e save:$TEST_TUNEFS_OUTPUT -o empty -s exit:0 \ 50 tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE) 51 52 check_image_contents "$@" 53} 54 55# With no -M, -m, or -s options, makefs should autocalculate the image size 56atf_test_case autocalculate_image_size cleanup 57autocalculate_image_size_body() 58{ 59 create_test_inputs 60 61 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 62 mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 63 64 cd $TEST_INPUTS_DIR 65 atf_check -e empty -o not-empty -s exit:0 \ 66 $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE 67 cd - 68 69 mount_image 70 check_ffs_image_contents 71} 72autocalculate_image_size_cleanup() 73{ 74 common_cleanup 75} 76 77atf_test_case D_flag cleanup 78D_flag_body() 79{ 80 atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839" 81 82 create_test_inputs 83 84 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 85 mtree -cp $TEST_INPUTS_DIR 86 atf_check -e empty -o not-empty -s exit:0 \ 87 $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 88 89 atf_check -e empty -o empty -s exit:0 \ 90 cp $TEST_SPEC_FILE spec2.mtree 91 atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \ 92 cat $TEST_SPEC_FILE spec2.mtree 93 94 atf_check -e empty -o not-empty -s not-exit:0 \ 95 $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 96 atf_check -e empty -o not-empty -s exit:0 \ 97 $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 98} 99D_flag_cleanup() 100{ 101 common_cleanup 102} 103 104atf_test_case F_flag cleanup 105F_flag_body() 106{ 107 create_test_inputs 108 109 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 110 mtree -cp $TEST_INPUTS_DIR 111 112 atf_check -e empty -o not-empty -s exit:0 \ 113 $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 114 115 mount_image 116 check_ffs_image_contents 117} 118F_flag_cleanup() 119{ 120 common_cleanup 121} 122 123atf_test_case from_mtree_spec_file cleanup 124from_mtree_spec_file_body() 125{ 126 create_test_inputs 127 128 atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 129 mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 130 131 cd $TEST_INPUTS_DIR 132 atf_check -e empty -o not-empty -s exit:0 \ 133 $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE 134 cd - 135 136 mount_image 137 check_ffs_image_contents 138} 139from_mtree_spec_file_cleanup() 140{ 141 common_cleanup 142} 143 144atf_test_case from_multiple_dirs cleanup 145from_multiple_dirs_body() 146{ 147 test_inputs_dir2=$TMPDIR/inputs2 148 149 create_test_inputs 150 151 atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2 152 atf_check -e empty -o empty -s exit:0 \ 153 touch $test_inputs_dir2/multiple_dirs_test_file 154 155 atf_check -e empty -o not-empty -s exit:0 \ 156 $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 157 158 mount_image 159 check_image_contents -d $test_inputs_dir2 160} 161from_multiple_dirs_cleanup() 162{ 163 common_cleanup 164} 165 166atf_test_case from_single_dir cleanup 167from_single_dir_body() 168{ 169 create_test_inputs 170 171 atf_check -e empty -o not-empty -s exit:0 \ 172 $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 173 174 mount_image 175 check_ffs_image_contents 176} 177from_single_dir_cleanup() 178{ 179 common_cleanup 180} 181 182atf_test_case o_flag_version_1 cleanup 183o_flag_version_1_body() 184{ 185 ffs_version=1 186 187 platform=$(uname) 188 case "$platform" in 189 FreeBSD) 190 ffs_label=UFS${ffs_version} 191 ;; 192 NetBSD) 193 ffs_label=FFSv${ffs_version} 194 ;; 195 *) 196 atf_skip "Unsupported platform" 197 ;; 198 esac 199 200 create_test_inputs 201 202 atf_check -e empty -o not-empty -s exit:0 \ 203 $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 204 205 mount_image 206 atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 207 check_ffs_image_contents 208} 209o_flag_version_1_cleanup() 210{ 211 common_cleanup 212} 213 214atf_test_case o_flag_version_2 cleanup 215o_flag_version_2_body() 216{ 217 ffs_version=2 218 219 platform=$(uname) 220 case "$platform" in 221 FreeBSD) 222 ffs_label=UFS${ffs_version} 223 ;; 224 NetBSD) 225 ffs_label=FFSv${ffs_version} 226 ;; 227 *) 228 atf_skip "Unsupported platform" 229 ;; 230 esac 231 232 create_test_inputs 233 234 atf_check -e empty -o not-empty -s exit:0 \ 235 $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 236 237 mount_image 238 atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 239 check_ffs_image_contents 240} 241o_flag_version_2_cleanup() 242{ 243 common_cleanup 244} 245 246atf_init_test_cases() 247{ 248 249 atf_add_test_case autocalculate_image_size 250 251 atf_add_test_case D_flag 252 atf_add_test_case F_flag 253 254 atf_add_test_case from_mtree_spec_file 255 atf_add_test_case from_multiple_dirs 256 atf_add_test_case from_single_dir 257 258 atf_add_test_case o_flag_version_1 259 atf_add_test_case o_flag_version_2 260} 261