[SCM] Socket Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Dec 17 06:51:30 MST 2013


The branch, master has been updated
       via  3c3b7f6 tests: Add test_echo_tcp_write_read.
       via  0d87b9e torture: Add tcp function to setup echo server.
       via  e778fa2 torture: Pass socket type to torture_setup_echo_srv_ip().
       via  356fc98 torture: Add torture_generate_random_buffer().
      from  2ee37e0 tests: Add test_echo_udp_send_recv test.

http://gitweb.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3c3b7f69d283fc6407a146b412df00517e500b01
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Dec 17 14:48:38 2013 +0100

    tests: Add test_echo_tcp_write_read.

commit 0d87b9e18aa400844c18639e575d95b2f98266d5
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Dec 17 14:44:54 2013 +0100

    torture: Add tcp function to setup echo server.

commit e778fa214fb69b2119f7f5e5ebbf21476cd8b0a8
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Dec 17 14:44:08 2013 +0100

    torture: Pass socket type to torture_setup_echo_srv_ip().

commit 356fc983ec7f3147b5685fa6dc586959ec50b0ea
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Dec 13 14:49:13 2013 +0100

    torture: Add torture_generate_random_buffer().

-----------------------------------------------------------------------

Summary of changes:
 tests/CMakeLists.txt                               |    2 +-
 ..._udp_send_recv.c => test_echo_tcp_write_read.c} |   44 ++++++++---------
 tests/torture.c                                    |   52 ++++++++++++++++++--
 tests/torture.h                                    |    5 ++
 4 files changed, 73 insertions(+), 30 deletions(-)
 copy tests/{test_echo_udp_send_recv.c => test_echo_tcp_write_read.c} (72%)


Changeset truncated at 500 lines:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ec5f238..63b0046 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -17,7 +17,7 @@ target_link_libraries(${TORTURE_LIBRARY}
     ${CMOCKA_LIBRARY}
     ${SWRAP_REQUIRED_LIBRARIES})
 
-set(SWRAP_TESTS test_ioctl test_echo_udp_sendto_recvfrom test_echo_udp_send_recv)
+set(SWRAP_TESTS test_ioctl test_echo_udp_sendto_recvfrom test_echo_udp_send_recv test_echo_tcp_write_read)
 
 foreach(_SWRAP_TEST ${SWRAP_TESTS})
     add_cmocka_test(${_SWRAP_TEST} ${_SWRAP_TEST}.c ${TORTURE_LIBRARY})
diff --git a/tests/test_echo_udp_send_recv.c b/tests/test_echo_tcp_write_read.c
similarity index 72%
copy from tests/test_echo_udp_send_recv.c
copy to tests/test_echo_tcp_write_read.c
index c197251..389e400 100644
--- a/tests/test_echo_udp_send_recv.c
+++ b/tests/test_echo_tcp_write_read.c
@@ -15,14 +15,14 @@
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_udp_ipv4(void **state)
+static void setup_echo_srv_tcp_ipv4(void **state)
 {
-	torture_setup_echo_srv_udp_ipv4(state);
+	torture_setup_echo_srv_tcp_ipv4(state);
 }
 
-static void setup_echo_srv_udp_ipv6(void **state)
+static void setup_echo_srv_tcp_ipv6(void **state)
 {
-	torture_setup_echo_srv_udp_ipv6(state);
+	torture_setup_echo_srv_tcp_ipv6(state);
 }
 
 static void teardown(void **state)
@@ -30,7 +30,7 @@ static void teardown(void **state)
 	torture_teardown_echo_srv(state);
 }
 
-static void test_send_recv_ipv4(void **state)
+static void test_write_read_ipv4(void **state)
 {
 	struct sockaddr_in sin;
 	socklen_t slen = sizeof(struct sockaddr_in);
@@ -41,7 +41,7 @@ static void test_send_recv_ipv4(void **state)
 
 	(void) state; /* unused */
 
-	s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+	s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 	assert_int_not_equal(s, -1);
 
 	ZERO_STRUCT(sin);
@@ -60,16 +60,14 @@ static void test_send_recv_ipv4(void **state)
 
 		snprintf(send_buf, sizeof(send_buf), "packet.%d", i);
 
-		ret = send(s,
-			   send_buf,
-			   sizeof(send_buf),
-			   0);
+		ret = write(s,
+			    send_buf,
+			    sizeof(send_buf));
 		assert_int_not_equal(ret, -1);
 
-		ret = recv(s,
+		ret = read(s,
 			   recv_buf,
-			   sizeof(recv_buf),
-			   0);
+			   sizeof(recv_buf));
 		assert_int_not_equal(ret, -1);
 
 		assert_memory_equal(send_buf, recv_buf, sizeof(send_buf));
@@ -79,7 +77,7 @@ static void test_send_recv_ipv4(void **state)
 }
 
 #ifdef HAVE_IPV6
