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