Path: blob/master/test/hotspot/gtest/logging/test_logSelectionList.cpp
41144 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "jvm.h"25#include "logging/logLevel.hpp"26#include "logging/logSelectionList.hpp"27#include "logging/logTagSet.hpp"28#include "utilities/globalDefinitions.hpp"29#include "logTestUtils.inline.hpp"30#include "unittest.hpp"3132TEST(LogSelectionList, combination_limit) {33size_t max_combinations = LogSelectionList::MaxSelections;34EXPECT_GT(max_combinations, LogTagSet::ntagsets())35<< "Combination limit not sufficient for configuring all available tag sets";36}3738TEST(LogSelectionList, parse) {39char buf[256];40const char* valid_expression[] = {41"logging=off,all", "gc,logging", "logging+gc", "logging+gc,gc", "gc=trace,logging=info",42"logging+gc=trace,gc+logging=warning,logging", "gc,all=info"43};4445// Verify valid expressions parse without problems46for (size_t i = 0; i < ARRAY_SIZE(valid_expression); i++) {47LogSelectionList expr;48EXPECT_TRUE(expr.parse(valid_expression[i])) << "Valid expression '" << valid_expression[i] << "' did not parse";49}5051// Verify invalid expressions do not parse52for (size_t i = 0; i < ARRAY_SIZE(valid_expression); i++) {53for (size_t j = 0; j < ARRAY_SIZE(invalid_selection_substr); j++) {54// Prefix with invalid substr55LogSelectionList expr;56jio_snprintf(buf, sizeof(buf), "%s%s", invalid_selection_substr[j], valid_expression[i]);57EXPECT_FALSE(expr.parse(buf)) << "'" << buf << "'" << " considered legal";5859// Suffix with invalid substr60LogSelectionList expr1;61jio_snprintf(buf, sizeof(buf), "%s%s", valid_expression[i], invalid_selection_substr[j]);62EXPECT_FALSE(expr1.parse(buf)) << "'" << buf << "'" << " considered legal";6364// Use only the invalid substr65LogSelectionList expr2;66EXPECT_FALSE(expr2.parse(invalid_selection_substr[j])) << "'" << invalid_selection_substr[j] << "'" << " considered legal";67}6869// Suffix/prefix with some unique invalid prefixes/suffixes70LogSelectionList expr;71jio_snprintf(buf, sizeof(buf), "*%s", valid_expression[i]);72EXPECT_FALSE(expr.parse(buf)) << "'" << buf << "'" << " considered legal";7374LogSelectionList expr1;75jio_snprintf(buf, sizeof(buf), "logging*%s", valid_expression[i]);76EXPECT_FALSE(expr1.parse(buf)) << "'" << buf << "'" << " considered legal";77}78}7980// Test the level_for() function for an empty expression81TEST(LogSelectionList, level_for_empty) {82LogSelectionList emptyexpr;83ASSERT_TRUE(emptyexpr.parse(""));84// All tagsets should be unspecified since the expression doesn't involve any tagset85for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {86EXPECT_EQ(LogLevel::Unspecified, emptyexpr.level_for(*ts));87}88}8990// Test level_for() with an expression that has overlap (last subexpression should be used)91TEST(LogSelectionList, level_for_overlap) {92LogSelectionList overlapexpr;93// The all=warning will be overridden with gc=info and/or logging+safepoint*=trace94ASSERT_TRUE(overlapexpr.parse("all=warning,gc=info,logging+safepoint*=trace"));95for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {96if (ts->contains(PREFIX_LOG_TAG(gc)) && ts->ntags() == 1) {97EXPECT_EQ(LogLevel::Info, overlapexpr.level_for(*ts));98} else if (ts->contains(PREFIX_LOG_TAG(logging)) && ts->contains(PREFIX_LOG_TAG(safepoint))) {99EXPECT_EQ(LogLevel::Trace, overlapexpr.level_for(*ts));100} else {101EXPECT_EQ(LogLevel::Warning, overlapexpr.level_for(*ts));102}103}104EXPECT_EQ(LogLevel::Warning, overlapexpr.level_for(LogTagSetMapping<LOG_TAGS(class)>::tagset()));105EXPECT_EQ(LogLevel::Info, overlapexpr.level_for(LogTagSetMapping<LOG_TAGS(gc)>::tagset()));106EXPECT_EQ(LogLevel::Trace, overlapexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, safepoint)>::tagset()));107EXPECT_EQ(LogLevel::Trace,108overlapexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, gc, class, safepoint, heap)>::tagset()));109}110111// Test level_for() with an expression containing two independent subexpressions112TEST(LogSelectionList, level_for_disjoint) {113LogSelectionList reducedexpr;114ASSERT_TRUE(reducedexpr.parse("gc+logging=trace,class*=error"));115EXPECT_EQ(LogLevel::Error, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(class)>::tagset()));116EXPECT_EQ(LogLevel::Error, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(safepoint, class)>::tagset()));117EXPECT_EQ(LogLevel::NotMentioned, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(safepoint)>::tagset()));118EXPECT_EQ(LogLevel::NotMentioned, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(logging)>::tagset()));119EXPECT_EQ(LogLevel::NotMentioned, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(gc)>::tagset()));120EXPECT_EQ(LogLevel::Trace, reducedexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, gc)>::tagset()));121}122123// Test level_for() with an expression that is completely overridden in the last part of the expression124TEST(LogSelectionList, level_for_override) {125LogSelectionList overrideexpr;126// No matter what, everything should be set to error level because of the last part127ASSERT_TRUE(overrideexpr.parse("logging,gc*=trace,all=error"));128EXPECT_EQ(LogLevel::Error, overrideexpr.level_for(LogTagSetMapping<LOG_TAGS(class)>::tagset()));129EXPECT_EQ(LogLevel::Error, overrideexpr.level_for(LogTagSetMapping<LOG_TAGS(logging)>::tagset()));130EXPECT_EQ(LogLevel::Error, overrideexpr.level_for(LogTagSetMapping<LOG_TAGS(gc)>::tagset()));131EXPECT_EQ(LogLevel::Error, overrideexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, gc)>::tagset()));132}133134// Test level_for() with a mixed expression with a bit of everything135TEST(LogSelectionList, level_for_mixed) {136LogSelectionList mixedexpr;137ASSERT_TRUE(mixedexpr.parse("all=warning,gc*=debug,gc=trace,safepoint*=off"));138EXPECT_EQ(LogLevel::Warning, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(logging)>::tagset()));139EXPECT_EQ(LogLevel::Warning, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, class)>::tagset()));140EXPECT_EQ(LogLevel::Debug, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(gc, class)>::tagset()));141EXPECT_EQ(LogLevel::Off, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(gc, safepoint, logging)>::tagset()));142EXPECT_EQ(LogLevel::Off, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(safepoint)>::tagset()));143EXPECT_EQ(LogLevel::Debug, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(logging, gc)>::tagset()));144EXPECT_EQ(LogLevel::Trace, mixedexpr.level_for(LogTagSetMapping<LOG_TAGS(gc)>::tagset()));145}146147148