39
39
* - verify that the received content matches what was sent.
40
40
*/
41
41
42
+ #define ADD_BLOCK_TEST_ALPN "ADD_BLOCK_TEST"
42
43
#define add_block_test_unique_1 0x1111111111111111uul
43
44
#define add_block_test_unique_2 0x2222222222222222uul
44
45
#define add_block_test_max_block_nb 10
45
- #define add_block_test_max_sent size_t(1<<20)
46
+ #define add_block_test_max_sent 0x100000
46
47
47
48
#define add_block_test_block_unknown 1
48
49
#define add_block_test_block_not_sent 2
@@ -64,7 +65,7 @@ typedef struct st_add_block_test_stream_t {
64
65
65
66
typedef struct st_add_block_test_block_t {
66
67
/* we only use one stream, but we use this data type to test that the context is passed correctly */
67
- add_block_test_ctx_t * block_test_ctx ;
68
+ struct st_add_block_test_ctx_t * block_test_ctx ;
68
69
int block_id ;
69
70
int block_was_sent ;
70
71
int block_was_confirmed ;
@@ -87,6 +88,7 @@ typedef struct st_add_block_test_ctx_t {
87
88
int fin_sent ;
88
89
int fin_recv ;
89
90
add_block_test_block_t block [add_block_test_max_block_nb ];
91
+ int next_block_id ;
90
92
add_block_test_stream_t client_stream ;
91
93
add_block_test_stream_t server_stream ;
92
94
} add_block_test_ctx_t ;
@@ -100,20 +102,20 @@ int picoquic_add_block_to_stream(picoquic_cnx_t* cnx, uint64_t stream_id,
100
102
const uint8_t * data , size_t length , int set_fin , void * app_stream_ctx ,
101
103
picoquic_block_sent_fn block_sent_fn , void * block_sent_ctx );
102
104
103
- void add_block_test_sent_fn (const uint8_t * data , void * v_add_block_ctx )
105
+ void add_block_test_sent_fn (const uint8_t * data , void * v_block_sent_ctx )
104
106
{
105
107
add_block_test_block_t * block_sent_ctx = (add_block_test_block_t * )v_block_sent_ctx ;
106
108
107
109
if (block_sent_ctx -> block_test_ctx != current_ctx ||
108
110
block_sent_ctx -> block_id >= add_block_test_max_block_nb ||
109
- & block_sent_ctx -> block [block_sent_ctx -> block_id ] != block_sent_ctx ) {
111
+ & block_sent_ctx -> block_test_ctx -> block [block_sent_ctx -> block_id ] != block_sent_ctx ) {
110
112
/* This is really bad. */
111
113
error_found |= add_block_test_block_unknown ;
112
114
}
113
115
else if (!block_sent_ctx -> block_was_sent ) {
114
116
error_found |= add_block_test_block_not_sent ;
115
117
}
116
- else if (! block_sent_ctx -> block_was_confirmed ) {
118
+ else if (block_sent_ctx -> block_was_confirmed ) {
117
119
error_found |= add_block_test_block_already_reported ;
118
120
}
119
121
else {
@@ -126,8 +128,8 @@ void add_block_test_sent_fn(const uint8_t* data, void* v_add_block_ctx)
126
128
127
129
void add_block_test_send (add_block_test_ctx_t * add_block_ctx , int block_id )
128
130
{
129
- for (int i = 0 ; i < block_id ; i ++ ) {
130
- int new_id = block_id + i ;
131
+ for (int i = 0 ; i <= block_id ; i ++ ) {
132
+ int new_id = add_block_ctx -> next_block_id ;
131
133
132
134
if (new_id >= add_block_test_max_block_nb || add_block_ctx -> send_offset >= add_block_ctx -> test_data_length ) {
133
135
/* we are done */
@@ -150,13 +152,16 @@ void add_block_test_send(add_block_test_ctx_t* add_block_ctx, int block_id)
150
152
set_fin = 1 ;
151
153
}
152
154
add_block_ctx -> block [new_id ].block_was_sent = 1 ;
153
- add_block_ctx -> block [new_id ].is_trigger = (i == 0 );
155
+ add_block_ctx -> block [new_id ].block_is_trigger = (i == 0 );
154
156
add_block_ctx -> block [new_id ].block_id = new_id ;
157
+ add_block_ctx -> block [new_id ].block_test_ctx = add_block_ctx ;
158
+ add_block_ctx -> next_block_id = new_id + 1 ;
159
+
155
160
if (picoquic_add_block_to_stream (add_block_ctx -> cnx_client ,
156
161
add_block_ctx -> stream_id ,
157
162
add_block_ctx -> test_data + add_block_ctx -> send_offset ,
158
163
length , set_fin , & add_block_ctx -> client_stream ,
159
- add_block_test_sent_fn , & add_block_ctx -> block [new_id ]) = = 0 ) {
164
+ add_block_test_sent_fn , & add_block_ctx -> block [new_id ]) ! = 0 ) {
160
165
error_found |= add_block_test_block_send_failed ;
161
166
break ;
162
167
}
@@ -169,15 +174,17 @@ void add_block_test_send(add_block_test_ctx_t* add_block_ctx, int block_id)
169
174
170
175
int add_block_test_recv (picoquic_cnx_t * cnx ,
171
176
uint64_t stream_id , uint8_t * bytes , size_t length ,
172
- picoquic_call_back_event_t fin_or_event , void * add_block_ctx , void * v_stream_ctx )
177
+ picoquic_call_back_event_t fin_or_event , add_block_test_ctx_t * add_block_ctx , void * v_stream_ctx )
173
178
{
179
+ int ret = 0 ;
180
+
174
181
if (cnx == add_block_ctx -> cnx_client ) {
175
182
/* the client is not expected to receive data. It MAY receive a FIN mark */
176
183
if (fin_or_event != picoquic_callback_stream_fin || length > 0 ) {
177
184
ret = -1 ;
178
185
}
179
186
}
180
- else if (picoquic_get_quic ( cnx ) != add_block_ctx -> quic [0 ]) {
187
+ else if (cnx -> quic != add_block_ctx -> quic [1 ]) {
181
188
/* Not from the expected server */
182
189
ret = -1 ;
183
190
}
@@ -190,20 +197,23 @@ int add_block_test_recv(picoquic_cnx_t* cnx,
190
197
ret = -1 ;
191
198
}
192
199
else {
193
- memcpy (add_block_ctx -> recv_data + add_block_ctx -> recv_length , bytes , length );
200
+ if (length > 0 ) {
201
+ memcpy (add_block_ctx -> recv_data + add_block_ctx -> recv_length , bytes , length );
202
+ }
194
203
add_block_ctx -> recv_length += length ;
195
204
if (fin_or_event == picoquic_callback_stream_fin ) {
196
205
add_block_ctx -> fin_recv = 1 ;
197
206
}
198
207
}
208
+ return ret ;
199
209
}
200
210
201
211
int add_block_test_callback (picoquic_cnx_t * cnx ,
202
212
uint64_t stream_id , uint8_t * bytes , size_t length ,
203
213
picoquic_call_back_event_t fin_or_event , void * callback_ctx , void * v_stream_ctx )
204
214
{
205
215
int ret = 0 ;
206
- add_block_test_ctx_t * add_block_ctx = (sample_add_block_ctx_t * )callback_ctx ;
216
+ add_block_test_ctx_t * add_block_ctx = (add_block_test_ctx_t * )callback_ctx ;
207
217
208
218
if (add_block_ctx == NULL ) {
209
219
/* This should never happen, because the callback context is initialized
@@ -216,7 +226,7 @@ int add_block_test_callback(picoquic_cnx_t* cnx,
216
226
case picoquic_callback_stream_data :
217
227
case picoquic_callback_stream_fin :
218
228
/* Data arrival on stream #x, maybe with fin mark */
219
-
229
+ ret = add_block_test_recv ( cnx , stream_id , bytes , length , fin_or_event , add_block_ctx , v_stream_ctx );
220
230
break ;
221
231
case picoquic_callback_stop_sending : /* Should not happen, treated as reset */
222
232
ret = -1 ;
@@ -229,7 +239,8 @@ int add_block_test_callback(picoquic_cnx_t* cnx,
229
239
case picoquic_callback_application_close : /* Received application close */
230
240
fprintf (stdout , "Connection closed.\n" );
231
241
/* Mark the connection as completed */
232
- add_block_ctx -> is_disconnected = 1 ;
242
+ add_block_ctx -> fin_sent = 1 ;
243
+ add_block_ctx -> fin_recv = 1 ;
233
244
/* Remove the application callback */
234
245
picoquic_set_callback (cnx , NULL , NULL );
235
246
break ;
@@ -406,10 +417,6 @@ int add_block_test_is_finished(add_block_test_ctx_t* add_block_ctx)
406
417
407
418
void add_block_test_delete_ctx (add_block_test_ctx_t * add_block_ctx )
408
419
{
409
- /* Delete the connections */
410
- while (add_block_ctx -> first_cnx != NULL ) {
411
- add_block_test_delete_cnx_context (add_block_ctx -> first_cnx );
412
- }
413
420
/* Delete the links */
414
421
for (int i = 0 ; i < 2 ; i ++ ) {
415
422
if (add_block_ctx -> link [i ] != NULL ) {
@@ -429,23 +436,22 @@ void add_block_test_delete_ctx(add_block_test_ctx_t* add_block_ctx)
429
436
}
430
437
431
438
if (add_block_ctx -> recv_data ) {
432
- free (add_block_ctx -> test_data );
433
- add_block_ctx -> test_data = NULL ;
439
+ free (add_block_ctx -> recv_data );
440
+ add_block_ctx -> recv_data = NULL ;
434
441
}
435
442
436
443
/* Free the context */
437
444
free (add_block_ctx );
438
445
}
439
446
440
- add_block_test_ctx_t * add_block_test_configure (int media_test_id , add_block_test_spec_t * spec )
447
+ add_block_test_ctx_t * add_block_test_configure ()
441
448
{
442
449
int ret = 0 ;
443
450
add_block_test_ctx_t * add_block_ctx = NULL ;
444
451
char test_server_cert_file [512 ];
445
452
char test_server_key_file [512 ];
446
453
char test_server_cert_store_file [512 ];
447
- picoquic_connection_id_t icid = { { 0xed , 0x1a , 0x7e , 0x57 , 0 , 0 , 0 , 0 }, 8 };
448
- icid .id [4 ] = media_test_id ;
454
+ picoquic_connection_id_t icid = { { 0xad , 0xdb , 0x10 , 0xc8 , 0 , 0 , 0 , 0 }, 8 };
449
455
450
456
ret = picoquic_get_input_path (test_server_cert_file , sizeof (test_server_cert_file ), picoquic_solution_dir , PICOQUIC_TEST_FILE_SERVER_CERT );
451
457
@@ -473,18 +479,11 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
473
479
add_block_ctx -> quic [1 ] = picoquic_create (4 ,
474
480
test_server_cert_file , test_server_key_file , test_server_cert_store_file ,
475
481
ADD_BLOCK_TEST_ALPN , add_block_test_callback , (void * )add_block_ctx , NULL , NULL , NULL ,
476
- add_block_ctx -> simulated_time , & add_block_ctx -> simulated_time , NULL , add_block_test_ticket_encrypt_key , sizeof ( add_block_test_ticket_encrypt_key ) );
482
+ add_block_ctx -> simulated_time , & add_block_ctx -> simulated_time , NULL , NULL , 0 );
477
483
478
484
if (add_block_ctx -> quic [0 ] == NULL || add_block_ctx -> quic [1 ] == NULL ) {
479
485
ret = -1 ;
480
486
}
481
-
482
- if (spec -> ccalgo != NULL ) {
483
- for (int i = 0 ; i < 2 && ret == 0 ; i ++ ) {
484
- picoquic_set_default_congestion_algorithm (add_block_ctx -> quic [i ], spec -> ccalgo );
485
- ret = picoquic_set_binlog (add_block_ctx -> quic [i ], "." );
486
- }
487
- }
488
487
}
489
488
490
489
if (ret == 0 ) {
@@ -498,8 +497,7 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
498
497
}
499
498
/* register the links */
500
499
for (int i = 0 ; i < 2 ; i ++ ) {
501
- add_block_ctx -> link [i ] = picoquictest_sim_link_create (0.01 ,
502
- (spec -> link_latency == 0 ) ? 10000 : spec -> link_latency , NULL , 0 , 0 );
500
+ add_block_ctx -> link [i ] = picoquictest_sim_link_create (0.01 , 10000 , NULL , 0 , 0 );
503
501
if (add_block_ctx -> link [i ] == NULL ) {
504
502
ret = -1 ;
505
503
break ;
@@ -515,9 +513,15 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
515
513
ret = -1 ;
516
514
}
517
515
else {
516
+ uint64_t rdx = 0xdeeddaadd00dd11dull ;
518
517
add_block_ctx -> test_data_length = add_block_test_max_sent ;
519
518
520
- picoquic_public_random (add_block_ctx -> test_data , add_block_ctx -> test_data_length );
519
+ for (size_t i = 0 ; i < add_block_ctx -> test_data_length ; i ++ ) {
520
+ add_block_ctx -> test_data [i ] = (uint8_t )(rdx & 0xff );
521
+ rdx *= 101 ;
522
+ rdx += 0xbadc0ffee ;
523
+ rdx += i ;
524
+ }
521
525
memset (add_block_ctx -> recv_data , 0 , add_block_ctx -> test_data_length );
522
526
}
523
527
}
@@ -528,7 +532,7 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
528
532
icid , picoquic_null_connection_id ,
529
533
(struct sockaddr * )& add_block_ctx -> addr [1 ], add_block_ctx -> simulated_time , 0 , PICOQUIC_TEST_SNI , ADD_BLOCK_TEST_ALPN , 1 );
530
534
/* Start the connection and create the context */
531
- if (add_block_ctx -> cnx_client = NULL ) {
535
+ if (add_block_ctx -> cnx_client == NULL ) {
532
536
ret = -1 ;
533
537
}
534
538
else {
@@ -537,8 +541,8 @@ add_block_test_ctx_t* add_block_test_configure(int media_test_id, add_block_test
537
541
/* Queue the first block */
538
542
add_block_test_send (add_block_ctx , 0 );
539
543
/* start the connection */
540
- if (picoquic_start_client_cnx (cnx ) != 0 ) {
541
- picoquic_delete_cnx (cnx );
544
+ if (picoquic_start_client_cnx (add_block_ctx -> cnx_client ) != 0 ) {
545
+ picoquic_delete_cnx (add_block_ctx -> cnx_client );
542
546
ret = -1 ;
543
547
}
544
548
}
@@ -582,7 +586,8 @@ int add_block_test()
582
586
int is_finished = 0 ;
583
587
584
588
/* set the configuration */
585
- add_block_test_ctx_t * add_block_ctx = add_block_test_configure (media_test_id , spec );
589
+ add_block_test_ctx_t * add_block_ctx = add_block_test_configure ();
590
+ current_ctx = add_block_ctx ;
586
591
if (add_block_ctx == NULL ) {
587
592
ret = -1 ;
588
593
}
0 commit comments