Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame^] | 1 | //===-- ThreadsInJstopinfoTest.cpp ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "TestClient.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | #include <string> |
| 13 | |
| 14 | using namespace llgs_tests; |
| 15 | |
| 16 | class ThreadsInJstopinfoTest : public ::testing::Test { |
| 17 | protected: |
| 18 | virtual void SetUp() { TestClient::Initialize(); } |
| 19 | }; |
| 20 | |
| 21 | TEST_F(ThreadsInJstopinfoTest, TestStopReplyContainsThreadPcsLlgs) { |
| 22 | std::vector<std::string> inferior_args; |
| 23 | // This inferior spawns N threads, then forces a break. |
| 24 | inferior_args.push_back(THREAD_INFERIOR); |
| 25 | inferior_args.push_back("4"); |
| 26 | |
| 27 | auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 28 | |
| 29 | TestClient client(test_info->name(), test_info->test_case_name()); |
| 30 | ASSERT_TRUE(client.StartDebugger()); |
| 31 | ASSERT_TRUE(client.SetInferior(inferior_args)); |
| 32 | ASSERT_TRUE(client.ListThreadsInStopReply()); |
| 33 | ASSERT_TRUE(client.ContinueAll()); |
| 34 | unsigned int pc_reg = client.GetPcRegisterId(); |
| 35 | ASSERT_NE(pc_reg, UINT_MAX); |
| 36 | |
| 37 | auto jthreads_info = client.GetJThreadsInfo(); |
| 38 | ASSERT_TRUE(jthreads_info); |
| 39 | |
| 40 | auto stop_reply = client.GetLatestStopReply(); |
| 41 | auto stop_reply_pcs = stop_reply.GetThreadPcs(); |
| 42 | auto thread_infos = jthreads_info->GetThreadInfos(); |
| 43 | ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size()) |
| 44 | << "Thread count mismatch."; |
| 45 | |
| 46 | for (auto stop_reply_pc : stop_reply_pcs) { |
| 47 | unsigned long tid = stop_reply_pc.first; |
| 48 | ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end()) |
| 49 | << "Thread ID: " << tid << " not in JThreadsInfo."; |
| 50 | uint64_t pc_value; |
| 51 | ASSERT_TRUE(thread_infos[tid].ReadRegisterAsUint64(pc_reg, pc_value)) |
| 52 | << "Failure reading ThreadInfo register " << pc_reg; |
| 53 | ASSERT_EQ(stop_reply_pcs[tid], pc_value) |
| 54 | << "Mismatched PC for thread: " << tid; |
| 55 | } |
| 56 | |
| 57 | ASSERT_TRUE(client.StopDebugger()); |
| 58 | } |