Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Jul 20, 2023
1 parent d3140a8 commit 42582bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 45 deletions.
21 changes: 0 additions & 21 deletions tests/testlib/s2n_self_talk_test_utils.c

This file was deleted.

7 changes: 0 additions & 7 deletions tests/testlib/s2n_testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,3 @@ extern const s2n_parsed_extension EMPTY_PARSED_EXTENSIONS[S2N_PARSED_EXTENSIONS_
int s2n_kem_recv_public_key_fuzz_test(const uint8_t *buf, size_t len, struct s2n_kem_params *kem_params);
int s2n_kem_recv_ciphertext_fuzz_test(const uint8_t *buf, size_t len, struct s2n_kem_params *kem_params);
int s2n_kem_recv_ciphertext_fuzz_test_init(const char *kat_file_path, struct s2n_kem_params *kem_params);

/* A collection of callbacks run during inet socket self talk tests */
struct self_talk_inet_socket_callbacks {
S2N_RESULT (*server_post_handshake_cb)(struct s2n_connection *conn);
S2N_RESULT (*client_post_handshake_cb)(struct s2n_connection *conn);
};
S2N_RESULT s2n_noop_inet_socket_cb(struct s2n_connection *conn);
42 changes: 25 additions & 17 deletions tests/unit/s2n_self_talk_inet_socket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
const char CHAR_A = 'a';
const char CHAR_B = 'b';

/* A collection of callbacks run during inet socket self talk tests */
struct self_talk_inet_socket_callbacks {
S2N_RESULT (*server_post_handshake_cb)(struct s2n_connection *conn);
S2N_RESULT (*client_post_handshake_cb)(struct s2n_connection *conn);
};

S2N_RESULT s2n_noop_inet_socket_cb(struct s2n_connection *conn)
{
return S2N_RESULT_OK;
}

static S2N_RESULT start_client(int fd, int read_pipe, const struct self_talk_inet_socket_callbacks *socket_cb)
{
/* Setup connections */
Expand Down Expand Up @@ -57,15 +68,13 @@ static S2N_RESULT start_client(int fd, int read_pipe, const struct self_talk_ine
char sync = 0;
char recv_buffer[1] = { 0 };

{
RESULT_GUARD_POSIX(read(read_pipe, &sync, 1));
RESULT_GUARD_POSIX(s2n_recv(client_conn, recv_buffer, 1, &blocked));
RESULT_ENSURE_EQ(memcmp(&CHAR_A, &recv_buffer[0], 1), 0);
RESULT_GUARD_POSIX(read(read_pipe, &sync, 1));
RESULT_GUARD_POSIX(s2n_recv(client_conn, recv_buffer, 1, &blocked));
RESULT_ENSURE_EQ(memcmp(&CHAR_A, &recv_buffer[0], 1), 0);

RESULT_GUARD_POSIX(read(read_pipe, &sync, 1));
RESULT_GUARD_POSIX(s2n_recv(client_conn, recv_buffer, 1, &blocked));
RESULT_ENSURE_EQ(memcmp(&CHAR_B, &recv_buffer[0], 1), 0);
}
RESULT_GUARD_POSIX(read(read_pipe, &sync, 1));
RESULT_GUARD_POSIX(s2n_recv(client_conn, recv_buffer, 1, &blocked));
RESULT_ENSURE_EQ(memcmp(&CHAR_B, &recv_buffer[0], 1), 0);

return S2N_RESULT_OK;
}
Expand Down Expand Up @@ -99,15 +108,14 @@ static S2N_RESULT start_server(int fd, int write_pipe, const struct self_talk_in

char sync = 0;
char send_buffer[1] = { 0 };
{
send_buffer[0] = CHAR_A;
EXPECT_SUCCESS(s2n_send(server_conn, send_buffer, 1, &blocked));
EXPECT_SUCCESS(write(write_pipe, &sync, 1));

send_buffer[0] = CHAR_B;
EXPECT_SUCCESS(s2n_send(server_conn, send_buffer, 1, &blocked));
EXPECT_SUCCESS(write(write_pipe, &sync, 1));
}

send_buffer[0] = CHAR_A;
EXPECT_SUCCESS(s2n_send(server_conn, send_buffer, 1, &blocked));
EXPECT_SUCCESS(write(write_pipe, &sync, 1));

send_buffer[0] = CHAR_B;
EXPECT_SUCCESS(s2n_send(server_conn, send_buffer, 1, &blocked));
EXPECT_SUCCESS(write(write_pipe, &sync, 1));

return S2N_RESULT_OK;
}
Expand Down

0 comments on commit 42582bd

Please sign in to comment.