67 if (tr.isOK()) { |
67 if (tr.isOK()) { |
68 System.out.println(tr); |
68 System.out.println(tr); |
69 throw new RuntimeException("Error: argument was accepted ????"); |
69 throw new RuntimeException("Error: argument was accepted ????"); |
70 } |
70 } |
71 } |
71 } |
|
72 |
|
73 /* |
|
74 * test argument : -XX:NativeMemoryTracking=value |
|
75 * A JVM flag, comsumed by the JVM, but requiring launcher |
|
76 * to set an environmental variable if and only if value is supplied. |
|
77 * Test and order: |
|
78 * 1) execute with valid parameter: -XX:NativeMemoryTracking=MyValue |
|
79 * a) check for correct env variable name: "NMT_LEVEL_" + pid |
|
80 * b) check that "MyValue" was found in local env. |
|
81 * 2) execute with invalid parameter: -XX:NativeMemoryTracking= |
|
82 * !) Won't find "NativeMemoryTracking:" |
|
83 * Code to create env variable not executed. |
|
84 * 3) execute with invalid parameter: -XX:NativeMemoryTracking |
|
85 * !) Won't find "NativeMemoryTracking:" |
|
86 * Code to create env variable not executed. |
|
87 * 4) give and invalid value and check to make sure JVM commented |
|
88 */ |
|
89 { // NativeMemoryTracking |
|
90 String launcherPidString = "launcher.pid="; |
|
91 String envVarPidString = "TRACER_MARKER: NativeMemoryTracking: env var is NMT_LEVEL_"; |
|
92 String NMT_Option_Value = "off"; |
|
93 String myClassName = "helloworld"; |
|
94 boolean haveLauncherPid = false; |
|
95 |
|
96 // === Run the tests === |
|
97 |
|
98 // ---Test 1a |
|
99 tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=" + NMT_Option_Value, |
|
100 "-version"); |
|
101 |
|
102 // get the PID from the env var we set for the JVM |
|
103 String envVarPid = null; |
|
104 for (String line : tr.testOutput) { |
|
105 if (line.contains(envVarPidString)) { |
|
106 int sindex = envVarPidString.length(); |
|
107 envVarPid = line.substring(sindex); |
|
108 break; |
|
109 } |
|
110 } |
|
111 // did we find envVarPid? |
|
112 if (envVarPid == null) { |
|
113 System.out.println(tr); |
|
114 throw new RuntimeException("Error: failed to find env Var Pid in tracking info"); |
|
115 } |
|
116 // we think we found the pid string. min test, not "". |
|
117 if (envVarPid.length() < 1) { |
|
118 System.out.println(tr); |
|
119 throw new RuntimeException("Error: env Var Pid in tracking info is empty string"); |
|
120 } |
|
121 |
|
122 /* |
|
123 * On Linux, Launcher Tracking will print the PID. Use this info |
|
124 * to validate what we got as the PID in the Launcher itself. |
|
125 * Linux is the only one that prints this, and trying to get it |
|
126 * here for win is awful. So let the linux test make sure we get |
|
127 * the valid pid, and for non-linux, just make sure pid string is |
|
128 * non-zero. |
|
129 */ |
|
130 if (isLinux) { |
|
131 // get what the test says is the launcher pid |
|
132 String launcherPid = null; |
|
133 for (String line : tr.testOutput) { |
|
134 int index = line.indexOf(launcherPidString); |
|
135 if (index >= 0) { |
|
136 int sindex = index + launcherPidString.length(); |
|
137 int tindex = sindex + line.substring(sindex).indexOf("'"); |
|
138 System.out.println("DEBUG INFO: sindex = " + sindex); |
|
139 System.out.println("DEBUG INFO: searching substring: " + line.substring(sindex)); |
|
140 System.out.println("DEBUG INFO: tindex = " + tindex); |
|
141 // DEBUG INFO |
|
142 System.out.println(tr); |
|
143 launcherPid = line.substring(sindex, tindex); |
|
144 break; |
|
145 } |
|
146 } |
|
147 if (launcherPid == null) { |
|
148 System.out.println(tr); |
|
149 throw new RuntimeException("Error: failed to find launcher Pid in launcher tracking info"); |
|
150 } |
|
151 |
|
152 // did we create the env var with the correct pid? |
|
153 if (!launcherPid.equals(envVarPid)) { |
|
154 System.out.println(tr); |
|
155 System.out.println("Error: wrong pid in creating env var"); |
|
156 System.out.println("Error Info: launcherPid = " + launcherPid); |
|
157 System.out.println("Error Info: envVarPid = " + envVarPid); |
|
158 throw new RuntimeException("Error: wrong pid in creating env var"); |
|
159 } |
|
160 } |
|
161 |
|
162 |
|
163 // --- Test 1b |
|
164 if (!tr.contains("NativeMemoryTracking: got value " + NMT_Option_Value)) { |
|
165 System.out.println(tr); |
|
166 throw new RuntimeException("Error: Valid param failed to set env variable"); |
|
167 } |
|
168 |
|
169 // --- Test 2 |
|
170 tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=", |
|
171 "-version"); |
|
172 if (tr.contains("NativeMemoryTracking:")) { |
|
173 System.out.println(tr); |
|
174 throw new RuntimeException("Error: invalid param caused env variable to be erroneously created"); |
|
175 } |
|
176 if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) { |
|
177 System.out.println(tr); |
|
178 throw new RuntimeException("Error: invalid param not checked by JVM"); |
|
179 } |
|
180 |
|
181 // --- Test 3 |
|
182 tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking", |
|
183 "-version"); |
|
184 if (tr.contains("NativeMemoryTracking:")) { |
|
185 System.out.println(tr); |
|
186 throw new RuntimeException("Error: invalid param caused env variable to be erroneously created"); |
|
187 } |
|
188 if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) { |
|
189 System.out.println(tr); |
|
190 throw new RuntimeException("Error: invalid param not checked by JVM"); |
|
191 } |
|
192 // --- Test 4 |
|
193 tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=BADVALUE", |
|
194 "-version"); |
|
195 if (!tr.contains("expecting -XX:NativeMemoryTracking")) { |
|
196 System.out.println(tr); |
|
197 throw new RuntimeException("Error: invalid param did not get JVM Syntax error message"); |
|
198 } |
|
199 |
|
200 } // NativeMemoryTracking |
|
201 |
|
202 |
72 // MacOSX specific tests ensue...... |
203 // MacOSX specific tests ensue...... |
73 if (!isMacOSX) |
204 if (!isMacOSX) |
74 return; |
205 return; |
75 Set<String> envToRemove = new HashSet<>(); |
206 Set<String> envToRemove = new HashSet<>(); |
76 Map<String, String> map = System.getenv(); |
207 Map<String, String> map = System.getenv(); |