Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/logging/test_logStream.cpp
41145 views
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"));
43
}
44
45
TEST_VM_F(LogStreamTest, from_log) {
46
Log(gc) log;
47
LogStream stream(log.debug());
48
49
verify_stream(&stream);
50
}
51
52
TEST_VM_F(LogStreamTest, from_logtarget) {
53
LogTarget(Debug, gc) log;
54
LogStream stream(log);
55
56
verify_stream(&stream);
57
}
58
59
TEST_VM_F(LogStreamTest, handle) {
60
LogStreamHandle(Debug, gc) stream;
61
62
verify_stream(&stream);
63
}
64
65
TEST_VM_F(LogStreamTest, no_rm) {
66
ResourceMark rm;
67
LogStream ls(Log(gc)::debug());
68
verify_stream(&ls);
69
}
70
71
TEST_VM_F(LogStreamTest, TestLineBufferAllocation) {
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) 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);
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');
87
}
88
ASSERT_TRUE(line_buffer[written] == '\0');
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) {
96
LogStream ls(Log(logging)::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);
102
// reset to prevent assert for unflushed content
103
ls._current_line.reset();
104
}
105
106
TEST_VM_F(LogStreamTest, autoflush_on_destruction) {
107
Log(gc) 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"));
114
}
115
116
117