test/hotspot/gtest/logging/test_logConfiguration.cpp
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
child 49180 9637557def32
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     1
/*
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 43431
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     4
 *
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     8
 *
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    13
 * accompanied this code).
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    14
 *
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    18
 *
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    21
 * questions.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    22
 */
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41680
diff changeset
    23
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    25
#include "jvm.h"
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    26
#include "logTestFixture.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    27
#include "logTestUtils.inline.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    28
#include "logging/logConfiguration.hpp"
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
    29
#include "logging/logFileStreamOutput.hpp"
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    30
#include "logging/logLevel.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    31
#include "logging/logOutput.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    32
#include "logging/logTag.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    33
#include "logging/logTagSet.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    34
#include "memory/resourceArea.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    35
#include "unittest.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    36
#include "utilities/ostream.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    37
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    38
class LogConfigurationTest : public LogTestFixture {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    39
 protected:
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    40
  static char _all_decorators[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    41
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    42
 public:
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    43
  static void SetUpTestCase();
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    44
};
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    45
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    46
char LogConfigurationTest::_all_decorators[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    47
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    48
// Prepare _all_decorators to contain the full list of decorators (comma separated)
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    49
void LogConfigurationTest::SetUpTestCase() {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    50
  char *pos = _all_decorators;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    51
  for (size_t i = 0; i < LogDecorators::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    52
    pos += jio_snprintf(pos, sizeof(_all_decorators) - (pos - _all_decorators), "%s%s",
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    53
                        (i == 0 ? "" : ","),
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    54
                        LogDecorators::name(static_cast<LogDecorators::Decorator>(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    55
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    56
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    57
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    58
// Check if the given text is included by LogConfiguration::describe()
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    59
static bool is_described(const char* text) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    60
  ResourceMark rm;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    61
  stringStream ss;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    62
  LogConfiguration::describe(&ss);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    63
  return string_contains_substring(ss.as_string(), text);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    64
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    65
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
    66
TEST_VM_F(LogConfigurationTest, describe) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    67
  ResourceMark rm;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    68
  stringStream ss;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    69
  LogConfiguration::describe(&ss);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    70
  const char* description = ss.as_string();
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    71
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    72
  // Verify that stdout and stderr are listed by default
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
    73
  EXPECT_PRED2(string_contains_substring, description, StdoutLog.name());
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
    74
  EXPECT_PRED2(string_contains_substring, description, StderrLog.name());
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    75
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    76
  // Verify that each tag, level and decorator is listed
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    77
  for (size_t i = 0; i < LogTag::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    78
    EXPECT_PRED2(string_contains_substring, description, LogTag::name(static_cast<LogTagType>(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    79
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    80
  for (size_t i = 0; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    81
    EXPECT_PRED2(string_contains_substring, description, LogLevel::name(static_cast<LogLevelType>(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    82
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    83
  for (size_t i = 0; i < LogDecorators::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    84
    EXPECT_PRED2(string_contains_substring, description, LogDecorators::name(static_cast<LogDecorators::Decorator>(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    85
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    86
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    87
  // Verify that the default configuration is printed
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    88
  char expected_buf[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    89
  int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "=%s", LogLevel::name(LogLevel::Default));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    90
  ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    91
  EXPECT_PRED2(string_contains_substring, description, expected_buf);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    92
  EXPECT_PRED2(string_contains_substring, description, "#1: stderr all=off");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    93
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    94
  // Verify default decorators are listed
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    95
  LogDecorators default_decorators;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    96
  expected_buf[0] = '\0';
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    97
  for (size_t i = 0; i < LogDecorators::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    98
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    99
    if (default_decorators.is_decorator(d)) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   100
      ASSERT_LT(strlen(expected_buf), sizeof(expected_buf));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   101
      ret = jio_snprintf(expected_buf + strlen(expected_buf),
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   102
                         sizeof(expected_buf) - strlen(expected_buf),
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   103
                         "%s%s",
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   104
                         strlen(expected_buf) > 0 ? "," : "",
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   105
                         LogDecorators::name(d));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   106
      ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   107
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   108
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   109
  EXPECT_PRED2(string_contains_substring, description, expected_buf);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   110
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   111
  // Add a new output and verify that it gets described after it has been added
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   112
  const char* what = "all=trace";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   113
  EXPECT_FALSE(is_described(TestLogFileName)) << "Test output already exists!";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   114
  set_log_config(TestLogFileName, what);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   115
  EXPECT_TRUE(is_described(TestLogFileName));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   116
  EXPECT_TRUE(is_described("logging=trace"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   117
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   118
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   119
// Test updating an existing log output
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   120
TEST_VM_F(LogConfigurationTest, update_output) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   121
  // Update stdout twice, first using it's name, and the second time its index #
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   122
  const char* test_outputs[] = { "stdout", "#0" };
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   123
  for (size_t i = 0; i < ARRAY_SIZE(test_outputs); i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   124
    set_log_config(test_outputs[i], "all=info");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   125
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   126
    // Verify configuration using LogConfiguration::describe
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   127
    EXPECT_TRUE(is_described("#0: stdout"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   128
    EXPECT_TRUE(is_described("logging=info"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   129
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   130
    // Verify by iterating over tagsets
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   131
    LogOutput* o = &StdoutLog;
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   132
    for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   133
      EXPECT_TRUE(ts->has_output(o));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   134
      EXPECT_TRUE(ts->is_level(LogLevel::Info));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   135
      EXPECT_FALSE(ts->is_level(LogLevel::Debug));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   136
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   137
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   138
    // Now change the level and verify the change propagated
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   139
    set_log_config(test_outputs[i], "all=debug");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   140
    for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   141
      EXPECT_TRUE(ts->has_output(o));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   142
      EXPECT_TRUE(ts->is_level(LogLevel::Debug));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   143
      EXPECT_FALSE(ts->is_level(LogLevel::Trace));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   144
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   145
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   146
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   147
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   148
// Test adding a new output to the configuration
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   149
TEST_VM_F(LogConfigurationTest, add_new_output) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   150
  const char* what = "all=trace";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   151
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   152
  ASSERT_FALSE(is_described(TestLogFileName));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   153
  set_log_config(TestLogFileName, what);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   154
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   155
  // Verify new output using LogConfiguration::describe
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   156
  EXPECT_TRUE(is_described(TestLogFileName));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   157
  EXPECT_TRUE(is_described("logging=trace"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   158
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   159
  // Also verify by iterating over tagsets, checking levels on tagsets
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   160
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   161
    EXPECT_TRUE(ts->is_level(LogLevel::Trace));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   162
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   163
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   164
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   165
TEST_VM_F(LogConfigurationTest, disable_logging) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   166
  // Add TestLogFileName as an output
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   167
  set_log_config(TestLogFileName, "logging=info");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   168
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   169
  // Add a second file output
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   170
  char other_file_name[2 * K];
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   171
  jio_snprintf(other_file_name, sizeof(other_file_name), "%s-other", TestLogFileName);
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   172
  set_log_config(other_file_name, "logging=info");
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   173
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   174
  LogConfiguration::disable_logging();
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   175
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   176
  // Verify that both file outputs were disabled
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   177
  EXPECT_FALSE(is_described(TestLogFileName));
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   178
  EXPECT_FALSE(is_described(other_file_name));
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   179
  delete_file(other_file_name);
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   180
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   181
  // Verify that no tagset has logging enabled
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   182
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   183
    EXPECT_FALSE(ts->has_output(&StdoutLog));
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   184
    EXPECT_FALSE(ts->has_output(&StderrLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   185
    EXPECT_FALSE(ts->is_level(LogLevel::Error));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   186
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   187
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   188
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   189
// Test disabling a particular output
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   190
TEST_VM_F(LogConfigurationTest, disable_output) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   191
  // Disable the default configuration for stdout
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   192
  set_log_config("stdout", "all=off");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   193
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   194
  // Verify configuration using LogConfiguration::describe
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   195
  EXPECT_TRUE(is_described("#0: stdout all=off"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   196
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   197
  // Verify by iterating over tagsets
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   198
  LogOutput* o = &StdoutLog;
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   199
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   200
    EXPECT_FALSE(ts->has_output(o));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   201
    EXPECT_FALSE(ts->is_level(LogLevel::Error));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   202
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   203
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   204
  // Add a new file output
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   205
  const char* what = "all=debug";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   206
  set_log_config(TestLogFileName, what);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   207
  EXPECT_TRUE(is_described(TestLogFileName));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   208
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   209
  // Now disable it, verifying it is removed completely
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   210
  set_log_config(TestLogFileName, "all=off");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   211
  EXPECT_FALSE(is_described(TestLogFileName));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   212
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   213
    EXPECT_FALSE(ts->is_level(LogLevel::Error));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   214
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   215
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   216
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   217
// Test reconfiguration of the selected decorators for an output
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   218
TEST_VM_F(LogConfigurationTest, reconfigure_decorators) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   219
  // Configure stderr with all decorators
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   220
  set_log_config("stderr", "all=off", _all_decorators);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   221
  char buf[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   222
  int ret = jio_snprintf(buf, sizeof(buf), "#1: stderr all=off %s", _all_decorators);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   223
  ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   224
  EXPECT_TRUE(is_described(buf)) << "'" << buf << "' not described after reconfiguration";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   225
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   226
  // Now reconfigure logging on stderr with no decorators
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   227
  set_log_config("stderr", "all=off", "none");
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   228
  EXPECT_TRUE(is_described("#1: stderr all=off \n")) << "Expecting no decorators";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   229
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   230
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   231
// Test that invalid options cause configuration errors
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   232
TEST_VM_F(LogConfigurationTest, invalid_configure_options) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   233
  LogConfiguration::disable_logging();
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   234
  const char* invalid_outputs[] = { "#2", "invalidtype=123", ":invalid/path}to*file?" };
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   235
  for (size_t i = 0; i < ARRAY_SIZE(invalid_outputs); i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   236
    EXPECT_FALSE(set_log_config(invalid_outputs[i], "", "", "", true))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   237
      << "Accepted invalid output '" << invalid_outputs[i] << "'";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   238
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   239
  EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("all=invalid_level"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   240
  EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("what=invalid"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   241
  EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("all::invalid_decorator"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   242
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   243
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   244
// Test empty configuration options
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   245
TEST_VM_F(LogConfigurationTest, parse_empty_command_line_arguments) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   246
  const char* empty_variations[] = { "", ":", "::", ":::", "::::" };
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   247
  for (size_t i = 0; i < ARRAY_SIZE(empty_variations); i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   248
    const char* cmdline = empty_variations[i];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   249
    bool ret = LogConfiguration::parse_command_line_arguments(cmdline);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   250
    EXPECT_TRUE(ret) << "Error parsing command line arguments '" << cmdline << "'";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   251
    for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   252
      EXPECT_EQ(LogLevel::Unspecified, ts->level_for(&StdoutLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   253
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   254
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   255
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   256
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   257
// Test basic command line parsing & configuration
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   258
TEST_VM_F(LogConfigurationTest, parse_command_line_arguments) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   259
  // Prepare a command line for logging*=debug on stderr with all decorators
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   260
  int ret;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   261
  char buf[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   262
  ret = jio_snprintf(buf, sizeof(buf), "logging*=debug:stderr:%s", _all_decorators);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   263
  ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   264
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   265
  bool success = LogConfiguration::parse_command_line_arguments(buf);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   266
  EXPECT_TRUE(success) << "Error parsing valid command line arguments '" << buf << "'";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   267
  // Ensure the new configuration applied
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   268
  EXPECT_TRUE(is_described("logging=debug"));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   269
  EXPECT_TRUE(is_described(_all_decorators));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   270
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   271
  // Test the configuration of file outputs as well
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   272
  ret = jio_snprintf(buf, sizeof(buf), ":%s", TestLogFileName);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   273
  ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   274
  EXPECT_TRUE(LogConfiguration::parse_command_line_arguments(buf));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   275
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   276
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   277
// Test split up log configuration arguments
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   278
TEST_VM_F(LogConfigurationTest, parse_log_arguments) {
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   279
  ResourceMark rm;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   280
  stringStream ss;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   281
  // Verify that it's possible to configure each individual tag
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   282
  for (size_t t = 1 /* Skip _NO_TAG */; t < LogTag::Count; t++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   283
    const LogTagType tag = static_cast<LogTagType>(t);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   284
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("stdout", LogTag::name(tag), "", "", &ss));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   285
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   286
  // Same for each level
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   287
  for (size_t l = 0; l < LogLevel::Count; l++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   288
    const LogLevelType level = static_cast<LogLevelType>(l);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   289
    char expected_buf[256];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   290
    int ret = jio_snprintf(expected_buf, sizeof(expected_buf), "all=%s", LogLevel::name(level));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   291
    ASSERT_NE(-1, ret);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   292
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("stderr", expected_buf, "", "", &ss));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   293
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   294
  // And for each decorator
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   295
  for (size_t d = 0; d < LogDecorators::Count; d++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   296
    const LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   297
    EXPECT_TRUE(LogConfiguration::parse_log_arguments("#0", "", LogDecorators::name(decorator), "", &ss));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   298
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   299
}
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   300
43431
5ffa076f526d 8172098: A lot of gtests uses TEST instead of TEST_VM
kzhaldyb
parents: 42067
diff changeset
   301
TEST_VM_F(LogConfigurationTest, configure_stdout) {
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   302
  // Start out with all logging disabled
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   303
  LogConfiguration::disable_logging();
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   304
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   305
  // Enable 'logging=info', verifying it has been set
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   306
  LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   307
  EXPECT_TRUE(log_is_enabled(Info, logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   308
  EXPECT_FALSE(log_is_enabled(Debug, logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   309
  EXPECT_FALSE(log_is_enabled(Info, gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   310
  LogTagSet* logging_ts = &LogTagSetMapping<LOG_TAGS(logging)>::tagset();
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   311
  EXPECT_EQ(LogLevel::Info, logging_ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   312
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   313
  // Enable 'gc=debug' (no wildcard), verifying no other tags are enabled
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   314
  LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   315
  EXPECT_TRUE(log_is_enabled(Debug, gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   316
  EXPECT_TRUE(log_is_enabled(Info, logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   317
  EXPECT_FALSE(log_is_enabled(Debug, gc, heap));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   318
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   319
    if (ts->contains(PREFIX_LOG_TAG(gc))) {
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   320
      if (ts->ntags() == 1) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   321
        EXPECT_EQ(LogLevel::Debug, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   322
      } else {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   323
        EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   324
      }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   325
    }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   326
  }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   327
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   328
  // Enable 'gc*=trace' (with wildcard), verifying that all tag combinations with gc are enabled (gc+...)
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   329
  LogConfiguration::configure_stdout(LogLevel::Trace, false, LOG_TAGS(gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   330
  EXPECT_TRUE(log_is_enabled(Trace, gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   331
  EXPECT_TRUE(log_is_enabled(Trace, gc, heap));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   332
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   333
    if (ts->contains(PREFIX_LOG_TAG(gc))) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   334
      EXPECT_EQ(LogLevel::Trace, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   335
    } else if (ts == logging_ts) {
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   336
      // Previous setting for 'logging' should remain
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   337
      EXPECT_EQ(LogLevel::Info, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   338
    } else {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   339
      EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   340
    }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   341
  }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   342
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   343
  // Disable 'gc*' and 'logging', verifying all logging is properly disabled
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   344
  LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   345
  EXPECT_FALSE(log_is_enabled(Error, logging));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   346
  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   347
  EXPECT_FALSE(log_is_enabled(Error, gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   348
  EXPECT_FALSE(log_is_enabled(Error, gc, heap));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   349
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   350
    EXPECT_EQ(LogLevel::Off, ts->level_for(&StdoutLog));
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   351
  }
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   352
}
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   353
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   354
static int Test_logconfiguration_subscribe_triggered = 0;
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   355
static void Test_logconfiguration_subscribe_helper() {
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   356
  Test_logconfiguration_subscribe_triggered++;
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   357
}
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   358
43431
5ffa076f526d 8172098: A lot of gtests uses TEST instead of TEST_VM
kzhaldyb
parents: 42067
diff changeset
   359
TEST_VM_F(LogConfigurationTest, subscribe) {
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   360
  ResourceMark rm;
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   361
  Log(logging) log;
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   362
  set_log_config("stdout", "logging*=trace");
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   363
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   364
  LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper);
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   365
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46560
diff changeset
   366
  LogStream ls(log.error());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46560
diff changeset
   367
  LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, &ls);
41680
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   368
  ASSERT_EQ(1, Test_logconfiguration_subscribe_triggered);
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   369
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   370
  LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   371
  ASSERT_EQ(2, Test_logconfiguration_subscribe_triggered);
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   372
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   373
  LogConfiguration::disable_logging();
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   374
  ASSERT_EQ(3, Test_logconfiguration_subscribe_triggered);
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   375
}
bb5ec2c00465 8165600: Convert internal logging tests to GTest
mlarsson
parents: 41671
diff changeset
   376
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   377
TEST_VM_F(LogConfigurationTest, parse_invalid_tagset) {
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   378
  static const char* invalid_tagset = "logging+start+exit+safepoint+gc"; // Must not exist for test to function.
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   379
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   380
  // Make sure warning is produced if one or more configured tagsets are invalid
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   381
  ResourceMark rm;
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   382
  stringStream ss;
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   383
  bool success = LogConfiguration::parse_log_arguments("stdout", invalid_tagset, NULL, NULL, &ss);
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   384
  const char* msg = ss.as_string();
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   385
  EXPECT_TRUE(success) << "Should only cause a warning, not an error";
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   386
  EXPECT_TRUE(string_contains_substring(msg, "No tag set matches selection(s):"));
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   387
  EXPECT_TRUE(string_contains_substring(msg, invalid_tagset));
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 40656
diff changeset
   388
}
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   389
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 40902
diff changeset
   390
TEST_VM_F(LogConfigurationTest, output_name_normalization) {
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   391
  const char* patterns[] = { "%s", "file=%s", "\"%s\"", "file=\"%s\"" };
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   392
  char buf[1 * K];
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   393
  for (size_t i = 0; i < ARRAY_SIZE(patterns); i++) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   394
    int ret = jio_snprintf(buf, sizeof(buf), patterns[i], TestLogFileName);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   395
    ASSERT_NE(-1, ret);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   396
    set_log_config(buf, "logging=trace");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   397
    EXPECT_TRUE(is_described("#2: "));
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   398
    EXPECT_TRUE(is_described(TestLogFileName));
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   399
    EXPECT_FALSE(is_described("#3: "))
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   400
        << "duplicate file output due to incorrect normalization for pattern: " << patterns[i];
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   401
  }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   402
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   403
  // Make sure prefixes are ignored when used within quotes
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   404
  // (this should create a log with "file=" in its filename)
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   405
  int ret = jio_snprintf(buf, sizeof(buf), "\"file=%s\"", TestLogFileName);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   406
  ASSERT_NE(-1, ret);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   407
  set_log_config(buf, "logging=trace");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   408
  EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   409
  set_log_config(buf, "all=off");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   410
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   411
  // Remove the extra log file created
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   412
  ret = jio_snprintf(buf, sizeof(buf), "file=%s", TestLogFileName);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   413
  ASSERT_NE(-1, ret);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   414
  delete_file(buf);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   415
}