File: | jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp |
Warning: | line 154, column 24 The left operand of '==' is a garbage value due to array index out of bounds |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright (c) 2015, 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 "gc/shared/gcTraceTime.inline.hpp" | |||
27 | #include "logTestFixture.hpp" | |||
28 | #include "logTestUtils.inline.hpp" | |||
29 | #include "logging/log.hpp" | |||
30 | #include "runtime/interfaceSupport.inline.hpp" | |||
31 | #include "unittest.hpp" | |||
32 | ||||
33 | class GCTraceTimeTest : public LogTestFixture { | |||
34 | }; | |||
35 | ||||
36 | TEST_VM_F(GCTraceTimeTest, full)class GCTraceTimeTest_full_vm_Test : public GCTraceTimeTest { public: GCTraceTimeTest_full_vm_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); GCTraceTimeTest_full_vm_Test(GCTraceTimeTest_full_vm_Test const &) = delete; void operator=(GCTraceTimeTest_full_vm_Test const &) = delete;};::testing::TestInfo* const GCTraceTimeTest_full_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "GCTraceTimeTest", "full_vm", __null, __null, ::testing::internal ::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 36), (::testing::internal::GetTypeId<GCTraceTimeTest> ()), GCTraceTimeTest::SetUpTestCase, GCTraceTimeTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< GCTraceTimeTest_full_vm_Test >);void GCTraceTimeTest_full_vm_Test::TestBody() { | |||
37 | set_log_config(TestLogFileName, "gc=debug,gc+start=debug"); | |||
38 | ||||
39 | LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_debug; | |||
40 | LogTarget(Debug, gc, start)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_start ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_start_debug; | |||
41 | ||||
42 | EXPECT_TRUE(gc_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_debug.is_enabled() )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 42, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_debug.is_enabled()", "false", "true").c_str()) = ::testing ::Message(); | |||
43 | EXPECT_TRUE(gc_start_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_start_debug.is_enabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 43, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_start_debug.is_enabled()", "false", "true").c_str()) = :: testing::Message(); | |||
44 | ||||
45 | { | |||
46 | ThreadInVMfromNative tvn(JavaThread::current()); | |||
47 | MutexLocker lock(Heap_lock); // Needed to read heap usage | |||
48 | GCTraceTime(Debug, gc)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> timer("Test GC", NULL__null, GCCause::_allocation_failure, true); | |||
49 | } | |||
50 | ||||
51 | const char* expected[] = { | |||
52 | "[gc,start", "] Test GC (Allocation Failure)", | |||
53 | "[gc", "] Test GC (Allocation Failure) ", "M) ", "ms", | |||
54 | NULL__null | |||
55 | }; | |||
56 | EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substrings_in_order (TestLogFileName, expected))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 56, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, expected)" , "false", "true").c_str()) = ::testing::Message(); | |||
57 | } | |||
58 | ||||
59 | TEST_VM_F(GCTraceTimeTest, full_multitag)class GCTraceTimeTest_full_multitag_vm_Test : public GCTraceTimeTest { public: GCTraceTimeTest_full_multitag_vm_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); GCTraceTimeTest_full_multitag_vm_Test (GCTraceTimeTest_full_multitag_vm_Test const &) = delete; void operator=(GCTraceTimeTest_full_multitag_vm_Test const & ) = delete;};::testing::TestInfo* const GCTraceTimeTest_full_multitag_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "GCTraceTimeTest", "full_multitag_vm", __null, __null, ::testing ::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 59), (::testing::internal::GetTypeId<GCTraceTimeTest> ()), GCTraceTimeTest::SetUpTestCase, GCTraceTimeTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< GCTraceTimeTest_full_multitag_vm_Test >);void GCTraceTimeTest_full_multitag_vm_Test::TestBody() { | |||
60 | set_log_config(TestLogFileName, "gc+ref=debug,gc+ref+start=debug"); | |||
61 | ||||
62 | LogTarget(Debug, gc, ref)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_ref ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_debug; | |||
63 | LogTarget(Debug, gc, ref, start)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_ref ), (LogTag::_start), (LogTag::__NO_TAG), (LogTag::__NO_TAG), ( LogTag::__NO_TAG)> gc_start_debug; | |||
64 | ||||
65 | EXPECT_TRUE(gc_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_debug.is_enabled() )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 65, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_debug.is_enabled()", "false", "true").c_str()) = ::testing ::Message(); | |||
66 | EXPECT_TRUE(gc_start_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_start_debug.is_enabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 66, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_start_debug.is_enabled()", "false", "true").c_str()) = :: testing::Message(); | |||
67 | ||||
68 | { | |||
69 | ThreadInVMfromNative tvn(JavaThread::current()); | |||
70 | MutexLocker lock(Heap_lock); // Needed to read heap usage | |||
71 | GCTraceTime(Debug, gc, ref)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag ::_ref), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG)> timer("Test GC", NULL__null, GCCause::_allocation_failure, true); | |||
72 | } | |||
73 | ||||
74 | const char* expected[] = { | |||
75 | "[gc,ref,start", "] Test GC (Allocation Failure)", | |||
76 | "[gc,ref", "] Test GC (Allocation Failure) ", "M) ", "ms", | |||
77 | NULL__null | |||
78 | }; | |||
79 | EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substrings_in_order (TestLogFileName, expected))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 79, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, expected)" , "false", "true").c_str()) = ::testing::Message(); | |||
80 | } | |||
81 | ||||
82 | TEST_VM_F(GCTraceTimeTest, no_heap)class GCTraceTimeTest_no_heap_vm_Test : public GCTraceTimeTest { public: GCTraceTimeTest_no_heap_vm_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); GCTraceTimeTest_no_heap_vm_Test(GCTraceTimeTest_no_heap_vm_Test const &) = delete; void operator=(GCTraceTimeTest_no_heap_vm_Test const &) = delete;};::testing::TestInfo* const GCTraceTimeTest_no_heap_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "GCTraceTimeTest", "no_heap_vm", __null, __null, ::testing:: internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 82), (::testing::internal::GetTypeId<GCTraceTimeTest> ()), GCTraceTimeTest::SetUpTestCase, GCTraceTimeTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< GCTraceTimeTest_no_heap_vm_Test >);void GCTraceTimeTest_no_heap_vm_Test::TestBody() { | |||
83 | set_log_config(TestLogFileName, "gc=debug,gc+start=debug"); | |||
84 | ||||
85 | LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_debug; | |||
86 | LogTarget(Debug, gc, start)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_start ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_start_debug; | |||
87 | ||||
88 | EXPECT_TRUE(gc_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_debug.is_enabled() )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 88, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_debug.is_enabled()", "false", "true").c_str()) = ::testing ::Message(); | |||
89 | EXPECT_TRUE(gc_start_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_start_debug.is_enabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 89, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_start_debug.is_enabled()", "false", "true").c_str()) = :: testing::Message(); | |||
90 | ||||
91 | { | |||
92 | GCTraceTime(Debug, gc)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> timer("Test GC", NULL__null, GCCause::_allocation_failure, false); | |||
93 | } | |||
94 | ||||
95 | const char* expected[] = { | |||
96 | // [2.975s][debug][gc,start] Test GC (Allocation Failure) | |||
97 | "[gc,start", "] Test GC (Allocation Failure)", | |||
98 | // [2.975s][debug][gc ] Test GC (Allocation Failure) 0.026ms | |||
99 | "[gc", "] Test GC (Allocation Failure) ", "ms", | |||
100 | NULL__null | |||
101 | }; | |||
102 | EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substrings_in_order (TestLogFileName, expected))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 102, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, expected)" , "false", "true").c_str()) = ::testing::Message(); | |||
103 | ||||
104 | const char* not_expected[] = { | |||
105 | // [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms | |||
106 | "[gc", "] Test GC ", "M) ", "ms", | |||
107 | }; | |||
108 | EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(file_contains_substrings_in_order (TestLogFileName, not_expected)))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 108, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, not_expected)" , "true", "false").c_str()) = ::testing::Message(); | |||
109 | } | |||
110 | ||||
111 | TEST_VM_F(GCTraceTimeTest, no_cause)class GCTraceTimeTest_no_cause_vm_Test : public GCTraceTimeTest { public: GCTraceTimeTest_no_cause_vm_Test() {} private: virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); GCTraceTimeTest_no_cause_vm_Test(GCTraceTimeTest_no_cause_vm_Test const &) = delete; void operator=(GCTraceTimeTest_no_cause_vm_Test const &) = delete;};::testing::TestInfo* const GCTraceTimeTest_no_cause_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "GCTraceTimeTest", "no_cause_vm", __null, __null, ::testing:: internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 111), (::testing::internal::GetTypeId<GCTraceTimeTest> ()), GCTraceTimeTest::SetUpTestCase, GCTraceTimeTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< GCTraceTimeTest_no_cause_vm_Test >);void GCTraceTimeTest_no_cause_vm_Test::TestBody() { | |||
112 | set_log_config(TestLogFileName, "gc=debug,gc+start=debug"); | |||
113 | ||||
114 | LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_debug; | |||
115 | LogTarget(Debug, gc, start)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_start ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_start_debug; | |||
116 | ||||
117 | EXPECT_TRUE(gc_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_debug.is_enabled() )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 117, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_debug.is_enabled()", "false", "true").c_str()) = ::testing ::Message(); | |||
118 | EXPECT_TRUE(gc_start_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_start_debug.is_enabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 118, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_start_debug.is_enabled()", "false", "true").c_str()) = :: testing::Message(); | |||
119 | ||||
120 | { | |||
121 | ThreadInVMfromNative tvn(JavaThread::current()); | |||
122 | MutexLocker lock(Heap_lock); // Needed to read heap usage | |||
123 | GCTraceTime(Debug, gc)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> timer("Test GC", NULL__null, GCCause::_no_gc, true); | |||
124 | } | |||
125 | ||||
126 | const char* expected[] = { | |||
127 | // [2.975s][debug][gc,start] Test GC | |||
128 | "[gc,start", "] Test GC", | |||
129 | // [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms | |||
130 | "[gc", "] Test GC ", "M) ", "ms", | |||
131 | NULL__null | |||
132 | }; | |||
133 | EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substrings_in_order (TestLogFileName, expected))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 133, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, expected)" , "false", "true").c_str()) = ::testing::Message(); | |||
134 | } | |||
135 | ||||
136 | TEST_VM_F(GCTraceTimeTest, no_heap_no_cause)class GCTraceTimeTest_no_heap_no_cause_vm_Test : public GCTraceTimeTest { public: GCTraceTimeTest_no_heap_no_cause_vm_Test() {} private : virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); GCTraceTimeTest_no_heap_no_cause_vm_Test (GCTraceTimeTest_no_heap_no_cause_vm_Test const &) = delete ; void operator=(GCTraceTimeTest_no_heap_no_cause_vm_Test const &) = delete;};::testing::TestInfo* const GCTraceTimeTest_no_heap_no_cause_vm_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "GCTraceTimeTest", "no_heap_no_cause_vm", __null, __null, :: testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 136), (::testing::internal::GetTypeId<GCTraceTimeTest> ()), GCTraceTimeTest::SetUpTestCase, GCTraceTimeTest::TearDownTestCase , new ::testing::internal::TestFactoryImpl< GCTraceTimeTest_no_heap_no_cause_vm_Test >);void GCTraceTimeTest_no_heap_no_cause_vm_Test::TestBody () { | |||
137 | set_log_config(TestLogFileName, "gc=debug,gc+start=debug"); | |||
138 | ||||
139 | LogTarget(Debug, gc)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_debug; | |||
140 | LogTarget(Debug, gc, start)LogTargetImpl<LogLevel::Debug, (LogTag::_gc), (LogTag::_start ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> gc_start_debug; | |||
141 | ||||
142 | EXPECT_TRUE(gc_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_debug.is_enabled() )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 142, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_debug.is_enabled()", "false", "true").c_str()) = ::testing ::Message(); | |||
| ||||
143 | EXPECT_TRUE(gc_start_debug.is_enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gc_start_debug.is_enabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gc_start_debug.is_enabled()", "false", "true").c_str()) = :: testing::Message(); | |||
144 | ||||
145 | { | |||
146 | GCTraceTime(Debug, gc)GCTraceTimeWrapper<LogLevel::Debug, (LogTag::_gc), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> timer("Test GC", NULL__null, GCCause::_no_gc, false); | |||
147 | } | |||
148 | ||||
149 | const char* expected[] = { | |||
150 | // [2.975s][debug][gc,start] Test GC | |||
151 | "[gc,start", "] Test GC", | |||
152 | // [2.975s][debug][gc ] Test GC 0.026ms | |||
153 | "[gc", "] Test GC ", "ms", | |||
154 | NULL__null | |||
155 | }; | |||
156 | EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(file_contains_substrings_in_order (TestLogFileName, expected))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 156, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, expected)" , "false", "true").c_str()) = ::testing::Message(); | |||
157 | ||||
158 | const char* not_expected[] = { | |||
159 | // [2.975s][debug][gc ] Test GC 59M->59M(502M) 0.026ms | |||
160 | "[gc", "] Test GC ", "M) ", "ms", | |||
161 | }; | |||
162 | EXPECT_FALSE(file_contains_substrings_in_order(TestLogFileName, not_expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(file_contains_substrings_in_order (TestLogFileName, not_expected)))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/test_gcTraceTime.cpp" , 162, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "file_contains_substrings_in_order(TestLogFileName, not_expected)" , "true", "false").c_str()) = ::testing::Message(); | |||
163 | } |
1 | /* | ||||
2 | * Copyright (c) 2016, 2019, 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 "logging/log.hpp" | ||||
25 | #include "logging/logAsyncWriter.hpp" | ||||
26 | #include "logging/logConfiguration.hpp" | ||||
27 | #include "logging/logStream.hpp" | ||||
28 | #include "memory/resourceArea.hpp" | ||||
29 | #include "runtime/os.hpp" | ||||
30 | #include "unittest.hpp" | ||||
31 | |||||
32 | #define LOG_TEST_STRING_LITERAL"a (hopefully) unique log message for testing" "a (hopefully) unique log message for testing" | ||||
33 | |||||
34 | static const char* invalid_selection_substr[] = { | ||||
35 | "=", "+", " ", "+=", "+=*", "*+", " +", "**", "++", ".", ",", ",,", ",+", | ||||
36 | " *", "all+", "all*", "+all", "+all=Warning", "==Info", "=InfoWarning", | ||||
37 | "BadTag+", "logging++", "logging*+", ",=", "gc+gc+" | ||||
38 | }; | ||||
39 | |||||
40 | static inline bool string_contains_substring(const char* haystack, const char* needle) { | ||||
41 | return strstr(haystack, needle) != NULL__null; | ||||
42 | } | ||||
43 | |||||
44 | static inline bool file_exists(const char* filename) { | ||||
45 | struct stat st; | ||||
46 | return os::stat(filename, &st) == 0; | ||||
47 | } | ||||
48 | |||||
49 | static inline void delete_file(const char* filename) { | ||||
50 | AsyncLogWriter::flush(); | ||||
51 | if (!file_exists(filename)) { | ||||
52 | return; | ||||
53 | } | ||||
54 | int ret = remove(filename); | ||||
55 | EXPECT_TRUE(ret == 0 || errno == ENOENT)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ret == 0 || (*__errno_location ()) == 2)) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 55, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ret == 0 || errno == ENOENT", "false", "true").c_str()) = :: testing::Message() << "failed to remove file '" << filename << "': " | ||||
56 | << os::strerror(errno(*__errno_location ())) << " (" << errno(*__errno_location ()) << ")"; | ||||
57 | } | ||||
58 | |||||
59 | static inline void create_directory(const char* name) { | ||||
60 | assert(!file_exists(name), "can't create directory: %s already exists", name)do { if (!(!file_exists(name))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 60, "assert(" "!file_exists(name)" ") failed", "can't create directory: %s already exists" , name); ::breakpoint(); } } while (0); | ||||
61 | bool failed; | ||||
62 | #ifdef _WINDOWS | ||||
63 | failed = !CreateDirectory(name, NULL__null); | ||||
64 | #else | ||||
65 | failed = mkdir(name, 0777); | ||||
66 | #endif | ||||
67 | assert(!failed, "failed to create directory %s", name)do { if (!(!failed)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 67, "assert(" "!failed" ") failed", "failed to create directory %s" , name); ::breakpoint(); } } while (0); | ||||
68 | } | ||||
69 | |||||
70 | static inline void delete_empty_directory(const char* name) { | ||||
71 | #ifdef _WINDOWS | ||||
72 | if (!file_exists(name)) { | ||||
73 | return; | ||||
74 | } | ||||
75 | bool failed; | ||||
76 | failed = !RemoveDirectory(name); | ||||
77 | EXPECT_FALSE(failed)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(failed))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 77, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "failed", "true", "false").c_str()) = ::testing::Message() << "failed to remove directory '" << name | ||||
78 | << "': LastError = " << GetLastError(); | ||||
79 | #else | ||||
80 | delete_file(name); | ||||
81 | #endif | ||||
82 | } | ||||
83 | |||||
84 | static inline void init_log_file(const char* filename, const char* options = "") { | ||||
85 | LogStreamHandle(Error, logging)LogStreamTemplate<LogLevel::Error, (LogTag::_logging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> stream; | ||||
86 | bool success = LogConfiguration::parse_log_arguments(filename, "logging=trace", "", options, &stream); | ||||
87 | guarantee(success, "Failed to initialize log file '%s' with options '%s'", filename, options)do { if (!(success)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 87, "guarantee(" "success" ") failed", "Failed to initialize log file '%s' with options '%s'" , filename, options); ::breakpoint(); } } while (0); | ||||
88 | log_debug(logging)(!(LogImpl<(LogTag::_logging), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_logging), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("%s", LOG_TEST_STRING_LITERAL"a (hopefully) unique log message for testing"); | ||||
89 | success = LogConfiguration::parse_log_arguments(filename, "all=off", "", "", &stream); | ||||
90 | guarantee(success, "Failed to disable logging to file '%s'", filename)do { if (!(success)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 90, "guarantee(" "success" ") failed", "Failed to disable logging to file '%s'" , filename); ::breakpoint(); } } while (0); | ||||
91 | } | ||||
92 | |||||
93 | static const char* tmp_dir = os::get_temp_directory(); | ||||
94 | static const char* file_sep = os::file_separator(); | ||||
95 | |||||
96 | // Prepend filename with the temp directory and pid and return the result as a | ||||
97 | // resource allocated string. | ||||
98 | static inline char* prepend_temp_dir(const char* filename) { | ||||
99 | size_t temp_file_len = strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 28; | ||||
100 | char* temp_file = NEW_RESOURCE_ARRAY(char, temp_file_len)(char*) resource_allocate_bytes((temp_file_len) * sizeof(char )); | ||||
101 | int ret = jio_snprintf(temp_file, temp_file_len, "%s%spid%d.%s", | ||||
102 | tmp_dir, file_sep, | ||||
103 | os::current_process_id(), filename); | ||||
104 | return temp_file; | ||||
105 | } | ||||
106 | |||||
107 | // Prepend filename with specified prefix and the temp directory and return the | ||||
108 | // result as a malloc allocated string. This is used by test_logFileOutput.cpp. | ||||
109 | static inline char* prepend_prefix_temp_dir(const char* prefix, const char* filename) { | ||||
110 | size_t temp_file_len = strlen(prefix) + strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 1; | ||||
111 | char* temp_file = (char*)os::malloc(temp_file_len, mtLogging); | ||||
112 | int ret = jio_snprintf(temp_file, temp_file_len, "%s%s%s%s", | ||||
113 | prefix, tmp_dir, file_sep, filename); | ||||
114 | return temp_file; | ||||
115 | } | ||||
116 | |||||
117 | // Read a complete line from fp and return it as a resource allocated string. | ||||
118 | // Returns NULL on EOF. | ||||
119 | static inline char* read_line(FILE* fp) { | ||||
120 | assert(fp != NULL, "invalid fp")do { if (!(fp != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 120, "assert(" "fp != __null" ") failed", "invalid fp"); :: breakpoint(); } } while (0); | ||||
121 | int buflen = 512; | ||||
122 | char* buf = NEW_RESOURCE_ARRAY(char, buflen)(char*) resource_allocate_bytes((buflen) * sizeof(char)); | ||||
123 | long pos = ftell(fp); | ||||
124 | if (pos < 0) return NULL__null; | ||||
125 | |||||
126 | char* ret = fgets(buf, buflen, fp); | ||||
127 | while (ret != NULL__null && buf[strlen(buf) - 1] != '\n' && !feof(fp)) { | ||||
128 | // retry with a larger buffer | ||||
129 | buf = REALLOC_RESOURCE_ARRAY(char, buf, buflen, buflen * 2)(char*) resource_reallocate_bytes((char*)(buf), (buflen) * sizeof (char), (buflen * 2) * sizeof(char)); | ||||
130 | buflen *= 2; | ||||
131 | // rewind to beginning of line | ||||
132 | fseek(fp, pos, SEEK_SET0); | ||||
133 | // retry read with new buffer | ||||
134 | ret = fgets(buf, buflen, fp); | ||||
135 | } | ||||
136 | return ret; | ||||
137 | } | ||||
138 | |||||
139 | static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) { | ||||
140 | AsyncLogWriter::flush(); | ||||
141 | FILE* fp = fopen(filename, "r"); | ||||
142 | assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno))do { if (!(fp != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/test/hotspot/gtest/logging/logTestUtils.inline.hpp" , 142, "assert(" "fp != __null" ") failed", "error opening file %s: %s" , filename, strerror((*__errno_location ()))); ::breakpoint() ; } } while (0); | ||||
143 | |||||
144 | size_t idx = 0; | ||||
145 | while (substrs[idx] != NULL__null) { | ||||
146 | ResourceMark rm; | ||||
147 | char* line = read_line(fp); | ||||
148 | if (line
| ||||
149 | break; | ||||
150 | } | ||||
151 | for (char* match = strstr(line, substrs[idx]); match != NULL__null;) { | ||||
152 | size_t match_len = strlen(substrs[idx]); | ||||
153 | idx++; | ||||
154 | if (substrs[idx] == NULL__null) { | ||||
| |||||
155 | break; | ||||
156 | } | ||||
157 | match = strstr(match + match_len, substrs[idx]); | ||||
158 | } | ||||
159 | } | ||||
160 | |||||
161 | fclose(fp); | ||||
162 | return substrs[idx] == NULL__null; | ||||
163 | } | ||||
164 | |||||
165 | static inline bool file_contains_substring(const char* filename, const char* substr) { | ||||
166 | const char* strs[] = {substr, NULL__null}; | ||||
167 | return file_contains_substrings_in_order(filename, strs); | ||||
168 | } |