Bug 891551 - Part 6: Add log dumper to multi_tcp_socket_unittest. r=bwc
author"Peter Tatrai <ptatrai@gmail.com>"
Tue, 03 Jun 2014 08:44:59 +0200
changeset 249701 4c413795f28ab425eb581db5dac7334ca2981e98
parent 249700 1cb943d6a204ef6729f8430ffb5eb54f971fc3f0
child 249702 057cd9bbfbd31655284527a95d66ecbccbb37b8c
push id28936
push userryanvm@gmail.com
push dateFri, 19 Jun 2015 20:34:42 +0000
treeherdermozilla-central@c319f262ce3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc
bugs891551
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 891551 - Part 6: Add log dumper to multi_tcp_socket_unittest. r=bwc
media/mtransport/test/multi_tcp_socket_unittest.cpp
media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c
--- a/media/mtransport/test/multi_tcp_socket_unittest.cpp
+++ b/media/mtransport/test/multi_tcp_socket_unittest.cpp
@@ -15,16 +15,17 @@ extern "C" {
 #include "nr_api.h"
 #include "nr_socket.h"
 #include "transport_addr.h"
 #include "ice_ctx.h"
 #include "nr_socket_multi_tcp.h"
 }
 
 #include "mtransport_test_utils.h"
+#include "gtest_ringbuffer_dumper.h"
 
 #include "nr_socket_prsock.h"
 
 #include "nricectx.h"
 #include "nricemediastream.h"
 
 #define GTEST_HAS_RTTI 0
 #include "gtest/gtest.h"
@@ -386,16 +387,21 @@ TEST_F(MultiTcpSocketTest, TestBigData) 
   RecvData(socks[1], socks[0], buf1, sizeof(buf1));
 }
 
 
 int main(int argc, char **argv)
 {
   test_utils = new MtransportTestUtils();
 
+  ::testing::TestEventListeners& listeners =
+        ::testing::UnitTest::GetInstance()->listeners();
+  // Adds a listener to the end.  Google Test takes the ownership.
+  listeners.Append(new test::RingbufferDumper(test_utils));
+
   // Start the tests
   ::testing::InitGoogleTest(&argc, argv);
 
   int rv = RUN_ALL_TESTS();
 
   delete test_utils;
   return rv;
 }
