blob: 961b0a3b3167c1caa6411544f57add1e623c05c4 [file] [log] [blame]
Pavel Labath015f17d2017-06-06 13:40:18 +00001//===-- 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
14using namespace llgs_tests;
15
16class ThreadsInJstopinfoTest : public ::testing::Test {
17protected:
18 virtual void SetUp() { TestClient::Initialize(); }
19};
20
21TEST_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}