From 8c5284ff194f444877ae25012d3d07ee46e46219 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Mon, 21 Aug 2023 16:10:53 +0100 Subject: [PATCH] Test that we send multiple datagrams in one go if appropriate If we have enough data for more than one datagram then we should send more than one datagram Reviewed-by: Hugo Landau Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/21798) --- test/quicapitest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/quicapitest.c b/test/quicapitest.c index 91e63429a52..83a048bc744 100644 --- a/test/quicapitest.c +++ b/test/quicapitest.c @@ -949,6 +949,60 @@ static int test_back_pressure(void) return testresult; } + +static int dgram_ctr = 0; + +static void dgram_cb(int write_p, int version, int content_type, + const void *buf, size_t msglen, SSL *ssl, void *arg) +{ + if (!write_p) + return; + + if (content_type != SSL3_RT_QUIC_DATAGRAM) + return; + + dgram_ctr++; +} + +/* Test that we send multiple datagrams in one go when appropriate */ +static int test_multiple_dgrams(void) +{ + SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method()); + SSL *clientquic = NULL; + QUIC_TSERVER *qtserv = NULL; + int testresult = 0; + unsigned char *buf; + const size_t buflen = 1400; + size_t written; + + buf = OPENSSL_zalloc(buflen); + + if (!TEST_ptr(cctx) + || !TEST_ptr(buf) + || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert, + privkey, 0, &qtserv, + &clientquic, NULL)) + || !TEST_true(qtest_create_quic_connection(qtserv, clientquic))) + goto err; + + dgram_ctr = 0; + SSL_set_msg_callback(clientquic, dgram_cb); + if (!TEST_true(SSL_write_ex(clientquic, buf, buflen, &written)) + || !TEST_size_t_eq(written, buflen) + /* We wrote enough data for 2 datagrams */ + || !TEST_int_eq(dgram_ctr, 2)) + goto err; + + testresult = 1; + err: + OPENSSL_free(buf); + SSL_free(clientquic); + ossl_quic_tserver_free(qtserv); + SSL_CTX_free(cctx); + + return testresult; +} + OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n") int setup_tests(void) @@ -1017,6 +1071,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_quic_set_fd, 3); ADD_TEST(test_bio_ssl); ADD_TEST(test_back_pressure); + ADD_TEST(test_multiple_dgrams); return 1; err: cleanup_tests(); -- 2.47.2