author | coleenp |
Thu, 07 Apr 2016 16:37:35 -0400 | |
changeset 37430 | fd743dadef12 |
parent 37256 | 568ff1f6631c |
child 37461 | b5c955296b75 |
permissions | -rw-r--r-- |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
1 |
/* |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
4 |
* |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
8 |
* |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
13 |
* accompanied this code). |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
14 |
* |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
18 |
* |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
21 |
* questions. |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
22 |
* |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
23 |
*/ |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
24 |
|
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
26 |
|
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
27 |
/////////////// Unit tests /////////////// |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
28 |
|
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
29 |
#ifndef PRODUCT |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
30 |
|
37255 | 31 |
#include "gc/shared/gcTraceTime.inline.hpp" |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
32 |
#include "logging/log.hpp" |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
33 |
#include "logging/logConfiguration.hpp" |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
34 |
#include "logging/logOutput.hpp" |
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
35 |
#include "logging/logStream.inline.hpp" |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
36 |
#include "memory/resourceArea.hpp" |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
37 |
|
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
38 |
#define assert_str_eq(s1, s2) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
39 |
assert(strcmp(s1, s2) == 0, "Expected '%s' to equal '%s'", s1, s2) |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
40 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
41 |
#define assert_char_in(c, s) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
42 |
assert(strchr(s, c) != NULL, "Expected '%s' to contain character '%c'", s, c) |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
43 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
44 |
#define assert_char_not_in(c, s) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
45 |
assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c) |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
46 |
|
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
47 |
class TestLogFile { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
48 |
private: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
49 |
char file_name[256]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
50 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
51 |
void set_name(const char* test_name) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
52 |
const char* tmpdir = os::get_temp_directory(); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
53 |
int pos = jio_snprintf(file_name, sizeof(file_name), "%s%svmtest.%s.%d.log", tmpdir, os::file_separator(), test_name, os::current_process_id()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
54 |
assert(pos > 0, "too small log file name buffer"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
55 |
assert((size_t)pos < sizeof(file_name), "too small log file name buffer"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
56 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
57 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
58 |
public: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
59 |
TestLogFile(const char* test_name) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
60 |
set_name(test_name); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
61 |
remove(name()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
62 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
63 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
64 |
~TestLogFile() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
65 |
remove(name()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
66 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
67 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
68 |
const char* name() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
69 |
return file_name; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
70 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
71 |
}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
72 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
73 |
class TestLogSavedConfig { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
74 |
private: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
75 |
char* _saved_config; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
76 |
char* _new_output; |
37242 | 77 |
Log(logging) _log; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
78 |
public: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
79 |
TestLogSavedConfig(const char* apply_output = NULL, const char* apply_setting = NULL) : _new_output(0) { |
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
80 |
ResourceMark rm; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
81 |
_saved_config = os::strdup_check_oom(LogOutput::Stdout->config_string()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
82 |
bool success = LogConfiguration::parse_log_arguments("stdout", "all=off", NULL, NULL, _log.error_stream()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
83 |
assert(success, "test unable to turn all off"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
84 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
85 |
if (apply_output) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
86 |
_new_output = os::strdup_check_oom(apply_output); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
87 |
bool success = LogConfiguration::parse_log_arguments(_new_output, apply_setting, NULL, NULL, _log.error_stream()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
88 |
assert(success, "test unable to apply test log configuration"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
89 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
90 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
91 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
92 |
~TestLogSavedConfig() { |
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
93 |
ResourceMark rm; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
94 |
if (_new_output) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
95 |
bool success = LogConfiguration::parse_log_arguments(_new_output, "all=off", NULL, NULL, _log.error_stream()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
96 |
assert(success, "test unable to turn all off"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
97 |
os::free(_new_output); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
98 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
99 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
100 |
bool success = LogConfiguration::parse_log_arguments("stdout", _saved_config, NULL, NULL, _log.error_stream()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
101 |
assert(success, "test unable to restore log configuration"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
102 |
os::free(_saved_config); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
103 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
104 |
}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
105 |
|
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
106 |
void Test_configure_stdout() { |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
107 |
LogOutput* stdoutput = LogOutput::Stdout; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
108 |
TestLogSavedConfig tlsc; |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
109 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
110 |
// Enable 'logging=info', verifying it has been set |
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
111 |
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging)); |
37239
a6cda2376a19
8153174: Remove trailing comma from log configuration listings
mlarsson
parents:
37201
diff
changeset
|
112 |
assert_str_eq("logging=info", stdoutput->config_string()); |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
113 |
assert(log_is_enabled(Info, logging), "logging was not properly enabled"); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
114 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
115 |
// Enable 'gc=debug' (no wildcard), verifying no other tags are enabled |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
116 |
LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
117 |
// No '+' character means only single tags are enabled, and no combinations |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
118 |
assert_char_not_in('+', stdoutput->config_string()); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
119 |
assert(log_is_enabled(Debug, gc), "logging was not properly enabled"); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
120 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
121 |
// Enable 'gc*=trace' (with wildcard), verifying at least one tag combination is enabled (gc+...) |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
122 |
LogConfiguration::configure_stdout(LogLevel::Trace, false, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
123 |
assert_char_in('+', stdoutput->config_string()); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
124 |
assert(log_is_enabled(Trace, gc), "logging was not properly enabled"); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
125 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
126 |
// Disable 'gc*' and 'logging', verifying all logging is properly disabled |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
127 |
LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
128 |
LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
129 |
assert_str_eq("all=off", stdoutput->config_string()); |
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
130 |
} |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
131 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
132 |
static int Test_logconfiguration_subscribe_triggered = 0; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
133 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
134 |
static void Test_logconfiguration_subscribe_helper() { |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
135 |
Test_logconfiguration_subscribe_triggered++; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
136 |
} |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
137 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
138 |
void Test_logconfiguration_subscribe() { |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
139 |
ResourceMark rm; |
37242 | 140 |
Log(logging) log; |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
141 |
|
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
142 |
TestLogSavedConfig log_cfg("stdout", "logging*=trace"); |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
143 |
|
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
144 |
LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
145 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
146 |
LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, log.error_stream()); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
147 |
assert(Test_logconfiguration_subscribe_triggered == 1, "subscription not triggered (1)"); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
148 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
149 |
LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc)); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
150 |
assert(Test_logconfiguration_subscribe_triggered == 2, "subscription not triggered (2)"); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
151 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
152 |
LogConfiguration::disable_logging(); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
153 |
assert(Test_logconfiguration_subscribe_triggered == 3, "subscription not triggered (3)"); |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
154 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
155 |
// We need to renable stderr error logging since "disable_logging" disable it all. |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
156 |
// TestLogSavedConfig log_cfg will only renable stdout for us. |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
157 |
LogConfiguration::parse_log_arguments("stderr", "all=warning", NULL, NULL, log.error_stream()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
158 |
assert(Test_logconfiguration_subscribe_triggered == 4, "subscription not triggered (3)"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
159 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
160 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
161 |
#define LOG_PREFIX_STR "THE_PREFIX " |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
162 |
#define LOG_LINE_STR "a log line" |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
163 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
164 |
size_t Test_log_prefix_prefixer(char* buf, size_t len) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
165 |
int ret = jio_snprintf(buf, len, LOG_PREFIX_STR); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
166 |
assert(ret > 0, "Failed to print prefix. Log buffer too small?"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
167 |
return (size_t) ret; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
168 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
169 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
170 |
void Test_log_prefix() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
171 |
TestLogFile log_file("log_prefix"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
172 |
TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
173 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
174 |
log_trace(logging, test)(LOG_LINE_STR); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
175 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
176 |
FILE* fp = fopen(log_file.name(), "r"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
177 |
assert(fp, "File read error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
178 |
char output[1024]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
179 |
if (fgets(output, 1024, fp) != NULL) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
180 |
assert(strstr(output, LOG_PREFIX_STR LOG_LINE_STR), "logging prefix error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
181 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
182 |
fclose(fp); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
183 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
184 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
185 |
void Test_log_big() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
186 |
char big_msg[4096] = {0}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
187 |
char Xchar = '~'; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
188 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
189 |
TestLogFile log_file("log_big"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
190 |
TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
191 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
192 |
memset(big_msg, Xchar, sizeof(big_msg) - 1); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
193 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
194 |
log_trace(logging, test)("%s", big_msg); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
195 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
196 |
FILE* fp = fopen(log_file.name(), "r"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
197 |
assert(fp, "File read error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
198 |
char output[sizeof(big_msg)+128 /*decorators*/ ]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
199 |
if (fgets(output, sizeof(output), fp) != NULL) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
200 |
assert(strstr(output, LOG_PREFIX_STR), "logging prefix error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
201 |
size_t count = 0; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
202 |
for (size_t ps = 0 ; output[ps + count] != '\0'; output[ps + count] == Xchar ? count++ : ps++); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
203 |
assert(count == (sizeof(big_msg) - 1) , "logging msg error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
204 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
205 |
fclose(fp); |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
206 |
} |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
207 |
|
37200 | 208 |
void Test_logtagset_duplicates() { |
209 |
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) { |
|
210 |
char ts_name[512]; |
|
211 |
ts->label(ts_name, sizeof(ts_name), ","); |
|
212 |
||
213 |
// verify that NO_TAG is never followed by a real tag |
|
214 |
for (size_t i = 0; i < LogTag::MaxTags; i++) { |
|
215 |
if (ts->tag(i) == LogTag::__NO_TAG) { |
|
216 |
for (i++; i < LogTag::MaxTags; i++) { |
|
217 |
assert(ts->tag(i) == LogTag::__NO_TAG, |
|
218 |
"NO_TAG was followed by a real tag (%s) in tagset %s", |
|
219 |
LogTag::name(ts->tag(i)), ts_name); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
// verify that there are no duplicate tagsets (same tags in different order) |
|
225 |
for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) { |
|
226 |
if (ts->ntags() != other->ntags()) { |
|
227 |
continue; |
|
228 |
} |
|
229 |
bool equal = true; |
|
230 |
for (size_t i = 0; i < ts->ntags(); i++) { |
|
231 |
LogTagType tag = ts->tag(i); |
|
232 |
if (!other->contains(tag)) { |
|
233 |
equal = false; |
|
234 |
break; |
|
235 |
} |
|
236 |
} |
|
237 |
// Since tagsets are implemented using template arguments, using both of |
|
238 |
// the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will |
|
239 |
// instantiate two different LogTagSetMappings. This causes multiple |
|
240 |
// tagset instances to be created for the same logical set. We want to |
|
241 |
// avoid this to save time, memory and prevent any confusion around it. |
|
242 |
if (equal) { |
|
243 |
char other_name[512]; |
|
244 |
other->label(other_name, sizeof(other_name), ","); |
|
245 |
assert(false, "duplicate LogTagSets found: '%s' vs '%s' " |
|
246 |
"(tags must always be specified in the same order for each tagset)", |
|
247 |
ts_name, other_name); |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
||
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
253 |
#define Test_logtarget_string_literal "First line" |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
254 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
255 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
256 |
static void Test_logtarget_on() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
257 |
TestLogFile log_file("log_target"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
258 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
259 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
260 |
LogTarget(Debug, gc) log; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
261 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
262 |
assert(log.is_enabled(), "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
263 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
264 |
// Log the line and expect it to be available in the output file. |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
265 |
log.print(Test_logtarget_string_literal); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
266 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
267 |
FILE* fp = fopen(log_file.name(), "r"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
268 |
assert(fp != NULL, "File read error"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
269 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
270 |
char output[256 /* Large enough buffer */]; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
271 |
char* res = fgets(output, sizeof(output), fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
272 |
assert(res != NULL, "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
273 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
274 |
assert(strstr(output, Test_logtarget_string_literal) != NULL, "log line missing"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
275 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
276 |
fclose(fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
277 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
278 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
279 |
static void Test_logtarget_off() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
280 |
TestLogFile log_file("log_target"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
281 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
282 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
283 |
LogTarget(Debug, gc) log; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
284 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
285 |
if (log.is_enabled()) { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
286 |
// The log config could have been redirected gc=debug to a file. If gc=debug |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
287 |
// is enabled, we can only test that the LogTarget returns the same value |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
288 |
// as the log_is_enabled function. The rest of the test will be ignored. |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
289 |
assert(log.is_enabled() == log_is_enabled(Debug, gc), "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
290 |
log_warning(logging)("This test doesn't support runs with -Xlog"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
291 |
return; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
292 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
293 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
294 |
// Try to log, but expect this to be filtered out. |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
295 |
log.print(Test_logtarget_string_literal); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
296 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
297 |
// Log a dummy line so that fgets doesn't return NULL because the file is empty. |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
298 |
log_info(gc)("Dummy line"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
299 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
300 |
FILE* fp = fopen(log_file.name(), "r"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
301 |
assert(fp != NULL, "File read error"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
302 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
303 |
char output[256 /* Large enough buffer */]; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
304 |
char* res = fgets(output, sizeof(output), fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
305 |
assert(res != NULL, "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
306 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
307 |
assert(strstr(output, Test_logtarget_string_literal) == NULL, "log line not missing"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
308 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
309 |
fclose(fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
310 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
311 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
312 |
void Test_logtarget() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
313 |
Test_logtarget_on(); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
314 |
Test_logtarget_off(); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
315 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
316 |
|
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
317 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
318 |
static void Test_logstream_helper(outputStream* stream) { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
319 |
TestLogFile log_file("log_stream"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
320 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
321 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
322 |
// Try to log, but expect this to be filtered out. |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
323 |
stream->print("%d ", 3); stream->print("workers"); stream->cr(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
324 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
325 |
FILE* fp = fopen(log_file.name(), "r"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
326 |
assert(fp != NULL, "File read error"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
327 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
328 |
char output[256 /* Large enough buffer */]; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
329 |
char* res = fgets(output, sizeof(output), fp); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
330 |
assert(res != NULL, "assert"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
331 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
332 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
333 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
334 |
fclose(fp); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
335 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
336 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
337 |
static void Test_logstream_log() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
338 |
Log(gc) log; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
339 |
LogStream stream(log.debug()); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
340 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
341 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
342 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
343 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
344 |
static void Test_logstream_logtarget() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
345 |
LogTarget(Debug, gc) log; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
346 |
LogStream stream(log); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
347 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
348 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
349 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
350 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
351 |
static void Test_logstream_logstreamhandle() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
352 |
LogStreamHandle(Debug, gc) stream; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
353 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
354 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
355 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
356 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
357 |
static void Test_logstream_no_rm() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
358 |
ResourceMark rm; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
359 |
outputStream* stream = LogTarget(Debug, gc)::stream(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
360 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
361 |
Test_logstream_helper(stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
362 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
363 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
364 |
void Test_logstream() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
365 |
Test_logstream_log(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
366 |
Test_logstream_logtarget(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
367 |
Test_logstream_logstreamhandle(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
368 |
Test_logstream_no_rm(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
369 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
370 |
|
37255 | 371 |
void Test_loghandle_on() { |
372 |
TestLogFile log_file("log_handle"); |
|
373 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
|
374 |
||
375 |
Log(gc) log; |
|
376 |
LogHandle log_handle(log); |
|
377 |
||
378 |
assert(log_handle.is_debug(), "assert"); |
|
379 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
380 |
// Try to log through a LogHandle. |
37255 | 381 |
log_handle.debug("%d workers", 3); |
382 |
||
383 |
FILE* fp = fopen(log_file.name(), "r"); |
|
384 |
assert(fp, "File read error"); |
|
385 |
||
386 |
char output[256 /* Large enough buffer */]; |
|
387 |
char* res = fgets(output, sizeof(output), fp); |
|
388 |
assert(res != NULL, "assert"); |
|
389 |
||
390 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
|
391 |
||
392 |
fclose(fp); |
|
393 |
} |
|
394 |
||
395 |
void Test_loghandle_off() { |
|
396 |
TestLogFile log_file("log_handle"); |
|
397 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
|
398 |
||
399 |
Log(gc) log; |
|
400 |
LogHandle log_handle(log); |
|
401 |
||
402 |
if (log_handle.is_debug()) { |
|
403 |
// The log config could have been redirected gc=debug to a file. If gc=debug |
|
404 |
// is enabled, we can only test that the LogTarget returns the same value |
|
405 |
// as the log_is_enabled function. The rest of the test will be ignored. |
|
406 |
assert(log_handle.is_debug() == log_is_enabled(Debug, gc), "assert"); |
|
407 |
log_warning(logging)("This test doesn't support runs with -Xlog"); |
|
408 |
return; |
|
409 |
} |
|
410 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
411 |
// Try to log through a LogHandle. Should fail, since only info is turned on. |
37255 | 412 |
log_handle.debug("%d workers", 3); |
413 |
||
414 |
// Log a dummy line so that fgets doesn't return NULL because the file is empty. |
|
415 |
log_info(gc)("Dummy line"); |
|
416 |
||
417 |
FILE* fp = fopen(log_file.name(), "r"); |
|
418 |
assert(fp, "File read error"); |
|
419 |
||
420 |
char output[256 /* Large enough buffer */]; |
|
421 |
char* res = fgets(output, sizeof(output), fp); |
|
422 |
assert(res != NULL, "assert"); |
|
423 |
||
424 |
assert(strstr(output, "3 workers") == NULL, "log line missing"); |
|
425 |
||
426 |
fclose(fp); |
|
427 |
} |
|
428 |
||
429 |
void Test_loghandle() { |
|
430 |
Test_loghandle_on(); |
|
431 |
Test_loghandle_off(); |
|
432 |
} |
|
433 |
||
434 |
static void Test_logtargethandle_on() { |
|
435 |
TestLogFile log_file("log_handle"); |
|
436 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
|
437 |
||
438 |
LogTarget(Debug, gc) log; |
|
439 |
LogTargetHandle log_handle(log); |
|
440 |
||
441 |
assert(log_handle.is_enabled(), "assert"); |
|
442 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
443 |
// Try to log through a LogHandle. |
37255 | 444 |
log_handle.print("%d workers", 3); |
445 |
||
446 |
FILE* fp = fopen(log_file.name(), "r"); |
|
447 |
assert(fp, "File read error"); |
|
448 |
||
449 |
char output[256 /* Large enough buffer */]; |
|
450 |
char* res = fgets(output, sizeof(output), fp); |
|
451 |
assert(res != NULL, "assert"); |
|
452 |
||
453 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
|
454 |
||
455 |
fclose(fp); |
|
456 |
} |
|
457 |
||
458 |
static void Test_logtargethandle_off() { |
|
459 |
TestLogFile log_file("log_handle"); |
|
460 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
|
461 |
||
462 |
LogTarget(Debug, gc) log; |
|
463 |
LogTargetHandle log_handle(log); |
|
464 |
||
465 |
if (log_handle.is_enabled()) { |
|
466 |
// The log config could have been redirected gc=debug to a file. If gc=debug |
|
467 |
// is enabled, we can only test that the LogTarget returns the same value |
|
468 |
// as the log_is_enabled function. The rest of the test will be ignored. |
|
469 |
assert(log_handle.is_enabled() == log_is_enabled(Debug, gc), "assert"); |
|
470 |
log_warning(logging)("This test doesn't support runs with -Xlog"); |
|
471 |
return; |
|
472 |
} |
|
473 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
474 |
// Try to log through a LogHandle. Should fail, since only info is turned on. |
37255 | 475 |
log_handle.print("%d workers", 3); |
476 |
||
477 |
// Log a dummy line so that fgets doesn't return NULL because the file is empty. |
|
478 |
log_info(gc)("Dummy line"); |
|
479 |
||
480 |
FILE* fp = fopen(log_file.name(), "r"); |
|
481 |
assert(fp, "File read error"); |
|
482 |
||
483 |
char output[256 /* Large enough buffer */]; |
|
484 |
char* res = fgets(output, sizeof(output), fp); |
|
485 |
assert(res != NULL, "assert"); |
|
486 |
||
487 |
assert(strstr(output, "3 workers") == NULL, "log line missing"); |
|
488 |
||
489 |
fclose(fp); |
|
490 |
} |
|
491 |
||
492 |
void Test_logtargethandle() { |
|
493 |
Test_logtargethandle_on(); |
|
494 |
Test_logtargethandle_off(); |
|
495 |
} |
|
496 |
||
497 |
static void Test_log_gctracetime_full() { |
|
498 |
TestLogFile log_file("log_gctracetime"); |
|
499 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
500 |
||
501 |
LogTarget(Debug, gc) gc_debug; |
|
502 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
503 |
||
504 |
assert(gc_debug.is_enabled(), "assert"); |
|
505 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
506 |
||
507 |
{ |
|
508 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
509 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, true); |
|
510 |
} |
|
511 |
||
512 |
FILE* fp = fopen(log_file.name(), "r"); |
|
513 |
assert(fp, "File read error"); |
|
514 |
||
515 |
char output[256 /* Large enough buffer */]; |
|
516 |
||
517 |
char* res = fgets(output, sizeof(output), fp); |
|
518 |
assert(res != NULL, "assert"); |
|
519 |
||
520 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
521 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
522 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
523 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
524 |
||
525 |
res = fgets(output, sizeof(output), fp); |
|
526 |
assert(res != NULL, "assert"); |
|
527 |
||
528 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
529 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
530 |
assert(strstr(output, "] Test GC (Allocation Failure) ") != NULL, "Incorrect log line"); |
|
531 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
532 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
533 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
534 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
535 |
||
536 |
fclose(fp); |
|
537 |
} |
|
538 |
||
539 |
static void Test_log_gctracetime_full_multitag() { |
|
540 |
TestLogFile log_file("log_gctracetime"); |
|
541 |
TestLogSavedConfig tlsc(log_file.name(), "gc+ref=debug,gc+ref+start=debug"); |
|
542 |
||
543 |
LogTarget(Debug, gc, ref) gc_debug; |
|
544 |
LogTarget(Debug, gc, ref, start) gc_start_debug; |
|
545 |
||
546 |
assert(gc_debug.is_enabled(), "assert"); |
|
547 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
548 |
||
549 |
{ |
|
550 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
551 |
GCTraceTime(Debug, gc, ref) timer("Test GC", NULL, GCCause::_allocation_failure, true); |
|
552 |
} |
|
553 |
||
554 |
FILE* fp = fopen(log_file.name(), "r"); |
|
555 |
assert(fp, "File read error"); |
|
556 |
||
557 |
char output[256 /* Large enough buffer */]; |
|
558 |
||
559 |
char* res = fgets(output, sizeof(output), fp); |
|
560 |
assert(res != NULL, "assert"); |
|
561 |
||
562 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
563 |
assert(strstr(output, "[gc,ref,start") != NULL, "Incorrect tag set"); |
|
564 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
565 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
566 |
||
567 |
res = fgets(output, sizeof(output), fp); |
|
568 |
assert(res != NULL, "assert"); |
|
569 |
||
570 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
571 |
assert(strstr(output, "[gc,ref ") != NULL, "Incorrect tag set"); |
|
572 |
assert(strstr(output, "] Test GC (Allocation Failure) ") != NULL, "Incorrect log line"); |
|
573 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
574 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
575 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
576 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
577 |
||
578 |
fclose(fp); |
|
579 |
} |
|
580 |
||
581 |
static void Test_log_gctracetime_no_heap() { |
|
582 |
TestLogFile log_file("log_gctracetime"); |
|
583 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
584 |
||
585 |
LogTarget(Debug, gc) gc_debug; |
|
586 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
587 |
||
588 |
assert(gc_debug.is_enabled(), "assert"); |
|
589 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
590 |
||
591 |
{ |
|
592 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, false); |
|
593 |
} |
|
594 |
||
595 |
FILE* fp = fopen(log_file.name(), "r"); |
|
596 |
assert(fp, "File read error"); |
|
597 |
||
598 |
char output[256 /* Large enough buffer */]; |
|
599 |
||
600 |
char* res = fgets(output, sizeof(output), fp); |
|
601 |
assert(res != NULL, "assert"); |
|
602 |
||
603 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
604 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
605 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
606 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
607 |
||
608 |
res = fgets(output, sizeof(output), fp); |
|
609 |
assert(res != NULL, "assert"); |
|
610 |
||
611 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) (2.975s, 2.975s) 0.026ms |
|
612 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
613 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
614 |
assert(strstr(output, "M) (") == NULL, "Incorrect log line"); |
|
615 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
616 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
617 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
618 |
||
619 |
fclose(fp); |
|
620 |
} |
|
621 |
||
622 |
static void Test_log_gctracetime_no_cause() { |
|
623 |
TestLogFile log_file("log_gctracetime"); |
|
624 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
625 |
||
626 |
LogTarget(Debug, gc) gc_debug; |
|
627 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
628 |
||
629 |
assert(gc_debug.is_enabled(), "assert"); |
|
630 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
631 |
||
632 |
{ |
|
633 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
634 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, true); |
|
635 |
} |
|
636 |
||
637 |
FILE* fp = fopen(log_file.name(), "r"); |
|
638 |
assert(fp, "File read error"); |
|
639 |
||
640 |
char output[256 /* Large enough buffer */]; |
|
641 |
||
642 |
char* res = fgets(output, sizeof(output), fp); |
|
643 |
assert(res != NULL, "assert"); |
|
644 |
||
645 |
// [2.975s][debug][gc,start] Test GC (2.975s) |
|
646 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
647 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
648 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
649 |
||
650 |
res = fgets(output, sizeof(output), fp); |
|
651 |
assert(res != NULL, "assert"); |
|
652 |
||
653 |
// [2.975s][debug][gc ] Test GC 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
654 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
655 |
assert(strstr(output, "] Test GC ") != NULL, "Incorrect log line"); |
|
656 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
657 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
658 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
659 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
660 |
||
661 |
fclose(fp); |
|
662 |
} |
|
663 |
||
664 |
static void Test_log_gctracetime_no_heap_no_cause() { |
|
665 |
TestLogFile log_file("log_gctracetime"); |
|
666 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
667 |
||
668 |
LogTarget(Debug, gc) gc_debug; |
|
669 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
670 |
||
671 |
assert(gc_debug.is_enabled(), "assert"); |
|
672 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
673 |
||
674 |
{ |
|
675 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
676 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, false); |
|
677 |
} |
|
678 |
||
679 |
FILE* fp = fopen(log_file.name(), "r"); |
|
680 |
assert(fp, "File read error"); |
|
681 |
||
682 |
char output[256 /* Large enough buffer */]; |
|
683 |
||
684 |
char* res = fgets(output, sizeof(output), fp); |
|
685 |
assert(res != NULL, "assert"); |
|
686 |
||
687 |
// [2.975s][debug][gc,start] Test GC (2.975s) |
|
688 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
689 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
690 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
691 |
||
692 |
res = fgets(output, sizeof(output), fp); |
|
693 |
assert(res != NULL, "assert"); |
|
694 |
||
695 |
// [2.975s][debug][gc ] Test GC (2.975s, 2.975s) 0.026ms |
|
696 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
697 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
698 |
assert(strstr(output, "M) (") == NULL, "Incorrect log line"); |
|
699 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
700 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
701 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
702 |
||
703 |
fclose(fp); |
|
704 |
} |
|
705 |
||
706 |
void Test_log_gctracetime() { |
|
707 |
Test_log_gctracetime_full(); |
|
708 |
Test_log_gctracetime_full_multitag(); |
|
709 |
Test_log_gctracetime_no_heap(); |
|
710 |
Test_log_gctracetime_no_cause(); |
|
711 |
Test_log_gctracetime_no_heap_no_cause(); |
|
712 |
} |
|
713 |
||
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
714 |
#endif // PRODUCT |