Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 1 | //===-- ThreadsInJstopinfoTest.cpp ------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 9 | #include "TestBase.h" |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 10 | #include "TestClient.h" |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 11 | #include "lldb/Utility/DataExtractor.h" |
| 12 | #include "llvm/Support/FormatVariadic.h" |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 13 | #include "llvm/Support/Path.h" |
Pavel Labath | 1ebc85f | 2017-11-09 15:45:09 +0000 | [diff] [blame] | 14 | #include "llvm/Testing/Support/Error.h" |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 15 | #include "gmock/gmock.h" |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 16 | #include "gtest/gtest.h" |
| 17 | #include <string> |
| 18 | |
| 19 | using namespace llgs_tests; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 20 | using namespace lldb_private; |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 21 | using namespace llvm; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 22 | using namespace lldb; |
| 23 | using namespace testing; |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 24 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 25 | TEST_F(StandardStartupTest, TestStopReplyContainsThreadPcs) { |
| 26 | // This inferior spawns 4 threads, then forces a break. |
| 27 | ASSERT_THAT_ERROR( |
| 28 | Client->SetInferior({getInferiorPath("thread_inferior"), "4"}), |
| 29 | Succeeded()); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 30 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 31 | ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded()); |
| 32 | ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded()); |
| 33 | unsigned int pc_reg = Client->GetPcRegisterId(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 34 | ASSERT_NE(pc_reg, UINT_MAX); |
| 35 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 36 | auto jthreads_info = Client->GetJThreadsInfo(); |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 37 | ASSERT_THAT_EXPECTED(jthreads_info, Succeeded()); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 38 | |
Pavel Labath | 93a582c | 2017-12-15 15:19:45 +0000 | [diff] [blame] | 39 | auto stop_reply = Client->GetLatestStopReplyAs<StopReplyStop>(); |
| 40 | ASSERT_THAT_EXPECTED(stop_reply, Succeeded()); |
| 41 | auto stop_reply_pcs = stop_reply->getThreadPcs(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 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."; |
Pavel Labath | 9a9556f | 2018-02-19 15:42:48 +0000 | [diff] [blame] | 50 | EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg), |
| 51 | Pointee(Eq(stop_reply_pc.second))); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 52 | } |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 53 | } |