Skip to content

Commit d6ecf78

Browse files
author
jbachorik
committed
adding functional tests support; extending coverage for @OnProbe annotation
1 parent 5a81dc6 commit d6ecf78

9 files changed

Lines changed: 591 additions & 184 deletions

File tree

make/build.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@
290290
<exclude name="traces/**"/>
291291
</javac>
292292
<copy todir="${tests.dir}/traces">
293-
<fileset dir="${test.src.dir}/traces" includes="**/*.java"/>
293+
<fileset dir="${test.src.dir}/traces">
294+
<include name="**/*.java"/>
295+
<include name="**/*.xml"/>
296+
</fileset>
294297
</copy>
295298
</target>
296299

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2013, 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. 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 com.sun.btrace;
27+
28+
import org.junit.Assert;
29+
import org.junit.Before;
30+
import support.RuntimeTest;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
34+
/**
35+
* A set of end-to-end functional tests.
36+
* <p>
37+
* The test simulates a user submitting a BTrace script to the target application
38+
* and asserts that no exceptions are thrown, JVM keeps on running and
39+
* BTrace generates the anticipated output.
40+
*
41+
* @author Jaroslav Bachorik
42+
*/
43+
public class BTraceFunctionalTests extends RuntimeTest {
44+
@BeforeClass
45+
public static void classSetup() {
46+
RuntimeTest.setup();
47+
}
48+
49+
@Before
50+
@Override
51+
public void reset() {
52+
super.reset();
53+
}
54+
55+
@Test
56+
public void testOSMBean() throws Exception {
57+
isUnsafe = true;
58+
test(
59+
"resources.Main",
60+
"traces/OSMBeanTest.java",
61+
2,
62+
new ResultValidator() {
63+
public void validate(String stdout, String stderr, int retcode) {
64+
Assert.assertFalse("Script should not have failed", stdout.contains("FAILED"));
65+
Assert.assertTrue("Non-empty stderr", stderr.isEmpty());
66+
Assert.assertEquals("Unexpected return code", 0, retcode);
67+
}
68+
}
69+
);
70+
}
71+
72+
@Test
73+
public void testOnProbe() throws Exception {
74+
test(
75+
"resources.Main",
76+
"traces/ProbeTest.java",
77+
5,
78+
new ResultValidator() {
79+
public void validate(String stdout, String stderr, int retcode) {
80+
Assert.assertFalse("Script should not have failed", stdout.contains("FAILED"));
81+
Assert.assertTrue("Non-empty stderr", stderr.isEmpty());
82+
Assert.assertTrue(stdout.contains("[this, noargs]"));
83+
Assert.assertTrue(stdout.contains("[this, args]"));
84+
Assert.assertEquals("Unexpected return code", 0, retcode);
85+
}
86+
}
87+
);
88+
}
89+
90+
@Test
91+
public void testOnMethod() throws Exception {
92+
test(
93+
"resources.Main",
94+
"traces/OnMethodTest.java",
95+
5,
96+
new ResultValidator() {
97+
public void validate(String stdout, String stderr, int retcode) {
98+
Assert.assertFalse("Script should not have failed", stdout.contains("FAILED"));
99+
Assert.assertTrue("Non-empty stderr", stderr.isEmpty());
100+
Assert.assertTrue(stdout.contains("[this, noargs]"));
101+
Assert.assertTrue(stdout.contains("[this, args]"));
102+
Assert.assertEquals("Unexpected return code", 0, retcode);
103+
}
104+
}
105+
);
106+
}
107+
}

src/test/com/sun/btrace/TestBTraceUtils.java

Lines changed: 0 additions & 169 deletions
This file was deleted.

src/test/resources/Main.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,34 @@
2424
*/
2525
package resources;
2626

27-
import java.io.BufferedReader;
28-
import java.io.InputStreamReader;
29-
3027
/**
3128
*
3229
* @author Jaroslav Bachorik
3330
*/
34-
public class Main {
35-
31+
public class Main extends TestApp {
3632
public static void main(String[] args) throws Exception {
37-
System.out.println("ready:" + getPID());
38-
System.out.flush();
39-
String resp = new BufferedReader(new InputStreamReader(System.in)).readLine();
40-
if (!"done".equals(resp)) {
41-
System.exit(1);
33+
Main i = new Main();
34+
i.start();
35+
}
36+
37+
@Override
38+
protected void startWork() {
39+
while (!Thread.currentThread().isInterrupted()) {
40+
callA();
41+
try {
42+
Thread.sleep(200);
43+
} catch (InterruptedException e) {
44+
Thread.currentThread().interrupt();
45+
}
4246
}
4347
}
4448

45-
private static long getPID() {
46-
String processName
47-
= java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
48-
return Long.parseLong(processName.split("@")[0]);
49+
private void callA() {
50+
callB(1, "Hello World");
51+
}
52+
53+
private void callB(int i, String s) {
54+
System.out.println("[" + i + "] = " + s);
55+
System.out.flush();
4956
}
5057
}

0 commit comments

Comments
 (0)