Skip to content

Commit

Permalink
move fail impl to test
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Aug 17, 2023
1 parent 101f1d0 commit 77ebe1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
10 changes: 0 additions & 10 deletions tests/testlib/s2n_ktls_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,6 @@ ssize_t s2n_test_ktls_recvmsg_io_stuffer(void *io_context, struct msghdr *msg)
return bytes_read;
}

ssize_t s2n_test_ktls_sendmsg_fail(void *io_context, const struct msghdr *msg)
{
struct s2n_test_ktls_io_fail *io_ctx = (struct s2n_test_ktls_io_fail *) io_context;
POSIX_ENSURE_REF(io_ctx);
io_ctx->invoked_count++;

errno = io_ctx->errno_code;
return -1;
}

S2N_RESULT s2n_test_init_ktls_io_stuffer(struct s2n_connection *server, struct s2n_connection *client,
struct s2n_test_ktls_io_stuffer_pair *io_pair)
{
Expand Down
7 changes: 0 additions & 7 deletions tests/testlib/s2n_ktls_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ struct s2n_test_ktls_io_stuffer_pair {
ssize_t s2n_test_ktls_sendmsg_io_stuffer(void *io_context, const struct msghdr *msg);
ssize_t s2n_test_ktls_recvmsg_io_stuffer(void *io_context, struct msghdr *msg);

/* Mock implementation used for validating failure behavior */
struct s2n_test_ktls_io_fail {
size_t errno_code;
size_t invoked_count;
};
ssize_t s2n_test_ktls_sendmsg_fail(void *io_context, const struct msghdr *msg);

S2N_RESULT s2n_test_init_ktls_io_stuffer(struct s2n_connection *server, struct s2n_connection *client,
struct s2n_test_ktls_io_stuffer_pair *io_pair);
S2N_CLEANUP_RESULT s2n_ktls_io_stuffer_pair_free(struct s2n_test_ktls_io_stuffer_pair *pair);
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/s2n_ktls_io_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ S2N_RESULT s2n_ktls_set_control_data(struct msghdr *msg, char *buf, size_t buf_s
int cmsg_type, uint8_t record_type);
S2N_RESULT s2n_ktls_get_control_data(struct msghdr *msg, int cmsg_type, uint8_t *record_type);

/* Mock implementation used for validating failure behavior */
struct s2n_test_ktls_io_fail {
size_t errno_code;
size_t invoked_count;
};

static ssize_t s2n_test_ktls_sendmsg_fail(void *io_context, const struct msghdr *msg)
{
struct s2n_test_ktls_io_fail *io_ctx = (struct s2n_test_ktls_io_fail *) io_context;
POSIX_ENSURE_REF(io_ctx);
io_ctx->invoked_count++;

errno = io_ctx->errno_code;
return -1;
}

int main(int argc, char **argv)
{
BEGIN_TEST();
Expand Down

0 comments on commit 77ebe1b

Please sign in to comment.