Path: blob/main/tests/sys/geom/class/eli/misc_test.sh
39635 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#2526. $(atf_get_srcdir)/conf.sh2728atf_test_case preserve_props cleanup29preserve_props_head()30{31atf_set "descr" "geli should preserve basic GEOM properties"32atf_set "require.user" "root"33atf_set "timeout" 1534}35preserve_props_body()36{37geli_test_setup3839attach_md md -s1m40atf_check geli onetime /dev/${md}41md_secsize=$(diskinfo ${md} | cut -wf 2)42md_stripesize=$(diskinfo ${md} | cut -wf 5)43eli_secsize=$(diskinfo ${md}.eli | cut -wf 2)44eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5)45atf_check_equal "$md_secsize" "$eli_secsize"46atf_check_equal "$md_stripesize" "$eli_stripesize"47}48preserve_props_cleanup()49{50geli_test_cleanup51}5253atf_test_case preserve_disk_props cleanup54preserve_disk_props_head()55{56atf_set "descr" "geli should preserve properties for disks"57atf_set "require.user" "root"58atf_set "require.config" "disks"59atf_set "timeout" 1560}61preserve_disk_props_body()62{63geli_test_setup6465disks=`atf_config_get disks`66disk=${disks%% *}67if [ -z "$disk" ]; then68atf_skip "Must define disks (see tests(7))"69fi70atf_check geli onetime ${disk}7172disk_ident=$(diskinfo -s ${disk})73disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')74disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')75disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')76eli_ident=$(diskinfo -s ${disk}.eli)77eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}')78eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}')79eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}')80atf_check_equal "$disk_ident" "$eli_ident"81atf_check_equal "$disk_descr" "$eli_descr"82atf_check_equal "$disk_rotrate" "$eli_rotrate"83atf_check_equal "$disk_zonemode" "$eli_zonemode"84}85preserve_disk_props_cleanup()86{87disk_cleanup88geli_test_cleanup89}9091atf_test_case physpath cleanup92physpath_head()93{94atf_set "descr" "geli should append /eli to the underlying device's physical path"95atf_set "require.user" "root"96atf_set "timeout" 1597}98physpath_body()99{100geli_test_setup101if ! error_message=$(geom_load_class_if_needed nop); then102atf_skip "$error_message"103fi104105attach_md md -s1m106# If the underlying device has no physical path, then geli should not107# create one.108atf_check -o empty -e ignore diskinfo -p $md109atf_check -s exit:0 geli onetime $md110atf_check -o empty -e ignore diskinfo -p $md.eli111atf_check -s exit:0 geli kill $md112113# If the underlying device does have a physical path, then geli should114# append "/eli"115physpath="some/physical/path"116atf_check gnop create -z $physpath ${md}117atf_check -s exit:0 geli onetime $md.nop118atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli119}120physpath_cleanup()121{122if [ -f "$TEST_MDS_FILE" ]; then123while read md; do124[ -c /dev/${md}.nop.eli ] && \125geli detach $md.nop.eli 2>/dev/null126[ -c /dev/${md}.nop ] && \127gnop destroy -f $md.nop 2>/dev/null128[ -c /dev/${md}.eli ] && \129geli detach $md.eli 2>/dev/null130mdconfig -d -u $md 2>/dev/null131done < $TEST_MDS_FILE132fi133true134}135136unaligned_io_test()137{138cipher=$1139secsize=$2140ealgo=${cipher%%:*}141keylen=${cipher##*:}142143atf_check -s exit:0 -e ignore \144geli init -B none -e $ealgo -l $keylen -P -K keyfile \145-s $secsize ${md}146atf_check geli attach -p -k keyfile ${md}147148atf_check $(atf_get_srcdir)/unaligned_io /dev/${md}.eli149}150151atf_test_case unaligned_io cleanup152unaligned_io_head()153{154atf_set "descr" "regression test for PR 271766"155atf_set "require.user" "root"156}157unaligned_io_body()158{159geli_test_setup160161sectors=4162163atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none164for_each_geli_config_nointegrity unaligned_io_test165}166unaligned_io_cleanup()167{168geli_test_cleanup169}170171atf_init_test_cases()172{173atf_add_test_case physpath174atf_add_test_case preserve_props175atf_add_test_case preserve_disk_props176atf_add_test_case unaligned_io177}178179common_cleanup()180{181if [ -f "$MD_DEVS" ]; then182while read test_md; do183gnop destroy -f ${test_md}.nop 2>/dev/null184mdconfig -d -u $test_md 2>/dev/null185done < $MD_DEVS186rm $MD_DEVS187fi188189if [ -f "$PLAINFILES" ]; then190while read f; do191rm -f ${f}192done < ${PLAINFILES}193rm ${PLAINFILES}194fi195true196}197198disk_cleanup()199{200disks=`atf_config_get disks`201disk=${disks%% *}202if [ -n "$disk" ]; then203geli kill ${disk} 2>/dev/null204fi205}206207208