1# SPDX-License-Identifier: BSD-2-Clause 2# 3# Copyright (c) 2024 Axcient 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS DOCUMENTATION IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26. $(atf_get_srcdir)/ctl.subr 27 28# TODO: 29# * format layer 30# * IMM bit 31# * LOEJ 32# * noflush 33# * power conditions 34 35# Not Tested 36# * Power Condition Modifier (not implemented in CTL) 37 38atf_test_case eject cleanup 39eject_head() 40{ 41 atf_set "descr" "START STOP UNIT can eject a CDROM device" 42 atf_set "require.user" "root" 43 atf_set "require.progs" "sg_start sg_readcap ctladm" 44} 45eject_body() 46{ 47 # -t 5 for CD/DVD device type 48 create_ramdisk -t 5 49 50 # Verify that the device is online 51 # Too bad I don't know of any other way to check that it's stopped but 52 # by using sg_readcap. 53 atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev 54 55 # eject the device 56 atf_check sg_start --eject /dev/$dev 57 58 # Ejected, it should now return ENXIO 59 atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null 60} 61eject_cleanup() 62{ 63 cleanup 64} 65 66atf_test_case load cleanup 67load_head() 68{ 69 atf_set "descr" "START STOP UNIT can load a CDROM device" 70 atf_set "require.user" "root" 71 atf_set "require.progs" "sg_start sg_readcap ctladm" 72} 73load_body() 74{ 75 # -t 5 for CD/DVD device type 76 create_ramdisk -t 5 77 78 # eject the device 79 atf_check sg_start --eject /dev/$dev 80 81 # Verify that it's offline it should now return ENXIO 82 atf_check -s exit:1 -o ignore -e match:"Device not configured" dd if=/dev/$dev bs=4096 count=1 of=/dev/null 83 84 # Load it again 85 atf_check sg_start --load /dev/$dev 86 87 atf_check -o ignore -e ignore dd if=/dev/$dev bs=4096 count=1 of=/dev/null 88 atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev 89} 90load_cleanup() 91{ 92 cleanup 93} 94 95atf_test_case start cleanup 96start_head() 97{ 98 atf_set "descr" "START STOP UNIT can start a device" 99 atf_set "require.user" "root" 100 atf_set "require.progs" "sg_start sg_readcap ctladm" 101} 102start_body() 103{ 104 create_ramdisk 105 106 # stop the device 107 atf_check sg_start --stop /dev/$dev 108 109 # And start it again 110 atf_check sg_start /dev/$dev 111 112 # Now sg_readcap should succeed. Too bad I don't know of any other way 113 # to check that it's stopped. 114 atf_check -o ignore -e not-match:"Device not ready" sg_readcap /dev/$dev 115} 116start_cleanup() 117{ 118 cleanup 119} 120 121atf_test_case stop cleanup 122stop_head() 123{ 124 atf_set "descr" "START STOP UNIT can stop a device" 125 atf_set "require.user" "root" 126 atf_set "require.progs" "sg_start sg_readcap ctladm" 127} 128stop_body() 129{ 130 create_ramdisk 131 132 # Stop the device 133 atf_check sg_start --stop /dev/$dev 134 135 # Now sg_readcap should fail. Too bad I don't know of any other way to 136 # check that it's stopped. 137 atf_check -s exit:2 -e match:"Device not ready" sg_readcap /dev/$dev 138} 139stop_cleanup() 140{ 141 cleanup 142} 143 144atf_init_test_cases() 145{ 146 atf_add_test_case eject 147 atf_add_test_case load 148 atf_add_test_case start 149 atf_add_test_case stop 150} 151