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