Thu Aug 25 18:46:01 2011 UTC ()
t_fd/sigio: pass test if we receive at least one SIGIO signal.

While a real kernel collects these signals until the connect() returns and
then delivers one signal rump delivers every signal so we get more than one.

Ok: Antti Kantee <pooka@netbsd.org>


(hannken)
diff -r1.3 -r1.4 src/tests/lib/librumpclient/t_fd.c

cvs diff -r1.3 -r1.4 src/tests/lib/librumpclient/t_fd.c (switch to unified diff)

--- src/tests/lib/librumpclient/t_fd.c 2011/08/15 15:19:08 1.3
+++ src/tests/lib/librumpclient/t_fd.c 2011/08/25 18:46:01 1.4
@@ -1,146 +1,146 @@ @@ -1,146 +1,146 @@
1/* $NetBSD: t_fd.c,v 1.3 2011/08/15 15:19:08 gson Exp $ */ 1/* $NetBSD: t_fd.c,v 1.4 2011/08/25 18:46:01 hannken Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32#include <sys/socket.h> 32#include <sys/socket.h>
33 33
34#include <netinet/in.h> 34#include <netinet/in.h>
35#include <arpa/inet.h> 35#include <arpa/inet.h>
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38#include <errno.h> 38#include <errno.h>
39#include <fcntl.h> 39#include <fcntl.h>
40#include <unistd.h> 40#include <unistd.h>
41 41
42#include <rump/rumpclient.h> 42#include <rump/rumpclient.h>
43#include <rump/rump_syscalls.h> 43#include <rump/rump_syscalls.h>
44 44
45#include "../../h_macros.h" 45#include "../../h_macros.h"
46 46
47ATF_TC_WITH_CLEANUP(bigenough); 47ATF_TC_WITH_CLEANUP(bigenough);
48ATF_TC_HEAD(bigenough, tc) 48ATF_TC_HEAD(bigenough, tc)
49{ 49{
50 atf_tc_set_md_var(tc, "descr", "Check that rumpclient uses " 50 atf_tc_set_md_var(tc, "descr", "Check that rumpclient uses "
51 "fd > 2"); 51 "fd > 2");
52} 52}
53ATF_TC_WITH_CLEANUP(sigio); 53ATF_TC_WITH_CLEANUP(sigio);
54ATF_TC_HEAD(sigio, tc) 54ATF_TC_HEAD(sigio, tc)
55{ 55{
56 atf_tc_set_md_var(tc, "descr", "Check that rump client receives " 56 atf_tc_set_md_var(tc, "descr", "Check that rump client receives "
57 "SIGIO"); 57 "SIGIO");
58} 58}
59 59
60#define RUMPSERV "unix://sucket" 60#define RUMPSERV "unix://sucket"
61 61
62ATF_TC_CLEANUP(bigenough, tc){system("env RUMP_SERVER=" RUMPSERV " rump.halt");} 62ATF_TC_CLEANUP(bigenough, tc){system("env RUMP_SERVER=" RUMPSERV " rump.halt");}
63ATF_TC_CLEANUP(sigio, tc) { system("env RUMP_SERVER=" RUMPSERV " rump.halt"); } 63ATF_TC_CLEANUP(sigio, tc) { system("env RUMP_SERVER=" RUMPSERV " rump.halt"); }
64 64
65ATF_TC_BODY(bigenough, tc) 65ATF_TC_BODY(bigenough, tc)
66{ 66{
67 struct stat sb; 67 struct stat sb;
68 68
69 RZ(system("rump_server " RUMPSERV)); 69 RZ(system("rump_server " RUMPSERV));
70 RL(setenv("RUMP_SERVER", RUMPSERV, 1)); 70 RL(setenv("RUMP_SERVER", RUMPSERV, 1));
71 71
72 RL(dup2(0, 10)); 72 RL(dup2(0, 10));
73 RL(dup2(1, 11)); 73 RL(dup2(1, 11));
74 RL(dup2(2, 12)); 74 RL(dup2(2, 12));
75 75
76 RL(close(0)); 76 RL(close(0));
77 RL(close(1)); 77 RL(close(1));
78 RL(close(2)); 78 RL(close(2));
79 79
80 RL(rumpclient_init()); 80 RL(rumpclient_init());
81 RL(rump_sys_getpid()); 81 RL(rump_sys_getpid());
82 82
83 ATF_REQUIRE_ERRNO(EBADF, fstat(0, &sb) == -1); 83 ATF_REQUIRE_ERRNO(EBADF, fstat(0, &sb) == -1);
84 ATF_REQUIRE_ERRNO(EBADF, fstat(1, &sb) == -1); 84 ATF_REQUIRE_ERRNO(EBADF, fstat(1, &sb) == -1);
85 ATF_REQUIRE_ERRNO(EBADF, fstat(2, &sb) == -1); 85 ATF_REQUIRE_ERRNO(EBADF, fstat(2, &sb) == -1);
86 86
87 RL(rump_sys_getpid()); 87 RL(rump_sys_getpid());
88 88
89 /* restore these. does it help? */ 89 /* restore these. does it help? */
90 dup2(10, 0); 90 dup2(10, 0);
91 dup2(11, 1); 91 dup2(11, 1);
92 dup2(12, 2); 92 dup2(12, 2);
93} 93}
94 94
95static volatile sig_atomic_t sigcnt; 95static volatile sig_atomic_t sigcnt;
96static void 96static void
97gotsig(int sig) 97gotsig(int sig)
98{ 98{
99 99
100 sigcnt++; 100 sigcnt++;
101} 101}
102 102
103ATF_TC_BODY(sigio, tc) 103ATF_TC_BODY(sigio, tc)
104{ 104{
105 struct sockaddr_in sin; 105 struct sockaddr_in sin;
106 int ls; 106 int ls;
107 int cs; 107 int cs;
108 int fl; 108 int fl;
109 int sc; 109 int sc;
110 110
111 signal(SIGIO, gotsig); 111 signal(SIGIO, gotsig);
112 RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet " 112 RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
113 RUMPSERV)); 113 RUMPSERV));
114 RL(setenv("RUMP_SERVER", RUMPSERV, 1)); 114 RL(setenv("RUMP_SERVER", RUMPSERV, 1));
115 115
116 RL(rumpclient_init()); 116 RL(rumpclient_init());
117 RL(ls = rump_sys_socket(PF_INET, SOCK_STREAM, 0)); 117 RL(ls = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
118 118
119 RL(rump_sys_fcntl(ls, F_SETOWN, rump_sys_getpid())); 119 RL(rump_sys_fcntl(ls, F_SETOWN, rump_sys_getpid()));
120 RL(fl = rump_sys_fcntl(ls, F_GETFL)); 120 RL(fl = rump_sys_fcntl(ls, F_GETFL));
121 RL(rump_sys_fcntl(ls, F_SETFL, fl | O_ASYNC)); 121 RL(rump_sys_fcntl(ls, F_SETFL, fl | O_ASYNC));
122 122
123 memset(&sin, 0, sizeof(sin)); 123 memset(&sin, 0, sizeof(sin));
124 sin.sin_len = sizeof(sin); 124 sin.sin_len = sizeof(sin);
125 sin.sin_family = AF_INET; 125 sin.sin_family = AF_INET;
126 sin.sin_port = htons(12345); 126 sin.sin_port = htons(12345);
127 RL(rump_sys_bind(ls, (struct sockaddr *)&sin, sizeof(sin))); 127 RL(rump_sys_bind(ls, (struct sockaddr *)&sin, sizeof(sin)));
128 RL(rump_sys_listen(ls, 5)); 128 RL(rump_sys_listen(ls, 5));
129 129
130 RL(cs = rump_sys_socket(PF_INET, SOCK_STREAM, 0)); 130 RL(cs = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
131 sin.sin_addr.s_addr = inet_addr("127.0.0.1"); 131 sin.sin_addr.s_addr = inet_addr("127.0.0.1");
132 132
133 ATF_REQUIRE_EQ(sigcnt, 0); 133 ATF_REQUIRE_EQ(sigcnt, 0);
134 RL(rump_sys_connect(cs, (struct sockaddr *)&sin, sizeof(sin))); 134 RL(rump_sys_connect(cs, (struct sockaddr *)&sin, sizeof(sin)));
135 sc = sigcnt; 135 sc = sigcnt;
136 printf("sigcnt after connect: %d\n", sc); 136 printf("sigcnt after connect: %d\n", sc);
137 ATF_REQUIRE_EQ(sc, 1); 137 ATF_REQUIRE(sc >= 1);
138} 138}
139 139
140ATF_TP_ADD_TCS(tp) 140ATF_TP_ADD_TCS(tp)
141{ 141{
142 ATF_TP_ADD_TC(tp, bigenough); 142 ATF_TP_ADD_TC(tp, bigenough);
143 ATF_TP_ADD_TC(tp, sigio); 143 ATF_TP_ADD_TC(tp, sigio);
144 144
145 return atf_no_error(); 145 return atf_no_error();
146} 146}