Path: blob/main/tests/sys/cam/ctl/start_stop_unit.sh
39536 views
# SPDX-License-Identifier: BSD-2-Clause1#2# Copyright (c) 2024 Axcient3# All rights reserved.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS DOCUMENTATION IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,18# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425. $(atf_get_srcdir)/ctl.subr2627# TODO:28# * format layer29# * IMM bit30# * LOEJ31# * noflush32# * power conditions3334# Not Tested35# * Power Condition Modifier (not implemented in CTL)3637atf_test_case eject cleanup38eject_head()39{40atf_set "descr" "START STOP UNIT can eject a CDROM device"41atf_set "require.user" "root"42atf_set "require.progs" "sg_start sg_readcap ctladm"43}44eject_body()45{46# -t 5 for CD/DVD device type47create_ramdisk -t 54849# Verify that the device is online50# Too bad I don't know of any other way to check that it's stopped but51# by using sg_readcap.52atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev5354# eject the device55atf_check sg_start --eject /dev/$dev5657# Ejected, it should now return ENXIO58atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null59}60eject_cleanup()61{62cleanup63}6465atf_test_case load cleanup66load_head()67{68atf_set "descr" "START STOP UNIT can load a CDROM device"69atf_set "require.user" "root"70atf_set "require.progs" "sg_start sg_readcap ctladm"71}72load_body()73{74# -t 5 for CD/DVD device type75create_ramdisk -t 57677# eject the device78atf_check sg_start --eject /dev/$dev7980# Verify that it's offline it should now return ENXIO81atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null8283# Load it again84atf_check sg_start --load /dev/$dev8586atf_check -o ignore -e ignore dd if=/dev/$dev bs=4096 count=1 of=/dev/null87atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev88}89load_cleanup()90{91cleanup92}9394atf_test_case start cleanup95start_head()96{97atf_set "descr" "START STOP UNIT can start a device"98atf_set "require.user" "root"99atf_set "require.progs" "sg_start sg_readcap ctladm"100}101start_body()102{103create_ramdisk104105# stop the device106atf_check sg_start --stop /dev/$dev107108# And start it again109atf_check sg_start /dev/$dev110111# Now sg_readcap should succeed. Too bad I don't know of any other way112# to check that it's stopped.113atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev114}115start_cleanup()116{117cleanup118}119120atf_test_case stop cleanup121stop_head()122{123atf_set "descr" "START STOP UNIT can stop a device"124atf_set "require.user" "root"125atf_set "require.progs" "sg_start sg_readcap ctladm"126}127stop_body()128{129create_ramdisk130131# Stop the device132atf_check sg_start --stop /dev/$dev133134# Now sg_readcap should fail. Too bad I don't know of any other way to135# check that it's stopped.136atf_check -s exit:2 -e match:"Device not ready" sg_readcap /dev/$dev137}138stop_cleanup()139{140cleanup141}142143atf_init_test_cases()144{145atf_add_test_case eject146atf_add_test_case load147atf_add_test_case start148atf_add_test_case stop149}150151152