brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · b438d74 Raw
91 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "TestBase.h"10#include "lldb/Host/Host.h"11#include "llvm/Testing/Support/Error.h"12#include "gtest/gtest.h"13 14using namespace llgs_tests;15using namespace lldb_private;16using namespace llvm;17 18// Disable this test on Windows as it appears to have a race condition19// that causes lldb-server not to exit after the inferior hangs up.20#if !defined(_WIN32)21TEST_F(TestBase, LaunchModePreservesEnvironment) {22  putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE"));23 24  auto ClientOr = TestClient::launchCustom(25      getLogFileName(),26      /* disable_stdio */ true, {}, {getInferiorPath("environment_check")});27  ASSERT_THAT_EXPECTED(ClientOr, Succeeded());28  auto &Client = **ClientOr;29 30  ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());31  ASSERT_THAT_EXPECTED(32      Client.GetLatestStopReplyAs<StopReplyExit>(),33      HasValue(testing::Property(&StopReply::getKind,34                                 WaitStatus{WaitStatus::Exit, 0})));35}36#endif37 38TEST_F(TestBase, DS_TEST(DebugserverEnv)) {39  // Test that --env takes precedence over inherited environment variables.40  putenv(const_cast<char *>("LLDB_TEST_MAGIC_VARIABLE=foobar"));41 42  auto ClientOr = TestClient::launchCustom(43      getLogFileName(), /* disable_stdio */ true,44      {"--env", "LLDB_TEST_MAGIC_VARIABLE=LLDB_TEST_MAGIC_VALUE"},45      {getInferiorPath("environment_check")});46  ASSERT_THAT_EXPECTED(ClientOr, Succeeded());47  auto &Client = **ClientOr;48 49  ASSERT_THAT_ERROR(Client.ContinueAll(), Succeeded());50  ASSERT_THAT_EXPECTED(51      Client.GetLatestStopReplyAs<StopReplyExit>(),52      HasValue(testing::Property(&StopReply::getKind,53                                 WaitStatus{WaitStatus::Exit, 0})));54}55 56TEST_F(TestBase, LLGS_TEST(vAttachRichError)) {57  auto ClientOr = TestClient::launchCustom(58      getLogFileName(),59      /* disable_stdio */ true, {}, {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 79TEST_F(TestBase, LLGS_TEST(qStructuredDataPlugins)) {80  auto ClientOr = TestClient::launchCustom(81      getLogFileName(),82      /* disable_stdio */ true, {}, {getInferiorPath("environment_check")});83  ASSERT_THAT_EXPECTED(ClientOr, Succeeded());84  auto &Client = **ClientOr;85  std::string response_string;86  ASSERT_THAT_ERROR(87      Client.SendMessage("qStructuredDataPlugins", response_string),88      Succeeded());89  EXPECT_STREQ("[]", response_string.c_str());90}91