Sun Mar 28 17:30:01 2021 UTC ()
yield so we can lose packets


(christos)
diff -r1.7 -r1.8 src/tests/lib/libc/sys/t_sendrecv.c

cvs diff -r1.7 -r1.8 src/tests/lib/libc/sys/t_sendrecv.c (expand / switch to unified diff)

--- src/tests/lib/libc/sys/t_sendrecv.c 2021/03/21 16:58:07 1.7
+++ src/tests/lib/libc/sys/t_sendrecv.c 2021/03/28 17:30:01 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $ */ 1/* $NetBSD: t_sendrecv.c,v 1.8 2021/03/28 17:30:01 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -19,37 +19,38 @@ @@ -19,37 +19,38 @@
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__RCSID("$NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $"); 32__RCSID("$NetBSD: t_sendrecv.c,v 1.8 2021/03/28 17:30:01 christos Exp $");
33 33
34#include <atf-c.h> 34#include <atf-c.h>
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
37 37
38#include <string.h> 38#include <string.h>
39#include <stdint.h> 39#include <stdint.h>
40#include <errno.h> 40#include <errno.h>
41#include <stdio.h> 41#include <stdio.h>
42#include <stdlib.h> 42#include <stdlib.h>
 43#include <sched.h>
43#include <unistd.h> 44#include <unistd.h>
44#include <signal.h> 45#include <signal.h>
45 46
46 47
47#define COUNT 100 48#define COUNT 100
48 49
49union packet { 50union packet {
50 uint8_t buf[1316]; 51 uint8_t buf[1316];
51 uintmax_t seq; 52 uintmax_t seq;
52}; 53};
53 54
54static volatile sig_atomic_t rdied; 55static volatile sig_atomic_t rdied;
55 56
@@ -84,26 +85,28 @@ receiver(int sd) @@ -84,26 +85,28 @@ receiver(int sd)
84 ssize_t n; 85 ssize_t n;
85 uintmax_t seq = 0; 86 uintmax_t seq = 0;
86 87
87 for (size_t i = 0; i < COUNT; i++) { 88 for (size_t i = 0; i < COUNT; i++) {
88 if (rdied) 89 if (rdied)
89 return; 90 return;
90 while ((n = recv(sd, &p, sizeof(p), 0), sizeof(p)) 91 while ((n = recv(sd, &p, sizeof(p), 0), sizeof(p))
91 == sizeof(p)) 92 == sizeof(p))
92 { 93 {
93 if (rdied) 94 if (rdied)
94 return; 95 return;
95 if (p.seq != seq) 96 if (p.seq != seq)
96 printf("%ju != %ju\n", p.seq, seq); 97 printf("%ju != %ju\n", p.seq, seq);
 98 if (seq % 10 == 0)
 99 sched_yield();
97 seq = p.seq + 1; 100 seq = p.seq + 1;
98 } 101 }
99// printf("<<%zd %d %ju\n", n, errno, seq); 102// printf("<<%zd %d %ju\n", n, errno, seq);
100 if (n == 0) 103 if (n == 0)
101 return; 104 return;
102 ATF_REQUIRE_EQ(n, -1); 105 ATF_REQUIRE_EQ(n, -1);
103 ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno)); 106 ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno));
104 } 107 }
105 close(sd); 108 close(sd);
106} 109}
107 110
108static void 111static void
109sendrecv(int rerror) 112sendrecv(int rerror)