1 /* $NetBSD: t_fd.c,v 1.4 2011/08/25 18:46:01 hannken Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
42 #include <rump/rumpclient.h>
43 #include <rump/rump_syscalls.h>
45 #include "../../h_macros.h"
47 ATF_TC_WITH_CLEANUP(bigenough
);
48 ATF_TC_HEAD(bigenough
, tc
)
50 atf_tc_set_md_var(tc
, "descr", "Check that rumpclient uses "
53 ATF_TC_WITH_CLEANUP(sigio
);
54 ATF_TC_HEAD(sigio
, tc
)
56 atf_tc_set_md_var(tc
, "descr", "Check that rump client receives "
60 #define RUMPSERV "unix://sucket"
62 ATF_TC_CLEANUP(bigenough
, tc
){system("env RUMP_SERVER=" RUMPSERV
" rump.halt");}
63 ATF_TC_CLEANUP(sigio
, tc
) { system("env RUMP_SERVER=" RUMPSERV
" rump.halt"); }
65 ATF_TC_BODY(bigenough
, tc
)
69 RZ(system("rump_server " RUMPSERV
));
70 RL(setenv("RUMP_SERVER", RUMPSERV
, 1));
80 RL(rumpclient_init());
81 RL(rump_sys_getpid());
83 ATF_REQUIRE_ERRNO(EBADF
, fstat(0, &sb
) == -1);
84 ATF_REQUIRE_ERRNO(EBADF
, fstat(1, &sb
) == -1);
85 ATF_REQUIRE_ERRNO(EBADF
, fstat(2, &sb
) == -1);
87 RL(rump_sys_getpid());
89 /* restore these. does it help? */
95 static volatile sig_atomic_t sigcnt
;
103 ATF_TC_BODY(sigio
, tc
)
105 struct sockaddr_in sin
;
111 signal(SIGIO
, gotsig
);
112 RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
114 RL(setenv("RUMP_SERVER", RUMPSERV
, 1));
116 RL(rumpclient_init());
117 RL(ls
= rump_sys_socket(PF_INET
, SOCK_STREAM
, 0));
119 RL(rump_sys_fcntl(ls
, F_SETOWN
, rump_sys_getpid()));
120 RL(fl
= rump_sys_fcntl(ls
, F_GETFL
));
121 RL(rump_sys_fcntl(ls
, F_SETFL
, fl
| O_ASYNC
));
123 memset(&sin
, 0, sizeof(sin
));
124 sin
.sin_len
= sizeof(sin
);
125 sin
.sin_family
= AF_INET
;
126 sin
.sin_port
= htons(12345);
127 RL(rump_sys_bind(ls
, (struct sockaddr
*)&sin
, sizeof(sin
)));
128 RL(rump_sys_listen(ls
, 5));
130 RL(cs
= rump_sys_socket(PF_INET
, SOCK_STREAM
, 0));
131 sin
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
133 ATF_REQUIRE_EQ(sigcnt
, 0);
134 RL(rump_sys_connect(cs
, (struct sockaddr
*)&sin
, sizeof(sin
)));
136 printf("sigcnt after connect: %d\n", sc
);
137 ATF_REQUIRE(sc
>= 1);
142 ATF_TP_ADD_TC(tp
, bigenough
);
143 ATF_TP_ADD_TC(tp
, sigio
);
145 return atf_no_error();