From d7b0ba9d7c8b62425f060988f860cd7d21e7915e Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Thu, 9 Nov 2023 17:52:08 +0000 Subject: [PATCH] 8319554: Select LogOutput* directly for stdout and stderr Reviewed-by: jsjolen, dholmes --- .../share/logging/logConfiguration.cpp | 6 +++ test/hotspot/gtest/logging/test_asynclog.cpp | 46 +++++++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/hotspot/share/logging/logConfiguration.cpp b/src/hotspot/share/logging/logConfiguration.cpp index b82458cf472..18f225f7dd4 100644 --- a/src/hotspot/share/logging/logConfiguration.cpp +++ b/src/hotspot/share/logging/logConfiguration.cpp @@ -505,6 +505,12 @@ bool LogConfiguration::parse_log_arguments(const char* outputstr, errstream->print_cr("Invalid output index '%s'", outputstr); return false; } + } else if (strcmp(outputstr, StdoutLog->name()) == 0) { // stdout + idx = 0; + assert(find_output(outputstr) == idx, "sanity check"); + } else if (strcmp(outputstr, StderrLog->name()) == 0) { // stderr + idx = 1; + assert(find_output(outputstr) == idx, "sanity check"); } else { // Output specified using name // Normalize the name, stripping quotes and ensures it includes type prefix size_t len = strlen(outputstr) + strlen(implicit_output_prefix) + 1; diff --git a/test/hotspot/gtest/logging/test_asynclog.cpp b/test/hotspot/gtest/logging/test_asynclog.cpp index 216cc320d38..89a1d6fef8a 100644 --- a/test/hotspot/gtest/logging/test_asynclog.cpp +++ b/test/hotspot/gtest/logging/test_asynclog.cpp @@ -256,7 +256,10 @@ TEST_VM_F(AsyncLogTest, droppingMessage) { TEST_VM_F(AsyncLogTest, stdoutOutput) { testing::internal::CaptureStdout(); fprintf(stdout, "header"); - set_log_config("stdout", "logging=debug"); + + if (!set_log_config("stdout", "logging=debug")) { + return; + } test_asynclog_ls(); test_asynclog_drop_messages(); @@ -264,22 +267,27 @@ TEST_VM_F(AsyncLogTest, stdoutOutput) { AsyncLogWriter::flush(); fflush(nullptr); - if (write_to_file(testing::internal::GetCapturedStdout())) { - EXPECT_TRUE(file_contains_substring(TestLogFileName, "header")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "LogStreamWithAsyncLogImpl")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream msg1-msg2-msg3")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream newline")); + if (!write_to_file(testing::internal::GetCapturedStdout())) { + return; + } - if (AsyncLogWriter::instance() != nullptr) { - EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging")); - } + EXPECT_TRUE(file_contains_substring(TestLogFileName, "header")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "LogStreamWithAsyncLogImpl")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream msg1-msg2-msg3")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream newline")); + + if (AsyncLogWriter::instance() != nullptr) { + EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging")); } } TEST_VM_F(AsyncLogTest, stderrOutput) { testing::internal::CaptureStderr(); fprintf(stderr, "header"); - set_log_config("stderr", "logging=debug"); + + if (!set_log_config("stderr", "logging=debug")) { + return; + } test_asynclog_ls(); test_asynclog_drop_messages(); @@ -287,14 +295,16 @@ TEST_VM_F(AsyncLogTest, stderrOutput) { AsyncLogWriter::flush(); fflush(nullptr); - if (write_to_file(testing::internal::GetCapturedStderr())) { - EXPECT_TRUE(file_contains_substring(TestLogFileName, "header")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "LogStreamWithAsyncLogImpl")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream msg1-msg2-msg3")); - EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream newline")); + if (!write_to_file(testing::internal::GetCapturedStderr())) { + return; + } - if (AsyncLogWriter::instance() != nullptr) { - EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging")); - } + EXPECT_TRUE(file_contains_substring(TestLogFileName, "header")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "LogStreamWithAsyncLogImpl")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream msg1-msg2-msg3")); + EXPECT_TRUE(file_contains_substring(TestLogFileName, "logStream newline")); + + if (AsyncLogWriter::instance() != nullptr) { + EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging")); } }