blob: 1cd8e0d38b9c98f1892931785fddc33b1022f88a [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
Aaron Smith5032c6e2019-08-16 03:49:41 +000021// 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)
Pavel Labath11e59172017-12-18 14:31:39 +000024TEST_F(TestBase, LaunchModePreservesEnvironment) {
Pavel Labath11e59172017-12-18 14:31:39 +000025 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}
Aaron Smith5032c6e2019-08-16 03:49:41 +000038#endif
Pavel Labathdeb45f22017-12-22 11:09:21 +000039
40TEST_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}
Pavel Labatha70512a2018-04-11 13:30:54 +000056
57TEST_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}