annotate test/serviceability/ParserTest.java @ 5978:51612f0c0a79

7148488: Whitebox tests for the Diagnostic Framework Parser Reviewed-by: brutisso, sla, mgerdin
author nloodin
date Thu, 15 Mar 2012 13:37:13 +0100
parents
children 5a1f452f8f90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5978
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
1 /*
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
2 * @test ParserTest
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
3 * @summary verify that whitebox functions can be linked and executed
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
4 * @run compile -J-XX:+UnlockDiagnosticVMOptions -J-XX:+WhiteBoxAPI ParserTest.java
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
5 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
6 */
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
7
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
8 import java.math.BigInteger;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
9
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
10 import sun.hotspot.parser.DiagnosticCommand;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
11 import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
12 import sun.hotspot.WhiteBox;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
13
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
14 public class ParserTest {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
15 WhiteBox wb;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
16
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
17 public ParserTest() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
18 wb = WhiteBox.getWhiteBox();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
19
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
20 testNanoTime();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
21 testJLong();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
22 testBool();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
23 testMemorySize();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
24 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
25
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
26 public static void main(String... args) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
27 new ParserTest();
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
28 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
29
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
30 public void testNanoTime() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
31 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
32 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
33 "desc", DiagnosticArgumentType.NANOTIME,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
34 false, "0");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
35 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
36
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
37 BigInteger bi = new BigInteger("7");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
38 //These should work
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
39 parse(name, bi.toString(), name + "=7ns", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
40
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
41 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
42 parse(name, bi.toString(), name + "=7us", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
43
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
44 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
45 parse(name, bi.toString(), name + "=7ms", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
46
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
47 bi = bi.multiply(BigInteger.valueOf(1000));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
48 parse(name, bi.toString(), name + "=7s", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
49
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
50 bi = bi.multiply(BigInteger.valueOf(60));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
51 parse(name, bi.toString() , name + "=7m", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
52
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
53 bi = bi.multiply(BigInteger.valueOf(60));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
54 parse(name, bi.toString() , name + "=7h", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
55
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
56 bi = bi.multiply(BigInteger.valueOf(24));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
57 parse(name, bi.toString() , name + "=7d", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
58
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
59 parse(name, "0", name + "=0", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
60
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
61 shouldFail(name + "=7xs", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
62 shouldFail(name + "=7mms", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
63 shouldFail(name + "=7f", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
64 //Currently, only value 0 is allowed without unit
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
65 shouldFail(name + "=7", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
66 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
67
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
68 public void testJLong() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
69 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
70 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
71 "desc", DiagnosticArgumentType.JLONG,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
72 false, "0");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
73 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
74
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
75 wb.parseCommandLine(name + "=10", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
76 parse(name, "10", name + "=10", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
77 parse(name, "-5", name + "=-5", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
78
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
79 //shouldFail(name + "=12m", args); <-- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
80 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
81
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
82 public void testBool() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
83 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
84 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
85 "desc", DiagnosticArgumentType.BOOLEAN,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
86 false, "false");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
87 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
88
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
89 parse(name, "true", name + "=true", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
90 parse(name, "false", name + "=false", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
91 parse(name, "true", name, args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
92
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
93 //Empty commandline to parse, tests default value
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
94 //of the parameter "name"
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
95 parse(name, "false", "", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
96 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
97
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
98 public void testMemorySize() throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
99 String name = "name";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
100 String defaultValue = "1024";
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
101 DiagnosticCommand arg = new DiagnosticCommand(name,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
102 "desc", DiagnosticArgumentType.MEMORYSIZE,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
103 false, defaultValue);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
104 DiagnosticCommand[] args = {arg};
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
105
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
106 BigInteger bi = new BigInteger("7");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
107 parse(name, bi.toString(), name + "=7b", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
108
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
109 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
110 parse(name, bi.toString(), name + "=7k", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
111
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
112 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
113 parse(name, bi.toString(), name + "=7m", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
114
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
115 bi = bi.multiply(BigInteger.valueOf(1024));
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
116 parse(name, bi.toString(), name + "=7g", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
117 parse(name, defaultValue, "", args);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
118
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
119 //shouldFail(name + "=7gg", args); <---- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
120 //shouldFail(name + "=7t", args); <----- should fail, doesn't
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
121 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
122
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
123 public void parse(String searchName, String expectedValue,
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
124 String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
125 //parseCommandLine will return an object array that looks like
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
126 //{<name of parsed object>, <of parsed object> ... }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
127 Object[] res = wb.parseCommandLine(cmdLine, argumentTypes);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
128 for (int i = 0; i < res.length-1; i+=2) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
129 String parsedName = (String) res[i];
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
130 if (searchName.equals(parsedName)) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
131 String parsedValue = (String) res[i+1];
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
132 if (expectedValue.equals(parsedValue)) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
133 return;
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
134 } else {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
135 throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n"
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
136 + searchName + " parsed as " + parsedValue
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
137 + "! Expected: " + expectedValue);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
138 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
139 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
140 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
141 throw new Exception(searchName + " not found as a parsed Argument!");
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
142 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
143
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
144 private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
145 try {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
146 wb.parseCommandLine(argument, argumentTypes);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
147 throw new Exception("Parser accepted argument: " + argument);
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
148 } catch (IllegalArgumentException e) {
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
149 //expected
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
150 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
151 }
51612f0c0a79 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
152 }