diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-02-15 13:11:03 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-02-15 13:11:03 +0100 |
commit | a3e2b3e40467e44ff068c5893bd6ccd3a695db61 (patch) | |
tree | 2e5c868f2af73fb37693f337c90ae5f9a81095db | |
parent | 3b6b9435c5692eb56838867e184e59dbe4f6b5c0 (diff) | |
download | minetest-a3e2b3e40467e44ff068c5893bd6ccd3a695db61.tar.gz minetest-a3e2b3e40467e44ff068c5893bd6ccd3a695db61.tar.bz2 minetest-a3e2b3e40467e44ff068c5893bd6ccd3a695db61.zip |
Fix unit test if there isn't a localhost address (for example FreeBSD jails)
-rw-r--r-- | src/test.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/test.cpp b/src/test.cpp index 5d6fdd2d8..ed92ad43a 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1669,9 +1669,24 @@ struct TestSocket: public TestBase void Run() { const int port = 30003; - Address address(0,0,0,0, port); + Address address(0, 0, 0, 0, port); + Address bind_addr(0, 0, 0, 0, port); Address address6((IPv6AddressBytes*) NULL, port); + /* + * Try to use the bind_address for servers with no localhost address + * For example: FreeBSD jails + */ + std::string bind_str = g_settings->get("bind_address"); + try { + bind_addr.Resolve(bind_str.c_str()); + + if (!bind_addr.isIPv6()) { + address = bind_addr; + } + } catch (ResolveError &e) { + } + // IPv6 socket test if (g_settings->getBool("enable_ipv6")) { UDPSocket socket6; @@ -1709,7 +1724,7 @@ struct TestSocket: public TestBase UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr, Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0); } - catch (SendFailedException e) { + catch (SendFailedException &e) { errorstream << "IPv6 support enabled but not available!" << std::endl; } @@ -1722,7 +1737,15 @@ struct TestSocket: public TestBase socket.Bind(address); const char sendbuffer[] = "hello world!"; - socket.Send(Address(127, 0, 0 ,1, port), sendbuffer, sizeof(sendbuffer)); + /* + * If there is a bind address, use it. + * It's useful in container environments + */ + if (address != Address(0, 0, 0, 0, port)) { + socket.Send(address, sendbuffer, sizeof(sendbuffer)); + } + else + socket.Send(Address(127, 0, 0 ,1, port), sendbuffer, sizeof(sendbuffer)); sleep_ms(50); @@ -1734,8 +1757,15 @@ struct TestSocket: public TestBase } //FIXME: This fails on some systems UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0); - UASSERT(sender.getAddress().sin_addr.s_addr == - Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr); + + if (address != Address(0, 0, 0, 0, port)) { + UASSERT(sender.getAddress().sin_addr.s_addr == + address.getAddress().sin_addr.s_addr); + } + else { + UASSERT(sender.getAddress().sin_addr.s_addr == + Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr); + } } } }; |