author | cito |
Wed, 25 Sep 2019 20:32:56 +0900 | |
changeset 58335 | cfef85f63f47 |
parent 58240 | 046533575954 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
55199
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
52669
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jfr.jcmd; |
|
27 |
||
58335
cfef85f63f47
8231317: jdk/jfr/jcmd/TestJcmdConfigure.java fails with "java.lang.RuntimeException: assertTrue: expected true, was false"
cito
parents:
58240
diff
changeset
|
28 |
import java.io.File; |
50113 | 29 |
import java.nio.file.Files; |
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
30 |
import java.nio.file.Paths; |
50113 | 31 |
import java.util.ArrayList; |
32 |
import java.util.List; |
|
33 |
||
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
34 |
import jdk.jfr.internal.Repository; |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
35 |
import jdk.jfr.internal.SecuritySupport.SafePath; |
50113 | 36 |
import jdk.jfr.internal.Options; |
37 |
import jdk.test.lib.Asserts; |
|
55199
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
52669
diff
changeset
|
38 |
import jdk.test.lib.Utils; |
50113 | 39 |
|
51214 | 40 |
/** |
50113 | 41 |
* @test |
42 |
* @summary The test verifies JFR.configure command |
|
43 |
* @key jfr |
|
51214 | 44 |
* @requires vm.hasJFR |
50113 | 45 |
* @library /test/lib /test/jdk |
46 |
* @modules jdk.jfr/jdk.jfr.internal |
|
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
47 |
* @run main/othervm -Xlog:jfr=info:file=jfr_info.txt jdk.jfr.jcmd.TestJcmdConfigure |
50113 | 48 |
*/ |
49 |
public class TestJcmdConfigure { |
|
50 |
||
51 |
private static final String DUMPPATH = "dumppath"; |
|
52 |
private static final String STACK_DEPTH = "stackdepth"; |
|
53 |
private static final String GLOBAL_BUFFER_COUNT = "globalbuffercount"; |
|
54 |
private static final String GLOBAL_BUFFER_SIZE = "globalbuffersize"; |
|
55 |
private static final String THREAD_BUFFER_SIZE = "thread_buffer_size"; |
|
56 |
private static final String MAX_CHUNK_SIZE = "maxchunksize"; |
|
57 |
private static final String SAMPLE_THREADS = "samplethreads"; |
|
58 |
private static final String UNSUPPORTED_OPTION = "unsupportedoption"; |
|
59 |
||
58335
cfef85f63f47
8231317: jdk/jfr/jcmd/TestJcmdConfigure.java fails with "java.lang.RuntimeException: assertTrue: expected true, was false"
cito
parents:
58240
diff
changeset
|
60 |
private static final String REPOSITORYPATH_1 = "." + File.pathSeparator + "repo1"; |
cfef85f63f47
8231317: jdk/jfr/jcmd/TestJcmdConfigure.java fails with "java.lang.RuntimeException: assertTrue: expected true, was false"
cito
parents:
58240
diff
changeset
|
61 |
private static final String REPOSITORYPATH_2 = "." + File.pathSeparator + "repo2"; |
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
62 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
63 |
private static final String REPOSITORYPATH_SETTING_1 = "repositorypath="+REPOSITORYPATH_1; |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
64 |
private static final String REPOSITORYPATH_SETTING_2 = "repositorypath="+REPOSITORYPATH_2; |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
65 |
private static final String JFR_UNIFIED_LOG_FILE = "jfr_info.txt"; |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
66 |
|
50113 | 67 |
public static void main(String[] args) throws Exception { |
68 |
// |
|
69 |
// Simple sanity tests against what is available in Java, |
|
70 |
// before Flight Recorder is loaded. To do: |
|
71 |
// |
|
72 |
// - set values when JFR is running, check for errors. |
|
73 |
// - validate against output from JFR.configure |
|
74 |
// - where feasible, check if they are respected |
|
75 |
// |
|
76 |
||
55199
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
52669
diff
changeset
|
77 |
String dumpPath = Utils.createTempDirectory("dump-path-").toAbsolutePath().toString(); |
50113 | 78 |
|
79 |
test(DUMPPATH, dumpPath); |
|
80 |
test(STACK_DEPTH, 15); |
|
81 |
test(GLOBAL_BUFFER_COUNT, 7); |
|
82 |
test(GLOBAL_BUFFER_SIZE, 6); |
|
83 |
test(THREAD_BUFFER_SIZE, 5); |
|
84 |
test(MAX_CHUNK_SIZE, 14 * 1000 * 1000); |
|
85 |
test(SAMPLE_THREADS, false); |
|
86 |
test(SAMPLE_THREADS, true); |
|
87 |
testNegative(UNSUPPORTED_OPTION, 100000); |
|
88 |
testNegative(MAX_CHUNK_SIZE, -500); |
|
89 |
||
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
90 |
testRepository(); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
91 |
|
50113 | 92 |
if (!testExceptions.isEmpty()) { |
93 |
for (Exception e : testExceptions) { |
|
94 |
System.out.println("Error: " + e.getMessage()); |
|
95 |
} |
|
96 |
throw testExceptions.get(0); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
private static List<Exception> testExceptions = new ArrayList<>(); |
|
101 |
||
102 |
private static void test(String configName, Object value) { |
|
103 |
JcmdHelper.jcmd("JFR.configure", configName + "=" + value); |
|
104 |
Object actualValue = getOption(configName); |
|
105 |
System.out.format("Test param='%s', expected='%s', actual='%s'%n", configName, value, actualValue); |
|
106 |
try { |
|
107 |
// Need convert to string to compare Integer and Long |
|
108 |
Asserts.assertEquals(value.toString(), actualValue.toString(), "Wrong JFR.configure " + configName); |
|
109 |
} catch (Exception e) { |
|
110 |
testExceptions.add(e); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
private static void testNegative(String configName, Object value) { |
|
115 |
try { |
|
52669
e21361bccfa1
8213015: Inconsistent settings between JFR.configure and -XX:FlightRecorderOptions
ysuenaga
parents:
51214
diff
changeset
|
116 |
JcmdHelper.jcmd(1, "JFR.configure", configName + "=" + value); |
50113 | 117 |
} catch(Exception e) { |
118 |
testExceptions.add(e); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
private static Object getOption(String name) { |
|
123 |
switch (name) { |
|
124 |
case DUMPPATH: return Options.getDumpPath().toString(); |
|
125 |
case STACK_DEPTH: return Options.getStackDepth(); |
|
126 |
case GLOBAL_BUFFER_COUNT: return Options.getGlobalBufferCount(); |
|
127 |
case GLOBAL_BUFFER_SIZE: return Options.getGlobalBufferSize(); |
|
128 |
case THREAD_BUFFER_SIZE: return Options.getThreadBufferSize(); |
|
129 |
case MAX_CHUNK_SIZE: return Options.getMaxChunkSize(); |
|
130 |
case SAMPLE_THREADS: return Options.getSampleThreads(); |
|
131 |
default: throw new RuntimeException("Unknown option " + name); |
|
132 |
} |
|
133 |
} |
|
58240
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
134 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
135 |
private static void testRepository(){ |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
136 |
final String findWhat = "[info][jfr] Same base repository path " + REPOSITORYPATH_1 + " is set"; |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
137 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
138 |
try { |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
139 |
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
140 |
SafePath initialPath = Repository.getRepository().getRepositoryPath(); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
141 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
142 |
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_1); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
143 |
SafePath samePath = Repository.getRepository().getRepositoryPath(); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
144 |
Asserts.assertTrue(samePath.equals(initialPath)); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
145 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
146 |
List<String> lines = Files.readAllLines(Paths.get(JFR_UNIFIED_LOG_FILE)); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
147 |
Asserts.assertTrue(lines.stream().anyMatch(l->l.contains(findWhat))); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
148 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
149 |
JcmdHelper.jcmd("JFR.configure", REPOSITORYPATH_SETTING_2); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
150 |
SafePath changedPath = Repository.getRepository().getRepositoryPath(); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
151 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
152 |
Asserts.assertFalse(changedPath.equals(initialPath)); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
153 |
|
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
154 |
} catch(Exception e) { |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
155 |
testExceptions.add(e); |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
156 |
} |
046533575954
8216565: Specifying the same path creates a new directory in JFR.configure
cito
parents:
55199
diff
changeset
|
157 |
} |
50113 | 158 |
} |