aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2026-03-10 17:36:21 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2026-03-10 21:02:40 +0000
commit35b976c6ce6145678ab378b21fdeab687a0a76d5 (patch)
treee9813e62630aee7b90433fe4166ad157484a64bb
parent96c5eaf0ac6b98d0832e1037d672064de43a7e00 (diff)
tests/kern/ssl_sendfile: reduce copy & paste
Provide sendme_locked_wait() for a common pattern. Not functional change.
-rw-r--r--tests/sys/kern/ssl_sendfile.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/sys/kern/ssl_sendfile.c b/tests/sys/kern/ssl_sendfile.c
index 884079e80be5..066674f5fb03 100644
--- a/tests/sys/kern/ssl_sendfile.c
+++ b/tests/sys/kern/ssl_sendfile.c
@@ -253,6 +253,14 @@ sendme_locked(struct ctx *c, off_t offset, size_t size, bool nb)
}
static void
+sendme_locked_wait(struct ctx *c, off_t offset, size_t size, bool nb)
+{
+ sendme_locked(c, offset, size, nb);
+ while (c->state != READY)
+ ATF_REQUIRE(pthread_cond_wait(&c->cv, &c->mtx) == 0);
+}
+
+static void
sendme(struct ctx *c, off_t offset, size_t size, bool nb)
{
ATF_REQUIRE(pthread_mutex_lock(&c->mtx) == 0);
@@ -454,9 +462,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
* socket. Internall sendfile(2) returns -1 and errno == EAGAIN.
*/
ATF_REQUIRE(pthread_mutex_lock(&c.mtx) == 0);
- sendme_locked(&c, 0, FSIZE, true);
- while (c.state != READY)
- ATF_REQUIRE(pthread_cond_wait(&c.cv, &c.mtx) == 0);
+ sendme_locked_wait(&c, 0, FSIZE, true);
ATF_REQUIRE(c.sbytes > 0);
ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == 0);
#if 0 /* see https://github.com/openssl/openssl/issues/29742 */
@@ -466,9 +472,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
/*
* Exercise second attempt on already full buffer.
*/
- sendme_locked(&c, 0, FSIZE, true);
- while (c.state != READY)
- ATF_REQUIRE(pthread_cond_wait(&c.cv, &c.mtx) == 0);
+ sendme_locked_wait(&c, 0, FSIZE, true);
ATF_REQUIRE(c.sbytes == -1);
ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == SSL_ERROR_WANT_WRITE);
ATF_REQUIRE(BIO_should_retry(SSL_get_wbio(c.srv)));
@@ -489,9 +493,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
* legitimate one. This test just documents the existing behavior
* rather than asserts that this is a correct behavior.
*/
- sendme_locked(&c, FSIZE, 0, true);
- while (c.state != READY)
- ATF_REQUIRE(pthread_cond_wait(&c.cv, &c.mtx) == 0);
+ sendme_locked_wait(&c, FSIZE, 0, true);
ATF_REQUIRE(c.sbytes == 0);
ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == SSL_ERROR_SYSCALL);
#if 0 /* see https://github.com/openssl/openssl/issues/29742 */
@@ -501,9 +503,7 @@ ATF_TC_BODY(eagain_vs_eof, tc)
/*
* Exercise short write due to end of file.
*/
- sendme_locked(&c, FSIZE - 100, 0, true);
- while (c.state != READY)
- ATF_REQUIRE(pthread_cond_wait(&c.cv, &c.mtx) == 0);
+ sendme_locked_wait(&c, FSIZE - 100, 0, true);
ATF_REQUIRE(c.sbytes == 100);
ATF_REQUIRE(SSL_get_error(c.srv, c.sbytes) == 0);
#if 0 /* see https://github.com/openssl/openssl/issues/29742 */