1 | //===-- GDBRemoteCommunicationServerLLGSTest.cpp --------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "gtest/gtest.h" |
10 | |
11 | #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h" |
12 | |
13 | using namespace lldb_private::process_gdb_remote; |
14 | |
15 | TEST(GDBRemoteCommunicationServerLLGSTest, LLGSArgToURL) { |
16 | // LLGS new-style URLs should be passed through (indepenently of |
17 | // --reverse-connect) |
18 | EXPECT_EQ(LLGSArgToURL("listen://127.0.0.1:1234" , false), |
19 | "listen://127.0.0.1:1234" ); |
20 | EXPECT_EQ(LLGSArgToURL("listen://127.0.0.1:1234" , true), |
21 | "listen://127.0.0.1:1234" ); |
22 | EXPECT_EQ(LLGSArgToURL("connect://127.0.0.1:1234" , false), |
23 | "connect://127.0.0.1:1234" ); |
24 | EXPECT_EQ(LLGSArgToURL("connect://127.0.0.1:1234" , true), |
25 | "connect://127.0.0.1:1234" ); |
26 | |
27 | // LLGS legacy listen URLs should be converted if !reverse_connect |
28 | EXPECT_EQ(LLGSArgToURL("tcp://127.0.0.1:1234" , false), |
29 | "listen://127.0.0.1:1234" ); |
30 | EXPECT_EQ(LLGSArgToURL("unix:///tmp/foo" , false), "unix-accept:///tmp/foo" ); |
31 | EXPECT_EQ(LLGSArgToURL("unix-abstract://foo" , false), |
32 | "unix-abstract-accept://foo" ); |
33 | |
34 | // LLGS listen host:port pairs should be converted to listen:// |
35 | EXPECT_EQ(LLGSArgToURL("127.0.0.1:1234" , false), "listen://127.0.0.1:1234" ); |
36 | EXPECT_EQ(LLGSArgToURL("[::1]:1234" , false), "listen://[::1]:1234" ); |
37 | EXPECT_EQ(LLGSArgToURL("[[::1]:1234]" , false), "listen://[[::1]:1234]" ); |
38 | EXPECT_EQ(LLGSArgToURL("localhost:1234" , false), "listen://localhost:1234" ); |
39 | EXPECT_EQ(LLGSArgToURL("*:1234" , false), "listen://*:1234" ); |
40 | |
41 | // LLGS listen :port special-case should be converted to listen:// |
42 | EXPECT_EQ(LLGSArgToURL(":1234" , false), "listen://localhost:1234" ); |
43 | |
44 | // LLGS listen UNIX sockets should be converted to unix-accept:// |
45 | EXPECT_EQ(LLGSArgToURL("/tmp/foo" , false), "unix-accept:///tmp/foo" ); |
46 | EXPECT_EQ(LLGSArgToURL("127.0.0.1" , false), "unix-accept://127.0.0.1" ); |
47 | EXPECT_EQ(LLGSArgToURL("[::1]" , false), "unix-accept://[::1]" ); |
48 | EXPECT_EQ(LLGSArgToURL("localhost" , false), "unix-accept://localhost" ); |
49 | EXPECT_EQ(LLGSArgToURL(":frobnicate" , false), "unix-accept://:frobnicate" ); |
50 | |
51 | // LLGS reverse connect host:port pairs should be converted to connect:// |
52 | EXPECT_EQ(LLGSArgToURL("127.0.0.1:1234" , true), "connect://127.0.0.1:1234" ); |
53 | EXPECT_EQ(LLGSArgToURL("[::1]:1234" , true), "connect://[::1]:1234" ); |
54 | EXPECT_EQ(LLGSArgToURL("[[::1]:1234]" , true), "connect://[[::1]:1234]" ); |
55 | EXPECT_EQ(LLGSArgToURL("localhost:1234" , true), "connect://localhost:1234" ); |
56 | |
57 | // with LLGS reverse connect, anything else goes as unix-connect:// |
58 | EXPECT_EQ(LLGSArgToURL("/tmp/foo" , true), "unix-connect:///tmp/foo" ); |
59 | EXPECT_EQ(LLGSArgToURL("127.0.0.1" , true), "unix-connect://127.0.0.1" ); |
60 | EXPECT_EQ(LLGSArgToURL("[::1]" , true), "unix-connect://[::1]" ); |
61 | EXPECT_EQ(LLGSArgToURL("localhost" , true), "unix-connect://localhost" ); |
62 | EXPECT_EQ(LLGSArgToURL(":frobnicate" , true), "unix-connect://:frobnicate" ); |
63 | } |
64 | |