[Lldb-commits] [lldb] 59656c0 - [lldb] Make CommunicationTest compatible with windows
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 26 06:26:01 PDT 2022
Author: Pavel Labath
Date: 2022-08-26T15:25:46+02:00
New Revision: 59656c0492224a2da590b913959630107e0a31f4
URL: https://github.com/llvm/llvm-project/commit/59656c0492224a2da590b913959630107e0a31f4
DIFF: https://github.com/llvm/llvm-project/commit/59656c0492224a2da590b913959630107e0a31f4.diff
LOG: [lldb] Make CommunicationTest compatible with windows
Our (TCP) socket support is in a much better state than pipes. Use that
for testing the Communication class.
Move the CreateTCPConnectedSockets function
(SocketTestUtilities.{h,cpp}) to a place where it can be used from
Communication tests.
Added:
lldb/unittests/TestingSupport/Host/CMakeLists.txt
lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
Modified:
lldb/unittests/Core/CMakeLists.txt
lldb/unittests/Core/CommunicationTest.cpp
lldb/unittests/Core/FormatEntityTest.cpp
lldb/unittests/Host/CMakeLists.txt
lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
lldb/unittests/Host/SocketTest.cpp
lldb/unittests/TestingSupport/CMakeLists.txt
Removed:
lldb/unittests/Host/SocketTestUtilities.cpp
lldb/unittests/Host/SocketTestUtilities.h
################################################################################
diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt
index ea3f652203e7..bda0ac750fe8 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -21,6 +21,7 @@ add_lldb_unittest(LLDBCoreTests
lldbPluginSymbolFileSymtab
lldbSymbol
lldbUtilityHelpers
+ lldbHostHelpers
LLVMTestingSupport
LINK_COMPONENTS
Support
diff --git a/lldb/unittests/Core/CommunicationTest.cpp b/lldb/unittests/Core/CommunicationTest.cpp
index 13ebfae772f4..5cb1d4a3bbbf 100644
--- a/lldb/unittests/Core/CommunicationTest.cpp
+++ b/lldb/unittests/Core/CommunicationTest.cpp
@@ -12,6 +12,8 @@
#include "lldb/Host/Pipe.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
+#include "TestingSupport/Host/SocketTestUtilities.h"
+#include "TestingSupport/SubsystemRAII.h"
#include <thread>
@@ -21,30 +23,31 @@
using namespace lldb_private;
-#ifndef _WIN32
+class CommunicationTest : public testing::Test {
+private:
+ SubsystemRAII<Socket> m_subsystems;
+};
+
static void CommunicationReadTest(bool use_read_thread) {
- Pipe pipe;
- ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(),
- llvm::Succeeded());
+ std::unique_ptr<TCPSocket> a, b;
+ ASSERT_TRUE(CreateTCPConnectedSockets("localhost", &a, &b));
- Status error;
- size_t bytes_written;
- ASSERT_THAT_ERROR(pipe.Write("test", 4, bytes_written).ToError(),
- llvm::Succeeded());
- ASSERT_EQ(bytes_written, 4U);
+ size_t num_bytes = 4;
+ ASSERT_THAT_ERROR(a->Write("test", num_bytes).ToError(), llvm::Succeeded());
+ ASSERT_EQ(num_bytes, 4U);
Communication comm("test");
- comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(
- pipe.ReleaseReadFileDescriptor(), /*owns_fd=*/true));
+ comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(b.release()));
comm.SetCloseOnEOF(true);
- if (use_read_thread)
+ if (use_read_thread) {
ASSERT_TRUE(comm.StartReadThread());
+ }
// This read should wait for the data to become available and return it.
lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
char buf[16];
- error.Clear();
+ Status error;
EXPECT_EQ(
comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, &error), 4U);
EXPECT_EQ(status, lldb::eConnectionStatusSuccess);
@@ -68,7 +71,7 @@ static void CommunicationReadTest(bool use_read_thread) {
EXPECT_THAT_ERROR(error.ToError(), llvm::Failed());
// This read should return EOF.
- pipe.CloseWriteFileDescriptor();
+ ASSERT_THAT_ERROR(a->Close().ToError(), llvm::Succeeded());
error.Clear();
EXPECT_EQ(
comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, &error), 0U);
@@ -80,37 +83,33 @@ static void CommunicationReadTest(bool use_read_thread) {
EXPECT_TRUE(comm.JoinReadThread());
}
-TEST(CommunicationTest, Read) {
+TEST_F(CommunicationTest, Read) {
CommunicationReadTest(/*use_thread=*/false);
}
-TEST(CommunicationTest, ReadThread) {
+TEST_F(CommunicationTest, ReadThread) {
CommunicationReadTest(/*use_thread=*/true);
}
-TEST(CommunicationTest, SynchronizeWhileClosing) {
- // Set up a communication object reading from a pipe.
- Pipe pipe;
- ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(),
- llvm::Succeeded());
+TEST_F(CommunicationTest, SynchronizeWhileClosing) {
+ std::unique_ptr<TCPSocket> a, b;
+ ASSERT_TRUE(CreateTCPConnectedSockets("localhost", &a, &b));
Communication comm("test");
- comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(
- pipe.ReleaseReadFileDescriptor(), /*owns_fd=*/true));
+ comm.SetConnection(std::make_unique<ConnectionFileDescriptor>(b.release()));
comm.SetCloseOnEOF(true);
ASSERT_TRUE(comm.StartReadThread());
// Ensure that we can safely synchronize with the read thread while it is
// closing the read end (in response to us closing the write end).
- pipe.CloseWriteFileDescriptor();
+ ASSERT_THAT_ERROR(a->Close().ToError(), llvm::Succeeded());
comm.SynchronizeWithReadThread();
ASSERT_TRUE(comm.StopReadThread());
}
-#endif
#if LLDB_ENABLE_POSIX
-TEST(CommunicationTest, WriteAll) {
+TEST_F(CommunicationTest, WriteAll) {
Pipe pipe;
ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(),
llvm::Succeeded());
diff --git a/lldb/unittests/Core/FormatEntityTest.cpp b/lldb/unittests/Core/FormatEntityTest.cpp
index c22dd4399573..0a68c9340b77 100644
--- a/lldb/unittests/Core/FormatEntityTest.cpp
+++ b/lldb/unittests/Core/FormatEntityTest.cpp
@@ -20,7 +20,7 @@ using Entry = FormatEntity::Entry;
TEST(FormatEntityTest, DefinitionConstructionNameAndType) {
Definition d("foo", FormatEntity::Entry::Type::Invalid);
- EXPECT_EQ(d.name, "foo");
+ EXPECT_STREQ(d.name, "foo");
EXPECT_EQ(d.string, nullptr);
EXPECT_EQ(d.type, FormatEntity::Entry::Type::Invalid);
EXPECT_EQ(d.data, 0UL);
@@ -32,8 +32,8 @@ TEST(FormatEntityTest, DefinitionConstructionNameAndType) {
TEST(FormatEntityTest, DefinitionConstructionNameAndString) {
Definition d("foo", "string");
- EXPECT_EQ(d.name, "foo");
- EXPECT_EQ(d.string, "string");
+ EXPECT_STREQ(d.name, "foo");
+ EXPECT_STREQ(d.string, "string");
EXPECT_EQ(d.type, FormatEntity::Entry::Type::EscapeCode);
EXPECT_EQ(d.data, 0UL);
EXPECT_EQ(d.num_children, 0UL);
@@ -44,7 +44,7 @@ TEST(FormatEntityTest, DefinitionConstructionNameAndString) {
TEST(FormatEntityTest, DefinitionConstructionNameTypeData) {
Definition d("foo", FormatEntity::Entry::Type::Invalid, 33);
- EXPECT_EQ(d.name, "foo");
+ EXPECT_STREQ(d.name, "foo");
EXPECT_EQ(d.string, nullptr);
EXPECT_EQ(d.type, FormatEntity::Entry::Type::Invalid);
EXPECT_EQ(d.data, 33UL);
@@ -56,14 +56,14 @@ TEST(FormatEntityTest, DefinitionConstructionNameTypeData) {
TEST(FormatEntityTest, DefinitionConstructionNameTypeChildren) {
Definition d("foo", FormatEntity::Entry::Type::Invalid, 33);
Definition parent("parent", FormatEntity::Entry::Type::Invalid, 1, &d);
- EXPECT_EQ(parent.name, "parent");
- EXPECT_EQ(parent.string, nullptr);
+ EXPECT_STREQ(parent.name, "parent");
+ EXPECT_STREQ(parent.string, nullptr);
EXPECT_EQ(parent.type, FormatEntity::Entry::Type::Invalid);
EXPECT_EQ(parent.num_children, 1UL);
EXPECT_EQ(parent.children, &d);
EXPECT_FALSE(parent.keep_separator);
- EXPECT_EQ(parent.children[0].name, "foo");
+ EXPECT_STREQ(parent.children[0].name, "foo");
EXPECT_EQ(parent.children[0].string, nullptr);
EXPECT_EQ(parent.children[0].type, FormatEntity::Entry::Type::Invalid);
EXPECT_EQ(parent.children[0].data, 33UL);
diff --git a/lldb/unittests/Host/CMakeLists.txt b/lldb/unittests/Host/CMakeLists.txt
index bf14bf16e4e3..23a6aae721e7 100644
--- a/lldb/unittests/Host/CMakeLists.txt
+++ b/lldb/unittests/Host/CMakeLists.txt
@@ -11,7 +11,6 @@ set (FILES
ProcessLaunchInfoTest.cpp
SocketAddressTest.cpp
SocketTest.cpp
- SocketTestUtilities.cpp
ThreadLauncherTest.cpp
XMLTest.cpp
)
@@ -34,5 +33,6 @@ add_lldb_unittest(HostTests
LINK_LIBS
lldbHost
lldbUtilityHelpers
+ lldbHostHelpers
LLVMTestingSupport
)
diff --git a/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp b/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
index 0c99d14dd628..82cd49fdb067 100644
--- a/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
+++ b/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
@@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "SocketTestUtilities.h"
+#include "TestingSupport/Host/SocketTestUtilities.h"
#include "gtest/gtest.h"
-
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
#include "lldb/Utility/UriParser.h"
diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp
index 6af0b3c92b3b..a209600141ff 100644
--- a/lldb/unittests/Host/SocketTest.cpp
+++ b/lldb/unittests/Host/SocketTest.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "SocketTestUtilities.h"
+#include "TestingSupport/Host/SocketTestUtilities.h"
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/Host/Config.h"
#include "lldb/Utility/UriParser.h"
diff --git a/lldb/unittests/TestingSupport/CMakeLists.txt b/lldb/unittests/TestingSupport/CMakeLists.txt
index 4dc77e491202..df0a37005358 100644
--- a/lldb/unittests/TestingSupport/CMakeLists.txt
+++ b/lldb/unittests/TestingSupport/CMakeLists.txt
@@ -12,4 +12,5 @@ add_lldb_library(lldbUtilityHelpers
ObjectYAML
)
+add_subdirectory(Host)
add_subdirectory(Symbol)
diff --git a/lldb/unittests/TestingSupport/Host/CMakeLists.txt b/lldb/unittests/TestingSupport/Host/CMakeLists.txt
new file mode 100644
index 000000000000..e81d6a988ee4
--- /dev/null
+++ b/lldb/unittests/TestingSupport/Host/CMakeLists.txt
@@ -0,0 +1,9 @@
+set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
+add_lldb_library(lldbHostHelpers
+ SocketTestUtilities.cpp
+
+ LINK_LIBS
+ lldbHost
+ LLVMTestingSupport
+ llvm_gtest
+ )
diff --git a/lldb/unittests/Host/SocketTestUtilities.cpp b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
similarity index 98%
rename from lldb/unittests/Host/SocketTestUtilities.cpp
rename to lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
index a37a2cd4ddf0..4ab65aa6208c 100644
--- a/lldb/unittests/Host/SocketTestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "SocketTestUtilities.h"
+#include "TestingSupport/Host/SocketTestUtilities.h"
#include "lldb/Host/Config.h"
#include "lldb/Utility/StreamString.h"
diff --git a/lldb/unittests/Host/SocketTestUtilities.h b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
similarity index 92%
rename from lldb/unittests/Host/SocketTestUtilities.h
rename to lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
index 943d98a96be0..2130cc33dd5b 100644
--- a/lldb/unittests/Host/SocketTestUtilities.h
+++ b/lldb/unittests/TestingSupport/Host/SocketTestUtilities.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLDB_UNITTESTS_HOST_SOCKETTESTUTILITIES_H
-#define LLDB_UNITTESTS_HOST_SOCKETTESTUTILITIES_H
+#ifndef LLDB_UNITTESTS_TESTINGSUPPORT_HOST_SOCKETTESTUTILITIES_H
+#define LLDB_UNITTESTS_TESTINGSUPPORT_HOST_SOCKETTESTUTILITIES_H
#include <cstdio>
#include <functional>
More information about the lldb-commits
mailing list