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 27MAKEFS="makefs -t ffs" 28MOUNT="mount" 29 30. "$(dirname "$0")/makefs_tests_common.sh" 31 32TEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output 33 34common_cleanup() 35{ 36 if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then 37 echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" 38 return 39 fi 40 41 umount -f /dev/$test_md_device || : 42 mdconfig -d -u $test_md_device || : 43} 44 45check_ffs_image_contents() 46{ 47 atf_check -e save:$TEST_TUNEFS_OUTPUT \ 48 tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE) 49 50 check_image_contents "$@" 51} 52 53# With no -M, -m, or -s options, makefs should autocalculate the image size 54atf_test_case autocalculate_image_size cleanup 55autocalculate_image_size_body() 56{ 57 create_test_inputs 58 59 atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR 60 61 cd $TEST_INPUTS_DIR 62 atf_check -o not-empty $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE 63 cd - 64 65 mount_image 66 check_ffs_image_contents 67} 68autocalculate_image_size_cleanup() 69{ 70 common_cleanup 71} 72 73atf_test_case D_flag 74D_flag_body() 75{ 76 create_test_inputs 77 78 create_manifest_file 79 80 # Check that it works 81 atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE 82 83 # Duplicate entries in the manifest file 84 cp $TEST_SPEC_FILE spec2.mtree 85 cat $TEST_SPEC_FILE spec2.mtree | sort > "${TEST_SPEC_FILE}_dupe" 86 87 # Check that it errors 88 atf_check -e not-empty -s not-exit:0 \ 89 $MAKEFS -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe 90 # Check that it warns 91 atf_check -e not-empty -o not-empty \ 92 $MAKEFS -D -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe 93} 94 95atf_test_case F_flag cleanup 96F_flag_body() 97{ 98 create_test_inputs 99 100 atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR 101 102 atf_check -o not-empty \ 103 $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 104 105 mount_image 106 check_ffs_image_contents 107} 108F_flag_cleanup() 109{ 110 common_cleanup 111} 112 113atf_test_case from_mtree_spec_file cleanup 114from_mtree_spec_file_body() 115{ 116 create_test_inputs 117 118 atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR 119 120 cd $TEST_INPUTS_DIR 121 atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE 122 cd - 123 124 mount_image 125 check_ffs_image_contents 126} 127from_mtree_spec_file_cleanup() 128{ 129 common_cleanup 130} 131 132atf_test_case from_multiple_dirs cleanup 133from_multiple_dirs_body() 134{ 135 test_inputs_dir2=$TMPDIR/inputs2 136 137 create_test_inputs 138 139 atf_check mkdir -p $test_inputs_dir2 140 atf_check touch $test_inputs_dir2/multiple_dirs_test_file 141 142 atf_check -o not-empty \ 143 $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 144 145 mount_image 146 check_image_contents -d $test_inputs_dir2 147} 148from_multiple_dirs_cleanup() 149{ 150 common_cleanup 151} 152 153atf_test_case from_single_dir cleanup 154from_single_dir_body() 155{ 156 create_test_inputs 157 158 atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 159 160 mount_image 161 check_ffs_image_contents 162} 163from_single_dir_cleanup() 164{ 165 common_cleanup 166} 167 168atf_test_case o_flag_version_1 cleanup 169o_flag_version_1_body() 170{ 171 ffs_version=1 172 173 platform=$(uname) 174 case "$platform" in 175 FreeBSD) 176 ffs_label=UFS${ffs_version} 177 ;; 178 NetBSD) 179 ffs_label=FFSv${ffs_version} 180 ;; 181 *) 182 atf_skip "Unsupported platform" 183 ;; 184 esac 185 186 create_test_inputs 187 188 atf_check -o not-empty \ 189 $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 190 191 mount_image 192 atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 193 check_ffs_image_contents 194} 195o_flag_version_1_cleanup() 196{ 197 common_cleanup 198} 199 200atf_test_case o_flag_version_2 cleanup 201o_flag_version_2_body() 202{ 203 ffs_version=2 204 205 platform=$(uname) 206 case "$platform" in 207 FreeBSD) 208 ffs_label=UFS${ffs_version} 209 ;; 210 NetBSD) 211 ffs_label=FFSv${ffs_version} 212 ;; 213 *) 214 atf_skip "Unsupported platform" 215 ;; 216 esac 217 218 create_test_inputs 219 220 atf_check -o not-empty \ 221 $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 222 223 mount_image 224 atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 225 check_ffs_image_contents 226} 227o_flag_version_2_cleanup() 228{ 229 common_cleanup 230} 231 232 233atf_test_case T_flag_dir cleanup 234T_flag_dir_body() 235{ 236 timestamp=1742574909 237 create_test_dirs 238 239 mkdir -p $TEST_INPUTS_DIR/dir1 240 atf_check -o not-empty \ 241 $MAKEFS -M 1m -T $timestamp $TEST_IMAGE $TEST_INPUTS_DIR 242 243 mount_image 244 eval $(stat -s $TEST_MOUNT_DIR/dir1) 245 atf_check_equal $st_atime $timestamp 246 atf_check_equal $st_mtime $timestamp 247 atf_check_equal $st_ctime $timestamp 248} 249 250T_flag_dir_cleanup() 251{ 252 common_cleanup 253} 254 255atf_test_case T_flag_F_flag cleanup 256T_flag_F_flag_body() 257{ 258 timestamp_F=1742574909 259 timestamp_T=1742574910 260 create_test_dirs 261 mkdir -p $TEST_INPUTS_DIR/dir1 262 263 atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR 264 change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F 265 atf_check -o not-empty \ 266 $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 267 268 mount_image 269 eval $(stat -s $TEST_MOUNT_DIR/dir1) 270 atf_check_equal $st_atime $timestamp_F 271 atf_check_equal $st_mtime $timestamp_F 272 # atf_check_equal $st_ctime $timestamp_F 273} 274 275T_flag_F_flag_cleanup() 276{ 277 common_cleanup 278} 279 280atf_test_case T_flag_mtree cleanup 281T_flag_mtree_body() 282{ 283 timestamp=1742574909 284 create_test_dirs 285 mkdir -p $TEST_INPUTS_DIR/dir1 286 287 atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR 288 atf_check -o not-empty \ 289 $MAKEFS -M 1m -T $timestamp $TEST_IMAGE $TEST_SPEC_FILE 290 291 mount_image 292 eval $(stat -s $TEST_MOUNT_DIR/dir1) 293 atf_check_equal $st_atime $timestamp 294 atf_check_equal $st_mtime $timestamp 295 atf_check_equal $st_ctime $timestamp 296} 297 298T_flag_mtree_cleanup() 299{ 300 common_cleanup 301} 302 303atf_init_test_cases() 304{ 305 atf_add_test_case autocalculate_image_size 306 307 atf_add_test_case D_flag 308 atf_add_test_case F_flag 309 310 atf_add_test_case from_mtree_spec_file 311 atf_add_test_case from_multiple_dirs 312 atf_add_test_case from_single_dir 313 314 atf_add_test_case o_flag_version_1 315 atf_add_test_case o_flag_version_2 316 atf_add_test_case T_flag_dir 317 atf_add_test_case T_flag_F_flag 318 atf_add_test_case T_flag_mtree 319} 320