Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: de594c59b19bc1e12c5e249d94dcb3cc3d98b661 (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
/*******************************************************************************
 * Copyright (c) 2011, 2018 IBM Corporation and others.
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Daniel H Barboza <danielhb@br.ibm.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.helgrind.tests;

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.linuxtools.internal.valgrind.helgrind.HelgrindPlugin;
import org.eclipse.linuxtools.internal.valgrind.helgrind.HelgrindToolPage;
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindOptionsTab;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LaunchConfigTabTest extends AbstractHelgrindTest {

    private ILaunchConfiguration config;
    private Shell testShell;
    private ValgrindOptionsTab tab;
    private HelgrindToolPage dynamicTab;

    @Before
    public void prep() throws Exception {
        proj = createProjectAndBuild("cpptest"); //$NON-NLS-1$

        config = createConfiguration(proj.getProject());

        testShell = new Shell(Display.getDefault());
        testShell.setLayout(new GridLayout());
        tab = new ValgrindOptionsTab();
    }

    @Override
    @After
    public void tearDown() throws CoreException {
        tab.dispose();
        testShell.dispose();
        deleteProject(proj);
        super.tearDown();
    }

    private ILaunchConfigurationWorkingCopy initConfig() throws CoreException {
        ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
        tab.setDefaults(wc);
        tab.createControl(testShell);
        tab.initializeFrom(config);
        int ix = Arrays.asList(tab.getTools()).indexOf(HelgrindPlugin.TOOL_ID);
        tab.getToolsCombo().select(ix);
        ILaunchConfigurationTab dynamicTab = tab.getDynamicTab();
        this.dynamicTab = (HelgrindToolPage) dynamicTab;
        return wc;
    }

    private ILaunch saveAndLaunch(ILaunchConfigurationWorkingCopy wc,
            String testName) throws CoreException, URISyntaxException, IOException  {
        tab.performApply(wc);
        config = wc.doSave();

        ILaunch launch = doLaunch(config, testName);
        return launch;
    }

    @Test
    public void testDefaults() throws CoreException, URISyntaxException, IOException   {
        ILaunchConfigurationWorkingCopy wc = initConfig();
        ILaunch launch = saveAndLaunch(wc, "testHelgrindGeneric"); //$NON-NLS-1$
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        assertTrue(cmd.contains("--tool=helgrind")); //$NON-NLS-1$
        assertFalse(cmd.contains("--xml=yes")); //$NON-NLS-1$
        assertTrue(cmd.contains("-q")); //$NON-NLS-1$
        assertTrue(cmd.contains("--track-lockorders=yes")); //$NON-NLS-1$
        assertTrue(cmd.contains("--history-level=full")); //$NON-NLS-1$
        assertTrue(cmd.contains("--conflict-cache-size=1000000")); //$NON-NLS-1$
    }

    @Test
    public void testTrackLockorders() throws CoreException, URISyntaxException, IOException  {
        ILaunchConfigurationWorkingCopy wc = initConfig();
        dynamicTab.getLockordersButton().setSelection(false);
        tab.performApply(wc);
        wc.doSave();

        ILaunch launch = saveAndLaunch(wc, "testHelgrindGeneric"); //$NON-NLS-1$
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        assertTrue(cmd.contains("--track-lockorders=no")); //$NON-NLS-1$
    }

    @Test
    public void testHistoryNone() throws CoreException, URISyntaxException, IOException {
        ILaunchConfigurationWorkingCopy wc = initConfig();
        dynamicTab.getHistoryCombo().setText("none");
        tab.performApply(wc);
        wc.doSave();

        ILaunch launch = saveAndLaunch(wc, "testHelgrindGeneric"); //$NON-NLS-1$
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        assertTrue(cmd.contains("--history-level=none")); //$NON-NLS-1$
    }

    @Test
    public void testHistoryApprox() throws CoreException, URISyntaxException, IOException {
        ILaunchConfigurationWorkingCopy wc = initConfig();
        dynamicTab.getHistoryCombo().setText("approx");
        tab.performApply(wc);
        wc.doSave();

        ILaunch launch = saveAndLaunch(wc, "testHelgrindGeneric"); //$NON-NLS-1$
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        assertTrue(cmd.contains("--history-level=approx")); //$NON-NLS-1$
    }

    @Test
    public void testConflictCacheSize() throws CoreException, URISyntaxException, IOException  {
        ILaunchConfigurationWorkingCopy wc = initConfig();

        dynamicTab.getCacheSizeSpinner().setSelection(123456);
        tab.performApply(wc);
        wc.doSave();

        ILaunch launch = saveAndLaunch(wc, "testHelgrindGeneric"); //$NON-NLS-1$
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        assertTrue(cmd.contains("--conflict-cache-size=123456")); //$NON-NLS-1$
    }
}

Back to the top