blob: c8972710454eb6b01d799e08a5d6d2f015407217 [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
Pavel Labath671d3e62017-12-15 13:56:22 +000010#include "TestBase.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000011#include "TestClient.h"
Pavel Labath671d3e62017-12-15 13:56:22 +000012#include "llvm/Support/Path.h"
Pavel Labath1ebc85f2017-11-09 15:45:09 +000013#include "llvm/Testing/Support/Error.h"
Pavel Labath015f17d2017-06-06 13:40:18 +000014#include "gtest/gtest.h"
15#include <string>
16
17using namespace llgs_tests;
Pavel Labath671d3e62017-12-15 13:56:22 +000018using namespace llvm;
Pavel Labath015f17d2017-06-06 13:40:18 +000019
Pavel Labath671d3e62017-12-15 13:56:22 +000020TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) {
21 // This inferior spawns 4 threads, then forces a break.
22 ASSERT_THAT_ERROR(
23 Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
24 Succeeded());
Pavel Labath015f17d2017-06-06 13:40:18 +000025
Pavel Labath671d3e62017-12-15 13:56:22 +000026 ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
27 ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
28 unsigned int pc_reg = Client->GetPcRegisterId();
Pavel Labath015f17d2017-06-06 13:40:18 +000029 ASSERT_NE(pc_reg, UINT_MAX);
30
Pavel Labath671d3e62017-12-15 13:56:22 +000031 auto jthreads_info = Client->GetJThreadsInfo();
Pavel Labath015f17d2017-06-06 13:40:18 +000032 ASSERT_TRUE(jthreads_info);
33
Pavel Labath671d3e62017-12-15 13:56:22 +000034 auto stop_reply = Client->GetLatestStopReply();
Pavel Labath015f17d2017-06-06 13:40:18 +000035 auto stop_reply_pcs = stop_reply.GetThreadPcs();
36 auto thread_infos = jthreads_info->GetThreadInfos();
37 ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
38 << "Thread count mismatch.";
39
40 for (auto stop_reply_pc : stop_reply_pcs) {
41 unsigned long tid = stop_reply_pc.first;
42 ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
43 << "Thread ID: " << tid << " not in JThreadsInfo.";
Pavel Labath1ebc85f2017-11-09 15:45:09 +000044 auto pc_value = thread_infos[tid].ReadRegisterAsUint64(pc_reg);
Pavel Labath671d3e62017-12-15 13:56:22 +000045 ASSERT_THAT_EXPECTED(pc_value, Succeeded());
Pavel Labath1ebc85f2017-11-09 15:45:09 +000046 ASSERT_EQ(stop_reply_pcs[tid], *pc_value)
Pavel Labath015f17d2017-06-06 13:40:18 +000047 << "Mismatched PC for thread: " << tid;
48 }
Pavel Labath015f17d2017-06-06 13:40:18 +000049}