From 7fa216095a7ebcfa8fbf9f6143b0fb336e77c964 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 28 Feb 2023 20:25:53 +0100 Subject: [PATCH] test_rstream_random(): Test adding final empty frame Reviewed-by: Matt Caswell Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/19794) --- test/quic_stream_test.c | 51 ++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/test/quic_stream_test.c b/test/quic_stream_test.c index e8174eacea4..e7690ff20f2 100644 --- a/test/quic_stream_test.c +++ b/test/quic_stream_test.c @@ -328,17 +328,20 @@ static int test_single_copy_read(QUIC_RSTREAM *qrs, *readbytes = 0; - while (ossl_quic_rstream_get_record(qrs, &record, &rec_len, fin)) { - if (rec_len > 0) { - if (rec_len > size) { - rec_len = size; - *fin = 0; - } - memcpy(buf, record, rec_len); - size -= rec_len; - *readbytes += rec_len; - buf += rec_len; + for (;;) { + if (!ossl_quic_rstream_get_record(qrs, &record, &rec_len, fin)) + return 0; + if (rec_len == 0) + break; + if (rec_len > size) { + rec_len = size; + *fin = 0; } + memcpy(buf, record, rec_len); + size -= rec_len; + *readbytes += rec_len; + buf += rec_len; + if (!ossl_quic_rstream_release_record(qrs, rec_len)) return 0; if (*fin || size == 0) @@ -457,7 +460,7 @@ static int test_rstream_random(int idx) QUIC_RSTREAM *rstream = NULL; size_t i, read_off, queued_min, queued_max; const size_t data_size = 10000; - int r, s, fin; + int r, s, fin = 0, fin_set = 0; int ret = 0; size_t readbytes = 0; @@ -474,7 +477,7 @@ static int test_rstream_random(int idx) for (s = 0; s < 10; ++s) { size_t off = (r * 10 + s) * 10, size = 10; - if (test_random() % 5 == 0) + if (test_random() % 10 == 0) /* drop packet */ continue; @@ -529,9 +532,31 @@ static int test_rstream_random(int idx) queued_max - read_off + 1)) || !TEST_true(ossl_quic_rstream_move_to_rbuf(rstream))) goto err; + if (!fin_set && queued_max >= data_size - test_random() % 200) { + fin_set = 1; + /* Queue empty fin frame */ + if (!TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, data_size, + NULL, 0, 1))) + goto err; + } } - TEST_info("Total read bytes: %zu", read_off); + TEST_info("Total read bytes: %zu Fin rcvd: %d", read_off, fin); + + if (read_off == data_size && fin_set && !fin) { + /* We might still receive the final empty frame */ + if (idx % 2 == 0) { + if (!TEST_true(test_single_copy_read(rstream, read_buf, data_size, + &readbytes, &fin))) + goto err; + } else if (!TEST_true(ossl_quic_rstream_read(rstream, read_buf, + data_size, + &readbytes, &fin))) { + goto err; + } + if (!TEST_size_t_eq(readbytes, 0) || !TEST_true(fin)) + goto err; + } ret = 1; -- 2.47.2