Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d17a24cdf3718d6afc14b3ab21c3b6ef11977aa4 (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.debug.test;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

import org.eclipse.tcf.debug.test.util.ICache;
import org.eclipse.tcf.debug.test.util.RangeCache;
import org.eclipse.tcf.debug.test.util.Transaction;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.services.IRunControl;
import org.eclipse.tcf.services.IRunControl.RunControlContext;
import org.eclipse.tcf.services.IStackTrace.StackTraceContext;
import org.junit.Assert;

public class StackTraceCMTest extends AbstractCMTest {

    public void testStackTraceCMResetOnResumeSuspend() throws Exception {
        final TestProcessInfo processInfo = startProcess("tcf_test_func2");
        doTestStackTraceCMReset(
            processInfo,
            new Callable<Object>() { 
                public Object call() throws Exception {
                    resumeAndWaitForSuspend(processInfo.fThreadCtx, IRunControl.RM_STEP_OUT);
                    return null;
                }
            }, 
            true);

    }

    public void testStackTraceCMResetOnContextChange() throws Exception {
        final TestProcessInfo processInfo = startProcess("tcf_test_func2");
        doTestStackTraceCMReset(
            processInfo,
            new Callable<Object>() { 
                public Object call() throws Exception {
                    Protocol.invokeAndWait(new Runnable() {
                        public void run() {
                            fStackTraceCM.fRunControlListener.contextChanged(new RunControlContext[] { processInfo.fThreadCtx });
                        }
                    });
                    return null;
                }
            }, 
            false);
    }

    public void testStackTraceCMResetOnMemoryChange() throws Exception {
        final TestProcessInfo processInfo = startProcess("tcf_test_func2");
        doTestStackTraceCMReset(
            processInfo,
            new Callable<Object>() { 
                public Object call() throws Exception {
                    Protocol.invokeAndWait(new Runnable() {
                        public void run() {
                            fStackTraceCM.fMemoryListener.memoryChanged(processInfo.fProcessId, new Number[0], new long[0]);
                        }
                    });
                    return null;
                }
            }, 
            false);
    }

    public void testStackTraceCMResetOnMemoryMapChange() throws Exception {
        final TestProcessInfo processInfo = startProcess("tcf_test_func2");
        doTestStackTraceCMReset(
            processInfo,
            new Callable<Object>() { 
                public Object call() throws Exception {
                    Protocol.invokeAndWait(new Runnable() {
                        public void run() {
                            fStackTraceCM.fMemoryMapListener.changed(processInfo.fProcessId);
                        }
                    });
                    return null;
                }
            }, 
            false);
    }

    private void doTestStackTraceCMReset(final TestProcessInfo processInfo, Callable<?> resetCallable, 
        final boolean pcShouldChange) throws Exception 
    {
        // Retrieve the current PC and top frame for use later
        final String pc = new Transaction<String>() {
            @Override
            protected String process() throws InvalidCacheException, ExecutionException {
                return validate(fRunControlCM.getState(processInfo.fThreadId)).pc;
                
            }
        }.get();

        // Retrieve data from caches (make them valid).
        new Transaction<Object>() {
            @Override
            protected String process() throws InvalidCacheException, ExecutionException {
                String[] frameIds = validate( fStackTraceCM.getChildren(processInfo.fThreadId) );
                validate (fStackTraceCM.getContexts(frameIds));
                RangeCache<StackTraceContext> framesRange = fStackTraceCM.getContextRange(processInfo.fThreadId);
                List<StackTraceContext> frames = validate( framesRange.getRange(0, frameIds.length) );
                StackTraceContext topFrame = frames.get(frames.size() - 1);
                Assert.assertTrue("Expected PC to match", pc.equals(topFrame.getInstructionAddress().toString()));
                return null;
            }
        }.get();

        // Call the runnable that should reset the stack caches' state.
        resetCallable.call();

        // End test, check that all caches were reset and now return an error.
        new Transaction<Object>() {
            @Override
            protected Object process() throws InvalidCacheException, ExecutionException {
                ICache<String[]> frameIdsCache = fStackTraceCM.getChildren(processInfo.fThreadId);
                Assert.assertFalse("Expected cache to be reset", frameIdsCache.isValid());
                return null;
            }
        }.get();

        new Transaction<Object>() {
            @Override
            protected Object process() throws InvalidCacheException, ExecutionException {
                String[] frameIds = validate( fStackTraceCM.getChildren(processInfo.fThreadId) );
                ICache<StackTraceContext[]> cache = fStackTraceCM.getContexts(frameIds);
                Assert.assertFalse("Expected cache to be reset", cache.isValid());

                RangeCache<StackTraceContext> framesRange = fStackTraceCM.getContextRange(processInfo.fThreadId);
                ICache<List<StackTraceContext>> framesRangeCache = framesRange.getRange(0, frameIds.length);
                Assert.assertFalse("Expected cache to be reset", framesRangeCache.isValid());

                return null;
            }
        }.get();
        
        new Transaction<Object>() {
            @Override
            protected Object process() throws InvalidCacheException, ExecutionException {
                String[] frameIds = validate( fStackTraceCM.getChildren(processInfo.fThreadId) );
                
                RangeCache<StackTraceContext> framesRange = fStackTraceCM.getContextRange(processInfo.fThreadId);
                List<StackTraceContext> frames = validate(framesRange.getRange(frameIds.length - 1, 1));
                if (pcShouldChange) { 
                    StackTraceContext topFrame = frames.get(0);
                    Assert.assertFalse("Expected PC to be updated", pc.equals(topFrame.getInstructionAddress().toString()));
                }
                return null;
            }
        }.get();
    }

}

Back to the top