Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/logging/test_log.cpp
41145 views
1
/*
2
* Copyright (c) 2015, 2017, 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 "unittest.hpp"
31
32
class LogTest : public LogTestFixture {
33
};
34
35
#define LOG_PREFIX_STR "THE_PREFIX "
36
#define LOG_LINE_STR "a log line"
37
38
size_t Test_log_prefix_prefixer(char* buf, size_t len) {
39
int ret = jio_snprintf(buf, len, LOG_PREFIX_STR);
40
assert(ret > 0, "Failed to print prefix. Log buffer too small?");
41
return (size_t) ret;
42
}
43
44
#ifdef ASSERT // 'test' tag is debug only
45
TEST_VM_F(LogTest, prefix) {
46
set_log_config(TestLogFileName, "logging+test=trace");
47
log_trace(logging, test)(LOG_LINE_STR);
48
EXPECT_TRUE(file_contains_substring(TestLogFileName, LOG_PREFIX_STR LOG_LINE_STR));
49
}
50
#endif
51
52
TEST_VM_F(LogTest, large_message) {
53
char big_msg[4096] = {0};
54
char Xchar = '~';
55
56
set_log_config(TestLogFileName, "logging=trace");
57
58
memset(big_msg, Xchar, sizeof(big_msg) - 1);
59
log_trace(logging)("%s", big_msg);
60
61
AsyncLogWriter::flush();
62
ResourceMark rm;
63
FILE* fp = fopen(TestLogFileName, "r");
64
ASSERT_NE((void*)NULL, fp);
65
char* output = read_line(fp);
66
fclose(fp);
67
68
size_t count = 0;
69
for (size_t ps = 0 ; output[ps + count] != '\0'; output[ps + count] == Xchar ? count++ : ps++);
70
EXPECT_EQ(sizeof(big_msg) - 1, count);
71
}
72
73
TEST_VM_F(LogTest, enabled_logtarget) {
74
set_log_config(TestLogFileName, "gc=debug");
75
76
LogTarget(Debug, gc) log;
77
EXPECT_TRUE(log.is_enabled());
78
79
// Log the line and expect it to be available in the output file.
80
log.print(LOG_TEST_STRING_LITERAL);
81
82
EXPECT_TRUE(file_contains_substring(TestLogFileName, LOG_TEST_STRING_LITERAL));
83
}
84
85
TEST_VM_F(LogTest, disabled_logtarget) {
86
set_log_config(TestLogFileName, "gc=info");
87
88
LogTarget(Debug, gc) log;
89
EXPECT_FALSE(log.is_enabled());
90
91
// Try to log, but expect this to be filtered out.
92
log.print(LOG_TEST_STRING_LITERAL);
93
94
// Log a dummy line so that fgets doesn't return NULL because the file is empty.
95
log_info(gc)("Dummy line");
96
97
EXPECT_FALSE(file_contains_substring(TestLogFileName, LOG_TEST_STRING_LITERAL));
98
}
99
100
TEST_VM_F(LogTest, enabled_loghandle) {
101
set_log_config(TestLogFileName, "gc=debug");
102
103
Log(gc) log;
104
LogHandle log_handle(log);
105
106
EXPECT_TRUE(log_handle.is_debug());
107
108
// Try to log through a LogHandle.
109
log_handle.debug("%d workers", 3);
110
111
EXPECT_TRUE(file_contains_substring(TestLogFileName, "3 workers"));
112
}
113
114
TEST_VM_F(LogTest, disabled_loghandle) {
115
set_log_config(TestLogFileName, "gc=info");
116
117
Log(gc) log;
118
LogHandle log_handle(log);
119
120
EXPECT_FALSE(log_handle.is_debug());
121
122
// Try to log through a LogHandle.
123
log_handle.debug("%d workers", 3);
124
125
// Log a dummy line so that fgets doesn't return NULL because the file is empty.
126
log_info(gc)("Dummy line");
127
128
EXPECT_FALSE(file_contains_substring(TestLogFileName, "3 workers"));
129
}
130
131
TEST_VM_F(LogTest, enabled_logtargethandle) {
132
set_log_config(TestLogFileName, "gc=debug");
133
134
LogTarget(Debug, gc) log;
135
LogTargetHandle log_handle(log);
136
137
EXPECT_TRUE(log_handle.is_enabled());
138
139
// Try to log through a LogHandle.
140
log_handle.print("%d workers", 3);
141
142
EXPECT_TRUE(file_contains_substring(TestLogFileName, "3 workers"));
143
}
144
145
TEST_VM_F(LogTest, disabled_logtargethandle) {
146
set_log_config(TestLogFileName, "gc=info");
147
148
LogTarget(Debug, gc) log;
149
LogTargetHandle log_handle(log);
150
151
EXPECT_FALSE(log_handle.is_enabled());
152
153
// Try to log through a LogHandle.
154
log_handle.print("%d workers", 3);
155
156
// Log a dummy line so that fgets doesn't return NULL because the file is empty.
157
log_info(gc)("Dummy line");
158
159
EXPECT_FALSE(file_contains_substring(TestLogFileName, "3 workers"));
160
}
161
162