1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
17 import junit
.framework
.Test
;
18 import junit
.framework
.TestCase
;
19 import junit
.framework
.TestSuite
;
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
;
51 * The class <code>TraceControlUstProviderTests</code> contains UST provider handling
54 @SuppressWarnings("nls")
55 public class TraceControlUstProviderTests
extends TestCase
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
60 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
61 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
66 private TraceControlTestFacility fFacility
;
67 private TestRemoteSystemProxy fProxy
;
68 private String fTestFile
;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 * Returns test setup used when executing test case stand-alone.
76 * @return Test setup class
78 public static Test
suite() {
79 return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests
.class));
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
87 * Perform pre-test initialization.
90 * if the initialization fails for some reason
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();
104 * Perform post-test clean-up.
107 * if the clean-up fails for some reason
112 public void tearDown() throws Exception
{
113 fFacility
.waitForJobs();
117 * Run the TraceControlComponent.
120 * This will fail the test
122 public void testUstProviderTree() throws Exception
{
124 fProxy
.setTestFile(fTestFile
);
125 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
127 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
129 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
130 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
131 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
133 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
136 fFacility
.waitForJobs();
138 fFacility
.executeCommand(node
, "connect");
141 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
143 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
146 // Verify that node is connected
147 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
149 // Get provider groups
150 ITraceControlComponent
[] groups
= node
.getChildren();
151 assertNotNull(groups
);
152 assertEquals(2, groups
.length
);
154 // Get kernel provider
155 ITraceControlComponent
[] providers
= groups
[0].getChildren();
156 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
158 // Get kernel provider events and select 2 events
159 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
160 assertNotNull(events
);
161 assertEquals(3, events
.length
);
163 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
164 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
166 // Initialize dialog implementations for command execution
167 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
168 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
169 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
174 // Initialize session handling scenario
175 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
177 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
178 sessionDialogStub
.setSessionPath("/home/user/temp");
179 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
181 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
183 // Verify that session was created
184 assertNotNull(session
);
185 assertEquals("mysession", session
.getName());
186 assertEquals("/home/user/temp", session
.getSessionPath());
187 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
189 // ------------------------------------------------------------------------
190 // Enable Channel on UST global domain
191 // ------------------------------------------------------------------------
192 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
193 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
194 channelDialogStub
.setIsKernel(false);
195 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
196 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
197 channelDialogStub
.getChannelInfo().setReadTimer(100);
198 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
199 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
201 fFacility
.executeCommand(session
, "enableChannelOnSession");
203 // Verify that UST domain was created
204 ITraceControlComponent
[] domains
= session
.getChildren();
205 assertNotNull(domains
);
206 assertEquals(1, domains
.length
);
208 assertEquals("UST global", domains
[0].getName());
210 // Verify that channel was created with correct data
211 ITraceControlComponent
[]channels
= domains
[0].getChildren();
212 assertNotNull(channels
);
213 assertEquals(1, channels
.length
);
215 assertTrue(channels
[0] instanceof TraceChannelComponent
);
216 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
217 assertEquals("mychannel", channel
.getName());
218 assertEquals(2, channel
.getNumberOfSubBuffers());
219 assertEquals("mmap()", channel
.getOutputType());
220 assertEquals(false, channel
.isOverwriteMode());
221 assertEquals(100, channel
.getReadTimer());
222 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
223 assertEquals(16384, channel
.getSubBufferSize());
224 assertEquals(200, channel
.getSwitchTimer());
226 // ------------------------------------------------------------------------
227 // Enable event on default channel on created session above
228 // ------------------------------------------------------------------------
229 // Get first UST provider
230 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
231 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
232 assertEquals(9379, ustProvider
.getPid());
235 events
= ustProvider
.getChildren();
236 assertNotNull(events
);
237 assertEquals(2, events
.length
);
239 baseEventInfo0
= (BaseEventComponent
) events
[0];
240 baseEventInfo1
= (BaseEventComponent
) events
[1];
242 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
244 fFacility
.executeCommand(ustSelection
, "assign.event");
246 // verify that events were created under the channel
247 // Note that domain and channel has to be re-read because the tree is re-created
249 domains
= session
.getChildren();
251 // Verify that channel was created with correct data
252 channels
= domains
[0].getChildren();
254 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
255 assertEquals(2, ustEvents
.length
);
257 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
258 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
259 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
260 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
261 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
263 event
= (TraceEventComponent
) ustEvents
[1];
264 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
265 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
266 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
267 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
269 // ------------------------------------------------------------------------
270 // Disable event components
271 // ------------------------------------------------------------------------
272 fFacility
.executeCommand(event
, "disableEvent");
274 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
276 // ------------------------------------------------------------------------
277 // Enable event component
278 // ------------------------------------------------------------------------
279 fFacility
.executeCommand(event
, "enableEvent");
281 // Verify event state
282 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
284 // ------------------------------------------------------------------------
286 // ------------------------------------------------------------------------
288 // Initialize session handling scenario
289 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
291 fFacility
.destroySession(session
);
293 // Verify that no more session components exist
294 assertEquals(0, groups
[1].getChildren().length
);
296 //-------------------------------------------------------------------------
298 //-------------------------------------------------------------------------
299 fFacility
.executeCommand(node
, "disconnect");
300 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
302 //-------------------------------------------------------------------------
304 //-------------------------------------------------------------------------
305 fFacility
.executeCommand(node
, "delete");
306 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);