summaryrefslogtreecommitdiff
path: root/unittests/Host
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Host')
-rw-r--r--unittests/Host/CMakeLists.txt2
-rw-r--r--unittests/Host/HostInfoTest.cpp45
-rw-r--r--unittests/Host/MainLoopTest.cpp20
-rw-r--r--unittests/Host/TaskPoolTest.cpp45
4 files changed, 112 insertions, 0 deletions
diff --git a/unittests/Host/CMakeLists.txt b/unittests/Host/CMakeLists.txt
index 0c42eb533fa0b..238026b64c4da 100644
--- a/unittests/Host/CMakeLists.txt
+++ b/unittests/Host/CMakeLists.txt
@@ -1,11 +1,13 @@
set (FILES
FileSpecTest.cpp
FileSystemTest.cpp
+ HostInfoTest.cpp
HostTest.cpp
MainLoopTest.cpp
SocketAddressTest.cpp
SocketTest.cpp
SymbolsTest.cpp
+ TaskPoolTest.cpp
)
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
diff --git a/unittests/Host/HostInfoTest.cpp b/unittests/Host/HostInfoTest.cpp
new file mode 100644
index 0000000000000..75b8c770bbeb9
--- /dev/null
+++ b/unittests/Host/HostInfoTest.cpp
@@ -0,0 +1,45 @@
+//===-- HostInfoTest.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/HostInfo.h"
+#include "lldb/lldb-defines.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class HostInfoTest: public ::testing::Test {
+ public:
+ void SetUp() override { HostInfo::Initialize(); }
+ void TearDown() override { HostInfo::Terminate(); }
+};
+}
+
+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());
+}
diff --git a/unittests/Host/MainLoopTest.cpp b/unittests/Host/MainLoopTest.cpp
index 3a39ea1c9ac75..8f2c55c2416df 100644
--- a/unittests/Host/MainLoopTest.cpp
+++ b/unittests/Host/MainLoopTest.cpp
@@ -8,6 +8,8 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/MainLoop.h"
+#include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/common/TCPSocket.h"
#include "gtest/gtest.h"
#include <future>
@@ -107,6 +109,24 @@ TEST_F(MainLoopTest, TerminatesImmediately) {
}
#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 = llvm::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;
diff --git a/unittests/Host/TaskPoolTest.cpp b/unittests/Host/TaskPoolTest.cpp
new file mode 100644
index 0000000000000..fea5442679575
--- /dev/null
+++ b/unittests/Host/TaskPoolTest.cpp
@@ -0,0 +1,45 @@
+#include "gtest/gtest.h"
+
+#include "lldb/Host/TaskPool.h"
+
+using namespace lldb_private;
+
+TEST(TaskPoolTest, AddTask) {
+ auto fn = [](int x) { return x * x + 1; };
+
+ auto f1 = TaskPool::AddTask(fn, 1);
+ auto f2 = TaskPool::AddTask(fn, 2);
+ auto f3 = TaskPool::AddTask(fn, 3);
+ auto f4 = TaskPool::AddTask(fn, 4);
+
+ ASSERT_EQ(10, f3.get());
+ ASSERT_EQ(2, f1.get());
+ ASSERT_EQ(17, f4.get());
+ ASSERT_EQ(5, f2.get());
+}
+
+TEST(TaskPoolTest, RunTasks) {
+ std::vector<int> r(4);
+
+ auto fn = [](int x, int &y) { y = x * x + 1; };
+
+ TaskPool::RunTasks([fn, &r]() { fn(1, r[0]); }, [fn, &r]() { fn(2, r[1]); },
+ [fn, &r]() { fn(3, r[2]); }, [fn, &r]() { fn(4, r[3]); });
+
+ ASSERT_EQ(2, r[0]);
+ ASSERT_EQ(5, r[1]);
+ ASSERT_EQ(10, r[2]);
+ ASSERT_EQ(17, r[3]);
+}
+
+TEST(TaskPoolTest, TaskMap) {
+ int data[4];
+ auto fn = [&data](int x) { data[x] = x * x; };
+
+ TaskMapOverInt(0, 4, fn);
+
+ ASSERT_EQ(data[0], 0);
+ ASSERT_EQ(data[1], 1);
+ ASSERT_EQ(data[2], 4);
+ ASSERT_EQ(data[3], 9);
+}