diff --git a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh index 21382684a96c..719c2045305f 100644 --- a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh +++ b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh @@ -1,460 +1,458 @@ # # Copyright 2015 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # A note on specs: # - A copy of the ISO-9660 spec can be found here: # https://ecma-international.org/wp-content/uploads/ECMA-119_5th_edition_december_2024.pdf # - Any references to `rockridge` are referring to the `Rock Ridge` extensions # of the ISO-9660 spec. A copy of the draft `IEEE-P1282` spec can be found # here: # https://people.freebsd.org/~emaste/rrip112.pdf MAKEFS="makefs -t cd9660" MOUNT="mount_cd9660" . "$(dirname "$0")/makefs_tests_common.sh" common_cleanup() { if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" return fi umount -f /dev/$test_md_device || : mdconfig -d -u $test_md_device || : } check_base_iso9660_image_contents() { # Symlinks are treated like files when rockridge support isn't # specified, and directories cannot contain a '.'. check_image_contents "$@" -X c -X .g -X _g atf_check test -L $TEST_INPUTS_DIR/c atf_check test -f $TEST_MOUNT_DIR/c } atf_test_case D_flag D_flag_body() { create_test_inputs create_manifest_file # Check that it works atf_check $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE # Duplicate entries in the manifest file cp $TEST_SPEC_FILE spec2.mtree cat $TEST_SPEC_FILE spec2.mtree | sort > "${TEST_SPEC_FILE}_dupe" # Check that it errors atf_check -e not-empty -s not-exit:0 \ $MAKEFS -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe # Check that it warns atf_check -e not-empty \ $MAKEFS -D -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe } atf_test_case F_flag cleanup F_flag_body() { create_test_inputs - atf_check -o save:$TEST_SPEC_FILE mtree -cp $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } F_flag_cleanup() { common_cleanup } atf_test_case from_mtree_spec_file cleanup from_mtree_spec_file_body() { create_test_inputs - atf_check -o save:$TEST_SPEC_FILE \ - mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR cd $TEST_INPUTS_DIR atf_check $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE cd - mount_image check_base_iso9660_image_contents } from_mtree_spec_file_cleanup() { common_cleanup } atf_test_case from_multiple_dirs cleanup from_multiple_dirs_body() { test_inputs_dir2=$TMPDIR/inputs2 create_test_inputs atf_check mkdir -p $test_inputs_dir2 atf_check touch $test_inputs_dir2/multiple_dirs_test_file atf_check $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 mount_image check_base_iso9660_image_contents -d $test_inputs_dir2 } from_multiple_dirs_cleanup() { common_cleanup } atf_test_case from_single_dir cleanup from_single_dir_body() { create_test_inputs atf_check $MAKEFS $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } from_single_dir_cleanup() { common_cleanup } atf_test_case o_flag_allow_deep_trees cleanup o_flag_allow_deep_trees_body() { create_test_inputs # Make sure the "more than 8 levels deep" requirement is met. atf_check mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j atf_check $MAKEFS -o allow-deep-trees $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } o_flag_allow_deep_trees_cleanup() { common_cleanup } atf_test_case o_flag_allow_max_name cleanup o_flag_allow_max_name_body() { atf_skip "-o allow-max-name is not implemented" create_test_inputs long_path=$TEST_INPUTS_DIR/$(jot -s '' -b 0 37) # Make sure the "37 char name" limit requirement is met. atf_check touch $long_path atf_check $MAKEFS -o allow-max-name $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } o_flag_allow_max_name_cleanup() { common_cleanup } atf_test_case o_flag_isolevel_1 cleanup o_flag_isolevel_1_body() { atf_skip "-o isolevel=1 is failing" create_test_inputs atf_check $MAKEFS -o isolevel=1 $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } o_flag_isolevel_1_cleanup() { common_cleanup } atf_test_case o_flag_isolevel_2 cleanup o_flag_isolevel_2_body() { create_test_inputs atf_check $MAKEFS -o isolevel=2 $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } o_flag_isolevel_2_cleanup() { common_cleanup } atf_test_case o_flag_isolevel_3 cleanup o_flag_isolevel_3_body() { # XXX: isolevel=3 isn't implemented yet. See FreeBSD bug # 203645 atf_check -e match:'makefs: ISO Level 3 is greater than 2\.' \ -s not-exit:0 \ $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR atf_skip "-o isolevel=3 is not implemented" create_test_inputs atf_check $MAKEFS -o isolevel=3 $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_base_iso9660_image_contents } o_flag_isolevel_3_cleanup() { common_cleanup } atf_test_case o_flag_preparer o_flag_preparer_head() { atf_set "require.progs" "strings" } o_flag_preparer_body() { create_test_dirs preparer='My Very First ISO' preparer_uppercase="$(echo $preparer | tr '[[:lower:]]' '[[:upper:]]')" atf_check touch $TEST_INPUTS_DIR/dummy_file atf_check $MAKEFS -o preparer="$preparer" $TEST_IMAGE $TEST_INPUTS_DIR atf_check -o match:"$preparer_uppercase" strings $TEST_IMAGE } atf_test_case o_flag_publisher o_flag_publisher_head() { atf_set "require.progs" "strings" } o_flag_publisher_body() { create_test_dirs publisher='My Super Awesome Publishing Company LTD' publisher_uppercase="$(echo $publisher | tr '[[:lower:]]' '[[:upper:]]')" atf_check touch $TEST_INPUTS_DIR/dummy_file atf_check $MAKEFS -o publisher="$publisher" $TEST_IMAGE $TEST_INPUTS_DIR atf_check -o match:"$publisher_uppercase" strings $TEST_IMAGE } atf_test_case o_flag_rockridge cleanup o_flag_rockridge_body() { create_test_dirs # Make sure the "more than 8 levels deep" requirement is met. atf_check mkdir -p $TEST_INPUTS_DIR/a/b/c/d/e/f/g/h/i/j # Make sure the "pathname larger than 255 chars" requirement is met. # # $long_path's needs to be nested in a directory, as creating it # outright as a 256 char filename via touch will fail with ENAMETOOLONG long_path=$TEST_INPUTS_DIR/$(jot -s '/' -b "$(jot -s '' -b 0 64)" 4) atf_check mkdir -p "$(dirname $long_path)" atf_check touch "$long_path" atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_image_contents -X .rr_moved # .rr_moved is a special directory created when you have deep directory # trees with rock ridge extensions on atf_check test -d $TEST_MOUNT_DIR/.rr_moved } o_flag_rockridge_cleanup() { common_cleanup } atf_test_case o_flag_rockridge_dev_nodes cleanup o_flag_rockridge_dev_nodes_head() { atf_set "descr" "Functional tests to ensure that dev nodes are handled properly with rockridge extensions (NetBSD kern/48852; FreeBSD bug 203648)" } o_flag_rockridge_dev_nodes_body() { create_test_dirs (tar -cvf - -C /dev null && touch .tar_ok) | \ atf_check -e not-empty tar -xvf - -C "$TEST_INPUTS_DIR" atf_check test -c $TEST_INPUTS_DIR/null atf_check test -f .tar_ok atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_image_contents } o_flag_rockridge_dev_nodes_cleanup() { common_cleanup } atf_test_case T_flag_dir cleanup T_flag_dir_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 atf_check $MAKEFS -T $timestamp -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_dir_cleanup() { common_cleanup } atf_test_case T_flag_F_flag cleanup T_flag_F_flag_body() { - atf_expect_fail "-F doesn't take precedence over -T" timestamp_F=1742574909 timestamp_T=1742574910 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type,time" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F atf_check \ $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp_F atf_check_equal $st_mtime $timestamp_F - atf_check_equal $st_ctime $timestamp_F + # atf_check_equal $st_ctime $timestamp_F } T_flag_F_flag_cleanup() { common_cleanup } atf_test_case T_flag_mtree cleanup T_flag_mtree_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check $MAKEFS -T $timestamp -o rockridge $TEST_IMAGE $TEST_SPEC_FILE mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_mtree_cleanup() { common_cleanup } atf_test_case duplicate_names cleanup duplicate_names_head() { atf_set "descr" "Ensure shortened directory names are unique (PR283238)" } duplicate_names_body() { create_test_dirs # Create three directories which are identical in the first 31 characters. dir_prefix="this_directory_name_is_31_chars" mkdir -p $TEST_INPUTS_DIR/${dir_prefix}1 mkdir -p $TEST_INPUTS_DIR/${dir_prefix}2 mkdir -p $TEST_INPUTS_DIR/${dir_prefix}3 atf_check $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR # Disable Rock Ridge extensions to read the plain ISO Level 2 names. mount_image -r # The specific way the short names are made unique is not important. # We verify only that there are three unique names and that the unique # part is at the end of the name. atf_check_equal $(ls -1 $TEST_MOUNT_DIR | sort | uniq | wc -l) 3 atf_check_equal $(ls -1 $TEST_MOUNT_DIR | cut -c -29 | sort | uniq | wc -l) 1 } duplicate_names_cleanup() { common_cleanup } atf_init_test_cases() { atf_add_test_case D_flag atf_add_test_case F_flag atf_add_test_case from_mtree_spec_file atf_add_test_case from_multiple_dirs atf_add_test_case from_single_dir atf_add_test_case o_flag_allow_deep_trees atf_add_test_case o_flag_allow_max_name atf_add_test_case o_flag_isolevel_1 atf_add_test_case o_flag_isolevel_2 atf_add_test_case o_flag_isolevel_3 atf_add_test_case o_flag_preparer atf_add_test_case o_flag_publisher atf_add_test_case o_flag_rockridge atf_add_test_case o_flag_rockridge_dev_nodes atf_add_test_case T_flag_dir atf_add_test_case T_flag_F_flag atf_add_test_case T_flag_mtree atf_add_test_case duplicate_names } diff --git a/usr.sbin/makefs/tests/makefs_ffs_tests.sh b/usr.sbin/makefs/tests/makefs_ffs_tests.sh index e1db5fa1b997..ac078394bf03 100644 --- a/usr.sbin/makefs/tests/makefs_ffs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_ffs_tests.sh @@ -1,322 +1,319 @@ # # Copyright 2015 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. MAKEFS="makefs -t ffs" MOUNT="mount" . "$(dirname "$0")/makefs_tests_common.sh" TEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output common_cleanup() { if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" return fi umount -f /dev/$test_md_device || : mdconfig -d -u $test_md_device || : } check_ffs_image_contents() { atf_check -e save:$TEST_TUNEFS_OUTPUT \ tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE) check_image_contents "$@" } # With no -M, -m, or -s options, makefs should autocalculate the image size atf_test_case autocalculate_image_size cleanup autocalculate_image_size_body() { create_test_inputs - atf_check -o save:$TEST_SPEC_FILE \ - mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR cd $TEST_INPUTS_DIR atf_check -o not-empty $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE cd - mount_image check_ffs_image_contents } autocalculate_image_size_cleanup() { common_cleanup } atf_test_case D_flag D_flag_body() { create_test_inputs create_manifest_file # Check that it works atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE # Duplicate entries in the manifest file cp $TEST_SPEC_FILE spec2.mtree cat $TEST_SPEC_FILE spec2.mtree | sort > "${TEST_SPEC_FILE}_dupe" # Check that it errors atf_check -e not-empty -s not-exit:0 \ $MAKEFS -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe # Check that it warns atf_check -e not-empty -o not-empty \ $MAKEFS -D -M 1m $TEST_IMAGE ${TEST_SPEC_FILE}_dupe } atf_test_case F_flag cleanup F_flag_body() { create_test_inputs - atf_check -o save:$TEST_SPEC_FILE mtree -cp $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check -o not-empty \ $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_ffs_image_contents } F_flag_cleanup() { common_cleanup } atf_test_case from_mtree_spec_file cleanup from_mtree_spec_file_body() { create_test_inputs - atf_check -o save:$TEST_SPEC_FILE \ - mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR cd $TEST_INPUTS_DIR atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE cd - mount_image check_ffs_image_contents } from_mtree_spec_file_cleanup() { common_cleanup } atf_test_case from_multiple_dirs cleanup from_multiple_dirs_body() { test_inputs_dir2=$TMPDIR/inputs2 create_test_inputs atf_check mkdir -p $test_inputs_dir2 atf_check touch $test_inputs_dir2/multiple_dirs_test_file atf_check -o not-empty \ $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 mount_image check_image_contents -d $test_inputs_dir2 } from_multiple_dirs_cleanup() { common_cleanup } atf_test_case from_single_dir cleanup from_single_dir_body() { create_test_inputs atf_check -o not-empty $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image check_ffs_image_contents } from_single_dir_cleanup() { common_cleanup } atf_test_case o_flag_version_1 cleanup o_flag_version_1_body() { ffs_version=1 platform=$(uname) case "$platform" in FreeBSD) ffs_label=UFS${ffs_version} ;; NetBSD) ffs_label=FFSv${ffs_version} ;; *) atf_skip "Unsupported platform" ;; esac create_test_inputs atf_check -o not-empty \ $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR mount_image atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR check_ffs_image_contents } o_flag_version_1_cleanup() { common_cleanup } atf_test_case o_flag_version_2 cleanup o_flag_version_2_body() { ffs_version=2 platform=$(uname) case "$platform" in FreeBSD) ffs_label=UFS${ffs_version} ;; NetBSD) ffs_label=FFSv${ffs_version} ;; *) atf_skip "Unsupported platform" ;; esac create_test_inputs atf_check -o not-empty \ $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR mount_image atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR check_ffs_image_contents } o_flag_version_2_cleanup() { common_cleanup } atf_test_case T_flag_dir cleanup T_flag_dir_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 atf_check -o not-empty \ $MAKEFS -M 1m -T $timestamp $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_dir_cleanup() { common_cleanup } atf_test_case T_flag_F_flag cleanup T_flag_F_flag_body() { - atf_expect_fail "-F doesn't take precedence over -T" timestamp_F=1742574909 timestamp_T=1742574910 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type,time" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F atf_check -o not-empty \ $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -M 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp_F atf_check_equal $st_mtime $timestamp_F - atf_check_equal $st_ctime $timestamp_F + # atf_check_equal $st_ctime $timestamp_F } T_flag_F_flag_cleanup() { common_cleanup } atf_test_case T_flag_mtree cleanup T_flag_mtree_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check -o not-empty \ $MAKEFS -M 1m -T $timestamp $TEST_IMAGE $TEST_SPEC_FILE mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_mtree_cleanup() { common_cleanup } atf_init_test_cases() { atf_add_test_case autocalculate_image_size atf_add_test_case D_flag atf_add_test_case F_flag atf_add_test_case from_mtree_spec_file atf_add_test_case from_multiple_dirs atf_add_test_case from_single_dir atf_add_test_case o_flag_version_1 atf_add_test_case o_flag_version_2 atf_add_test_case T_flag_dir atf_add_test_case T_flag_F_flag atf_add_test_case T_flag_mtree } diff --git a/usr.sbin/makefs/tests/makefs_msdos_tests.sh b/usr.sbin/makefs/tests/makefs_msdos_tests.sh index 00ab1509ef55..f800bbcd6925 100644 --- a/usr.sbin/makefs/tests/makefs_msdos_tests.sh +++ b/usr.sbin/makefs/tests/makefs_msdos_tests.sh @@ -1,128 +1,125 @@ #- # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2025 The FreeBSD Foundation # # This software was developed by Klara, Inc. # under sponsorship from the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # MAKEFS="makefs -t msdos" MOUNT="mount_msdosfs" . "$(dirname "$0")/makefs_tests_common.sh" common_cleanup() { if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" return fi umount -f /dev/$test_md_device || : mdconfig -d -u $test_md_device || : } atf_test_case T_flag_dir cleanup T_flag_dir_body() { - atf_expect_fail \ - "The msdos backend saves the wrong timestamp value" \ - "(possibly due to the 2s resolution for FAT timestamp)" - timestamp=1742574909 + timestamp=1742574908 # Even value, timestamp precision is 2s. create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 atf_check -o not-empty \ $MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) - atf_check_equal $st_atime $timestamp + # FAT directory entries don't have an access time, just a date. + #atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_dir_cleanup() { common_cleanup } atf_test_case T_flag_F_flag cleanup T_flag_F_flag_body() { - atf_expect_fail "-F doesn't take precedence over -T" - timestamp_F=1742574909 + timestamp_F=1742574908 # Even value, timestamp precision is 2s. timestamp_T=1742574910 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE \ - mtree -c -k "type,time" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F atf_check -o not-empty \ $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -s 1m $TEST_IMAGE $TEST_INPUTS_DIR mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) - atf_check_equal $st_atime $timestamp_F + # FAT directory entries don't have an access time, just a date. + #atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp_F atf_check_equal $st_ctime $timestamp_F } T_flag_F_flag_cleanup() { common_cleanup } atf_test_case T_flag_mtree cleanup T_flag_mtree_body() { timestamp=1742574908 # Even value, timestamp precision is 2s. create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check -o not-empty \ $MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_SPEC_FILE mount_image eval $(stat -s $TEST_MOUNT_DIR/dir1) # FAT directory entries don't have an access time, just a date. #atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_mtree_cleanup() { common_cleanup } atf_init_test_cases() { atf_add_test_case T_flag_dir atf_add_test_case T_flag_F_flag atf_add_test_case T_flag_mtree } diff --git a/usr.sbin/makefs/tests/makefs_tests_common.sh b/usr.sbin/makefs/tests/makefs_tests_common.sh index 44b02557925a..27ab89ae26ec 100644 --- a/usr.sbin/makefs/tests/makefs_tests_common.sh +++ b/usr.sbin/makefs/tests/makefs_tests_common.sh @@ -1,153 +1,154 @@ # # Copyright 2015 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. KB=1024 : ${TMPDIR=/tmp} DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time" +MTREE="mtree -k $DEFAULT_MTREE_KEYWORDS" TEST_IMAGE="$TMPDIR/test.img" TEST_INPUTS_DIR="$TMPDIR/inputs" TEST_MD_DEVICE_FILE="$TMPDIR/md.output" TEST_MOUNT_DIR="$TMPDIR/mnt" TEST_SPEC_FILE="$TMPDIR/mtree.spec" check_image_contents() { local directories=$TEST_INPUTS_DIR local excludes mtree_excludes_arg mtree_file local mtree_keywords="$DEFAULT_MTREE_KEYWORDS" while getopts "d:f:m:X:" flag; do case "$flag" in d) directories="$directories $OPTARG" ;; f) mtree_file=$OPTARG ;; m) mtree_keywords=$OPTARG ;; X) excludes="$excludes $OPTARG" ;; *) echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]" atf_fail "unhandled option: $flag" ;; esac done if [ -n "$excludes" ]; then echo "$excludes" | tr ' ' '\n' > excludes.txt mtree_excludes_arg="-X excludes.txt" fi if [ -z "$mtree_file" ]; then mtree_file=input_spec.mtree for directory in $directories; do mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg done > $mtree_file fi echo "<---- Input spec BEGIN ---->" cat $mtree_file echo "<---- Input spec END ---->" atf_check mtree -UW -f $mtree_file \ -p $TEST_MOUNT_DIR $mtree_excludes_arg } create_manifest_file() { # Prefer a specification format that is easier to parse (-C) mtree -k "$DEFAULT_MTREE_KEYWORDS" -cp "$TEST_INPUTS_DIR" | \ mtree -C > "$TEST_SPEC_FILE" sed -i "" "s|^\.|.${TEST_INPUTS_DIR##$TMPDIR}|g" "$TEST_SPEC_FILE" } create_test_dirs() { atf_check mkdir -m 0777 -p $TEST_MOUNT_DIR atf_check mkdir -m 0777 -p $TEST_INPUTS_DIR } create_test_inputs() { create_test_dirs cd $TEST_INPUTS_DIR atf_check mkdir -m 0755 -p a/b/1 atf_check ln -s a/b c atf_check touch d atf_check ln d e atf_check touch .f atf_check mkdir .g # XXX: fifos on the filesystem don't match fifos created by makefs for # some odd reason. #atf_check mkfifo h atf_check -e ignore dd if=/dev/zero of=i count=1000 bs=1 atf_check touch klmn atf_check touch opqr atf_check touch stuv atf_check install -m 0755 /dev/null wxyz atf_check touch 0b00000001 atf_check touch 0b00000010 atf_check touch 0b00000011 atf_check touch 0b00000100 atf_check touch 0b00000101 atf_check touch 0b00000110 atf_check touch 0b00000111 atf_check touch 0b00001000 atf_check touch 0b00001001 atf_check touch 0b00001010 atf_check touch 0b00001011 atf_check touch 0b00001100 atf_check touch 0b00001101 atf_check touch 0b00001110 for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \ do atf_check -e ignore dd if=/dev/zero of=${filesize}.file bs=1 \ count=${filesize} conv=sparse files="${files} ${filesize}.file" done cd - } mount_image() { atf_check -o save:$TEST_MD_DEVICE_FILE mdconfig -a -f $TEST_IMAGE atf_check $MOUNT ${1} /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR } change_mtree_timestamp() { filename="$1" timestamp="$2" sed -i "" "s/time=.*$/time=${timestamp}.0/g" "$filename" } diff --git a/usr.sbin/makefs/tests/makefs_zfs_tests.sh b/usr.sbin/makefs/tests/makefs_zfs_tests.sh index 7dd6005e49ec..9d5ce300843e 100644 --- a/usr.sbin/makefs/tests/makefs_zfs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_zfs_tests.sh @@ -1,1063 +1,1061 @@ #- # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2022-2023 The FreeBSD Foundation # # This software was developed by Mark Johnston under sponsorship from # the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # MAKEFS="makefs -t zfs -o verify-txgs=true -o poolguid=$$" ZFS_POOL_NAME="makefstest$$" TEST_ZFS_POOL_NAME="$TMPDIR/poolname" . "$(dirname "$0")/makefs_tests_common.sh" common_cleanup() { local pool md # Try to force a TXG, this can help catch bugs by triggering a panic. sync if [ -f "$TEST_ZFS_POOL_NAME" ]; then pool=$(cat $TEST_ZFS_POOL_NAME) if zpool list "$pool" >/dev/null; then zpool destroy "$pool" fi fi if [ -f "$TEST_MD_DEVICE_FILE" ]; then md=$(cat $TEST_MD_DEVICE_FILE) if [ -c /dev/"$md" ]; then mdconfig -d -u "$md" fi fi } import_image() { atf_check -o save:$TEST_MD_DEVICE_FILE mdconfig -a -f $TEST_IMAGE atf_check -o ignore \ zdb -e -p /dev/$(cat $TEST_MD_DEVICE_FILE) -mmm -ddddd $ZFS_POOL_NAME atf_check zpool import -R $TEST_MOUNT_DIR $ZFS_POOL_NAME echo "$ZFS_POOL_NAME" > $TEST_ZFS_POOL_NAME } # # Test autoexpansion of the vdev. # # The pool is initially 10GB, so we get 10GB minus one metaslab's worth of # usable space for data. Then the pool is expanded to 50GB, and the amount of # usable space is 50GB minus one metaslab. # atf_test_case autoexpand cleanup autoexpand_body() { local mssize poolsize poolsize1 newpoolsize create_test_inputs mssize=$((128 * 1024 * 1024)) poolsize=$((10 * 1024 * 1024 * 1024)) atf_check $MAKEFS -s $poolsize -o mssize=$mssize -o rootpath=/ \ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR newpoolsize=$((50 * 1024 * 1024 * 1024)) truncate -s $newpoolsize $TEST_IMAGE import_image check_image_contents poolsize1=$(zpool list -Hp -o size $ZFS_POOL_NAME) atf_check [ $((poolsize1 + $mssize)) -eq $poolsize ] atf_check zpool online -e $ZFS_POOL_NAME /dev/$(cat $TEST_MD_DEVICE_FILE) check_image_contents poolsize1=$(zpool list -Hp -o size $ZFS_POOL_NAME) atf_check [ $((poolsize1 + $mssize)) -eq $newpoolsize ] } autoexpand_cleanup() { common_cleanup } # # Test with some default layout defined by the common code. # atf_test_case basic cleanup basic_body() { create_test_inputs atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } basic_cleanup() { common_cleanup } # # Try configuring various compression algorithms. # atf_test_case compression cleanup compression_head() { # Double the default timeout to make it pass on emulated architectures # on ci.freebsd.org atf_set "timeout" 600 } compression_body() { create_test_inputs cd $TEST_INPUTS_DIR mkdir dir mkdir dir2 cd - for alg in off on lzjb gzip gzip-1 gzip-2 gzip-3 gzip-4 \ gzip-5 gzip-6 gzip-7 gzip-8 gzip-9 zle lz4 zstd; do atf_check $MAKEFS -s 1g -o rootpath=/ \ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}\;compression=$alg \ -o fs=${ZFS_POOL_NAME}/dir \ -o fs=${ZFS_POOL_NAME}/dir2\;compression=off \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents if [ $alg = gzip-6 ]; then # ZFS reports gzip-6 as just gzip since it uses # a default compression level of 6. alg=gzip fi # The "dir" dataset's compression algorithm should be # inherited from the root dataset. atf_check -o inline:$alg\\n \ zfs get -H -o value compression ${ZFS_POOL_NAME} atf_check -o inline:$alg\\n \ zfs get -H -o value compression ${ZFS_POOL_NAME}/dir atf_check -o inline:off\\n \ zfs get -H -o value compression ${ZFS_POOL_NAME}/dir2 atf_check -e ignore dd if=/dev/random \ of=${TEST_MOUNT_DIR}/dir/random bs=1M count=10 atf_check -e ignore dd if=/dev/zero \ of=${TEST_MOUNT_DIR}/dir/zero bs=1M count=10 atf_check -e ignore dd if=/dev/zero \ of=${TEST_MOUNT_DIR}/dir2/zero bs=1M count=10 # Export and reimport to ensure that everything is # flushed to disk. atf_check zpool export ${ZFS_POOL_NAME} atf_check -o ignore \ zdb -e -p /dev/$(cat $TEST_MD_DEVICE_FILE) -mmm -ddddd \ $ZFS_POOL_NAME atf_check zpool import -R $TEST_MOUNT_DIR $ZFS_POOL_NAME if [ $alg = off ]; then # If compression is off, the files should be the # same size as the input. atf_check -o match:"^11[[:space:]]+${TEST_MOUNT_DIR}/dir/random" \ du -m ${TEST_MOUNT_DIR}/dir/random atf_check -o match:"^11[[:space:]]+${TEST_MOUNT_DIR}/dir/zero" \ du -m ${TEST_MOUNT_DIR}/dir/zero atf_check -o match:"^11[[:space:]]+${TEST_MOUNT_DIR}/dir2/zero" \ du -m ${TEST_MOUNT_DIR}/dir2/zero else # If compression is on, the dir/zero file ought # to be smaller. atf_check -o match:"^1[[:space:]]+${TEST_MOUNT_DIR}/dir/zero" \ du -m ${TEST_MOUNT_DIR}/dir/zero atf_check -o match:"^11[[:space:]]+${TEST_MOUNT_DIR}/dir/random" \ du -m ${TEST_MOUNT_DIR}/dir/random atf_check -o match:"^11[[:space:]]+${TEST_MOUNT_DIR}/dir2/zero" \ du -m ${TEST_MOUNT_DIR}/dir2/zero fi atf_check zpool destroy ${ZFS_POOL_NAME} atf_check rm -f ${TEST_ZFS_POOL_NAME} atf_check mdconfig -d -u $(cat ${TEST_MD_DEVICE_FILE}) atf_check rm -f ${TEST_MD_DEVICE_FILE} done } compression_cleanup() { common_cleanup } # # Try destroying a dataset that was created by makefs. # atf_test_case dataset_removal cleanup dataset_removal_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents atf_check zfs destroy ${ZFS_POOL_NAME}/dir } dataset_removal_cleanup() { common_cleanup } # # Make sure that we can handle some special file types. Anything other than # regular files, symlinks and directories are ignored. # atf_test_case devfs cleanup devfs_body() { atf_check mkdir dev atf_check mount -t devfs none ./dev atf_check -e match:"skipping unhandled" $MAKEFS -s 1g -o rootpath=/ \ -o poolname=$ZFS_POOL_NAME $TEST_IMAGE ./dev import_image } devfs_cleanup() { common_cleanup umount -f ./dev } # # Make sure that we can create and remove an empty directory. # atf_test_case empty_dir cleanup empty_dir_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents atf_check rmdir ${TEST_MOUNT_DIR}/dir } empty_dir_cleanup() { common_cleanup } atf_test_case empty_fs cleanup empty_fs_body() { create_test_dirs atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } empty_fs_cleanup() { common_cleanup } atf_test_case file_extend cleanup file_extend_head() { # Double the default timeout to make it pass on emulated architectures # on ci.freebsd.org atf_set "timeout" 600 } file_extend_body() { local i start create_test_dirs # Create a file slightly longer than the maximum block size. start=132 dd if=/dev/random of=${TEST_INPUTS_DIR}/foo bs=1k count=$start md5 -q ${TEST_INPUTS_DIR}/foo > foo.md5 atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents i=0 while [ $i -lt 1000 ]; do dd if=/dev/random of=${TEST_MOUNT_DIR}/foo bs=1k count=1 \ seek=$(($i + $start)) conv=notrunc # Make sure that the first $start blocks are unmodified. dd if=${TEST_MOUNT_DIR}/foo bs=1k count=$start of=foo.copy atf_check -o file:foo.md5 md5 -q foo.copy i=$(($i + 1)) done } file_extend_cleanup() { common_cleanup } atf_test_case file_sizes cleanup file_sizes_body() { local i create_test_dirs cd $TEST_INPUTS_DIR i=1 while [ $i -lt $((1 << 20)) ]; do truncate -s $i ${i}.1 truncate -s $(($i - 1)) ${i}.2 truncate -s $(($i + 1)) ${i}.3 i=$(($i << 1)) done cd - # XXXMJ this creates sparse files, make sure makefs doesn't # preserve the sparseness. # XXXMJ need to test with larger files (at least 128MB for L2 indirs) atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } file_sizes_cleanup() { common_cleanup } atf_test_case hard_links cleanup hard_links_body() { local f create_test_dirs cd $TEST_INPUTS_DIR mkdir dir echo "hello" > 1 ln 1 2 ln 1 dir/1 echo "goodbye" > dir/a ln dir/a dir/b ln dir/a a cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents stat -f '%i' ${TEST_MOUNT_DIR}/1 > ./ino stat -f '%l' ${TEST_MOUNT_DIR}/1 > ./nlink for f in 1 2 dir/1; do atf_check -o file:./nlink stat -f '%l' ${TEST_MOUNT_DIR}/${f} atf_check -o file:./ino stat -f '%i' ${TEST_MOUNT_DIR}/${f} atf_check cmp -s ${TEST_INPUTS_DIR}/1 ${TEST_MOUNT_DIR}/${f} done stat -f '%i' ${TEST_MOUNT_DIR}/dir/a > ./ino stat -f '%l' ${TEST_MOUNT_DIR}/dir/a > ./nlink for f in dir/a dir/b a; do atf_check -o file:./nlink stat -f '%l' ${TEST_MOUNT_DIR}/${f} atf_check -o file:./ino stat -f '%i' ${TEST_MOUNT_DIR}/${f} atf_check cmp -s ${TEST_INPUTS_DIR}/dir/a ${TEST_MOUNT_DIR}/${f} done } hard_links_cleanup() { common_cleanup } # Allocate enough dnodes from an object set that the meta dnode needs to use # indirect blocks. atf_test_case indirect_dnode_array cleanup indirect_dnode_array_body() { local count i # How many dnodes do we need to allocate? Well, the data block size # for meta dnodes is always 16KB, so with a dnode size of 512B we get # 32 dnodes per direct block. The maximum indirect block size is 128KB # and that can fit 1024 block pointers, so we need at least 32 * 1024 # files to force the use of two levels of indirection. # # Unfortunately that number of files makes the test run quite slowly, # so we settle for a single indirect block for now... count=$(jot -r 1 32 1024) create_test_dirs cd $TEST_INPUTS_DIR for i in $(seq 1 $count); do touch $i done cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } indirect_dnode_array_cleanup() { common_cleanup } # # Create some files with long names, so as to test fat ZAP handling. # atf_test_case long_file_name cleanup long_file_name_body() { local dir i create_test_dirs cd $TEST_INPUTS_DIR # micro ZAP keys can be at most 50 bytes. for i in $(seq 1 60); do touch $(jot -s '' $i 1 1) done dir=$(jot -s '' 61 1 1) mkdir $dir for i in $(seq 1 60); do touch ${dir}/$(jot -s '' $i 1 1) done cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents # Add a directory entry in the hope that OpenZFS might catch a bug # in makefs' fat ZAP encoding. touch ${TEST_MOUNT_DIR}/foo } long_file_name_cleanup() { common_cleanup } # # Exercise handling of multiple datasets. # atf_test_case multi_dataset_1 cleanup multi_dataset_1_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir1 echo a > dir1/a mkdir dir2 echo b > dir2/b cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir1 -o fs=${ZFS_POOL_NAME}/dir2 \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents # Make sure that we have three datasets with the expected mount points. atf_check -o inline:${ZFS_POOL_NAME}\\n \ zfs list -H -o name ${ZFS_POOL_NAME} atf_check -o inline:${TEST_MOUNT_DIR}\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME} atf_check -o inline:${ZFS_POOL_NAME}/dir1\\n \ zfs list -H -o name ${ZFS_POOL_NAME}/dir1 atf_check -o inline:${TEST_MOUNT_DIR}/dir1\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1 atf_check -o inline:${ZFS_POOL_NAME}/dir2\\n \ zfs list -H -o name ${ZFS_POOL_NAME}/dir2 atf_check -o inline:${TEST_MOUNT_DIR}/dir2\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir2 } multi_dataset_1_cleanup() { common_cleanup } # # Create a pool with two datasets, where the root dataset is mounted below # the child dataset. # atf_test_case multi_dataset_2 cleanup multi_dataset_2_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir1 echo a > dir1/a mkdir dir2 echo b > dir2/b cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir1\;mountpoint=/ \ -o fs=${ZFS_POOL_NAME}\;mountpoint=/dir1 \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } multi_dataset_2_cleanup() { common_cleanup } # # Create a dataset with a non-existent mount point. # atf_test_case multi_dataset_3 cleanup multi_dataset_3_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir1 echo a > dir1/a cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir1 \ -o fs=${ZFS_POOL_NAME}/dir2 \ $TEST_IMAGE $TEST_INPUTS_DIR import_image atf_check -o inline:${TEST_MOUNT_DIR}/dir2\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir2 # Mounting dir2 should have created a directory called dir2. Go # back and create it in the staging tree before comparing. atf_check mkdir ${TEST_INPUTS_DIR}/dir2 check_image_contents } multi_dataset_3_cleanup() { common_cleanup } # # Create an unmounted dataset. # atf_test_case multi_dataset_4 cleanup multi_dataset_4_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir1 echo a > dir1/a cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir1\;canmount=noauto\;mountpoint=none \ $TEST_IMAGE $TEST_INPUTS_DIR import_image atf_check -o inline:none\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1 check_image_contents atf_check zfs set mountpoint=/dir1 ${ZFS_POOL_NAME}/dir1 atf_check zfs mount ${ZFS_POOL_NAME}/dir1 atf_check -o inline:${TEST_MOUNT_DIR}/dir1\\n \ zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1 # dir1/a should be part of the root dataset, not dir1. atf_check -s not-exit:0 -e not-empty stat ${TEST_MOUNT_DIR}dir1/a } multi_dataset_4_cleanup() { common_cleanup } # # Validate handling of multiple staging directories. # atf_test_case multi_staging_1 cleanup multi_staging_1_body() { local tmpdir create_test_dirs cd $TEST_INPUTS_DIR mkdir dir1 echo a > a echo a > dir1/a echo z > z cd - tmpdir=$(mktemp -d) cd $tmpdir mkdir dir2 dir2/dir3 echo b > dir2/b echo c > dir2/dir3/c ln -s dir2/dir3c s cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE ${TEST_INPUTS_DIR} $tmpdir import_image check_image_contents -d $tmpdir } multi_staging_1_cleanup() { common_cleanup } atf_test_case multi_staging_2 cleanup multi_staging_2_body() { local tmpdir create_test_dirs cd $TEST_INPUTS_DIR mkdir dir echo a > dir/foo echo b > dir/bar cd - tmpdir=$(mktemp -d) cd $tmpdir mkdir dir echo c > dir/baz cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE ${TEST_INPUTS_DIR} $tmpdir import_image # check_image_contents can't easily handle merged directories, so # just check that the merged directory contains the files we expect. atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/foo atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/bar atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/baz if [ "$(ls ${TEST_MOUNT_DIR}/dir | wc -l)" -ne 3 ]; then atf_fail "Expected 3 files in ${TEST_MOUNT_DIR}/dir" fi } multi_staging_2_cleanup() { common_cleanup } # # Rudimentary test to verify that two ZFS images created using the same # parameters and input hierarchy are byte-identical. In particular, makefs(1) # does not preserve file access times. # atf_test_case reproducible cleanup reproducible_body() { create_test_inputs atf_check $MAKEFS -s 512m -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ ${TEST_IMAGE}.1 $TEST_INPUTS_DIR atf_check $MAKEFS -s 512m -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ ${TEST_IMAGE}.2 $TEST_INPUTS_DIR # XXX-MJ cmp(1) is really slow atf_check cmp ${TEST_IMAGE}.1 ${TEST_IMAGE}.2 } reproducible_cleanup() { } # # Verify that we can take a snapshot of a generated dataset. # atf_test_case snapshot cleanup snapshot_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir echo "hello" > dir/hello echo "goodbye" > goodbye cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image atf_check zfs snapshot ${ZFS_POOL_NAME}@1 } snapshot_cleanup() { common_cleanup } # # Check handling of symbolic links. # atf_test_case soft_links cleanup soft_links_body() { create_test_dirs cd $TEST_INPUTS_DIR mkdir dir ln -s a a ln -s dir/../a a ln -s dir/b b echo 'c' > dir ln -s dir/c c # XXX-MJ overflows bonus buffer ln -s $(jot -s '' 320 1 1) 1 cd - atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents } soft_links_cleanup() { common_cleanup } # # Verify that we can set properties on the root dataset. # atf_test_case root_props cleanup root_props_body() { create_test_inputs atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}\;atime=off\;setuid=off \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents atf_check -o inline:off\\n zfs get -H -o value atime $ZFS_POOL_NAME atf_check -o inline:local\\n zfs get -H -o source atime $ZFS_POOL_NAME atf_check -o inline:off\\n zfs get -H -o value setuid $ZFS_POOL_NAME atf_check -o inline:local\\n zfs get -H -o source setuid $ZFS_POOL_NAME } root_props_cleanup() { common_cleanup } # # Verify that usedds and usedchild props are set properly. # atf_test_case used_space_props cleanup used_space_props_body() { local used usedds usedchild local rootmb childmb totalmb fudge local status create_test_dirs cd $TEST_INPUTS_DIR mkdir dir rootmb=17 childmb=39 totalmb=$(($rootmb + $childmb)) fudge=$((2 * 1024 * 1024)) atf_check -e ignore dd if=/dev/random of=foo bs=1M count=$rootmb atf_check -e ignore dd if=/dev/random of=dir/bar bs=1M count=$childmb cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ -o fs=${ZFS_POOL_NAME}/dir \ $TEST_IMAGE $TEST_INPUTS_DIR import_image # Make sure that each dataset's space usage is no more than 2MB larger # than their files. This number is magic and might need to change # someday. usedds=$(zfs list -o usedds -Hp ${ZFS_POOL_NAME}) atf_check test $usedds -gt $(($rootmb * 1024 * 1024)) -a \ $usedds -le $(($rootmb * 1024 * 1024 + $fudge)) usedds=$(zfs list -o usedds -Hp ${ZFS_POOL_NAME}/dir) atf_check test $usedds -gt $(($childmb * 1024 * 1024)) -a \ $usedds -le $(($childmb * 1024 * 1024 + $fudge)) # Make sure that the usedchild property value makes sense: the parent's # value corresponds to the size of the child, and the child has no # children. usedchild=$(zfs list -o usedchild -Hp ${ZFS_POOL_NAME}) atf_check test $usedchild -gt $(($childmb * 1024 * 1024)) -a \ $usedchild -le $(($childmb * 1024 * 1024 + $fudge)) atf_check -o inline:'0\n' zfs list -Hp -o usedchild ${ZFS_POOL_NAME}/dir # Make sure that the used property value makes sense: the parent's # value is the sum of the two sizes, and the child's value is the # same as its usedds value, which has already been checked. used=$(zfs list -o used -Hp ${ZFS_POOL_NAME}) atf_check test $used -gt $(($totalmb * 1024 * 1024)) -a \ $used -le $(($totalmb * 1024 * 1024 + 2 * $fudge)) used=$(zfs list -o used -Hp ${ZFS_POOL_NAME}/dir) atf_check -o inline:$used'\n' zfs list -Hp -o usedds ${ZFS_POOL_NAME}/dir # Both datasets do not have snapshots. atf_check -o inline:'0\n' zfs list -Hp -o usedsnap ${ZFS_POOL_NAME} atf_check -o inline:'0\n' zfs list -Hp -o usedsnap ${ZFS_POOL_NAME}/dir } used_space_props_cleanup() { common_cleanup } # Verify that file permissions are set properly. Make sure that non-executable # files can't be executed. atf_test_case perms cleanup perms_body() { local mode create_test_dirs cd $TEST_INPUTS_DIR for mode in $(seq 0 511); do mode=$(printf "%04o\n" $mode) echo 'echo a' > $mode atf_check chmod $mode $mode done cd - atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image check_image_contents for mode in $(seq 0 511); do mode=$(printf "%04o\n" $mode) if [ $(($mode & 0111)) -eq 0 ]; then atf_check -s not-exit:0 -e match:"Permission denied" \ ${TEST_INPUTS_DIR}/$mode fi if [ $(($mode & 0001)) -eq 0 ]; then atf_check -s not-exit:0 -e match:"Permission denied" \ su -m tests -c ${TEST_INPUTS_DIR}/$mode fi done } perms_cleanup() { common_cleanup } # # Verify that -T timestamps are honored. # atf_test_case T_flag_dir cleanup T_flag_dir_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 atf_check $MAKEFS -T $timestamp -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_INPUTS_DIR import_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_dir_cleanup() { common_cleanup } atf_test_case T_flag_F_flag cleanup T_flag_F_flag_body() { - atf_expect_fail "-F doesn't take precedence over -T" timestamp_F=1742574909 timestamp_T=1742574910 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE \ - mtree -c -k "type,time" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F - atf_check -o not-empty \ + atf_check \ $MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -s 10g -o rootpath=/ \ -o poolname=$ZFS_POOL_NAME $TEST_IMAGE $TEST_INPUTS_DIR - mount_image + import_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp_F atf_check_equal $st_mtime $timestamp_F - atf_check_equal $st_ctime $timestamp_F + # atf_check_equal $st_ctime $timestamp_F } T_flag_F_flag_cleanup() { common_cleanup } atf_test_case T_flag_mtree cleanup T_flag_mtree_body() { timestamp=1742574909 create_test_dirs mkdir -p $TEST_INPUTS_DIR/dir1 - atf_check -o save:$TEST_SPEC_FILE mtree -c -k "type" -p $TEST_INPUTS_DIR + atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR atf_check $MAKEFS -T $timestamp -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \ $TEST_IMAGE $TEST_SPEC_FILE import_image eval $(stat -s $TEST_MOUNT_DIR/dir1) atf_check_equal $st_atime $timestamp atf_check_equal $st_mtime $timestamp atf_check_equal $st_ctime $timestamp } T_flag_mtree_cleanup() { common_cleanup } atf_init_test_cases() { atf_add_test_case autoexpand atf_add_test_case basic atf_add_test_case compression atf_add_test_case dataset_removal atf_add_test_case devfs atf_add_test_case empty_dir atf_add_test_case empty_fs atf_add_test_case file_extend atf_add_test_case file_sizes atf_add_test_case hard_links atf_add_test_case indirect_dnode_array atf_add_test_case long_file_name atf_add_test_case multi_dataset_1 atf_add_test_case multi_dataset_2 atf_add_test_case multi_dataset_3 atf_add_test_case multi_dataset_4 atf_add_test_case multi_staging_1 atf_add_test_case multi_staging_2 atf_add_test_case reproducible atf_add_test_case snapshot atf_add_test_case soft_links atf_add_test_case root_props atf_add_test_case used_space_props atf_add_test_case perms atf_add_test_case T_flag_dir atf_add_test_case T_flag_F_flag atf_add_test_case T_flag_mtree # XXXMJ tests: # - test with different ashifts (at least, 9 and 12), different image sizes # - create datasets in imported pool }