Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5cbf960660ab879ab2319f223b4337820b5c7bb5 (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
/*******************************************************************************
 * 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.math.BigInteger;
import java.util.concurrent.ExecutionException;

import org.eclipse.tcf.debug.test.util.Transaction;
import org.eclipse.tcf.services.ILineNumbers.CodeArea;
import org.junit.Assert;

public class LineNumbersCMTest extends AbstractCMTest {

    public void testLineNumbersCMResetOnContextRemove() throws Exception {
        final TestProcessInfo processInfo = startProcess("tcf_test_func0");

        // Retrieve the current PC for use later
        final String pc = new Transaction<String>() {
            @Override
            protected String process() throws InvalidCacheException, ExecutionException {
                return validate(fRunControlCM.getState(processInfo.fThreadId)).pc;
            }
        }.get();

        final BigInteger pcNumber = new BigInteger(pc);
        final BigInteger pcNumberPlusOne = pcNumber.add(BigInteger.valueOf(1));

        // Retrieve the line number for current PC.
        final CodeArea[] pcCodeAreas = new Transaction<CodeArea[]>() {
            @Override
            protected CodeArea[] process() throws InvalidCacheException, ExecutionException {
                CodeArea[] areas = validate(fLineNumbersCM.mapToSource(processInfo.fProcessId, pcNumber, pcNumberPlusOne));
                Assert.assertNotNull(areas);
                Assert.assertTrue(areas.length != 0);

                areas = validate(fLineNumbersCM.mapToSource(processInfo.fThreadId, pcNumber, pcNumberPlusOne));
                Assert.assertNotNull(areas);
                Assert.assertTrue(areas.length != 0);

                CodeArea[] areas2 = validate(fLineNumbersCM.mapToMemory(processInfo.fProcessId, areas[0].file, areas[0].start_line, areas[0].start_column));
                Assert.assertNotNull(areas2);
                Assert.assertTrue(areas2.length != 0);

                areas2 = validate(fLineNumbersCM.mapToMemory(processInfo.fThreadId, areas[0].file, areas[0].start_line, areas[0].start_column));
                Assert.assertNotNull(areas2);
                Assert.assertTrue(areas2.length != 0);

                return areas;
            }
        }.get();

        // End test, check that all caches were reset and now return an error.
        new Transaction<String>() {
            @Override
            protected String process() throws InvalidCacheException, ExecutionException {
                validate( fDiagnosticsCM.cancelTest(processInfo.fTestId, this) );
                validate( fRunControlCM.waitForContextRemoved(processInfo.fProcessId, this) );
                try {
                    validate(fLineNumbersCM.mapToSource(processInfo.fProcessId, pcNumber, pcNumberPlusOne));
                    Assert.fail("Expected error");
                } catch (ExecutionException e) {}
                try {
                    validate(fLineNumbersCM.mapToSource(processInfo.fThreadId, pcNumber, pcNumberPlusOne));
                    Assert.fail("Expected error");
                } catch (ExecutionException e) {}
                try {
                    CodeArea[] areas3 = validate(fLineNumbersCM.mapToMemory(processInfo.fProcessId, pcCodeAreas[0].file, pcCodeAreas[0].start_line, pcCodeAreas[0].start_column));
                    Assert.fail("Expected error");
                } catch (ExecutionException e) {}
                try {
                    validate(fLineNumbersCM.mapToMemory(processInfo.fThreadId, pcCodeAreas[0].file, pcCodeAreas[0].start_line, pcCodeAreas[0].start_column));
                    Assert.fail("Expected error");
                } catch (ExecutionException e) {}

                return null;
            }
        }.get();
    }

}

Back to the top