Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/logging/TestQuotedLogOutputs.java
41152 views
1
/*
2
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test TestQuotedLogOutputs
26
* @summary Ensure proper parsing of quoted output names for -Xlog arguments.
27
* @modules java.base/jdk.internal.misc
28
* @library /test/lib
29
* @comment after JDK-8224505, this has to be run in othervm mode
30
* @run main/othervm TestQuotedLogOutputs
31
*/
32
33
import java.io.File;
34
import java.nio.file.Path;
35
import java.nio.file.Paths;
36
37
import jdk.test.lib.Asserts;
38
import jdk.test.lib.process.ProcessTools;
39
import jdk.test.lib.process.OutputAnalyzer;
40
41
public class TestQuotedLogOutputs {
42
43
public static void main(String[] args) throws Exception {
44
// Ensure log files can be specified with full path.
45
// On windows, this means that the file name will contain
46
// a colon ('C:\log.txt' for example), which is used to
47
// separate -Xlog: options (-Xlog:tags:filename:decorators).
48
// Try to log to a file in our current directory, using its absolute path.
49
String baseName = "test file.log";
50
Path filePath = Paths.get(baseName).toAbsolutePath();
51
String fileName = filePath.toString();
52
File file = filePath.toFile();
53
54
// In case the file already exists, attempt to delete it before running the test
55
file.delete();
56
57
// Depending on if we're on Windows or not the quotation marks must be escaped,
58
// otherwise they will be stripped from the command line arguments.
59
String quote;
60
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
61
quote = "\\\""; // quote should be \" (escaped quote)
62
} else {
63
quote = "\""; // quote should be " (no escape needed)
64
}
65
66
// Test a few variations with valid log output specifiers
67
String[] validOutputs = new String[] {
68
quote + fileName + quote,
69
"file=" + quote + fileName + quote,
70
quote + fileName + quote + ":",
71
quote + fileName + quote + "::"
72
};
73
for (String logOutput : validOutputs) {
74
// Run with logging=trace on stdout so that we can verify the log configuration afterwards.
75
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=trace",
76
"-Xlog:all=trace:" + logOutput,
77
"-version");
78
OutputAnalyzer output = new OutputAnalyzer(pb.start());
79
output.shouldHaveExitValue(0);
80
Asserts.assertTrue(file.exists());
81
file.deleteOnExit(); // Clean up after test
82
output.shouldMatch("\\[logging *\\].*" + baseName); // Expect to see the log output listed
83
}
84
85
// Test a bunch of invalid output specifications and ensure the VM fails with these
86
String[] invalidOutputs = new String[] {
87
quote,
88
quote + quote, // should fail because the VM will try to create a file without a name
89
quote + quote + quote,
90
quote + quote + quote + quote,
91
quote + quote + quote + quote + quote,
92
"prefix" + quote + quote + "suffix",
93
"prefix" + quote + quote,
94
quote + quote + "suffix",
95
quote + "A" + quote + quote + "B" + quote,
96
quote + "A" + quote + "B" + quote + "C" + quote,
97
"A" + quote + quote + "B"
98
};
99
for (String logOutput : invalidOutputs) {
100
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=trace",
101
"-Xlog:all=trace:" + logOutput,
102
"-version");
103
OutputAnalyzer output = new OutputAnalyzer(pb.start());
104
output.shouldHaveExitValue(1);
105
// Ensure error message was logged
106
output.shouldMatch("([Mm]issing terminating quote)"
107
+ "|(Error opening log file '')"
108
+ "|(Output name can not be partially quoted)");
109
}
110
}
111
}
112
113
114