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
.linuxtools
.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
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.EnableChannelDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceEventComponent
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.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
.junit
.Test
;
49 import org
.osgi
.framework
.FrameworkUtil
;
52 * The class <code>TraceControlUstProviderTests</code> contains UST provider
53 * handling test cases.
55 public class TraceControlUstProviderTests
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
62 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 private TraceControlTestFacility fFacility
;
69 private TestRemoteSystemProxy fProxy
;
70 private String fTestFile
;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * Perform pre-test initialization.
80 * if the initialization fails for some reason
83 public void setUp() throws Exception
{
84 fFacility
= TraceControlTestFacility
.getInstance();
86 fProxy
= new TestRemoteSystemProxy();
87 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
88 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
89 fTestFile
= testfile
.getAbsolutePath();
93 * Perform post-test clean-up.
96 public void tearDown() {
97 fFacility
.waitForJobs();
102 * Run the TraceControlComponent.
105 * This will fail the test
108 public void testUstProviderTree() throws Exception
{
110 fProxy
.setTestFile(fTestFile
);
111 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
113 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
115 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
116 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
117 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
119 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
122 fFacility
.waitForJobs();
124 fFacility
.executeCommand(node
, "connect");
127 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
129 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
132 // Verify that node is connected
133 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
135 // Get provider groups
136 ITraceControlComponent
[] groups
= node
.getChildren();
137 assertNotNull(groups
);
138 assertEquals(2, groups
.length
);
140 // Get kernel provider
141 ITraceControlComponent
[] providers
= groups
[0].getChildren();
142 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
144 // Get kernel provider events and select 2 events
145 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
146 assertNotNull(events
);
147 assertEquals(3, events
.length
);
149 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
150 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
152 // Initialize dialog implementations for command execution
153 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
154 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
155 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
160 // Initialize session handling scenario
161 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
163 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
164 sessionDialogStub
.setSessionPath("/home/user/temp");
165 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
167 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
169 // Verify that session was created
170 assertNotNull(session
);
171 assertEquals("mysession", session
.getName());
172 assertEquals("/home/user/temp", session
.getSessionPath());
173 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
175 // ------------------------------------------------------------------------
176 // Enable Channel on UST global domain
177 // ------------------------------------------------------------------------
178 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
179 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
180 channelDialogStub
.setIsKernel(false);
181 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
182 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
183 channelDialogStub
.getChannelInfo().setReadTimer(100);
184 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
185 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
187 fFacility
.executeCommand(session
, "enableChannelOnSession");
189 // Verify that UST domain was created
190 ITraceControlComponent
[] domains
= session
.getChildren();
191 assertNotNull(domains
);
192 assertEquals(1, domains
.length
);
194 assertEquals("UST global", domains
[0].getName());
196 // Verify that channel was created with correct data
197 ITraceControlComponent
[]channels
= domains
[0].getChildren();
198 assertNotNull(channels
);
199 assertEquals(1, channels
.length
);
201 assertTrue(channels
[0] instanceof TraceChannelComponent
);
202 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
203 assertEquals("mychannel", channel
.getName());
204 assertEquals(2, channel
.getNumberOfSubBuffers());
205 assertEquals("mmap()", channel
.getOutputType());
206 assertEquals(false, channel
.isOverwriteMode());
207 assertEquals(100, channel
.getReadTimer());
208 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
209 assertEquals(16384, channel
.getSubBufferSize());
210 assertEquals(200, channel
.getSwitchTimer());
212 // ------------------------------------------------------------------------
213 // Enable event on default channel on created session above
214 // ------------------------------------------------------------------------
215 // Get first UST provider
216 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
217 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
218 assertEquals(9379, ustProvider
.getPid());
221 events
= ustProvider
.getChildren();
222 assertNotNull(events
);
223 assertEquals(2, events
.length
);
225 baseEventInfo0
= (BaseEventComponent
) events
[0];
226 baseEventInfo1
= (BaseEventComponent
) events
[1];
228 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
230 fFacility
.executeCommand(ustSelection
, "assign.event");
232 // verify that events were created under the channel
233 // Note that domain and channel has to be re-read because the tree is re-created
235 domains
= session
.getChildren();
237 // Verify that channel was created with correct data
238 channels
= domains
[0].getChildren();
240 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
241 assertEquals(2, ustEvents
.length
);
243 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
244 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
245 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
246 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
247 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
249 event
= (TraceEventComponent
) ustEvents
[1];
250 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
251 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
252 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
253 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
255 // ------------------------------------------------------------------------
256 // Disable event components
257 // ------------------------------------------------------------------------
258 fFacility
.executeCommand(event
, "disableEvent");
260 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
262 // ------------------------------------------------------------------------
263 // Enable event component
264 // ------------------------------------------------------------------------
265 fFacility
.executeCommand(event
, "enableEvent");
267 // Verify event state
268 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
270 // ------------------------------------------------------------------------
272 // ------------------------------------------------------------------------
274 // Initialize session handling scenario
275 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
277 fFacility
.destroySession(session
);
279 // Verify that no more session components exist
280 assertEquals(0, groups
[1].getChildren().length
);
282 //-------------------------------------------------------------------------
284 //-------------------------------------------------------------------------
285 fFacility
.executeCommand(node
, "disconnect");
286 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
288 //-------------------------------------------------------------------------
290 //-------------------------------------------------------------------------
291 fFacility
.executeCommand(node
, "delete");
292 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);