diff options
author | Zachary Turner <zturner@google.com> | 2018-09-05 23:30:17 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-09-05 23:30:17 +0000 |
commit | e9f1df84af2f50a2cde01f7f2333f12ae326f3c1 (patch) | |
tree | a7fbb3d14185cc8d4303e0214c2d3b941247768c /llvm/lib/Testing | |
parent | b29d42ee31832406dc8ab100935209e1f457458b (diff) | |
download | bcm5719-llvm-e9f1df84af2f50a2cde01f7f2333f12ae326f3c1.tar.gz bcm5719-llvm-e9f1df84af2f50a2cde01f7f2333f12ae326f3c1.zip |
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
llvm-svn: 341502
Diffstat (limited to 'llvm/lib/Testing')
-rw-r--r-- | llvm/lib/Testing/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Testing/Support/SupportHelpers.cpp | 36 |
2 files changed, 37 insertions, 0 deletions
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); +} |