~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/model/component/TraceControlUstProviderTests.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 * Copyright (c) 2012 Ericsson
 
3
 * 
 
4
 * All rights reserved. This program and the accompanying materials are
 
5
 * made available under the terms of the Eclipse Public License v1.0 which
 
6
 * accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 * 
 
9
 * Contributors: 
 
10
 *   Bernd Hufmann - Initial API and implementation
 
11
 **********************************************************************/
 
12
package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
 
13
 
 
14
import java.io.File;
 
15
import java.net.URL;
 
16
 
 
17
import junit.framework.Test;
 
18
import junit.framework.TestCase;
 
19
import junit.framework.TestSuite;
 
20
 
 
21
import org.eclipse.core.runtime.FileLocator;
 
22
import org.eclipse.core.runtime.Path;
 
23
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
 
24
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
 
25
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
 
26
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
 
27
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
 
28
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
 
29
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
 
30
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableChannelDialogStub;
 
31
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
 
32
import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
 
33
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
 
34
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
 
35
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent;
 
36
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent;
 
37
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
 
38
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
 
39
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
 
40
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
 
41
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent;
 
42
import org.eclipse.rse.core.RSECorePlugin;
 
43
import org.eclipse.rse.core.model.IHost;
 
44
import org.eclipse.rse.core.model.ISystemProfile;
 
45
import org.eclipse.rse.core.model.ISystemRegistry;
 
46
import org.junit.After;
 
47
import org.junit.Before;
 
48
import org.osgi.framework.FrameworkUtil;
 
49
 
 
50
/**
 
51
 * The class <code>TraceControlUstProviderTests</code> contains UST provider handling
 
52
 * test cases.
 
53
 */
 
54
@SuppressWarnings("nls")
 
55
public class TraceControlUstProviderTests extends TestCase {
 
56
 
 
57
    // ------------------------------------------------------------------------
 
58
    // Constants
 
59
    // ------------------------------------------------------------------------
 
60
    private static final String TEST_STREAM = "CreateTreeTest.cfg";
 
61
    private static final String SCEN_SCENARIO2_TEST = "Scenario2";
 
62
 
 
63
    // ------------------------------------------------------------------------
 
64
    // Test data
 
65
    // ------------------------------------------------------------------------
 
66
    private TraceControlTestFacility fFacility;
 
67
    private TestRemoteSystemProxy fProxy;
 
68
    private String fTestFile; 
 
69
    
 
70
    // ------------------------------------------------------------------------
 
71
    // Static methods
 
72
    // ------------------------------------------------------------------------
 
73
 
 
74
    /**
 
75
     * Returns test setup used when executing test case stand-alone.
 
76
     * @return Test setup class 
 
77
     */
 
78
    public static Test suite() {
 
79
        return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests.class));
 
80
    }
 
81
 
 
82
    // ------------------------------------------------------------------------
 
83
    // Housekeeping
 
84
    // ------------------------------------------------------------------------
 
85
 
 
86
    /**
 
87
     * Perform pre-test initialization.
 
88
     *
 
89
     * @throws Exception
 
90
     *         if the initialization fails for some reason
 
91
     *
 
92
     */
 
93
    @Override
 
94
    @Before
 
95
    public void setUp() throws Exception {
 
96
        fFacility = TraceControlTestFacility.getInstance();
 
97
        fProxy = new TestRemoteSystemProxy();
 
98
        URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
 
99
        File testfile = new File(FileLocator.toFileURL(location).toURI());
 
100
        fTestFile = testfile.getAbsolutePath();
 
101
    }
 
102
 
 
103
    /**
 
104
     * Perform post-test clean-up.
 
105
     *
 
106
     * @throws Exception
 
107
     *         if the clean-up fails for some reason
 
108
     *
 
109
     */
 
110
    @Override
 
111
    @After
 
112
    public void tearDown() throws Exception {
 
113
        fFacility.waitForJobs();
 
114
    }
 
