diff hotspot/test/native/logging/test_logConfiguration.cpp @ 40902:395e1f3ec886

8157948: UL allows same log file with multiple file= Reviewed-by: dholmes, rehn
author mlarsson
date Mon, 29 Aug 2016 14:11:22 +0200
parents b3958b331451
children 9e0c6db4918a
line wrap: on
line diff
--- a/hotspot/test/native/logging/test_logConfiguration.cpp	Wed Aug 24 19:21:20 2016 +0300
+++ b/hotspot/test/native/logging/test_logConfiguration.cpp	Mon Aug 29 14:11:22 2016 +0200
@@ -308,3 +308,30 @@
   EXPECT_TRUE(string_contains_substring(msg, "No tag set matches selection(s):"));
   EXPECT_TRUE(string_contains_substring(msg, invalid_tagset));
 }
+
+TEST_F(LogConfigurationTest, output_name_normalization) {
+  const char* patterns[] = { "%s", "file=%s", "\"%s\"", "file=\"%s\"" };
+  char buf[1 * K];
+  for (size_t i = 0; i < ARRAY_SIZE(patterns); i++) {
+    int ret = jio_snprintf(buf, sizeof(buf), patterns[i], TestLogFileName);
+    ASSERT_NE(-1, ret);
+    set_log_config(buf, "logging=trace");
+    EXPECT_TRUE(is_described("#2: "));
+    EXPECT_TRUE(is_described(TestLogFileName));
+    EXPECT_FALSE(is_described("#3: "))
+        << "duplicate file output due to incorrect normalization for pattern: " << patterns[i];
+  }
+
+  // Make sure prefixes are ignored when used within quotes
+  // (this should create a log with "file=" in its filename)
+  int ret = jio_snprintf(buf, sizeof(buf), "\"file=%s\"", TestLogFileName);
+  ASSERT_NE(-1, ret);
+  set_log_config(buf, "logging=trace");
+  EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
+  set_log_config(buf, "all=off");
+
+  // Remove the extra log file created
+  ret = jio_snprintf(buf, sizeof(buf), "file=%s", TestLogFileName);
+  ASSERT_NE(-1, ret);
+  delete_file(buf);
+}