Skip to content

Commit

Permalink
Added check tests for abstract socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Miniwoffer committed Nov 22, 2021
1 parent 079c963 commit 4bb687b
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions check/check_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,89 @@ START_TEST(test_uwsgi_opt_set_int)
}
END_TEST

/* abstract socket tests */

START_TEST(test_uwsgi_connect_to_unix) {
int sfd, cfd;
// Normal abstract socket bind
sfd = bind_to_unix("uwsgi_abs_test_socket", 10, 0, 1);
ck_assert_msg(sfd > 0, "Failed to bind abstract socket");

//Test open '@' prefix
cfd = uwsgi_connect("@uwsgi_abs_test_socket", 0, 0);
ck_assert_msg(cfd > 0, "Failed to connect with abstract socket with '@' prefix");
close(cfd);

//Test open '\\0' prefix
cfd = uwsgi_connect("\\0uwsgi_abs_test_socket", 0, 0);
ck_assert_msg(cfd > 0, "Failed to connect with abstract socket with \"\\0\" prefix");
close(cfd);
close(sfd);
}
END_TEST

START_TEST(test_uwsgi_bind_to_unix_normal) {
int sfd, cfd;
// Normal abstract socket bind
sfd = bind_to_unix("uwsgi_abs_test_socket", 10, 0, 1);
ck_assert_msg(sfd > 0, "Failed to bind abstract socket");

//Test open '@' prefix
cfd = uwsgi_connect("@uwsgi_abs_test_socket", 0, 0);
ck_assert_msg(cfd > 0, "Failed to connect to abstract socket");

close(cfd);
close(sfd);
}
END_TEST

START_TEST(test_uwsgi_bind_to_unix_at) {
int sfd, cfd;
// Normal abstract socket bind
sfd = bind_to_unix("@uwsgi_abs_test_socket", 10, 0, 0);
ck_assert_msg(sfd > 0, "Failed to bind abstract socket");

//Test open '@' prefix
cfd = uwsgi_connect("@uwsgi_abs_test_socket", 0, 0);
ck_assert_msg(cfd > 0, "Failed to connect to abstract socket");

close(cfd);
close(sfd);
}
END_TEST

START_TEST(test_uwsgi_bind_to_unix_null) {
int sfd, cfd;
// Normal abstract socket bind
sfd = bind_to_unix("\\0uwsgi_abs_test_socket", 10, 0, 0);
ck_assert_msg(sfd > 0, "Failed to bind abstract socket");

//Test open '@' prefix
cfd = uwsgi_connect("@uwsgi_abs_test_socket", 0, 0);
ck_assert_msg(cfd > 0, "Failed to connect to abstract socket");

close(cfd);
close(sfd);
}
END_TEST


Suite *check_core_opt_parsing(void)
{
Suite *s = suite_create("uwsgi opt parsing");
TCase *tc = tcase_create("opt_parsing");

suite_add_tcase(s, tc);
tcase_add_test(tc, test_uwsgi_opt_set_int);


TCase *socket_tc = tcase_create("socket_tests");
suite_add_tcase(s, socket_tc);

tcase_add_test(socket_tc, test_uwsgi_connect_to_unix);
tcase_add_test(socket_tc, test_uwsgi_bind_to_unix_normal);
tcase_add_test(socket_tc, test_uwsgi_bind_to_unix_at);
tcase_add_test(socket_tc, test_uwsgi_bind_to_unix_null);
return s;
}

Expand Down

0 comments on commit 4bb687b

Please sign in to comment.