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 | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Path.h" |
Pavel Labath | 1ebc85f | 2017-11-09 15:45:09 +0000 | [diff] [blame] | 13 | #include "llvm/Testing/Support/Error.h" |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 14 | #include "gtest/gtest.h" |
| 15 | #include <string> |
| 16 | |
| 17 | using namespace llgs_tests; |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 19 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 20 | TEST_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 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 | ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded()); |
| 27 | ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded()); |
| 28 | unsigned int pc_reg = Client->GetPcRegisterId(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 29 | ASSERT_NE(pc_reg, UINT_MAX); |
| 30 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 31 | auto jthreads_info = Client->GetJThreadsInfo(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 32 | ASSERT_TRUE(jthreads_info); |
| 33 | |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 34 | auto stop_reply = Client->GetLatestStopReply(); |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 35 | 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 Labath | 1ebc85f | 2017-11-09 15:45:09 +0000 | [diff] [blame] | 44 | auto pc_value = thread_infos[tid].ReadRegisterAsUint64(pc_reg); |
Pavel Labath | 671d3e6 | 2017-12-15 13:56:22 +0000 | [diff] [blame] | 45 | ASSERT_THAT_EXPECTED(pc_value, Succeeded()); |
Pavel Labath | 1ebc85f | 2017-11-09 15:45:09 +0000 | [diff] [blame] | 46 | ASSERT_EQ(stop_reply_pcs[tid], *pc_value) |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 47 | << "Mismatched PC for thread: " << tid; |
| 48 | } |
Pavel Labath | 015f17d | 2017-06-06 13:40:18 +0000 | [diff] [blame] | 49 | } |