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.
This commit is contained in:
Gleb Smirnoff
2026-01-27 13:13:11 -08:00
parent 938915a22c
commit 8a95085635
+16 -2
View File
@@ -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);
}