Path: blob/main/tests/sys/geom/class/nop/nop_test.sh
39638 views
# SPDX-License-Identifier: BSD-2-Clause1#2# Copyright (c) 2016 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"27PLAINFILES=plainfiles2829atf_test_case preserve_props cleanup30preserve_props_head()31{32atf_set "descr" "gnop should preserve basic GEOM properties"33atf_set "require.user" "root"34atf_set "timeout" 1535}36preserve_props_body()37{38load_gnop39us=$(alloc_md)40atf_check gnop create /dev/${us}41md_secsize=$(diskinfo ${us} | cut -wf 2)42md_mediasize=$(diskinfo ${us} | cut -wf 3)43md_stripesize=$(diskinfo ${us} | cut -wf 5)44nop_secsize=$(diskinfo ${us}.nop | cut -wf 2)45nop_mediasize=$(diskinfo ${us}.nop | cut -wf 3)46nop_stripesize=$(diskinfo ${us}.nop | cut -wf 5)47atf_check_equal "$md_secsize" "$nop_secsize"48atf_check_equal "$md_mediasize" "$nop_mediasize"49atf_check_equal "$md_stripesize" "$nop_stripesize"50}51preserve_props_cleanup()52{53common_cleanup54}5556atf_test_case preserve_disk_props cleanup57preserve_disk_props_head()58{59atf_set "descr" "gnop should preserve properties for disks"60atf_set "require.user" "root"61atf_set "require.config" "disks"62atf_set "timeout" 1563}64preserve_disk_props_body()65{66load_gnop67disks=`atf_config_get disks`68disk=${disks%% *}69if [ -z "$disk" ]; then70atf_skip "Must define disks (see tests(7))"71fi72atf_check gnop create ${disk}7374disk_ident=$(diskinfo -s ${disk})75disk_physpath=$(diskinfo -p ${disk})76disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')77disk_trim=$(diskinfo -v ${disk} | awk '/TRIM.UNMAP/ {print $1}')78disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')79disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')80nop_ident=$(diskinfo -s ${disk}.nop)81nop_physpath=$(diskinfo -p ${disk}.nop)82nop_descr=$(diskinfo -v ${disk}.nop | awk '/Disk descr/ {print $1}')83nop_trim=$(diskinfo -v ${disk}.nop | awk '/TRIM.UNMAP/ {print $1}')84nop_rotrate=$(diskinfo -v ${disk}.nop | awk '/Rotation/ {print $1}')85nop_zonemode=$(diskinfo -v ${disk}.nop | awk '/Zone Mode/ {print $1}')86atf_check_equal "$disk_ident" "$nop_ident"87atf_check_equal "$disk_physpath" "$nop_physpath"88atf_check_equal "$disk_descr" "$nop_descr"89atf_check_equal "$disk_trim" "$nop_trim"90atf_check_equal "$disk_rotrate" "$nop_rotrate"91atf_check_equal "$disk_zonemode" "$nop_zonemode"92}93preserve_disk_props_cleanup()94{95disk_cleanup96common_cleanup97}9899atf_test_case io cleanup100io_head()101{102atf_set "descr" "I/O works on gnop devices"103atf_set "require.user" "root"104atf_set "timeout" 15105}106io_body()107{108load_gnop109us=$(alloc_md)110atf_check gnop create /dev/${us}111112echo src >> $PLAINFILES113echo dst >> $PLAINFILES114dd if=/dev/random of=src bs=1m count=1 >/dev/null 2>&1115dd if=src of=/dev/${us}.nop bs=1m count=1 > /dev/null 2>&1116dd if=/dev/${us}.nop of=dst bs=1m count=1 > /dev/null 2>&1117118atf_check_equal `md5 -q src` `md5 -q dst`119}120io_cleanup()121{122common_cleanup123}124125atf_test_case physpath cleanup126physpath_head()127{128atf_set "descr" "Test gnop's -z option"129atf_set "require.user" "root"130atf_set "timeout" 15131}132physpath_body()133{134load_gnop135us=$(alloc_md)136physpath="some/physical/path"137atf_check gnop create -z $physpath /dev/${us}138gnop_physpath=$(diskinfo -p ${us}.nop)139atf_check_equal "$physpath" "$gnop_physpath"140}141physpath_cleanup()142{143common_cleanup144}145146atf_test_case physpath_blank cleanup147physpath_blank_head()148{149atf_set "descr" "gnop can set physical path to the empty string"150atf_set "require.user" "root"151atf_set "require.config" "disks"152atf_set "timeout" 15153}154physpath_blank_body()155{156load_gnop157disks=`atf_config_get disks`158disk=${disks%% *}159if [ -z "$disk" ]; then160atf_skip "Must define disks (see tests(7))"161fi162163atf_check gnop create -z "" ${disk}164gnop_physpath=$(diskinfo -p ${disk}.nop)165atf_check_equal "" "$gnop_physpath"166}167physpath_blank_cleanup()168{169disk_cleanup170common_cleanup171}172173atf_test_case size cleanup174size_head()175{176atf_set "descr" "Test gnop's -s option"177atf_set "require.user" "root"178atf_set "timeout" 15179}180size_body()181{182load_gnop183us=$(alloc_md)184for mediasize in 65536 524288 1048576; do185atf_check gnop create -s ${mediasize} /dev/${us}186gnop_mediasize=`diskinfo /dev/${us}.nop | cut -wf 3`187atf_check_equal "${mediasize}" "${gnop_mediasize}"188atf_check gnop destroy /dev/${us}.nop189done190# We shouldn't be able to extend the provider's size191atf_check -s not-exit:0 -e ignore gnop create -s 2097152 /dev/${us}192}193size_cleanup()194{195common_cleanup196}197198atf_test_case stripesize cleanup199stripesize_head()200{201atf_set "descr" "Test gnop's -p and -P options"202atf_set "require.user" "root"203atf_set "timeout" 120204}205stripesize_body()206{207load_gnop208us=$(alloc_md)209for ss in 512 1024 2048 4096 8192; do210for sofs in `seq 0 512 ${ss}`; do211[ "$sofs" -eq "$ss" ] && continue212atf_check gnop create -p ${ss} -P ${sofs} /dev/${us}213gnop_ss=`diskinfo /dev/${us}.nop | cut -wf 5`214gnop_sofs=`diskinfo /dev/${us}.nop | cut -wf 6`215atf_check_equal "${ss}" "${gnop_ss}"216atf_check_equal "${sofs}" "${gnop_sofs}"217atf_check gnop destroy /dev/${us}.nop218done219done220}221stripesize_cleanup()222{223common_cleanup224}225226atf_init_test_cases()227{228atf_add_test_case io229atf_add_test_case physpath230atf_add_test_case physpath_blank231atf_add_test_case preserve_props232atf_add_test_case preserve_disk_props233atf_add_test_case stripesize234atf_add_test_case size235}236237alloc_md()238{239local md240241md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"242echo ${md} >> $MD_DEVS243echo ${md}244}245246common_cleanup()247{248if [ -f "$MD_DEVS" ]; then249while read test_md; do250gnop destroy -f ${test_md}.nop 2>/dev/null251mdconfig -d -u $test_md 2>/dev/null252done < $MD_DEVS253rm $MD_DEVS254fi255256if [ -f "$PLAINFILES" ]; then257while read f; do258rm -f ${f}259done < ${PLAINFILES}260rm ${PLAINFILES}261fi262true263}264265disk_cleanup()266{267disks=`atf_config_get disks`268disk=${disks%% *}269if [ -n "$disk" ]; then270gnop destroy -f ${disk}.nop 2>/dev/null271fi272}273274load_gnop()275{276if ! kldstat -q -m g_nop; then277geom nop load || atf_skip "could not load module for geom nop"278fi279}280281282