-static void test_send_recv_ipv6(void **state)
+static void test_write_read_ipv6(void **state)
 {
 	struct sockaddr_in6 sin6;
 	socklen_t slen = sizeof(struct sockaddr_in6);
@@ -90,7 +88,7 @@ static void test_send_recv_ipv6(void **state)
 
 	(void) state; /* unused */
 
-	s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+	s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
 	assert_int_not_equal(s, -1);
 
 	ZERO_STRUCT(sin6);
@@ -109,16 +107,14 @@ static void test_send_recv_ipv6(void **state)
 
 		snprintf(send_buf, sizeof(send_buf), "packet.%d", i);
 
-		ret = send(s,
-			   send_buf,
-			   sizeof(send_buf),
-			   0);
+		ret = write(s,
+			    send_buf,
+			    sizeof(send_buf));
 		assert_int_not_equal(ret, -1);
 
-		ret = recv(s,
+		ret = read(s,
 			   recv_buf,
-			   sizeof(recv_buf),
-			   0);
+			   sizeof(recv_buf));
 		assert_int_not_equal(ret, -1);
 
 		assert_memory_equal(send_buf, recv_buf, sizeof(send_buf));
@@ -132,9 +128,9 @@ int main(void) {
 	int rc;
 
 	const UnitTest tests[] = {
-		unit_test_setup_teardown(test_send_recv_ipv4, setup_echo_srv_udp_ipv4, teardown),
+		unit_test_setup_teardown(test_write_read_ipv4, setup_echo_srv_tcp_ipv4, teardown),
 #ifdef HAVE_IPV6
-		unit_test_setup_teardown(test_send_recv_ipv6, setup_echo_srv_udp_ipv6, teardown),
+		unit_test_setup_teardown(test_write_read_ipv6, setup_echo_srv_tcp_ipv6, teardown),
 #endif
 	};
 
diff --git a/tests/torture.c b/tests/torture.c
index e2bab8c..d44fa25 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -39,6 +39,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
 #include <signal.h>
 #include <fcntl.h>
 
@@ -46,6 +47,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 
 #define TORTURE_SOCKET_DIR "/tmp/test_socket_wrapper_XXXXXX"
 #define TORTURE_ECHO_SRV_PIDFILE "echo_srv.pid"
@@ -78,19 +80,34 @@ void torture_setup_socket_dir(void **state)
 	*state = s;
 }
 
-static void torture_setup_echo_srv_udp_ip(void **state, const char *ip)
+static void torture_setup_echo_srv_ip(void **state,
+				      const char *ip,
+				      int type)
 {
 	struct torture_state *s;
 	char start_echo_srv[1024] = {0};
+	const char *t;
 	int rc;
 
 	torture_setup_socket_dir(state);
 
 	s = *state;
 
+	switch (type) {
+	case SOCK_STREAM:
+		t = "-t";
+		break;
+	case SOCK_DGRAM:
+		t = "-u";
+		break;
+	default:
+		t = "";
+		break;
+	}
+
 	snprintf(start_echo_srv, sizeof(start_echo_srv),
-		 "%s/tests/echo_srv -b %s -D -u --pid %s",
-		 BINARYDIR, ip, s->srv_pidfile);
+		 "%s/tests/echo_srv -b %s -D %s --pid %s",
+		 BINARYDIR, ip, t, s->srv_pidfile);
 
 	rc = system(start_echo_srv);
 	assert_int_equal(rc, 0);
@@ -100,12 +117,26 @@ static void torture_setup_echo_srv_udp_ip(void **state, const char *ip)
 
 void torture_setup_echo_srv_udp_ipv4(void **state)
 {
-	torture_setup_echo_srv_udp_ip(state, TORTURE_ECHO_SRV_IPV4);
+	torture_setup_echo_srv_ip(state, TORTURE_ECHO_SRV_IPV4, SOCK_DGRAM);
 }
 
 void torture_setup_echo_srv_udp_ipv6(void **state)
 {
-	torture_setup_echo_srv_udp_ip(state, TORTURE_ECHO_SRV_IPV6);
+	torture_setup_echo_srv_ip(state, TORTURE_ECHO_SRV_IPV6, SOCK_DGRAM);
+}
+
+void torture_setup_echo_srv_tcp_ipv4(void **state)
+{
+	torture_setup_echo_srv_ip(state,
+				      TORTURE_ECHO_SRV_IPV4,
+				      SOCK_STREAM);
+}
+
+void torture_setup_echo_srv_tcp_ipv6(void **state)
+{
+	torture_setup_echo_srv_ip(state,
+				      TORTURE_ECHO_SRV_IPV6,
+				      SOCK_STREAM);
 }
 
 void torture_teardown_socket_dir(void **state)
@@ -168,3 +199,14 @@ void torture_teardown_echo_srv(void **state)
 done:
 	torture_teardown_socket_dir(state);
 }
+
+void torture_generate_random_buffer(uint8_t *out, int len)
+{
+	int i;
+
+	srand(time(NULL));
+
+	for (i = 0; i < len; i++) {
+		out[i] = (uint8_t)rand();
+	}
+}
diff --git a/tests/torture.h b/tests/torture.h
index 7b88a4c..3d0b517 100644
--- a/tests/torture.h
+++ b/tests/torture.h
@@ -41,6 +41,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 
+#include <stdint.h>
 #include <string.h>
 
 #define TORTURE_ECHO_SRV_IPV4 "127.0.0.10"
@@ -61,7 +62,11 @@ void torture_setup_socket_dir(void **state);
 void torture_setup_echo_srv_udp_ipv4(void **state);
 void torture_setup_echo_srv_udp_ipv6(void **state);
 
+void torture_setup_echo_srv_tcp_ipv4(void **state);
+void torture_setup_echo_srv_tcp_ipv6(void **state);
+
 void torture_teardown_socket_dir(void **state);
 void torture_teardown_echo_srv(void **state);
 
+void torture_generate_random_buffer(uint8_t *out, int len);
 #endif /* _TORTURE_H */


-- 
Socket Wrapper Repository


More information about the samba-cvs mailing list