changeset 42909:e440bfad5d9a

8170936: Logging: LogFileOutput.invalid_file_test crashes when executed twice. Reviewed-by: iignatyev, stuefe
author kzhaldyb
date Wed, 21 Dec 2016 11:51:57 +0300
parents 22186844c94c
children 1196b2e0adca 2e9f2cc24de3
files hotspot/test/native/logging/logTestUtils.inline.hpp hotspot/test/native/logging/test_logFileOutput.cpp
diffstat 2 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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");
 }