Pavel Labath | 11e5917 | 2017-12-18 14:31:39 +0000 | [diff] [blame] | 1 | //===-- LLGSTest.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Pavel Labath | 11e5917 | 2017-12-18 14:31:39 +0000 | [diff] [blame] | 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 | TEST_F(TestBase, LaunchModePreservesEnvironment) { |
Pavel Labath | 11e5917 | 2017-12-18 14:31:39 +0000 | [diff] [blame] | 18 | 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 Labath | deb45f2 | 2017-12-22 11:09:21 +0000 | [diff] [blame] | 31 | |
| 32 | TEST_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 Labath | a70512a | 2018-04-11 13:30:54 +0000 | [diff] [blame] | 48 | |
| 49 | TEST_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 | } |