test/hotspot/gtest/logging/test_logTag.cpp
author mlarsson
Mon, 19 Feb 2018 09:16:04 +0100
changeset 49015 a12c9536d8a6
parent 47216 71c04702a3d5
child 49163 580bb0b85f63
permissions -rw-r--r--
8176298: Log tags in -Xlog:help not sorted Reviewed-by: ecaspole, gtriantafill, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     1
/*
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, 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: 40656
diff changeset
    23
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    25
#include "logging/logTag.hpp"
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    26
#include "utilities/ostream.hpp"
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    27
#include "unittest.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    28
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    29
TEST(LogTag, from_string) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    30
  // Verify for all tags defined in LOG_TAG_LIST
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    31
#define LOG_TAG(tag) \
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    32
  EXPECT_EQ(PREFIX_LOG_TAG(tag), LogTag::from_string(#tag));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    33
  LOG_TAG_LIST
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    34
#undef LOG_TAG
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    35
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    36
  // Verify a couple of invalid strings parsing as invalid tags
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    37
  const char* invalid_tag[] = {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    38
    "bad tag", ".^@", "**", "*", "gcc", "+gc", "gc+", "gc+safepoint",
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    39
    "gc+safepoint=warning", "warning", "=info", "gcsafepointlogging",
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    40
    "gc+safepointlogging", "gclogging", "+", " gc", "logging ", ","
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    41
  };
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    42
  for (size_t i = 0; i < sizeof(invalid_tag) / sizeof(*invalid_tag); i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    43
    EXPECT_EQ(LogTag::__NO_TAG, LogTag::from_string(invalid_tag[i]))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    44
        << "'" << invalid_tag[i] << "' did not parse as an invalid tag";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    45
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    46
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    47
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    48
TEST(LogTag, name) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    49
  // Verify for each tag from the macro
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    50
#define LOG_TAG(tag) \
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    51
  EXPECT_STREQ(#tag, LogTag::name(PREFIX_LOG_TAG(tag)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    52
  LOG_TAG_LIST
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    53
#undef LOG_TAG
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    54
}
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    55
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    56
TEST(LogTag, list_tags) {
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    57
  char buf[LogTag::Count * 16] = {0};
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    58
  stringStream ss(buf, sizeof(buf));
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    59
  LogTag::list_tags(&ss);
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    60
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    61
  bool listed_tags[LogTag::Count] = { false };
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    62
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    63
  char* last_tag = NULL;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    64
  for (char* tag = buf; *tag != '\0';) {
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    65
    char* end = strpbrk(tag, ",\n");
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    66
    ASSERT_TRUE(end != NULL) <<  "line should end with newline";
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    67
    *end = '\0';
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    68
    if (*tag == ' ') {
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    69
      tag++;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    70
    }
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    71
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    72
    EXPECT_TRUE(last_tag == NULL || strcmp(last_tag, tag) < 0) << tag << " should be listed before " << last_tag;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    73
    listed_tags[LogTag::from_string(tag)] = true;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    74
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    75
    last_tag = tag;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    76
    tag = end + 1;
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    77
  }
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    78
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    79
  for (size_t i = 1; i < LogTag::Count; i++) {
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    80
    EXPECT_TRUE(listed_tags[i]) << "tag '" << LogTag::name(static_cast<LogTagType>(i)) << "' not listed!";
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    81
  }
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 47216
diff changeset
    82
}