1 #include "gmock/gmock.h"
2 #include "gtest/gtest.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
15 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
18 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
21 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
24 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
27 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
30 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
33 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
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
);
44 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
47 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
50 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
53 EXPECT_EQ(ex
.GetPidTid(0), std::nullopt
);
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
75 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
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
86 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
89 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
92 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
95 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
98 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
100 ex
.Reset("p0.123456789ABCDEF0");
101 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
104 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
106 ex
.Reset("p123456789ABCDEF0.0");
107 EXPECT_EQ(ex
.GetPidTid(100), std::nullopt
);
112 EXPECT_THAT(*ex
.GetPidTid(100),
113 ::testing::Pair(100, StringExtractorGDBRemote::AllThreads
));
116 EXPECT_THAT(*ex
.GetPidTid(100), ::testing::Pair(100, 0x1234ULL
));
118 ex
.Reset("123456789ABCDEF0");
119 EXPECT_THAT(*ex
.GetPidTid(100), ::testing::Pair(100, 0x123456789ABCDEF0ULL
));
124 EXPECT_THAT(*ex
.GetPidTid(100),
125 ::testing::Pair(StringExtractorGDBRemote::AllProcesses
,
126 StringExtractorGDBRemote::AllThreads
));
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
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
));