1 /* $NetBSD: t_pr.c,v 1.7 2011/04/26 20:42:01 martin Exp $ */
4 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Antti Kantee <pooka@NetBSD.org> and Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
42 #include <rump/rump.h>
43 #include <rump/rump_syscalls.h>
46 sendsome(int from
, int to
)
50 static const char msg
[] = "hello world\n";
51 char buf
[sizeof(msg
)+10];
53 memset(buf
, 0, sizeof(buf
));
54 rump_sys_write(from
, msg
, strlen(msg
));
55 cnt
= rump_sys_read(to
, buf
, sizeof(buf
));
56 if (cnt
< (ssize_t
)strlen(msg
)) {
57 printf("short message read: %zd chars: \"%s\"\n", cnt
, buf
);
60 for (i
= 0; i
< sizeof(buf
); i
++) {
61 if (buf
[i
] == '\r' || buf
[i
] == '\n') {
68 return strcmp(buf
, msg
) != 0;
72 exercise_ptytty(int master
, int slave
)
77 * send a few bytes from master to slave and read them back
79 error
= sendsome(master
, slave
);
84 rump_sys_ioctl(master
, TIOCFLUSH
, &flags
);
87 * and the same in the other direction
89 error
= sendsome(slave
, master
);
94 rump_sys_ioctl(master
, TIOCFLUSH
, &flags
);
99 ATF_TC_HEAD(client_first
, tc
)
102 atf_tc_set_md_var(tc
, "descr",
103 "test basic tty/pty operation when opening client side first");
106 ATF_TC_BODY(client_first
, tc
)
108 int master
, slave
, error
, v
;
111 slave
= rump_sys_open("/dev/ttyp1", O_RDWR
|O_NONBLOCK
);
112 ATF_CHECK(slave
!= -1);
114 master
= rump_sys_open("/dev/ptyp1", O_RDWR
);
115 ATF_CHECK(master
!= -1);
118 rump_sys_ioctl(slave
, FIOASYNC
, &v
);
119 error
= exercise_ptytty(master
, slave
);
120 ATF_CHECK(error
== 0);
122 rump_sys_close(master
);
123 rump_sys_close(slave
);
126 ATF_TC(master_first
);
127 ATF_TC_HEAD(master_first
, tc
)
130 atf_tc_set_md_var(tc
, "descr",
131 "test basic tty/pty operation when opening master side first");
134 ATF_TC_BODY(master_first
, tc
)
136 int master
, slave
, error
;
139 master
= rump_sys_open("/dev/ptyp1", O_RDWR
);
140 ATF_CHECK(master
!= -1);
142 slave
= rump_sys_open("/dev/ttyp1", O_RDWR
);
143 ATF_CHECK(slave
!= -1);
145 error
= exercise_ptytty(master
, slave
);
146 ATF_CHECK(error
== 0);
148 rump_sys_close(master
);
149 rump_sys_close(slave
);
153 ATF_TC_HEAD(ptyioctl
, tc
)
156 atf_tc_set_md_var(tc
, "descr",
157 "ioctl on pty with client side not open");
160 ATF_TC_BODY(ptyioctl
, tc
)
166 fd
= rump_sys_open("/dev/ptyp1", O_RDWR
);
170 * This used to die with null deref under ptcwakeup()
171 * atf_tc_expect_signal(-1, "PR kern/40688");
173 rump_sys_ioctl(fd
, TIOCGETA
, &tio
);
181 ATF_TP_ADD_TC(tp
, ptyioctl
);
182 ATF_TP_ADD_TC(tp
, client_first
);
183 ATF_TP_ADD_TC(tp
, master_first
);
185 return atf_no_error();