author | miauno |
Fri, 30 Jan 2015 20:00:57 +0100 | |
changeset 28821 | f7820f311663 |
parent 26941 | 96aa76b27b9c |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
26587 | 1 |
/* |
2 |
* Copyright (c) 2014, 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 CodelistTest |
|
26 |
* @bug 8054889 |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
27 |
* @library /testlibrary |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
28 |
* @build com.oracle.java.testlibrary.* |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
29 |
* @build com.oracle.java.testlibrary.dcmd.* |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
30 |
* @build MethodIdentifierParser |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
31 |
* @run testng CodelistTest |
26587 | 32 |
* @summary Test of diagnostic command Compiler.codelist |
33 |
*/ |
|
34 |
||
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
35 |
import org.testng.annotations.Test; |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
36 |
import org.testng.Assert; |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
37 |
|
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
38 |
import com.oracle.java.testlibrary.OutputAnalyzer; |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
39 |
import com.oracle.java.testlibrary.dcmd.CommandExecutor; |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
40 |
import com.oracle.java.testlibrary.dcmd.JMXExecutor; |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
41 |
|
26587 | 42 |
import java.lang.reflect.Method; |
43 |
||
44 |
public class CodelistTest { |
|
45 |
||
46 |
/** |
|
47 |
* This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output, |
|
48 |
* making sure that the first methods in the list is valid by reflection. |
|
49 |
* |
|
50 |
* Output example: |
|
51 |
* |
|
52 |
* 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30] |
|
53 |
* 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490] |
|
54 |
* 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338] |
|
55 |
* 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698] |
|
56 |
* 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510] |
|
57 |
* 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118] |
|
58 |
* |
|
59 |
*/ |
|
60 |
||
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
61 |
public void run(CommandExecutor executor) { |
26587 | 62 |
int ok = 0; |
63 |
int fail = 0; |
|
64 |
||
65 |
// Get output from dcmd (diagnostic command) |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
66 |
OutputAnalyzer output = executor.execute("Compiler.codelist"); |
26587 | 67 |
|
68 |
// Grab a method name from the output |
|
69 |
int count = 0; |
|
70 |
||
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
71 |
for (String line : output.asLines()) { |
26587 | 72 |
count++; |
73 |
||
74 |
String[] parts = line.split(" "); |
|
75 |
// int compileID = Integer.parseInt(parts[0]); |
|
76 |
// int compileLevel = Integer.parseInt(parts[1]); |
|
77 |
String methodPrintedInLogFormat = parts[2]; |
|
78 |
||
26941
96aa76b27b9c
8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents:
26587
diff
changeset
|
79 |
// skip inits, clinits and methodHandles - they can not be reflected |
26587 | 80 |
if (methodPrintedInLogFormat.contains("<init>")) { |
81 |
continue; |
|
82 |
} |
|
83 |
if (methodPrintedInLogFormat.contains("<clinit>")) { |
|
84 |
continue; |
|
85 |
} |
|
26941
96aa76b27b9c
8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents:
26587
diff
changeset
|
86 |
if (methodPrintedInLogFormat.contains("MethodHandle")) { |
96aa76b27b9c
8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents:
26587
diff
changeset
|
87 |
continue; |
96aa76b27b9c
8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents:
26587
diff
changeset
|
88 |
} |
26587 | 89 |
|
90 |
MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat); |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
91 |
Method m = null; |
26587 | 92 |
try { |
93 |
m = mf.getMethod(); |
|
94 |
} catch (NoSuchMethodException e) { |
|
95 |
m = null; |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
96 |
} catch (ClassNotFoundException e) { |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
97 |
Assert.fail("Test error: Caught unexpected exception", e); |
26587 | 98 |
} |
99 |
if (m == null) { |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
100 |
Assert.fail("Test failed on: " + methodPrintedInLogFormat); |
26587 | 101 |
} |
102 |
if (count > 10) { |
|
103 |
// Testing 10 entries is enough. Lets not waste time. |
|
104 |
break; |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
28821
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
108 |
|
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
109 |
@Test |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
110 |
public void jmx() { |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
111 |
run(new JMXExecutor()); |
f7820f311663
8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents:
26941
diff
changeset
|
112 |
} |
26587 | 113 |
} |