diff options
author | Andreas Schneider <asn@samba.org> | 2015-09-14 22:07:09 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2015-10-14 10:27:51 +0200 |
commit | 96dbeb75f78665cf81a4ef8e3842e819043f8d51 (patch) | |
tree | 82fd1f19c6add4f5eda0384e77c96e199f13c583 /tests/test_echo_tcp_socket_options.c | |
parent | 1db61302b6036bdfabf0e3a1507e0e5573a57368 (diff) | |
download | socket_wrapper-96dbeb75f78665cf81a4ef8e3842e819043f8d51.tar.gz socket_wrapper-96dbeb75f78665cf81a4ef8e3842e819043f8d51.tar.xz socket_wrapper-96dbeb75f78665cf81a4ef8e3842e819043f8d51.zip |
tests: Add test for TCP_NODELAY getsockopt()
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'tests/test_echo_tcp_socket_options.c')
-rw-r--r-- | tests/test_echo_tcp_socket_options.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_echo_tcp_socket_options.c b/tests/test_echo_tcp_socket_options.c index f068fb8..9be2bf0 100644 --- a/tests/test_echo_tcp_socket_options.c +++ b/tests/test_echo_tcp_socket_options.c @@ -10,6 +10,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> +#include <netinet/tcp.h> #include <arpa/inet.h> #include <netdb.h> #include <stdlib.h> @@ -293,6 +294,40 @@ static void test_bind_ipv6_only(void **state) } #endif +static void test_sockopt_tcp(void **state) +{ + struct torture_address addr = { + .sa_socklen = sizeof(struct sockaddr_in), + }; + int opt = -1; + socklen_t optlen = sizeof(int); + int rc; + + int s; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_int_not_equal(s, -1); + + addr.sa.in.sin_family = AF_INET; + addr.sa.in.sin_port = htons(torture_server_port()); + + rc = inet_pton(addr.sa.in.sin_family, + torture_server_address(AF_INET), + &addr.sa.in.sin_addr); + assert_int_equal(rc, 1); + + rc = connect(s, &addr.sa.s, addr.sa_socklen); + assert_int_equal(rc, 0); + + rc = getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen); + assert_return_code(rc, errno); + assert_int_equal(opt, 0); + + close(s); +} + int main(void) { int rc; @@ -311,6 +346,9 @@ int main(void) { setup_ipv6, teardown), #endif + cmocka_unit_test_setup_teardown(test_sockopt_tcp, + setup_echo_srv_tcp_ipv4, + teardown), }; rc = cmocka_run_group_tests(sockopt_tests, NULL, NULL); |