Path: blob/main/tests/sys/geom/class/part/misc.sh
105417 views
# SPDX-License-Identifier: BSD-2-Clause1#2# Copyright (c) 2018 Alan Somers3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions6# are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# 2. Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12#13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23# SUCH DAMAGE.24#2526MD_DEVS="md.devs"2728atf_test_case blank_physpath cleanup29blank_physpath_head()30{31atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none"32atf_set "require.user" "root"33}34blank_physpath_body()35{36load_gnop37load_gpart38md=$(alloc_md)39atf_check -o empty -e ignore diskinfo -p ${md}40atf_check -s exit:0 -o ignore gpart create -s bsd ${md}41atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}42atf_check -o empty -e ignore diskinfo -p ${md}a43}44blank_physpath_cleanup()45{46common_cleanup47}484950atf_test_case bsd_physpath cleanup51bsd_physpath_head()52{53atf_set "descr" "BSD partitions should append /X to the underlying device's physical path"54atf_set "require.user" "root"55}56bsd_physpath_body()57{58load_gnop59load_gpart60md=$(alloc_md)61physpath="some/physical/path"62atf_check gnop create -z $physpath /dev/${md}63atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop64atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop65gpart_physpath=$(diskinfo -p ${md}.nopa)66atf_check_equal "${physpath}/a" "$gpart_physpath"67}68bsd_physpath_cleanup()69{70common_cleanup71}7273atf_test_case gpt_physpath cleanup74gpt_physpath_head()75{76atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path"77atf_set "require.user" "root"78}79gpt_physpath_body()80{81load_gnop82load_gpart83md=$(alloc_md)84physpath="some/physical/path"85atf_check gnop create -z $physpath /dev/${md}86atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop87atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop88gpart_physpath=$(diskinfo -p ${md}.nopp1)89atf_check_equal "${physpath}/p1" "$gpart_physpath"90}91gpt_physpath_cleanup()92{93common_cleanup94}9596atf_test_case mbr_physpath cleanup97mbr_physpath_head()98{99atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path"100atf_set "require.user" "root"101}102mbr_physpath_body()103{104load_gnop105load_gpart106md=$(alloc_md)107physpath="some/physical/path"108atf_check gnop create -z $physpath /dev/${md}109atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop110atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop111gpart_physpath=$(diskinfo -p ${md}.nops1)112atf_check_equal "${physpath}/s1" "$gpart_physpath"113}114mbr_physpath_cleanup()115{116common_cleanup117}118119atf_test_case mbr_bsd_physpath cleanup120mbr_bsd_physpath_head()121{122atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path"123atf_set "require.user" "root"124}125mbr_bsd_physpath_body()126{127load_gnop128load_gpart129md=$(alloc_md)130physpath="some/physical/path"131atf_check gnop create -z $physpath /dev/${md}132atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop133atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop134atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1135atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1136gpart_physpath=$(diskinfo -p ${md}.nops1a)137atf_check_equal "${physpath}/s1/a" "$gpart_physpath"138}139mbr_bsd_physpath_cleanup()140{141common_cleanup142}143144atf_init_test_cases()145{146atf_add_test_case blank_physpath147atf_add_test_case bsd_physpath148atf_add_test_case gpt_physpath149atf_add_test_case mbr_physpath150atf_add_test_case mbr_bsd_physpath151}152153alloc_md()154{155local md156157md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"158echo ${md} >> $MD_DEVS159echo ${md}160}161162common_cleanup()163{164if [ -f "$MD_DEVS" ]; then165while read test_md; do166gnop destroy -f ${test_md}.nop 2>/dev/null167mdconfig -d -u $test_md 2>/dev/null168done < $MD_DEVS169rm $MD_DEVS170fi171true172}173174load_gpart()175{176if ! kldstat -q -m g_part; then177geom part load || atf_skip "could not load module for geom part"178fi179}180181load_gnop()182{183if ! kldstat -q -m g_nop; then184geom nop load || atf_skip "could not load module for geom nop"185fi186}187188189