8147348: LogTagLevelExpression not properly initialized in configure_stdout

Reviewed-by: brutisso, sla
This commit is contained in:
Marcus Larsson 2016-01-27 09:07:10 +01:00
parent 4ca382aeee
commit 127158a210
4 changed files with 65 additions and 59 deletions

View file

@ -36,11 +36,12 @@ void Test_log_length() {
remove("loglengthoutput.txt");
// Write long message to output file
LogConfiguration::parse_log_arguments("loglengthoutput.txt", "logging=trace",
NULL, NULL, NULL);
ResourceMark rm;
outputStream* logstream = LogHandle(logging)::trace_stream();
logstream->print_cr("01:1234567890-"
LogHandle(logging) log;
bool success = LogConfiguration::parse_log_arguments("loglengthoutput.txt", "logging=trace",
NULL, NULL, log.error_stream());
assert(success, "test unable to configure logging");
log.trace("01:1234567890-"
"02:1234567890-"
"03:1234567890-"
"04:1234567890-"
@ -77,10 +78,11 @@ void Test_log_length() {
"35:1234567890-"
"36:1234567890-"
"37:1234567890-");
LogConfiguration::parse_log_arguments("loglengthoutput.txt", "all=off",
NULL, NULL, log.error_stream());
// Look for end of message in output file
FILE* fp;
fp = fopen("loglengthoutput.txt", "r");
FILE* fp = fopen("loglengthoutput.txt", "r");
assert(fp, "File read error");
char output[600];
if (fgets(output, 600, fp) != NULL) {
@ -89,5 +91,12 @@ void Test_log_length() {
fclose(fp);
remove("loglengthoutput.txt");
}
#endif // PRODUCT
void Test_configure_stdout() {
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
assert(log_is_enabled(Info, logging), "configure_stdout did not enable requested logging");
assert(!log_is_enabled(Info, logging, gc), "configure_stdout enabled too much logging");
LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(logging));
assert(!log_is_enabled(Info, logging), "configure_stdout did not disable requested logging");
}
#endif // PRODUCT

View file

@ -29,21 +29,8 @@
const char* LogTagLevelExpression::DefaultExpressionString = "all";
void LogTagLevelExpression::clear() {
_ntags = 0;
_ncombinations = 0;
for (size_t combination = 0; combination < MaxCombinations; combination++) {
_level[combination] = LogLevel::Invalid;
_allow_other_tags[combination] = false;
for (size_t tag = 0; tag < LogTag::MaxTags; tag++) {
_tags[combination][tag] = LogTag::__NO_TAG;
}
}
}
bool LogTagLevelExpression::parse(const char* str, outputStream* errstream) {
bool success = true;
clear();
if (str == NULL || strcmp(str, "") == 0) {
str = DefaultExpressionString;
}

View file

@ -47,6 +47,11 @@ class LogTagLevelExpression : public StackObj {
bool _allow_other_tags[MaxCombinations];
void new_combination() {
// Make sure either all tags are set or the last tag is __NO_TAG
if (_ntags < LogTag::MaxTags) {
_tags[_ncombinations][_ntags] = LogTag::__NO_TAG;
}
_ncombinations++;
_ntags = 0;
}
@ -64,10 +69,13 @@ class LogTagLevelExpression : public StackObj {
_allow_other_tags[_ncombinations] = true;
}
void clear();
public:
LogTagLevelExpression() : _ntags(0), _ncombinations(0) {
for (size_t combination = 0; combination < MaxCombinations; combination++) {
_level[combination] = LogLevel::Invalid;
_allow_other_tags[combination] = false;
_tags[combination][0] = LogTag::__NO_TAG;
}
}
bool parse(const char* str, outputStream* errstream = NULL);

View file

@ -53,6 +53,7 @@ void Test_linked_list();
void TestResourcehash_test();
void TestChunkedList_test();
void Test_log_length();
void Test_configure_stdout();
void Test_TempNewSymbol();
void GlobalDefinitions_test();
void GCTimer_test();
@ -110,6 +111,7 @@ void InternalVMTests::run() {
run_unit_test(TestChunkedList_test());
run_unit_test(JSON_test());
run_unit_test(Test_log_length());
run_unit_test(Test_configure_stdout());
run_unit_test(DirectivesParser_test());
run_unit_test(Test_TempNewSymbol());
#if INCLUDE_VM_STRUCTS