tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / librumpclient / t_fd.c
blobaa0d1ccc6945bafb0f1db89026f6251cf50b057b
1 /* $NetBSD: t_fd.c,v 1.4 2011/08/25 18:46:01 hannken Exp $ */
3 /*
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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>
31 #include <sys/stat.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
37 #include <atf-c.h>
38 #include <errno.h>
39 #include <fcntl.h>
40 #include <unistd.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 "
51 "fd > 2");
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 "
57 "SIGIO");
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)
67 struct stat sb;
69 RZ(system("rump_server " RUMPSERV));
70 RL(setenv("RUMP_SERVER", RUMPSERV, 1));
72 RL(dup2(0, 10));
73 RL(dup2(1, 11));
74 RL(dup2(2, 12));
76 RL(close(0));
77 RL(close(1));
78 RL(close(2));
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? */
90 dup2(10, 0);
91 dup2(11, 1);
92 dup2(12, 2);
95 static volatile sig_atomic_t sigcnt;
96 static void
97 gotsig(int sig)
100 sigcnt++;
103 ATF_TC_BODY(sigio, tc)
105 struct sockaddr_in sin;
106 int ls;
107 int cs;
108 int fl;
109 int sc;
111 signal(SIGIO, gotsig);
112 RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
113 RUMPSERV));
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)));
135 sc = sigcnt;
136 printf("sigcnt after connect: %d\n", sc);
137 ATF_REQUIRE(sc >= 1);
140 ATF_TP_ADD_TCS(tp)
142 ATF_TP_ADD_TC(tp, bigenough);
143 ATF_TP_ADD_TC(tp, sigio);
145 return atf_no_error();