[Lldb-commits] [lldb] r232247 - [gtest] Fix gtest failures on Windows.
Zachary Turner
zturner at google.com
Fri Mar 13 21:19:32 PDT 2015
Author: zturner
Date: Fri Mar 13 23:19:32 2015
New Revision: 232247
URL: http://llvm.org/viewvc/llvm-project?rev=232247&view=rev
Log:
[gtest] Fix gtest failures on Windows.
On Windows, you need to call WSAStartup() before making any socket
calls, and WSACleanup() before you shutdown. This wasn't being
done, so all of the socket tests were failing. This fixes
that, which brings the unit test suite to a fully working state
on Windows.
Modified:
lldb/trunk/unittests/Host/SocketTest.cpp
Modified: lldb/trunk/unittests/Host/SocketTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/SocketTest.cpp?rev=232247&r1=232246&r2=232247&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/SocketTest.cpp (original)
+++ lldb/trunk/unittests/Host/SocketTest.cpp Fri Mar 13 23:19:32 2015
@@ -13,66 +13,79 @@
#include "lldb/Host/Socket.h"
-class SocketTest: public ::testing::Test
-{
-};
-
using namespace lldb_private;
-void AcceptThread (Socket* listen_socket,
- const char* listen_remote_address,
- bool child_processes_inherit,
- Socket** accept_socket,
- Error* error)
+class SocketTest : public testing::Test
{
- *error = listen_socket->BlockingAccept (listen_remote_address, child_processes_inherit, *accept_socket);
-}
+ public:
+ void
+ SetUp() override
+ {
+#if defined(_MSC_VER)
+ WSADATA data;
+ ::WSAStartup(MAKEWORD(2, 2), &data);
+#endif
+ }
+
+ void
+ TearDown() override
+ {
+#if defined(_MSC_VER)
+ ::WSACleanup();
+#endif
+ }
+
+ protected:
+ static void
+ AcceptThread(Socket *listen_socket, const char *listen_remote_address, bool child_processes_inherit,
+ Socket **accept_socket, Error *error)
+ {
+ *error = listen_socket->BlockingAccept(listen_remote_address, child_processes_inherit, *accept_socket);
+ }
+
+ void
+ CreateConnectedSockets(std::unique_ptr<Socket> *a_up, std::unique_ptr<Socket> *b_up)
+ {
+ Predicate<uint16_t> port_predicate;
+ // Used when binding to port zero to wait for the thread
+ // that creates the socket, binds and listens to resolve
+ // the port number.
+
+ port_predicate.SetValue(0, eBroadcastNever);
+
+ bool child_processes_inherit = false;
+ Socket *socket = nullptr;
+ const char *listen_remote_address = "localhost:0";
+ Error error = Socket::TcpListen(listen_remote_address, child_processes_inherit, socket, &port_predicate);
+ std::unique_ptr<Socket> listen_socket_up(socket);
+ socket = nullptr;
+ EXPECT_FALSE(error.Fail());
+ EXPECT_NE(nullptr, listen_socket_up.get());
+ EXPECT_TRUE(listen_socket_up->IsValid());
+
+ Error accept_error;
+ Socket *accept_socket;
+ std::thread accept_thread(AcceptThread, listen_socket_up.get(), listen_remote_address, child_processes_inherit,
+ &accept_socket, &accept_error);
+
+ char connect_remote_address[64];
+ snprintf(connect_remote_address, sizeof(connect_remote_address), "localhost:%u", port_predicate.GetValue());
+ error = Socket::TcpConnect(connect_remote_address, child_processes_inherit, socket);
+ a_up->reset(socket);
+ socket = nullptr;
+ EXPECT_TRUE(error.Success());
+ EXPECT_NE(nullptr, a_up->get());
+ EXPECT_TRUE((*a_up)->IsValid());
+
+ accept_thread.join();
+ b_up->reset(accept_socket);
+ EXPECT_TRUE(accept_error.Success());
+ EXPECT_NE(nullptr, b_up->get());
+ EXPECT_TRUE((*b_up)->IsValid());
-void CreateConnectedSockets (std::unique_ptr<Socket>* a_up, std::unique_ptr<Socket>* b_up)
-{
- Predicate<uint16_t> port_predicate;
- // Used when binding to port zero to wait for the thread
- // that creates the socket, binds and listens to resolve
- // the port number.
-
- port_predicate.SetValue (0, eBroadcastNever);
-
- bool child_processes_inherit = false;
- Socket *socket = nullptr;
- const char* listen_remote_address = "localhost:0";
- Error error = Socket::TcpListen (listen_remote_address, child_processes_inherit, socket, &port_predicate);
- std::unique_ptr<Socket> listen_socket_up (socket);
- socket = nullptr;
- EXPECT_FALSE (error.Fail ());
- EXPECT_NE (nullptr, listen_socket_up.get ());
- EXPECT_TRUE (listen_socket_up->IsValid ());
-
- Error accept_error;
- Socket* accept_socket;
- std::thread accept_thread (AcceptThread,
- listen_socket_up.get (),
- listen_remote_address,
- child_processes_inherit,
- &accept_socket,
- &accept_error);
-
- char connect_remote_address[64];
- snprintf (connect_remote_address, sizeof (connect_remote_address), "localhost:%u", port_predicate.GetValue ());
- error = Socket::TcpConnect (connect_remote_address, child_processes_inherit, socket);
- a_up->reset (socket);
- socket = nullptr;
- EXPECT_TRUE (error.Success ());
- EXPECT_NE (nullptr, a_up->get ());
- EXPECT_TRUE ((*a_up)->IsValid ());
-
- accept_thread.join ();
- b_up->reset (accept_socket);
- EXPECT_TRUE (accept_error.Success ());
- EXPECT_NE (nullptr, b_up->get ());
- EXPECT_TRUE ((*b_up)->IsValid ());
-
- listen_socket_up.reset ();
-}
+ listen_socket_up.reset();
+ }
+};
TEST_F (SocketTest, DecodeHostAndPort)
{
More information about the lldb-commits
mailing list