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 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 10 | #include "TestBase.h" |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 11 | #include "TestClient.h" |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 12 | #include "lldb/Utility/DataExtractor.h" |
| 13 | #include "llvm/Support/FormatVariadic.h" |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Path.h" |
Pavel Labath | 1ebc85f | 2017-11-09 15:45:09 +0000 | [diff] [blame] | 15 | #include "llvm/Testing/Support/Error.h" |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 16 | #include "gmock/gmock.h" |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 17 | #include "gtest/gtest.h" |
| 18 | #include <string> |
| 19 | |
| 20 | using namespace llgs_tests; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 21 | using namespace lldb_private; |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 23 | using namespace lldb; |
| 24 | using namespace testing; |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 25 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 26 | TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) { |
| 27 | // This inferior spawns 4 threads, then forces a break. |
| 28 | ASSERT_THAT_ERROR( |
| 29 | Client->SetInferior({getInferiorPath("thread_inferior"), "4"}), |
| 30 | Succeeded()); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 31 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 32 | ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded()); |
| 33 | ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded()); |
| 34 | unsigned int pc_reg = Client->GetPcRegisterId(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 35 | ASSERT_NE(pc_reg, UINT_MAX); |
| 36 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 37 | auto jthreads_info = Client->GetJThreadsInfo(); |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 38 | ASSERT_THAT_EXPECTED(jthreads_info, Succeeded()); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 39 | |
Pavel Labath | 93a582c | 2017-12-15 15:19:45 +0000 | [diff] [blame] | 40 | auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>(); |
| 41 | ASSERT_THAT_EXPECTED(stop_reply, Succeeded()); |
| 42 | auto stop_reply_pcs = stop_reply->getThreadPcs(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 43 | auto thread_infos = jthreads_info->GetThreadInfos(); |
| 44 | ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size()) |
| 45 | << "Thread count mismatch."; |
| 46 | |
| 47 | for (auto stop_reply_pc : stop_reply_pcs) { |
| 48 | unsigned long tid = stop_reply_pc.first; |
| 49 | ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end()) |
| 50 | << "Thread ID: " << tid << " not in JThreadsInfo."; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 51 | EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg), |
| 52 | Pointee(Eq(stop_reply_pc.second))); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 53 | } |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 54 | } |