summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/cmake/modules/AddLLVM.cmake6
-rw-r--r--llvm/include/llvm/Testing/Support/SupportHelpers.h8
-rw-r--r--llvm/lib/Testing/Support/CMakeLists.txt1
-rw-r--r--llvm/lib/Testing/Support/SupportHelpers.cpp36
-rw-r--r--llvm/unittests/unittest.cfg.in1
5 files changed, 51 insertions, 1 deletions
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index e94e3c4aec2..dcc65d078cb 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1112,6 +1112,11 @@ function(add_unittest test_suite test_name)
# executable must be linked with it in order to provide consistent
# API for all shared libaries loaded by this executable.
target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
+
+ set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+ configure_file(
+ ${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/llvm.srcdir.txt)
add_dependencies(${test_suite} ${test_name})
get_target_property(test_suite_folder ${test_suite} FOLDER)
@@ -1120,6 +1125,7 @@ function(add_unittest test_suite test_name)
endif ()
endfunction()
+
# Generic support for adding a benchmark.
function(add_benchmark benchmark_name)
if( NOT LLVM_BUILD_BENCHMARKS )
diff --git a/llvm/include/llvm/Testing/Support/SupportHelpers.h b/llvm/include/llvm/Testing/Support/SupportHelpers.h
index 96264ac81dc..437e3c1086a 100644
--- a/llvm/include/llvm/Testing/Support/SupportHelpers.h
+++ b/llvm/include/llvm/Testing/Support/SupportHelpers.h
@@ -10,10 +10,12 @@
#ifndef LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
#define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
-#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Error.h"
#include "gtest/gtest-printers.h"
+#include <string>
+
namespace llvm {
namespace detail {
struct ErrorHolder {
@@ -52,6 +54,10 @@ void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
}
}
} // namespace detail
+
+namespace unittest {
+SmallString<128> getInputFileDirectory();
+}
} // namespace llvm
#endif
diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 969875e55a1..c10a81015c5 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -3,6 +3,7 @@ add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
add_llvm_library(LLVMTestingSupport
Error.cpp
+ SupportHelpers.cpp
BUILDTREE_ONLY
diff --git a/llvm/lib/Testing/Support/SupportHelpers.cpp b/llvm/lib/Testing/Support/SupportHelpers.cpp
new file mode 100644
index 00000000000..c26697988ce
--- /dev/null
+++ b/llvm/lib/Testing/Support/SupportHelpers.cpp
@@ -0,0 +1,36 @@
+
+#include "llvm/Testing/Support/SupportHelpers.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::unittest;
+
+extern const char *TestMainArgv0;
+
+SmallString<128> llvm::unittest::getInputFileDirectory() {
+ llvm::SmallString<128> Result = llvm::sys::path::parent_path(TestMainArgv0);
+ llvm::sys::fs::make_absolute(Result);
+ llvm::sys::path::append(Result, "llvm.srcdir.txt");
+
+ EXPECT_TRUE(llvm::sys::fs::is_directory(Result))
+ << "Unit test source directory file does not exist.";
+
+ auto File = MemoryBuffer::getFile(Result);
+
+ EXPECT_TRUE(static_cast<bool>(File))
+ << "Could not open unit test source directory file.";
+
+ Result.clear();
+ Result.append((*File)->getBuffer().trim());
+ llvm::sys::path::append(Result, "Inputs");
+ llvm::sys::path::native(Result);
+ return std::move(Result);
+}
diff --git a/llvm/unittests/unittest.cfg.in b/llvm/unittests/unittest.cfg.in
new file mode 100644
index 00000000000..e2db16ffe2b
--- /dev/null
+++ b/llvm/unittests/unittest.cfg.in
@@ -0,0 +1 @@
+@LLVM_UNITTEST_SOURCE_DIR@
OpenPOWER on IntegriCloud