xref: /llvm-project/lldb/unittests/tools/lldb-server/tests/TestBase.cpp (revision 777180a32b61070a10dd330b4f038bf24e916af1)
180814287SRaphael Isemann //===-- TestBase.cpp ------------------------------------------------------===//
2671d3e63SPavel Labath //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6671d3e63SPavel Labath //
7671d3e63SPavel Labath //===----------------------------------------------------------------------===//
8671d3e63SPavel Labath 
9671d3e63SPavel Labath #include "TestBase.h"
10671d3e63SPavel Labath #include <cstdlib>
11671d3e63SPavel Labath 
12671d3e63SPavel Labath using namespace llgs_tests;
13671d3e63SPavel Labath using namespace llvm;
14671d3e63SPavel Labath 
getLogFileName()15671d3e63SPavel Labath std::string TestBase::getLogFileName() {
16671d3e63SPavel Labath   const auto *test_info =
17671d3e63SPavel Labath       ::testing::UnitTest::GetInstance()->current_test_info();
18671d3e63SPavel Labath   assert(test_info);
19671d3e63SPavel Labath 
20671d3e63SPavel Labath   const char *Dir = getenv("LOG_FILE_DIRECTORY");
21671d3e63SPavel Labath   if (!Dir)
22671d3e63SPavel Labath     return "";
23671d3e63SPavel Labath 
24671d3e63SPavel Labath   if (!llvm::sys::fs::is_directory(Dir)) {
25671d3e63SPavel Labath     GTEST_LOG_(WARNING) << "Cannot access log directory: " << Dir;
26671d3e63SPavel Labath     return "";
27671d3e63SPavel Labath   }
28671d3e63SPavel Labath 
29671d3e63SPavel Labath   SmallString<64> DirStr(Dir);
30671d3e63SPavel Labath   sys::path::append(DirStr, std::string("server-") +
31671d3e63SPavel Labath                                 test_info->test_case_name() + "-" +
32671d3e63SPavel Labath                                 test_info->name() + ".log");
33*777180a3SBenjamin Kramer   return std::string(DirStr.str());
34671d3e63SPavel Labath }
35671d3e63SPavel Labath 
36