[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / unittests / Utility / StringExtractorGDBRemoteTest.cpp
blob5bf7440c9e5bdaf9a3332c2cfa2bb710627e7d72
1 #include "gmock/gmock.h"
2 #include "gtest/gtest.h"
3 #include <limits.h>
5 #include "lldb/Utility/StringExtractorGDBRemote.h"
6 #include "lldb/lldb-defines.h"
8 TEST(StringExtractorGDBRemoteTest, GetPidTid) {
9 StringExtractorGDBRemote ex("");
10 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
12 // invalid/short values
14 ex.Reset("narf");
15 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
17 ex.Reset(";1234");
18 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
20 ex.Reset(".1234");
21 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
23 ex.Reset("p");
24 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
26 ex.Reset("pnarf");
27 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
29 ex.Reset("p;1234");
30 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
32 ex.Reset("p.1234");
33 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
35 ex.Reset("p1234.");
36 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
38 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
40 ex.Reset("p1234.;1234");
41 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
43 ex.Reset("-2");
44 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
46 ex.Reset("p1234.-2");
47 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
49 ex.Reset("p-2");
50 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
52 ex.Reset("p-2.1234");
53 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
55 // overflow
57 ex.Reset("p10000000000000000");
58 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
60 ex.Reset("p10000000000000000.0");
61 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
63 ex.Reset("10000000000000000");
64 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
66 ex.Reset("p0.10000000000000000");
67 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
69 ex.Reset("p10000000000000000.10000000000000000");
70 EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
72 // invalid: all processes but specific thread
74 ex.Reset("p-1.0");
75 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
77 ex.Reset("p-1.1234");
78 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
80 ex.Reset("p-1.123456789ABCDEF0");
81 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
83 // unsupported: pid/tid 0
85 ex.Reset("0");
86 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
88 ex.Reset("p0");
89 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
91 ex.Reset("p0.0");
92 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
94 ex.Reset("p0.-1");
95 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
97 ex.Reset("p0.1234");
98 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
100 ex.Reset("p0.123456789ABCDEF0");
101 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
103 ex.Reset("p1234.0");
104 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
106 ex.Reset("p123456789ABCDEF0.0");
107 EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
109 // pure thread id
111 ex.Reset("-1");
112 EXPECT_THAT(*ex.GetPidTid(100),
113 ::testing::Pair(100, StringExtractorGDBRemote::AllThreads));
115 ex.Reset("1234");
116 EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
118 ex.Reset("123456789ABCDEF0");
119 EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x123456789ABCDEF0ULL));
121 // pure process id
123 ex.Reset("p-1");
124 EXPECT_THAT(*ex.GetPidTid(100),
125 ::testing::Pair(StringExtractorGDBRemote::AllProcesses,
126 StringExtractorGDBRemote::AllThreads));
128 ex.Reset("p1234");
129 EXPECT_THAT(*ex.GetPidTid(100),
130 ::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
132 ex.Reset("p123456789ABCDEF0");
133 EXPECT_THAT(*ex.GetPidTid(100),
134 ::testing::Pair(0x123456789ABCDEF0ULL,
135 StringExtractorGDBRemote::AllThreads));
137 ex.Reset("pFFFFFFFFFFFFFFFF");
138 EXPECT_THAT(*ex.GetPidTid(100),
139 ::testing::Pair(StringExtractorGDBRemote::AllProcesses,
140 StringExtractorGDBRemote::AllThreads));
142 // combined thread id + process id
144 ex.Reset("p-1.-1");
145 EXPECT_THAT(*ex.GetPidTid(100),
146 ::testing::Pair(StringExtractorGDBRemote::AllProcesses,
147 StringExtractorGDBRemote::AllThreads));
149 ex.Reset("p1234.-1");
150 EXPECT_THAT(*ex.GetPidTid(100),
151 ::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
153 ex.Reset("p1234.123456789ABCDEF0");
154 EXPECT_THAT(*ex.GetPidTid(100),
155 ::testing::Pair(0x1234ULL, 0x123456789ABCDEF0ULL));
157 ex.Reset("p123456789ABCDEF0.-1");
158 EXPECT_THAT(*ex.GetPidTid(100),
159 ::testing::Pair(0x123456789ABCDEF0ULL,
160 StringExtractorGDBRemote::AllThreads));
162 ex.Reset("p123456789ABCDEF0.1234");
163 EXPECT_THAT(*ex.GetPidTid(100),
164 ::testing::Pair(0x123456789ABCDEF0ULL, 0x1234ULL));
166 ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
167 EXPECT_THAT(*ex.GetPidTid(100),
168 ::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
170 ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
171 EXPECT_THAT(*ex.GetPidTid(100),
172 ::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
175 TEST(StringExtractorGDBRemoteTest, GetPidTidMultipleValues) {
176 StringExtractorGDBRemote ex("1234;p12;p1234.-1");
177 ASSERT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
178 ASSERT_EQ(ex.GetChar(), ';');
179 ASSERT_THAT(*ex.GetPidTid(100),
180 ::testing::Pair(0x12ULL, StringExtractorGDBRemote::AllThreads));
181 ASSERT_EQ(ex.GetChar(), ';');
182 ASSERT_THAT(*ex.GetPidTid(100),
183 ::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));