# HG changeset patch # User kzhaldyb # Date 1482310317 -10800 # Node ID e440bfad5d9adaaea35004aa3c13b2d7efcbe7c7 # Parent 22186844c94cfcb489e6d8a2d6abe1f7f7e58aca 8170936: Logging: LogFileOutput.invalid_file_test crashes when executed twice. Reviewed-by: iignatyev, stuefe diff -r 22186844c94c -r e440bfad5d9a hotspot/test/native/logging/logTestUtils.inline.hpp --- a/hotspot/test/native/logging/logTestUtils.inline.hpp Wed Dec 21 11:51:57 2016 +0300 +++ b/hotspot/test/native/logging/logTestUtils.inline.hpp Wed Dec 21 11:51:57 2016 +0300 @@ -59,6 +59,20 @@ assert(!failed, "failed to create directory %s", name); } +static inline void delete_empty_directory(const char* name) { +#ifdef _WINDOWS + if (!file_exists(name)) { + return; + } + bool failed; + failed = !RemoveDirectory(name); + EXPECT_FALSE(failed) << "failed to remove directory '" << name + << "': 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 -r 22186844c94c -r e440bfad5d9a hotspot/test/native/logging/test_logFileOutput.cpp --- a/hotspot/test/native/logging/test_logFileOutput.cpp Wed Dec 21 11:51:57 2016 +0300 +++ b/hotspot/test/native/logging/test_logFileOutput.cpp Wed Dec 21 11:51:57 2016 +0300 @@ -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_empty_directory("tmplogdir"); }