001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.tests.jfluid.cpu;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045: import org.netbeans.lib.profiler.ProfilerEngineSettings;
046: import org.netbeans.lib.profiler.global.CommonConstants;
047: import org.netbeans.lib.profiler.global.InstrumentationFilter;
048:
049: /**
050: *
051: * @author ehucka
052: */
053: public class BasicTest extends CPUTestCase {
054: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
055:
056: private static final long MAX_DELAY = 25000L;
057:
058: //~ Constructors -------------------------------------------------------------------------------------------------------------
059:
060: /** Creates a new instance of BasicTest */
061: public BasicTest(String name) {
062: super (name);
063: }
064:
065: //~ Methods ------------------------------------------------------------------------------------------------------------------
066:
067: public static Test suite() {
068: TestSuite suite = new TestSuite(
069: org.netbeans.lib.profiler.tests.jfluid.cpu.BasicTest.class);
070:
071: return suite;
072: }
073:
074: public void temptestSettingsInstrumentRootMethod(boolean server) {
075: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
076: "simple.cpu.CPU1", new String[][] { {
077: "simple.cpu.CPUThread", "run", "()V" } });
078: settings.setInstrumentSpawnedThreads(false);
079: settings.setInstrumentMethodInvoke(true);
080: settings.setInstrumentGetterSetterMethods(true);
081: settings.setInstrumentEmptyMethods(true);
082: settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
083:
084: if (server) {
085: addJVMArgs(settings, "-server");
086: }
087:
088: startCPUTest(settings,
089: new String[] { "simple.cpu.CPUThread.run512()" },
090: new long[] { 512L }, 40.0, new String[] { "simple" },
091: ALL_INV_ERROR_METHOD);
092: }
093:
094: public void testLiveResultsAll() {
095: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
096: "simple.cpu.CPU1");
097: startCPUTest(settings, new String[] { "" }, 1000, MAX_DELAY);
098: }
099:
100: public void testLiveResultsBasic() {
101: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
102: "simple.CPU");
103: startCPUTest(settings, new String[] { "simple" }, 1500,
104: MAX_DELAY);
105: }
106:
107: public void testLiveResultsWaitEager() {
108: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
109: "simple.cpu.WaitingTest");
110: settings.setInstrScheme(CommonConstants.INSTRSCHEME_EAGER);
111: startCPUTest(settings, new String[] { "simple" }, 1000,
112: MAX_DELAY);
113: }
114:
115: public void testLiveResultsWaitLazy() {
116: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
117: "simple.cpu.WaitingTest");
118: settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
119: startCPUTest(settings, new String[] { "simple" }, 1000,
120: MAX_DELAY);
121: }
122:
123: public void testLiveResultsWaitSampled() {
124: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
125: "simple.cpu.WaitingTest");
126: settings.setCPUProfilingType(CommonConstants.CPU_INSTR_SAMPLED);
127: settings.setSamplingInterval(1);
128: startCPUTest(settings, new String[] { "simple" }, 1000,
129: MAX_DELAY);
130: }
131:
132: public void testLiveResultsWaitServer() {
133: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
134: "simple.cpu.WaitingTest");
135: addJVMArgs(settings, "-server");
136: startCPUTest(settings, new String[] { "simple" }, 1000,
137: MAX_DELAY);
138: }
139:
140: public void testLiveResultsWaitTotal() {
141: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
142: "simple.cpu.WaitingTest");
143: settings.setInstrScheme(CommonConstants.INSTRSCHEME_TOTAL);
144: startCPUTest(settings, new String[] { "simple" }, 1000,
145: MAX_DELAY);
146: }
147:
148: public void testMethodWithWaitEager() {
149: temptestMethodWithWait(CommonConstants.INSTRSCHEME_EAGER,
150: false, false, 2000L);
151: }
152:
153: public void testMethodWithWaitEagerServer() {
154: temptestMethodWithWait(CommonConstants.INSTRSCHEME_EAGER,
155: false, true, 2000L);
156: }
157:
158: public void testMethodWithWaitExcludeWEager() {
159: temptestMethodWithWait(CommonConstants.INSTRSCHEME_EAGER, true,
160: false, 4000L);
161: }
162:
163: public void testMethodWithWaitExcludeWLazy() {
164: temptestMethodWithWait(CommonConstants.INSTRSCHEME_LAZY, true,
165: false, 4000L);
166: }
167:
168: public void testMethodWithWaitExcludeWTotal() {
169: temptestMethodWithWait(CommonConstants.INSTRSCHEME_TOTAL, true,
170: false, 4000L);
171: }
172:
173: public void testMethodWithWaitLazy() {
174: temptestMethodWithWait(CommonConstants.INSTRSCHEME_LAZY, false,
175: false, 2000L);
176: }
177:
178: public void testMethodWithWaitLazyServer() {
179: temptestMethodWithWait(CommonConstants.INSTRSCHEME_LAZY, false,
180: true, 2000L);
181: }
182:
183: public void testMethodWithWaitTotal() {
184: temptestMethodWithWait(CommonConstants.INSTRSCHEME_TOTAL,
185: false, false, 2000L);
186: }
187:
188: public void testMethodWithWaitTotalServer() {
189: temptestMethodWithWait(CommonConstants.INSTRSCHEME_TOTAL,
190: false, true, 2000L);
191: }
192:
193: public void testSettingsDefault() {
194: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
195: "simple.cpu.CPU1");
196: startCPUTest(settings, new String[] {
197: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
198: "simple.cpu.Bean.run1000()",
199: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
200: 100L, 1000L, 512L }, 40.0, new String[] { "simple" },
201: ALL_INV_ERROR_METHOD);
202: }
203:
204: public void testSettingsInstrumenManyMethodsLazy() {
205: temptestSettingsInstrumentManyMethods(CommonConstants.INSTRSCHEME_LAZY);
206: }
207:
208: public void testSettingsInstrumentAllEager() {
209: temptestSettingsInstrumentAll(
210: CommonConstants.INSTRSCHEME_EAGER, false);
211: }
212:
213: public void testSettingsInstrumentAllEagerServer() {
214: temptestSettingsInstrumentAll(
215: CommonConstants.INSTRSCHEME_EAGER, true);
216: }
217:
218: public void testSettingsInstrumentAllLazy() {
219: temptestSettingsInstrumentAll(CommonConstants.INSTRSCHEME_LAZY,
220: false);
221: }
222:
223: public void testSettingsInstrumentAllLazyServer() {
224: temptestSettingsInstrumentAll(CommonConstants.INSTRSCHEME_LAZY,
225: true);
226: }
227:
228: public void testSettingsInstrumentAllTotal() {
229: temptestSettingsInstrumentAll(
230: CommonConstants.INSTRSCHEME_TOTAL, false);
231: }
232:
233: public void testSettingsInstrumentAllTotalServer() {
234: temptestSettingsInstrumentAll(
235: CommonConstants.INSTRSCHEME_TOTAL, true);
236: }
237:
238: public void testSettingsInstrumentExcludeJavas() {
239: temptestSettingsInstrumentExcludeJavas(false);
240: }
241:
242: public void testSettingsInstrumentExcludeJavasServer() {
243: temptestSettingsInstrumentExcludeJavas(true);
244: }
245:
246: public void testSettingsInstrumentManyMethodsTotal() {
247: temptestSettingsInstrumentManyMethods(CommonConstants.INSTRSCHEME_TOTAL);
248: }
249:
250: public void testSettingsInstrumentNotSpawnedThreads() {
251: temptestSettingsInstrumentNotSpawnedThreads(false);
252: }
253:
254: public void testSettingsInstrumentNotSpawnedThreadsServer() {
255: temptestSettingsInstrumentNotSpawnedThreads(true);
256: }
257:
258: public void testSettingsInstrumentRootMethod() {
259: temptestSettingsInstrumentRootMethod(false);
260: }
261:
262: public void testSettingsInstrumentRootMethodServer() {
263: temptestSettingsInstrumentRootMethod(true);
264: }
265:
266: public void testSettingsLimitedThreads() {
267: temptestSettingsLimitedThreads(false);
268: }
269:
270: public void testSettingsLimitedThreadsServer() {
271: temptestSettingsLimitedThreads(true);
272: }
273:
274: public void testSettingsSampledProfilingEager() {
275: temptestSettingsSampledProfiling(false,
276: CommonConstants.INSTRSCHEME_EAGER);
277: }
278:
279: public void testSettingsSampledProfilingLazy() {
280: temptestSettingsSampledProfiling(false,
281: CommonConstants.INSTRSCHEME_LAZY);
282: }
283:
284: public void testSettingsSampledProfilingServerEager() {
285: temptestSettingsSampledProfiling(true,
286: CommonConstants.INSTRSCHEME_EAGER);
287: }
288:
289: public void testSettingsSampledProfilingServerLazy() {
290: temptestSettingsSampledProfiling(true,
291: CommonConstants.INSTRSCHEME_LAZY);
292: }
293:
294: public void testSettingsSampledProfilingServerTotal() {
295: temptestSettingsSampledProfiling(true,
296: CommonConstants.INSTRSCHEME_TOTAL);
297: }
298:
299: public void testSettingsSampledProfilingTotal() {
300: temptestSettingsSampledProfiling(false,
301: CommonConstants.INSTRSCHEME_TOTAL);
302: }
303:
304: protected void temptestMethodWithWait(int instrscheme,
305: boolean withwaits, boolean server, long idealtime) {
306: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
307: "simple.cpu.WaitingTest",
308: new String[][] { { "simple.cpu.WaitingTest",
309: "method1000", "()V" } });
310: settings.setInstrScheme(instrscheme);
311: settings.setExcludeWaitTime(!withwaits);
312:
313: if (server) {
314: addJVMArgs(settings, "-server");
315: }
316:
317: startCPUTest(settings,
318: new String[] { "simple.cpu.WaitingTest.method1000()" },
319: new long[] { idealtime }, 40.0,
320: new String[] { "simple" }, ALL_INV_ERROR_METHOD);
321: }
322:
323: protected void temptestSettingsInstrumentAll(int instrScheme,
324: boolean server) {
325: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
326: "simple.cpu.CPU1");
327: settings.setInstrumentSpawnedThreads(true);
328: settings.setInstrumentMethodInvoke(true);
329: settings.setInstrumentGetterSetterMethods(true);
330: settings.setInstrumentEmptyMethods(true);
331: settings.setInstrScheme(instrScheme);
332:
333: if (server) {
334: addJVMArgs(settings, "-server");
335: }
336:
337: startCPUTest(settings, new String[] {
338: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
339: "simple.cpu.Bean.run1000()",
340: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
341: 100L, 1000L, 512L }, 40.0, new String[] { "simple" },
342: ALL_INV_ERROR_METHOD);
343: }
344:
345: protected void temptestSettingsInstrumentExcludeJavas(boolean server) {
346: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
347: "simple.cpu.CPU1");
348: settings.setInstrumentSpawnedThreads(true);
349: settings.setInstrumentMethodInvoke(true);
350: settings.setInstrumentGetterSetterMethods(false);
351: settings.setInstrumentEmptyMethods(false);
352: settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
353:
354: if (server) {
355: addJVMArgs(settings, "-server");
356: }
357:
358: InstrumentationFilter filter = new InstrumentationFilter();
359: filter
360: .setFilterType(InstrumentationFilter.INSTR_FILTER_EXCLUSIVE);
361: filter.setFilterStrings("java");
362: settings.setInstrumentationFilter(filter);
363: startCPUTest(settings, new String[] {
364: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
365: "simple.cpu.Bean.run1000()",
366: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
367: 100L, 1000L, 512L }, 40.0, new String[] { "simple",
368: "java" }, ALL_INV_ERROR_METHOD);
369: }
370:
371: protected void temptestSettingsInstrumentManyMethods(int instrscheme) {
372: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
373: "simple.cpu.Methods2");
374: settings.setInstrumentSpawnedThreads(true);
375: settings.setInstrumentMethodInvoke(true);
376: settings.setInstrumentGetterSetterMethods(true);
377: settings.setInstrumentEmptyMethods(true);
378: settings.setInstrScheme(instrscheme);
379: startCPUTest(settings,
380: new String[] { "simple.cpu.Methods2.method0()" },
381: new long[] { 400L }, 40.0,
382: new String[] { "simple.cpu.Methods2.method1" },
383: ALL_INV_ERROR_METHOD);
384: }
385:
386: protected void temptestSettingsInstrumentNotSpawnedThreads(
387: boolean server) {
388: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
389: "simple.cpu.CPU1");
390: settings.setInstrumentSpawnedThreads(false);
391: settings.setInstrumentMethodInvoke(true);
392: settings.setInstrumentGetterSetterMethods(true);
393: settings.setInstrumentEmptyMethods(true);
394: settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
395:
396: if (server) {
397: addJVMArgs(settings, "-server");
398: }
399:
400: startCPUTest(settings, new String[] {
401: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
402: "simple.cpu.Bean.run1000()",
403: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
404: 100L, 1000L, 512L }, 40.0, new String[] { "simple" },
405: ALL_INV_ERROR_METHOD);
406: }
407:
408: protected void temptestSettingsLimitedThreads(boolean server) {
409: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
410: "simple.cpu.CPU1");
411: settings.setInstrumentSpawnedThreads(true);
412: settings.setInstrumentMethodInvoke(true);
413: settings.setInstrumentGetterSetterMethods(true);
414: settings.setInstrumentEmptyMethods(true);
415: settings.setNProfiledThreadsLimit(1);
416: settings.setInstrScheme(CommonConstants.INSTRSCHEME_LAZY);
417:
418: if (server) {
419: addJVMArgs(settings, "-server");
420: }
421:
422: startCPUTest(settings, new String[] {
423: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
424: "simple.cpu.Bean.run1000()",
425: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
426: 100L, 1000L, 512L }, 40.0, new String[] { "simple" },
427: ALL_INV_ERROR_METHOD);
428: }
429:
430: protected void temptestSettingsSampledProfiling(boolean server,
431: int instrScheme) {
432: ProfilerEngineSettings settings = initCpuTest("j2se-simple",
433: "simple.cpu.CPU1");
434: settings.setInstrumentSpawnedThreads(true);
435: settings.setInstrumentMethodInvoke(true);
436: settings.setInstrumentGetterSetterMethods(true);
437: settings.setInstrumentEmptyMethods(true);
438: settings.setCPUProfilingType(CommonConstants.CPU_INSTR_SAMPLED);
439: settings.setSamplingInterval(5);
440: settings.setInstrScheme(instrScheme);
441:
442: if (server) {
443: addJVMArgs(settings, "-server");
444: }
445:
446: startCPUTest(settings, new String[] {
447: "simple.cpu.Bean.run20()", "simple.cpu.Bean.run100()",
448: "simple.cpu.Bean.run1000()",
449: "simple.cpu.CPUThread.run512()" }, new long[] { 20L,
450: 100L, 1000L, 512L }, 40.0, new String[] { "simple" },
451: ALL_INV_ERROR_METHOD);
452: }
453: }
|