author | mlarsson |
Mon, 09 May 2016 15:46:12 +0200 | |
changeset 38263 | a7488329ad27 |
parent 37465 | 1d5551f466ee |
child 38292 | 73a0be9b2f47 |
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" |
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
34 |
#include "logging/logFileOutput.hpp" |
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
35 |
#include "logging/logMessage.hpp" |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
36 |
#include "logging/logMessageBuffer.hpp" |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
37 |
#include "logging/logOutput.hpp" |
37463
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
38 |
#include "logging/logTagLevelExpression.hpp" |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
39 |
#include "logging/logTagSet.hpp" |
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
40 |
#include "logging/logStream.inline.hpp" |
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
41 |
#include "memory/resourceArea.hpp" |
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
42 |
|
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
43 |
#define assert_str_eq(s1, s2) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
44 |
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
|
45 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
46 |
#define assert_char_in(c, s) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
47 |
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
|
48 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
49 |
#define assert_char_not_in(c, s) \ |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
50 |
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
|
51 |
|
37463
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
52 |
void Test_log_tag_combinations_limit() { |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
53 |
assert(LogTagLevelExpression::MaxCombinations > LogTagSet::ntagsets(), |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
54 |
"Combination limit (" SIZE_FORMAT ") not sufficient " |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
55 |
"for configuring all available tag sets (" SIZE_FORMAT ")", |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
56 |
LogTagLevelExpression::MaxCombinations, LogTagSet::ntagsets()); |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
57 |
} |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37461
diff
changeset
|
58 |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
59 |
// Read a complete line from fp and return it as a resource allocated string. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
60 |
// Returns NULL on EOF. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
61 |
static char* read_line(FILE* fp) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
62 |
assert(fp != NULL, "bad fp"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
63 |
int buflen = 512; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
64 |
char* buf = NEW_RESOURCE_ARRAY(char, buflen); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
65 |
long pos = ftell(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
66 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
67 |
char* ret = fgets(buf, buflen, fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
68 |
while (ret != NULL && buf[strlen(buf) - 1] != '\n' && !feof(fp)) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
69 |
// retry with a larger buffer |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
70 |
buf = REALLOC_RESOURCE_ARRAY(char, buf, buflen, buflen * 2); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
71 |
buflen *= 2; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
72 |
// rewind to beginning of line |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
73 |
fseek(fp, pos, SEEK_SET); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
74 |
// retry read with new buffer |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
75 |
ret = fgets(buf, buflen, fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
76 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
77 |
return ret; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
78 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
79 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
80 |
static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
81 |
FILE* fp = fopen(filename, "r"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
82 |
assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno)); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
83 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
84 |
size_t idx = 0; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
85 |
while (substrs[idx] != NULL) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
86 |
ResourceMark rm; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
87 |
char* line = read_line(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
88 |
if (line == NULL) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
89 |
break; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
90 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
91 |
for (char* match = strstr(line, substrs[idx]); match != NULL;) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
92 |
size_t match_len = strlen(substrs[idx]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
93 |
idx++; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
94 |
if (substrs[idx] == NULL) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
95 |
break; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
96 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
97 |
match = strstr(match + match_len, substrs[idx]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
98 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
99 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
100 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
101 |
fclose(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
102 |
return substrs[idx] == NULL; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
103 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
104 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
105 |
static bool file_contains_substring(const char* filename, const char* substr) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
106 |
const char* strs[] = {substr, NULL}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
107 |
return file_contains_substrings_in_order(filename, strs); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
108 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
109 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
110 |
static size_t number_of_lines_with_substring_in_file(const char* filename, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
111 |
const char* substr) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
112 |
FILE* fp = fopen(filename, "r"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
113 |
assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno)); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
114 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
115 |
size_t ret = 0; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
116 |
for (;;) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
117 |
ResourceMark rm; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
118 |
char* line = read_line(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
119 |
if (line == NULL) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
120 |
break; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
121 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
122 |
if (strstr(line, substr) != NULL) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
123 |
ret++; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
124 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
125 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
126 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
127 |
fclose(fp); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
128 |
return ret; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
129 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
130 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
131 |
static bool file_exists(const char* filename) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
132 |
struct stat st; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
133 |
return os::stat(filename, &st) == 0; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
134 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
135 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
136 |
static void delete_file(const char* filename) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
137 |
if (!file_exists(filename)) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
138 |
return; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
139 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
140 |
int ret = remove(filename); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
141 |
assert(ret == 0, "failed to remove file '%s': %s", filename, strerror(errno)); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
142 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
143 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
144 |
static void create_directory(const char* name) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
145 |
assert(!file_exists(name), "can't create directory: %s already exists", name); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
146 |
bool failed; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
147 |
#ifdef _WINDOWS |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
148 |
failed = !CreateDirectory(name, NULL); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
149 |
#else |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
150 |
failed = mkdir(name, 0777); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
151 |
#endif |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
152 |
assert(!failed, "failed to create directory %s", name); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
153 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
154 |
|
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
155 |
class TestLogFile { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
156 |
private: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
157 |
char file_name[256]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
158 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
159 |
void set_name(const char* test_name) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
160 |
const char* tmpdir = os::get_temp_directory(); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
161 |
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
|
162 |
assert(pos > 0, "too small log file name buffer"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
163 |
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
|
164 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
165 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
166 |
public: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
167 |
TestLogFile(const char* test_name) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
168 |
set_name(test_name); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
169 |
remove(name()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
170 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
171 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
172 |
~TestLogFile() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
173 |
remove(name()); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
174 |
} |
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 |
const char* name() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
177 |
return file_name; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
178 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
179 |
}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
180 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
181 |
class TestLogSavedConfig { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
182 |
private: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
183 |
char* _saved_config; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
184 |
char* _new_output; |
37242 | 185 |
Log(logging) _log; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
186 |
public: |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
187 |
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
|
188 |
ResourceMark rm; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
189 |
_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
|
190 |
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
|
191 |
assert(success, "test unable to turn all off"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
192 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
193 |
if (apply_output) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
194 |
_new_output = os::strdup_check_oom(apply_output); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
195 |
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
|
196 |
assert(success, "test unable to apply test log configuration"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
197 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
198 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
199 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
200 |
~TestLogSavedConfig() { |
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
201 |
ResourceMark rm; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
202 |
if (_new_output) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
203 |
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
|
204 |
assert(success, "test unable to turn all off"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
205 |
os::free(_new_output); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
206 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
207 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
208 |
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
|
209 |
assert(success, "test unable to restore log configuration"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
210 |
os::free(_saved_config); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
211 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
212 |
}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
213 |
|
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
214 |
void Test_configure_stdout() { |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
215 |
LogOutput* stdoutput = LogOutput::Stdout; |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
216 |
TestLogSavedConfig tlsc; |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
217 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
218 |
// Enable 'logging=info', verifying it has been set |
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
219 |
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging)); |
37239
a6cda2376a19
8153174: Remove trailing comma from log configuration listings
mlarsson
parents:
37201
diff
changeset
|
220 |
assert_str_eq("logging=info", stdoutput->config_string()); |
35950
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
221 |
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
|
222 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
223 |
// 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
|
224 |
LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
225 |
// 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
|
226 |
assert_char_not_in('+', stdoutput->config_string()); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
227 |
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
|
228 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
229 |
// 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
|
230 |
LogConfiguration::configure_stdout(LogLevel::Trace, false, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
231 |
assert_char_in('+', stdoutput->config_string()); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
232 |
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
|
233 |
|
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
234 |
// Disable 'gc*' and 'logging', verifying all logging is properly disabled |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
235 |
LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
236 |
LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging)); |
c6142cb6bc4a
8149112: configure_stdout test depends on VM arguments
mlarsson
parents:
35852
diff
changeset
|
237 |
assert_str_eq("all=off", stdoutput->config_string()); |
35852
15ca44d4ae0c
8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents:
35228
diff
changeset
|
238 |
} |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
239 |
|
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
240 |
static const char* ExpectedLine = "a (hopefully) unique log line for testing"; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
241 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
242 |
static void init_file(const char* filename, const char* options = "") { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
243 |
LogConfiguration::parse_log_arguments(filename, "logging=trace", "", options, |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
244 |
Log(logging)::error_stream()); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
245 |
log_debug(logging)("%s", ExpectedLine); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
246 |
LogConfiguration::parse_log_arguments(filename, "all=off", "", "", |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
247 |
Log(logging)::error_stream()); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
248 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
249 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
250 |
void Test_log_file_startup_rotation() { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
251 |
ResourceMark rm; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
252 |
const size_t rotations = 5; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
253 |
const char* filename = "start-rotate-test"; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
254 |
char* rotated_file[rotations]; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
255 |
for (size_t i = 0; i < rotations; i++) { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
256 |
size_t len = strlen(filename) + 3; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
257 |
rotated_file[i] = NEW_RESOURCE_ARRAY(char, len); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
258 |
jio_snprintf(rotated_file[i], len, "%s." SIZE_FORMAT, filename, i); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
259 |
delete_file(rotated_file[i]); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
260 |
}; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
261 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
262 |
delete_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
263 |
init_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
264 |
assert(file_exists(filename), |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
265 |
"configured logging to file '%s' but file was not found", filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
266 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
267 |
// Initialize the same file a bunch more times to trigger rotations |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
268 |
for (size_t i = 0; i < rotations; i++) { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
269 |
init_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
270 |
assert(file_exists(rotated_file[i]), "existing file was not rotated"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
271 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
272 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
273 |
// Remove a file and expect its slot to be re-used |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
274 |
delete_file(rotated_file[1]); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
275 |
init_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
276 |
assert(file_exists(rotated_file[1]), "log file not properly rotated"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
277 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
278 |
// Clean up after test |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
279 |
delete_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
280 |
for (size_t i = 0; i < rotations; i++) { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
281 |
delete_file(rotated_file[i]); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
282 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
283 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
284 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
285 |
void Test_log_file_startup_truncation() { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
286 |
ResourceMark rm; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
287 |
const char* filename = "start-truncate-test"; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
288 |
const char* archived_filename = "start-truncate-test.0"; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
289 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
290 |
delete_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
291 |
delete_file(archived_filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
292 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
293 |
// Use the same log file twice and expect it to be overwritten/truncated |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
294 |
init_file(filename, "filecount=0"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
295 |
assert(file_exists(filename), "couldn't find log file: %s", filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
296 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
297 |
init_file(filename, "filecount=0"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
298 |
assert(file_exists(filename), "couldn't find log file: %s", filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
299 |
assert(!file_exists(archived_filename), |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
300 |
"existing log file %s was not properly truncated when filecount was 0", |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
301 |
filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
302 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
303 |
// Verify that the file was really truncated and not just appended |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
304 |
assert(number_of_lines_with_substring_in_file(filename, ExpectedLine) == 1, |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
305 |
"log file %s appended rather than truncated", filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
306 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
307 |
delete_file(filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
308 |
delete_file(archived_filename); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
309 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
310 |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
311 |
class LogMessageTest { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
312 |
private: |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
313 |
static Log(logging) _log; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
314 |
static const char* _level_filename[]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
315 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
316 |
static void test_level_inclusion(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
317 |
static void test_long_message(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
318 |
static void test_message_with_many_lines(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
319 |
static void test_line_order(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
320 |
static void test_prefixing(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
321 |
static void test_scoped_messages(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
322 |
static void test_scoped_flushing(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
323 |
static void test_scoped_reset(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
324 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
325 |
public: |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
326 |
static void test(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
327 |
}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
328 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
329 |
const char* LogMessageTest::_level_filename[] = { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
330 |
NULL, // LogLevel::Off |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
331 |
#define LOG_LEVEL(name, printname) "multiline-" #printname ".log", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
332 |
LOG_LEVEL_LIST |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
333 |
#undef LOG_LEVEL |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
334 |
}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
335 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
336 |
void Test_multiline_logging() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
337 |
LogMessageTest::test(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
338 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
339 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
340 |
void LogMessageTest::test() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
341 |
ResourceMark rm; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
342 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
343 |
for (int i = 0; i < LogLevel::Count; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
344 |
char buf[32]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
345 |
// Attempt to remove possibly pre-existing log files |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
346 |
remove(_level_filename[i]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
347 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
348 |
jio_snprintf(buf, sizeof(buf), "logging=%s", LogLevel::name(static_cast<LogLevelType>(i))); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
349 |
bool success = LogConfiguration::parse_log_arguments(_level_filename[i], buf, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
350 |
NULL, NULL, _log.error_stream()); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
351 |
assert(success, "unable to configure logging to file '%s'", _level_filename[i]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
352 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
353 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
354 |
test_level_inclusion(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
355 |
test_line_order(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
356 |
test_long_message(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
357 |
test_message_with_many_lines(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
358 |
test_prefixing(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
359 |
test_scoped_messages(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
360 |
test_scoped_flushing(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
361 |
test_scoped_reset(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
362 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
363 |
// Stop logging to the files and remove them. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
364 |
for (int i = 0; i < LogLevel::Count; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
365 |
LogConfiguration::parse_log_arguments(_level_filename[i], "all=off", NULL, NULL, _log.error_stream()); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
366 |
remove(_level_filename[i]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
367 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
368 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
369 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
370 |
// Verify that messages with multiple levels are written |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
371 |
// to outputs configured for all the corresponding levels |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
372 |
void LogMessageTest::test_level_inclusion() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
373 |
const size_t message_count = 10; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
374 |
LogMessageBuffer msg[message_count]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
375 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
376 |
struct { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
377 |
int message_number; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
378 |
LogLevelType level; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
379 |
} lines[] = { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
380 |
{ 0, LogLevel::Error }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
381 |
{ 1, LogLevel::Info }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
382 |
{ 2, LogLevel::Info }, { 2, LogLevel::Debug }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
383 |
{ 3, LogLevel::Info }, { 3, LogLevel::Warning }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
384 |
{ 4, LogLevel::Debug }, { 4, LogLevel::Warning }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
385 |
{ 5, LogLevel::Trace }, { 5, LogLevel::Debug }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
386 |
{ 6, LogLevel::Warning }, { 6, LogLevel::Error }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
387 |
{ 7, LogLevel::Trace }, { 7, LogLevel::Info }, { 7, LogLevel::Debug }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
388 |
{ 8, LogLevel::Trace }, { 8, LogLevel::Debug }, { 8, LogLevel::Info }, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
389 |
{ 8, LogLevel::Warning }, { 8, LogLevel::Error}, |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
390 |
{ 9, LogLevel::Trace } |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
391 |
}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
392 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
393 |
// Fill in messages with the above lines |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
394 |
for (size_t i = 0; i < ARRAY_SIZE(lines); i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
395 |
switch (lines[i].level) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
396 |
#define LOG_LEVEL(name, printname) \ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
397 |
case LogLevel::name: \ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
398 |
msg[lines[i].message_number].printname("msg[%d]: " #printname, lines[i].message_number); \ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
399 |
break; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
400 |
LOG_LEVEL_LIST |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
401 |
#undef LOG_LEVEL |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
402 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
403 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
404 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
405 |
for (size_t i = 0; i < message_count; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
406 |
_log.write(msg[i]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
407 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
408 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
409 |
// Verify that lines are written to the expected log files |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
410 |
for (size_t i = 0; i < ARRAY_SIZE(lines); i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
411 |
char expected[256]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
412 |
jio_snprintf(expected, sizeof(expected), "msg[%d]: %s", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
413 |
lines[i].message_number, LogLevel::name(lines[i].level)); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
414 |
for (int level = lines[i].level; level > 0; level--) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
415 |
assert(file_contains_substring(_level_filename[level], expected), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
416 |
"line #" SIZE_FORMAT " missing from log file '%s'", i, _level_filename[level]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
417 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
418 |
for (int level = lines[i].level + 1; level < LogLevel::Count; level++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
419 |
assert(!file_contains_substring(_level_filename[level], expected), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
420 |
"line #" SIZE_FORMAT " erroneously included in log file '%s'", i, _level_filename[level]); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
421 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
422 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
423 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
424 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
425 |
// Verify that messages are logged in the order they are added to the log message |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
426 |
void LogMessageTest::test_line_order() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
427 |
LogMessageBuffer msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
428 |
msg.info("info line").error("error line").trace("trace line") |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
429 |
.error("another error").warning("warning line").debug("debug line"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
430 |
_log.write(msg); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
431 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
432 |
const char* expected[] = { "info line", "error line", "trace line", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
433 |
"another error", "warning line", "debug line", NULL }; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
434 |
assert(file_contains_substrings_in_order(_level_filename[LogLevel::Trace], expected), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
435 |
"output missing or in incorrect order"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
436 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
437 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
438 |
void LogMessageTest::test_long_message() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
439 |
// Write 10K bytes worth of log data |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
440 |
LogMessageBuffer msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
441 |
const size_t size = 10 * K; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
442 |
const char* start_marker = "#start#"; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
443 |
const char* end_marker = "#the end#"; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
444 |
char* data = NEW_C_HEAP_ARRAY(char, size, mtLogging); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
445 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
446 |
// fill buffer with start_marker...some data...end_marker |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
447 |
sprintf(data, "%s", start_marker); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
448 |
for (size_t i = strlen(start_marker); i < size; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
449 |
data[i] = '0' + (i % 10); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
450 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
451 |
sprintf(data + size - strlen(end_marker) - 1, "%s", end_marker); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
452 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
453 |
msg.trace("%s", data); // Adds a newline, making the message exactly 10K in length. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
454 |
_log.write(msg); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
455 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
456 |
const char* expected[] = { start_marker, "0123456789", end_marker, NULL }; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
457 |
assert(file_contains_substrings_in_order(_level_filename[LogLevel::Trace], expected), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
458 |
"unable to print long line"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
459 |
FREE_C_HEAP_ARRAY(char, data); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
460 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
461 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
462 |
void LogMessageTest::test_message_with_many_lines() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
463 |
const size_t lines = 100; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
464 |
const size_t line_length = 16; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
465 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
466 |
LogMessageBuffer msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
467 |
for (size_t i = 0; i < lines; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
468 |
msg.info("Line #" SIZE_FORMAT, i); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
469 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
470 |
_log.write(msg); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
471 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
472 |
char expected_lines_data[lines][line_length]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
473 |
const char* expected_lines[lines + 1]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
474 |
for (size_t i = 0; i < lines; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
475 |
jio_snprintf(&expected_lines_data[i][0], line_length, "Line #" SIZE_FORMAT, i); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
476 |
expected_lines[i] = expected_lines_data[i]; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
477 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
478 |
expected_lines[lines] = NULL; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
479 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
480 |
assert(file_contains_substrings_in_order(_level_filename[LogLevel::Trace], expected_lines), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
481 |
"couldn't find all lines in multiline message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
482 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
483 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
484 |
static size_t dummy_prefixer(char* buf, size_t len) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
485 |
static int i = 0; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
486 |
const char* prefix = "some prefix: "; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
487 |
const size_t prefix_len = strlen(prefix); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
488 |
if (len < prefix_len) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
489 |
return prefix_len; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
490 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
491 |
jio_snprintf(buf, len, "%s", prefix); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
492 |
return prefix_len; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
493 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
494 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
495 |
void LogMessageTest::test_prefixing() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
496 |
LogMessageBuffer msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
497 |
msg.set_prefix(dummy_prefixer); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
498 |
for (int i = 0; i < 3; i++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
499 |
msg.info("test %d", i); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
500 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
501 |
msg.set_prefix(NULL); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
502 |
msg.info("test 3"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
503 |
_log.write(msg); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
504 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
505 |
const char* expected[] = { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
506 |
"] some prefix: test 0", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
507 |
"] some prefix: test 1", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
508 |
"] some prefix: test 2", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
509 |
"] test 3", |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
510 |
NULL |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
511 |
}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
512 |
assert(file_contains_substrings_in_order(_level_filename[LogLevel::Trace], expected), "error in prefixed output"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
513 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
514 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
515 |
void LogMessageTest::test_scoped_messages() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
516 |
{ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
517 |
LogMessage(logging) msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
518 |
msg.info("scoped info"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
519 |
msg.warning("scoped warn"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
520 |
assert(!file_contains_substring(_level_filename[LogLevel::Info], "scoped info"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
521 |
"scoped log message written prematurely"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
522 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
523 |
assert(file_contains_substring(_level_filename[LogLevel::Info], "scoped info"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
524 |
"missing output from scoped log message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
525 |
assert(file_contains_substring(_level_filename[LogLevel::Warning], "scoped warn"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
526 |
"missing output from scoped log message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
527 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
528 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
529 |
void LogMessageTest::test_scoped_flushing() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
530 |
{ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
531 |
LogMessage(logging) msg; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
532 |
msg.info("manual flush info"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
533 |
msg.flush(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
534 |
assert(file_contains_substring(_level_filename[LogLevel::Info], "manual flush info"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
535 |
"missing output from manually flushed scoped log message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
536 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
537 |
const char* tmp[] = {"manual flush info", "manual flush info", NULL}; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
538 |
assert(!file_contains_substrings_in_order(_level_filename[LogLevel::Info], tmp), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
539 |
"log file contains duplicate lines from single scoped log message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
540 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
541 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
542 |
void LogMessageTest::test_scoped_reset() { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
543 |
{ |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
544 |
LogMessage(logging) msg, partial; |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
545 |
msg.info("%s", "info reset msg"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
546 |
msg.reset(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
547 |
partial.info("%s", "info reset msg"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
548 |
partial.reset(); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
549 |
partial.trace("%s", "trace reset msg"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
550 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
551 |
assert(!file_contains_substring(_level_filename[LogLevel::Info], "info reset msg"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
552 |
"reset message written anyway"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
553 |
assert(file_contains_substring(_level_filename[LogLevel::Trace], "trace reset msg"), |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
554 |
"missing message from partially reset scoped log message"); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
555 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
556 |
|
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37465
diff
changeset
|
557 |
|
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
558 |
static int Test_logconfiguration_subscribe_triggered = 0; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
559 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
560 |
static void Test_logconfiguration_subscribe_helper() { |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
561 |
Test_logconfiguration_subscribe_triggered++; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
562 |
} |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
563 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
564 |
void Test_logconfiguration_subscribe() { |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
565 |
ResourceMark rm; |
37242 | 566 |
Log(logging) log; |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
567 |
|
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
568 |
TestLogSavedConfig log_cfg("stdout", "logging*=trace"); |
37201
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
569 |
|
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
570 |
LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
571 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
572 |
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
|
573 |
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
|
574 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
575 |
LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc)); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
576 |
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
|
577 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
578 |
LogConfiguration::disable_logging(); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
579 |
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
|
580 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
581 |
// 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
|
582 |
// TestLogSavedConfig log_cfg will only renable stdout for us. |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
583 |
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
|
584 |
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
|
585 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
586 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
587 |
#define LOG_PREFIX_STR "THE_PREFIX " |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
588 |
#define LOG_LINE_STR "a log line" |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
589 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
590 |
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
|
591 |
int ret = jio_snprintf(buf, len, LOG_PREFIX_STR); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
592 |
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
|
593 |
return (size_t) ret; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
594 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
595 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
596 |
void Test_log_prefix() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
597 |
TestLogFile log_file("log_prefix"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
598 |
TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
599 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
600 |
log_trace(logging, test)(LOG_LINE_STR); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
601 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
602 |
FILE* fp = fopen(log_file.name(), "r"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
603 |
assert(fp, "File read error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
604 |
char output[1024]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
605 |
if (fgets(output, 1024, fp) != NULL) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
606 |
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
|
607 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
608 |
fclose(fp); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
609 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
610 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
611 |
void Test_log_big() { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
612 |
char big_msg[4096] = {0}; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
613 |
char Xchar = '~'; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
614 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
615 |
TestLogFile log_file("log_big"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
616 |
TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
617 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
618 |
memset(big_msg, Xchar, sizeof(big_msg) - 1); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
619 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
620 |
log_trace(logging, test)("%s", big_msg); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
621 |
|
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
622 |
FILE* fp = fopen(log_file.name(), "r"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
623 |
assert(fp, "File read error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
624 |
char output[sizeof(big_msg)+128 /*decorators*/ ]; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
625 |
if (fgets(output, sizeof(output), fp) != NULL) { |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
626 |
assert(strstr(output, LOG_PREFIX_STR), "logging prefix error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
627 |
size_t count = 0; |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
628 |
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
|
629 |
assert(count == (sizeof(big_msg) - 1) , "logging msg error"); |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
630 |
} |
928cf689af1a
8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents:
37200
diff
changeset
|
631 |
fclose(fp); |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
632 |
} |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35950
diff
changeset
|
633 |
|
37200 | 634 |
void Test_logtagset_duplicates() { |
635 |
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) { |
|
636 |
char ts_name[512]; |
|
637 |
ts->label(ts_name, sizeof(ts_name), ","); |
|
638 |
||
639 |
// verify that NO_TAG is never followed by a real tag |
|
640 |
for (size_t i = 0; i < LogTag::MaxTags; i++) { |
|
641 |
if (ts->tag(i) == LogTag::__NO_TAG) { |
|
642 |
for (i++; i < LogTag::MaxTags; i++) { |
|
643 |
assert(ts->tag(i) == LogTag::__NO_TAG, |
|
644 |
"NO_TAG was followed by a real tag (%s) in tagset %s", |
|
645 |
LogTag::name(ts->tag(i)), ts_name); |
|
646 |
} |
|
647 |
} |
|
648 |
} |
|
649 |
||
650 |
// verify that there are no duplicate tagsets (same tags in different order) |
|
651 |
for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) { |
|
652 |
if (ts->ntags() != other->ntags()) { |
|
653 |
continue; |
|
654 |
} |
|
655 |
bool equal = true; |
|
656 |
for (size_t i = 0; i < ts->ntags(); i++) { |
|
657 |
LogTagType tag = ts->tag(i); |
|
658 |
if (!other->contains(tag)) { |
|
659 |
equal = false; |
|
660 |
break; |
|
661 |
} |
|
662 |
} |
|
663 |
// Since tagsets are implemented using template arguments, using both of |
|
664 |
// the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will |
|
665 |
// instantiate two different LogTagSetMappings. This causes multiple |
|
666 |
// tagset instances to be created for the same logical set. We want to |
|
667 |
// avoid this to save time, memory and prevent any confusion around it. |
|
668 |
if (equal) { |
|
669 |
char other_name[512]; |
|
670 |
other->label(other_name, sizeof(other_name), ","); |
|
671 |
assert(false, "duplicate LogTagSets found: '%s' vs '%s' " |
|
672 |
"(tags must always be specified in the same order for each tagset)", |
|
673 |
ts_name, other_name); |
|
674 |
} |
|
675 |
} |
|
676 |
} |
|
677 |
} |
|
678 |
||
37245
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
679 |
#define Test_logtarget_string_literal "First line" |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
680 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
681 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
682 |
static void Test_logtarget_on() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
683 |
TestLogFile log_file("log_target"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
684 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
685 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
686 |
LogTarget(Debug, gc) log; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
687 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
688 |
assert(log.is_enabled(), "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
689 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
690 |
// 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
|
691 |
log.print(Test_logtarget_string_literal); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
692 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
693 |
FILE* fp = fopen(log_file.name(), "r"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
694 |
assert(fp != NULL, "File read error"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
695 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
696 |
char output[256 /* Large enough buffer */]; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
697 |
char* res = fgets(output, sizeof(output), fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
698 |
assert(res != NULL, "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
699 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
700 |
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
|
701 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
702 |
fclose(fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
703 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
704 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
705 |
static void Test_logtarget_off() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
706 |
TestLogFile log_file("log_target"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
707 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
708 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
709 |
LogTarget(Debug, gc) log; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
710 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
711 |
if (log.is_enabled()) { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
712 |
// 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
|
713 |
// 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
|
714 |
// 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
|
715 |
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
|
716 |
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
|
717 |
return; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
718 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
719 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
720 |
// 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
|
721 |
log.print(Test_logtarget_string_literal); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
722 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
723 |
// 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
|
724 |
log_info(gc)("Dummy line"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
725 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
726 |
FILE* fp = fopen(log_file.name(), "r"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
727 |
assert(fp != NULL, "File read error"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
728 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
729 |
char output[256 /* Large enough buffer */]; |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
730 |
char* res = fgets(output, sizeof(output), fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
731 |
assert(res != NULL, "assert"); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
732 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
733 |
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
|
734 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
735 |
fclose(fp); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
736 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
737 |
|
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
738 |
void Test_logtarget() { |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
739 |
Test_logtarget_on(); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
740 |
Test_logtarget_off(); |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
741 |
} |
70413a0266d4
8152635: Create a UL class to represent a Log + Level combination
stefank
parents:
37243
diff
changeset
|
742 |
|
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
743 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
744 |
static void Test_logstream_helper(outputStream* stream) { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
745 |
TestLogFile log_file("log_stream"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
746 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
747 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
748 |
// Try to log, but expect this to be filtered out. |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
749 |
stream->print("%d ", 3); stream->print("workers"); stream->cr(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
750 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
751 |
FILE* fp = fopen(log_file.name(), "r"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
752 |
assert(fp != NULL, "File read error"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
753 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
754 |
char output[256 /* Large enough buffer */]; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
755 |
char* res = fgets(output, sizeof(output), fp); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
756 |
assert(res != NULL, "assert"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
757 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
758 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
759 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
760 |
fclose(fp); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
761 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
762 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
763 |
static void Test_logstream_log() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
764 |
Log(gc) log; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
765 |
LogStream stream(log.debug()); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
766 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
767 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
768 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
769 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
770 |
static void Test_logstream_logtarget() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
771 |
LogTarget(Debug, gc) log; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
772 |
LogStream stream(log); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
773 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
774 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
775 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
776 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
777 |
static void Test_logstream_logstreamhandle() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
778 |
LogStreamHandle(Debug, gc) stream; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
779 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
780 |
Test_logstream_helper(&stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
781 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
782 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
783 |
static void Test_logstream_no_rm() { |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
784 |
ResourceMark rm; |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
785 |
outputStream* stream = LogTarget(Debug, gc)::stream(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
786 |
|
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
787 |
Test_logstream_helper(stream); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
788 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
789 |
|
37461 | 790 |
static void Test_logstreamcheap_log() { |
791 |
Log(gc) log; |
|
792 |
LogStreamCHeap stream(log.debug()); |
|
793 |
||
794 |
Test_logstream_helper(&stream); |
|
795 |
} |
|
796 |
||
797 |
static void Test_logstreamcheap_logtarget() { |
|
798 |
LogTarget(Debug, gc) log; |
|
799 |
LogStreamCHeap stream(log); |
|
800 |
||
801 |
Test_logstream_helper(&stream); |
|
802 |
} |
|
803 |
||
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
804 |
void Test_logstream() { |
37461 | 805 |
// Test LogStreams with embedded ResourceMark. |
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
806 |
Test_logstream_log(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
807 |
Test_logstream_logtarget(); |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
808 |
Test_logstream_logstreamhandle(); |
37461 | 809 |
|
810 |
// Test LogStreams without embedded ResourceMark. |
|
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
811 |
Test_logstream_no_rm(); |
37461 | 812 |
|
813 |
// Test LogStreams backed by CHeap memory. |
|
814 |
Test_logstreamcheap_log(); |
|
815 |
Test_logstreamcheap_logtarget(); |
|
37254
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
816 |
} |
8631304f255c
8152637: Create a stack allocatable LogStream class
stefank
parents:
37247
diff
changeset
|
817 |
|
37255 | 818 |
void Test_loghandle_on() { |
819 |
TestLogFile log_file("log_handle"); |
|
820 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
|
821 |
||
822 |
Log(gc) log; |
|
823 |
LogHandle log_handle(log); |
|
824 |
||
825 |
assert(log_handle.is_debug(), "assert"); |
|
826 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
827 |
// Try to log through a LogHandle. |
37255 | 828 |
log_handle.debug("%d workers", 3); |
829 |
||
830 |
FILE* fp = fopen(log_file.name(), "r"); |
|
831 |
assert(fp, "File read error"); |
|
832 |
||
833 |
char output[256 /* Large enough buffer */]; |
|
834 |
char* res = fgets(output, sizeof(output), fp); |
|
835 |
assert(res != NULL, "assert"); |
|
836 |
||
837 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
|
838 |
||
839 |
fclose(fp); |
|
840 |
} |
|
841 |
||
842 |
void Test_loghandle_off() { |
|
843 |
TestLogFile log_file("log_handle"); |
|
844 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
|
845 |
||
846 |
Log(gc) log; |
|
847 |
LogHandle log_handle(log); |
|
848 |
||
849 |
if (log_handle.is_debug()) { |
|
850 |
// The log config could have been redirected gc=debug to a file. If gc=debug |
|
851 |
// is enabled, we can only test that the LogTarget returns the same value |
|
852 |
// as the log_is_enabled function. The rest of the test will be ignored. |
|
853 |
assert(log_handle.is_debug() == log_is_enabled(Debug, gc), "assert"); |
|
854 |
log_warning(logging)("This test doesn't support runs with -Xlog"); |
|
855 |
return; |
|
856 |
} |
|
857 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
858 |
// Try to log through a LogHandle. Should fail, since only info is turned on. |
37255 | 859 |
log_handle.debug("%d workers", 3); |
860 |
||
861 |
// Log a dummy line so that fgets doesn't return NULL because the file is empty. |
|
862 |
log_info(gc)("Dummy line"); |
|
863 |
||
864 |
FILE* fp = fopen(log_file.name(), "r"); |
|
865 |
assert(fp, "File read error"); |
|
866 |
||
867 |
char output[256 /* Large enough buffer */]; |
|
868 |
char* res = fgets(output, sizeof(output), fp); |
|
869 |
assert(res != NULL, "assert"); |
|
870 |
||
871 |
assert(strstr(output, "3 workers") == NULL, "log line missing"); |
|
872 |
||
873 |
fclose(fp); |
|
874 |
} |
|
875 |
||
876 |
void Test_loghandle() { |
|
877 |
Test_loghandle_on(); |
|
878 |
Test_loghandle_off(); |
|
879 |
} |
|
880 |
||
881 |
static void Test_logtargethandle_on() { |
|
882 |
TestLogFile log_file("log_handle"); |
|
883 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug"); |
|
884 |
||
885 |
LogTarget(Debug, gc) log; |
|
886 |
LogTargetHandle log_handle(log); |
|
887 |
||
888 |
assert(log_handle.is_enabled(), "assert"); |
|
889 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
890 |
// Try to log through a LogHandle. |
37255 | 891 |
log_handle.print("%d workers", 3); |
892 |
||
893 |
FILE* fp = fopen(log_file.name(), "r"); |
|
894 |
assert(fp, "File read error"); |
|
895 |
||
896 |
char output[256 /* Large enough buffer */]; |
|
897 |
char* res = fgets(output, sizeof(output), fp); |
|
898 |
assert(res != NULL, "assert"); |
|
899 |
||
900 |
assert(strstr(output, "3 workers") != NULL, "log line missing"); |
|
901 |
||
902 |
fclose(fp); |
|
903 |
} |
|
904 |
||
905 |
static void Test_logtargethandle_off() { |
|
906 |
TestLogFile log_file("log_handle"); |
|
907 |
TestLogSavedConfig tlsc(log_file.name(), "gc=info"); |
|
908 |
||
909 |
LogTarget(Debug, gc) log; |
|
910 |
LogTargetHandle log_handle(log); |
|
911 |
||
912 |
if (log_handle.is_enabled()) { |
|
913 |
// The log config could have been redirected gc=debug to a file. If gc=debug |
|
914 |
// is enabled, we can only test that the LogTarget returns the same value |
|
915 |
// as the log_is_enabled function. The rest of the test will be ignored. |
|
916 |
assert(log_handle.is_enabled() == log_is_enabled(Debug, gc), "assert"); |
|
917 |
log_warning(logging)("This test doesn't support runs with -Xlog"); |
|
918 |
return; |
|
919 |
} |
|
920 |
||
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
37256
diff
changeset
|
921 |
// Try to log through a LogHandle. Should fail, since only info is turned on. |
37255 | 922 |
log_handle.print("%d workers", 3); |
923 |
||
924 |
// Log a dummy line so that fgets doesn't return NULL because the file is empty. |
|
925 |
log_info(gc)("Dummy line"); |
|
926 |
||
927 |
FILE* fp = fopen(log_file.name(), "r"); |
|
928 |
assert(fp, "File read error"); |
|
929 |
||
930 |
char output[256 /* Large enough buffer */]; |
|
931 |
char* res = fgets(output, sizeof(output), fp); |
|
932 |
assert(res != NULL, "assert"); |
|
933 |
||
934 |
assert(strstr(output, "3 workers") == NULL, "log line missing"); |
|
935 |
||
936 |
fclose(fp); |
|
937 |
} |
|
938 |
||
939 |
void Test_logtargethandle() { |
|
940 |
Test_logtargethandle_on(); |
|
941 |
Test_logtargethandle_off(); |
|
942 |
} |
|
943 |
||
944 |
static void Test_log_gctracetime_full() { |
|
945 |
TestLogFile log_file("log_gctracetime"); |
|
946 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
947 |
||
948 |
LogTarget(Debug, gc) gc_debug; |
|
949 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
950 |
||
951 |
assert(gc_debug.is_enabled(), "assert"); |
|
952 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
953 |
||
954 |
{ |
|
955 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
956 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, true); |
|
957 |
} |
|
958 |
||
959 |
FILE* fp = fopen(log_file.name(), "r"); |
|
960 |
assert(fp, "File read error"); |
|
961 |
||
962 |
char output[256 /* Large enough buffer */]; |
|
963 |
||
964 |
char* res = fgets(output, sizeof(output), fp); |
|
965 |
assert(res != NULL, "assert"); |
|
966 |
||
967 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
968 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
969 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
970 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
971 |
||
972 |
res = fgets(output, sizeof(output), fp); |
|
973 |
assert(res != NULL, "assert"); |
|
974 |
||
975 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
976 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
977 |
assert(strstr(output, "] Test GC (Allocation Failure) ") != NULL, "Incorrect log line"); |
|
978 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
979 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
980 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
981 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
982 |
||
983 |
fclose(fp); |
|
984 |
} |
|
985 |
||
986 |
static void Test_log_gctracetime_full_multitag() { |
|
987 |
TestLogFile log_file("log_gctracetime"); |
|
988 |
TestLogSavedConfig tlsc(log_file.name(), "gc+ref=debug,gc+ref+start=debug"); |
|
989 |
||
990 |
LogTarget(Debug, gc, ref) gc_debug; |
|
991 |
LogTarget(Debug, gc, ref, start) gc_start_debug; |
|
992 |
||
993 |
assert(gc_debug.is_enabled(), "assert"); |
|
994 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
995 |
||
996 |
{ |
|
997 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
998 |
GCTraceTime(Debug, gc, ref) timer("Test GC", NULL, GCCause::_allocation_failure, true); |
|
999 |
} |
|
1000 |
||
1001 |
FILE* fp = fopen(log_file.name(), "r"); |
|
1002 |
assert(fp, "File read error"); |
|
1003 |
||
1004 |
char output[256 /* Large enough buffer */]; |
|
1005 |
||
1006 |
char* res = fgets(output, sizeof(output), fp); |
|
1007 |
assert(res != NULL, "assert"); |
|
1008 |
||
1009 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
1010 |
assert(strstr(output, "[gc,ref,start") != NULL, "Incorrect tag set"); |
|
1011 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
1012 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
1013 |
||
1014 |
res = fgets(output, sizeof(output), fp); |
|
1015 |
assert(res != NULL, "assert"); |
|
1016 |
||
1017 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
1018 |
assert(strstr(output, "[gc,ref ") != NULL, "Incorrect tag set"); |
|
1019 |
assert(strstr(output, "] Test GC (Allocation Failure) ") != NULL, "Incorrect log line"); |
|
1020 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
1021 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
1022 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
1023 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
1024 |
||
1025 |
fclose(fp); |
|
1026 |
} |
|
1027 |
||
1028 |
static void Test_log_gctracetime_no_heap() { |
|
1029 |
TestLogFile log_file("log_gctracetime"); |
|
1030 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
1031 |
||
1032 |
LogTarget(Debug, gc) gc_debug; |
|
1033 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
1034 |
||
1035 |
assert(gc_debug.is_enabled(), "assert"); |
|
1036 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
1037 |
||
1038 |
{ |
|
1039 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_allocation_failure, false); |
|
1040 |
} |
|
1041 |
||
1042 |
FILE* fp = fopen(log_file.name(), "r"); |
|
1043 |
assert(fp, "File read error"); |
|
1044 |
||
1045 |
char output[256 /* Large enough buffer */]; |
|
1046 |
||
1047 |
char* res = fgets(output, sizeof(output), fp); |
|
1048 |
assert(res != NULL, "assert"); |
|
1049 |
||
1050 |
// [2.975s][debug][gc,start] Test GC (Allocation Failure) (2.975s) |
|
1051 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
1052 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
1053 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
1054 |
||
1055 |
res = fgets(output, sizeof(output), fp); |
|
1056 |
assert(res != NULL, "assert"); |
|
1057 |
||
1058 |
// [2.975s][debug][gc ] Test GC (Allocation Failure) (2.975s, 2.975s) 0.026ms |
|
1059 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
1060 |
assert(strstr(output, "] Test GC (Allocation Failure) (") != NULL, "Incorrect log line"); |
|
1061 |
assert(strstr(output, "M) (") == NULL, "Incorrect log line"); |
|
1062 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
1063 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
1064 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
1065 |
||
1066 |
fclose(fp); |
|
1067 |
} |
|
1068 |
||
1069 |
static void Test_log_gctracetime_no_cause() { |
|
1070 |
TestLogFile log_file("log_gctracetime"); |
|
1071 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
1072 |
||
1073 |
LogTarget(Debug, gc) gc_debug; |
|
1074 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
1075 |
||
1076 |
assert(gc_debug.is_enabled(), "assert"); |
|
1077 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
1078 |
||
1079 |
{ |
|
1080 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
1081 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, true); |
|
1082 |
} |
|
1083 |
||
1084 |
FILE* fp = fopen(log_file.name(), "r"); |
|
1085 |
assert(fp, "File read error"); |
|
1086 |
||
1087 |
char output[256 /* Large enough buffer */]; |
|
1088 |
||
1089 |
char* res = fgets(output, sizeof(output), fp); |
|
1090 |
assert(res != NULL, "assert"); |
|
1091 |
||
1092 |
// [2.975s][debug][gc,start] Test GC (2.975s) |
|
1093 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
1094 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
1095 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
1096 |
||
1097 |
res = fgets(output, sizeof(output), fp); |
|
1098 |
assert(res != NULL, "assert"); |
|
1099 |
||
1100 |
// [2.975s][debug][gc ] Test GC 59M->59M(502M) (2.975s, 2.975s) 0.026ms |
|
1101 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
1102 |
assert(strstr(output, "] Test GC ") != NULL, "Incorrect log line"); |
|
1103 |
assert(strstr(output, "M) (") != NULL, "Incorrect log line"); |
|
1104 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
1105 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
1106 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
1107 |
||
1108 |
fclose(fp); |
|
1109 |
} |
|
1110 |
||
1111 |
static void Test_log_gctracetime_no_heap_no_cause() { |
|
1112 |
TestLogFile log_file("log_gctracetime"); |
|
1113 |
TestLogSavedConfig tlsc(log_file.name(), "gc=debug,gc+start=debug"); |
|
1114 |
||
1115 |
LogTarget(Debug, gc) gc_debug; |
|
1116 |
LogTarget(Debug, gc, start) gc_start_debug; |
|
1117 |
||
1118 |
assert(gc_debug.is_enabled(), "assert"); |
|
1119 |
assert(gc_start_debug.is_enabled(), "assert"); |
|
1120 |
||
1121 |
{ |
|
1122 |
MutexLocker lock(Heap_lock); // Needed to read heap usage |
|
1123 |
GCTraceTime(Debug, gc) timer("Test GC", NULL, GCCause::_no_gc, false); |
|
1124 |
} |
|
1125 |
||
1126 |
FILE* fp = fopen(log_file.name(), "r"); |
|
1127 |
assert(fp, "File read error"); |
|
1128 |
||
1129 |
char output[256 /* Large enough buffer */]; |
|
1130 |
||
1131 |
char* res = fgets(output, sizeof(output), fp); |
|
1132 |
assert(res != NULL, "assert"); |
|
1133 |
||
1134 |
// [2.975s][debug][gc,start] Test GC (2.975s) |
|
1135 |
assert(strstr(output, "[gc,start") != NULL, "Incorrect tag set"); |
|
1136 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
1137 |
assert(strstr(output, "s)") != NULL, "Incorrect log line"); |
|
1138 |
||
1139 |
res = fgets(output, sizeof(output), fp); |
|
1140 |
assert(res != NULL, "assert"); |
|
1141 |
||
1142 |
// [2.975s][debug][gc ] Test GC (2.975s, 2.975s) 0.026ms |
|
1143 |
assert(strstr(output, "[gc ") != NULL, "Incorrect tag set"); |
|
1144 |
assert(strstr(output, "] Test GC (") != NULL, "Incorrect log line"); |
|
1145 |
assert(strstr(output, "M) (") == NULL, "Incorrect log line"); |
|
1146 |
assert(strstr(output, "s, ") != NULL, "Incorrect log line"); |
|
1147 |
assert(strstr(output, "s) ") != NULL, "Incorrect log line"); |
|
1148 |
assert(strstr(output, "ms") != NULL, "Incorrect log line"); |
|
1149 |
||
1150 |
fclose(fp); |
|
1151 |
} |
|
1152 |
||
1153 |
void Test_log_gctracetime() { |
|
1154 |
Test_log_gctracetime_full(); |
|
1155 |
Test_log_gctracetime_full_multitag(); |
|
1156 |
Test_log_gctracetime_no_heap(); |
|
1157 |
Test_log_gctracetime_no_cause(); |
|
1158 |
Test_log_gctracetime_no_heap_no_cause(); |
|
1159 |
} |
|
1160 |
||
37465
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1161 |
void Test_invalid_log_file() { |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1162 |
ResourceMark rm; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1163 |
stringStream ss; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1164 |
const char* target_name = "tmplogdir"; |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1165 |
|
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1166 |
// Attempt to log to a directory (existing log not a regular file) |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1167 |
create_directory(target_name); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1168 |
LogFileOutput bad_file("tmplogdir"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1169 |
assert(bad_file.initialize("", &ss) == false, "file was initialized " |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1170 |
"when there was an existing directory with the same name"); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1171 |
assert(strstr(ss.as_string(), "tmplogdir is not a regular file") != NULL, |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1172 |
"missing expected error message, received msg: %s", ss.as_string()); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1173 |
ss.reset(); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1174 |
remove(target_name); |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1175 |
} |
1d5551f466ee
8146879: Add option for handling existing log files in UL
mlarsson
parents:
37463
diff
changeset
|
1176 |
|
33766
3290cae587f9
8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff
changeset
|
1177 |
#endif // PRODUCT |