quic_stream_test.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "internal/packet.h"
  10. #include "internal/quic_stream.h"
  11. #include "testutil.h"
  12. static int compare_iov(const unsigned char *ref, size_t ref_len,
  13. const OSSL_QTX_IOVEC *iov, size_t iov_len)
  14. {
  15. size_t i, total_len = 0;
  16. const unsigned char *cur = ref;
  17. for (i = 0; i < iov_len; ++i)
  18. total_len += iov[i].buf_len;
  19. if (ref_len != total_len)
  20. return 0;
  21. for (i = 0; i < iov_len; ++i) {
  22. if (memcmp(cur, iov[i].buf, iov[i].buf_len))
  23. return 0;
  24. cur += iov[i].buf_len;
  25. }
  26. return 1;
  27. }
  28. static const unsigned char data_1[] = {
  29. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  30. 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f
  31. };
  32. static int test_sstream_simple(void)
  33. {
  34. int testresult = 0;
  35. QUIC_SSTREAM *sstream = NULL;
  36. OSSL_QUIC_FRAME_STREAM hdr;
  37. OSSL_QTX_IOVEC iov[2];
  38. size_t num_iov = 0, wr = 0, i, init_size = 8192;
  39. if (!TEST_ptr(sstream = ossl_quic_sstream_new(init_size)))
  40. goto err;
  41. /* Should not have any data yet */
  42. num_iov = OSSL_NELEM(iov);
  43. if (!TEST_false(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  44. &num_iov)))
  45. goto err;
  46. /* Append data */
  47. if (!TEST_true(ossl_quic_sstream_append(sstream, data_1, sizeof(data_1),
  48. &wr))
  49. || !TEST_size_t_eq(wr, sizeof(data_1)))
  50. goto err;
  51. /* Read data */
  52. num_iov = OSSL_NELEM(iov);
  53. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  54. &num_iov))
  55. || !TEST_size_t_gt(num_iov, 0)
  56. || !TEST_uint64_t_eq(hdr.offset, 0)
  57. || !TEST_uint64_t_eq(hdr.len, sizeof(data_1))
  58. || !TEST_false(hdr.is_fin))
  59. goto err;
  60. if (!TEST_true(compare_iov(data_1, sizeof(data_1), iov, num_iov)))
  61. goto err;
  62. /* Mark data as half transmitted */
  63. if (!TEST_true(ossl_quic_sstream_mark_transmitted(sstream, 0, 7)))
  64. goto err;
  65. /* Read data */
  66. num_iov = OSSL_NELEM(iov);
  67. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  68. &num_iov))
  69. || !TEST_size_t_gt(num_iov, 0)
  70. || !TEST_uint64_t_eq(hdr.offset, 8)
  71. || !TEST_uint64_t_eq(hdr.len, sizeof(data_1) - 8)
  72. || !TEST_false(hdr.is_fin))
  73. goto err;
  74. if (!TEST_true(compare_iov(data_1 + 8, sizeof(data_1) - 8, iov, num_iov)))
  75. goto err;
  76. if (!TEST_true(ossl_quic_sstream_mark_transmitted(sstream, 8, 15)))
  77. goto err;
  78. /* Read more data; should not be any more */
  79. num_iov = OSSL_NELEM(iov);
  80. if (!TEST_false(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  81. &num_iov)))
  82. goto err;
  83. /* Now we have lost bytes 4-6 */
  84. if (!TEST_true(ossl_quic_sstream_mark_lost(sstream, 4, 6)))
  85. goto err;
  86. /* Should be able to read them */
  87. num_iov = OSSL_NELEM(iov);
  88. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  89. &num_iov))
  90. || !TEST_size_t_gt(num_iov, 0)
  91. || !TEST_uint64_t_eq(hdr.offset, 4)
  92. || !TEST_uint64_t_eq(hdr.len, 3)
  93. || !TEST_false(hdr.is_fin))
  94. goto err;
  95. if (!TEST_true(compare_iov(data_1 + 4, 3, iov, num_iov)))
  96. goto err;
  97. /* Retransmit */
  98. if (!TEST_true(ossl_quic_sstream_mark_transmitted(sstream, 4, 6)))
  99. goto err;
  100. /* Read more data; should not be any more */
  101. num_iov = OSSL_NELEM(iov);
  102. if (!TEST_false(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  103. &num_iov)))
  104. goto err;
  105. if (!TEST_size_t_eq(ossl_quic_sstream_get_buffer_used(sstream), 16))
  106. goto err;
  107. /* Data has been acknowledged, space should be not be freed yet */
  108. if (!TEST_true(ossl_quic_sstream_mark_acked(sstream, 1, 7))
  109. || !TEST_size_t_eq(ossl_quic_sstream_get_buffer_used(sstream), 16))
  110. goto err;
  111. /* Now data should be freed */
  112. if (!TEST_true(ossl_quic_sstream_mark_acked(sstream, 0, 0))
  113. || !TEST_size_t_eq(ossl_quic_sstream_get_buffer_used(sstream), 8))
  114. goto err;
  115. if (!TEST_true(ossl_quic_sstream_mark_acked(sstream, 0, 15))
  116. || !TEST_size_t_eq(ossl_quic_sstream_get_buffer_used(sstream), 0))
  117. goto err;
  118. /* Now FIN */
  119. ossl_quic_sstream_fin(sstream);
  120. /* Get FIN frame */
  121. for (i = 0; i < 2; ++i) {
  122. num_iov = OSSL_NELEM(iov);
  123. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  124. &num_iov))
  125. || !TEST_uint64_t_eq(hdr.offset, 16)
  126. || !TEST_uint64_t_eq(hdr.len, 0)
  127. || !TEST_true(hdr.is_fin)
  128. || !TEST_size_t_eq(num_iov, 0))
  129. goto err;
  130. }
  131. if (!TEST_true(ossl_quic_sstream_mark_transmitted_fin(sstream, 16)))
  132. goto err;
  133. /* Read more data; FIN should not be returned any more */
  134. num_iov = OSSL_NELEM(iov);
  135. if (!TEST_false(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  136. &num_iov)))
  137. goto err;
  138. /* Lose FIN frame */
  139. if (!TEST_true(ossl_quic_sstream_mark_lost_fin(sstream)))
  140. goto err;
  141. /* Get FIN frame */
  142. for (i = 0; i < 2; ++i) {
  143. num_iov = OSSL_NELEM(iov);
  144. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  145. &num_iov))
  146. || !TEST_uint64_t_eq(hdr.offset, 16)
  147. || !TEST_uint64_t_eq(hdr.len, 0)
  148. || !TEST_true(hdr.is_fin)
  149. || !TEST_size_t_eq(num_iov, 0))
  150. goto err;
  151. }
  152. if (!TEST_true(ossl_quic_sstream_mark_transmitted_fin(sstream, 16)))
  153. goto err;
  154. /* Read more data; FIN should not be returned any more */
  155. num_iov = OSSL_NELEM(iov);
  156. if (!TEST_false(ossl_quic_sstream_get_stream_frame(sstream, 0, &hdr, iov,
  157. &num_iov)))
  158. goto err;
  159. /* Acknowledge fin. */
  160. if (!TEST_true(ossl_quic_sstream_mark_acked_fin(sstream)))
  161. goto err;
  162. testresult = 1;
  163. err:
  164. ossl_quic_sstream_free(sstream);
  165. return testresult;
  166. }
  167. static int test_sstream_bulk(int idx)
  168. {
  169. int testresult = 0;
  170. QUIC_SSTREAM *sstream = NULL;
  171. OSSL_QUIC_FRAME_STREAM hdr;
  172. OSSL_QTX_IOVEC iov[2];
  173. size_t i, j, num_iov = 0, init_size = 8192, l;
  174. size_t consumed = 0, total_written = 0, rd, cur_rd, expected = 0, start_at;
  175. unsigned char *src_buf = NULL, *dst_buf = NULL;
  176. unsigned char *ref_src_buf = NULL, *ref_dst_buf = NULL;
  177. unsigned char *ref_dst_cur, *ref_src_cur, *dst_cur;
  178. if (!TEST_ptr(sstream = ossl_quic_sstream_new(init_size)))
  179. goto err;
  180. if (!TEST_size_t_eq(ossl_quic_sstream_get_buffer_size(sstream), init_size))
  181. goto err;
  182. if (!TEST_ptr(src_buf = OPENSSL_zalloc(init_size)))
  183. goto err;
  184. if (!TEST_ptr(dst_buf = OPENSSL_malloc(init_size)))
  185. goto err;
  186. if (!TEST_ptr(ref_src_buf = OPENSSL_malloc(init_size)))
  187. goto err;
  188. if (!TEST_ptr(ref_dst_buf = OPENSSL_malloc(init_size)))
  189. goto err;
  190. /*
  191. * Append a preliminary buffer to allow later code to exercise wraparound.
  192. */
  193. if (!TEST_true(ossl_quic_sstream_append(sstream, src_buf, init_size / 2,
  194. &consumed))
  195. || !TEST_size_t_eq(consumed, init_size / 2)
  196. || !TEST_true(ossl_quic_sstream_mark_transmitted(sstream, 0,
  197. init_size / 2 - 1))
  198. || !TEST_true(ossl_quic_sstream_mark_acked(sstream, 0,
  199. init_size / 2 - 1)))
  200. goto err;
  201. start_at = init_size / 2;
  202. /* Generate a random buffer. */
  203. for (i = 0; i < init_size; ++i)
  204. src_buf[i] = (unsigned char)(test_random() & 0xFF);
  205. /* Append bytes into the buffer in chunks of random length. */
  206. ref_src_cur = ref_src_buf;
  207. do {
  208. l = (test_random() % init_size) + 1;
  209. if (!TEST_true(ossl_quic_sstream_append(sstream, src_buf, l, &consumed)))
  210. goto err;
  211. memcpy(ref_src_cur, src_buf, consumed);
  212. ref_src_cur += consumed;
  213. total_written += consumed;
  214. } while (consumed > 0);
  215. if (!TEST_size_t_eq(ossl_quic_sstream_get_buffer_used(sstream), init_size)
  216. || !TEST_size_t_eq(ossl_quic_sstream_get_buffer_avail(sstream), 0))
  217. goto err;
  218. /*
  219. * Randomly select bytes out of the buffer by marking them as transmitted.
  220. * Record the remaining bytes, which should be the sequence of bytes
  221. * returned.
  222. */
  223. ref_src_cur = ref_src_buf;
  224. ref_dst_cur = ref_dst_buf;
  225. for (i = 0; i < total_written; ++i) {
  226. if ((test_random() & 1) != 0) {
  227. *ref_dst_cur++ = *ref_src_cur;
  228. ++expected;
  229. } else if (!TEST_true(ossl_quic_sstream_mark_transmitted(sstream,
  230. start_at + i,
  231. start_at + i)))
  232. goto err;
  233. ++ref_src_cur;
  234. }
  235. /* Exercise resize. */
  236. if (!TEST_true(ossl_quic_sstream_set_buffer_size(sstream, init_size * 2))
  237. || !TEST_true(ossl_quic_sstream_set_buffer_size(sstream, init_size)))
  238. goto err;
  239. /* Readout and verification. */
  240. dst_cur = dst_buf;
  241. for (i = 0, rd = 0; rd < expected; ++i) {
  242. num_iov = OSSL_NELEM(iov);
  243. if (!TEST_true(ossl_quic_sstream_get_stream_frame(sstream, i, &hdr, iov,
  244. &num_iov)))
  245. goto err;
  246. cur_rd = 0;
  247. for (j = 0; j < num_iov; ++j) {
  248. if (!TEST_size_t_le(iov[j].buf_len + rd, expected))
  249. goto err;
  250. memcpy(dst_cur, iov[j].buf, iov[j].buf_len);
  251. dst_cur += iov[j].buf_len;
  252. cur_rd += iov[j].buf_len;
  253. }
  254. if (!TEST_uint64_t_eq(cur_rd, hdr.len))
  255. goto err;
  256. rd += cur_rd;
  257. }
  258. if (!TEST_mem_eq(dst_buf, rd, ref_dst_buf, expected))
  259. goto err;
  260. testresult = 1;
  261. err:
  262. OPENSSL_free(src_buf);
  263. OPENSSL_free(dst_buf);
  264. OPENSSL_free(ref_src_buf);
  265. OPENSSL_free(ref_dst_buf);
  266. ossl_quic_sstream_free(sstream);
  267. return testresult;
  268. }
  269. static int test_single_copy_read(QUIC_RSTREAM *qrs,
  270. unsigned char *buf, size_t size,
  271. size_t *readbytes, int *fin)
  272. {
  273. const unsigned char *record;
  274. size_t rec_len;
  275. *readbytes = 0;
  276. for (;;) {
  277. if (!ossl_quic_rstream_get_record(qrs, &record, &rec_len, fin))
  278. return 0;
  279. if (rec_len == 0)
  280. break;
  281. if (rec_len > size) {
  282. rec_len = size;
  283. *fin = 0;
  284. }
  285. memcpy(buf, record, rec_len);
  286. size -= rec_len;
  287. *readbytes += rec_len;
  288. buf += rec_len;
  289. if (!ossl_quic_rstream_release_record(qrs, rec_len))
  290. return 0;
  291. if (*fin || size == 0)
  292. break;
  293. }
  294. return 1;
  295. }
  296. static const unsigned char simple_data[] =
  297. "Hello world! And thank you for all the fish!";
  298. static int test_rstream_simple(int idx)
  299. {
  300. QUIC_RSTREAM *rstream = NULL;
  301. int ret = 0;
  302. unsigned char buf[sizeof(simple_data)];
  303. size_t readbytes = 0, avail = 0;
  304. int fin = 0;
  305. int use_rbuf = idx > 1;
  306. int use_sc = idx % 2;
  307. int (* read_fn)(QUIC_RSTREAM *, unsigned char *, size_t, size_t *,
  308. int *) = use_sc ? test_single_copy_read
  309. : ossl_quic_rstream_read;
  310. if (!TEST_ptr(rstream = ossl_quic_rstream_new(NULL, NULL, 0)))
  311. goto err;
  312. if (!TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, 5,
  313. simple_data + 5, 10, 0))
  314. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  315. sizeof(simple_data) - 1,
  316. simple_data + sizeof(simple_data) - 1,
  317. 1, 1))
  318. || !TEST_true(ossl_quic_rstream_peek(rstream, buf, sizeof(buf),
  319. &readbytes, &fin))
  320. || !TEST_false(fin)
  321. || !TEST_size_t_eq(readbytes, 0)
  322. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  323. sizeof(simple_data) - 10,
  324. simple_data + sizeof(simple_data) - 10,
  325. 10, 1))
  326. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, 0,
  327. simple_data, 1, 0))
  328. || !TEST_true(ossl_quic_rstream_peek(rstream, buf, sizeof(buf),
  329. &readbytes, &fin))
  330. || !TEST_false(fin)
  331. || !TEST_size_t_eq(readbytes, 1)
  332. || !TEST_mem_eq(buf, 1, simple_data, 1)
  333. || (use_rbuf && !TEST_false(ossl_quic_rstream_move_to_rbuf(rstream)))
  334. || (use_rbuf
  335. && !TEST_true(ossl_quic_rstream_resize_rbuf(rstream,
  336. sizeof(simple_data))))
  337. || (use_rbuf && !TEST_true(ossl_quic_rstream_move_to_rbuf(rstream)))
  338. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  339. 0, simple_data,
  340. 10, 0))
  341. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  342. sizeof(simple_data),
  343. NULL,
  344. 0, 1))
  345. || !TEST_true(ossl_quic_rstream_peek(rstream, buf, sizeof(buf),
  346. &readbytes, &fin))
  347. || !TEST_false(fin)
  348. || !TEST_size_t_eq(readbytes, 15)
  349. || !TEST_mem_eq(buf, 15, simple_data, 15)
  350. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  351. 15,
  352. simple_data + 15,
  353. sizeof(simple_data) - 15, 1))
  354. || !TEST_true(ossl_quic_rstream_available(rstream, &avail, &fin))
  355. || !TEST_true(fin)
  356. || !TEST_size_t_eq(avail, sizeof(simple_data))
  357. || !TEST_true(read_fn(rstream, buf, 2, &readbytes, &fin))
  358. || !TEST_false(fin)
  359. || !TEST_size_t_eq(readbytes, 2)
  360. || !TEST_mem_eq(buf, 2, simple_data, 2)
  361. || !TEST_true(read_fn(rstream, buf + 2, 12, &readbytes, &fin))
  362. || !TEST_false(fin)
  363. || !TEST_size_t_eq(readbytes, 12)
  364. || !TEST_mem_eq(buf + 2, 12, simple_data + 2, 12)
  365. || !TEST_true(ossl_quic_rstream_queue_data(rstream, NULL,
  366. sizeof(simple_data),
  367. NULL,
  368. 0, 1))
  369. || (use_rbuf
  370. && !TEST_true(ossl_quic_rstream_resize_rbuf(rstream,
  371. 2 * sizeof(simple_data))))
  372. || (use_rbuf && !TEST_true(ossl_quic_rstream_move_to_rbuf(rstream)))
  373. || !TEST_true(read_fn(rstream, buf + 14, 5, &readbytes, &fin))
  374. || !TEST_false(fin)
  375. || !TEST_size_t_eq(readbytes, 5)
  376. || !TEST_mem_eq(buf, 14 + 5, simple_data, 14 + 5)
  377. || !TEST_true(read_fn(rstream, buf + 14 + 5, sizeof(buf) - 14 - 5,
  378. &readbytes, &fin))
  379. || !TEST_true(fin)
  380. || !TEST_size_t_eq(readbytes, sizeof(buf) - 14 - 5)
  381. || !TEST_mem_eq(buf, sizeof(buf), simple_data, sizeof(simple_data))
  382. || (use_rbuf && !TEST_true(ossl_quic_rstream_move_to_rbuf(rstream)))
  383. || !TEST_true(read_fn(rstream, buf, sizeof(buf), &readbytes, &fin))
  384. || !TEST_true(fin)
  385. || !TEST_size_t_eq(readbytes, 0))
  386. goto err;
  387. ret = 1;
  388. err:
  389. ossl_quic_rstream_free(rstream);
  390. return ret;
  391. }
  392. static int test_rstream_random(int idx)
  393. {
  394. unsigned char *bulk_data = NULL;
  395. unsigned char *read_buf = NULL;
  396. QUIC_RSTREAM *rstream = NULL;
  397. size_t i, read_off, queued_min, queued_max;
  398. const size_t data_size = 10000;
  399. int r, s, fin = 0, fin_set = 0;
  400. int ret = 0;
  401. size_t readbytes = 0;
  402. if (!TEST_ptr(bulk_data = OPENSSL_malloc(data_size))
  403. || !TEST_ptr(read_buf = OPENSSL_malloc(data_size))
  404. || !TEST_ptr(rstream = ossl_quic_rstream_new(NULL, NULL, 0)))
  405. goto err;
  406. if (idx % 3 == 0)
  407. ossl_quic_rstream_set_cleanse(rstream, 1);
  408. for (i = 0; i < data_size; ++i)
  409. bulk_data[i] = (unsigned char)(test_random() & 0xFF);
  410. read_off = queued_min = queued_max = 0;
  411. for (r = 0; r < 100; ++r) {
  412. for (s = 0; s < 10; ++s) {
  413. size_t off = (r * 10 + s) * 10, size = 10;
  414. if (test_random() % 10 == 0)
  415. /* drop packet */
  416. continue;
  417. if (off <= queued_min && off + size > queued_min)
  418. queued_min = off + size;
  419. if (!TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, off,
  420. bulk_data + off,
  421. size, 0)))
  422. goto err;
  423. if (queued_max < off + size)
  424. queued_max = off + size;
  425. if (test_random() % 5 != 0)
  426. continue;
  427. /* random overlapping retransmit */
  428. off = read_off + test_random() % 50;
  429. if (off > 50)
  430. off -= 50;
  431. size = test_random() % 100 + 1;
  432. if (off + size > data_size)
  433. off = data_size - size;
  434. if (off <= queued_min && off + size > queued_min)
  435. queued_min = off + size;
  436. if (!TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, off,
  437. bulk_data + off,
  438. size, 0)))
  439. goto err;
  440. if (queued_max < off + size)
  441. queued_max = off + size;
  442. }
  443. if (idx % 2 == 0) {
  444. if (!TEST_true(test_single_copy_read(rstream, read_buf, data_size,
  445. &readbytes, &fin)))
  446. goto err;
  447. } else if (!TEST_true(ossl_quic_rstream_read(rstream, read_buf,
  448. data_size,
  449. &readbytes, &fin))) {
  450. goto err;
  451. }
  452. if (!TEST_size_t_ge(readbytes, queued_min - read_off)
  453. || !TEST_size_t_le(readbytes + read_off, data_size)
  454. || (idx % 3 != 0
  455. && !TEST_mem_eq(read_buf, readbytes, bulk_data + read_off,
  456. readbytes)))
  457. goto err;
  458. read_off += readbytes;
  459. queued_min = read_off;
  460. if (test_random() % 50 == 0)
  461. if (!TEST_true(ossl_quic_rstream_resize_rbuf(rstream,
  462. queued_max - read_off + 1))
  463. || !TEST_true(ossl_quic_rstream_move_to_rbuf(rstream)))
  464. goto err;
  465. if (!fin_set && queued_max >= data_size - test_random() % 200) {
  466. fin_set = 1;
  467. /* Queue empty fin frame */
  468. if (!TEST_true(ossl_quic_rstream_queue_data(rstream, NULL, data_size,
  469. NULL, 0, 1)))
  470. goto err;
  471. }
  472. }
  473. TEST_info("Total read bytes: %zu Fin rcvd: %d", read_off, fin);
  474. if (idx % 3 == 0)
  475. for (i = 0; i < read_off; i++)
  476. if (!TEST_uchar_eq(bulk_data[i], 0))
  477. goto err;
  478. if (read_off == data_size && fin_set && !fin) {
  479. /* We might still receive the final empty frame */
  480. if (idx % 2 == 0) {
  481. if (!TEST_true(test_single_copy_read(rstream, read_buf, data_size,
  482. &readbytes, &fin)))
  483. goto err;
  484. } else if (!TEST_true(ossl_quic_rstream_read(rstream, read_buf,
  485. data_size,
  486. &readbytes, &fin))) {
  487. goto err;
  488. }
  489. if (!TEST_size_t_eq(readbytes, 0) || !TEST_true(fin))
  490. goto err;
  491. }
  492. ret = 1;
  493. err:
  494. ossl_quic_rstream_free(rstream);
  495. OPENSSL_free(bulk_data);
  496. OPENSSL_free(read_buf);
  497. return ret;
  498. }
  499. int setup_tests(void)
  500. {
  501. ADD_TEST(test_sstream_simple);
  502. ADD_ALL_TESTS(test_sstream_bulk, 100);
  503. ADD_ALL_TESTS(test_rstream_simple, 4);
  504. ADD_ALL_TESTS(test_rstream_random, 100);
  505. return 1;
  506. }