Index: uspace/srv/net/tcp/Makefile
===================================================================
--- uspace/srv/net/tcp/Makefile	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/Makefile	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -57,4 +57,5 @@
 TEST_SOURCES = \
 	$(SOURCES_COMMON) \
+	test/conn.c \
 	test/iqueue.c \
 	test/main.c \
Index: uspace/srv/net/tcp/conn.c
===================================================================
--- uspace/srv/net/tcp/conn.c	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/conn.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -59,8 +59,11 @@
 #define TIME_WAIT_TIMEOUT	(2*MAX_SEGMENT_LIFETIME)
 
+/** List of all allocated connections */
 static LIST_INITIALIZE(conn_list);
 /** Taken after tcp_conn_t lock */
 static FIBRIL_MUTEX_INITIALIZE(conn_list_lock);
+/** Connection association map */
 static amap_t *amap;
+static FIBRIL_MUTEX_INITIALIZE(amap_lock);
 
 static void tcp_conn_seg_process(tcp_conn_t *, tcp_segment_t *);
@@ -85,4 +88,13 @@
 
 	return EOK;
+}
+
+/** Finalize connections. */
+void tcp_conns_fini(void)
+{
+	amap_destroy(amap);
+	amap = NULL;
+
+	assert(list_empty(&conn_list));
 }
 
@@ -156,4 +168,8 @@
 	if (epp != NULL)
 		conn->ident = *epp;
+
+	fibril_mutex_lock(&conn_list_lock);
+	list_append(&conn->link, &conn_list);
+	fibril_mutex_unlock(&conn_list_lock);
 
 	return conn;
@@ -192,4 +208,8 @@
 	tcp_tqueue_fini(&conn->retransmit);
 
+	fibril_mutex_lock(&conn_list_lock);
+	list_remove(&conn->link);
+	fibril_mutex_unlock(&conn_list_lock);
+
 	if (conn->rcv_buf != NULL)
 		free(conn->rcv_buf);
@@ -263,4 +283,5 @@
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_delete(%p)", conn->name, conn);
 
+	assert(conn->mapped == false);
 	assert(conn->deleted == false);
 	conn->deleted = true;
@@ -280,5 +301,5 @@
 
 	tcp_conn_addref(conn);
-	fibril_mutex_lock(&conn_list_lock);
+	fibril_mutex_lock(&amap_lock);
 
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_add: conn=%p", conn);
@@ -287,11 +308,11 @@
 	if (rc != EOK) {
 		tcp_conn_delref(conn);
-		fibril_mutex_unlock(&conn_list_lock);
+		fibril_mutex_unlock(&amap_lock);
 		return rc;
 	}
 
 	conn->ident = aepp;
-	list_append(&conn->link, &conn_list);
-	fibril_mutex_unlock(&conn_list_lock);
+	conn->mapped = true;
+	fibril_mutex_unlock(&amap_lock);
 
 	return EOK;
@@ -304,11 +325,11 @@
 void tcp_conn_remove(tcp_conn_t *conn)
 {
-	if (!link_used(&conn->link))
-		return;
-
-	fibril_mutex_lock(&conn_list_lock);
+	if (!conn->mapped)
+		return;
+
+	fibril_mutex_lock(&amap_lock);
 	amap_remove(amap, &conn->ident);
-	list_remove(&conn->link);
-	fibril_mutex_unlock(&conn_list_lock);
+	conn->mapped = false;
+	fibril_mutex_unlock(&amap_lock);
 	tcp_conn_delref(conn);
 }
@@ -400,10 +421,10 @@
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", epp);
 
-	fibril_mutex_lock(&conn_list_lock);
+	fibril_mutex_lock(&amap_lock);
 
 	rc = amap_find_match(amap, epp, &arg);
 	if (rc != EOK) {
 		assert(rc == ENOENT);
-		fibril_mutex_unlock(&conn_list_lock);
+		fibril_mutex_unlock(&amap_lock);
 		return NULL;
 	}
@@ -412,5 +433,5 @@
 	tcp_conn_addref(conn);
 
