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)
TEST_F(TestBase,LaunchModePreservesEnvironment)24 TEST_F(TestBase, LaunchModePreservesEnvironment) {
25 putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE"));
26
27 auto ClientOr = TestClient::launch(getLogFileName(),
28 {getInferiorPath("environment_check")});
29 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
30 auto &Client = **ClientOr;
31
32 ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());
33 ASSERT_THAT_EXPECTED(
34 Client.GetLatestStopReplyAs<StopReplyExit>(),
35 HasValue(testing::Property(&StopReply::getKind,
36 WaitStatus{WaitStatus::Exit, 0})));
37 }
38 #endif
39
TEST_F(TestBase,DS_TEST (DebugserverEnv))40 TEST_F(TestBase, DS_TEST(DebugserverEnv)) {
41 // Test that --env takes precedence over inherited environment variables.
42 putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=foobar"));
43
44 auto ClientOr = TestClient::launchCustom(getLogFileName(),
45 { "--env", "LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE" },
46 {getInferiorPath("environment_check")});
47 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
48 auto &Client = **ClientOr;
49
50 ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());
51 ASSERT_THAT_EXPECTED(
52 Client.GetLatestStopReplyAs<StopReplyExit>(),
53 HasValue(testing::Property(&StopReply::getKind,
54 WaitStatus{WaitStatus::Exit, 0})));
55 }
56
TEST_F(TestBase,LLGS_TEST (vAttachRichError))57 TEST_F(TestBase, LLGS_TEST(vAttachRichError)) {
58 auto ClientOr = TestClient::launch(getLogFileName(),
59 {getInferiorPath("environment_check")});
60 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
61 auto &Client = **ClientOr;
62
63 // Until we enable error strings we should just get the error code.
64 ASSERT_THAT_ERROR(Client.SendMessage("vAttach;1"),
65 Failed<ErrorInfoBase>(testing::Property(
66 &ErrorInfoBase::message, "Error 255")));
67
68 ASSERT_THAT_ERROR(Client.SendMessage("QEnableErrorStrings"), Succeeded());
69
70 // Now, we expect the full error message.
71 ASSERT_THAT_ERROR(
72 Client.SendMessage("vAttach;1"),
73 Failed<ErrorInfoBase>(testing::Property(
74 &ErrorInfoBase::message,
75 testing::StartsWith(
76 "cannot attach to process 1 when another process with pid"))));
77 }
78