[llvm] r341502 - Add support for unittest inputs.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 5 16:30:17 PDT 2018
Author: zturner
Date: Wed Sep 5 16:30:17 2018
New Revision: 341502
URL: http://llvm.org/viewvc/llvm-project?rev=341502&view=rev
Log:
Add support for unittest inputs.
Occasionally it is useful to have unittest which take inputs.
While we normally try to have this test be more of a lit test
we occasionally don't have tools that can exercise the code
in the right way to test certain things. LLDB has been using
this style of unit test for a while, particularly with regards
to how it tests core dump and minidump file parsing. Recently
i needed this as well for the case where we want to test that
some of the PDB reading code works correctly. It needs to
exercise the code in a way that is not covered by any dumper
and would be impractical to implement in one of the dumpers,
but requires a valid PDB file. Since this is now needed by
more than one project, it makes sense to have this be a
generally supported thing that unit tests can do, and we just
encourage people to use this sparingly.
Differential Revision: https://reviews.llvm.org/D51561
Added:
llvm/trunk/lib/Testing/Support/SupportHelpers.cpp
llvm/trunk/unittests/unittest.cfg.in
Modified:
llvm/trunk/cmake/modules/AddLLVM.cmake
llvm/trunk/include/llvm/Testing/Support/SupportHelpers.h
llvm/trunk/lib/Testing/Support/CMakeLists.txt
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=341502&r1=341501&r2=341502&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Wed Sep 5 16:30:17 2018
@@ -1112,6 +1112,11 @@ function(add_unittest test_suite test_na
# 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_na
endif ()
endfunction()
+
# Generic support for adding a benchmark.
function(add_benchmark benchmark_name)
if( NOT LLVM_BUILD_BENCHMARKS )
Modified: llvm/trunk/include/llvm/Testing/Support/SupportHelpers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Testing/Support/SupportHelpers.h?rev=341502&r1=341501&r2=341502&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Testing/Support/SupportHelpers.h (original)
+++ llvm/trunk/include/llvm/Testing/Support/SupportHelpers.h Wed Sep 5 16:30:17 2018
@@ -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> &It
}
}
} // namespace detail
+
+namespace unittest {
+SmallString<128> getInputFileDirectory();
+}
} // namespace llvm
#endif
Modified: llvm/trunk/lib/Testing/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Testing/Support/CMakeLists.txt?rev=341502&r1=341501&r2=341502&view=diff
==============================================================================
--- llvm/trunk/lib/Testing/Support/CMakeLists.txt (original)
+++ llvm/trunk/lib/Testing/Support/CMakeLists.txt Wed Sep 5 16:30:17 2018
@@ -3,6 +3,7 @@ add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
add_llvm_library(LLVMTestingSupport
Error.cpp
+ SupportHelpers.cpp
BUILDTREE_ONLY
Added: llvm/trunk/lib/Testing/Support/SupportHelpers.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Testing/Support/SupportHelpers.cpp?rev=341502&view=auto
==============================================================================
--- llvm/trunk/lib/Testing/Support/SupportHelpers.cpp (added)
+++ llvm/trunk/lib/Testing/Support/SupportHelpers.cpp Wed Sep 5 16:30:17 2018
@@ -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);
+}
Added: llvm/trunk/unittests/unittest.cfg.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/unittest.cfg.in?rev=341502&view=auto
==============================================================================
--- llvm/trunk/unittests/unittest.cfg.in (added)
+++ llvm/trunk/unittests/unittest.cfg.in Wed Sep 5 16:30:17 2018
@@ -0,0 +1 @@
+ at LLVM_UNITTEST_SOURCE_DIR@
More information about the llvm-commits
mailing list