[Tarantool-patches] [PATCH 03/10] test: rename fake libc network methods to fakenet

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Dec 1 02:56:12 MSK 2020


SWIM unit tests contain special libraries for emulating event loop
and network: swim_test_ev and swim_test_transport. They provide
API similar to libev and to network part of libc, which internally
is implemented entirely in user-space and allows to simulate all
kinds of errors, any time durations, etc.

These test libraries are going to be re-used for Raft unit tests.
But for that it is necessary to detach them from all SWIM
dependencies.

--

The only dependency left in fake network functions is the 'swim'
prefix. This commit replaces it with 'fakenet' before they are
going to be moved to their own library.

Part of #5303
---
 test/unit/swim.c                |   4 +-
 test/unit/swim_errinj.c         |   4 +-
 test/unit/swim_test_transport.c | 234 +++++++++++++++++---------------
 test/unit/swim_test_transport.h |  30 ++--
 test/unit/swim_test_utils.c     |  18 ++-
 5 files changed, 148 insertions(+), 142 deletions(-)

diff --git a/test/unit/swim.c b/test/unit/swim.c
index 4e9dce8ce..1787745bc 100644
--- a/test/unit/swim.c
+++ b/test/unit/swim.c
@@ -1078,7 +1078,7 @@ main_f(va_list ap)
 
 	(void) ap;
 	swim_test_ev_init();
-	swim_test_transport_init();
+	fakenet_init();
 
 	swim_test_one_link();
 	swim_test_sequence();
@@ -1103,7 +1103,7 @@ main_f(va_list ap)
 	swim_test_dissemination_speed();
 	swim_test_suspect_new_members();
 
-	swim_test_transport_free();
+	fakenet_free();
 	swim_test_ev_free();
 
 	test_result = check_plan();
diff --git a/test/unit/swim_errinj.c b/test/unit/swim_errinj.c
index 0f8718a33..005be380d 100644
--- a/test/unit/swim_errinj.c
+++ b/test/unit/swim_errinj.c
@@ -217,12 +217,12 @@ main_f(va_list ap)
 
 	(void) ap;
 	swim_test_ev_init();
-	swim_test_transport_init();
+	fakenet_init();
 
 	swim_test_payload_refutation();
 	swim_test_indirect_ping();
 
-	swim_test_transport_free();
+	fakenet_free();
 	swim_test_ev_free();
 
 	test_result = check_plan();
diff --git a/test/unit/swim_test_transport.c b/test/unit/swim_test_transport.c
index 855fb2d8e..a259addc9 100644
--- a/test/unit/swim_test_transport.c
+++ b/test/unit/swim_test_transport.c
@@ -52,14 +52,14 @@ enum {
 };
 
 static inline int
-swim_test_sockaddr_in_to_fd(const struct sockaddr_in *addr)
+fakenet_sockaddr_in_to_fd(const struct sockaddr_in *addr)
 {
 	assert(addr->sin_family == AF_INET);
 	return ntohs(addr->sin_port) + FAKE_FD_BASE;
 }
 
 static inline void
