2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
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
9 #include <openssl/ssl.h>
10 #include <openssl/quic.h>
11 #include <openssl/bio.h>
12 #include <openssl/lhash.h>
13 #include "internal/quic_tserver.h"
14 #include "internal/quic_ssl.h"
16 #if defined(OPENSSL_THREADS)
17 # include "internal/thread_arch.h"
20 static const char *certfile, *keyfile;
22 #if defined(OPENSSL_THREADS)
23 struct child_thread_args {
25 const struct script_op *script;
35 typedef struct stream_info {
41 DEFINE_LHASH_OF_EX(STREAM_INFO);
45 BIO *s_net_bio, *s_net_bio_own;
46 BIO_ADDR *s_net_bio_addr;
48 LHASH_OF(STREAM_INFO) *s_streams;
51 BIO *c_net_bio, *c_net_bio_own;
54 LHASH_OF(STREAM_INFO) *c_streams;
56 #if defined(OPENSSL_THREADS)
57 struct child_thread_args *threads;
62 int init, blocking, check_spin_again;
68 LHASH_OF(STREAM_INFO) *c_streams;
76 int (*check_func)(struct helper *h, const struct script_op *op);
77 const char *stream_name;
83 #define OPK_C_SET_ALPN 2
84 #define OPK_C_CONNECT_WAIT 3
87 #define OPK_C_READ_EXPECT 6
88 #define OPK_S_READ_EXPECT 7
89 #define OPK_C_EXPECT_FIN 8
90 #define OPK_S_EXPECT_FIN 9
91 #define OPK_C_CONCLUDE 10
92 #define OPK_S_CONCLUDE 11
93 #define OPK_C_DETACH 12
94 #define OPK_C_ATTACH 13
95 #define OPK_C_NEW_STREAM 14
96 #define OPK_S_NEW_STREAM 15
97 #define OPK_C_ACCEPT_STREAM_WAIT 16
98 #define OPK_C_ACCEPT_STREAM_NONE 17
99 #define OPK_C_FREE_STREAM 18
100 #define OPK_C_SET_DEFAULT_STREAM_MODE 19
101 #define OPK_C_SET_INCOMING_STREAM_POLICY 20
102 #define OPK_C_SHUTDOWN 21
103 #define OPK_C_EXPECT_CONN_CLOSE_INFO 22
104 #define OPK_S_EXPECT_CONN_CLOSE_INFO 23
105 #define OPK_S_BIND_STREAM_ID 24
106 #define OPK_C_WAIT_FOR_DATA 25
107 #define OPK_C_WRITE_FAIL 26
108 #define OPK_S_WRITE_FAIL 27
109 #define OPK_C_READ_FAIL 28
110 #define OPK_C_STREAM_RESET 29
111 #define OPK_S_ACCEPT_STREAM_WAIT 30
112 #define OPK_NEW_THREAD 31
113 #define OPK_BEGIN_REPEAT 32
114 #define OPK_END_REPEAT 33
115 #define OPK_S_UNBIND_STREAM_ID 34
117 #define EXPECT_CONN_CLOSE_APP (1U << 0)
118 #define EXPECT_CONN_CLOSE_REMOTE (1U << 1)
120 #define C_BIDI_ID(ordinal) \
121 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI)
122 #define S_BIDI_ID(ordinal) \
123 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI)
124 #define C_UNI_ID(ordinal) \
125 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI)
126 #define S_UNI_ID(ordinal) \
127 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI)
129 #define ANY_ID UINT64_MAX
133 #define OP_CHECK(func, arg2) \
134 {OPK_CHECK, NULL, 0, (func), NULL, (arg2)},
135 #define OP_C_SET_ALPN(alpn) \
136 {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL},
137 #define OP_C_CONNECT_WAIT() \
138 {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL},
139 #define OP_C_WRITE(stream_name, buf, buf_len) \
140 {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name},
141 #define OP_S_WRITE(stream_name, buf, buf_len) \
142 {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name},
143 #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \
144 {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
145 #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \
146 {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
147 #define OP_C_EXPECT_FIN(stream_name) \
148 {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name},
149 #define OP_S_EXPECT_FIN(stream_name) \
150 {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name},
151 #define OP_C_CONCLUDE(stream_name) \
152 {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name},
153 #define OP_S_CONCLUDE(stream_name) \
154 {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name},
155 #define OP_C_DETACH(stream_name) \
156 {OPK_C_DETACH, NULL, 0, NULL, #stream_name},
157 #define OP_C_ATTACH(stream_name) \
158 {OPK_C_ATTACH, NULL, 0, NULL, #stream_name},
159 #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \
160 {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
161 #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \
162 {OPK_C_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
163 #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \
164 {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
165 #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \
166 {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
167 #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \
168 {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
169 #define OP_C_ACCEPT_STREAM_NONE() \
170 {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL},
171 #define OP_C_FREE_STREAM(stream_name) \
172 {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name},
173 #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \
174 {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
175 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
176 {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
177 #define OP_C_SHUTDOWN() \
178 {OPK_C_SHUTDOWN, NULL, 0, NULL, NULL},
179 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
180 {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \
181 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
182 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
184 #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
185 {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \
186 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
187 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
189 #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \
190 {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)},
191 #define OP_C_WAIT_FOR_DATA(stream_name) \
192 {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name},
193 #define OP_C_WRITE_FAIL(stream_name) \
194 {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name},
195 #define OP_S_WRITE_FAIL(stream_name) \
196 {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name},
197 #define OP_C_READ_FAIL(stream_name) \
198 {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name},
199 #define OP_C_STREAM_RESET(stream_name, aec) \
200 {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)},
201 #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \
202 {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
203 #define OP_NEW_THREAD(num_threads, script) \
204 {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 },
205 #define OP_BEGIN_REPEAT(n) \
206 {OPK_BEGIN_REPEAT, NULL, (n)},
207 #define OP_END_REPEAT() \
209 #define OP_S_UNBIND_STREAM_ID(stream_name) \
210 {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name},
212 static int check_rejected(struct helper *h, const struct script_op *op)
214 uint64_t stream_id = op->arg2;
216 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)
217 || !ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, NULL)) {
218 h->check_spin_again = 1;
225 static int check_stream_reset(struct helper *h, const struct script_op *op)
227 uint64_t stream_id = op->arg2, aec = 0;
229 if (!ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, &aec)) {
230 h->check_spin_again = 1;
234 return TEST_uint64_t_eq(aec, 42);
237 static int check_stream_stopped(struct helper *h, const struct script_op *op)
239 uint64_t stream_id = op->arg2;
241 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)) {
242 h->check_spin_again = 1;
249 static unsigned long stream_info_hash(const STREAM_INFO *info)
251 return OPENSSL_LH_strhash(info->name);
254 static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b)
256 return strcmp(a->name, b->name);
259 static void cleanup_stream(STREAM_INFO *info)
261 SSL_free(info->c_stream);
265 static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh)
270 lh_STREAM_INFO_doall(*lh, cleanup_stream);
271 lh_STREAM_INFO_free(*lh);
275 #if defined(OPENSSL_THREADS)
276 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg);
278 static int join_threads(struct child_thread_args *threads, size_t num_threads)
282 CRYPTO_THREAD_RETVAL rv;
284 for (i = 0; i < num_threads; ++i) {
285 if (threads[i].t != NULL) {
286 ossl_crypto_thread_native_join(threads[i].t, &rv);
288 if (!threads[i].testresult)
289 /* Do not log failure here, worker will do it. */
292 ossl_crypto_thread_native_clean(threads[i].t);
296 ossl_crypto_mutex_free(&threads[i].m);
303 static void helper_cleanup(struct helper *h)
305 #if defined(OPENSSL_THREADS)
306 join_threads(h->threads, h->num_threads);
307 OPENSSL_free(h->threads);
312 if (h->free_order == 0) {
313 /* order 0: streams, then conn */
314 helper_cleanup_streams(&h->c_streams);
319 /* order 1: conn, then streams */
323 helper_cleanup_streams(&h->c_streams);
326 helper_cleanup_streams(&h->s_streams);
327 ossl_quic_tserver_free(h->s);
330 BIO_free(h->s_net_bio_own);
331 h->s_net_bio_own = NULL;
333 BIO_free(h->c_net_bio_own);
334 h->c_net_bio_own = NULL;
337 BIO_closesocket(h->s_fd);
342 BIO_closesocket(h->c_fd);
346 BIO_ADDR_free(h->s_net_bio_addr);
347 h->s_net_bio_addr = NULL;
349 SSL_CTX_free(h->c_ctx);
353 static int helper_init(struct helper *h, int free_order)
356 struct in_addr ina = {0};
357 QUIC_TSERVER_ARGS s_args = {0};
359 memset(h, 0, sizeof(*h));
362 h->free_order = free_order;
364 if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash,
368 if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash,
372 ina.s_addr = htonl(0x7f000001UL);
374 h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
375 if (!TEST_int_ge(h->s_fd, 0))
378 if (!TEST_true(BIO_socket_nbio(h->s_fd, 1)))
381 if (!TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new()))
384 if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_addr, AF_INET, &ina, sizeof(ina),
388 if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_addr, 0)))
391 if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0))
394 if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0)))
397 if (!BIO_up_ref(h->s_net_bio))
400 s_args.net_rbio = h->s_net_bio;
401 s_args.net_wbio = h->s_net_bio;
403 if (!TEST_ptr(h->s = ossl_quic_tserver_new(&s_args, certfile, keyfile)))
406 h->s_net_bio_own = NULL;
408 h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
409 if (!TEST_int_ge(h->c_fd, 0))
412 if (!TEST_true(BIO_socket_nbio(h->c_fd, 1)))
415 if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0)))
418 if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr)))
422 if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method())))
425 if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx)))
428 /* Takes ownership of our reference to the BIO. */
429 SSL_set0_rbio(h->c_conn, h->c_net_bio);
430 h->c_net_bio_own = NULL;
432 if (!TEST_true(BIO_up_ref(h->c_net_bio)))
435 SSL_set0_wbio(h->c_conn, h->c_net_bio);
437 if (!TEST_true(SSL_set_blocking_mode(h->c_conn, 0)))
440 h->start_time = ossl_time_now();
449 static int helper_local_init(struct helper_local *hl, struct helper *h,
453 hl->c_streams = NULL;
454 hl->thread_idx = thread_idx;
459 if (thread_idx < 0) {
460 hl->c_streams = h->c_streams;
462 if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash,
470 static void helper_local_cleanup(struct helper_local *hl)
475 if (hl->thread_idx >= 0)
476 helper_cleanup_streams(&hl->c_streams);
481 static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh,
482 const char *stream_name)
484 STREAM_INFO key, *info;
486 if (!TEST_ptr(stream_name))
489 if (!strcmp(stream_name, "DEFAULT"))
492 key.name = stream_name;
493 info = lh_STREAM_INFO_retrieve(lh, &key);
495 info = OPENSSL_zalloc(sizeof(*info));
499 info->name = stream_name;
500 info->s_stream_id = UINT64_MAX;
501 lh_STREAM_INFO_insert(lh, info);
507 static int helper_local_set_c_stream(struct helper_local *hl,
508 const char *stream_name,
511 STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name);
516 info->c_stream = c_stream;
517 info->s_stream_id = UINT64_MAX;
521 static SSL *helper_local_get_c_stream(struct helper_local *hl,
522 const char *stream_name)
526 if (!strcmp(stream_name, "DEFAULT"))
527 return hl->h->c_conn;
529 info = get_stream_info(hl->c_streams, stream_name);
533 return info->c_stream;
537 helper_set_s_stream(struct helper *h, const char *stream_name,
538 uint64_t s_stream_id)
542 if (!strcmp(stream_name, "DEFAULT"))
545 info = get_stream_info(h->s_streams, stream_name);
549 info->c_stream = NULL;
550 info->s_stream_id = s_stream_id;
554 static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name)
558 if (!strcmp(stream_name, "DEFAULT"))
561 info = get_stream_info(h->s_streams, stream_name);
565 return info->s_stream_id;
568 static int is_want(SSL *s, int ret)
570 int ec = SSL_get_error(s, ret);
572 return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE;
575 static int run_script_worker(struct helper *h, const struct script_op *script,
579 unsigned char *tmp_buf = NULL;
580 int connect_started = 0;
583 const struct script_op *op = NULL;
584 int no_advance = 0, first = 1;
585 #if defined(OPENSSL_THREADS)
586 int end_wait_warning = 0;
588 OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero();
589 struct helper_local hl;
590 #define REPEAT_SLOTS 8
591 size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS];
592 size_t repeat_stack_limit[REPEAT_SLOTS];
593 size_t repeat_stack_len = 0;
595 if (!TEST_true(helper_local_init(&hl, h, thread_idx)))
598 #define SPIN_AGAIN() { no_advance = 1; continue; }
601 SSL *c_tgt = h->c_conn;
602 uint64_t s_stream_id = UINT64_MAX;
612 op_start_time = ossl_time_now();
613 op_deadline = ossl_time_add(op_start_time, ossl_ms2time(2000));
616 if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) {
617 TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx);
621 op = &script[op_idx];
623 if (op->stream_name != NULL) {
624 c_tgt = helper_local_get_c_stream(&hl, op->stream_name);
626 s_stream_id = helper_get_s_stream(h, op->stream_name);
628 s_stream_id = UINT64_MAX;
632 ossl_quic_tserver_tick(h->s);
634 if (thread_idx >= 0 || connect_started)
635 SSL_handle_events(h->c_conn);
637 if (thread_idx >= 0) {
638 /* Only allow certain opcodes on child threads. */
641 case OPK_C_ACCEPT_STREAM_WAIT:
642 case OPK_C_NEW_STREAM:
643 case OPK_C_READ_EXPECT:
644 case OPK_C_EXPECT_FIN:
647 case OPK_C_FREE_STREAM:
648 case OPK_BEGIN_REPEAT:
653 TEST_error("opcode %d not allowed on child thread", op->op);
660 if (!TEST_size_t_eq(repeat_stack_len, 0))
663 #if defined(OPENSSL_THREADS)
664 if (thread_idx < 0) {
668 for (i = 0; i < h->num_threads; ++i) {
669 if (h->threads[i].m == NULL)
672 ossl_crypto_mutex_lock(h->threads[i].m);
673 done = h->threads[i].done;
674 ossl_crypto_mutex_unlock(h->threads[i].m);
677 if (!end_wait_warning) {
678 TEST_info("still waiting for other threads to finish (%zu)", i);
679 end_wait_warning = 1;
688 TEST_info("script finished on thread %d", thread_idx);
692 case OPK_BEGIN_REPEAT:
693 if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx)))
696 if (!TEST_size_t_gt(op->arg1, 0))
699 repeat_stack_idx[repeat_stack_len] = op_idx + 1;
700 repeat_stack_done[repeat_stack_len] = 0;
701 repeat_stack_limit[repeat_stack_len] = op->arg1;
706 if (!TEST_size_t_gt(repeat_stack_len, 0))
709 if (++repeat_stack_done[repeat_stack_len - 1]
710 == repeat_stack_limit[repeat_stack_len - 1]) {
713 op_idx = repeat_stack_idx[repeat_stack_len - 1];
722 int ok = op->check_func(h, op);
723 if (h->check_spin_again) {
724 h->check_spin_again = 0;
735 const char *alpn = op->arg0;
736 size_t alpn_len = strlen(alpn);
738 if (!TEST_size_t_le(alpn_len, UINT8_MAX)
739 || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1)))
742 memcpy(tmp_buf + 1, alpn, alpn_len);
743 tmp_buf[0] = (unsigned char)alpn_len;
745 /* 0 is the success case for SSL_set_alpn_protos(). */
746 if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf,
750 OPENSSL_free(tmp_buf);
755 case OPK_C_CONNECT_WAIT:
761 ret = SSL_connect(h->c_conn);
762 if (!TEST_true(ret == 1
763 || (!h->blocking && is_want(h->c_conn, ret))))
766 if (!h->blocking && ret != 1)
773 size_t bytes_written = 0;
775 if (!TEST_ptr(c_tgt))
778 if (!TEST_true(SSL_write_ex(c_tgt, op->arg0, op->arg1,
780 || !TEST_size_t_eq(bytes_written, op->arg1))
787 size_t bytes_written = 0;
789 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
792 if (!TEST_true(ossl_quic_tserver_write(h->s, s_stream_id,
795 || !TEST_size_t_eq(bytes_written, op->arg1))
802 if (!TEST_true(SSL_stream_conclude(c_tgt, 0)))
809 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
812 ossl_quic_tserver_conclude(h->s, s_stream_id);
816 case OPK_C_WAIT_FOR_DATA:
819 size_t bytes_read = 0;
821 if (!TEST_ptr(c_tgt))
824 if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read)
830 case OPK_C_READ_EXPECT:
832 size_t bytes_read = 0;
834 if (op->arg1 > 0 && tmp_buf == NULL
835 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
838 if (!SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset,
842 if (bytes_read + offset != op->arg1) {
843 offset += bytes_read;
848 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
851 OPENSSL_free(tmp_buf);
856 case OPK_S_READ_EXPECT:
858 size_t bytes_read = 0;
860 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
863 if (op->arg1 > 0 && tmp_buf == NULL
864 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
867 if (!TEST_true(ossl_quic_tserver_read(h->s, s_stream_id,
873 if (bytes_read + offset != op->arg1) {
874 offset += bytes_read;
879 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
882 OPENSSL_free(tmp_buf);
887 case OPK_C_EXPECT_FIN:
890 size_t bytes_read = 0;
892 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf),
894 || !TEST_size_t_eq(bytes_read, 0))
897 if (is_want(c_tgt, 0))
900 if (!TEST_int_eq(SSL_get_error(c_tgt, 0),
901 SSL_ERROR_ZERO_RETURN))
906 case OPK_S_EXPECT_FIN:
908 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
911 if (!ossl_quic_tserver_has_read_ended(h->s, s_stream_id))
920 if (!TEST_ptr_null(c_tgt))
921 goto out; /* don't overwrite existing stream with same name */
923 if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn)))
926 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
933 if (!TEST_ptr(c_tgt))
936 if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt)))
939 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
944 case OPK_C_NEW_STREAM:
949 if (!TEST_ptr_null(c_tgt))
950 goto out; /* don't overwrite existing stream with same name */
953 flags |= SSL_STREAM_FLAG_UNI;
955 if (!TEST_ptr(c_stream = SSL_new_stream(h->c_conn, flags)))
958 if (op->arg2 != UINT64_MAX
959 && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream),
963 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
968 case OPK_S_NEW_STREAM:
970 uint64_t stream_id = UINT64_MAX;
972 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
973 goto out; /* don't overwrite existing stream with same name */
975 if (!TEST_true(ossl_quic_tserver_stream_new(h->s,
980 if (op->arg2 != UINT64_MAX
981 && !TEST_uint64_t_eq(stream_id, op->arg2))
984 if (!TEST_true(helper_set_s_stream(h, op->stream_name,
990 case OPK_C_ACCEPT_STREAM_WAIT:
994 if (!TEST_ptr_null(c_tgt))
995 goto out; /* don't overwrite existing stream with same name */
997 if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL)
1000 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name,
1006 case OPK_S_ACCEPT_STREAM_WAIT:
1008 uint64_t new_stream_id;
1010 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1013 new_stream_id = ossl_quic_tserver_pop_incoming_stream(h->s);
1014 if (new_stream_id == UINT64_MAX)
1017 if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id)))
1022 case OPK_C_ACCEPT_STREAM_NONE:
1026 if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, 0))) {
1033 case OPK_C_FREE_STREAM:
1035 if (!TEST_ptr(c_tgt)
1036 || !TEST_true(!SSL_is_connection(c_tgt)))
1039 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
1047 case OPK_C_SET_DEFAULT_STREAM_MODE:
1049 if (!TEST_ptr(c_tgt))
1052 if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1)))
1057 case OPK_C_SET_INCOMING_STREAM_POLICY:
1059 if (!TEST_ptr(c_tgt))
1062 if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt,
1068 case OPK_C_SHUTDOWN:
1072 if (!TEST_ptr(c_tgt))
1075 ret = SSL_shutdown_ex(c_tgt, 0, NULL, 0);
1076 if (!TEST_int_ge(ret, 0))
1082 case OPK_C_EXPECT_CONN_CLOSE_INFO:
1084 SSL_CONN_CLOSE_INFO cc_info = {0};
1085 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1086 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1087 uint64_t error_code = op->arg2;
1089 if (!TEST_ptr(c_tgt))
1092 if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info)))
1095 if (!TEST_int_eq(expect_app, !cc_info.is_transport)
1096 || !TEST_int_eq(expect_remote, !cc_info.is_local)
1097 || !TEST_uint64_t_eq(error_code, cc_info.error_code))
1102 case OPK_S_EXPECT_CONN_CLOSE_INFO:
1104 const QUIC_TERMINATE_CAUSE *tc;
1105 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1106 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1107 uint64_t error_code = op->arg2;
1109 if (!ossl_quic_tserver_is_term_any(h->s))
1112 if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(h->s)))
1115 if (!TEST_uint64_t_eq(error_code, tc->error_code)
1116 || !TEST_int_eq(expect_app, tc->app)
1117 || !TEST_int_eq(expect_remote, tc->remote))
1122 case OPK_S_BIND_STREAM_ID:
1124 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1127 if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2)))
1132 case OPK_S_UNBIND_STREAM_ID:
1134 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1137 if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX)))
1142 case OPK_C_WRITE_FAIL:
1144 size_t bytes_written = 0;
1146 if (!TEST_ptr(c_tgt))
1149 if (!TEST_false(SSL_write_ex(c_tgt, "apple", 5, &bytes_written)))
1154 case OPK_S_WRITE_FAIL:
1156 size_t bytes_written = 0;
1158 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1161 if (!TEST_false(ossl_quic_tserver_write(h->s, s_stream_id,
1162 (const unsigned char *)"apple", 5,
1168 case OPK_C_READ_FAIL:
1170 size_t bytes_read = 0;
1173 if (!TEST_ptr(c_tgt))
1176 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read)))
1181 case OPK_C_STREAM_RESET:
1183 SSL_STREAM_RESET_ARGS args = {0};
1185 if (!TEST_ptr(c_tgt))
1188 args.quic_error_code = op->arg2;
1190 if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args))))
1195 case OPK_NEW_THREAD:
1197 #if !defined(OPENSSL_THREADS)
1199 * If this test script requires threading and we do not have
1200 * support for it, skip the rest of it.
1202 TEST_skip("threading not supported, skipping");
1208 if (!TEST_ptr_null(h->threads)) {
1209 TEST_error("max one NEW_THREAD operation per script");
1213 h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args));
1214 if (!TEST_ptr(h->threads))
1217 h->num_threads = op->arg1;
1219 for (i = 0; i < op->arg1; ++i) {
1220 h->threads[i].h = h;
1221 h->threads[i].script = op->arg0;
1222 h->threads[i].thread_idx = i;
1224 h->threads[i].m = ossl_crypto_mutex_new();
1225 if (!TEST_ptr(h->threads[i].m))
1229 = ossl_crypto_thread_native_start(run_script_child_thread,
1231 if (!TEST_ptr(h->threads[i].t))
1239 TEST_error("unknown op");
1248 TEST_error("failed at script op %zu, thread %d\n",
1249 op_idx + 1, thread_idx);
1251 for (i = 0; i < repeat_stack_len; ++i)
1252 TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu",
1253 repeat_stack_done[i],
1254 repeat_stack_limit[i],
1255 repeat_stack_idx[i]);
1258 OPENSSL_free(tmp_buf);
1259 helper_local_cleanup(&hl);
1263 static int run_script(const struct script_op *script, int free_order)
1268 if (!TEST_true(helper_init(&h, free_order)))
1271 if (!TEST_true(run_script_worker(&h, script, -1)))
1274 #if defined(OPENSSL_THREADS)
1275 if (!TEST_true(join_threads(h.threads, h.num_threads)))
1285 #if defined(OPENSSL_THREADS)
1286 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg)
1289 struct child_thread_args *args = arg;
1291 testresult = run_script_worker(args->h, args->script,
1294 ossl_crypto_mutex_lock(args->m);
1295 args->testresult = testresult;
1297 ossl_crypto_mutex_unlock(args->m);
1302 /* 1. Simple single-stream test */
1303 static const struct script_op script_1[] = {
1304 OP_C_SET_ALPN ("ossltest")
1305 OP_C_CONNECT_WAIT ()
1306 OP_C_WRITE (DEFAULT, "apple", 5)
1307 OP_C_CONCLUDE (DEFAULT)
1308 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1309 OP_S_READ_EXPECT (a, "apple", 5)
1311 OP_S_WRITE (a, "orange", 6)
1313 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1314 OP_C_EXPECT_FIN (DEFAULT)
1318 /* 2. Multi-stream test */
1319 static const struct script_op script_2[] = {
1320 OP_C_SET_ALPN ("ossltest")
1321 OP_C_CONNECT_WAIT ()
1322 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT)
1323 OP_C_WRITE (DEFAULT, "apple", 5)
1324 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1325 OP_S_READ_EXPECT (a, "apple", 5)
1326 OP_S_WRITE (a, "orange", 6)
1327 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1329 OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1))
1330 OP_C_WRITE (b, "flamingo", 8)
1332 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1333 OP_S_READ_EXPECT (b, "flamingo", 8)
1335 OP_S_WRITE (b, "gargoyle", 8)
1337 OP_C_READ_EXPECT (b, "gargoyle", 8)
1340 OP_C_NEW_STREAM_UNI (c, C_UNI_ID(0))
1341 OP_C_WRITE (c, "elephant", 8)
1343 OP_S_BIND_STREAM_ID (c, C_UNI_ID(0))
1344 OP_S_READ_EXPECT (c, "elephant", 8)
1348 OP_C_ACCEPT_STREAM_NONE ()
1350 OP_S_NEW_STREAM_BIDI (d, S_BIDI_ID(0))
1351 OP_S_WRITE (d, "frog", 4)
1354 OP_C_ACCEPT_STREAM_WAIT (d)
1355 OP_C_ACCEPT_STREAM_NONE ()
1356 OP_C_READ_EXPECT (d, "frog", 4)
1359 OP_S_NEW_STREAM_BIDI (e, S_BIDI_ID(1))
1360 OP_S_WRITE (e, "mixture", 7)
1363 OP_C_ACCEPT_STREAM_WAIT (e)
1364 OP_C_READ_EXPECT (e, "mixture", 7)
1366 OP_C_WRITE (e, "ramble", 6)
1367 OP_S_READ_EXPECT (e, "ramble", 6)
1371 OP_S_NEW_STREAM_UNI (f, S_UNI_ID(0))
1372 OP_S_WRITE (f, "yonder", 6)
1375 OP_C_ACCEPT_STREAM_WAIT (f)
1376 OP_C_ACCEPT_STREAM_NONE ()
1377 OP_C_READ_EXPECT (f, "yonder", 6)
1381 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT)
1382 OP_S_NEW_STREAM_BIDI (g, S_BIDI_ID(2))
1383 OP_S_WRITE (g, "unseen", 6)
1386 OP_C_ACCEPT_STREAM_NONE ()
1388 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO)
1389 OP_S_NEW_STREAM_BIDI (h, S_BIDI_ID(3))
1390 OP_S_WRITE (h, "UNSEEN", 6)
1393 OP_C_ACCEPT_STREAM_NONE ()
1396 * Streams g, h should have been rejected, so server should have got
1397 * STOP_SENDING/RESET_STREAM.
1399 OP_CHECK (check_rejected, S_BIDI_ID(2))
1400 OP_CHECK (check_rejected, S_BIDI_ID(3))
1405 /* 3. Default stream detach/reattach test */
1406 static const struct script_op script_3[] = {
1407 OP_C_SET_ALPN ("ossltest")
1408 OP_C_CONNECT_WAIT ()
1410 OP_C_WRITE (DEFAULT, "apple", 5)
1411 OP_C_DETACH (a) /* DEFAULT becomes stream 'a' */
1412 OP_C_WRITE_FAIL (DEFAULT)
1414 OP_C_WRITE (a, "by", 2)
1416 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1417 OP_S_READ_EXPECT (a, "appleby", 7)
1419 OP_S_WRITE (a, "hello", 5)
1420 OP_C_READ_EXPECT (a, "hello", 5)
1422 OP_C_WRITE_FAIL (DEFAULT)
1424 OP_C_WRITE (DEFAULT, "is here", 7)
1425 OP_S_READ_EXPECT (a, "is here", 7)
1434 /* 4. Default stream mode test */
1435 static const struct script_op script_4[] = {
1436 OP_C_SET_ALPN ("ossltest")
1437 OP_C_CONNECT_WAIT ()
1439 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1440 OP_C_WRITE_FAIL (DEFAULT)
1442 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1443 OP_S_WRITE (a, "apple", 5)
1445 OP_C_READ_FAIL (DEFAULT)
1447 OP_C_ACCEPT_STREAM_WAIT (a)
1448 OP_C_READ_EXPECT (a, "apple", 5)
1451 OP_C_WRITE (DEFAULT, "orange", 6)
1452 OP_S_READ_EXPECT (a, "orange", 6)
1457 /* 5. Test stream reset functionality */
1458 static const struct script_op script_5[] = {
1459 OP_C_SET_ALPN ("ossltest")
1460 OP_C_CONNECT_WAIT ()
1462 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1463 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
1465 OP_C_WRITE (a, "apple", 5)
1466 OP_C_STREAM_RESET (a, 42)
1468 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1469 OP_S_READ_EXPECT (a, "apple", 5)
1470 OP_CHECK (check_stream_reset, C_BIDI_ID(0))
1475 /* 6. Test STOP_SENDING functionality */
1476 static const struct script_op script_6[] = {
1477 OP_C_SET_ALPN ("ossltest")
1478 OP_C_CONNECT_WAIT ()
1480 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1481 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1482 OP_S_WRITE (a, "apple", 5)
1484 OP_C_ACCEPT_STREAM_WAIT (a)
1485 OP_C_FREE_STREAM (a)
1486 OP_C_ACCEPT_STREAM_NONE ()
1488 OP_CHECK (check_stream_stopped, S_BIDI_ID(0))
1493 /* 7. Unidirectional default stream mode test (client sends first) */
1494 static const struct script_op script_7[] = {
1495 OP_C_SET_ALPN ("ossltest")
1496 OP_C_CONNECT_WAIT ()
1498 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1499 OP_C_WRITE (DEFAULT, "apple", 5)
1501 OP_S_BIND_STREAM_ID (a, C_UNI_ID(0))
1502 OP_S_READ_EXPECT (a, "apple", 5)
1508 /* 8. Unidirectional default stream mode test (server sends first) */
1509 static const struct script_op script_8[] = {
1510 OP_C_SET_ALPN ("ossltest")
1511 OP_C_CONNECT_WAIT ()
1513 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1514 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
1515 OP_S_WRITE (a, "apple", 5)
1516 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1517 OP_C_WRITE_FAIL (DEFAULT)
1522 /* 9. Unidirectional default stream mode test (server sends first on bidi) */
1523 static const struct script_op script_9[] = {
1524 OP_C_SET_ALPN ("ossltest")
1525 OP_C_CONNECT_WAIT ()
1527 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1528 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1529 OP_S_WRITE (a, "apple", 5)
1530 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1531 OP_C_WRITE (DEFAULT, "orange", 6)
1532 OP_S_READ_EXPECT (a, "orange", 6)
1538 static const struct script_op script_10[] = {
1539 OP_C_SET_ALPN ("ossltest")
1540 OP_C_CONNECT_WAIT ()
1542 OP_C_WRITE (DEFAULT, "apple", 5)
1543 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1544 OP_S_READ_EXPECT (a, "apple", 5)
1547 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
1548 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
1553 /* 11. Many threads accepted on the same client connection */
1554 static const struct script_op script_11_child[] = {
1555 OP_C_ACCEPT_STREAM_WAIT (a)
1556 OP_C_READ_EXPECT (a, "foo", 3)
1562 static const struct script_op script_11[] = {
1563 OP_C_SET_ALPN ("ossltest")
1564 OP_C_CONNECT_WAIT ()
1565 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1567 OP_NEW_THREAD (5, script_11_child)
1569 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1570 OP_S_WRITE (a, "foo", 3)
1573 OP_S_NEW_STREAM_BIDI (b, ANY_ID)
1574 OP_S_WRITE (b, "foo", 3)
1577 OP_S_NEW_STREAM_BIDI (c, ANY_ID)
1578 OP_S_WRITE (c, "foo", 3)
1581 OP_S_NEW_STREAM_BIDI (d, ANY_ID)
1582 OP_S_WRITE (d, "foo", 3)
1585 OP_S_NEW_STREAM_BIDI (e, ANY_ID)
1586 OP_S_WRITE (e, "foo", 3)
1592 /* 12. Many threads initiated on the same client connection */
1593 static const struct script_op script_12_child[] = {
1594 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1595 OP_C_WRITE (a, "foo", 3)
1597 OP_C_FREE_STREAM (a)
1602 static const struct script_op script_12[] = {
1603 OP_C_SET_ALPN ("ossltest")
1604 OP_C_CONNECT_WAIT ()
1605 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1607 OP_NEW_THREAD (5, script_12_child)
1609 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1610 OP_S_READ_EXPECT (a, "foo", 3)
1612 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1613 OP_S_READ_EXPECT (b, "foo", 3)
1615 OP_S_BIND_STREAM_ID (c, C_BIDI_ID(2))
1616 OP_S_READ_EXPECT (c, "foo", 3)
1618 OP_S_BIND_STREAM_ID (d, C_BIDI_ID(3))
1619 OP_S_READ_EXPECT (d, "foo", 3)
1621 OP_S_BIND_STREAM_ID (e, C_BIDI_ID(4))
1622 OP_S_READ_EXPECT (e, "foo", 3)
1628 /* 13. Many threads accepted on the same client connection (stress test) */
1629 static const struct script_op script_13_child[] = {
1630 OP_BEGIN_REPEAT (10)
1632 OP_C_ACCEPT_STREAM_WAIT (a)
1633 OP_C_READ_EXPECT (a, "foo", 3)
1635 OP_C_FREE_STREAM (a)
1642 static const struct script_op script_13[] = {
1643 OP_C_SET_ALPN ("ossltest")
1644 OP_C_CONNECT_WAIT ()
1645 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1647 OP_NEW_THREAD (5, script_13_child)
1649 OP_BEGIN_REPEAT (50)
1651 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1652 OP_S_WRITE (a, "foo", 3)
1654 OP_S_UNBIND_STREAM_ID (a)
1661 /* 14. Many threads initiating on the same client connection (stress test) */
1662 static const struct script_op script_14_child[] = {
1663 OP_BEGIN_REPEAT (10)
1665 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1666 OP_C_WRITE (a, "foo", 3)
1668 OP_C_FREE_STREAM (a)
1675 static const struct script_op script_14[] = {
1676 OP_C_SET_ALPN ("ossltest")
1677 OP_C_CONNECT_WAIT ()
1678 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1680 OP_NEW_THREAD (5, script_14_child)
1682 OP_BEGIN_REPEAT (50)
1684 OP_S_ACCEPT_STREAM_WAIT (a)
1685 OP_S_READ_EXPECT (a, "foo", 3)
1687 OP_S_UNBIND_STREAM_ID (a)
1694 /* 15. Client sending large number of streams, MAX_STREAMS test */
1695 static const struct script_op script_15[] = {
1696 OP_C_SET_ALPN ("ossltest")
1697 OP_C_CONNECT_WAIT ()
1698 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1701 * This will cause a protocol violation to be raised by the server if we are
1702 * not handling the stream limit correctly on the TX side.
1704 OP_BEGIN_REPEAT (200)
1706 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1707 OP_C_WRITE (a, "foo", 3)
1709 OP_C_FREE_STREAM (a)
1713 /* Prove the connection is still good. */
1714 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1715 OP_S_WRITE (a, "bar", 3)
1718 OP_C_ACCEPT_STREAM_WAIT (a)
1719 OP_C_READ_EXPECT (a, "bar", 3)
1723 * Drain the queue of incoming streams. We should be able to get all 200
1724 * even though only 100 can be initiated at a time.
1726 OP_BEGIN_REPEAT (200)
1728 OP_S_ACCEPT_STREAM_WAIT (b)
1729 OP_S_READ_EXPECT (b, "foo", 3)
1731 OP_S_UNBIND_STREAM_ID (b)
1738 /* 16. Server sending large number of streams, MAX_STREAMS test */
1739 static const struct script_op script_16[] = {
1740 OP_C_SET_ALPN ("ossltest")
1741 OP_C_CONNECT_WAIT ()
1742 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1745 * This will cause a protocol violation to be raised by the client if we are
1746 * not handling the stream limit correctly on the TX side.
1748 OP_BEGIN_REPEAT (200)
1750 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1751 OP_S_WRITE (a, "foo", 3)
1753 OP_S_UNBIND_STREAM_ID (a)
1757 /* Prove that the connection is still good. */
1758 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1759 OP_C_WRITE (a, "bar", 3)
1762 OP_S_ACCEPT_STREAM_WAIT (b)
1763 OP_S_READ_EXPECT (b, "bar", 3)
1766 /* Drain the queue of incoming streams. */
1767 OP_BEGIN_REPEAT (200)
1769 OP_C_ACCEPT_STREAM_WAIT (b)
1770 OP_C_READ_EXPECT (b, "foo", 3)
1772 OP_C_FREE_STREAM (b)
1779 static const struct script_op *const scripts[] = {
1798 static int test_script(int idx)
1800 int script_idx = idx >> 1;
1801 int free_order = idx & 1;
1803 TEST_info("Running script %d (order=%d)", script_idx + 1, free_order);
1804 return run_script(scripts[script_idx], free_order);
1807 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
1809 int setup_tests(void)
1811 if (!test_skip_common_options()) {
1812 TEST_error("Error parsing test options\n");
1816 if (!TEST_ptr(certfile = test_get_argument(0))
1817 || !TEST_ptr(keyfile = test_get_argument(1)))
1820 ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2);