Skip to content

Commit 6b0e24e

Browse files
committed
test_memio: support WANT_WRITE simulation
1 parent 610d8e5 commit 6b0e24e

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/utils.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int test_memio_write_cb(WOLFSSL *ssl, char *data, int sz, void *ctx)
4848
int *len;
4949
int *msg_sizes;
5050
int *msg_count;
51+
int *forceWantWrite;
5152

5253
test_ctx = (struct test_memio_ctx*)ctx;
5354

@@ -56,14 +57,19 @@ int test_memio_write_cb(WOLFSSL *ssl, char *data, int sz, void *ctx)
5657
len = &test_ctx->c_len;
5758
msg_sizes = test_ctx->c_msg_sizes;
5859
msg_count = &test_ctx->c_msg_count;
60+
forceWantWrite = &test_ctx->c_force_want_write;
5961
}
6062
else {
6163
buf = test_ctx->s_buff;
6264
len = &test_ctx->s_len;
6365
msg_sizes = test_ctx->s_msg_sizes;
6466
msg_count = &test_ctx->s_msg_count;
67+
forceWantWrite = &test_ctx->s_force_want_write;
6568
}
6669

70+
if (*forceWantWrite)
71+
return WOLFSSL_CBIO_ERR_WANT_WRITE;
72+
6773
if ((unsigned)(*len + sz) > TEST_MEMIO_BUF_SZ)
6874
return WOLFSSL_CBIO_ERR_WANT_WRITE;
6975

@@ -362,16 +368,30 @@ int test_memio_setup_ex(struct test_memio_ctx *ctx,
362368
return 0;
363369
}
364370

371+
void test_memio_simulate_want_write(struct test_memio_ctx *ctx, int is_client,
372+
int enable)
373+
{
374+
if (ctx == NULL)
375+
return;
376+
377+
if (is_client)
378+
ctx->c_force_want_write = (enable != 0);
379+
else
380+
ctx->s_force_want_write = (enable != 0);
381+
}
382+
365383
void test_memio_clear_buffer(struct test_memio_ctx *ctx, int is_client)
366384
{
367385
if (is_client) {
368386
ctx->c_len = 0;
369387
ctx->c_msg_pos = 0;
370388
ctx->c_msg_count = 0;
389+
ctx->c_force_want_write = 0;
371390
} else {
372391
ctx->s_len = 0;
373392
ctx->s_msg_pos = 0;
374393
ctx->s_msg_count = 0;
394+
ctx->s_force_want_write = 0;
375395
}
376396
}
377397

tests/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct test_memio_ctx
4444
int s_len;
4545
const char* s_ciphers;
4646

47+
int c_force_want_write;
48+
int s_force_want_write;
49+
4750
int c_msg_sizes[TEST_MEMIO_MAX_MSGS];
4851
int c_msg_count;
4952
int c_msg_pos;
@@ -64,6 +67,8 @@ int test_memio_setup_ex(struct test_memio_ctx *ctx,
6467
method_provider method_c, method_provider method_s,
6568
byte *caCert, int caCertSz, byte *serverCert, int serverCertSz,
6669
byte *serverKey, int serverKeySz);
70+
void test_memio_simulate_want_write(struct test_memio_ctx *ctx, int is_client,
71+
int enable);
6772
void test_memio_clear_buffer(struct test_memio_ctx *ctx, int is_client);
6873
int test_memio_inject_message(struct test_memio_ctx *ctx, int client, const char *data, int sz);
6974
int test_memio_copy_message(const struct test_memio_ctx *ctx, int client,

0 commit comments

Comments
 (0)