summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/raw_pwrite_stream_test.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-09-02 00:51:34 +0000
committerReid Kleckner <rnk@google.com>2016-09-02 00:51:34 +0000
commit75e557f1fd9392a20989e57d31eaa1878f7ca9c1 (patch)
treea461719db45df760167f6def422e480352ad58c3 /llvm/unittests/Support/raw_pwrite_stream_test.cpp
parent1200a050ff59e16631972e25e93f24d34b982115 (diff)
downloadbcm5719-llvm-75e557f1fd9392a20989e57d31eaa1878f7ca9c1.tar.gz
bcm5719-llvm-75e557f1fd9392a20989e57d31eaa1878f7ca9c1.zip
Try to fix some temp file leaks in SupportTests, PR18335
llvm-svn: 280443
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