1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.*;
21 import org
.eclipse
.core
.runtime
.FileLocator
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.rse
.core
.RSECorePlugin
;
24 import org
.eclipse
.rse
.core
.model
.IHost
;
25 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
26 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceChannelOutputType
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.EnableChannelDialogStub
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceEventComponent
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
47 import org
.junit
.After
;
48 import org
.junit
.Before
;
49 import org
.junit
.Test
;
50 import org
.osgi
.framework
.FrameworkUtil
;
53 * The class <code>TraceControlUstProviderTests</code> contains UST provider
54 * handling test cases.
56 public class TraceControlUstProviderTests
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
63 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 private TraceControlTestFacility fFacility
;
70 private TestRemoteSystemProxy fProxy
;
71 private String fTestFile
;
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Perform pre-test initialization.
81 * if the initialization fails for some reason
84 public void setUp() throws Exception
{
85 fFacility
= TraceControlTestFacility
.getInstance();
87 fProxy
= new TestRemoteSystemProxy();
88 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
89 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
90 fTestFile
= testfile
.getAbsolutePath();
94 * Perform post-test clean-up.
97 public void tearDown() {
98 fFacility
.waitForJobs();
103 * Run the TraceControlComponent.
106 * This will fail the test
109 public void testUstProviderTree() throws Exception
{
111 fProxy
.setTestFile(fTestFile
);
112 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
114 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
116 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
117 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
118 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
120 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
123 fFacility
.waitForJobs();
125 fFacility
.executeCommand(node
, "connect");
128 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
130 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
133 // Verify that node is connected
134 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
136 // Get provider groups
137 ITraceControlComponent
[] groups
= node
.getChildren();
138 assertNotNull(groups
);
139 assertEquals(2, groups
.length
);
141 // Get kernel provider
142 ITraceControlComponent
[] providers
= groups
[0].getChildren();
143 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
145 // Get kernel provider events and select 2 events
146 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
147 assertNotNull(events
);
148 assertEquals(3, events
.length
);
150 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
151 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
153 // Initialize dialog implementations for command execution
154 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
155 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
156 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
161 // Initialize session handling scenario
162 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
164 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
165 sessionDialogStub
.setSessionPath("/home/user/temp");
166 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
168 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
170 // Verify that session was created
171 assertNotNull(session
);
172 assertEquals("mysession", session
.getName());
173 assertEquals("/home/user/temp", session
.getSessionPath());
174 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
176 // ------------------------------------------------------------------------
177 // Enable Channel on UST global domain
178 // ------------------------------------------------------------------------
179 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
180 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
181 channelDialogStub
.setIsKernel(false);
182 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
183 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
184 channelDialogStub
.getChannelInfo().setReadTimer(100);
185 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
186 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
188 fFacility
.executeCommand(session
, "enableChannelOnSession");
190 // Verify that UST domain was created
191 ITraceControlComponent
[] domains
= session
.getChildren();
192 assertNotNull(domains
);
193 assertEquals(1, domains
.length
);
195 assertEquals("UST global", domains
[0].getName());
197 // Verify that channel was created with correct data
198 ITraceControlComponent
[]channels
= domains
[0].getChildren();
199 assertNotNull(channels
);
200 assertEquals(1, channels
.length
);
202 assertTrue(channels
[0] instanceof TraceChannelComponent
);
203 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
204 assertEquals("mychannel", channel
.getName());
205 assertEquals(2, channel
.getNumberOfSubBuffers());
206 assertEquals("mmap()", channel
.getOutputType().getInName());
207 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
208 assertEquals(false, channel
.isOverwriteMode());
209 assertEquals(100, channel
.getReadTimer());
210 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
211 assertEquals(16384, channel
.getSubBufferSize());
212 assertEquals(200, channel
.getSwitchTimer());
214 // ------------------------------------------------------------------------
215 // Enable event on default channel on created session above
216 // ------------------------------------------------------------------------
217 // Get first UST provider
218 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
219 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
220 assertEquals(9379, ustProvider
.getPid());
223 events
= ustProvider
.getChildren();
224 assertNotNull(events
);
225 assertEquals(2, events
.length
);
227 baseEventInfo0
= (BaseEventComponent
) events
[0];
228 baseEventInfo1
= (BaseEventComponent
) events
[1];
230 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
232 fFacility
.executeCommand(ustSelection
, "assign.event");
234 // verify that events were created under the channel
235 // Note that domain and channel has to be re-read because the tree is re-created
237 domains
= session
.getChildren();
239 // Verify that channel was created with correct data
240 channels
= domains
[0].getChildren();
242 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
243 assertEquals(2, ustEvents
.length
);
245 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
246 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
247 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
248 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
249 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
251 event
= (TraceEventComponent
) ustEvents
[1];
252 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
253 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
254 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
255 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
257 // ------------------------------------------------------------------------
258 // Disable event components
259 // ------------------------------------------------------------------------
260 fFacility
.executeCommand(event
, "disableEvent");
262 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
264 // ------------------------------------------------------------------------
265 // Enable event component
266 // ------------------------------------------------------------------------
267 fFacility
.executeCommand(event
, "enableEvent");
269 // Verify event state
270 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
272 // ------------------------------------------------------------------------
274 // ------------------------------------------------------------------------
276 // Initialize session handling scenario
277 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
279 fFacility
.destroySession(session
);
281 // Verify that no more session components exist
282 assertEquals(0, groups
[1].getChildren().length
);
284 //-------------------------------------------------------------------------
286 //-------------------------------------------------------------------------
287 fFacility
.executeCommand(node
, "disconnect");
288 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
290 //-------------------------------------------------------------------------
292 //-------------------------------------------------------------------------
293 fFacility
.executeCommand(node
, "delete");
294 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);