-swim_test_fd_to_sockaddr_in(int fd, struct sockaddr_in *addr)
+fakenet_fd_to_sockaddr_in(int fd, struct sockaddr_in *addr)
 {
 	*addr = (struct sockaddr_in){
 		.sin_family = AF_INET,
@@ -71,7 +71,7 @@ swim_test_fd_to_sockaddr_in(int fd, struct sockaddr_in *addr)
 }
 
 /** UDP packet wrapper. It is stored in send/recv queues. */
-struct swim_test_packet {
+struct fakenet_packet {
 	/** Source address. */
 	struct sockaddr_in src;
 	/** Destination address. */
@@ -85,12 +85,11 @@ struct swim_test_packet {
 };
 
 /** Wrap @a data into a new packet. */
-static inline struct swim_test_packet *
-swim_test_packet_new(const char *data, int size, const struct sockaddr_in *src,
-		     const struct sockaddr_in *dst)
+static inline struct fakenet_packet *
+fakenet_packet_new(const char *data, int size, const struct sockaddr_in *src,
+		   const struct sockaddr_in *dst)
 {
-	struct swim_test_packet *p =
-		(struct swim_test_packet *) malloc(sizeof(*p) + size);
+	struct fakenet_packet *p = malloc(sizeof(*p) + size);
 	assert(p != NULL);
 	rlist_create(&p->in_queue);
 	p->src = *src;
@@ -102,18 +101,18 @@ swim_test_packet_new(const char *data, int size, const struct sockaddr_in *src,
 
 /** Free packet memory. */
 static inline void
-swim_test_packet_delete(struct swim_test_packet *p)
+fakenet_packet_delete(struct fakenet_packet *p)
 {
 	rlist_del_entry(p, in_queue);
 	free(p);
 }
 
 /** Fully duplicate a packet on new memory. */
-static inline struct swim_test_packet *
-swim_test_packet_dup(struct swim_test_packet *p)
+static inline struct fakenet_packet *
+fakenet_packet_dup(struct fakenet_packet *p)
 {
-	int size = sizeof(struct swim_test_packet) + p->size;
-	struct swim_test_packet *res = (struct swim_test_packet *) malloc(size);
+	int size = sizeof(struct fakenet_packet) + p->size;
+	struct fakenet_packet *res = malloc(size);
 	assert(res != NULL);
 	memcpy(res, p, size);
 	rlist_create(&res->in_queue);
@@ -126,9 +125,9 @@ swim_test_packet_dup(struct swim_test_packet *p)
  * filters in the list. If anyone wants to filter the packet out,
  * then the packet is dropped.
  */
-struct swim_fd_filter {
+struct fakenet_filter {
 	/** A function to decide whether to drop a packet. */
-	swim_test_filter_check_f check;
+	fakenet_filter_check_f check;
 	/**
 	 * Arbitrary user data. Passed to each call of @a check.
 	 */
@@ -138,10 +137,10 @@ struct swim_fd_filter {
 };
 
 /** Create a new filter. */
-static inline struct swim_fd_filter *
-swim_fd_filter_new(swim_test_filter_check_f check, void *udata)
+static inline struct fakenet_filter *
+fakenet_filter_new(fakenet_filter_check_f check, void *udata)
 {
-	struct swim_fd_filter *f = (struct swim_fd_filter *) malloc(sizeof(*f));
+	struct fakenet_filter *f = malloc(sizeof(*f));
 	assert(f != NULL);
 	f->udata = udata;
 	f->check = check;
@@ -151,14 +150,14 @@ swim_fd_filter_new(swim_test_filter_check_f check, void *udata)
 
 /** Delete @a filter and its data. */
 static inline void
-swim_fd_filter_delete(struct swim_fd_filter *filter)
+fakenet_filter_delete(struct fakenet_filter *filter)
 {
 	rlist_del_entry(filter, in_filters);
 	free(filter);
 }
 
 /** Fake file descriptor. */
-struct swim_fd {
+struct fakenet_fd {
 	/** File descriptor number visible to libev. */
 	int evfd;
 	/**
@@ -185,71 +184,70 @@ struct swim_fd {
 };
 
 /** Table of fake file descriptors. */
-static struct swim_fd swim_fd[FAKE_FD_NUMBER];
+static struct fakenet_fd fakenet_fd[FAKE_FD_NUMBER];
 /**
  * List of active file descriptors. Used to avoid fullscan of the
  * table.
  */
-static RLIST_HEAD(swim_fd_active);
+static RLIST_HEAD(fakenet_fd_active);
 
 /** Open a fake file descriptor. */
 static inline int
-swim_fd_open(struct swim_fd *fd)
+fakenet_fd_open(struct fakenet_fd *fd)
 {
 	if (fd->is_opened) {
 		errno = EADDRINUSE;
-		diag_set(SocketError, "test_socket:1", "bind");
+		diag_set(SocketError, "fake_socket:1", "bind");
 		return -1;
 	}
 	assert(rlist_empty(&fd->filters));
 	fd->is_opened = true;
-	rlist_add_tail_entry(&swim_fd_active, fd, in_active);
+	rlist_add_tail_entry(&fakenet_fd_active, fd, in_active);
 	return 0;
 }
 
 void
-swim_test_transport_remove_filter(int fd, swim_test_filter_check_f check)
+fakenet_remove_filter(int fd, fakenet_filter_check_f check)
 {
-	struct swim_fd *sfd = &swim_fd[fd - FAKE_FD_BASE];
+	struct fakenet_fd *sfd = &fakenet_fd[fd - FAKE_FD_BASE];
 	assert(sfd->is_opened);
-	struct swim_fd_filter *f;
+	struct fakenet_filter *f;
 	rlist_foreach_entry(f, &sfd->filters, in_filters) {
 		if (check == f->check) {
-			swim_fd_filter_delete(f);
+			fakenet_filter_delete(f);
 			return;
 		}
 	}
 }
 
 void
-swim_test_transport_add_filter(int fd, swim_test_filter_check_f check,
-			       void *udata)
+fakenet_add_filter(int fd, fakenet_filter_check_f check, void *udata)
 {
-	struct swim_fd *sfd = &swim_fd[fd - FAKE_FD_BASE];
+	struct fakenet_fd *sfd = &fakenet_fd[fd - FAKE_FD_BASE];
 	assert(sfd->is_opened);
-	struct swim_fd_filter *f = swim_fd_filter_new(check, udata);
-	swim_test_transport_remove_filter(fd, check);
+	struct fakenet_filter *f = fakenet_filter_new(check, udata);
+	fakenet_remove_filter(fd, check);
 	rlist_add_tail_entry(&sfd->filters, f, in_filters);
 }
 
 /** Send one packet to destination's recv queue. */
 static inline void
-swim_fd_send_packet(struct swim_fd *fd);
+fakenet_fd_send_packet(struct fakenet_fd *fd);
 
 /** Close a fake file descriptor. */
 static inline void
-swim_fd_close(struct swim_fd *fd)
+fakenet_fd_close(struct fakenet_fd *fd)
 {
 	if (! fd->is_opened)
 		return;
-	struct swim_fd_filter *f, *f_tmp;
+	struct fakenet_filter *f, *f_tmp;
 	rlist_foreach_entry_safe(f, &fd->filters, in_filters, f_tmp)
-		swim_fd_filter_delete(f);
-	struct swim_test_packet *i, *tmp;
+		fakenet_filter_delete(f);
+	struct fakenet_packet *i, *tmp;
 	rlist_foreach_entry_safe(i, &fd->recv_queue, in_queue, tmp)
-		swim_test_packet_delete(i);
+		fakenet_packet_delete(i);
 	while (! rlist_empty(&fd->send_queue))
-		swim_fd_send_packet(fd);
+		fakenet_fd_send_packet(fd);
 	rlist_del_entry(fd, in_active);
 	fd->is_opened = false;
 }
@@ -262,10 +260,10 @@ swim_fd_close(struct swim_fd *fd)
  * @a dir.
  */
 static inline bool
-swim_fd_test_if_drop(struct swim_fd *fd, const struct swim_test_packet *p,
+fakenet_test_if_drop(struct fakenet_fd *fd, const struct fakenet_packet *p,
 		     int dir, int peer_fd)
 {
-	struct swim_fd_filter *f;
+	struct fakenet_filter *f;
 	rlist_foreach_entry(f, &fd->filters, in_filters) {
 		if (f->check(p->data, p->size, f->udata, dir, peer_fd))
 			return true;
@@ -274,31 +272,30 @@ swim_fd_test_if_drop(struct swim_fd *fd, const struct swim_test_packet *p,
 }
 
 void
-swim_test_transport_init(void)
+fakenet_init(void)
 {
 	for (int i = 0, evfd = FAKE_FD_BASE; i < FAKE_FD_NUMBER; ++i, ++evfd) {
-		rlist_create(&swim_fd[i].filters);
-		swim_fd[i].evfd = evfd;
-		swim_fd[i].is_opened = false;
-		rlist_create(&swim_fd[i].in_active);
-		rlist_create(&swim_fd[i].recv_queue);
-		rlist_create(&swim_fd[i].send_queue);
+		rlist_create(&fakenet_fd[i].filters);
+		fakenet_fd[i].evfd = evfd;
+		fakenet_fd[i].is_opened = false;
+		rlist_create(&fakenet_fd[i].in_active);
+		rlist_create(&fakenet_fd[i].recv_queue);
+		rlist_create(&fakenet_fd[i].send_queue);
 	}
 }
 
 void
-swim_test_transport_free(void)
+fakenet_free(void)
 {
-	struct swim_test_packet *p, *tmp;
-	for (int i = 0; i < (int)lengthof(swim_fd); ++i)
-		swim_fd_close(&swim_fd[i]);
+	for (int i = 0; i < (int)lengthof(fakenet_fd); ++i)
+		fakenet_fd_close(&fakenet_fd[i]);
 }
 
 static void
-swim_test_close(int fd)
+fakenet_close(int fd)
 {
 	assert(fd >= FAKE_FD_BASE);
-	swim_fd_close(&swim_fd[fd - FAKE_FD_BASE]);
+	fakenet_fd_close(&fakenet_fd[fd - FAKE_FD_BASE]);
 }
 
 /**
@@ -306,8 +303,8 @@ swim_test_close(int fd)
  * it on EV_WRITE event.
  */
 static ssize_t
-swim_test_sendto(int fd, const void *data, size_t size,
-		 const struct sockaddr *addr, socklen_t addr_size)
+fakenet_sendto(int fd, const void *data, size_t size,
+	       const struct sockaddr *addr, socklen_t addr_size)
 {
 	/*
 	 * Create packet. Put into sending queue.
@@ -315,11 +312,11 @@ swim_test_sendto(int fd, const void *data, size_t size,
 	(void) addr_size;
 	assert(addr->sa_family == AF_INET);
 	struct sockaddr_in src_addr;
-	swim_test_fd_to_sockaddr_in(fd, &src_addr);
-	struct swim_test_packet *p =
-		swim_test_packet_new(data, size, &src_addr,
-				     (const struct sockaddr_in *) addr);
-	struct swim_fd *src = &swim_fd[fd - FAKE_FD_BASE];
+	fakenet_fd_to_sockaddr_in(fd, &src_addr);
+	struct fakenet_packet *p =
+		fakenet_packet_new(data, size, &src_addr,
+				   (const struct sockaddr_in *)addr);
+	struct fakenet_fd *src = &fakenet_fd[fd - FAKE_FD_BASE];
 	assert(src->is_opened);
 	rlist_add_tail_entry(&src->send_queue, p, in_queue);
 	return size;
@@ -330,40 +327,40 @@ swim_test_sendto(int fd, const void *data, size_t size,
  * processed on EV_READ event.
  */
 static ssize_t
-swim_test_recvfrom(int fd, void *buffer, size_t size, struct sockaddr *addr,
-		   socklen_t *addr_size)
+fakenet_recvfrom(int fd, void *buffer, size_t size, struct sockaddr *addr,
+		 socklen_t *addr_size)
 {
 	/*
 	 * Pop a packet from a receiving queue.
 	 */
-	struct swim_fd *dst = &swim_fd[fd - FAKE_FD_BASE];
+	struct fakenet_fd *dst = &fakenet_fd[fd - FAKE_FD_BASE];
 	assert(dst->is_opened);
-	struct swim_test_packet *p =
-		rlist_shift_entry(&dst->recv_queue, struct swim_test_packet,
+	struct fakenet_packet *p =
+		rlist_shift_entry(&dst->recv_queue, struct fakenet_packet,
 				  in_queue);
 	*(struct sockaddr_in *) addr = p->src;
 	*addr_size = sizeof(p->src);
 	ssize_t result = MIN((size_t) p->size, size);
 	memcpy(buffer, p->data, result);
-	swim_test_packet_delete(p);
+	fakenet_packet_delete(p);
 	return result;
 }
 
 static int
-swim_test_bind(int *fd, const struct sockaddr *addr, socklen_t addr_len)
+fakenet_bind(int *fd, const struct sockaddr *addr, socklen_t addr_len)
 {
 	assert(addr->sa_family == AF_INET);
 	const struct sockaddr_in *new_addr = (const struct sockaddr_in *) addr;
 	assert(addr_len >= sizeof(*new_addr));
 	(void)addr_len;
-	int new_fd = swim_test_sockaddr_in_to_fd(new_addr);
+	int new_fd = fakenet_sockaddr_in_to_fd(new_addr);
 	int old_fd = *fd;
 	if (old_fd == new_fd)
 		return 0;
-	if (swim_fd_open(&swim_fd[new_fd - FAKE_FD_BASE]) != 0)
+	if (fakenet_fd_open(&fakenet_fd[new_fd - FAKE_FD_BASE]) != 0)
 		return -1;
 	if (old_fd != -1)
-		swim_test_close(old_fd);
+		fakenet_close(old_fd);
 	*fd = new_fd;
 	return 0;
 }
@@ -373,14 +370,14 @@ swim_transport_send(struct swim_transport *transport, const void *data,
 		    size_t size, const struct sockaddr *addr,
 		    socklen_t addr_size)
 {
-	return swim_test_sendto(transport->fd, data, size, addr, addr_size);
+	return fakenet_sendto(transport->fd, data, size, addr, addr_size);
 }
 
 ssize_t
 swim_transport_recv(struct swim_transport *transport, void *buffer, size_t size,
 		    struct sockaddr *addr, socklen_t *addr_size)
 {
-	return swim_test_recvfrom(transport->fd, buffer, size, addr, addr_size);
+	return fakenet_recvfrom(transport->fd, buffer, size, addr, addr_size);
 }
 
 int
@@ -388,7 +385,7 @@ swim_transport_bind(struct swim_transport *transport,
 		    const struct sockaddr *addr, socklen_t addr_len)
 {
 	assert(addr->sa_family == AF_INET);
-	if (swim_test_bind(&transport->fd, addr, addr_len) != 0)
+	if (fakenet_bind(&transport->fd, addr, addr_len) != 0)
 		return -1;
 	transport->addr = *(struct sockaddr_in *)addr;
 	return 0;
@@ -398,7 +395,7 @@ void
 swim_transport_destroy(struct swim_transport *transport)
 {
 	if (transport->fd != -1)
-		swim_test_close(transport->fd);
+		fakenet_close(transport->fd);
 }
 
 void
@@ -409,19 +406,21 @@ swim_transport_create(struct swim_transport *transport)
 }
 
 void
-swim_test_transport_block_fd(int fd)
+fakenet_block(int fd)
 {
-	struct swim_fd *sfd = &swim_fd[fd - FAKE_FD_BASE];
-	assert(! rlist_empty(&sfd->in_active));
+	assert(fd >= FAKE_FD_BASE);
+	struct fakenet_fd *sfd = &fakenet_fd[fd - FAKE_FD_BASE];
+	assert(!rlist_empty(&sfd->in_active));
 	rlist_del_entry(sfd, in_active);
 }
 
 void
-swim_test_transport_unblock_fd(int fd)
+fakenet_unblock(int fd)
 {
-	struct swim_fd *sfd = &swim_fd[fd - FAKE_FD_BASE];
+	assert(fd >= FAKE_FD_BASE);
+	struct fakenet_fd *sfd = &fakenet_fd[fd - FAKE_FD_BASE];
 	if (sfd->is_opened && rlist_empty(&sfd->in_active))
-		rlist_add_tail_entry(&swim_fd_active, sfd, in_active);
+		rlist_add_tail_entry(&fakenet_fd_active, sfd, in_active);
 }
 
 /**
@@ -431,35 +430,35 @@ swim_test_transport_unblock_fd(int fd)
  * drop rate is not 0.
  */
 static inline void
-swim_move_packet(struct swim_fd *src, struct swim_fd *dst,
-		 struct swim_test_packet *p)
+fakenet_move_packet(struct fakenet_fd *src, struct fakenet_fd *dst,
+		    struct fakenet_packet *p)
 {
-	if (dst->is_opened && !swim_fd_test_if_drop(dst, p, 0, src->evfd) &&
-	    !swim_fd_test_if_drop(src, p, 1, dst->evfd))
+	if (dst->is_opened && !fakenet_test_if_drop(dst, p, 0, src->evfd) &&
+	    !fakenet_test_if_drop(src, p, 1, dst->evfd))
 		rlist_add_tail_entry(&dst->recv_queue, p, in_queue);
 	else
-		swim_test_packet_delete(p);
+		fakenet_packet_delete(p);
 }
 
 static inline void
-swim_fd_send_packet(struct swim_fd *fd)
+fakenet_fd_send_packet(struct fakenet_fd *fd)
 {
 	assert(! rlist_empty(&fd->send_queue));
-	struct swim_fd *dst;
-	struct swim_test_packet *dup, *p =
-		rlist_shift_entry(&fd->send_queue, struct swim_test_packet,
+	struct fakenet_fd *dst;
+	struct fakenet_packet *dup, *p =
+		rlist_shift_entry(&fd->send_queue, struct fakenet_packet,
 				  in_queue);
 	if (p->dst.sin_addr.s_addr == INADDR_BROADCAST &&
 	    p->dst.sin_port == 0) {
-		rlist_foreach_entry(dst, &swim_fd_active, in_active) {
-			dup = swim_test_packet_dup(p);
-			swim_move_packet(fd, dst, dup);
+		rlist_foreach_entry(dst, &fakenet_fd_active, in_active) {
+			dup = fakenet_packet_dup(p);
+			fakenet_move_packet(fd, dst, dup);
 		}
-		swim_test_packet_delete(p);
+		fakenet_packet_delete(p);
 	} else {
-		int fdnum = swim_test_sockaddr_in_to_fd(&p->dst);
-		dst = &swim_fd[fdnum - FAKE_FD_BASE];
-		swim_move_packet(fd, dst, p);
+		int fdnum = fakenet_sockaddr_in_to_fd(&p->dst);
+		dst = &fakenet_fd[fdnum - FAKE_FD_BASE];
+		fakenet_move_packet(fd, dst, p);
 	}
 }
 
@@ -468,30 +467,30 @@ swim_fd_send_packet(struct swim_fd *fd)
  * to send/recv.
  */
 static inline void
-swim_test_transport_feed_events(struct ev_loop *loop)
+fakenet_feed_events(struct ev_loop *loop)
 {
-	struct swim_fd *fd;
+	struct fakenet_fd *fd;
 	/*
 	 * Reversed because libev invokes events in reversed
 	 * order. So this reverse + libev reverse = normal order.
 	 */
-	rlist_foreach_entry_reverse(fd, &swim_fd_active, in_active) {
+	rlist_foreach_entry_reverse(fd, &fakenet_fd_active, in_active) {
 		if (! rlist_empty(&fd->send_queue))
-			swim_fd_send_packet(fd);
+			fakenet_fd_send_packet(fd);
 		ev_feed_fd_event(loop, fd->evfd, EV_WRITE);
 	}
-	rlist_foreach_entry_reverse(fd, &swim_fd_active, in_active) {
+	rlist_foreach_entry_reverse(fd, &fakenet_fd_active, in_active) {
 		if (!rlist_empty(&fd->recv_queue))
 			ev_feed_fd_event(loop, fd->evfd, EV_READ);
 	}
 }
 
 void
-swim_test_transport_do_loop_step(struct ev_loop *loop)
+fakenet_loop_update(struct ev_loop *loop)
 {
 	do {
 		ev_invoke_pending(loop);
-		swim_test_transport_feed_events(loop);
+		fakenet_feed_events(loop);
 		/*
 		 * Just a single loop + invoke is not enough. At
 		 * least two are necessary.
@@ -510,8 +509,8 @@ swim_test_transport_do_loop_step(struct ev_loop *loop)
 	} while (ev_pending_count(loop) > 0);
 }
 
-int
-swim_getifaddrs(struct ifaddrs **ifaddrs)
+static int
+fakenet_getifaddrs(struct ifaddrs **ifaddrs)
 {
 	/*
 	 * This is a fake implementation of getifaddrs. It always
@@ -519,8 +518,7 @@ swim_getifaddrs(struct ifaddrs **ifaddrs)
 	 * which is later used to send a packet to all the opened
 	 * descriptors. Second is a dummy interface leading to
 	 * nowhere. The latter is used just for testing that the
-	 * real SWIM code correctly iterates through the
-	 * interface list.
+	 * real code correctly iterates through the interface list.
 	 */
 	int size = (sizeof(struct ifaddrs) + sizeof(struct sockaddr_in)) * 2;
 	struct ifaddrs *iface = (struct ifaddrs *) calloc(1, size);
@@ -543,8 +541,14 @@ swim_getifaddrs(struct ifaddrs **ifaddrs)
 	return 0;
 }
 
-void
-swim_freeifaddrs(struct ifaddrs *ifaddrs)
+int
+swim_getifaddrs(struct ifaddrs **ifaddrs)
+{
+	return fakenet_getifaddrs(ifaddrs);
+}
+
+static void
+fakenet_freeifaddrs(struct ifaddrs *ifaddrs)
 {
 	/*
 	 * The whole list is packed into a single allocation
@@ -552,3 +556,9 @@ swim_freeifaddrs(struct ifaddrs *ifaddrs)
 	 */
 	free(ifaddrs);
 }
+
+void
+swim_freeifaddrs(struct ifaddrs *ifaddrs)
+{
+	fakenet_freeifaddrs(ifaddrs);
+}
diff --git a/test/unit/swim_test_transport.h b/test/unit/swim_test_transport.h
index 6235278d0..1f754de00 100644
--- a/test/unit/swim_test_transport.h
+++ b/test/unit/swim_test_transport.h
@@ -34,10 +34,9 @@
 struct ev_loop;
 
 /**
- * SWIM test_transport implements a 'fake' file descriptors table
- * in user space in order to get the full control over UDP
- * sockets, used in core SWIM code. Fake fds are used to provide a
- * capability to set necessary loss level, delay, reorders.
+ * Fakenet implements a 'fake' file descriptors table in user space in order to
+ * get the full control over UDP sockets. Fake fds are used to provide means
+ * to set necessary loss level, delay, reorders, blocks.
  */
 
 /**
@@ -49,8 +48,8 @@ struct ev_loop;
  * parameter a sender/receiver descriptor number is passed
  * depending on @a dir.
  */
-typedef bool (*swim_test_filter_check_f)(const char *data, int size,
-					 void *udata, int dir, int peer_fd);
+typedef bool (*fakenet_filter_check_f)(const char *data, int size, void *udata,
+				       int dir, int peer_fd);
 
 /**
  * Until there are no new IO events, feed EV_WRITE event to all
@@ -59,18 +58,18 @@ typedef bool (*swim_test_filter_check_f)(const char *data, int size,
  * from send to recv queues.
  */
 void
-swim_test_transport_do_loop_step(struct ev_loop *loop);
+fakenet_loop_update(struct ev_loop *loop);
 
 /**
  * Block a file descriptor so as it can not receive nor send any
  * packets.
  */
 void
-swim_test_transport_block_fd(int fd);
+fakenet_block(int fd);
 
 /** Unblock a file descriptor. */
 void
-swim_test_transport_unblock_fd(int fd);
+fakenet_unblock(int fd);
 
 /**
  * Add a filter to the file descriptor @a fd. If a filter with
@@ -83,8 +82,7 @@ swim_test_transport_unblock_fd(int fd);
  *        invocation.
  */
 void
-swim_test_transport_add_filter(int fd, swim_test_filter_check_f check,
-			       void *udata);
+fakenet_add_filter(int fd, fakenet_filter_check_f check, void *udata);
 
 /**
  * Remove a filter having @a check function. Works just like the
@@ -92,14 +90,14 @@ swim_test_transport_add_filter(int fd, swim_test_filter_check_f check,
  * is found, then it is not an error.
  */
 void
-swim_test_transport_remove_filter(int fd, swim_test_filter_check_f check);
+fakenet_remove_filter(int fd, fakenet_filter_check_f check);
 
-/** Initialize test transport system. */
+/** Initialize fake network system. */
 void
-swim_test_transport_init(void);
+fakenet_init(void);
 
-/** Destroy test transport system, free resources. */
+/** Destroy fake network system, free resources. */
 void
-swim_test_transport_free(void);
+fakenet_free(void);
 
 #endif /* TARANTOOL_SWIM_TEST_TRANSPORT_H_INCLUDED */
diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c
index 9dbd28a9f..ef35f2134 100644
--- a/test/unit/swim_test_utils.c
+++ b/test/unit/swim_test_utils.c
@@ -398,14 +398,14 @@ swim_cluster_restart_node(struct swim_cluster *cluster, int i)
 void
 swim_cluster_block_io(struct swim_cluster *cluster, int i)
 {
-	swim_test_transport_block_fd(swim_fd(cluster->node[i].swim));
+	fakenet_block(swim_fd(cluster->node[i].swim));
 }
 
 void
 swim_cluster_unblock_io(struct swim_cluster *cluster, int i)
 {
 	struct swim *s = swim_cluster_member(cluster, i);
-	swim_test_transport_unblock_fd(swim_fd(s));
+	fakenet_unblock(swim_fd(s));
 }
 
 /** Create a new drop rate filter helper. */
@@ -447,12 +447,11 @@ swim_cluster_set_drop_generic(struct swim_cluster *cluster, int i,
 	struct swim_node *n = swim_cluster_node(cluster, i);
 	int fd = swim_fd(n->swim);
 	if (value == 0) {
-		swim_test_transport_remove_filter(fd, swim_filter_drop_rate);
+		fakenet_remove_filter(fd, swim_filter_drop_rate);
 		return;
 	}
 	swim_drop_rate_create(&n->drop_rate, value, is_for_in, is_for_out);
-	swim_test_transport_add_filter(fd, swim_filter_drop_rate,
-				       &n->drop_rate);
+	fakenet_add_filter(fd, swim_filter_drop_rate, &n->drop_rate);
 }
 
 void
@@ -509,9 +508,8 @@ swim_cluster_set_drop_channel(struct swim_cluster *cluster, int from_id,
 		return;
 	}
 	swim_drop_channel_add_fd(dc, to_fd);
-	swim_test_transport_add_filter(swim_fd(from_node->swim),
-				       swim_filter_drop_channel,
-				       &from_node->drop_channel);
+	fakenet_add_filter(swim_fd(from_node->swim), swim_filter_drop_channel,
+			   &from_node->drop_channel);
 }
 
 /** Check if @a s1 knows every member of @a s2's table. */
@@ -577,7 +575,7 @@ swim_wait_timeout(double timeout, struct swim_cluster *cluster,
 	 * send immediately without preliminary timeouts or
 	 * whatsoever.
 	 */
-	swim_test_transport_do_loop_step(loop);
+	fakenet_loop_update(loop);
 	if (cluster != NULL)
 		swim_cluster_run_triggers(cluster);
 	while (! check(cluster, data)) {
@@ -589,7 +587,7 @@ swim_wait_timeout(double timeout, struct swim_cluster *cluster,
 		 * some of them generated IO events. Process them
 		 * too.
 		 */
-		swim_test_transport_do_loop_step(loop);
+		fakenet_loop_update(loop);
 		if (cluster != NULL)
 			swim_cluster_run_triggers(cluster);
 	}
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list