8165698: Convert LogTagSet related internal tests to GTest
Reviewed-by: rehn, rprotacio
This commit is contained in:
parent
e3155ad3c3
commit
c48b110f17
@ -50,13 +50,6 @@
|
|||||||
#define assert_char_not_in(c, s) \
|
#define assert_char_not_in(c, s) \
|
||||||
assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
|
assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
|
||||||
|
|
||||||
void Test_log_tag_combinations_limit() {
|
|
||||||
assert(LogTagLevelExpression::MaxCombinations > LogTagSet::ntagsets(),
|
|
||||||
"Combination limit (" SIZE_FORMAT ") not sufficient "
|
|
||||||
"for configuring all available tag sets (" SIZE_FORMAT ")",
|
|
||||||
LogTagLevelExpression::MaxCombinations, LogTagSet::ntagsets());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read a complete line from fp and return it as a resource allocated string.
|
// Read a complete line from fp and return it as a resource allocated string.
|
||||||
// Returns NULL on EOF.
|
// Returns NULL on EOF.
|
||||||
static char* read_line(FILE* fp) {
|
static char* read_line(FILE* fp) {
|
||||||
@ -627,51 +620,6 @@ void Test_log_big() {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_logtagset_duplicates() {
|
|
||||||
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
|
|
||||||
char ts_name[512];
|
|
||||||
ts->label(ts_name, sizeof(ts_name), ",");
|
|
||||||
|
|
||||||
// verify that NO_TAG is never followed by a real tag
|
|
||||||
for (size_t i = 0; i < LogTag::MaxTags; i++) {
|
|
||||||
if (ts->tag(i) == LogTag::__NO_TAG) {
|
|
||||||
for (i++; i < LogTag::MaxTags; i++) {
|
|
||||||
assert(ts->tag(i) == LogTag::__NO_TAG,
|
|
||||||
"NO_TAG was followed by a real tag (%s) in tagset %s",
|
|
||||||
LogTag::name(ts->tag(i)), ts_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify that there are no duplicate tagsets (same tags in different order)
|
|
||||||
for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) {
|
|
||||||
if (ts->ntags() != other->ntags()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bool equal = true;
|
|
||||||
for (size_t i = 0; i < ts->ntags(); i++) {
|
|
||||||
LogTagType tag = ts->tag(i);
|
|
||||||
if (!other->contains(tag)) {
|
|
||||||
equal = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Since tagsets are implemented using template arguments, using both of
|
|
||||||
// the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will
|
|
||||||
// instantiate two different LogTagSetMappings. This causes multiple
|
|
||||||
// tagset instances to be created for the same logical set. We want to
|
|
||||||
// avoid this to save time, memory and prevent any confusion around it.
|
|
||||||
if (equal) {
|
|
||||||
char other_name[512];
|
|
||||||
other->label(other_name, sizeof(other_name), ",");
|
|
||||||
assert(false, "duplicate LogTagSets found: '%s' vs '%s' "
|
|
||||||
"(tags must always be specified in the same order for each tagset)",
|
|
||||||
ts_name, other_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define Test_logtarget_string_literal "First line"
|
#define Test_logtarget_string_literal "First line"
|
||||||
|
|
||||||
|
|
||||||
@ -953,28 +901,4 @@ void Test_invalid_log_file() {
|
|||||||
remove(target_name);
|
remove(target_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure -Xlog:help and LogConfiguration::describe contain tagset descriptions
|
|
||||||
void Test_logtagset_descriptions() {
|
|
||||||
for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
|
|
||||||
char expected[1024];
|
|
||||||
d->tagset->label(expected, sizeof(expected), "+");
|
|
||||||
jio_snprintf(expected + strlen(expected),
|
|
||||||
sizeof(expected) - strlen(expected),
|
|
||||||
": %s", d->descr);
|
|
||||||
|
|
||||||
ResourceMark rm;
|
|
||||||
stringStream ss;
|
|
||||||
LogConfiguration::describe(&ss);
|
|
||||||
assert(strstr(ss.as_string(), expected) != NULL,
|
|
||||||
"missing log tag set descriptions in LogConfiguration::describe");
|
|
||||||
|
|
||||||
TestLogFile file("log_tagset_descriptions");
|
|
||||||
FILE* fp = fopen(file.name(), "w+");
|
|
||||||
assert(fp != NULL, "File open error");
|
|
||||||
LogConfiguration::print_command_line_help(fp);
|
|
||||||
fclose(fp);
|
|
||||||
assert(number_of_lines_with_substring_in_file(file.name(), expected) > 0,
|
|
||||||
"missing log tag set descriptions in -Xlog:help output");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // PRODUCT
|
#endif // PRODUCT
|
||||||
|
@ -59,7 +59,6 @@ void InternalVMTests::run() {
|
|||||||
run_unit_test(TestOldSize_test);
|
run_unit_test(TestOldSize_test);
|
||||||
run_unit_test(TestBitMap_test);
|
run_unit_test(TestBitMap_test);
|
||||||
run_unit_test(ObjectMonitor_test);
|
run_unit_test(ObjectMonitor_test);
|
||||||
run_unit_test(Test_log_tag_combinations_limit);
|
|
||||||
run_unit_test(Test_logtarget);
|
run_unit_test(Test_logtarget);
|
||||||
run_unit_test(Test_logstream);
|
run_unit_test(Test_logstream);
|
||||||
run_unit_test(Test_loghandle);
|
run_unit_test(Test_loghandle);
|
||||||
@ -68,8 +67,6 @@ void InternalVMTests::run() {
|
|||||||
run_unit_test(Test_logconfiguration_subscribe);
|
run_unit_test(Test_logconfiguration_subscribe);
|
||||||
run_unit_test(Test_log_prefix);
|
run_unit_test(Test_log_prefix);
|
||||||
run_unit_test(Test_log_big);
|
run_unit_test(Test_log_big);
|
||||||
run_unit_test(Test_logtagset_duplicates);
|
|
||||||
run_unit_test(Test_logtagset_descriptions);
|
|
||||||
run_unit_test(Test_log_file_startup_rotation);
|
run_unit_test(Test_log_file_startup_rotation);
|
||||||
run_unit_test(Test_log_file_startup_truncation);
|
run_unit_test(Test_log_file_startup_truncation);
|
||||||
run_unit_test(Test_invalid_log_file);
|
run_unit_test(Test_invalid_log_file);
|
||||||
|
@ -28,6 +28,12 @@
|
|||||||
#include "unittest.hpp"
|
#include "unittest.hpp"
|
||||||
#include "utilities/globalDefinitions.hpp"
|
#include "utilities/globalDefinitions.hpp"
|
||||||
|
|
||||||
|
TEST(LogTagLevelExpression, combination_limit) {
|
||||||
|
size_t max_combinations = LogTagLevelExpression::MaxCombinations;
|
||||||
|
EXPECT_GT(max_combinations, LogTagSet::ntagsets())
|
||||||
|
<< "Combination limit not sufficient for configuring all available tag sets";
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LogTagLevelExpression, parse) {
|
TEST(LogTagLevelExpression, parse) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
const char* invalid_substr[] = {
|
const char* invalid_substr[] = {
|
||||||
|
@ -128,3 +128,46 @@ TEST(LogTagSet, label) {
|
|||||||
ASSERT_NE(-1, ts2.label(buf, sizeof(buf)));
|
ASSERT_NE(-1, ts2.label(buf, sizeof(buf)));
|
||||||
EXPECT_STREQ("logging", buf);
|
EXPECT_STREQ("logging", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LogTagSet, duplicates) {
|
||||||
|
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
|
||||||
|
char ts_name[512];
|
||||||
|
ts->label(ts_name, sizeof(ts_name), ",");
|
||||||
|
|
||||||
|
// verify that NO_TAG is never followed by a real tag
|
||||||
|
for (size_t i = 0; i < LogTag::MaxTags; i++) {
|
||||||
|
if (ts->tag(i) == LogTag::__NO_TAG) {
|
||||||
|
for (i++; i < LogTag::MaxTags; i++) {
|
||||||
|
EXPECT_EQ(LogTag::__NO_TAG, ts->tag(i))
|
||||||
|
<< "NO_TAG was followed by a real tag (" << LogTag::name(ts->tag(i)) << ") in tagset " << ts_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// verify that there are no duplicate tagsets (same tags in different order)
|
||||||
|
for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) {
|
||||||
|
if (ts->ntags() != other->ntags()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool equal = true;
|
||||||
|
for (size_t i = 0; i < ts->ntags(); i++) {
|
||||||
|
LogTagType tag = ts->tag(i);
|
||||||
|
if (!other->contains(tag)) {
|
||||||
|
equal = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Since tagsets are implemented using template arguments, using both of
|
||||||
|
// the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will
|
||||||
|
// instantiate two different LogTagSetMappings. This causes multiple
|
||||||
|
// tagset instances to be created for the same logical set. We want to
|
||||||
|
// avoid this to save time, memory and prevent any confusion around it.
|
||||||
|
if (equal) {
|
||||||
|
char other_name[512];
|
||||||
|
other->label(other_name, sizeof(other_name), ",");
|
||||||
|
FAIL() << "duplicate LogTagSets found: '" << ts_name << "' vs '" << other_name << "' "
|
||||||
|
<< "(tags must always be specified in the same order for each tagset)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
66
hotspot/test/native/logging/test_logTagSetDescriptions.cpp
Normal file
66
hotspot/test/native/logging/test_logTagSetDescriptions.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* ac_heapanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "precompiled.hpp"
|
||||||
|
#include "logTestUtils.inline.hpp"
|
||||||
|
#include "logging/logConfiguration.hpp"
|
||||||
|
#include "logging/logTagSet.hpp"
|
||||||
|
#include "logging/logTagSetDescriptions.hpp"
|
||||||
|
#include "memory/resourceArea.hpp"
|
||||||
|
#include "unittest.hpp"
|
||||||
|
#include "utilities/ostream.hpp"
|
||||||
|
|
||||||
|
TEST(LogTagSetDescriptions, describe) {
|
||||||
|
for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
|
||||||
|
char expected[1 * K];
|
||||||
|
d->tagset->label(expected, sizeof(expected), "+");
|
||||||
|
jio_snprintf(expected + strlen(expected),
|
||||||
|
sizeof(expected) - strlen(expected),
|
||||||
|
": %s", d->descr);
|
||||||
|
|
||||||
|
ResourceMark rm;
|
||||||
|
stringStream stream;
|
||||||
|
LogConfiguration::describe(&stream);
|
||||||
|
EXPECT_PRED2(string_contains_substring, stream.as_string(), expected)
|
||||||
|
<< "missing log tag set descriptions in LogConfiguration::describe";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LogTagSetDescriptions, command_line_help) {
|
||||||
|
const char* filename = "logtagset_descriptions";
|
||||||
|
FILE* fp = fopen(filename, "w+");
|
||||||
|
ASSERT_NE((void*)NULL, fp);
|
||||||
|
LogConfiguration::print_command_line_help(fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
|
||||||
|
char expected[1 * K];
|
||||||
|
d->tagset->label(expected, sizeof(expected), "+");
|
||||||
|
jio_snprintf(expected + strlen(expected),
|
||||||
|
sizeof(expected) - strlen(expected),
|
||||||
|
": %s", d->descr);
|
||||||
|
|
||||||
|
EXPECT_TRUE(file_contains_substring(filename, expected)) << "missing log tag set descriptions in -Xlog:help output";
|
||||||
|
}
|
||||||
|
delete_file(filename);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user