test/hotspot/gtest/logging/test_logOutputList.cpp
author stefank
Tue, 28 Nov 2017 21:43:45 +0100
changeset 48157 7c4d43c26352
parent 47216 71c04702a3d5
permissions -rw-r--r--
8192061: Clean up allocation.inline.hpp includes Reviewed-by: eosterlund, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     1
/*
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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"
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
    25
#include "logging/logFileStreamOutput.hpp"
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    26
#include "logging/logLevel.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    27
#include "logging/logOutput.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    28
#include "logging/logOutputList.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    29
#include "runtime/os.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    30
#include "unittest.hpp"
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    31
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    32
// Count the outputs in the given list, starting from the specified level
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    33
static size_t output_count(LogOutputList* list, LogLevelType from = LogLevel::Error)  {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    34
  size_t count = 0;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    35
  for (LogOutputList::Iterator it = list->iterator(from); it != list->end(); it++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    36
    count++;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    37
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    38
  return count;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    39
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    40
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    41
// Get the level for an output in the given list
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    42
static LogLevelType find_output_level(LogOutputList* list, LogOutput* o) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    43
  for (size_t levelnum = 1; levelnum < LogLevel::Count; levelnum++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    44
    LogLevelType level = static_cast<LogLevelType>(levelnum);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    45
    for (LogOutputList::Iterator it = list->iterator(level); it != list->end(); it++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    46
      if (*it == o) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    47
        return level;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    48
      }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    49
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    50
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    51
  return LogLevel::Off;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    52
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    53
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    54
// Create a dummy output pointer with the specified id.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    55
// This dummy pointer should not be used for anything
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    56
// but pointer comparisons with other dummies.
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    57
static LogOutput* dummy_output(size_t id) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    58
  return reinterpret_cast<LogOutput*>(id + 1);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    59
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    60
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    61
// Randomly update and verify some outputs some number of times
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    62
TEST(LogOutputList, set_output_level_update) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    63
  const size_t TestOutputCount = 10;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    64
  const size_t TestIterations = 10000;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    65
  LogOutputList list;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    66
  size_t outputs_on_level[LogLevel::Count];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    67
  LogLevelType expected_level_for_output[TestOutputCount];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    68
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    69
  os::init_random(0x4711);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    70
  for (size_t i = 0; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    71
    outputs_on_level[i] = 0;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    72
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    73
  outputs_on_level[LogLevel::Off] = TestOutputCount;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    74
  for (size_t i = 0; i < TestOutputCount; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    75
    expected_level_for_output[i] = LogLevel::Off;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    76
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    77
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    78
  for (size_t iteration = 0; iteration < TestIterations; iteration++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    79
    size_t output_idx = os::random() % TestOutputCount;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    80
    size_t levelnum = os::random() % LogLevel::Count;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    81
    LogLevelType level = static_cast<LogLevelType>(levelnum);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    82
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    83
    // Update the expectations
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    84
    outputs_on_level[expected_level_for_output[output_idx]]--;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    85
    outputs_on_level[levelnum]++;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    86
    expected_level_for_output[output_idx] = level;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    87
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    88
    // Update the actual list
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    89
    list.set_output_level(dummy_output(output_idx), level);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    90
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    91
    // Verify expected levels
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    92
    for (size_t i = 0; i < TestOutputCount; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    93
      ASSERT_EQ(expected_level_for_output[i], find_output_level(&list, dummy_output(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    94
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    95
    // Verify output counts
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    96
    size_t expected_count = 0;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    97
    for (size_t i = 1; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    98
      expected_count += outputs_on_level[i];
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
    99
      ASSERT_EQ(expected_count, output_count(&list, static_cast<LogLevelType>(i)));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   100
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   101
    ASSERT_EQ(TestOutputCount, expected_count + outputs_on_level[LogLevel::Off]);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   102
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   103
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   104
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   105
// Test removing outputs from a LogOutputList
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   106
TEST(LogOutputList, set_output_level_remove) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   107
  LogOutputList list;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   108
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   109
  // Add three dummy outputs per loglevel
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   110
  for (size_t i = 1; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   111
    list.set_output_level(dummy_output(i), static_cast<LogLevelType>(i));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   112
    list.set_output_level(dummy_output(i*10), static_cast<LogLevelType>(i));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   113
    list.set_output_level(dummy_output(i*100), static_cast<LogLevelType>(i));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   114
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   115
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   116
  // Verify that they have been added successfully
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   117
  // (Count - 1 since we don't count LogLevel::Off)
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   118
  EXPECT_EQ(3u * (LogLevel::Count - 1), output_count(&list));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   119
  // Now remove the second output from each loglevel
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   120
  for (size_t i = 1; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   121
    list.set_output_level(dummy_output(i*10), LogLevel::Off);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   122
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   123
  // Make sure they have been successfully removed
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   124
  EXPECT_EQ(2u * (LogLevel::Count - 1), output_count(&list));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   125
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   126
  // Now remove the remaining outputs
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   127
  for (size_t i = 1; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   128
    list.set_output_level(dummy_output(i), LogLevel::Off);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   129
    list.set_output_level(dummy_output(i*100), LogLevel::Off);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   130
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   131
  EXPECT_EQ(0u, output_count(&list));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   132
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   133
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   134
// Test adding to a LogOutputList
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   135
TEST(LogOutputList, set_output_level_add) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   136
  LogOutputList list;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   137
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   138
  // First add 5 outputs to Info level
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   139
  for (size_t i = 10; i < 15; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   140
    list.set_output_level(dummy_output(i), LogLevel::Info);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   141
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   142
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   143
  // Verify that they have been added successfully
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   144
  size_t count = 0;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   145
  for (LogOutputList::Iterator it = list.iterator(); it != list.end(); it++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   146
    ASSERT_EQ(dummy_output(10 + count++), *it);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   147
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   148
  ASSERT_EQ(5u, count);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   149
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   150
  // Now add more outputs, but on all different levels
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   151
  for (size_t i = 5; i < 10; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   152
    list.set_output_level(dummy_output(i), LogLevel::Warning);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   153
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   154
  for (size_t i = 0; i < 5; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   155
    list.set_output_level(dummy_output(i), LogLevel::Error);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   156
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   157
  for (size_t i = 15; i < 20; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   158
    list.set_output_level(dummy_output(i), LogLevel::Debug);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   159
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   160
  for (size_t i = 20; i < 25; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   161
    list.set_output_level(dummy_output(i), 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
  // Verify that that all outputs have been added, and that the order is Error, Warning, Info, Debug, Trace
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   165
  count = 0;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   166
  for (LogOutputList::Iterator it = list.iterator(); it != list.end(); it++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   167
    ASSERT_EQ(dummy_output(count++), *it);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   168
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   169
  ASSERT_EQ(25u, count);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   170
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   171
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   172
// Test is_level() on lists with a single output on different levels
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   173
TEST(LogOutputList, is_level_single_output) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   174
  for (size_t i = LogLevel::First; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   175
    LogLevelType level = static_cast<LogLevelType>(i);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   176
    LogOutputList list;
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   177
    list.set_output_level(&StdoutLog, level);
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   178
    for (size_t j = LogLevel::First; j < LogLevel::Count; j++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   179
      LogLevelType other = static_cast<LogLevelType>(j);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   180
      // Verify that levels finer than the current level for stdout are reported as disabled,
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   181
      // and levels equal to or included in the current level are reported as enabled
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   182
      if (other >= level) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   183
        EXPECT_TRUE(list.is_level(other))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   184
          << LogLevel::name(other) << " >= " << LogLevel::name(level) << " but is_level() returns false";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   185
      } else {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   186
        EXPECT_FALSE(list.is_level(other))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   187
          << LogLevel::name(other) << " < " << LogLevel::name(level) << " but is_level() returns true";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   188
      }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   189
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   190
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   191
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   192
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   193
// Test is_level() with an empty list
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   194
TEST(LogOutputList, is_level_empty) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   195
  LogOutputList emptylist;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   196
  for (size_t i = LogLevel::First; i < LogLevel::Count; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   197
    LogLevelType other = static_cast<LogLevelType>(i);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   198
    EXPECT_FALSE(emptylist.is_level(other)) << "is_level() returns true even though the list is empty";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   199
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   200
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   201
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   202
// Test is_level() on lists with two outputs on different levels
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   203
TEST(LogOutputList, is_level_multiple_outputs) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   204
  for (size_t i = LogLevel::First; i < LogLevel::Count - 1; i++) {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   205
      LogOutput* dummy1 = &StdoutLog;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   206
      LogOutput* dummy2 = &StderrLog;
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   207
      LogLevelType first = static_cast<LogLevelType>(i);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   208
      LogLevelType second = static_cast<LogLevelType>(i + 1);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   209
      LogOutputList list;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   210
      list.set_output_level(dummy1, first);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   211
      list.set_output_level(dummy2, second);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   212
      for (size_t j = LogLevel::First; j < LogLevel::Count; j++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   213
        LogLevelType other = static_cast<LogLevelType>(j);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   214
        // The first output's level will be the finest, expect it's level to be reported by the list
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   215
        if (other >= first) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   216
          EXPECT_TRUE(list.is_level(other))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   217
            << LogLevel::name(other) << " >= " << LogLevel::name(first) << " but is_level() returns false";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   218
        } else {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   219
          EXPECT_FALSE(list.is_level(other))
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   220
            << LogLevel::name(other) << " < " << LogLevel::name(first) << " but is_level() returns true";
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   221
        }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   222
      }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   223
    }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   224
}
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   225
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   226
TEST(LogOutputList, level_for) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   227
  LogOutputList list;
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   228
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   229
  // Ask the empty list about stdout, stderr
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   230
  EXPECT_EQ(LogLevel::Off, list.level_for(&StdoutLog));
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   231
  EXPECT_EQ(LogLevel::Off, list.level_for(&StderrLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   232
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   233
  // Ask for level in a list with two outputs on different levels
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   234
  list.set_output_level(&StdoutLog, LogLevel::Info);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   235
  list.set_output_level(&StderrLog, LogLevel::Trace);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   236
  EXPECT_EQ(LogLevel::Info, list.level_for(&StdoutLog));
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   237
  EXPECT_EQ(LogLevel::Trace, list.level_for(&StderrLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   238
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   239
  // Remove and ask again
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   240
  list.set_output_level(&StdoutLog, LogLevel::Off);
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   241
  EXPECT_EQ(LogLevel::Off, list.level_for(&StdoutLog));
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   242
  EXPECT_EQ(LogLevel::Trace, list.level_for(&StderrLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   243
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   244
  // Ask about an unknown output
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   245
  LogOutput* dummy = dummy_output(4711);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   246
  EXPECT_EQ(LogLevel::Off, list.level_for(dummy));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   247
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   248
  for (size_t i = LogLevel::First; i <= LogLevel::Last; i++) {
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   249
    LogLevelType level = static_cast<LogLevelType>(i);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   250
    list.set_output_level(dummy, level);
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   251
    EXPECT_EQ(level, list.level_for(dummy));
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   252
  }
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   253
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   254
  // Make sure the stderr level is still the same
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 41705
diff changeset
   255
  EXPECT_EQ(LogLevel::Trace, list.level_for(&StderrLog));
40656
d4964c292b78 8061219: Implement unit-tests for UL
mlarsson
parents:
diff changeset
   256
}