blob: 1b060f74238a48b64f9b4b7f3cebf9417d429a7a [file] [log] [blame]
Pavel Labath11e59172017-12-18 14:31:39 +00001//===-- LLGSTest.cpp --------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Pavel Labath11e59172017-12-18 14:31:39 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "TestBase.h"
10#include "lldb/Host/Host.h"
11#include "llvm/Testing/Support/Error.h"
12
13using namespace llgs_tests;
14using namespace lldb_private;
15using namespace llvm;
16
17TEST_F(TestBase, LaunchModePreservesEnvironment) {
Pavel Labath11e59172017-12-18 14:31:39 +000018 putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE"));
19
20 auto ClientOr = TestClient::launch(getLogFileName(),
21 {getInferiorPath("environment_check")});
22 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
23 auto &Client = **ClientOr;
24
25 ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());
26 ASSERT_THAT_EXPECTED(
27 Client.GetLatestStopReplyAs<StopReplyExit>(),
28 HasValue(testing::Property(&StopReply::getKind,
29 WaitStatus{WaitStatus::Exit, 0})));
30}
Pavel Labathdeb45f22017-12-22 11:09:21 +000031
32TEST_F(TestBase, DS_TEST(DebugserverEnv)) {
33 // Test that --env takes precedence over inherited environment variables.
34 putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=foobar"));
35
36 auto ClientOr = TestClient::launchCustom(getLogFileName(),
37 { "--env", "LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE" },
38 {getInferiorPath("environment_check")});
39 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
40 auto &Client = **ClientOr;
41
42 ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());
43 ASSERT_THAT_EXPECTED(
44 Client.GetLatestStopReplyAs<StopReplyExit>(),
45 HasValue(testing::Property(&StopReply::getKind,
46 WaitStatus{WaitStatus::Exit, 0})));
47}
Pavel Labatha70512a2018-04-11 13:30:54 +000048
49TEST_F(TestBase, LLGS_TEST(vAttachRichError)) {
50 auto ClientOr = TestClient::launch(getLogFileName(),
51 {getInferiorPath("environment_check")});
52 ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
53 auto &Client = **ClientOr;
54
55 // Until we enable error strings we should just get the error code.
56 ASSERT_THAT_ERROR(Client.SendMessage("vAttach;1"),
57 Failed<ErrorInfoBase>(testing::Property(
58 &ErrorInfoBase::message, "Error 255")));
59
60 ASSERT_THAT_ERROR(Client.SendMessage("QEnableErrorStrings"), Succeeded());
61
62 // Now, we expect the full error message.
63 ASSERT_THAT_ERROR(
64 Client.SendMessage("vAttach;1"),
65 Failed<ErrorInfoBase>(testing::Property(
66 &ErrorInfoBase::message,
67 testing::StartsWith(
68 "cannot attach to process 1 when another process with pid"))));
69}