--- a/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c
+++ b/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c
@@ -89,16 +89,17 @@ static int nr_tcp_socket_ctx_create(nr_s
     if ((r=nr_ip4_port_to_transport_addr(ntohl(INADDR_ANY), 0, IPPROTO_TCP, &sock->remote_addr)))
       ABORT(r);
 
     *sockp=sock;
 
     _status=0;
 abort:
     if (_status) {
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s failed with error %d",__FILE__,__LINE__,__FUNCTION__,_status);
       nr_tcp_socket_ctx_destroy(&sock);
     }
     return(_status);
   }
 
 static int nr_tcp_socket_ctx_initialize(nr_tcp_socket_ctx *tcpsock,
   nr_transport_addr *addr, void* cb_arg)
   {
@@ -108,16 +109,18 @@ static int nr_tcp_socket_ctx_initialize(
     if ((r=nr_transport_addr_copy(&tcpsock->remote_addr, addr)))
       ABORT(r);
     if ((r=nr_socket_getfd(tcpsock->inner, &fd)))
       ABORT(r);
     NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, nr_tcp_socket_readable_cb, cb_arg);
 
     _status=0;
   abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,addr->as_string,_status);
     return(_status);
   }
 
 typedef struct nr_socket_multi_tcp_ {
   nr_ice_ctx *ctx;
   nr_socket *listen_socket;
   nr_tcp_socket_head sockets;
   nr_socket_tcp_type tcp_type;
@@ -173,24 +176,28 @@ static int nr_socket_multi_tcp_create_st
 
     TAILQ_INSERT_TAIL(&sock->sockets, tcp_socket_ctx, entry);
 
     if (stun_server->type == NR_ICE_STUN_SERVER_TYPE_ADDR) {
       nr_transport_addr stun_server_addr;
 
       nr_transport_addr_copy(&stun_server_addr, &stun_server->u.addr);
       r=nr_socket_connect(tcp_socket_ctx->inner, &stun_server_addr);
-      if (!r && r!=R_WOULDBLOCK)
+      if (r && r!=R_WOULDBLOCK) {
+        r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s connect to STUN server(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,stun_server_addr.as_string,_status);
         ABORT(r);
+      }
 
       if ((r=nr_tcp_socket_ctx_initialize(tcp_socket_ctx, &stun_server_addr, sock)))
         ABORT(r);
     }
     _status=0;
   abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,addr->as_string,_status);
     return(_status);
   }
 
 int nr_socket_multi_tcp_create(struct nr_ice_ctx_ *ctx,
     nr_transport_addr *addr, nr_socket_tcp_type tcp_type,
     int precreated_so_count, int use_framing, int max_pending,
     nr_socket **sockp)
   {
@@ -247,16 +254,17 @@ int nr_socket_multi_tcp_create(struct nr
     }
 
     if((r=nr_socket_create_int(sock, &nr_socket_multi_tcp_vtbl, sockp)))
       ABORT(r);
 
     _status=0;
   abort:
     if (_status) {
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,addr->as_string,_status);
       nr_socket_multi_tcp_destroy((void**)&sock);
     }
     return(_status);
   }
 
 int nr_socket_multi_tcp_set_readable_cb(nr_socket *sock,
   NR_async_cb readable_cb, void *readable_cb_arg)
   {
@@ -344,19 +352,24 @@ static int nr_socket_multi_tcp_get_sock_
     if ((r=nr_tcp_socket_ctx_initialize(tcp_sock_ctx, to, sock)))
       ABORT(r);
 
     *ret_sock=tcp_sock_ctx->inner;
     tcp_sock_ctx=NULL;
 
     _status=0;
   abort:
-    if (_status && tcp_sock_ctx) {
-      TAILQ_REMOVE(&sock->sockets, tcp_sock_ctx, entry);
-      nr_tcp_socket_ctx_destroy(&tcp_sock_ctx);
+    if (_status) {
+      if (tcp_sock_ctx) {
+        r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s failed with error %d, tcp_sock_ctx remote_addr: %s",__FILE__,__LINE__,__FUNCTION__,_status, tcp_sock_ctx->remote_addr.as_string);
+        TAILQ_REMOVE(&sock->sockets, tcp_sock_ctx, entry);
+        nr_tcp_socket_ctx_destroy(&tcp_sock_ctx);
+      } else {
+        r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s failed with error %d, tcp_sock_ctx=NULL",__FILE__,__LINE__,__FUNCTION__,_status);
+      }
     }
 
     return(_status);
   }
 
 int nr_socket_multi_tcp_stun_server_connect(nr_socket *sock,
   nr_transport_addr *addr)
   {
@@ -368,16 +381,18 @@ int nr_socket_multi_tcp_stun_server_conn
     if (mtcp_sock->tcp_type == TCP_TYPE_ACTIVE)
       ABORT(R_INTERNAL);
 
     if ((r=nr_socket_multi_tcp_get_sock_connected_to(mtcp_sock,addr,PREALLOC_CONNECT_NON_FRAMED,&nrsock)))
       ABORT(r);
 
     _status=0;
   abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,addr->as_string,_status);
     return(_status);
   }
 
 static int nr_socket_multi_tcp_destroy(void **objp)
   {
     nr_socket_multi_tcp *sock;
     nr_tcp_socket_ctx *tcpsock;
     NR_SOCKET fd;
@@ -422,16 +437,18 @@ static int nr_socket_multi_tcp_sendto(vo
     if ((r=nr_socket_multi_tcp_get_sock_connected_to(sock, to, PREALLOC_DONT_CONNECT_UNLESS_SO, &nrsock)))
       ABORT(r);
 
     if((r=nr_socket_sendto(nrsock, msg, len, flags, to)))
       ABORT(r);
 
     _status=0;
   abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(to:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,to->as_string,_status);
 
     return(_status);
 }
 
 static int nr_socket_multi_tcp_recvfrom(void *obj,void * restrict buf,
   size_t maxlen, size_t *len, int flags, nr_transport_addr *from)
   {
     int r, _status;
@@ -450,16 +467,17 @@ static int nr_socket_multi_tcp_recvfrom(
 
         if (!nr_socket_getfd(tcpsock->inner, &fd)) {
           NR_ASYNC_CANCEL(fd, NR_ASYNC_WAIT_READ);
           NR_ASYNC_CANCEL(fd, NR_ASYNC_WAIT_WRITE);
         }
 
         TAILQ_REMOVE(&sock->sockets, tcpsock, entry);
         nr_tcp_socket_ctx_destroy(&tcpsock);
+        r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(from:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,from->as_string,_status);
         ABORT(r);
       }
     }
 
     _status=R_WOULDBLOCK;
   abort:
 
     return(_status);
@@ -503,16 +521,18 @@ static int nr_socket_multi_tcp_connect(v
     nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)obj;
     nr_socket *nrsock;
 
     if ((r=nr_socket_multi_tcp_get_sock_connected_to(sock,addr,PREALLOC_CONNECT_FRAMED,&nrsock)))
       ABORT(r);
 
     _status=0;
 abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s(addr:%s) failed with error %d",__FILE__,__LINE__,__FUNCTION__,addr->as_string,_status);
 
     return(_status);
   }
 
 static void nr_tcp_multi_lsocket_readable_cb(NR_SOCKET s, int how, void *arg)
   {
     nr_socket_multi_tcp *sock = (nr_socket_multi_tcp *)arg;
     nr_socket *newsock;
@@ -555,11 +575,13 @@ static int nr_socket_multi_tcp_listen(vo
 
     if ((r=nr_socket_getfd(sock->listen_socket, &fd)))
       ABORT(r);
 
     NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, nr_tcp_multi_lsocket_readable_cb, sock);
 
     _status=0;
   abort:
+    if (_status)
+      r_log(LOG_ICE,LOG_DEBUG,"%s:%d function %s failed with error %d",__FILE__,__LINE__,__FUNCTION__,_status);
 
     return(_status);
   }