diff options
author | Matt Caswell <matt@openssl.org> | 2023-08-21 16:10:53 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2023-08-25 08:42:39 +0200 |
commit | 8c5284ff194f444877ae25012d3d07ee46e46219 (patch) | |
tree | 06070d435d0986c924975e3096d33bb504985120 | |
parent | 0b31072e086dc9a53f62cec60ea8d565320e640a (diff) |
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 <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21798)
-rw-r--r-- | test/quicapitest.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/quicapitest.c b/test/quicapitest.c index 91e63429a5..83a048bc74 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(); |