Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 758f0249e008076270a9e5afa48da284034ea5c9 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*******************************************************************************
 * (C) Copyright 2010 IBM Corp. 2010
 * 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:
 *    Thavidu Ranatunga (IBM) - Initial implementation.
 *******************************************************************************/
package org.eclipse.linuxtools.internal.perf.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.linuxtools.internal.perf.PerfCore;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.PerfVersion;
import org.eclipse.linuxtools.internal.perf.launch.PerfEventsTab;
import org.eclipse.linuxtools.internal.perf.launch.PerfOptionsTab;
import org.eclipse.linuxtools.profiling.tests.AbstractTest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;

public class LaunchTabsTest extends AbstractTest {
    private ILaunchConfiguration config;
    private Shell testShell;

    @Before
    public void setUp() throws Exception {
        proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest"); //$NON-NLS-1$
        config = createConfiguration(proj.getProject());
        testShell = new Shell(Display.getDefault());
        testShell.setLayout(new GridLayout());
    }

    @After
    public void tearDown() throws Exception {
        testShell.dispose();
        deleteProject(proj);
    }

    @Override
    protected ILaunchConfigurationType getLaunchConfigType() {
        return getLaunchManager().getLaunchConfigurationType(PerfPlugin.LAUNCHCONF_ID);
    }

    @Override
    protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
        PerfEventsTab eventsTab = new PerfEventsTab();
        PerfOptionsTab optionsTab = new PerfOptionsTab();
        eventsTab.setDefaults(wc);
        optionsTab.setDefaults(wc);
    }


    //getter functions for otherwise unaccessible member variables
    private static class TestOptionsTab extends PerfOptionsTab {
        protected Text getTxtKernelLocation() { return txtKernelLocation; }
        protected Button getChkRecordRealtime() { return chkRecordRealtime; }
        protected Button getChkRecordVerbose() { return chkRecordVerbose; }
        protected Button getChkSourceLineNumbers() { return chkSourceLineNumbers; }
        protected Button getChkKernelSourceLineNumbers() { return chkKernelSourceLineNumbers; }
        protected Button getChkMultiplexEvents() { return chkMultiplexEvents; }
        protected Button getChkModuleSymbols() { return chkModuleSymbols; }
        protected Button getChkHideUnresolvedSymbols() { return chkHideUnresolvedSymbols; }
    }
    @Test
    public void testOptionsTab() throws CoreException {
        ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
        TestOptionsTab tab = new TestOptionsTab();
        tab.createControl(new Shell());
        assertNotNull(tab.getImage());
        assertNotNull(tab.getName());

        //default config
        tab.setDefaults(wc);
        tab.initializeFrom(config);
        assertTrue(tab.isValid(config));

        Button rrCheck = tab.getChkRecordRealtime();
        rrCheck.setSelection(true);
        rrCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_Record_Realtime, false));
        rrCheck.setSelection(false);
        rrCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_Record_Realtime, true));

        Button rvCheck = tab.getChkRecordVerbose();
        rvCheck.setSelection(true);
        rvCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_Record_Verbose, false));
        rvCheck.setSelection(false);
        rvCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_Record_Verbose, true));

        Button slcCheck = tab.getChkSourceLineNumbers();
        slcCheck.setSelection(true);
        slcCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_SourceLineNumbers, false));
        slcCheck.setSelection(false);
        slcCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_SourceLineNumbers, true));

        Button kslcCheck = tab.getChkKernelSourceLineNumbers();
        kslcCheck.setSelection(true);
        kslcCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, false));
        kslcCheck.setSelection(false);
        kslcCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, true));

        PerfVersion version = PerfCore.getPerfVersion(config);
        Button meCheck = tab.getChkMultiplexEvents();
        if (meCheck.isEnabled()) {
            assertTrue (version != null && new PerfVersion(2, 6, 35).isNewer(version));
            meCheck.setSelection(true);
            meCheck.notifyListeners(SWT.Selection, null);
            performApply(tab, wc);
            assertEquals(true, config.getAttribute(PerfPlugin.ATTR_Multiplex, false));
            meCheck.setSelection(false);
            meCheck.notifyListeners(SWT.Selection, null);
            performApply(tab, wc);
            assertEquals(false, config.getAttribute(PerfPlugin.ATTR_Multiplex, true));
        } else {
            assertTrue (version == null || !new PerfVersion(2, 6, 35).isNewer(version));
        }

        Button msCheck = tab.getChkModuleSymbols();
        msCheck.setSelection(true);
        msCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_ModuleSymbols, false));
        msCheck.setSelection(false);
        msCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_ModuleSymbols, true));

        Button husCheck = tab.getChkHideUnresolvedSymbols();
        husCheck.setSelection(true);
        husCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(true, config.getAttribute(PerfPlugin.ATTR_HideUnresolvedSymbols, false));
        husCheck.setSelection(false);
        husCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertEquals(false, config.getAttribute(PerfPlugin.ATTR_HideUnresolvedSymbols, true));

        rrCheck.setSelection(true);
        rrCheck.notifyListeners(SWT.Selection, null);
        rvCheck.setSelection(true);
        rvCheck.notifyListeners(SWT.Selection, null);
        slcCheck.setSelection(true);
        slcCheck.notifyListeners(SWT.Selection, null);
        kslcCheck.setSelection(true);
        kslcCheck.notifyListeners(SWT.Selection, null);
        meCheck.setSelection(true);
        meCheck.notifyListeners(SWT.Selection, null);
        msCheck.setSelection(true);
        msCheck.notifyListeners(SWT.Selection, null);
        husCheck.setSelection(true);
        husCheck.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        tab.initializeFrom(config);
        assertTrue(rrCheck.getSelection());
        assertTrue(rvCheck.getSelection());
        assertTrue(slcCheck.getSelection());
        assertTrue(kslcCheck.getSelection());
        assertTrue(meCheck.getSelection());
        assertTrue(msCheck.getSelection());
        assertTrue(husCheck.getSelection());

        Text klocText = tab.getTxtKernelLocation();
        klocText.setText("doesntexist"); //$NON-NLS-1$
        klocText.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertFalse(tab.isValid(config));

        klocText.setText(""); //$NON-NLS-1$
        klocText.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertTrue(tab.isValid(config));
    }

    //getter functions for otherwise unaccessible member variables
    private static class TestEventsTab extends PerfEventsTab {
        public Button get_chkDefaultEvent() { return chkDefaultEvent; }
    }

    @Test
    public void testEventsTab() throws CoreException {
        TestEventsTab tab = new TestEventsTab();
        tab.createControl(new Shell());
        assertNotNull(tab.getImage());
        assertNotNull(tab.getName());

        //default config
        tab.setDefaults(config.getWorkingCopy());
        tab.initializeFrom(config);
        assertTrue(tab.isValid(config));

        assertTrue(tab.get_chkDefaultEvent().getSelection());

        tab.get_chkDefaultEvent().notifyListeners(SWT.Selection, null);
        tab.get_chkDefaultEvent().setSelection(false);
        tab.get_chkDefaultEvent().notifyListeners(SWT.Selection, null);
        assertFalse(tab.get_chkDefaultEvent().getSelection());
    }

    public void performApply (ILaunchConfigurationTab tab, ILaunchConfigurationWorkingCopy wc) throws CoreException {
        tab.performApply(wc);
        wc.doSave();
    }

}

Back to the top