summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/raw_pwrite_stream_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/raw_pwrite_stream_test.cpp')
-rw-r--r--llvm/unittests/Support/raw_pwrite_stream_test.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/llvm/unittests/Support/raw_pwrite_stream_test.cpp b/llvm/unittests/Support/raw_pwrite_stream_test.cpp
index a62f6bacb07..88855675253 100644
--- a/llvm/unittests/Support/raw_pwrite_stream_test.cpp
+++ b/llvm/unittests/Support/raw_pwrite_stream_test.cpp
@@ -10,10 +10,20 @@
#include "gtest/gtest.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ errs() << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ } else { \
+ }
+
+
namespace {
TEST(raw_pwrite_ostreamTest, TestSVector) {
@@ -32,10 +42,28 @@ TEST(raw_pwrite_ostreamTest, TestSVector) {
#endif
}
+#ifdef _MSC_VER
+#define setenv(name, var, ignore) _putenv_s(name, var)
+#endif
+
TEST(raw_pwrite_ostreamTest, TestFD) {
SmallString<64> Path;
int FD;
- sys::fs::createTemporaryFile("foo", "bar", FD, Path);
+
+ // If we want to clean up from a death test, we have to remove the file from
+ // the parent process. Have the parent create the file, pass it via
+ // environment variable to the child, let the child crash, and then remove it
+ // in the parent.
+ const char *ParentPath = getenv("RAW_PWRITE_TEST_FILE");
+ if (ParentPath) {
+ Path = ParentPath;
+ ASSERT_NO_ERROR(sys::fs::openFileForRead(Path, FD));
+ } else {
+ ASSERT_NO_ERROR(sys::fs::createTemporaryFile("foo", "bar", FD, Path));
+ setenv("RAW_PWRITE_TEST_FILE", Path.c_str(), true);
+ }
+ FileRemover Cleanup(Path);
+
raw_fd_ostream OS(FD, true);
OS << "abcd";
StringRef Test = "test";
OpenPOWER on IntegriCloud