aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2026-01-27 21:13:11 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2026-01-27 21:17:08 +0000
commit8a9508563542d709b1a42a065e6e99e004a8b3fe (patch)
tree72059aadd533a3b77226c352b61d8ea526bd3f91
parent938915a22c84af88afa587694e8d63ce9dd202f4 (diff)
tests/kern: make ssl_sendfile:truncate and ssl_sendfile:grow less flaky
First problem is a trivial race that the client thread doesn't see updated c.sbytes. Second problem applies only to the truncate test. On a machine with huge default buffer sizes, there is a chance that sendfile(2) will fill both buffers with amount of data that is larger than the size we plan to truncate. To minimise chances for this scenario, increase file size and truncate it less aggressively, also try to decrease buffer sizes.
-rw-r--r--tests/sys/kern/ssl_sendfile.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/sys/kern/ssl_sendfile.c b/tests/sys/kern/ssl_sendfile.c
index 928a44a50811..884079e80be5 100644
--- a/tests/sys/kern/ssl_sendfile.c
+++ b/tests/sys/kern/ssl_sendfile.c
@@ -42,7 +42,7 @@
#include <atf-c.h>
-#define FSIZE (size_t)(1024 * 1024)
+#define FSIZE (size_t)(2 * 1024 * 1024)
struct ctx {
EVP_PKEY *pkey; /* Self-signed key ... */
@@ -338,10 +338,15 @@ ATF_TC_BODY(truncate, tc)
char buf[128 * 1024];
size_t nread;
int n;
-#define TRUNC (FSIZE / 2)
+#define TRUNC (FSIZE - 1024)
common_init(&c);
+ ATF_REQUIRE(setsockopt(c.ss, SOL_SOCKET, SO_SNDBUF, &(int){FSIZE / 16},
+ sizeof(int)) == 0);
+ ATF_REQUIRE(setsockopt(c.cs, SOL_SOCKET, SO_RCVBUF, &(int){FSIZE / 16},
+ sizeof(int)) == 0);
+
sendme(&c, 0, 0, false);
/* Make sure sender is waiting on the socket buffer. */
while (poll(&(struct pollfd){ .fd = c.ss, .events = POLLOUT }, 1, 1)
@@ -354,7 +359,9 @@ ATF_TC_BODY(truncate, tc)
nread += n;
}
ATF_REQUIRE(nread == TRUNC);
+ ATF_REQUIRE(pthread_mutex_lock(&c.mtx) == 0);
ATF_REQUIRE(c.sbytes == TRUNC);
+ ATF_REQUIRE(pthread_mutex_unlock(&c.mtx) == 0);
common_cleanup(&c);
}
@@ -372,6 +379,11 @@ ATF_TC_BODY(grow, tc)
common_init(&c);
+ ATF_REQUIRE(setsockopt(c.ss, SOL_SOCKET, SO_SNDBUF, &(int){FSIZE / 16},
+ sizeof(int)) == 0);
+ ATF_REQUIRE(setsockopt(c.cs, SOL_SOCKET, SO_RCVBUF, &(int){FSIZE / 16},
+ sizeof(int)) == 0);
+
sendme(&c, 0, 0, false);
/* Make sure sender is waiting on the socket buffer. */
while (poll(&(struct pollfd){ .fd = c.ss, .events = POLLOUT }, 1, 1)
@@ -398,7 +410,9 @@ ATF_TC_BODY(grow, tc)
nread += n;
}
ATF_REQUIRE(nread == GROW);
+ ATF_REQUIRE(pthread_mutex_lock(&c.mtx) == 0);
ATF_REQUIRE(c.sbytes == FSIZE + GROW);
+ ATF_REQUIRE(pthread_mutex_unlock(&c.mtx) == 0);
common_cleanup(&c);
}