Skip to content

Commit bb28424

Browse files
committed
test_dtls: change approach in want_write hs testing
1 parent 412a782 commit bb28424

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

tests/api/test_dtls.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,21 @@ int test_dtls13_hrr_want_write(void)
621621
return EXPECT_RESULT();
622622
}
623623

624+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
625+
struct test_dtls13_wwrite_ctx {
626+
int want_write;
627+
struct test_memio_ctx *text_ctx;
628+
};
629+
static int test_dtls13_want_write_send_cb(WOLFSSL *ssl, char *data, int sz, void *ctx)
630+
{
631+
struct test_dtls13_wwrite_ctx *wwctx = (struct test_dtls13_wwrite_ctx *)ctx;
632+
wwctx->want_write = !wwctx->want_write;
633+
if (wwctx->want_write) {
634+
return WOLFSSL_CBIO_ERR_WANT_WRITE;
635+
}
636+
return test_memio_write_cb(ssl, data, sz, wwctx->text_ctx);
637+
}
638+
#endif
624639
int test_dtls13_every_write_want_write(void)
625640
{
626641
EXPECT_DECLS;
@@ -631,52 +646,37 @@ int test_dtls13_every_write_want_write(void)
631646
const char msg[] = "want-write";
632647
const int msgLen = sizeof(msg);
633648
char readBuf[sizeof(msg)];
634-
int hs_complete[2] = {0};
635-
int rounds = 0;
636-
int ret, err;
637-
WOLFSSL* ssl;
638-
int side;
649+
struct test_dtls13_wwrite_ctx wwctx_c;
650+
struct test_dtls13_wwrite_ctx wwctx_s;
639651

640652
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
641653

642654
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
643655
wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method),
644656
0);
645657

646-
while ((!hs_complete[0] || !hs_complete[1]) && rounds < 10) {
647-
rounds++;
648-
for (side = 0; side < 2; side++) {
649-
ssl = (side == 0) ? ssl_s : ssl_c;
650-
if (hs_complete[side])
651-
continue;
652-
653-
test_memio_simulate_want_write(&test_ctx, side, 1);
654-
ret = wolfSSL_negotiate(ssl);
655-
if (ret != WOLFSSL_SUCCESS) {
656-
err = wolfSSL_get_error(ssl, ret);
657-
if (err == WOLFSSL_ERROR_WANT_WRITE) {
658-
test_memio_simulate_want_write(&test_ctx, side, 0);
659-
ret = wolfSSL_negotiate(ssl);
660-
}
661-
}
662-
if (ret == WOLFSSL_SUCCESS) {
663-
hs_complete[side] = 1;
664-
continue;
665-
}
666-
else {
667-
ExpectIntEQ(ret, -1);
668-
ExpectIntEQ(wolfSSL_get_error(ssl, ret),
669-
WOLFSSL_ERROR_WANT_READ);
670-
}
671-
}
672-
}
658+
wwctx_c.want_write = 0;
659+
wwctx_c.text_ctx = &test_ctx;
660+
wolfSSL_SetIOWriteCtx(ssl_c, &wwctx_c);
661+
wolfSSL_SSLSetIOSend(ssl_c, test_dtls13_want_write_send_cb);
662+
wwctx_s.want_write = 0;
663+
wwctx_s.text_ctx = &test_ctx;
664+
wolfSSL_SetIOWriteCtx(ssl_s, &wwctx_s);
665+
wolfSSL_SSLSetIOSend(ssl_s, test_dtls13_want_write_send_cb);
666+
667+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 20, NULL), 0);
673668

674669
ExpectTrue(wolfSSL_is_init_finished(ssl_c));
675670
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
676671

677672
test_memio_simulate_want_write(&test_ctx, 0, 0);
678673
test_memio_simulate_want_write(&test_ctx, 1, 0);
679674

675+
wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
676+
wolfSSL_SSLSetIOSend(ssl_c, test_memio_write_cb);
677+
wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
678+
wolfSSL_SSLSetIOSend(ssl_s, test_memio_write_cb);
679+
680680
XMEMSET(readBuf, 0, sizeof(readBuf));
681681
ExpectIntEQ(wolfSSL_write(ssl_c, msg, msgLen), msgLen);
682682
ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), msgLen);

0 commit comments

Comments
 (0)