115
    
 
116
    /**
 
117
     * Run the TraceControlComponent.
 
118
     */
 
119
    public void testUstProviderTree() throws Exception {
 
120
        
 
121
        fProxy.setTestFile(fTestFile);
 
122
        fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
 
123
        
 
124
        ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
 
125
 
 
126
        ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
 
127
        ISystemProfile profile =  registry.createSystemProfile("myProfile", true);
 
128
        IHost host = registry.createLocalHost(profile, "myProfile", "user");
 
129
 
 
130
        TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
 
131
        root.addChild(node);
 
132
        
 
133
        fFacility.waitForJobs();
 
134
        
 
135
        fFacility.executeCommand(node, "connect");
 
136
 
 
137
        int i = 0;
 
138
        while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
 
139
            i++;
 
140
            fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
 
141
        }
 
142
        
 
143
        // Verify that node is connected
 
144
        assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
 
145
 
 
146
        // Get provider groups
 
147
        ITraceControlComponent[] groups = node.getChildren();
 
148
        assertNotNull(groups);
 
149
        assertEquals(2, groups.length);
 
150
 
 
151
        // Get kernel provider
 
152
        ITraceControlComponent[] providers = groups[0].getChildren();
 
153
        KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
 
154
 
 
155
        // Get kernel provider events and select 2 events 
 
156
        ITraceControlComponent[] events = kernelProvider.getChildren();
 
157
        assertNotNull(events);
 
158
        assertEquals(3, events.length);
 
159
 
 
160
        BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
 
161
        BaseEventComponent baseEventInfo1  = (BaseEventComponent) events[1];
 
162
 
 
163
        // Initialize dialog implementations for command execution
 
164
        TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
 
165
        TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
 
166
        TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
 
167
 
 
168
        // ------------------------------------------------------------------------
 
169
        // Create session
 
170
        // ------------------------------------------------------------------------
 
171
        // Initialize session handling scenario
 
172
        fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH);
 
173
 
 
174
        CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
 
175
        sessionDialogStub.setSessionPath("/home/user/temp");
 
176
        TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
 
177
 
 
178
        TraceSessionComponent session = fFacility.createSession(groups[1]);
 
179
        
 
180
        // Verify that session was created
 
181
        assertNotNull(session);
 
182
        assertEquals("mysession", session.getName());
 
183
        assertEquals("/home/user/temp", session.getSessionPath());
 
184
        assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
 
185
        
 
186
        // ------------------------------------------------------------------------
 
187
        // Enable Channel on UST global domain
 
188
        // ------------------------------------------------------------------------
 
189
        fProxy.setScenario(SCEN_SCENARIO2_TEST);
 
190
        EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub();
 
191
        channelDialogStub.setIsKernel(false);
 
192
        channelDialogStub.getChannelInfo().setOverwriteMode(false);
 
193
        channelDialogStub.getChannelInfo().setSwitchTimer(200);
 
194
        channelDialogStub.getChannelInfo().setReadTimer(100);
 
195
        channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2);
 
196
        TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub);
 
197
 
 
198
        fFacility.executeCommand(session, "enableChannelOnSession");
 
199
        
 
200
        // Verify that UST domain was created
 
201
        ITraceControlComponent[] domains = session.getChildren();
 
202
        assertNotNull(domains);
 
203
        assertEquals(1, domains.length);
 
204
 
 
205
        assertEquals("UST global", domains[0].getName());
 
206
        
 
207
        // Verify that channel was created with correct data
 
208
        ITraceControlComponent[]channels =  domains[0].getChildren();
 
209
        assertNotNull(channels);
 
210
        assertEquals(1, channels.length);
 
211
 
 
212
        assertTrue(channels[0] instanceof TraceChannelComponent);
 
213
        TraceChannelComponent channel = (TraceChannelComponent) channels[0]; 
 
214
        assertEquals("mychannel", channel.getName());
 
215
        assertEquals(2, channel.getNumberOfSubBuffers());
 
