| File: | jdk/test/hotspot/gtest/logging/test_logStream.cpp |
| Warning: | line 81, column 17 Value stored to 'to_write' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | #include "precompiled.hpp" |
| 25 | #include "jvm.h" |
| 26 | #include "logTestFixture.hpp" |
| 27 | #include "logTestUtils.inline.hpp" |
| 28 | #include "logging/log.hpp" |
| 29 | #include "logging/logStream.hpp" |
| 30 | #include "unittest.hpp" |
| 31 | |
| 32 | class LogStreamTest : public LogTestFixture { |
| 33 | protected: |
| 34 | void verify_stream(outputStream* stream); |
| 35 | }; |
| 36 | |
| 37 | void LogStreamTest::verify_stream(outputStream* stream) { |
| 38 | set_log_config(TestLogFileName, "gc=debug"); |
| 39 | stream->print("%d ", 3); |
| 40 | stream->print("workers"); |
| 41 | stream->cr(); |
| 42 | EXPECT_TRUE(file_contains_substring(TestLogFileName, "3 workers\n"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substring (TestLogFileName, "3 workers\n"))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 42, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substring(TestLogFileName, \"3 workers\\n\")" , "false", "true").c_str()) = ::testing::Message(); |
| 43 | } |
| 44 | |
| 45 | TEST_VM_F(LogStreamTest, from_log)class LogStreamTest_from_log_vm_Test : public LogStreamTest { public: LogStreamTest_from_log_vm_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); LogStreamTest_from_log_vm_Test(LogStreamTest_from_log_vm_Test const &) = delete; void operator=(LogStreamTest_from_log_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_from_log_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "from_log_vm", __null, __null, ::testing::internal ::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 45), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_from_log_vm_Test >);void LogStreamTest_from_log_vm_Test::TestBody() { |
| 46 | Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) > log; |
| 47 | LogStream stream(log.debug()); |
| 48 | |
| 49 | verify_stream(&stream); |
| 50 | } |
| 51 | |
| 52 | TEST_VM_F(LogStreamTest, from_logtarget)class LogStreamTest_from_logtarget_vm_Test : public LogStreamTest { public: LogStreamTest_from_logtarget_vm_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); LogStreamTest_from_logtarget_vm_Test (LogStreamTest_from_logtarget_vm_Test const &) = delete; void operator=(LogStreamTest_from_logtarget_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_from_logtarget_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "from_logtarget_vm", __null, __null, ::testing ::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 52), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_from_logtarget_vm_Test >);void LogStreamTest_from_logtarget_vm_Test::TestBody() { |
| 53 | LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> log; |
| 54 | LogStream stream(log); |
| 55 | |
| 56 | verify_stream(&stream); |
| 57 | } |
| 58 | |
| 59 | TEST_VM_F(LogStreamTest, handle)class LogStreamTest_handle_vm_Test : public LogStreamTest { public : LogStreamTest_handle_vm_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); LogStreamTest_handle_vm_Test(LogStreamTest_handle_vm_Test const &) = delete; void operator=(LogStreamTest_handle_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_handle_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "handle_vm", __null, __null, ::testing::internal ::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 59), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_handle_vm_Test >);void LogStreamTest_handle_vm_Test::TestBody() { |
| 60 | LogStreamHandle(Debug, gc)LogStreamTemplate<LogLevel::Debug, (LogTag::_gc), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG)> stream; |
| 61 | |
| 62 | verify_stream(&stream); |
| 63 | } |
| 64 | |
| 65 | TEST_VM_F(LogStreamTest, no_rm)class LogStreamTest_no_rm_vm_Test : public LogStreamTest { public : LogStreamTest_no_rm_vm_Test() {} private: virtual void TestBody (); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); LogStreamTest_no_rm_vm_Test(LogStreamTest_no_rm_vm_Test const &) = delete; void operator=(LogStreamTest_no_rm_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_no_rm_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "no_rm_vm", __null, __null, ::testing::internal ::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 65), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_no_rm_vm_Test >);void LogStreamTest_no_rm_vm_Test::TestBody() { |
| 66 | ResourceMark rm; |
| 67 | LogStream ls(Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::debug()); |
| 68 | verify_stream(&ls); |
| 69 | } |
| 70 | |
| 71 | TEST_VM_F(LogStreamTest, TestLineBufferAllocation)class LogStreamTest_TestLineBufferAllocation_vm_Test : public LogStreamTest { public: LogStreamTest_TestLineBufferAllocation_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); LogStreamTest_TestLineBufferAllocation_vm_Test (LogStreamTest_TestLineBufferAllocation_vm_Test const &) = delete; void operator=(LogStreamTest_TestLineBufferAllocation_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_TestLineBufferAllocation_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "TestLineBufferAllocation_vm", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 71), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_TestLineBufferAllocation_vm_Test >);void LogStreamTest_TestLineBufferAllocation_vm_Test::TestBody () { |
| 72 | const int max_line_len = 1024; |
| 73 | char* const test_string = (char*) os::malloc(max_line_len, mtLogging); |
| 74 | memset(test_string, 'A', max_line_len); |
| 75 | Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) > log; |
| 76 | set_log_config(TestLogFileName, "gc=debug"); |
| 77 | for (int interval = 1; interval < max_line_len; interval++) { |
| 78 | LogStream ls(log.debug()); |
| 79 | int written = 0; |
| 80 | while (written < max_line_len) { |
| 81 | const int to_write = MIN2(interval, max_line_len - written); |
Value stored to 'to_write' during its initialization is never read | |
| 82 | ls.write(test_string, interval); |
| 83 | written += interval; |
| 84 | const char* const line_buffer = ls._current_line.buffer(); |
| 85 | for (int i = 0; i < written; i++) { |
| 86 | ASSERT_TRUE(line_buffer[i] == 'A')switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(line_buffer[i] == 'A' )) ; else return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 86, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "line_buffer[i] == 'A'", "false", "true").c_str()) = ::testing ::Message(); |
| 87 | } |
| 88 | ASSERT_TRUE(line_buffer[written] == '\0')switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(line_buffer[written] == '\0')) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 88, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "line_buffer[written] == '\\0'", "false", "true").c_str()) = ::testing::Message(); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Test, in release build, that the internal line buffer of a LogStream |
| 94 | // object caps out at 1M. |
| 95 | TEST_VM_F(LogStreamTest, TestLineBufferAllocationCap)class LogStreamTest_TestLineBufferAllocationCap_vm_Test : public LogStreamTest { public: LogStreamTest_TestLineBufferAllocationCap_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); LogStreamTest_TestLineBufferAllocationCap_vm_Test (LogStreamTest_TestLineBufferAllocationCap_vm_Test const & ) = delete; void operator=(LogStreamTest_TestLineBufferAllocationCap_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_TestLineBufferAllocationCap_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "TestLineBufferAllocationCap_vm", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 95), (::testing::internal::GetTypeId<LogStreamTest>() ), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_TestLineBufferAllocationCap_vm_Test >);void LogStreamTest_TestLineBufferAllocationCap_vm_Test:: TestBody() { |
| 96 | LogStream ls(Log(logging)LogImpl<(LogTag::_logging), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::info()); |
| 97 | for (size_t i = 0; i < (1*M + 512); i ++) { |
| 98 | ls.print_raw("A"); |
| 99 | } |
| 100 | const char* const line_buffer = ls._current_line.buffer(); |
| 101 | ASSERT_TRUE(strlen(line_buffer) == 1*M - 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(strlen(line_buffer) == 1*M - 1)) ; else return ::testing::internal::AssertHelper(:: testing::TestPartResult::kFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "strlen(line_buffer) == 1*M - 1", "false", "true").c_str()) = ::testing::Message(); |
| 102 | // reset to prevent assert for unflushed content |
| 103 | ls._current_line.reset(); |
| 104 | } |
| 105 | |
| 106 | TEST_VM_F(LogStreamTest, autoflush_on_destruction)class LogStreamTest_autoflush_on_destruction_vm_Test : public LogStreamTest { public: LogStreamTest_autoflush_on_destruction_vm_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); LogStreamTest_autoflush_on_destruction_vm_Test (LogStreamTest_autoflush_on_destruction_vm_Test const &) = delete; void operator=(LogStreamTest_autoflush_on_destruction_vm_Test const &) = delete;};::testing::TestInfo* const LogStreamTest_autoflush_on_destruction_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "LogStreamTest", "autoflush_on_destruction_vm", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 106), (::testing::internal::GetTypeId<LogStreamTest>( )), LogStreamTest::SetUpTestCase, LogStreamTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< LogStreamTest_autoflush_on_destruction_vm_Test >);void LogStreamTest_autoflush_on_destruction_vm_Test::TestBody () { |
| 107 | Log(gc)LogImpl<(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) > log; |
| 108 | set_log_config(TestLogFileName, "gc=debug"); |
| 109 | { |
| 110 | LogStream stream(log.debug()); |
| 111 | stream.print("ABCD"); // Unfinished line. I expect not to assert upon leaving the scope. |
| 112 | } |
| 113 | EXPECT_TRUE(file_contains_substring(TestLogFileName, "ABCD\n"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substring (TestLogFileName, "ABCD\n"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_logStream.cpp" , 113, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substring(TestLogFileName, \"ABCD\\n\")", "false" , "true").c_str()) = ::testing::Message(); |
| 114 | } |
| 115 |