blob: 6ff777bd17abf428e12c8307c7bc7530587b97f8 [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 Labath93a582c2017-12-15 15:19:45 +000034 auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>();
35 ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
36 auto stop_reply_pcs = stop_reply->getThreadPcs();
Pavel Labath015f17d2017-06-06 13:40:18 +000037 auto thread_infos = jthreads_info->GetThreadInfos();
38 ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
39 << "Thread count mismatch.";
40
41 for (auto stop_reply_pc : stop_reply_pcs) {
42 unsigned long tid = stop_reply_pc.first;
43 ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
44 << "Thread ID: " << tid << " not in JThreadsInfo.";
Pavel Labath1ebc85f2017-11-09 15:45:09 +000045 auto pc_value = thread_infos[tid].ReadRegisterAsUint64(pc_reg);
Pavel Labath671d3e62017-12-15 13:56:22 +000046 ASSERT_THAT_EXPECTED(pc_value, Succeeded());
Pavel Labath1ebc85f2017-11-09 15:45:09 +000047 ASSERT_EQ(stop_reply_pcs[tid], *pc_value)
Pavel Labath015f17d2017-06-06 13:40:18 +000048 << "Mismatched PC for thread: " << tid;
49 }
Pavel Labath015f17d2017-06-06 13:40:18 +000050}