216
        assertEquals("mmap()", channel.getOutputType());
 
217
        assertEquals(false, channel.isOverwriteMode());
 
218
        assertEquals(100, channel.getReadTimer());
 
219
        assertEquals(TraceEnablement.ENABLED, channel.getState());
 
220
        assertEquals(16384, channel.getSubBufferSize());
 
221
        assertEquals(200, channel.getSwitchTimer());
 
222
 
 
223
        // ------------------------------------------------------------------------
 
224
        // Enable event on default channel on created session above
 
225
        // ------------------------------------------------------------------------
 
226
        // Get first UST provider
 
227
        UstProviderComponent ustProvider = (UstProviderComponent) providers[1];
 
228
        assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName());
 
229
        assertEquals(9379, ustProvider.getPid());
 
230
 
 
231
        // Get events
 
232
        events = ustProvider.getChildren();
 
233
        assertNotNull(events);
 
234
        assertEquals(2, events.length);
 
235
 
 
236
        baseEventInfo0 = (BaseEventComponent) events[0];
 
237
        baseEventInfo1 = (BaseEventComponent) events[1];
 
238
 
 
239
        ITraceControlComponent[] ustSelection =  { baseEventInfo0, baseEventInfo1 };
 
240
 
 
241
        fFacility.executeCommand(ustSelection, "assign.event");
 
242
        
 
243
        // verify that events were created under the channel
 
244
        // Note that domain and channel has to be re-read because the tree is re-created
 
245
 
 
246
        domains = session.getChildren();
 
247
 
 
248
        // Verify that channel was created with correct data
 
249
        channels =  domains[0].getChildren();
 
250
 
 
251
        ITraceControlComponent[] ustEvents = channels[0].getChildren();
 
252
        assertEquals(2, ustEvents.length);
 
253
 
 
254
        TraceEventComponent event = (TraceEventComponent) ustEvents[0];
 
255
        assertEquals("ust_tests_hello:tptest_sighandler", event.getName());
 
256
        assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
 
257
        assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
 
258
        assertEquals(TraceEnablement.ENABLED, event.getState());
 
259
 
 
260
        event = (TraceEventComponent) ustEvents[1];
 
261
        assertEquals("ust_tests_hello:tptest", ustEvents[1].getName());
 
262
        assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
 
263
        assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
 
264
        assertEquals(TraceEnablement.ENABLED, event.getState());
 
265
 
 
266
        // ------------------------------------------------------------------------
 
267
        // Disable event components 
 
268
        // ------------------------------------------------------------------------
 
269
        fFacility.executeCommand(event, "disableEvent");
 
270
        
 
271
        assertEquals(TraceEnablement.DISABLED, event.getState());
 
272
 
 
273
        // ------------------------------------------------------------------------
 
274
        // Enable event component 
 
275
        // ------------------------------------------------------------------------
 
276
        fFacility.executeCommand(event, "enableEvent");
 
277
 
 
278
        // Verify event state
 
279
        assertEquals(TraceEnablement.ENABLED, event.getState());
 
280
        
 
281
        // ------------------------------------------------------------------------
 
282
        // Destroy session 
 
283
        // ------------------------------------------------------------------------
 
284
 
 
285
        // Initialize session handling scenario
 
286
        fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
 
287
 
 
288
        fFacility.destroySession(session);
 
289
        
 
290
        // Verify that no more session components exist
 
291
        assertEquals(0, groups[1].getChildren().length);
 
292
 
 
293
        //-------------------------------------------------------------------------
 
294
        // Disconnect node
 
295
        //-------------------------------------------------------------------------
 
296
        fFacility.executeCommand(node, "disconnect");
 
297
        assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
 
298
 
 
299
        //-------------------------------------------------------------------------
 
300
        // Delete node
 
301
        //-------------------------------------------------------------------------
 
302
        fFacility.executeCommand(node, "delete");
 
303
        assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
 
304
   }
 
305
}
 
 
b'\\ No newline at end of file'