From nobody Thu Sep 19 20:24:52 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X8n7T3bHkz5XLcF; Thu, 19 Sep 2024 20:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X8n7T0bqJz4cqd; Thu, 19 Sep 2024 20:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NFmUvHHuWrKTKd5DiTKt+OZGxLNBsE/0vku+Y7Fjtl4=; b=PAnHuxhe0sQr2SHahqIkXMvJc41Y+8BvclBEStsi7g0SFBOZ0Pz/Gh1+LCKpkdrYDaamrq Ly5K3nSEBaHc4MQK5sY87THUrq/60z53gKsCvmzcejLtX2Jk8xJ9RGSvqQKJZFg5wq9Y/J jlAAOJJeFyVAsbSlUigJsXLB4SUz2gLPXfPhqDeEA3WsI61TqcKVpzbQBHIWxvsWWXWz/X +8YCB/Muz3rEVT0MnvGk2gKRhj82mD1WQCVjvYy2wgflr7pqLwcHG1w/dy4N6ThBFUf4dn ZyXWaX3gbrixsEZJ+XOJpBN5AYrHBoYk80BeJusQs38KwLY37tMd8DaDUQ7AzQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726777493; a=rsa-sha256; cv=none; b=FpdJFnNz1ehYQ7UP6WGUTamKBHNcG8ppjKmC01VUp7ZWuWq7nJfjv7HeZKrwuWtJs7OUrg +7w0zdNvpQR1x4i57GxucdoqjOBASgglskwg6MjhKZY+T6tyq7xCWqW/AG5+0HDYZeKmrV a1wVezL7QYIpP6hM7nq54uEYeSNTEWedqAt8OzbN2gpoLZ7Yuqvumn/LemgFFK6AB6pTWT TaIaMSbuz7tRUQyGi7FJb+9PpUwRcsEWRGrRZ/gjEJCGaQ/meJf2n7jZY5Q0qn89GIAeyd 4xq5GQx7WAPkYUm4BK/P7kpA5bTFy8ZQw8bQSxpfBJfmNgaT8rzg6i0QzQOW6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NFmUvHHuWrKTKd5DiTKt+OZGxLNBsE/0vku+Y7Fjtl4=; b=dV5XvPvcfdgUghjfcmzE9Pas0ClHCWeWMs19C95d+PtlXkrJBXAhwHW+yRmpNi4HhYBatG dMVuRKikjladE7+QZpLkxPZx+fFhvnwZxttNnbobaaAVmkadHdSt99WFRpbo1EcRdGNPf2 4ZSfHqrhQHAdT3pyhEuiqCj7KhwLAqvDuIfa4ruuYKoW3ah+xMAvVKW4V6I2EcQhO886OC 7ZrZ00O/87j+xyAWMiwg1haNTwh65GSqouR+m4OC875wWJqnK3dexPWuOXytVvImQx7K/j eJu0JfQhJ/GLYwd6TzDz0QQW+6Z/vX97yK3KCVZKnPEdH4rRwthXpWA5VzEwOQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X8n7T0CdZzL6N; Thu, 19 Sep 2024 20:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48JKOqDS052895; Thu, 19 Sep 2024 20:24:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JKOq3R052892; Thu, 19 Sep 2024 20:24:52 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:24:52 GMT Message-Id: <202409192024.48JKOq3R052892@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 37357ba28a6d - stable/14 - ctl: add tests for START STOP UNIT List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 37357ba28a6dd984043a60e16084bd79071d95e2 Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=37357ba28a6dd984043a60e16084bd79071d95e2 commit 37357ba28a6dd984043a60e16084bd79071d95e2 Author: Alan Somers AuthorDate: 2024-08-23 20:51:32 +0000 Commit: Alan Somers CommitDate: 2024-09-19 20:23:59 +0000 ctl: add tests for START STOP UNIT Sponsored by: Axcient Reviewed by: emaste, markj Pull Request: https://github.com/freebsd/freebsd-src/pull/1409 (cherry picked from commit fe1755fa6bb4039c1e00f5226c473a024685005b) --- tests/sys/cam/ctl/Makefile | 5 +- tests/sys/cam/ctl/ctl.subr | 94 ++++++++++++++++++++++ tests/sys/cam/ctl/read_buffer.sh | 72 +++-------------- tests/sys/cam/ctl/start_stop_unit.sh | 150 +++++++++++++++++++++++++++++++++++ 4 files changed, 257 insertions(+), 64 deletions(-) diff --git a/tests/sys/cam/ctl/Makefile b/tests/sys/cam/ctl/Makefile index 0e6f39a1a56f..1b857bb0c291 100644 --- a/tests/sys/cam/ctl/Makefile +++ b/tests/sys/cam/ctl/Makefile @@ -2,9 +2,12 @@ PACKAGE= tests TESTSDIR= ${TESTSBASE}/sys/cam/ctl +${PACKAGE}FILES+= ctl.subr + ATF_TESTS_SH+= read_buffer +ATF_TESTS_SH+= start_stop_unit # Must be exclusive because it disables/enables camsim -TEST_METADATA.read_buffer+= is_exclusive="true" +TEST_METADATA+= is_exclusive="true" .include diff --git a/tests/sys/cam/ctl/ctl.subr b/tests/sys/cam/ctl/ctl.subr new file mode 100644 index 000000000000..18991e0fa144 --- /dev/null +++ b/tests/sys/cam/ctl/ctl.subr @@ -0,0 +1,94 @@ +# vim: filetype=sh + +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Axcient +# All rights reserved. +# +# 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 DOCUMENTATION IS PROVIDED BY THE AUTHOR ``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 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. + +load_modules() { + if ! kldstat -q -m ctl; then + kldload ctl || atf_skip "could not load ctl kernel mod" + fi + if ! ctladm port -o on -p 0; then + atf_skip "could not enable the camsim frontend" + fi +} + +find_device() { + LUN=$1 + + # Rescan camsim + # XXX camsim doesn't update when creating a new device. Worse, a + # rescan won't look for new devices. So we must disable/re-enable it. + # Worse still, enabling it isn't synchronous, so we need a retry loop + # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=281000 + retries=5 + ctladm port -o off -p 0 >/dev/null + ctladm port -o on -p 0 >/dev/null + HEXLUN=`printf %x $LUN` + while true; do + dev=`camcontrol devlist | awk -v lun=$HEXLUN '/FREEBSD CTL/ && $9==lun {split($10, fields, /[,]/); print fields[1];}' | sed 's:[()]::'` + if [ -z "$dev" -o ! -c /dev/$dev ]; then + retries=$(( $retries - 1 )) + if [ $retries -eq 0 ]; then + cat lun-create.txt + camcontrol devlist + atf_fail "Could not find GEOM device" + fi + sleep 0.1 + continue + fi + break + done + # Ensure that it's actually ready. camcontrol may report the disk's + # ident before it's actually ready to receive commands. Maybe that's + # because all of the GEOM providers must probe it? + while true; do + dd if=/dev/$dev bs=4096 count=1 of=/dev/null >/dev/null 2>/dev/null && break + retries=$(( $retries - 1 )) + if [ $retries -eq 0 ]; then + atf_fail "Device never became ready" + fi + sleep 0.1 + done +} + +# Create a CTL LUN +create_ramdisk() { + EXTRA_ARGS=$* + + atf_check -o save:lun-create.txt ctladm create -b ramdisk -s 1048576 $EXTRA_ARGS + atf_check egrep -q "LUN created successfully" lun-create.txt + LUN=`awk '/LUN ID:/ {print $NF}' lun-create.txt` + if [ -z "$LUN" ]; then + atf_fail "Could not find LUN id" + fi + find_device $LUN +} + +cleanup() { + if [ -e "lun-create.txt" ]; then + lun_id=`awk '/LUN ID:/ {print $NF}' lun-create.txt` + ctladm remove -b ramdisk -l $lun_id > /dev/null + fi +} diff --git a/tests/sys/cam/ctl/read_buffer.sh b/tests/sys/cam/ctl/read_buffer.sh index 4a84eb6b9725..e54b0dadc134 100644 --- a/tests/sys/cam/ctl/read_buffer.sh +++ b/tests/sys/cam/ctl/read_buffer.sh @@ -28,61 +28,7 @@ # * Buffer ID other than 0. We don't support those. # * The Mode Specific field. We don't support it. -load_modules() { - if ! kldstat -q -m ctl; then - kldload ctl || atf_skip "could not load ctl kernel mod" - fi - if ! ctladm port -o on -p 0; then - atf_skip "could not enable the camsim frontend" - fi -} - -find_da_device() { - SERIAL=$1 - - # Rescan camsim - # XXX camsim doesn't update when creating a new device. Worse, a - # rescan won't look for new devices. So we must disable/re-enable it. - # Worse still, enabling it isn't synchronous, so we need a retry loop - # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=281000 - retries=5 - ctladm port -o off -p 0 >/dev/null - ctladm port -o on -p 0 >/dev/null - while true; do - - # Find the corresponding da device - da=`geom disk list | awk -v serial=$SERIAL ' /Geom name:/ { devname=$NF } /ident:/ && $NF ~ serial { print devname; exit } '` - if [ -z "$da" ]; then - retries=$(( $retries - 1 )) - if [ $retries -eq 0 ]; then - cat lun-create.txt - geom disk list - atf_fail "Could not find da device" - fi - sleep 0.1 - continue - fi - break - done -} - -# Create a CTL LUN -create_ramdisk() { - atf_check -o save:lun-create.txt ctladm create -b ramdisk -s 1048576 - atf_check egrep -q "LUN created successfully" lun-create.txt - SERIAL=`awk '/Serial Number:/ {print $NF}' lun-create.txt` - if [ -z "$SERIAL" ]; then - atf_fail "Could not find serial number" - fi - find_da_device $SERIAL -} - -cleanup() { - if [ -e "lun-create.txt" ]; then - lun_id=`awk '/LUN ID:/ {print $NF}' lun-create.txt` - ctladm remove -b ramdisk -l $lun_id > /dev/null - fi -} +. $(atf_get_srcdir)/ctl.subr atf_test_case basic cleanup basic_head() @@ -98,10 +44,10 @@ basic_body() # Write to its buffer cp /etc/passwd input len=`wc -c input | cut -wf 2` - atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$da + atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$dev # Read it back - atf_check -o save:output sg_read_buffer --mode data -l $len --raw /dev/$da + atf_check -o save:output sg_read_buffer --mode data -l $len --raw /dev/$dev # And verify if ! diff -q input output; then @@ -126,7 +72,7 @@ desc_body() { create_ramdisk - atf_check -o inline:" 00 00 04 00 00\n" sg_read_buffer --hex --mode desc /dev/$da + atf_check -o inline:" 00 00 04 00 00\n" sg_read_buffer --hex --mode desc /dev/$dev } desc_cleanup() { @@ -147,10 +93,10 @@ length_body() # Write to its buffer atf_check -o ignore -e ignore dd if=/dev/random of=input bs=4096 count=1 atf_check -o ignore -e ignore dd if=input bs=2048 count=1 of=expected - atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$da + atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$dev # Read it back - atf_check -o save:output sg_read_buffer --mode data -l 2048 --raw /dev/$da + atf_check -o save:output sg_read_buffer --mode data -l 2048 --raw /dev/$dev # And verify if ! diff -q expected output; then @@ -176,10 +122,10 @@ offset_body() # Write to its buffer atf_check -o ignore -e ignore dd if=/dev/random of=input bs=4096 count=1 atf_check -o ignore -e ignore dd if=input iseek=2 bs=512 count=1 of=expected - atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$da + atf_check -o ignore sg_write_buffer --mode data --in=input /dev/$dev # Read it back - atf_check -o save:output sg_read_buffer --mode data -l 512 -o 1024 --raw /dev/$da + atf_check -o save:output sg_read_buffer --mode data -l 512 -o 1024 --raw /dev/$dev # And verify if ! diff -q expected output; then @@ -203,7 +149,7 @@ uninitialized_body() create_ramdisk # Read an uninitialized buffer - atf_check -o save:output sg_read_buffer --mode data -l 262144 --raw /dev/$da + atf_check -o save:output sg_read_buffer --mode data -l 262144 --raw /dev/$dev # And verify atf_check -o ignore -e ignore dd if=/dev/zero bs=262144 count=1 of=expected diff --git a/tests/sys/cam/ctl/start_stop_unit.sh b/tests/sys/cam/ctl/start_stop_unit.sh new file mode 100644 index 000000000000..163011c8f574 --- /dev/null +++ b/tests/sys/cam/ctl/start_stop_unit.sh @@ -0,0 +1,150 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Axcient +# All rights reserved. +# +# 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 DOCUMENTATION IS PROVIDED BY THE AUTHOR ``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 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. + +. $(atf_get_srcdir)/ctl.subr + +# TODO: +# * format layer +# * IMM bit +# * LOEJ +# * noflush +# * power conditions + +# Not Tested +# * Power Condition Modifier (not implemented in CTL) + +atf_test_case eject cleanup +eject_head() +{ + atf_set "descr" "START STOP UNIT can eject a CDROM device" + atf_set "require.user" "root" + atf_set "require.progs" sg_start sg_readcap +} +eject_body() +{ + # -t 5 for CD/DVD device type + create_ramdisk -t 5 + + # Verify that the device is online + # Too bad I don't know of any other way to check that it's stopped but + # by using sg_readcap. + atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev + + # eject the device + atf_check sg_start --eject /dev/$dev + + # Ejected, it should now return ENXIO + atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null +} +eject_cleanup() +{ + cleanup +} + +atf_test_case load cleanup +load_head() +{ + atf_set "descr" "START STOP UNIT can load a CDROM device" + atf_set "require.user" "root" + atf_set "require.progs" sg_start sg_readcap +} +load_body() +{ + # -t 5 for CD/DVD device type + create_ramdisk -t 5 + + # eject the device + atf_check sg_start --eject /dev/$dev + + # Verify that it's offline it should now return ENXIO + atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null + + # Load it again + atf_check sg_start --load /dev/$dev + + atf_check -o ignore -e ignore dd if=/dev/$dev bs=4096 count=1 of=/dev/null + atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev +} +load_cleanup() +{ + cleanup +} + +atf_test_case start cleanup +start_head() +{ + atf_set "descr" "START STOP UNIT can start a device" + atf_set "require.user" "root" + atf_set "require.progs" sg_start sg_readcap +} +start_body() +{ + create_ramdisk + + # stop the device + atf_check sg_start --stop /dev/$dev + + # And start it again + atf_check sg_start /dev/$dev + + # Now sg_readcap should succeed. Too bad I don't know of any other way + # to check that it's stopped. + atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev +} +start_cleanup() +{ + cleanup +} + +atf_test_case stop cleanup +stop_head() +{ + atf_set "descr" "START STOP UNIT can stop a device" + atf_set "require.user" "root" + atf_set "require.progs" sg_start sg_readcap +} +stop_body() +{ + create_ramdisk + + # Stop the device + atf_check sg_start --stop /dev/$dev + + # Now sg_readcap should fail. Too bad I don't know of any other way to + # check that it's stopped. + atf_check -s exit:2 -e match:"Device not ready" sg_readcap /dev/$dev +} +stop_cleanup() +{ + cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case eject + atf_add_test_case load + atf_add_test_case start + atf_add_test_case stop +}