[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Fix cases where the tests were doing closesocket() on a non-socket



commit 4c55e8a58f41933e76bcb309206c98e7b5a1d834
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Sep 9 10:28:12 2016 -0400

    Fix cases where the tests were doing closesocket() on a non-socket
    
    These seem to have caused warnings on windows. Hmmm.
---
 src/common/compat.c        |  4 ++--
 src/common/compat.h        |  2 +-
 src/test/test_address.c    | 12 +++++++++++-
 src/test/test_connection.c | 11 ++++++++++-
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/common/compat.c b/src/common/compat.c
index 5385bd8..3fde2b3 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1110,8 +1110,8 @@ tor_close_socket_simple(tor_socket_t s)
 
 /** As tor_close_socket_simple(), but keeps track of the number
  * of open sockets. Returns 0 on success, -1 on failure. */
-int
-tor_close_socket(tor_socket_t s)
+MOCK_IMPL(int,
+tor_close_socket,(tor_socket_t s))
 {
   int r = tor_close_socket_simple(s);
 
diff --git a/src/common/compat.h b/src/common/compat.h
index 12f280d..ee1c945 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -478,7 +478,7 @@ typedef int socklen_t;
 #endif
 
 int tor_close_socket_simple(tor_socket_t s);
-int tor_close_socket(tor_socket_t s);
+MOCK_DECL(int, tor_close_socket, (tor_socket_t s));
 tor_socket_t tor_open_socket_with_extensions(
                                            int domain, int type, int protocol,
                                            int cloexec, int nonblock);
diff --git a/src/test/test_address.c b/src/test/test_address.c
index 9b4c52f..1d13d53 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -557,6 +557,13 @@ fake_open_socket(int domain, int type, int protocol)
   return FAKE_SOCKET_FD;
 }
 
+static int
+fake_close_socket(tor_socket_t s)
+{
+  (void)s;
+  return 0;
+}
+
 static int last_connected_socket_fd = 0;
 
 static int connect_retval = 0;
@@ -617,6 +624,7 @@ test_address_udp_socket_trick_whitebox(void *arg)
   MOCK(tor_open_socket,fake_open_socket);
   MOCK(tor_connect_socket,pretend_to_connect);
   MOCK(tor_getsockname,fake_getsockname);
+  MOCK(tor_close_socket,fake_close_socket);
 
   mock_addr = tor_malloc_zero(sizeof(struct sockaddr_storage));
   sockaddr_in_from_string("23.32.246.118",(struct sockaddr_in *)mock_addr);
@@ -647,11 +655,13 @@ test_address_udp_socket_trick_whitebox(void *arg)
 
   tt_assert(sockaddr_in6_are_equal(mock_addr6,ipv6_to_check));
 
+
+ done:
   UNMOCK(tor_open_socket);
   UNMOCK(tor_connect_socket);
   UNMOCK(tor_getsockname);
+  UNMOCK(tor_close_socket);
 
-  done:
   tor_free(ipv6_to_check);
   tor_free(mock_addr);
   tor_free(addr_from_hack);
diff --git a/src/test/test_connection.c b/src/test/test_connection.c
index bf2cf18..d394fc9 100644
--- a/src/test/test_connection.c
+++ b/src/test/test_connection.c
@@ -95,6 +95,13 @@ mock_connection_connect_sockaddr(connection_t *conn,
   return 1;
 }
 
+static int
+fake_close_socket(evutil_socket_t sock)
+{
+  (void)sock;
+  return 0;
+}
+
 static void
 test_conn_lookup_addr_helper(const char *address, int family, tor_addr_t *addr)
 {
@@ -124,6 +131,7 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose)
 
   MOCK(connection_connect_sockaddr,
        mock_connection_connect_sockaddr);
+  MOCK(tor_close_socket, fake_close_socket);
 
   init_connection_lists();
 
@@ -148,12 +156,13 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose)
   assert_connection_ok(conn, time(NULL));
 
   UNMOCK(connection_connect_sockaddr);
-
+  UNMOCK(tor_close_socket);
   return conn;
 
   /* On failure */
  done:
   UNMOCK(connection_connect_sockaddr);
+  UNMOCK(tor_close_socket);
   return NULL;
 }
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits