|
| 1 | +//===-- TestBase.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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "TestBase.h" |
| 10 | +#include "Protocol/ProtocolBase.h" |
| 11 | +#include "lldb/Host/File.h" |
| 12 | +#include "lldb/Host/Pipe.h" |
| 13 | +#include "llvm/Testing/Support/Error.h" |
| 14 | + |
| 15 | +using namespace llvm; |
| 16 | +using namespace lldb; |
| 17 | +using namespace lldb_dap; |
| 18 | +using namespace lldb_dap::protocol; |
| 19 | +using namespace lldb_dap_tests; |
| 20 | +using lldb_private::File; |
| 21 | +using lldb_private::NativeFile; |
| 22 | +using lldb_private::Pipe; |
| 23 | + |
| 24 | +void PipeBase::SetUp() { |
| 25 | + ASSERT_THAT_ERROR(input.CreateNew(false).ToError(), Succeeded()); |
| 26 | + ASSERT_THAT_ERROR(output.CreateNew(false).ToError(), Succeeded()); |
| 27 | +} |
| 28 | + |
| 29 | +void TransportBase::SetUp() { |
| 30 | + PipeBase::SetUp(); |
| 31 | + to_dap = std::make_unique<Transport>( |
| 32 | + "to_dap", nullptr, |
| 33 | + std::make_shared<NativeFile>(input.GetReadFileDescriptor(), |
| 34 | + File::eOpenOptionReadOnly, |
| 35 | + NativeFile::Unowned), |
| 36 | + std::make_shared<NativeFile>(output.GetWriteFileDescriptor(), |
| 37 | + File::eOpenOptionWriteOnly, |
| 38 | + NativeFile::Unowned)); |
| 39 | + from_dap = std::make_unique<Transport>( |
| 40 | + "from_dap", nullptr, |
| 41 | + std::make_shared<NativeFile>(output.GetReadFileDescriptor(), |
| 42 | + File::eOpenOptionReadOnly, |
| 43 | + NativeFile::Unowned), |
| 44 | + std::make_shared<NativeFile>(input.GetWriteFileDescriptor(), |
| 45 | + File::eOpenOptionWriteOnly, |
| 46 | + NativeFile::Unowned)); |
| 47 | +} |
| 48 | + |
| 49 | +void DAPTestBase::SetUp() { |
| 50 | + TransportBase::SetUp(); |
| 51 | + dap = std::make_unique<DAP>( |
| 52 | + /*log=*/nullptr, |
| 53 | + /*default_repl_mode=*/ReplMode::Auto, |
| 54 | + /*pre_init_commands=*/std::vector<std::string>(), |
| 55 | + /*transport=*/*to_dap); |
| 56 | +} |
| 57 | + |
| 58 | +std::vector<Message> DAPTestBase::DrainOutput() { |
| 59 | + std::vector<Message> msgs; |
| 60 | + output.CloseWriteFileDescriptor(); |
| 61 | + while (true) { |
| 62 | + Expected<Message> next = from_dap->Read(std::chrono::milliseconds(1)); |
| 63 | + if (!next) { |
| 64 | + consumeError(next.takeError()); |
| 65 | + break; |
| 66 | + } |
| 67 | + msgs.push_back(*next); |
| 68 | + } |
| 69 | + return msgs; |
| 70 | +} |
0 commit comments