# HG changeset patch # User kzhaldyb # Date 1482236363 -10800 # Tue Dec 20 15:19:23 2016 +0300 # Node ID 716158203d461ef05e314dd09659ecd121adfc91 # Parent 9802f36e363f1d866ccde2f3085bcf489b5bf2ab 8170936: Logging: LogFileOutput.invalid_file_test crashes when executed twice. Reviewed-by: duke diff --git a/test/native/logging/logTestUtils.inline.hpp b/test/native/logging/logTestUtils.inline.hpp --- a/test/native/logging/logTestUtils.inline.hpp +++ b/test/native/logging/logTestUtils.inline.hpp @@ -59,6 +59,21 @@ assert(!failed, "failed to create directory %s", name); } +static inline void delete_directory(const char* name) { +#ifdef _WINDOWS + if (!file_exists(name)) { + return; + } + bool failed; + failed = !RemoveDirectory(name); + EXPECT_FALSE(failed) << "failed to remove directory '" << name << "': " + << os::strerror(errno) << " (" << errno << "); LastError = " + << GetLastError(); +#else + delete_file(name); +#endif +} + static inline void init_log_file(const char* filename, const char* options = "") { LogStreamHandle(Error, logging) stream; bool success = LogConfiguration::parse_log_arguments(filename, "logging=trace", "", options, &stream); diff --git a/test/native/logging/test_logFileOutput.cpp b/test/native/logging/test_logFileOutput.cpp --- a/test/native/logging/test_logFileOutput.cpp +++ b/test/native/logging/test_logFileOutput.cpp @@ -103,7 +103,7 @@ EXPECT_FALSE(fo.initialize(buf, &ss)) << "Accepted filesize that overflows"; } -TEST(LogFileOutput, startup_rotation) { +TEST_VM(LogFileOutput, startup_rotation) { const size_t rotations = 5; const char* filename = "start-rotate-test"; char* rotated_file[rotations]; @@ -140,7 +140,7 @@ } } -TEST(LogFileOutput, startup_truncation) { +TEST_VM(LogFileOutput, startup_truncation) { const char* filename = "start-truncate-test"; const char* archived_filename = "start-truncate-test.0"; @@ -168,7 +168,7 @@ delete_file(archived_filename); } -TEST(LogFileOutput, invalid_file) { +TEST_VM(LogFileOutput, invalid_file) { ResourceMark rm; stringStream ss; @@ -179,5 +179,5 @@ << "file was initialized when there was an existing directory with the same name"; EXPECT_TRUE(string_contains_substring(ss.as_string(), "tmplogdir is not a regular file")) << "missing expected error message, received msg: %s" << ss.as_string(); - remove("tmplogdir"); + delete_directory("tmplogdir"); }