-	fibril_mutex_unlock(&conn_list_lock);
+	fibril_mutex_unlock(&amap_lock);
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref: got conn=%p",
 	    conn);
@@ -424,4 +445,6 @@
 void tcp_conn_reset(tcp_conn_t *conn)
 {
+	assert(fibril_mutex_is_locked(&conn->lock));
+
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_conn_reset()", conn->name);
 	conn->reset = true;
@@ -1223,5 +1246,5 @@
 
 		/* Need to remove and re-insert connection with new identity */
-		fibril_mutex_lock(&conn_list_lock);
+		fibril_mutex_lock(&amap_lock);
 
 		if (inet_addr_is_any(&conn->ident.remote.addr))
@@ -1239,5 +1262,5 @@
 			assert(rc == ENOMEM);
 			log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
-			fibril_mutex_unlock(&conn_list_lock);
+			fibril_mutex_unlock(&amap_lock);
 			tcp_conn_unlock(conn);
 			return;
@@ -1245,5 +1268,5 @@
 
 		amap_remove(amap, &oldepp);
-		fibril_mutex_unlock(&conn_list_lock);
+		fibril_mutex_unlock(&amap_lock);
 
 		conn->name = (char *) "a";
Index: uspace/srv/net/tcp/conn.h
===================================================================
--- uspace/srv/net/tcp/conn.h	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/conn.h	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -41,4 +41,5 @@
 
 extern int tcp_conns_init(void);
+extern void tcp_conns_fini(void);
 extern tcp_conn_t *tcp_conn_new(inet_ep2_t *);
 extern void tcp_conn_delete(tcp_conn_t *);
Index: uspace/srv/net/tcp/tcp_type.h
===================================================================
--- uspace/srv/net/tcp/tcp_type.h	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/tcp_type.h	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -239,4 +239,6 @@
 	/** Connection identification (local and remote endpoint) */
 	inet_ep2_t ident;
+	/** Connection is in association map */
+	bool mapped;
 
 	/** Active or passive connection */
@@ -369,5 +371,5 @@
 /** TCP client */
 typedef struct tcp_client {
-	/** Client callbac session */
+	/** Client callback session */
 	async_sess_t *sess;
 	/** Client's connections */
Index: uspace/srv/net/tcp/test/conn.c
===================================================================
--- uspace/srv/net/tcp/test/conn.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
+++ uspace/srv/net/tcp/test/conn.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <inet/endpoint.h>
+#include <io/log.h>
+#include <pcut/pcut.h>
+
+#include "../conn.h"
+
+PCUT_INIT
+
+PCUT_TEST_SUITE(conn);
+
+PCUT_TEST_BEFORE
+{
+	int rc;
+
+	/* We will be calling functions that perform logging */
+	rc = log_init("test-tcp");
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+
+	rc = tcp_conns_init();
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+}
+
+PCUT_TEST_AFTER
+{
+	tcp_conns_fini();
+}
+
+/** Test creating and deleting connection */
+PCUT_TEST(new_delete)
+{
+	tcp_conn_t *conn;
+	inet_ep2_t epp;
+
+	inet_ep2_init(&epp);
+	conn = tcp_conn_new(&epp);
+	PCUT_ASSERT_NOT_NULL(conn);
+
+	tcp_conn_lock(conn);
+	tcp_conn_reset(conn);
+	tcp_conn_unlock(conn);
+	tcp_conn_delete(conn);
+}
+
+/** Test adding, finding and removing a connection */
+PCUT_TEST(add_find_remove)
+{
+	tcp_conn_t *conn, *cfound;
+	inet_ep2_t epp;
+	int rc;
+
+	inet_ep2_init(&epp);
+
+	conn = tcp_conn_new(&epp);
+	PCUT_ASSERT_NOT_NULL(conn);
+
+	rc = tcp_conn_add(conn);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+
+	/* Find the connection */
+	cfound = tcp_conn_find_ref(&conn->ident);
+	PCUT_ASSERT_EQUALS(conn, cfound);
+	tcp_conn_delref(cfound);
+
+	/* We should have been assigned a port address, should not match */
+	cfound = tcp_conn_find_ref(&epp);
+	PCUT_ASSERT_EQUALS(NULL, cfound);
+
+	tcp_conn_lock(conn);
+	tcp_conn_reset(conn);
+	tcp_conn_unlock(conn);
+	tcp_conn_delete(conn);
+}
+
+PCUT_EXPORT(conn);
Index: uspace/srv/net/tcp/test/iqueue.c
===================================================================
--- uspace/srv/net/tcp/test/iqueue.c	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/test/iqueue.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -56,5 +56,5 @@
 	tcp_iqueue_init(&iqueue, conn);
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(ENOENT, rc);
+	PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
 
 	tcp_conn_delete(conn);
@@ -89,15 +89,15 @@
 	tcp_iqueue_init(&iqueue, conn);
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(ENOENT, rc);
+	PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
 
 	seg->seq = 10;
 	tcp_iqueue_insert_seg(&iqueue, seg);
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 
 	seg->seq = 15;
 	tcp_iqueue_insert_seg(&iqueue, seg);
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(ENOENT, rc);
+	PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
 	tcp_iqueue_remove_seg(&iqueue, seg);
 
@@ -137,5 +137,5 @@
 	tcp_iqueue_init(&iqueue, conn);
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(ENOENT, rc);
+	PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
 
 	/* Test reception in ascending order */
@@ -146,9 +146,9 @@
 
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 	PCUT_ASSERT_TRUE(rseg == seg1);
 
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 	PCUT_ASSERT_TRUE(rseg == seg2);
 
@@ -160,13 +160,13 @@
 
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
-	PCUT_ASSERT_TRUE(rseg == seg2);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	PCUT_ASSERT_EQUALS(seg2, rseg);
 
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
-	PCUT_ASSERT_TRUE(rseg == seg1);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	PCUT_ASSERT_EQUALS(seg1, rseg);
 
 	rc = tcp_iqueue_get_ready_seg(&iqueue, &rseg);
-	PCUT_ASSERT_INT_EQUALS(ENOENT, rc);
+	PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
 
 	tcp_segment_delete(seg1);
Index: uspace/srv/net/tcp/test/main.c
===================================================================
--- uspace/srv/net/tcp/test/main.c	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/test/main.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -57,4 +57,5 @@
 PCUT_INIT
 
+PCUT_IMPORT(conn);
 PCUT_IMPORT(iqueue);
 PCUT_IMPORT(pdu);
Index: uspace/srv/net/tcp/test/pdu.c
===================================================================
--- uspace/srv/net/tcp/test/pdu.c	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/test/pdu.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -62,7 +62,7 @@
 
 	rc = tcp_pdu_encode(&epp, seg, &pdu);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 	rc = tcp_pdu_decode(pdu, &depp, &dseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 
 	test_seg_same(seg, dseg);
@@ -100,7 +100,7 @@
 
 	rc = tcp_pdu_encode(&epp, seg, &pdu);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 	rc = tcp_pdu_decode(pdu, &depp, &dseg);
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 
 	test_seg_same(seg, dseg);
Index: uspace/srv/net/tcp/test/tqueue.c
===================================================================
--- uspace/srv/net/tcp/test/tqueue.c	(revision 975d528567e7c0e0be4d004eed670b95ea360ac1)
+++ uspace/srv/net/tcp/test/tqueue.c	(revision 9713b0b213e041e8599c2108c67fa8c0a95be59c)
@@ -57,6 +57,15 @@
 	/* We will be calling functions that perform logging */
 	rc = log_init("test-tcp");
-	PCUT_ASSERT_INT_EQUALS(EOK, rc);
-}
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+
+	rc = tcp_conns_init();
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+}
+
+PCUT_TEST_AFTER
+{
+	tcp_conns_fini();
+}
+
 
 /** Test  */
@@ -75,4 +84,7 @@
 	seg_cnt = 0;
 
+	tcp_conn_lock(conn);
+	tcp_conn_reset(conn);
+	tcp_conn_unlock(conn);
 	tcp_conn_delete(conn);
 	PCUT_ASSERT_EQUALS(0, seg_cnt);
