Skip to content

Commit

Permalink
test_rstream_random(): Test adding final empty frame
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #19794)
  • Loading branch information
t8m committed Mar 6, 2023
1 parent 330ce4a commit 7fa2160
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions test/quic_stream_test.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 7fa2160

Please sign in to comment.