1 | //===-- LLGSTest.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 "TestBase.h" |
10 | #include "lldb/Host/Host.h" |
11 | #include "llvm/Testing/Support/Error.h" |
12 | |
13 | using namespace llgs_tests; |
14 | using namespace lldb_private; |
15 | using namespace llvm; |
16 | |
17 | #ifdef SendMessage |
18 | #undef SendMessage |
19 | #endif |
20 | |
21 | // Disable this test on Windows as it appears to have a race condition |
22 | // that causes lldb-server not to exit after the inferior hangs up. |
23 | #if !defined(_WIN32) |
24 | TEST_F(TestBase, LaunchModePreservesEnvironment) { |
25 | putenv(string: const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE" )); |
26 | |
27 | auto ClientOr = TestClient::launchCustom( |
28 | Log: getLogFileName(), |
29 | /* disable_stdio */ true, ServerArgs: {}, InferiorArgs: {getInferiorPath(Name: "environment_check" )}); |
30 | ASSERT_THAT_EXPECTED(ClientOr, Succeeded()); |
31 | auto &Client = **ClientOr; |
32 | |
33 | ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded()); |
34 | ASSERT_THAT_EXPECTED( |
35 | Client.GetLatestStopReplyAs<StopReplyExit>(), |
36 | HasValue(testing::Property(&StopReply::getKind, |
37 | WaitStatus{WaitStatus::Exit, 0}))); |
38 | } |
39 | #endif |
40 | |
41 | TEST_F(TestBase, DS_TEST(DebugserverEnv)) { |
42 | // Test that --env takes precedence over inherited environment variables. |
43 | putenv(string: const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=foobar" )); |
44 | |
45 | auto ClientOr = TestClient::launchCustom( |
46 | Log: getLogFileName(), /* disable_stdio */ true, |
47 | ServerArgs: {"--env" , "LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE" }, |
48 | InferiorArgs: {getInferiorPath(Name: "environment_check" )}); |
49 | ASSERT_THAT_EXPECTED(ClientOr, Succeeded()); |
50 | auto &Client = **ClientOr; |
51 | |
52 | ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded()); |
53 | ASSERT_THAT_EXPECTED( |
54 | Client.GetLatestStopReplyAs<StopReplyExit>(), |
55 | HasValue(testing::Property(&StopReply::getKind, |
56 | WaitStatus{WaitStatus::Exit, 0}))); |
57 | } |
58 | |
59 | TEST_F(TestBase, LLGS_TEST(vAttachRichError)) { |
60 | auto ClientOr = TestClient::launchCustom( |
61 | Log: getLogFileName(), |
62 | /* disable_stdio */ true, ServerArgs: {}, InferiorArgs: {getInferiorPath(Name: "environment_check" )}); |
63 | ASSERT_THAT_EXPECTED(ClientOr, Succeeded()); |
64 | auto &Client = **ClientOr; |
65 | |
66 | // Until we enable error strings we should just get the error code. |
67 | ASSERT_THAT_ERROR(Client.SendMessage("vAttach;1" ), |
68 | Failed<ErrorInfoBase>(testing::Property( |
69 | &ErrorInfoBase::message, "Error 255" ))); |
70 | |
71 | ASSERT_THAT_ERROR(Client.SendMessage("QEnableErrorStrings" ), Succeeded()); |
72 | |
73 | // Now, we expect the full error message. |
74 | ASSERT_THAT_ERROR( |
75 | Client.SendMessage("vAttach;1" ), |
76 | Failed<ErrorInfoBase>(testing::Property( |
77 | &ErrorInfoBase::message, |
78 | testing::StartsWith( |
79 | "cannot attach to process 1 when another process with pid" )))); |
80 | } |
81 | |