aboutsummaryrefslogtreecommitdiffstats
path: root/tests/debugger/ThreadTester.java
blob: bb7c270009f6ed51a8399aef96fcf203e2b40479 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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();
    }
}