xref: /freebsd/contrib/netbsd-tests/dev/scsipi/t_cd.c (revision 1a36faad54665288ed4eb839d2a4699ae2ead45e)
1*63d1fd59SEnji Cooper /*	$NetBSD: t_cd.c,v 1.8 2017/01/13 21:30:39 christos Exp $	*/
257718be8SEnji Cooper 
357718be8SEnji Cooper /*
457718be8SEnji Cooper  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
557718be8SEnji Cooper  *
657718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
757718be8SEnji Cooper  * modification, are permitted provided that the following conditions
857718be8SEnji Cooper  * are met:
957718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1057718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1157718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1257718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1357718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1457718be8SEnji Cooper  *
1557718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1657718be8SEnji Cooper  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1757718be8SEnji Cooper  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1857718be8SEnji Cooper  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1957718be8SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2057718be8SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2157718be8SEnji Cooper  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2257718be8SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2357718be8SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2457718be8SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2557718be8SEnji Cooper  * SUCH DAMAGE.
2657718be8SEnji Cooper  */
2757718be8SEnji Cooper 
2857718be8SEnji Cooper #include <sys/types.h>
2957718be8SEnji Cooper #include <sys/ioctl.h>
3057718be8SEnji Cooper 
3157718be8SEnji Cooper #include <atf-c.h>
3257718be8SEnji Cooper #include <fcntl.h>
3357718be8SEnji Cooper #include <signal.h>
3457718be8SEnji Cooper #include <stdio.h>
3557718be8SEnji Cooper #include <util.h>
3657718be8SEnji Cooper 
3757718be8SEnji Cooper #include <rump/rump.h>
3857718be8SEnji Cooper #include <rump/rump_syscalls.h>
3957718be8SEnji Cooper 
4057718be8SEnji Cooper #include "scsitest.h"
4157718be8SEnji Cooper 
42*63d1fd59SEnji Cooper #include "h_macros.h"
4357718be8SEnji Cooper 
4457718be8SEnji Cooper ATF_TC(noisyeject);
ATF_TC_HEAD(noisyeject,tc)4557718be8SEnji Cooper ATF_TC_HEAD(noisyeject, tc)
4657718be8SEnji Cooper {
4757718be8SEnji Cooper 
4857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "test for CD eject noisyness "
4957718be8SEnji Cooper 	    "(PR kern/43785)");
5057718be8SEnji Cooper }
5157718be8SEnji Cooper 
ATF_TC_BODY(noisyeject,tc)5257718be8SEnji Cooper ATF_TC_BODY(noisyeject, tc)
5357718be8SEnji Cooper {
5457718be8SEnji Cooper 	static char fname[] = "/dev/rcd0_";
5557718be8SEnji Cooper 	int part, fd, arg = 0;
5657718be8SEnji Cooper 
5757718be8SEnji Cooper 	RL(part = getrawpartition());
5857718be8SEnji Cooper 	fname[strlen(fname)-1] = 'a' + part;
5957718be8SEnji Cooper 	rump_init();
6057718be8SEnji Cooper 	/*
6157718be8SEnji Cooper 	 * Rump CD emulation has been fixed, so no longer a problem.
6257718be8SEnji Cooper 	 *
6357718be8SEnji Cooper 	atf_tc_expect_signal(SIGSEGV, "PR kern/47646: Broken test or "
6457718be8SEnji Cooper 	    "a real problem in rump or the driver");
6557718be8SEnji Cooper 	 */
6657718be8SEnji Cooper 	RL(fd = rump_sys_open(fname, O_RDWR));
6757718be8SEnji Cooper 	RL(rump_sys_ioctl(fd, DIOCEJECT, &arg));
6857718be8SEnji Cooper 
6957718be8SEnji Cooper 	ATF_REQUIRE_EQ(rump_scsitest_err[RUMP_SCSITEST_NOISYSYNC], 0);
7057718be8SEnji Cooper 	RL(rump_sys_close(fd));
7157718be8SEnji Cooper 	// atf_tc_expect_fail("PR kern/43785");
7257718be8SEnji Cooper 	ATF_REQUIRE_EQ(rump_scsitest_err[RUMP_SCSITEST_NOISYSYNC], 0);
7357718be8SEnji Cooper }
7457718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)7557718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
7657718be8SEnji Cooper {
7757718be8SEnji Cooper 
7857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, noisyeject);
7957718be8SEnji Cooper 
8057718be8SEnji Cooper 	return atf_no_error();
8157718be8SEnji Cooper }
82