From 4b171f7d69c92a0a296bba1639eef5570e49697a Mon Sep 17 00:00:00 2001 From: anton Date: Fri, 22 Oct 2021 05:03:04 +0000 Subject: [PATCH] add pipe select hangup test case; ok mpi@ --- regress/sys/kern/pipe/Makefile | 4 +- regress/sys/kern/pipe/pipe.c | 3 +- regress/sys/kern/pipe/pipe.h | 3 +- regress/sys/kern/pipe/test-select.c | 57 +++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 regress/sys/kern/pipe/test-select.c diff --git a/regress/sys/kern/pipe/Makefile b/regress/sys/kern/pipe/Makefile index b2ee4cfc406..38d5413c0bb 100644 --- a/regress/sys/kern/pipe/Makefile +++ b/regress/sys/kern/pipe/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2020/12/16 22:59:55 bluhm Exp $ +# $OpenBSD: Makefile,v 1.5 2021/10/22 05:03:04 anton Exp $ PROG= pipe @@ -7,6 +7,7 @@ SRCS+= test-close.c SRCS+= test-kqueue.c SRCS+= test-ping-pong.c SRCS+= test-run-down.c +SRCS+= test-select.c SRCS+= test-thundering-herd.c LDADD+= -lpthread @@ -22,6 +23,7 @@ TESTS+= kqueue-write-eof TESTS+= ping-pong TESTS+= run-down-write-big TESTS+= run-down-write-small +TESTS+= select-hup TESTS+= thundering-herd-read-signal TESTS+= thundering-herd-read-wakeup TESTS+= thundering-herd-write-signal diff --git a/regress/sys/kern/pipe/pipe.c b/regress/sys/kern/pipe/pipe.c index 1352b543897..ce4d92a0ecb 100644 --- a/regress/sys/kern/pipe/pipe.c +++ b/regress/sys/kern/pipe/pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pipe.c,v 1.4 2020/06/29 18:25:37 anton Exp $ */ +/* $OpenBSD: pipe.c,v 1.5 2021/10/22 05:03:04 anton Exp $ */ /* * Copyright (c) 2019 Anton Lindqvist @@ -48,6 +48,7 @@ main(int argc, char *argv[]) { "ping-pong", test_ping_pong }, { "run-down-write-big", test_run_down_write_big }, { "run-down-write-small", test_run_down_write_small }, + { "select-hup", test_select_hup }, { "thundering-herd-read-signal", test_thundering_herd_read_signal }, { "thundering-herd-read-wakeup", test_thundering_herd_read_wakeup }, { "thundering-herd-write-signal", test_thundering_herd_write_signal }, diff --git a/regress/sys/kern/pipe/pipe.h b/regress/sys/kern/pipe/pipe.h index 93b2f316661..4bd910a7b08 100644 --- a/regress/sys/kern/pipe/pipe.h +++ b/regress/sys/kern/pipe/pipe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pipe.h,v 1.3 2020/06/29 18:25:37 anton Exp $ */ +/* $OpenBSD: pipe.h,v 1.4 2021/10/22 05:03:04 anton Exp $ */ /* * Copyright (c) 2019 Anton Lindqvist @@ -28,6 +28,7 @@ int test_kqueue_write_eof(void); int test_ping_pong(void); int test_run_down_write_big(void); int test_run_down_write_small(void); +int test_select_hup(void); int test_thundering_herd_read_signal(void); int test_thundering_herd_read_wakeup(void); int test_thundering_herd_write_signal(void); diff --git a/regress/sys/kern/pipe/test-select.c b/regress/sys/kern/pipe/test-select.c new file mode 100644 index 00000000000..e2865eddbed --- /dev/null +++ b/regress/sys/kern/pipe/test-select.c @@ -0,0 +1,57 @@ +/* $OpenBSD: test-select.c,v 1.1 2021/10/22 05:03:04 anton Exp $ */ + +/* + * Copyright (c) 2021 Anton Lindqvist + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#include +#include + +#include "pipe.h" + +/* + * Verify select(2) hangup semantics. + */ +int +test_select_hup(void) +{ + fd_set writefds; + ssize_t n; + int pip[2]; + int nready; + char c = 'c'; + + if (pipe(pip) == -1) + err(1, "pipe"); + close(pip[0]); + + FD_ZERO(&writefds); + FD_SET(pip[1], &writefds); + nready = select(pip[1] + 1, NULL, &writefds, NULL, NULL); + if (nready == -1) + err(1, "select"); + if (nready != 1) + errx(1, "select: want 1, got %d", nready); + n = write(pip[1], &c, sizeof(c)); + if (n != -1) + errx(1, "read: want -1, got %zd", n); + if (errno != EPIPE) + errx(1, "errno: want %d, got %d", EPIPE, errno); + + return 0; +} -- 2.20.1