summaryrefslogtreecommitdiffstats
path: root/tests/debugger
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 18:51:06 +0000
committerwisberg <wisberg>2002-12-16 18:51:06 +0000
commit144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch)
treeb12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/debugger
parentfafae443719b26159ab2d7dac1c9b46b5e00b671 (diff)
downloadaspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz
aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip
initial version
Diffstat (limited to 'tests/debugger')
-rw-r--r--tests/debugger/AJDBThreads.java51
-rw-r--r--tests/debugger/ArgumentTester.java65
-rw-r--r--tests/debugger/Arguments.java22
-rw-r--r--tests/debugger/BreakpointTester.java85
-rw-r--r--tests/debugger/Main.java74
-rw-r--r--tests/debugger/Makefile70
-rw-r--r--tests/debugger/TestClass.java56
-rw-r--r--tests/debugger/Tester.java459
-rw-r--r--tests/debugger/ThreadTester.java105
9 files changed, 987 insertions, 0 deletions
diff --git a/tests/debugger/AJDBThreads.java b/tests/debugger/AJDBThreads.java
new file mode 100644
index 000000000..c3cc5e2e6
--- /dev/null
+++ b/tests/debugger/AJDBThreads.java
@@ -0,0 +1,51 @@
+//package debugger;
+
+public class AJDBThreads {
+ public static void main(String[] args) {
+ new ThreadForker().go();
+ }
+ public static String currentThread = "none";
+}
+
+class ThreadForker {
+ public void go() {
+ fork(1000);
+ fork(500);
+ fork(200);
+ fork(100);
+ }
+
+ void fork(long sleep) {
+ new NamedThread(sleep).start();
+ }
+}
+
+class NamedThread implements Runnable {
+ private long sleep;
+ private String name;
+ private Thread thread;
+ private int num = 0;
+
+ public NamedThread(long sleep) {
+ this.sleep = sleep;
+ }
+
+ public void start() {
+ if (thread == null) {
+ thread = new Thread(this);
+ name = thread.getName();
+ thread.start();
+ }
+ }
+
+ public void run() {
+ while (true) {
+ AJDBThreads.currentThread = name;
+ System.out.println("\n********** " + AJDBThreads.currentThread + ":" + (num++) + "\n");
+ try {
+ Thread.sleep(sleep);
+ } catch (Exception e) {
+ }
+ }
+ }
+}
diff --git a/tests/debugger/ArgumentTester.java b/tests/debugger/ArgumentTester.java
new file mode 100644
index 000000000..ade62baa7
--- /dev/null
+++ b/tests/debugger/ArgumentTester.java
@@ -0,0 +1,65 @@
+//package debugger;
+
+import com.sun.jdi.*;
+import com.sun.jdi.event.*;
+import com.sun.jdi.request.*;
+import java.io.*;
+import java.util.*;
+import org.aspectj.tools.debugger.*;
+
+public class ArgumentTester extends Tester {
+
+ public static void main(String[] args) {
+ new Main(new ArgumentTester(false), args);
+ }
+
+ public ArgumentTester(boolean b) {
+ super(b);
+ }
+
+ public String getClassName() {
+ return "Arguments";
+ }
+
+ public boolean test() {
+ db();
+ try {
+ setRunArgs("0 1 2");
+ stopon(19);
+ stop(3);
+ startTest();
+ setRunArgs("0 1 2 3 4 5 6");
+ stopon(19);
+ stop(7);
+ startTest();
+ quit();
+ return true;
+ } catch (DebuggerException de) {
+ de.printStackTrace();
+ }
+ return false;
+ }
+
+ protected void stop(final int max) {
+ d.addStopListener(new StopAdapter() {
+ int times = -1;
+ public void breakpointEvent(BreakpointEvent e) {
+ try {
+ String value = print("s") + "";
+ String str = "\"" + times + "\"";
+ if ((times++) != -1) {
+ check(value.equals(str), value + "!=" + str);
+ }
+ if (times < max) {
+ cont();
+ } else {
+ clear(19);
+ d.removeStopListener(this);
+ }
+ } catch (DebuggerException de) {
+ de(de);
+ }
+ }
+ });
+ }
+}
diff --git a/tests/debugger/Arguments.java b/tests/debugger/Arguments.java
new file mode 100644
index 000000000..3cb6c3ff2
--- /dev/null
+++ b/tests/debugger/Arguments.java
@@ -0,0 +1,22 @@
+//package debugger;
+
+public class Arguments {
+ String[] args;
+
+ public static void main(String[] args) {
+ new Arguments(args).go();
+ }
+
+ Arguments(String[] args) {
+ this.args = args;
+ }
+
+ void go () {
+ int i = -1;
+ String s = "";
+ while ((++i) < args.length) {
+ s = args[i];
+ System.out.println("[" + i + "] " + s);
+ }
+ }
+}
diff --git a/tests/debugger/BreakpointTester.java b/tests/debugger/BreakpointTester.java
new file mode 100644
index 000000000..89275acd6
--- /dev/null
+++ b/tests/debugger/BreakpointTester.java
@@ -0,0 +1,85 @@
+
+//package debugger;
+
+import com.sun.jdi.*;
+import com.sun.jdi.event.*;
+import com.sun.jdi.request.*;
+import java.io.*;
+import java.util.*;
+import org.aspectj.tools.debugger.*;
+
+/**
+ * BreakpointTester.java
+ *
+ *
+ * Created: Wed Sep 06 15:53:29 2000
+ *
+ * @author <a href="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
+ */
+
+public class BreakpointTester extends Tester {
+
+ public static void main(String[] args) {
+ new Main(new BreakpointTester(false), args);
+ }
+
+ public BreakpointTester(boolean d) {
+ super(d);
+ }
+
+ public String getClassName() {
+ return "TestClass";
+ }
+
+ public boolean test() {
+ db();
+ Vector locals = new Vector();
+ Vector names = new Vector();
+ names.add("");
+ names.add("system");
+ names.add("main");
+ IntVector sizes = new IntVector();
+ sizes.add(4);
+ sizes.add(3);
+ sizes.add(1);
+ Vector cases = new Vector();
+
+ try {
+ stopin("main");
+ stopin("a");
+ stopin("b");
+ //stopat("TestClassAspect", 41);
+ stopin("c");
+ stopat("TestClassAspect", 54);
+
+ int i = 0;
+ locals = new Vector();
+ locals.add("args");
+ cases.add(new Case(PCKG + "TestClass.main", 5, 1, locals, names, sizes, (i++)));
+
+ locals = new Vector();
+ cases.add(new Case(PCKG + "TestClass.a", -2, 3, locals, names, sizes, (i++)));
+
+ locals = new Vector();
+ cases.add(new Case(PCKG + "TestClass.b", -2, 5, locals, names, sizes, (i++)));
+
+// locals = new Vector();
+// locals.add("thisJoinPoint");
+// cases.add(new Case(PCKG + "TestClassAspect:41", 41, 6, locals, names, sizes, (i++)));
+
+ locals = new Vector();
+ cases.add(new Case(PCKG + "TestClass.c", -2, 7, locals, names, sizes, (i++)));
+
+ locals = new Vector();
+ locals.add("thisJoinPoint");
+ cases.add(new Case(PCKG + "TestClassAspect:54", 54, 8, locals, names, sizes, (i++)));
+
+ stop(cases);
+ startTest();
+
+ return true;
+ } catch (DebuggerException de) { de.printStackTrace(out);
+ }
+ return false;
+ }
+}
diff --git a/tests/debugger/Main.java b/tests/debugger/Main.java
new file mode 100644
index 000000000..fd3dadb37
--- /dev/null
+++ b/tests/debugger/Main.java
@@ -0,0 +1,74 @@
+
+//package debugger;
+
+/**
+ * Main.java
+ *
+ *
+ * Created: Wed Sep 06 15:54:41 2000
+ *
+ * @author <a href="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
+ */
+
+public class Main {
+
+ public Main(Tester tester, String[] args) {
+ String classPath = getArg(args, "-classpath");
+ String root = getArg(args, "-root");
+ String verbose = getSwitch(args, "-verbose");
+ String dbg = getSwitch(args, "-debug");
+ boolean debug = !dbg.equals("");
+ Tester.setClassPath(classPath);
+ Tester.setRoot(root);
+ if (verbose.equals("true")) {
+ Tester.setVerbose(true);
+ }
+ if (dbg.equals("true")) {
+ Tester.setDebug(true);
+ }
+ if (!root.equals("")) {
+ Tester.setRoot(root);
+ }
+ tester.go(args);
+// new BreakpointTester(debug).go(args);
+// new ThreadTester(debug).go(args);
+// new ArgumentTester(debug).go(args);
+ }
+
+ static void fail(Object o) {
+ System.err.println("ERROR: " + o);
+ System.exit(1);
+ }
+
+ public static String getSwitch(String[] args, String arg) {
+ return getArg(args, arg, false);
+ }
+
+ public static String getArg(String[] args, String arg) {
+ return getArg(args, arg, true);
+ }
+
+ public static String getArg(String[] args, String arg, boolean needArg) {
+ String s = "";
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals(arg)) {
+ try {
+ s = args[i+1];
+ break;
+ } catch (Exception e) {
+ if (needArg) {
+ e.printStackTrace();
+ fail("Need to set a value for switch " + arg);
+ }
+ }
+ if (needArg) {
+ return s;
+ } else {
+ return "true";
+ }
+ }
+ }
+ return "";
+
+ }
+}
diff --git a/tests/debugger/Makefile b/tests/debugger/Makefile
new file mode 100644
index 000000000..f17cf5bdd
--- /dev/null
+++ b/tests/debugger/Makefile
@@ -0,0 +1,70 @@
+SHELL = bash
+
+### Fill these in #######################
+aspectj = C:/aspectj
+root = C:/aspectj/tests
+your_classpath = C:/aspectj/tests/lib#C:/classes
+tools_jar = C:/apps/jdk1.3/lib/tools.jar
+aspectj_lib = C:/aspectj/lib
+##########################################
+
+aspectj_src = $(aspectj)/src
+jar_path = C:/apps/aspectj0.7/lib
+aspectj_jars = $(jar_path)/aspectjrt.jar;$(jar_path)/aspectjtools.jar
+path = debugger
+tests = $(aspectj)/tests
+d = $(tests)/lib
+lib = $(d)/$(path)
+srcpath = $(tests)
+classpath = "$(d);$(your_classpath);$(aspectj_lib);$(tools_jar)"
+javac_opts = -d $(d) $(g) -sourcepath $(srcpath) -classpath $(classpath)
+javac_compile = javac $(javac_opts)
+java_ex = Main
+java_main = debugger.$(java_ex)
+java_main_class = $(java_ex).class
+java_opts = -classpath $(classpath)
+java_args =
+g = -g
+ajc_compile = ajc $(g) -d $(your_classpath) -workingdir $(root)/ajworkingdir
+javac_names = \
+ Main\
+ Tester\
+ BreakpointTester\
+ ThreadTester
+javac_srcs = $(foreach name, $(javac_names), $(name).java)
+javac_classes = $(foreach name, $(javac_names), $(d)/$(path)/$(name).class)
+
+ajc_names = \
+ TestClass\
+ AJDBThreads
+ajc_srcs = $(foreach name, $(ajc_names), $(name).java)
+ajc_classes = $(foreach name, $(ajc_names), $(d)/$(path)/$(name).class)
+test_args = -classpath "$(your_classpath);$(aspectj_jars)" -root $(root)
+
+.SUFFIXES: .java .class
+
+all: classes aspects
+
+classes:
+ $(javac_compile) $(javac_srcs)
+
+aspects:
+ $(ajc_compile) $(ajc_srcs)
+
+run:
+ java $(java_opts) $(java_main) $(java_args)
+
+clean:
+ rm -Rf *~* $(lib)/*.class
+
+srcclean:
+ rm -Rf *~* *.ajsym #*
+
+db:
+ make -C ../../debugger
+
+test:
+ java $(java_opts) $(java_main) $(test_args)
+
+.java.class:
+ $(javac_compile) $?
diff --git a/tests/debugger/TestClass.java b/tests/debugger/TestClass.java
new file mode 100644
index 000000000..712244e6c
--- /dev/null
+++ b/tests/debugger/TestClass.java
@@ -0,0 +1,56 @@
+//package debugger;
+
+public class TestClass {
+ public static void main(String[] args) {
+ new TestClass().go();
+ }
+
+ void go() {
+ String s = "s";
+ String ss = "ss";
+ String sss = "sss";
+ a();
+ }
+
+ void a() {
+ int i3 = 3;
+ b();
+ }
+
+ void b() {
+ int i1 = 1;
+ int i2 = 2;
+ c();
+ }
+
+ void c() {
+ String c = "c";
+ System.out.println(c);
+ }
+
+}
+
+aspect TestClassAspect of eachobject(instanceof(TestClass)) {
+ pointcut a(): receptions(* a(..)) && instanceof(TestClass);
+ pointcut b(): receptions(* b(..)) && instanceof(TestClass);
+ pointcut c(): receptions(* c(..)) && instanceof(TestClass);
+ before(): a() {
+ System.out.println("before a");
+ }
+ before(): b() {
+ System.out.println("before b");
+ }
+ before(): c() {
+ System.out.println("before c");
+ }
+ after(): a() {
+ long l = 123;
+ System.out.println("after a");
+ }
+ after(): b() {
+ System.out.println("after b");
+ }
+ after(): c() {
+ System.out.println("after c");
+ }
+}
diff --git a/tests/debugger/Tester.java b/tests/debugger/Tester.java
new file mode 100644
index 000000000..770c04c44
--- /dev/null
+++ b/tests/debugger/Tester.java
@@ -0,0 +1,459 @@
+//package debugger;
+
+import com.sun.jdi.*;
+import com.sun.jdi.event.*;
+import com.sun.jdi.request.*;
+import java.io.*;
+import java.util.*;
+import org.aspectj.tools.debugger.*;
+
+/**
+ * Tester.java
+ *
+ *
+ * Created: Wed Sep 06 15:53:29 2000
+ *
+ * @author <a href="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
+ */
+
+public abstract class Tester extends DebuggerAdapter implements DebuggerListener {
+
+ public abstract boolean test();
+ public abstract String getClassName();
+
+ public static String ROOT = "."; //"C:/aspectj/tests/debugger";
+ public final static String PCKG = ""; //"debugger.";
+ public final static String PATH = ""; //"debugger/";
+ public String FILE = getClassName() + ".java";
+ public String CLASS = PCKG + getClassName();
+ public static String classPath = "..";
+ public int time = 0;
+ public static boolean verboseSuccess = false; //true;
+ protected AJDebugger d;
+ protected PrintStream out = System.out;
+ protected PrintStream err = System.err;
+ protected boolean mutex;
+ protected boolean good = true;
+ protected Vector failures = new Vector();
+
+ protected static boolean debug = false; //true;
+ public static void setDebug(boolean _debug) {
+ debug = _debug;
+ }
+
+ protected final static String errFile = "err.txt";
+
+ public Tester(boolean debug) {
+ this.debug = debug;
+ this.classPath = classPath;
+ if (debug()) {
+ outln("Testing..." + getClassName());
+ }
+ setErr();
+ }
+
+ public Tester() {
+ this(false);
+ }
+
+ public void go(String[] args){
+ good &= test();
+ sd();
+ if (!good) {
+ outln("The test failed with the following:\n" + d.iter(failures));
+ }
+ }
+
+ public boolean debug() {
+ return debug | false;
+ }
+
+ public static void setClassPath(String _classPath) {
+ classPath = _classPath;
+ }
+
+ public static void setRoot(String root) {
+ ROOT = root;
+ }
+
+ public static void setVerbose(boolean _verboseSuccess) {
+ verboseSuccess = _verboseSuccess;
+ }
+
+ /****************************** Tests ******************************/
+
+ protected HashMap breaks = new HashMap();
+
+ static class IntVector extends Vector {
+ public void add(int i) {
+ super.add(new Integer(i));
+ }
+ }
+
+ protected void quit() throws DebuggerException {
+ db("Quitting tester..." + getClassName());
+ d.quitCommand();
+ //d.exit(false);
+ d = null;
+ db("Quit.");
+ }
+
+ protected Value print(Object obj) throws DebuggerException {
+ return d.printCommand(obj);
+ }
+
+ protected void stopin(String method) throws DebuggerException {
+ stopin(getClassName(), method);
+ }
+
+ protected void stopin(String className, String method) throws DebuggerException {
+ d.stopInCommand(PCKG + className, method);
+ }
+
+ protected void stopat(int line) throws DebuggerException {
+ stopat(CLASS, line);
+ }
+
+ protected void stopat(String className, int line) throws DebuggerException {
+ d.stopAtCommand(PCKG + className, line);
+ }
+
+ protected void stopon(int line) throws DebuggerException {
+ d.stopOnCommand(PATH + FILE, line);
+ }
+
+ protected void clear(int line) throws DebuggerException {
+ d.clearOnCommand(PATH + FILE, line);
+ }
+
+ protected void clear(String className, int line) throws DebuggerException {
+ d.clearAtCommand(PCKG + className, line);
+ }
+
+ protected void clear(String method) throws DebuggerException {
+ clear(CLASS, method);
+ }
+
+ protected void clear(String className, String method) throws DebuggerException {
+ d.clearInCommand(PCKG + className, method);
+ }
+
+ protected void step() throws DebuggerException {
+ d.stepCommand();
+ }
+
+ protected void stepi() throws DebuggerException {
+ d.stepiCommand();
+ }
+
+ protected void stepup() throws DebuggerException {
+ d.stepUpCommand();
+ }
+
+ protected void next() throws DebuggerException {
+ d.nextCommand();
+ }
+
+ protected void de(Throwable de) {
+ de.printStackTrace();
+ good = false;
+ }
+
+ static class Case {
+ String msg;
+ int line;
+ int frames;
+ List locals;
+ List names;
+ List sizes;
+ int time;
+ public Case(String msg, int line, int frames, List locals, List names, List sizes, int time) {
+ this.msg = msg;
+ this.line = line;
+ this.frames = frames;
+ this.locals = locals;
+ this.names = names;
+ this.sizes = sizes;
+ this.time = time;
+ }
+ public String toString() {
+ return
+ "msg=" + msg +
+ " line=" + line +
+ " frames=" + frames +
+ " locals=" + locals +
+ " names=" + names +
+ " sizes=" + sizes +
+ " time=" + time;
+ }
+ }
+
+ protected void stop(final Vector cases) {
+ d.addStopListener(new StopAdapter() {
+ public void breakpointEvent(BreakpointEvent e) {
+ try {
+ if (cases.size() > time) {
+ Case caze = (Case) cases.get(time);
+ //System.out.println(caze);
+ //System.out.println(d.format(e));
+ String msg = caze.msg;
+ int line = caze.line;
+ int frames = caze.frames;
+ List locals = caze.locals;
+ List names = caze.names;
+ List sizes = caze.sizes;
+ int caseTime = caze.time;
+ check(time == caseTime, "Out of sync " + time + ":" + caseTime);
+ int lineNumber = d.lineNumber(e.location());
+ String methodName = d.methodName(e);
+ if (lineNumber > 0) {
+ check(lineNumber == line, "Lines don't match " +
+ lineNumber + ":" + line);
+ } else {
+ check(msg.endsWith(methodName),
+ "Method '" + msg + "' does not match '" + methodName + "'.");
+ }
+ msg(msg + ": " + d.format(e));
+ threads(names, sizes);
+ where("", frames);
+ locals(locals);
+ cont();
+ }
+ } catch (/*Debugger*/Exception de) {
+ de.printStackTrace(out);
+ good = false;
+ }
+ time++;
+ }});
+ }
+
+ protected boolean locals(List locals) throws DebuggerException {
+ List vars = d.localsCommand();
+ boolean allGood = true;
+ for (int i = 0; i < locals.size(); i++) {
+ boolean there = false;
+ if (vars != null) {
+ for (int j = 0; j < vars.size(); j++) {
+ LocalVariable lv = (LocalVariable) vars.get(j);
+ if (lv.name().equals(locals.get(i))) {
+ there = true;
+ }
+ }
+ }
+ allGood &= check(there, "The local variable '" + locals.get(i) +
+ "' was not found in\n" + d.locals(vars));
+ }
+ return allGood;
+ }
+
+ protected void threads(List names, List sizes) throws DebuggerException {
+ for (int i = 0; i < names.size(); i++) {
+ List threads = d.threadsCommand(names.get(i) + "");
+ check(threads.size() == ((Integer) sizes.get(i)).intValue(),
+ "need " + sizes.get(i) + " thread(s) in '" + names.get(i) + "':\n" + d.threads(threads));
+ }
+ }
+
+ protected void where(String name, int frames) throws DebuggerException {
+ try {
+ List stack = d.whereCommand(name);
+ check(stack.size() == frames,
+ "need " + frames + " frame(s) in '" + name + "':\n" + d.frames(stack));
+ } catch (WhereRequest.BadThreadStateException e) {
+ //TODO
+ }
+ }
+
+ /****************************** DebuggerListener ******************************/
+
+ public void requestSetEvent(RequestEvent re) {
+ msg("Set " + re.getRequest());
+ }
+ public void requestClearEvent(RequestEvent re) {
+ msg("Cleared " + re.getRequest());
+ }
+ public void requestDeferredEvent(RequestEvent re) {
+
+ }
+ public void requestFailedEvent(RequestEvent re) {
+ msg("Unable to set " + re.getRequest() + " : " + re.getErrorMessage());
+ }
+
+
+ /****************************** Misc. ******************************/
+
+ protected void setErr() {
+ try {
+ err = new PrintStream(new BufferedOutputStream(new FileOutputStream(errFile)), true) {
+ public void write(int b) {
+ super.write(b);
+ }
+ };
+ } catch (IOException ioe) {
+ }
+ System.setErr(err);
+ }
+
+ protected void setOut() {
+ PrintStream redirect = new PrintStream(new OutputStream() {
+ public void write(int b) {}
+ });
+ System.setOut(redirect);
+ }
+
+ protected void down() {
+ mutex = true;
+ }
+
+ protected void up() {
+ mutex = false;
+ }
+
+ protected void stall() {
+ stall(getMaxStallTime());
+ }
+
+ protected long getMaxStallTime() {
+ return (long) 20000;
+ }
+
+ protected void stall(long time) {
+ long start = System.currentTimeMillis();
+ while (mutex) {
+ if ((System.currentTimeMillis() - start) > time) {
+ errln("Stalled for too long");
+ break;
+ }
+ }
+ }
+
+ protected void cont() {
+ try {
+ d.contCommand();
+ } catch (DebuggerException de) {
+ }
+ }
+
+ protected void sd() {
+ if (d != null) {
+ d.shutDown();
+ }
+ d = null;
+ }
+
+ protected void db(Object o) {
+ if (debug()) {
+ System.out.println(o);
+ }
+ }
+
+ protected void db() {
+ sd();
+ d = new AJDebugger(this, false);
+ d.addDebuggerListener(this);
+ ex("use " + ROOT);
+ }
+
+ protected void stop() {
+ stop(5000);
+ }
+
+ protected void stop(long time) {
+ long start = System.currentTimeMillis();
+ while (!d.isAtBreakpoint()) {
+ if ((System.currentTimeMillis() - start) > time) {
+ errln("Stopped for too long");
+ break;
+ }
+ }
+ }
+
+ protected Object ex(String command) {
+ return d.execute(command);
+ }
+
+ public void outln(Object o) {
+ if ((o+"").startsWith("Initializing ajdb...")) {
+ return;
+ }
+ out(o);
+ out("\n");
+ }
+
+ protected void out(Object o) {
+ out.print(o);
+ out.flush();
+ }
+
+ protected void err(Object o) {
+ err.print(o);
+ err.flush();
+ }
+
+ protected void errln(Object o) {
+ err(o);
+ err("\n");
+ }
+
+ protected boolean check(boolean b, String msg) {
+ if (!b) {
+ outln("<<FAIL>> " + msg);
+ good = false;
+ failures.add(msg);
+ } else if (verboseSuccess) {
+ outln("<<SUCESS>> " + msg);
+ }
+ return b;
+ }
+
+ protected boolean check(Object o, String msg) {
+ return check(o != null, msg);
+ }
+
+ protected void msg(Object o) {
+ if (debug()) {
+ outln(o);
+ } else {
+ err.println(o);
+ }
+ }
+
+ private String runArgs = "";
+ public String getRunArgs() {
+ return runArgs;
+ }
+ public void setRunArgs(String runArgs) {
+ this.runArgs = runArgs;
+ }
+
+ private final String _getArgs() {
+ String args = getRunArgs();
+ if (args != null && !args.equals("") && !args.startsWith(" ")) {
+ args = " " + args;
+ }
+ return args;
+ }
+
+ protected void startTest() {
+ String cmd = "run " + classPath() + " " + CLASS + _getArgs();
+ startTest(cmd);
+ }
+
+ protected static String classPath() {
+ if (classPath == null || classPath.equals("")) {
+ return "";
+ }
+ return "-classpath \"" + classPath + "\"";
+ }
+
+ protected void startTest(String cmd) {
+ d.addVMListener(new VMAdapter() {
+ public void vmDisconnectEvent(VMDisconnectEvent e) {
+ msg("Done");
+ up();
+ }});
+ ex(cmd);
+ down();
+ stall();
+ }
+}
diff --git a/tests/debugger/ThreadTester.java b/tests/debugger/ThreadTester.java
new file mode 100644
index 000000000..bb7c27000
--- /dev/null
+++ b/tests/debugger/ThreadTester.java
@@ -0,0 +1,105 @@
+
+//package debugger;
+
+import com.sun.jdi.*;
+import com.sun.jdi.event.*;
+import com.sun.jdi.request.*;
+import java.io.*;
+import java.util.*;
+import org.aspectj.tools.debugger.*;
+
+/**
+ * ThreadTester.java
+ *
+ *
+ * Created: Wed Sep 27 13:56:44 2000
+ *
+ * @author <a href="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
+ */
+
+public class ThreadTester extends Tester {
+
+ public static void main(String[] args) {
+ new Main(new ThreadTester(false), args);
+ }
+
+ public ThreadTester(boolean d) {
+ super(d);
+ }
+
+ public String getClassName() {
+ return "AJDBThreads";
+ }
+
+ public boolean test() {
+ db();
+ try {
+ stopon(43);
+ stop1();
+ startTest();
+ quit();
+ return true;
+ } catch (DebuggerException de) {
+ de.printStackTrace();
+ }
+ return false;
+ }
+
+ protected void stop1() {
+ d.addStopListener(new StopAdapter() {
+
+ int times = 0;
+ int stopTimes = 0;
+ int max = 5;
+ int stopMax = 3;
+ String thread = "";
+ Pair[] pairs = new Pair[max];
+
+ class Pair {
+ String thread;
+ int time;
+ Pair(String thread, int time) {
+ this.thread = thread;
+ this.time = time;
+ }
+ }
+
+ public void breakpointEvent(BreakpointEvent e) {
+ try {
+ String threadName = d.getDefaultThread().name();
+ msg("stop times=" + times + " thread=" + threadName);
+ if ((++times) < max) {
+ thread = threadName;
+ Pair pair = new Pair(thread, times);
+ pairs[times] = pair;
+ step();
+ } else {
+ quit();
+ }
+ } catch (DebuggerException de) {
+ de(de);
+ }
+ }
+
+ public void stepEvent(StepEvent se) {
+ try {
+ ThreadReference threadRef = d.getDefaultThread();
+ check(pairs[times].thread.equals(thread), "Should step in *one* thread");
+ msg("\ttimes=" + times + ":" + stopTimes + " thread=" + threadRef.name());
+ if ((++stopTimes) < stopMax) {
+ step();
+ } else {
+ stopTimes = 0;
+ cont();
+ }
+ } catch (DebuggerException de) {
+ de(de);
+ }
+ }
+ });
+ }
+
+ protected long getMaxStallTime() {
+ return (long) 3 * super.getMaxStallTime();
+ }
+}