15455Sdg# 21541Srgrimes# Copyright 2015 EMC Corp. 31541Srgrimes# All rights reserved. 41541Srgrimes# 51541Srgrimes# Redistribution and use in source and binary forms, with or without 61541Srgrimes# modification, are permitted provided that the following conditions are 71541Srgrimes# met: 81541Srgrimes# 91541Srgrimes# * Redistributions of source code must retain the above copyright 101541Srgrimes# notice, this list of conditions and the following disclaimer. 111541Srgrimes# * Redistributions in binary form must reproduce the above copyright 121541Srgrimes# notice, this list of conditions and the following disclaimer in the 131541Srgrimes# documentation and/or other materials provided with the distribution. 141541Srgrimes# 151541Srgrimes# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161541Srgrimes# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171541Srgrimes# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 181541Srgrimes# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 191541Srgrimes# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 201541Srgrimes# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 211541Srgrimes# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221541Srgrimes# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231541Srgrimes# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241541Srgrimes# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 251541Srgrimes# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261541Srgrimes# 271541Srgrimes# $FreeBSD: stable/11/usr.sbin/makefs/tests/makefs_ffs_tests.sh 339048 2018-10-01 15:40:06Z asomers $ 281541Srgrimes# 291541Srgrimes 301541SrgrimesMAKEFS="makefs -t ffs" 311541SrgrimesMOUNT="mount" 321541Srgrimes 331541Srgrimes. "$(dirname "$0")/makefs_tests_common.sh" 341541Srgrimes 351541SrgrimesTEST_TUNEFS_OUTPUT=$TMPDIR/tunefs.output 361817Sdg 371541Srgrimescommon_cleanup() 381541Srgrimes{ 391541Srgrimes if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then 401541Srgrimes echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?" 411541Srgrimes return 421541Srgrimes fi 435455Sdg 441541Srgrimes umount -f /dev/$test_md_device || : 451541Srgrimes mdconfig -d -u $test_md_device || : 461541Srgrimes} 471541Srgrimes 481541Srgrimescheck_ffs_image_contents() 495455Sdg{ 505455Sdg atf_check -e save:$TEST_TUNEFS_OUTPUT -o empty -s exit:0 \ 515455Sdg tunefs -p /dev/$(cat $TEST_MD_DEVICE_FILE) 521541Srgrimes 535455Sdg check_image_contents "$@" 541541Srgrimes} 551541Srgrimes 561541Srgrimes# With no -M, -m, or -s options, makefs should autocalculate the image size 571541Srgrimesatf_test_case autocalculate_image_size cleanup 581541Srgrimesautocalculate_image_size_body() 591541Srgrimes{ 601541Srgrimes atf_expect_fail "PR 229929 makefs(8) can underestimate image size" 611541Srgrimes create_test_inputs 621541Srgrimes 631817Sdg atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 645455Sdg mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 651541Srgrimes 661541Srgrimes cd $TEST_INPUTS_DIR 671541Srgrimes atf_check -e empty -o not-empty -s exit:0 \ 681541Srgrimes $MAKEFS $TEST_IMAGE $TEST_SPEC_FILE 691541Srgrimes cd - 701541Srgrimes 711541Srgrimes mount_image 721541Srgrimes check_ffs_image_contents 732112Swollman} 742112Swollmanautocalculate_image_size_cleanup() 751541Srgrimes{ 761541Srgrimes common_cleanup 771541Srgrimes} 781541Srgrimes 791541Srgrimesatf_test_case D_flag cleanup 801541SrgrimesD_flag_body() 815455Sdg{ 825455Sdg atf_skip "makefs crashes with SIGBUS with dupe mtree entries; see FreeBSD bug # 192839" 835455Sdg 845455Sdg create_test_inputs 855455Sdg 865455Sdg atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 875455Sdg mtree -cp $TEST_INPUTS_DIR 885455Sdg atf_check -e empty -o not-empty -s exit:0 \ 895455Sdg $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 905455Sdg 912112Swollman atf_check -e empty -o empty -s exit:0 \ 921541Srgrimes cp $TEST_SPEC_FILE spec2.mtree 931541Srgrimes atf_check -e empty -o save:dupe_$TEST_SPEC_FILE -s exit:0 \ 941541Srgrimes cat $TEST_SPEC_FILE spec2.mtree 951541Srgrimes 961541Srgrimes atf_check -e empty -o not-empty -s not-exit:0 \ 971541Srgrimes $MAKEFS -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 981541Srgrimes atf_check -e empty -o not-empty -s exit:0 \ 995455Sdg $MAKEFS -D -F dupe_$TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 1005455Sdg} 1015455SdgD_flag_cleanup() 1025455Sdg{ 1031541Srgrimes common_cleanup 1045455Sdg} 1055455Sdg 1061541Srgrimesatf_test_case F_flag cleanup 1071541SrgrimesF_flag_body() 1081541Srgrimes{ 1091541Srgrimes create_test_inputs 1101541Srgrimes 1111541Srgrimes atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 1121541Srgrimes mtree -cp $TEST_INPUTS_DIR 1131541Srgrimes 1141541Srgrimes atf_check -e empty -o not-empty -s exit:0 \ 1151541Srgrimes $MAKEFS -F $TEST_SPEC_FILE -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 1165455Sdg 1171541Srgrimes mount_image 1185455Sdg check_ffs_image_contents 1191541Srgrimes} 1205455SdgF_flag_cleanup() 1211541Srgrimes{ 1221541Srgrimes common_cleanup 1231541Srgrimes} 1241541Srgrimes 1251541Srgrimesatf_test_case from_mtree_spec_file cleanup 1261541Srgrimesfrom_mtree_spec_file_body() 1275455Sdg{ 1285455Sdg create_test_inputs 1295455Sdg 1305455Sdg atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \ 1311541Srgrimes mtree -c -k "$DEFAULT_MTREE_KEYWORDS" -p $TEST_INPUTS_DIR 1325455Sdg 1335455Sdg cd $TEST_INPUTS_DIR 1345455Sdg atf_check -e empty -o not-empty -s exit:0 \ 1351541Srgrimes $MAKEFS -M 1m $TEST_IMAGE $TEST_SPEC_FILE 1361541Srgrimes cd - 1371541Srgrimes 1381541Srgrimes mount_image 1395455Sdg check_ffs_image_contents 1405455Sdg} 1411541Srgrimesfrom_mtree_spec_file_cleanup() 1421541Srgrimes{ 1431541Srgrimes common_cleanup 1445455Sdg} 1455455Sdg 1465455Sdgatf_test_case from_multiple_dirs cleanup 1471541Srgrimesfrom_multiple_dirs_body() 1481541Srgrimes{ 1491541Srgrimes test_inputs_dir2=$TMPDIR/inputs2 1501541Srgrimes 1511541Srgrimes create_test_inputs 1521541Srgrimes 1531541Srgrimes atf_check -e empty -o empty -s exit:0 mkdir -p $test_inputs_dir2 1541541Srgrimes atf_check -e empty -o empty -s exit:0 \ 1551541Srgrimes touch $test_inputs_dir2/multiple_dirs_test_file 1561541Srgrimes 1571541Srgrimes atf_check -e empty -o not-empty -s exit:0 \ 1581541Srgrimes $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR $test_inputs_dir2 1595455Sdg 1605455Sdg mount_image 1615455Sdg check_image_contents -d $test_inputs_dir2 1625455Sdg} 1635455Sdgfrom_multiple_dirs_cleanup() 1645455Sdg{ 1655455Sdg common_cleanup 1665455Sdg} 1675455Sdg 1685455Sdgatf_test_case from_single_dir cleanup 1695455Sdgfrom_single_dir_body() 1705455Sdg{ 1715455Sdg create_test_inputs 1725455Sdg 1735455Sdg atf_check -e empty -o not-empty -s exit:0 \ 1741541Srgrimes $MAKEFS -M 1m $TEST_IMAGE $TEST_INPUTS_DIR 1751541Srgrimes 1761541Srgrimes mount_image 1775455Sdg check_ffs_image_contents 1785455Sdg} 1791541Srgrimesfrom_single_dir_cleanup() 1805455Sdg{ 1811541Srgrimes common_cleanup 1821541Srgrimes} 1831541Srgrimes 1841541Srgrimesatf_test_case o_flag_version_1 cleanup 1851541Srgrimeso_flag_version_1_body() 1861541Srgrimes{ 1875455Sdg ffs_version=1 1881541Srgrimes 1891541Srgrimes platform=$(uname) 1905455Sdg case "$platform" in 1911541Srgrimes FreeBSD) 1925455Sdg ffs_label=UFS${ffs_version} 1931541Srgrimes ;; 1941541Srgrimes NetBSD) 1951541Srgrimes ffs_label=FFSv${ffs_version} 1961541Srgrimes ;; 1971541Srgrimes *) 1985455Sdg atf_skip "Unsupported platform" 1991541Srgrimes ;; 2001541Srgrimes esac 2011541Srgrimes 2025455Sdg create_test_inputs 2031541Srgrimes 2041541Srgrimes atf_check -e empty -o not-empty -s exit:0 \ 2051541Srgrimes $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 2061541Srgrimes 2071541Srgrimes mount_image 2081541Srgrimes atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 2091541Srgrimes check_ffs_image_contents 2101541Srgrimes} 2111541Srgrimeso_flag_version_1_cleanup() 2125455Sdg{ 2135455Sdg common_cleanup 2145455Sdg} 2155455Sdg 2165455Sdgatf_test_case o_flag_version_2 cleanup 2171541Srgrimeso_flag_version_2_body() 2181541Srgrimes{ 2191541Srgrimes ffs_version=2 2201541Srgrimes 2211541Srgrimes platform=$(uname) 2221541Srgrimes case "$platform" in 2231541Srgrimes FreeBSD) 2241541Srgrimes ffs_label=UFS${ffs_version} 2251541Srgrimes ;; 2261541Srgrimes NetBSD) 2271541Srgrimes ffs_label=FFSv${ffs_version} 2281541Srgrimes ;; 2291541Srgrimes *) 2301541Srgrimes atf_skip "Unsupported platform" 2311541Srgrimes ;; 2321541Srgrimes esac 2331541Srgrimes 2345455Sdg create_test_inputs 2355455Sdg 2365455Sdg atf_check -e empty -o not-empty -s exit:0 \ 2375455Sdg $MAKEFS -M 1m -o version=$ffs_version $TEST_IMAGE $TEST_INPUTS_DIR 2385455Sdg 2395455Sdg mount_image 2401541Srgrimes atf_check -e ignore -o match:"$ffs_label" dumpfs $TEST_MOUNT_DIR 2415455Sdg check_ffs_image_contents 2425455Sdg} 2431541Srgrimeso_flag_version_2_cleanup() 2441541Srgrimes{ 2451541Srgrimes common_cleanup 2461541Srgrimes} 2471541Srgrimes 2485455Sdgatf_init_test_cases() 2491541Srgrimes{ 2501541Srgrimes 2511541Srgrimes atf_add_test_case autocalculate_image_size 2521541Srgrimes 2531541Srgrimes atf_add_test_case D_flag 2541541Srgrimes atf_add_test_case F_flag 2551541Srgrimes 2561541Srgrimes atf_add_test_case from_mtree_spec_file 2571541Srgrimes atf_add_test_case from_multiple_dirs 2581541Srgrimes atf_add_test_case from_single_dir 2591541Srgrimes 2605455Sdg atf_add_test_case o_flag_version_1 2611541Srgrimes atf_add_test_case o_flag_version_2 2621541Srgrimes} 2631541Srgrimes