llgs-tests: Make addition of new tests easier
Summary:
Adding a new test would require one to duplicate a significant part of
the existing test that we have. This attempts to reduce that by moving
some part of that code to the test fixture. The StandardStartupTest
fixture automatically starts up the server and connects it to the
client. I also add a more low-level TestBase fixture, which allows one
to start up the client and server in a custom way (I am going to need
this for the test I am writing).
Reviewers: eugene, zturner
Subscribers: lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D41066
llvm-svn: 320809
diff --git a/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp b/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
index a97df44..c897271 100644
--- a/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
+++ b/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
@@ -7,38 +7,31 @@
//
//===----------------------------------------------------------------------===//
+#include "TestBase.h"
#include "TestClient.h"
+#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <string>
using namespace llgs_tests;
+using namespace llvm;
-class ThreadsInJstopinfoTest : public ::testing::Test {
-protected:
- virtual void SetUp() { TestClient::Initialize(); }
-};
+TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) {
+ // This inferior spawns 4 threads, then forces a break.
+ ASSERT_THAT_ERROR(
+ Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
+ Succeeded());
-TEST_F(ThreadsInJstopinfoTest, TestStopReplyContainsThreadPcsLlgs) {
- std::vector<std::string> inferior_args;
- // This inferior spawns N threads, then forces a break.
- inferior_args.push_back(THREAD_INFERIOR);
- inferior_args.push_back("4");
-
- auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
-
- TestClient client(test_info->name(), test_info->test_case_name());
- ASSERT_THAT_ERROR(client.StartDebugger(), llvm::Succeeded());
- ASSERT_THAT_ERROR(client.SetInferior(inferior_args), llvm::Succeeded());
- ASSERT_THAT_ERROR(client.ListThreadsInStopReply(), llvm::Succeeded());
- ASSERT_THAT_ERROR(client.ContinueAll(), llvm::Succeeded());
- unsigned int pc_reg = client.GetPcRegisterId();
+ ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
+ ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
+ unsigned int pc_reg = Client->GetPcRegisterId();
ASSERT_NE(pc_reg, UINT_MAX);
- auto jthreads_info = client.GetJThreadsInfo();
+ auto jthreads_info = Client->GetJThreadsInfo();
ASSERT_TRUE(jthreads_info);
- auto stop_reply = client.GetLatestStopReply();
+ auto stop_reply = Client->GetLatestStopReply();
auto stop_reply_pcs = stop_reply.GetThreadPcs();
auto thread_infos = jthreads_info->GetThreadInfos();
ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
@@ -49,10 +42,8 @@
ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
<< "Thread ID: " << tid << " not in JThreadsInfo.";
auto pc_value = thread_infos[tid].ReadRegisterAsUint64(pc_reg);
- ASSERT_THAT_EXPECTED(pc_value, llvm::Succeeded());
+ ASSERT_THAT_EXPECTED(pc_value, Succeeded());
ASSERT_EQ(stop_reply_pcs[tid], *pc_value)
<< "Mismatched PC for thread: " << tid;
}
-
- ASSERT_THAT_ERROR(client.StopDebugger(), llvm::Succeeded());
}