Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/serviceability/logging/TestFullNames.java
64474 views
1
/*
2
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test TestFullNames
26
* @bug 8215398
27
* @summary Ensure proper parsing of unquoted full output names for -Xlog arguments.
28
* @requires vm.flagless
29
* @modules java.base/jdk.internal.misc
30
* @library /test/lib
31
* @run driver TestFullNames
32
*/
33
34
import java.io.File;
35
import java.nio.file.Path;
36
import java.nio.file.Paths;
37
38
import jdk.test.lib.Asserts;
39
import jdk.test.lib.process.ProcessTools;
40
import jdk.test.lib.process.OutputAnalyzer;
41
42
public class TestFullNames {
43
44
public static void main(String[] args) throws Exception {
45
// Ensure log files can be specified with full path.
46
// On windows, this means that the file name will contain
47
// a colon ('C:\log.txt' for example), which is used to
48
// separate -Xlog: options (-Xlog:tags:filename:decorators).
49
// Try to log to a file in our current directory, using its absolute path.
50
String baseName = "testfile.log";
51
Path filePath = Paths.get(baseName).toAbsolutePath();
52
String fileName = filePath.toString();
53
File file = filePath.toFile();
54
55
// In case the file already exists, attempt to delete it before running the test
56
file.delete();
57
58
// Test full pathnames without quotes.
59
String[] validOutputs = new String[] {
60
"file=" + fileName,
61
fileName
62
};
63
for (String logOutput : validOutputs) {
64
Asserts.assertFalse(file.exists());
65
// Run with logging=trace on stdout so that we can verify the log configuration afterwards.
66
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=trace",
67
"-Xlog:all=trace:" + logOutput,
68
"-version");
69
OutputAnalyzer output = new OutputAnalyzer(pb.start());
70
output.shouldHaveExitValue(0);
71
Asserts.assertTrue(file.exists());
72
file.delete();
73
output.shouldMatch("\\[logging *\\].*" + baseName); // Expect to see the log output listed
74
}
75
}
76
}
77
78
79