changeset 10210:535178906f68

8149112: configure_stdout test depends on VM arguments Reviewed-by: ehelin, jbachorik
author mlarsson
date Tue, 09 Feb 2016 12:19:05 +0100
parents 2a8e87190908
children fe043f3261cc e3e5642da773
files src/share/vm/logging/log.cpp
diffstat 1 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/logging/log.cpp	Mon Feb 08 18:26:27 2016 +0300
+++ b/src/share/vm/logging/log.cpp	Tue Feb 09 12:19:05 2016 +0100
@@ -30,6 +30,7 @@
 
 #include "logging/log.hpp"
 #include "logging/logConfiguration.hpp"
+#include "logging/logOutput.hpp"
 #include "memory/resourceArea.hpp"
 
 void Test_log_length() {
@@ -92,11 +93,47 @@
   remove("loglengthoutput.txt");
 }
 
+#define assert_str_eq(s1, s2) \
+  assert(strcmp(s1, s2) == 0, "Expected '%s' to equal '%s'", s1, s2)
+
+#define assert_char_in(c, s) \
+  assert(strchr(s, c) != NULL, "Expected '%s' to contain character '%c'", s, c)
+
+#define assert_char_not_in(c, s) \
+  assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
+
 void Test_configure_stdout() {
+  ResourceMark rm;
+  LogHandle(logging) log;
+  LogOutput* stdoutput = LogOutput::Stdout;
+
+  // Save current stdout config and clear it
+  char* saved_config = os::strdup_check_oom(stdoutput->config_string());
+  LogConfiguration::parse_log_arguments("stdout", "all=off", NULL, NULL, log.error_stream());
+
+  // Enable 'logging=info', verifying it has been set
   LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
-  assert(log_is_enabled(Info, logging), "configure_stdout did not enable requested logging");
-  assert(!log_is_enabled(Info, logging, gc), "configure_stdout enabled too much logging");
-  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(logging));
-  assert(!log_is_enabled(Info, logging), "configure_stdout did not disable requested logging");
+  assert_str_eq("logging=info,", stdoutput->config_string());
+  assert(log_is_enabled(Info, logging), "logging was not properly enabled");
+
+  // Enable 'gc=debug' (no wildcard), verifying no other tags are enabled
+  LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
+  // No '+' character means only single tags are enabled, and no combinations
+  assert_char_not_in('+', stdoutput->config_string());
+  assert(log_is_enabled(Debug, gc), "logging was not properly enabled");
+
+  // Enable 'gc*=trace' (with wildcard), verifying at least one tag combination is enabled (gc+...)
+  LogConfiguration::configure_stdout(LogLevel::Trace, false, LOG_TAGS(gc));
+  assert_char_in('+', stdoutput->config_string());
+  assert(log_is_enabled(Trace, gc), "logging was not properly enabled");
+
+  // Disable 'gc*' and 'logging', verifying all logging is properly disabled
+  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc));
+  LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging));
+  assert_str_eq("all=off", stdoutput->config_string());
+
+  // Restore saved configuration
+  LogConfiguration::parse_log_arguments("stdout", saved_config, NULL, NULL, log.error_stream());
+  os::free(saved_config);
 }
 #endif // PRODUCT