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