diff options
author | Tomas Mraz <tomas@openssl.org> | 2023-01-09 18:39:50 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2023-01-27 16:11:38 +0100 |
commit | 3a857b9532169b1ffaa739ba29cd67a5d93cbe8a (patch) | |
tree | c335a84a2b4a7f99c35a6e8b78ecdc2fe2f15558 /test/bio_dgram_test.c | |
parent | 6e193d4d03f6c7bdf95e82e226c5fccbd67562f2 (diff) |
Implement BIO_s_dgram_mem() reusing the BIO_s_dgram_pair() code
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20012)
Diffstat (limited to 'test/bio_dgram_test.c')
-rw-r--r-- | test/bio_dgram_test.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/test/bio_dgram_test.c b/test/bio_dgram_test.c index f802d11f35..e925942a44 100644 --- a/test/bio_dgram_test.c +++ b/test/bio_dgram_test.c @@ -489,7 +489,7 @@ err: return ret; } -static int test_bio_dgram_pair(void) +static int test_bio_dgram_pair(int idx) { int testresult = 0, blen, mtu1, mtu2, r; BIO *bio1 = NULL, *bio2 = NULL; @@ -513,8 +513,13 @@ static int test_bio_dgram_pair(void) for (i = 0; i < OSSL_NELEM(key); ++i) key[i] = test_random(); - if (!TEST_int_eq(BIO_new_bio_dgram_pair(&bio1, 0, &bio2, 0), 1)) - goto err; + if (idx == 0) { + if (!TEST_int_eq(BIO_new_bio_dgram_pair(&bio1, 0, &bio2, 0), 1)) + goto err; + } else { + if (!TEST_ptr(bio1 = bio2 = BIO_new(BIO_s_dgram_mem()))) + goto err; + } mtu1 = BIO_dgram_get_mtu(bio1); if (!TEST_int_ge(mtu1, 1280)) @@ -530,7 +535,7 @@ static int test_bio_dgram_pair(void) if (!TEST_int_le(mtu1, sizeof(scratch) - 4)) goto err; - for (i = 0;; ++i) { + for (i = 0; idx == 0 || i < 9; ++i) { if (!TEST_int_eq(random_data(key, scratch, sizeof(scratch), i), 1)) goto err; @@ -630,8 +635,8 @@ static int test_bio_dgram_pair(void) msgs[0].peer = addr1; /* fails due to lack of caps on peer */ - if (!TEST_false(BIO_sendmmsg(bio1, msgs, sizeof(BIO_MSG), OSSL_NELEM(msgs), - 0, &num_processed)) + if (!TEST_false(BIO_sendmmsg(bio1, msgs, sizeof(BIO_MSG), + OSSL_NELEM(msgs), 0, &num_processed)) || !TEST_size_t_eq(num_processed, 0)) goto err; @@ -644,7 +649,7 @@ static int test_bio_dgram_pair(void) if (!TEST_int_eq(BIO_dgram_get_effective_caps(bio1), ref_caps)) goto err; - if (!TEST_int_eq(BIO_dgram_get_effective_caps(bio2), 0)) + if (idx == 0 && !TEST_int_eq(BIO_dgram_get_effective_caps(bio2), 0)) goto err; if (!TEST_int_eq(BIO_dgram_set_caps(bio1, ref_caps), 1)) @@ -739,7 +744,8 @@ static int test_bio_dgram_pair(void) testresult = 1; err: - BIO_free(bio1); + if (idx == 0) + BIO_free(bio1); BIO_free(bio2); BIO_ADDR_free(addr1); BIO_ADDR_free(addr2); @@ -760,7 +766,7 @@ int setup_tests(void) #if !defined(OPENSSL_NO_DGRAM) && !defined(OPENSSL_NO_SOCK) ADD_ALL_TESTS(test_bio_dgram, OSSL_NELEM(bio_dgram_cases)); # if !defined(OPENSSL_NO_CHACHA) - ADD_TEST(test_bio_dgram_pair); + ADD_ALL_TESTS(test_bio_dgram_pair, 2); # endif #endif |