diff options
Diffstat (limited to 'gnu/llvm/lldb/unittests/Host')
17 files changed, 0 insertions, 1453 deletions
diff --git a/gnu/llvm/lldb/unittests/Host/CMakeLists.txt b/gnu/llvm/lldb/unittests/Host/CMakeLists.txt deleted file mode 100644 index b88aa97a900..00000000000 --- a/gnu/llvm/lldb/unittests/Host/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set (FILES - ConnectionFileDescriptorTest.cpp - FileActionTest.cpp - FileSystemTest.cpp - FileTest.cpp - HostInfoTest.cpp - HostTest.cpp - MainLoopTest.cpp - NativeProcessProtocolTest.cpp - ProcessLaunchInfoTest.cpp - SocketAddressTest.cpp - SocketTest.cpp - SocketTestUtilities.cpp - TaskPoolTest.cpp -) - -if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android") - list(APPEND FILES - linux/HostTest.cpp - linux/SupportTest.cpp - ) -endif() - -add_lldb_unittest(HostTests - ${FILES} - LINK_LIBS - lldbHost - lldbUtilityHelpers - LLVMTestingSupport - ) diff --git a/gnu/llvm/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp b/gnu/llvm/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp deleted file mode 100644 index a5930f29702..00000000000 --- a/gnu/llvm/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===-- ConnectionFileDescriptorTest.cpp ------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "SocketTestUtilities.h" -#include "gtest/gtest.h" - -#include "TestingSupport/SubsystemRAII.h" -#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" -#include "lldb/Utility/UriParser.h" - -using namespace lldb_private; - -class ConnectionFileDescriptorTest : public testing::Test { -public: - SubsystemRAII<Socket> subsystems; - - void TestGetURI(std::string ip) { - std::unique_ptr<TCPSocket> socket_a_up; - std::unique_ptr<TCPSocket> socket_b_up; - if (!IsAddressFamilySupported(ip)) { - GTEST_LOG_(WARNING) << "Skipping test due to missing IPv" - << (IsIPv4(ip) ? "4" : "6") << " support."; - return; - } - CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up); - auto socket = socket_a_up.release(); - ConnectionFileDescriptor connection_file_descriptor(socket); - - llvm::StringRef scheme; - llvm::StringRef hostname; - int port; - llvm::StringRef path; - std::string uri(connection_file_descriptor.GetURI()); - EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path)); - EXPECT_EQ(ip, hostname); - EXPECT_EQ(socket->GetRemotePortNumber(), port); - } -}; - -TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) { TestGetURI("127.0.0.1"); } - -TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) { TestGetURI("::1"); } diff --git a/gnu/llvm/lldb/unittests/Host/FileActionTest.cpp b/gnu/llvm/lldb/unittests/Host/FileActionTest.cpp deleted file mode 100644 index ee1c0a39755..00000000000 --- a/gnu/llvm/lldb/unittests/Host/FileActionTest.cpp +++ /dev/null @@ -1,19 +0,0 @@ -//===-- FileActionTest.cpp --------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/FileAction.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -TEST(FileActionTest, Open) { - FileAction Action; - Action.Open(47, FileSpec("/tmp"), /*read*/ true, /*write*/ false); - EXPECT_EQ(Action.GetAction(), FileAction::eFileActionOpen); - EXPECT_EQ(Action.GetFileSpec(), FileSpec("/tmp")); -} diff --git a/gnu/llvm/lldb/unittests/Host/FileSystemTest.cpp b/gnu/llvm/lldb/unittests/Host/FileSystemTest.cpp deleted file mode 100644 index 31184d9ad53..00000000000 --- a/gnu/llvm/lldb/unittests/Host/FileSystemTest.cpp +++ /dev/null @@ -1,305 +0,0 @@ -//===-- FileSystemTest.cpp --------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include "lldb/Host/FileSystem.h" -#include "llvm/Support/Errc.h" - -extern const char *TestMainArgv0; - -using namespace lldb_private; -using namespace llvm; -using llvm::sys::fs::UniqueID; - -// Modified from llvm/unittests/Support/VirtualFileSystemTest.cpp -namespace { -struct DummyFile : public vfs::File { - vfs::Status S; - explicit DummyFile(vfs::Status S) : S(S) {} - llvm::ErrorOr<vfs::Status> status() override { return S; } - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> - getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator, - bool IsVolatile) override { - llvm_unreachable("unimplemented"); - } - std::error_code close() override { return std::error_code(); } -}; - -class DummyFileSystem : public vfs::FileSystem { - int FSID; // used to produce UniqueIDs - int FileID; // used to produce UniqueIDs - std::string cwd; - std::map<std::string, vfs::Status> FilesAndDirs; - - static int getNextFSID() { - static int Count = 0; - return Count++; - } - -public: - DummyFileSystem() : FSID(getNextFSID()), FileID(0) {} - - ErrorOr<vfs::Status> status(const Twine &Path) override { - std::map<std::string, vfs::Status>::iterator I = - FilesAndDirs.find(Path.str()); - if (I == FilesAndDirs.end()) - return make_error_code(llvm::errc::no_such_file_or_directory); - return I->second; - } - ErrorOr<std::unique_ptr<vfs::File>> - openFileForRead(const Twine &Path) override { - auto S = status(Path); - if (S) - return std::unique_ptr<vfs::File>(new DummyFile{*S}); - return S.getError(); - } - llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override { - return cwd; - } - std::error_code setCurrentWorkingDirectory(const Twine &Path) override { - cwd = Path.str(); - return std::error_code(); - } - // Map any symlink to "/symlink". - std::error_code getRealPath(const Twine &Path, - SmallVectorImpl<char> &Output) const override { - auto I = FilesAndDirs.find(Path.str()); - if (I == FilesAndDirs.end()) - return make_error_code(llvm::errc::no_such_file_or_directory); - if (I->second.isSymlink()) { - Output.clear(); - Twine("/symlink").toVector(Output); - return std::error_code(); - } - Output.clear(); - Path.toVector(Output); - return std::error_code(); - } - - struct DirIterImpl : public llvm::vfs::detail::DirIterImpl { - std::map<std::string, vfs::Status> &FilesAndDirs; - std::map<std::string, vfs::Status>::iterator I; - std::string Path; - bool isInPath(StringRef S) { - if (Path.size() < S.size() && S.find(Path) == 0) { - auto LastSep = S.find_last_of('/'); - if (LastSep == Path.size() || LastSep == Path.size() - 1) - return true; - } - return false; - } - DirIterImpl(std::map<std::string, vfs::Status> &FilesAndDirs, - const Twine &_Path) - : FilesAndDirs(FilesAndDirs), I(FilesAndDirs.begin()), - Path(_Path.str()) { - for (; I != FilesAndDirs.end(); ++I) { - if (isInPath(I->first)) { - CurrentEntry = - vfs::directory_entry(I->second.getName(), I->second.getType()); - break; - } - } - } - std::error_code increment() override { - ++I; - for (; I != FilesAndDirs.end(); ++I) { - if (isInPath(I->first)) { - CurrentEntry = - vfs::directory_entry(I->second.getName(), I->second.getType()); - break; - } - } - if (I == FilesAndDirs.end()) - CurrentEntry = vfs::directory_entry(); - return std::error_code(); - } - }; - - vfs::directory_iterator dir_begin(const Twine &Dir, - std::error_code &EC) override { - return vfs::directory_iterator( - std::make_shared<DirIterImpl>(FilesAndDirs, Dir)); - } - - void addEntry(StringRef Path, const vfs::Status &Status) { - FilesAndDirs[Path] = Status; - } - - void addRegularFile(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) { - vfs::Status S(Path, UniqueID(FSID, FileID++), - std::chrono::system_clock::now(), 0, 0, 1024, - sys::fs::file_type::regular_file, Perms); - addEntry(Path, S); - } - - void addDirectory(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) { - vfs::Status S(Path, UniqueID(FSID, FileID++), - std::chrono::system_clock::now(), 0, 0, 0, - sys::fs::file_type::directory_file, Perms); - addEntry(Path, S); - } - - void addSymlink(StringRef Path) { - vfs::Status S(Path, UniqueID(FSID, FileID++), - std::chrono::system_clock::now(), 0, 0, 0, - sys::fs::file_type::symlink_file, sys::fs::all_all); - addEntry(Path, S); - } -}; -} // namespace - -TEST(FileSystemTest, FileAndDirectoryComponents) { - using namespace std::chrono; - FileSystem fs; - -#ifdef _WIN32 - FileSpec fs1("C:\\FILE\\THAT\\DOES\\NOT\\EXIST.TXT"); -#else - FileSpec fs1("/file/that/does/not/exist.txt"); -#endif - FileSpec fs2(TestMainArgv0); - - fs.Resolve(fs2); - - EXPECT_EQ(system_clock::time_point(), fs.GetModificationTime(fs1)); - EXPECT_LT(system_clock::time_point() + hours(24 * 365 * 20), - fs.GetModificationTime(fs2)); -} - -static IntrusiveRefCntPtr<DummyFileSystem> GetSimpleDummyFS() { - IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem()); - D->addRegularFile("/foo"); - D->addDirectory("/bar"); - D->addSymlink("/baz"); - D->addRegularFile("/qux", ~sys::fs::perms::all_read); - D->setCurrentWorkingDirectory("/"); - return D; -} - -TEST(FileSystemTest, Exists) { - FileSystem fs(GetSimpleDummyFS()); - - EXPECT_TRUE(fs.Exists("/foo")); - EXPECT_TRUE(fs.Exists(FileSpec("/foo", FileSpec::Style::posix))); -} - -TEST(FileSystemTest, Readable) { - FileSystem fs(GetSimpleDummyFS()); - - EXPECT_TRUE(fs.Readable("/foo")); - EXPECT_TRUE(fs.Readable(FileSpec("/foo", FileSpec::Style::posix))); - - EXPECT_FALSE(fs.Readable("/qux")); - EXPECT_FALSE(fs.Readable(FileSpec("/qux", FileSpec::Style::posix))); -} - -TEST(FileSystemTest, GetByteSize) { - FileSystem fs(GetSimpleDummyFS()); - - EXPECT_EQ((uint64_t)1024, fs.GetByteSize("/foo")); - EXPECT_EQ((uint64_t)1024, - fs.GetByteSize(FileSpec("/foo", FileSpec::Style::posix))); -} - -TEST(FileSystemTest, GetPermissions) { - FileSystem fs(GetSimpleDummyFS()); - - EXPECT_EQ(sys::fs::all_all, fs.GetPermissions("/foo")); - EXPECT_EQ(sys::fs::all_all, - fs.GetPermissions(FileSpec("/foo", FileSpec::Style::posix))); -} - -TEST(FileSystemTest, MakeAbsolute) { - FileSystem fs(GetSimpleDummyFS()); - - { - StringRef foo_relative = "foo"; - SmallString<16> foo(foo_relative); - auto EC = fs.MakeAbsolute(foo); - EXPECT_FALSE(EC); - EXPECT_TRUE(foo.equals("/foo")); - } - - { - FileSpec file_spec("foo"); - auto EC = fs.MakeAbsolute(file_spec); - EXPECT_FALSE(EC); - EXPECT_EQ(FileSpec("/foo"), file_spec); - } -} - -TEST(FileSystemTest, Resolve) { - FileSystem fs(GetSimpleDummyFS()); - - { - StringRef foo_relative = "foo"; - SmallString<16> foo(foo_relative); - fs.Resolve(foo); - EXPECT_TRUE(foo.equals("/foo")); - } - - { - FileSpec file_spec("foo"); - fs.Resolve(file_spec); - EXPECT_EQ(FileSpec("/foo"), file_spec); - } - - { - StringRef foo_relative = "bogus"; - SmallString<16> foo(foo_relative); - fs.Resolve(foo); - EXPECT_TRUE(foo.equals("bogus")); - } - - { - FileSpec file_spec("bogus"); - fs.Resolve(file_spec); - EXPECT_EQ(FileSpec("bogus"), file_spec); - } -} - -FileSystem::EnumerateDirectoryResult -VFSCallback(void *baton, llvm::sys::fs::file_type file_type, - llvm::StringRef path) { - auto visited = static_cast<std::vector<std::string> *>(baton); - visited->push_back(path.str()); - return FileSystem::eEnumerateDirectoryResultNext; -} - -TEST(FileSystemTest, EnumerateDirectory) { - FileSystem fs(GetSimpleDummyFS()); - - std::vector<std::string> visited; - - constexpr bool find_directories = true; - constexpr bool find_files = true; - constexpr bool find_other = true; - - fs.EnumerateDirectory("/", find_directories, find_files, find_other, - VFSCallback, &visited); - - EXPECT_THAT(visited, - testing::UnorderedElementsAre("/foo", "/bar", "/baz", "/qux")); -} - -TEST(FileSystemTest, OpenErrno) { -#ifdef _WIN32 - FileSpec spec("C:\\FILE\\THAT\\DOES\\NOT\\EXIST.TXT"); -#else - FileSpec spec("/file/that/does/not/exist.txt"); -#endif - FileSystem fs; - auto file = fs.Open(spec, File::eOpenOptionRead, 0, true); - ASSERT_FALSE(file); - std::error_code code = errorToErrorCode(file.takeError()); - EXPECT_EQ(code.category(), std::system_category()); - EXPECT_EQ(code.value(), ENOENT); -} - diff --git a/gnu/llvm/lldb/unittests/Host/FileTest.cpp b/gnu/llvm/lldb/unittests/Host/FileTest.cpp deleted file mode 100644 index 6a0434327f3..00000000000 --- a/gnu/llvm/lldb/unittests/Host/FileTest.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===-- FileTest.cpp --------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/File.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/FileUtilities.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/Program.h" -#include "gtest/gtest.h" - -using namespace lldb; -using namespace lldb_private; - -TEST(File, GetWaitableHandleFileno) { - const auto *Info = testing::UnitTest::GetInstance()->current_test_info(); - - llvm::SmallString<128> name; - int fd; - llvm::sys::fs::createTemporaryFile(llvm::Twine(Info->test_case_name()) + "-" + - Info->name(), - "test", fd, name); - llvm::FileRemover remover(name); - ASSERT_GE(fd, 0); - - FILE *stream = fdopen(fd, "r"); - ASSERT_TRUE(stream); - - NativeFile file(stream, true); - EXPECT_EQ(file.GetWaitableHandle(), fd); -} - -TEST(File, GetStreamFromDescriptor) { - const auto *Info = testing::UnitTest::GetInstance()->current_test_info(); - llvm::SmallString<128> name; - int fd; - llvm::sys::fs::createTemporaryFile(llvm::Twine(Info->test_case_name()) + "-" + - Info->name(), - "test", fd, name); - - llvm::FileRemover remover(name); - ASSERT_GE(fd, 0); - - NativeFile file(fd, File::eOpenOptionWrite, true); - ASSERT_TRUE(file.IsValid()); - - FILE *stream = file.GetStream(); - ASSERT_TRUE(stream != NULL); - - EXPECT_EQ(file.GetDescriptor(), fd); - EXPECT_EQ(file.GetWaitableHandle(), fd); -} diff --git a/gnu/llvm/lldb/unittests/Host/HostInfoTest.cpp b/gnu/llvm/lldb/unittests/Host/HostInfoTest.cpp deleted file mode 100644 index c332606a4da..00000000000 --- a/gnu/llvm/lldb/unittests/Host/HostInfoTest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===-- HostInfoTest.cpp ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/HostInfo.h" -#include "TestingSupport/SubsystemRAII.h" -#include "TestingSupport/TestUtilities.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/lldb-defines.h" -#include "gtest/gtest.h" - -using namespace lldb_private; -using namespace llvm; - -namespace { -class HostInfoTest : public ::testing::Test { - SubsystemRAII<FileSystem, HostInfo> subsystems; -}; -} // namespace - -TEST_F(HostInfoTest, GetAugmentedArchSpec) { - // Fully specified triple should not be changed. - ArchSpec spec = HostInfo::GetAugmentedArchSpec("x86_64-pc-linux-gnu"); - EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc-linux-gnu"); - - // Same goes if we specify at least one of (os, vendor, env). - spec = HostInfo::GetAugmentedArchSpec("x86_64-pc"); - EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc"); - - // But if we specify only an arch, we should fill in the rest from the host. - spec = HostInfo::GetAugmentedArchSpec("x86_64"); - Triple triple(sys::getDefaultTargetTriple()); - EXPECT_EQ(spec.GetTriple().getArch(), Triple::x86_64); - EXPECT_EQ(spec.GetTriple().getOS(), triple.getOS()); - EXPECT_EQ(spec.GetTriple().getVendor(), triple.getVendor()); - EXPECT_EQ(spec.GetTriple().getEnvironment(), triple.getEnvironment()); - - // Test LLDB_ARCH_DEFAULT - EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(), - HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple()); -} - -TEST_F(HostInfoTest, GetHostname) { - // Check non-empty string input works correctly. - std::string s("abc"); - EXPECT_TRUE(HostInfo::GetHostname(s)); -} diff --git a/gnu/llvm/lldb/unittests/Host/HostTest.cpp b/gnu/llvm/lldb/unittests/Host/HostTest.cpp deleted file mode 100644 index ac149d81283..00000000000 --- a/gnu/llvm/lldb/unittests/Host/HostTest.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===-- HostTest.cpp --------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/Host.h" -#include "gtest/gtest.h" - -using namespace lldb_private; -using namespace llvm; - -TEST(Host, WaitStatusFormat) { - EXPECT_EQ("W01", formatv("{0:g}", WaitStatus{WaitStatus::Exit, 1}).str()); - EXPECT_EQ("X02", formatv("{0:g}", WaitStatus{WaitStatus::Signal, 2}).str()); - EXPECT_EQ("S03", formatv("{0:g}", WaitStatus{WaitStatus::Stop, 3}).str()); - EXPECT_EQ("Exited with status 4", - formatv("{0}", WaitStatus{WaitStatus::Exit, 4}).str()); -} - -TEST(Host, GetEnvironment) { - putenv(const_cast<char *>("LLDB_TEST_ENVIRONMENT_VAR=Host::GetEnvironment")); - ASSERT_EQ("Host::GetEnvironment", - Host::GetEnvironment().lookup("LLDB_TEST_ENVIRONMENT_VAR")); -} diff --git a/gnu/llvm/lldb/unittests/Host/MainLoopTest.cpp b/gnu/llvm/lldb/unittests/Host/MainLoopTest.cpp deleted file mode 100644 index da509b940a1..00000000000 --- a/gnu/llvm/lldb/unittests/Host/MainLoopTest.cpp +++ /dev/null @@ -1,155 +0,0 @@ -//===-- MainLoopTest.cpp ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/MainLoop.h" -#include "TestingSupport/SubsystemRAII.h" -#include "lldb/Host/ConnectionFileDescriptor.h" -#include "lldb/Host/PseudoTerminal.h" -#include "lldb/Host/common/TCPSocket.h" -#include "llvm/Testing/Support/Error.h" -#include "gtest/gtest.h" -#include <future> - -using namespace lldb_private; - -namespace { -class MainLoopTest : public testing::Test { -public: - SubsystemRAII<Socket> subsystems; - - void SetUp() override { - bool child_processes_inherit = false; - Status error; - std::unique_ptr<TCPSocket> listen_socket_up( - new TCPSocket(true, child_processes_inherit)); - ASSERT_TRUE(error.Success()); - error = listen_socket_up->Listen("localhost:0", 5); - ASSERT_TRUE(error.Success()); - - Socket *accept_socket; - std::future<Status> accept_error = std::async(std::launch::async, [&] { - return listen_socket_up->Accept(accept_socket); - }); - - std::unique_ptr<TCPSocket> connect_socket_up( - new TCPSocket(true, child_processes_inherit)); - error = connect_socket_up->Connect( - llvm::formatv("localhost:{0}", listen_socket_up->GetLocalPortNumber()) - .str()); - ASSERT_TRUE(error.Success()); - ASSERT_TRUE(accept_error.get().Success()); - - callback_count = 0; - socketpair[0] = std::move(connect_socket_up); - socketpair[1].reset(accept_socket); - } - - void TearDown() override { - socketpair[0].reset(); - socketpair[1].reset(); - } - -protected: - MainLoop::Callback make_callback() { - return [&](MainLoopBase &loop) { - ++callback_count; - loop.RequestTermination(); - }; - } - std::shared_ptr<Socket> socketpair[2]; - unsigned callback_count; -}; -} // namespace - -TEST_F(MainLoopTest, ReadObject) { - char X = 'X'; - size_t len = sizeof(X); - ASSERT_TRUE(socketpair[0]->Write(&X, len).Success()); - - MainLoop loop; - - Status error; - auto handle = loop.RegisterReadObject(socketpair[1], make_callback(), error); - ASSERT_TRUE(error.Success()); - ASSERT_TRUE(handle); - ASSERT_TRUE(loop.Run().Success()); - ASSERT_EQ(1u, callback_count); -} - -TEST_F(MainLoopTest, TerminatesImmediately) { - char X = 'X'; - size_t len = sizeof(X); - ASSERT_TRUE(socketpair[0]->Write(&X, len).Success()); - ASSERT_TRUE(socketpair[1]->Write(&X, len).Success()); - - MainLoop loop; - Status error; - auto handle0 = loop.RegisterReadObject(socketpair[0], make_callback(), error); - ASSERT_TRUE(error.Success()); - auto handle1 = loop.RegisterReadObject(socketpair[1], make_callback(), error); - ASSERT_TRUE(error.Success()); - - ASSERT_TRUE(loop.Run().Success()); - ASSERT_EQ(1u, callback_count); -} - -#ifdef LLVM_ON_UNIX -TEST_F(MainLoopTest, DetectsEOF) { - - PseudoTerminal term; - ASSERT_TRUE(term.OpenFirstAvailableMaster(O_RDWR, nullptr, 0)); - ASSERT_TRUE(term.OpenSlave(O_RDWR | O_NOCTTY, nullptr, 0)); - auto conn = std::make_unique<ConnectionFileDescriptor>( - term.ReleaseMasterFileDescriptor(), true); - - Status error; - MainLoop loop; - auto handle = - loop.RegisterReadObject(conn->GetReadObject(), make_callback(), error); - ASSERT_TRUE(error.Success()); - term.CloseSlaveFileDescriptor(); - - ASSERT_TRUE(loop.Run().Success()); - ASSERT_EQ(1u, callback_count); -} - -TEST_F(MainLoopTest, Signal) { - MainLoop loop; - Status error; - - auto handle = loop.RegisterSignal(SIGUSR1, make_callback(), error); - ASSERT_TRUE(error.Success()); - kill(getpid(), SIGUSR1); - ASSERT_TRUE(loop.Run().Success()); - ASSERT_EQ(1u, callback_count); -} - -// Test that a signal which is not monitored by the MainLoop does not -// cause a premature exit. -TEST_F(MainLoopTest, UnmonitoredSignal) { - MainLoop loop; - Status error; - struct sigaction sa; - sa.sa_sigaction = [](int, siginfo_t *, void *) { }; - sa.sa_flags = SA_SIGINFO; // important: no SA_RESTART - sigemptyset(&sa.sa_mask); - ASSERT_EQ(0, sigaction(SIGUSR2, &sa, nullptr)); - - auto handle = loop.RegisterSignal(SIGUSR1, make_callback(), error); - ASSERT_TRUE(error.Success()); - std::thread killer([]() { - sleep(1); - kill(getpid(), SIGUSR2); - sleep(1); - kill(getpid(), SIGUSR1); - }); - ASSERT_TRUE(loop.Run().Success()); - killer.join(); - ASSERT_EQ(1u, callback_count); -} -#endif diff --git a/gnu/llvm/lldb/unittests/Host/NativeProcessProtocolTest.cpp b/gnu/llvm/lldb/unittests/Host/NativeProcessProtocolTest.cpp deleted file mode 100644 index c5516b1b1d3..00000000000 --- a/gnu/llvm/lldb/unittests/Host/NativeProcessProtocolTest.cpp +++ /dev/null @@ -1,149 +0,0 @@ -//===-- NativeProcessProtocolTest.cpp ---------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "TestingSupport/Host/NativeProcessTestUtils.h" - -#include "lldb/Host/common/NativeProcessProtocol.h" -#include "llvm/Support/Process.h" -#include "llvm/Testing/Support/Error.h" -#include "gmock/gmock.h" - -using namespace lldb_private; -using namespace lldb; -using namespace testing; - -TEST(NativeProcessProtocolTest, SetBreakpoint) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("x86_64-pc-linux")); - auto Trap = cantFail(Process.GetSoftwareBreakpointTrapOpcode(1)); - InSequence S; - EXPECT_CALL(Process, ReadMemory(0x47, 1)) - .WillOnce(Return(ByMove(std::vector<uint8_t>{0xbb}))); - EXPECT_CALL(Process, WriteMemory(0x47, Trap)).WillOnce(Return(ByMove(1))); - EXPECT_CALL(Process, ReadMemory(0x47, 1)).WillOnce(Return(ByMove(Trap))); - EXPECT_THAT_ERROR(Process.SetBreakpoint(0x47, 0, false).ToError(), - llvm::Succeeded()); -} - -TEST(NativeProcessProtocolTest, SetBreakpointFailRead) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("x86_64-pc-linux")); - EXPECT_CALL(Process, ReadMemory(0x47, 1)) - .WillOnce(Return(ByMove( - llvm::createStringError(llvm::inconvertibleErrorCode(), "Foo")))); - EXPECT_THAT_ERROR(Process.SetBreakpoint(0x47, 0, false).ToError(), - llvm::Failed()); -} - -TEST(NativeProcessProtocolTest, SetBreakpointFailWrite) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("x86_64-pc-linux")); - auto Trap = cantFail(Process.GetSoftwareBreakpointTrapOpcode(1)); - InSequence S; - EXPECT_CALL(Process, ReadMemory(0x47, 1)) - .WillOnce(Return(ByMove(std::vector<uint8_t>{0xbb}))); - EXPECT_CALL(Process, WriteMemory(0x47, Trap)) - .WillOnce(Return(ByMove( - llvm::createStringError(llvm::inconvertibleErrorCode(), "Foo")))); - EXPECT_THAT_ERROR(Process.SetBreakpoint(0x47, 0, false).ToError(), - llvm::Failed()); -} - -TEST(NativeProcessProtocolTest, SetBreakpointFailVerify) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("x86_64-pc-linux")); - auto Trap = cantFail(Process.GetSoftwareBreakpointTrapOpcode(1)); - InSequence S; - EXPECT_CALL(Process, ReadMemory(0x47, 1)) - .WillOnce(Return(ByMove(std::vector<uint8_t>{0xbb}))); - EXPECT_CALL(Process, WriteMemory(0x47, Trap)).WillOnce(Return(ByMove(1))); - EXPECT_CALL(Process, ReadMemory(0x47, 1)) - .WillOnce(Return(ByMove( - llvm::createStringError(llvm::inconvertibleErrorCode(), "Foo")))); - EXPECT_THAT_ERROR(Process.SetBreakpoint(0x47, 0, false).ToError(), - llvm::Failed()); -} - -TEST(NativeProcessProtocolTest, ReadMemoryWithoutTrap) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("aarch64-pc-linux")); - FakeMemory M{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}; - EXPECT_CALL(Process, ReadMemory(_, _)) - .WillRepeatedly(Invoke(&M, &FakeMemory::Read)); - EXPECT_CALL(Process, WriteMemory(_, _)) - .WillRepeatedly(Invoke(&M, &FakeMemory::Write)); - - EXPECT_THAT_ERROR(Process.SetBreakpoint(0x4, 0, false).ToError(), - llvm::Succeeded()); - EXPECT_THAT_EXPECTED( - Process.ReadMemoryWithoutTrap(0, 10), - llvm::HasValue(std::vector<uint8_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); - EXPECT_THAT_EXPECTED(Process.ReadMemoryWithoutTrap(0, 6), - llvm::HasValue(std::vector<uint8_t>{0, 1, 2, 3, 4, 5})); - EXPECT_THAT_EXPECTED(Process.ReadMemoryWithoutTrap(6, 4), - llvm::HasValue(std::vector<uint8_t>{6, 7, 8, 9})); - EXPECT_THAT_EXPECTED(Process.ReadMemoryWithoutTrap(6, 2), - llvm::HasValue(std::vector<uint8_t>{6, 7})); - EXPECT_THAT_EXPECTED(Process.ReadMemoryWithoutTrap(4, 2), - llvm::HasValue(std::vector<uint8_t>{4, 5})); -} - -TEST(NativeProcessProtocolTest, ReadCStringFromMemory) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("aarch64-pc-linux")); - FakeMemory M({'h', 'e', 'l', 'l', 'o', 0, 'w', 'o'}); - EXPECT_CALL(Process, ReadMemory(_, _)) - .WillRepeatedly(Invoke(&M, &FakeMemory::Read)); - - char string[1024]; - size_t bytes_read; - EXPECT_THAT_EXPECTED(Process.ReadCStringFromMemory( - 0x0, &string[0], sizeof(string), bytes_read), - llvm::HasValue(llvm::StringRef("hello"))); - EXPECT_EQ(bytes_read, 6UL); -} - -TEST(NativeProcessProtocolTest, ReadCStringFromMemory_MaxSize) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("aarch64-pc-linux")); - FakeMemory M({'h', 'e', 'l', 'l', 'o', 0, 'w', 'o'}); - EXPECT_CALL(Process, ReadMemory(_, _)) - .WillRepeatedly(Invoke(&M, &FakeMemory::Read)); - - char string[4]; - size_t bytes_read; - EXPECT_THAT_EXPECTED(Process.ReadCStringFromMemory( - 0x0, &string[0], sizeof(string), bytes_read), - llvm::HasValue(llvm::StringRef("hel"))); - EXPECT_EQ(bytes_read, 3UL); -} - -TEST(NativeProcessProtocolTest, ReadCStringFromMemory_CrossPageBoundary) { - NiceMock<MockDelegate> DummyDelegate; - MockProcess<NativeProcessProtocol> Process(DummyDelegate, - ArchSpec("aarch64-pc-linux")); - unsigned string_start = llvm::sys::Process::getPageSizeEstimate() - 3; - FakeMemory M({'h', 'e', 'l', 'l', 'o', 0, 'w', 'o'}, string_start); - EXPECT_CALL(Process, ReadMemory(_, _)) - .WillRepeatedly(Invoke(&M, &FakeMemory::Read)); - - char string[1024]; - size_t bytes_read; - EXPECT_THAT_EXPECTED(Process.ReadCStringFromMemory(string_start, &string[0], - sizeof(string), - bytes_read), - llvm::HasValue(llvm::StringRef("hello"))); - EXPECT_EQ(bytes_read, 6UL); -}
\ No newline at end of file diff --git a/gnu/llvm/lldb/unittests/Host/PipeTest.cpp b/gnu/llvm/lldb/unittests/Host/PipeTest.cpp deleted file mode 100644 index 35a44ccf037..00000000000 --- a/gnu/llvm/lldb/unittests/Host/PipeTest.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===-- PipeTest.cpp ------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/Pipe.h" -#include "TestingSupport/SubsystemRAII.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -class PipeTest : public testing::Test { -public: - SubsystemRAII<FileSystem, HostInfo> subsystems; -}; - -TEST_F(PipeTest, CreateWithUniqueName) { - Pipe pipe; - llvm::SmallString<0> name; - ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-CreateWithUniqueName", - /*child_process_inherit=*/false, - name) - .ToError(), - llvm::Succeeded()); -} - -// Test broken -#ifndef _WIN32 -TEST_F(PipeTest, OpenAsReader) { - Pipe pipe; - llvm::SmallString<0> name; - ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-OpenAsReader", - /*child_process_inherit=*/false, - name) - .ToError(), - llvm::Succeeded()); - - // Ensure name is not null-terminated - size_t name_len = name.size(); - name += "foobar"; - llvm::StringRef name_ref(name.data(), name_len); - ASSERT_THAT_ERROR( - pipe.OpenAsReader(name_ref, /*child_process_inherit=*/false).ToError(), - llvm::Succeeded()); -} -#endif diff --git a/gnu/llvm/lldb/unittests/Host/ProcessLaunchInfoTest.cpp b/gnu/llvm/lldb/unittests/Host/ProcessLaunchInfoTest.cpp deleted file mode 100644 index 40b45c559f0..00000000000 --- a/gnu/llvm/lldb/unittests/Host/ProcessLaunchInfoTest.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===-- ProcessLaunchInfoTest.cpp -------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/ProcessLaunchInfo.h" -#include "gtest/gtest.h" - -using namespace lldb_private; -using namespace lldb; - -TEST(ProcessLaunchInfoTest, Constructor) { - ProcessLaunchInfo Info(FileSpec("/stdin"), FileSpec("/stdout"), - FileSpec("/stderr"), FileSpec("/wd"), - eLaunchFlagStopAtEntry); - EXPECT_EQ(FileSpec("/stdin"), - Info.GetFileActionForFD(STDIN_FILENO)->GetFileSpec()); - EXPECT_EQ(FileSpec("/stdout"), - Info.GetFileActionForFD(STDOUT_FILENO)->GetFileSpec()); - EXPECT_EQ(FileSpec("/stderr"), - Info.GetFileActionForFD(STDERR_FILENO)->GetFileSpec()); - EXPECT_EQ(FileSpec("/wd"), Info.GetWorkingDirectory()); - EXPECT_EQ(eLaunchFlagStopAtEntry, Info.GetFlags().Get()); -} diff --git a/gnu/llvm/lldb/unittests/Host/SocketAddressTest.cpp b/gnu/llvm/lldb/unittests/Host/SocketAddressTest.cpp deleted file mode 100644 index 8abf9c3376e..00000000000 --- a/gnu/llvm/lldb/unittests/Host/SocketAddressTest.cpp +++ /dev/null @@ -1,83 +0,0 @@ -//===-- SocketAddressTest.cpp -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/SocketAddress.h" -#include "TestingSupport/SubsystemRAII.h" -#include "lldb/Host/Socket.h" -#include "llvm/Testing/Support/Error.h" - -#include "gtest/gtest.h" - -using namespace lldb_private; - -namespace { -class SocketAddressTest : public testing::Test { -public: - SubsystemRAII<Socket> subsystems; -}; -} // namespace - -TEST_F(SocketAddressTest, Set) { - SocketAddress sa; - ASSERT_TRUE(sa.SetToLocalhost(AF_INET, 1138)); - ASSERT_STREQ("127.0.0.1", sa.GetIPAddress().c_str()); - ASSERT_EQ(1138, sa.GetPort()); - - ASSERT_TRUE(sa.SetToAnyAddress(AF_INET, 0)); - ASSERT_STREQ("0.0.0.0", sa.GetIPAddress().c_str()); - ASSERT_EQ(0, sa.GetPort()); - - ASSERT_TRUE(sa.SetToLocalhost(AF_INET6, 1139)); - ASSERT_TRUE(sa.GetIPAddress() == "::1" || - sa.GetIPAddress() == "0:0:0:0:0:0:0:1") - << "Address was: " << sa.GetIPAddress(); - ASSERT_EQ(1139, sa.GetPort()); -} - -TEST_F(SocketAddressTest, GetAddressInfo) { - auto addr = SocketAddress::GetAddressInfo("127.0.0.1", nullptr, AF_UNSPEC, - SOCK_STREAM, IPPROTO_TCP); - ASSERT_EQ(1u, addr.size()); - EXPECT_EQ(AF_INET, addr[0].GetFamily()); - EXPECT_EQ("127.0.0.1", addr[0].GetIPAddress()); -} - -#ifdef _WIN32 - -// we need to test our inet_ntop implementation for Windows XP -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); - -TEST_F(SocketAddressTest, inet_ntop) { - const uint8_t address4[4] = {255, 0, 1, 100}; - const uint8_t address6[16] = {0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 255, 0}; - - char buffer[INET6_ADDRSTRLEN]; - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ("1:203:405:607:809:a0b:c0d:ff00", - inet_ntop(AF_INET6, address6, buffer, sizeof(buffer))); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ("1:203:405:607:809:a0b:c0d:ff00", - inet_ntop(AF_INET6, address6, buffer, 31)); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ(nullptr, inet_ntop(AF_INET6, address6, buffer, 0)); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ(nullptr, inet_ntop(AF_INET6, address6, buffer, 30)); - - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ("255.0.1.100", - inet_ntop(AF_INET, address4, buffer, sizeof(buffer))); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ("255.0.1.100", inet_ntop(AF_INET, address4, buffer, 12)); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ(nullptr, inet_ntop(AF_INET, address4, buffer, 0)); - memset(buffer, 'x', sizeof(buffer)); - EXPECT_STREQ(nullptr, inet_ntop(AF_INET, address4, buffer, 11)); -} - -#endif diff --git a/gnu/llvm/lldb/unittests/Host/SocketTest.cpp b/gnu/llvm/lldb/unittests/Host/SocketTest.cpp deleted file mode 100644 index d4e8917bf94..00000000000 --- a/gnu/llvm/lldb/unittests/Host/SocketTest.cpp +++ /dev/null @@ -1,217 +0,0 @@ -//===-- SocketTest.cpp ------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "SocketTestUtilities.h" -#include "TestingSupport/SubsystemRAII.h" -#include "lldb/Host/Config.h" -#include "lldb/Utility/UriParser.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -class SocketTest : public testing::Test { -public: - SubsystemRAII<Socket> subsystems; -}; - -TEST_F(SocketTest, DecodeHostAndPort) { - std::string host_str; - std::string port_str; - int32_t port; - Status error; - EXPECT_TRUE(Socket::DecodeHostAndPort("localhost:1138", host_str, port_str, - port, &error)); - EXPECT_STREQ("localhost", host_str.c_str()); - EXPECT_STREQ("1138", port_str.c_str()); - EXPECT_EQ(1138, port); - EXPECT_TRUE(error.Success()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:65536'", - error.AsCString()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:-1138", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:-1138'", - error.AsCString()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:65536'", - error.AsCString()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("12345", host_str, port_str, port, &error)); - EXPECT_STREQ("", host_str.c_str()); - EXPECT_STREQ("12345", port_str.c_str()); - EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("*:0", host_str, port_str, port, &error)); - EXPECT_STREQ("*", host_str.c_str()); - EXPECT_STREQ("0", port_str.c_str()); - EXPECT_EQ(0, port); - EXPECT_TRUE(error.Success()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("*:65535", host_str, port_str, port, &error)); - EXPECT_STREQ("*", host_str.c_str()); - EXPECT_STREQ("65535", port_str.c_str()); - EXPECT_EQ(65535, port); - EXPECT_TRUE(error.Success()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("[::1]:12345", host_str, port_str, port, &error)); - EXPECT_STREQ("::1", host_str.c_str()); - EXPECT_STREQ("12345", port_str.c_str()); - EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("[abcd:12fg:AF58::1]:12345", host_str, port_str, port, &error)); - EXPECT_STREQ("abcd:12fg:AF58::1", host_str.c_str()); - EXPECT_STREQ("12345", port_str.c_str()); - EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); -} - -#if LLDB_ENABLE_POSIX -TEST_F(SocketTest, DomainListenConnectAccept) { - llvm::SmallString<64> Path; - std::error_code EC = llvm::sys::fs::createUniqueDirectory("DomainListenConnectAccept", Path); - ASSERT_FALSE(EC); - llvm::sys::path::append(Path, "test"); - - // Skip the test if the $TMPDIR is too long to hold a domain socket. - if (Path.size() > 107u) - return; - - std::unique_ptr<DomainSocket> socket_a_up; - std::unique_ptr<DomainSocket> socket_b_up; - CreateDomainConnectedSockets(Path, &socket_a_up, &socket_b_up); -} -#endif - -TEST_F(SocketTest, TCPListen0ConnectAccept) { - std::unique_ptr<TCPSocket> socket_a_up; - std::unique_ptr<TCPSocket> socket_b_up; - CreateTCPConnectedSockets("127.0.0.1", &socket_a_up, &socket_b_up); -} - -TEST_F(SocketTest, TCPGetAddress) { - std::unique_ptr<TCPSocket> socket_a_up; - std::unique_ptr<TCPSocket> socket_b_up; - if (!IsAddressFamilySupported("127.0.0.1")) { - GTEST_LOG_(WARNING) << "Skipping test due to missing IPv4 support."; - return; - } - CreateTCPConnectedSockets("127.0.0.1", &socket_a_up, &socket_b_up); - - EXPECT_EQ(socket_a_up->GetLocalPortNumber(), - socket_b_up->GetRemotePortNumber()); - EXPECT_EQ(socket_b_up->GetLocalPortNumber(), - socket_a_up->GetRemotePortNumber()); - EXPECT_NE(socket_a_up->GetLocalPortNumber(), - socket_b_up->GetLocalPortNumber()); - EXPECT_STREQ("127.0.0.1", socket_a_up->GetRemoteIPAddress().c_str()); - EXPECT_STREQ("127.0.0.1", socket_b_up->GetRemoteIPAddress().c_str()); -} - -TEST_F(SocketTest, UDPConnect) { - Socket *socket; - - bool child_processes_inherit = false; - auto error = UDPSocket::Connect("127.0.0.1:0", child_processes_inherit, - socket); - - std::unique_ptr<Socket> socket_up(socket); - - EXPECT_TRUE(error.Success()); - EXPECT_TRUE(socket_up->IsValid()); -} - -TEST_F(SocketTest, TCPListen0GetPort) { - Socket *server_socket; - Predicate<uint16_t> port_predicate; - port_predicate.SetValue(0, eBroadcastNever); - Status err = - Socket::TcpListen("10.10.12.3:0", false, server_socket, &port_predicate); - std::unique_ptr<TCPSocket> socket_up((TCPSocket*)server_socket); - EXPECT_TRUE(socket_up->IsValid()); - EXPECT_NE(socket_up->GetLocalPortNumber(), 0); -} - -TEST_F(SocketTest, TCPGetConnectURI) { - std::unique_ptr<TCPSocket> socket_a_up; - std::unique_ptr<TCPSocket> socket_b_up; - if (!IsAddressFamilySupported("127.0.0.1")) { - GTEST_LOG_(WARNING) << "Skipping test due to missing IPv4 support."; - return; - } - CreateTCPConnectedSockets("127.0.0.1", &socket_a_up, &socket_b_up); - - llvm::StringRef scheme; - llvm::StringRef hostname; - int port; - llvm::StringRef path; - std::string uri(socket_a_up->GetRemoteConnectionURI()); - EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path)); - EXPECT_EQ(scheme, "connect"); - EXPECT_EQ(port, socket_a_up->GetRemotePortNumber()); -} - -TEST_F(SocketTest, UDPGetConnectURI) { - if (!IsAddressFamilySupported("127.0.0.1")) { - GTEST_LOG_(WARNING) << "Skipping test due to missing IPv4 support."; - return; - } - Socket *socket; - bool child_processes_inherit = false; - auto error = - UDPSocket::Connect("127.0.0.1:0", child_processes_inherit, socket); - - llvm::StringRef scheme; - llvm::StringRef hostname; - int port; - llvm::StringRef path; - std::string uri(socket->GetRemoteConnectionURI()); - EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path)); - EXPECT_EQ(scheme, "udp"); -} - -#if LLDB_ENABLE_POSIX -TEST_F(SocketTest, DomainGetConnectURI) { - llvm::SmallString<64> domain_path; - std::error_code EC = - llvm::sys::fs::createUniqueDirectory("DomainListenConnectAccept", domain_path); - ASSERT_FALSE(EC); - llvm::sys::path::append(domain_path, "test"); - - // Skip the test if the $TMPDIR is too long to hold a domain socket. - if (domain_path.size() > 107u) - return; - - std::unique_ptr<DomainSocket> socket_a_up; - std::unique_ptr<DomainSocket> socket_b_up; - CreateDomainConnectedSockets(domain_path, &socket_a_up, &socket_b_up); - - llvm::StringRef scheme; - llvm::StringRef hostname; - int port; - llvm::StringRef path; - std::string uri(socket_a_up->GetRemoteConnectionURI()); - EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path)); - EXPECT_EQ(scheme, "unix-connect"); - EXPECT_EQ(path, domain_path); -} -#endif diff --git a/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.cpp b/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.cpp deleted file mode 100644 index 6e7345bc917..00000000000 --- a/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.cpp +++ /dev/null @@ -1,105 +0,0 @@ -//===----------------- SocketTestUtilities.cpp ------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "SocketTestUtilities.h" -#include "lldb/Host/Config.h" -#include "lldb/Utility/StreamString.h" - -#ifdef _WIN32 -#include <winsock2.h> -#include <ws2tcpip.h> -#else -#include <arpa/inet.h> -#endif - -using namespace lldb_private; - -static void AcceptThread(Socket *listen_socket, bool child_processes_inherit, - Socket **accept_socket, Status *error) { - *error = listen_socket->Accept(*accept_socket); -} - -template <typename SocketType> -void lldb_private::CreateConnectedSockets( - llvm::StringRef listen_remote_address, - const std::function<std::string(const SocketType &)> &get_connect_addr, - std::unique_ptr<SocketType> *a_up, std::unique_ptr<SocketType> *b_up) { - bool child_processes_inherit = false; - Status error; - std::unique_ptr<SocketType> listen_socket_up( - new SocketType(true, child_processes_inherit)); - EXPECT_FALSE(error.Fail()); - error = listen_socket_up->Listen(listen_remote_address, 5); - EXPECT_FALSE(error.Fail()); - EXPECT_TRUE(listen_socket_up->IsValid()); - - Status accept_error; - Socket *accept_socket; - std::thread accept_thread(AcceptThread, listen_socket_up.get(), - child_processes_inherit, &accept_socket, - &accept_error); - - std::string connect_remote_address = get_connect_addr(*listen_socket_up); - std::unique_ptr<SocketType> connect_socket_up( - new SocketType(true, child_processes_inherit)); - EXPECT_FALSE(error.Fail()); - error = connect_socket_up->Connect(connect_remote_address); - EXPECT_FALSE(error.Fail()); - EXPECT_TRUE(connect_socket_up->IsValid()); - - a_up->swap(connect_socket_up); - EXPECT_TRUE(error.Success()); - EXPECT_NE(nullptr, a_up->get()); - EXPECT_TRUE((*a_up)->IsValid()); - - accept_thread.join(); - b_up->reset(static_cast<SocketType *>(accept_socket)); - EXPECT_TRUE(accept_error.Success()); - EXPECT_NE(nullptr, b_up->get()); - EXPECT_TRUE((*b_up)->IsValid()); - - listen_socket_up.reset(); -} - -bool lldb_private::CreateTCPConnectedSockets( - std::string listen_remote_ip, std::unique_ptr<TCPSocket> *socket_a_up, - std::unique_ptr<TCPSocket> *socket_b_up) { - StreamString strm; - strm.Printf("[%s]:0", listen_remote_ip.c_str()); - CreateConnectedSockets<TCPSocket>( - strm.GetString(), - [=](const TCPSocket &s) { - char connect_remote_address[64]; - snprintf(connect_remote_address, sizeof(connect_remote_address), - "[%s]:%u", listen_remote_ip.c_str(), s.GetLocalPortNumber()); - return std::string(connect_remote_address); - }, - socket_a_up, socket_b_up); - return true; -} - -#if LLDB_ENABLE_POSIX -void lldb_private::CreateDomainConnectedSockets( - llvm::StringRef path, std::unique_ptr<DomainSocket> *socket_a_up, - std::unique_ptr<DomainSocket> *socket_b_up) { - return CreateConnectedSockets<DomainSocket>( - path, [=](const DomainSocket &) { return path.str(); }, socket_a_up, - socket_b_up); -} -#endif - -bool lldb_private::IsAddressFamilySupported(std::string ip) { - auto addresses = lldb_private::SocketAddress::GetAddressInfo( - ip.c_str(), NULL, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); - return addresses.size() > 0; -} - -bool lldb_private::IsIPv4(std::string ip) { - struct sockaddr_in sock_addr; - return inet_pton(AF_INET, ip.c_str(), &(sock_addr.sin_addr)) != 0; -} diff --git a/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.h b/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.h deleted file mode 100644 index 35627824754..00000000000 --- a/gnu/llvm/lldb/unittests/Host/SocketTestUtilities.h +++ /dev/null @@ -1,47 +0,0 @@ -//===--------------------- SocketTestUtilities.h ----------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_UNITTESTS_HOST_SOCKETTESTUTILITIES_H -#define LLDB_UNITTESTS_HOST_SOCKETTESTUTILITIES_H - -#include <cstdio> -#include <functional> -#include <thread> - -#include "lldb/Host/Config.h" -#include "lldb/Host/Socket.h" -#include "lldb/Host/common/TCPSocket.h" -#include "lldb/Host/common/UDPSocket.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Path.h" -#include "llvm/Testing/Support/Error.h" - -#if LLDB_ENABLE_POSIX -#include "lldb/Host/posix/DomainSocket.h" -#endif - -namespace lldb_private { -template <typename SocketType> -void CreateConnectedSockets( - llvm::StringRef listen_remote_address, - const std::function<std::string(const SocketType &)> &get_connect_addr, - std::unique_ptr<SocketType> *a_up, std::unique_ptr<SocketType> *b_up); -bool CreateTCPConnectedSockets(std::string listen_remote_ip, - std::unique_ptr<TCPSocket> *a_up, - std::unique_ptr<TCPSocket> *b_up); -#if LLDB_ENABLE_POSIX -void CreateDomainConnectedSockets(llvm::StringRef path, - std::unique_ptr<DomainSocket> *a_up, - std::unique_ptr<DomainSocket> *b_up); -#endif - -bool IsAddressFamilySupported(std::string ip); -bool IsIPv4(std::string ip); -} // namespace lldb_private - -#endif
\ No newline at end of file diff --git a/gnu/llvm/lldb/unittests/Host/linux/HostTest.cpp b/gnu/llvm/lldb/unittests/Host/linux/HostTest.cpp deleted file mode 100644 index d7676c24ce9..00000000000 --- a/gnu/llvm/lldb/unittests/Host/linux/HostTest.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===-- HostTest.cpp --------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/Host.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Target/Process.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -namespace { -class HostTest : public testing::Test { -public: - static void SetUpTestCase() { - FileSystem::Initialize(); - HostInfo::Initialize(); - } - static void TearDownTestCase() { - HostInfo::Terminate(); - FileSystem::Terminate(); - } -}; -} // namespace - -TEST_F(HostTest, GetProcessInfo) { - ProcessInstanceInfo Info; - ASSERT_FALSE(Host::GetProcessInfo(0, Info)); - - ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info)); - - ASSERT_TRUE(Info.ProcessIDIsValid()); - EXPECT_EQ(lldb::pid_t(getpid()), Info.GetProcessID()); - - ASSERT_TRUE(Info.ParentProcessIDIsValid()); - EXPECT_EQ(lldb::pid_t(getppid()), Info.GetParentProcessID()); - - ASSERT_TRUE(Info.EffectiveUserIDIsValid()); - EXPECT_EQ(geteuid(), Info.GetEffectiveUserID()); - - ASSERT_TRUE(Info.EffectiveGroupIDIsValid()); - EXPECT_EQ(getegid(), Info.GetEffectiveGroupID()); - - ASSERT_TRUE(Info.UserIDIsValid()); - EXPECT_EQ(geteuid(), Info.GetUserID()); - - ASSERT_TRUE(Info.GroupIDIsValid()); - EXPECT_EQ(getegid(), Info.GetGroupID()); - - EXPECT_TRUE(Info.GetArchitecture().IsValid()); - EXPECT_EQ(HostInfo::GetArchitecture(HostInfo::eArchKindDefault), - Info.GetArchitecture()); -} diff --git a/gnu/llvm/lldb/unittests/Host/linux/SupportTest.cpp b/gnu/llvm/lldb/unittests/Host/linux/SupportTest.cpp deleted file mode 100644 index f0687431979..00000000000 --- a/gnu/llvm/lldb/unittests/Host/linux/SupportTest.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===-- SupportTest.cpp -----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Host/linux/Support.h" -#include "llvm/Support/Threading.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -TEST(Support, getProcFile_Pid) { - auto BufferOrError = getProcFile(getpid(), "maps"); - ASSERT_TRUE(BufferOrError); - ASSERT_TRUE(*BufferOrError); -} - -TEST(Support, getProcFile_Tid) { - auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "comm"); - ASSERT_TRUE(BufferOrError); - ASSERT_TRUE(*BufferOrError); -} |