aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2022-05-09 17:42:48 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2022-05-09 17:42:48 +0000
commit2400c536b478b1d218507d29ee74b309522d65f5 (patch)
tree9d4a5f284ab8eae4e9665ccc54b44c4224ad67df
parent7496792841b9528ed4160c1972449bfb1486bc41 (diff)
downloadsrc-2400c536b478b1d218507d29ee74b309522d65f5.tar.gz
src-2400c536b478b1d218507d29ee74b309522d65f5.zip
tests/unix_passfd: add test for shutdown(2) on a buffer with an fd
This has two goals: - Exercize call to unp_dispose() via soshutdown() instead of sofree() - Make sure that shutdown indeed dereferences the fd stored Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35122
-rw-r--r--tests/sys/kern/unix_passfd_test.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c
index 2b5cdde012c1..13b569479af8 100644
--- a/tests/sys/kern/unix_passfd_test.c
+++ b/tests/sys/kern/unix_passfd_test.c
@@ -118,6 +118,17 @@ getnfds(void)
return (n);
}
+static int
+openfiles(void)
+{
+ int files;
+ size_t len = sizeof(files);
+
+ ATF_REQUIRE(sysctlbyname("kern.openfiles", &files, &len, NULL, 0) == 0);
+
+ return (files);
+}
+
static void
putfds(char *buf, int fd, int nfds)
{
@@ -337,6 +348,28 @@ ATF_TC_BODY(send_and_cancel, tc)
}
/*
+ * Send file then shutdown receive side to exercise unp_dispose() call
+ * via soshutdown(). Check that shutdown(SHUT_RD) would gc the file
+ * reference sitting in the receive buffer. There is no good way of
+ * checking that except using global open file count.
+ */
+ATF_TC_WITHOUT_HEAD(send_and_shutdown);
+ATF_TC_BODY(send_and_shutdown, tc)
+{
+ int fd[2], putfd, nfiles;
+
+ domainsocketpair(fd);
+ tempfile(&putfd);
+ sendfd(fd[0], putfd);
+ nfiles = openfiles();
+ close(putfd);
+ ATF_REQUIRE(openfiles() == nfiles);
+ shutdown(fd[1], SHUT_RD);
+ ATF_REQUIRE(openfiles() == nfiles - 1);
+ closesocketpair(fd);
+}
+
+/*
* Send two files. Then receive them. Make sure they are returned in the
* right order, and both get there.
*/
@@ -722,6 +755,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, simple_send_fd_msg_cmsg_cloexec);
ATF_TP_ADD_TC(tp, send_and_close);
ATF_TP_ADD_TC(tp, send_and_cancel);
+ ATF_TP_ADD_TC(tp, send_and_shutdown);
ATF_TP_ADD_TC(tp, two_files);
ATF_TP_ADD_TC(tp, bundle);
ATF_TP_ADD_TC(tp, bundle_cancel);