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
.stubs
.dialogs
.CreateChannelDialogStub
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TargetNodeState
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEnablement
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceSessionState
;
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
.model
.Host
;
43 import org
.eclipse
.rse
.core
.model
.IHost
;
44 import org
.eclipse
.rse
.internal
.core
.model
.SystemProfile
;
45 import org
.junit
.After
;
46 import org
.junit
.Before
;
47 import org
.osgi
.framework
.FrameworkUtil
;
50 * The class <code>TraceControlUstProviderTests</code> contains UST provider handling
53 @SuppressWarnings("nls")
54 public class TraceControlUstProviderTests
extends TestCase
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
59 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
60 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
65 private TraceControlTestFacility fFacility
;
66 private TestRemoteSystemProxy fProxy
;
67 private String fTestFile
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 * Returns test setup used when executing test case stand-alone.
75 * @return Test setup class
77 public static Test
suite() {
78 return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests
.class));
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
86 * Perform pre-test initialization.
89 * if the initialization fails for some reason
94 public void setUp() throws Exception
{
95 fFacility
= TraceControlTestFacility
.getInstance();
96 fProxy
= new TestRemoteSystemProxy();
97 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
98 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
99 fTestFile
= testfile
.getAbsolutePath();
103 * Perform post-test clean-up.
106 * if the clean-up fails for some reason
111 public void tearDown() throws Exception
{
112 fFacility
.waitForJobs();
116 * Run the TraceControlComponent.
118 public void testUstProviderTree() throws Exception
{
120 fProxy
.setTestFile(fTestFile
);
121 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
123 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
125 @SuppressWarnings("restriction")
126 IHost host
= new Host(new SystemProfile("myProfile", true));
127 host
.setHostName("127.0.0.1");
129 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
132 fFacility
.waitForJobs();
134 fFacility
.executeCommand(node
, "connect");
137 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
139 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
142 // Verify that node is connected
143 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
145 // Get provider groups
146 ITraceControlComponent
[] groups
= node
.getChildren();
147 assertNotNull(groups
);
148 assertEquals(2, groups
.length
);
150 // Get kernel provider
151 ITraceControlComponent
[] providers
= groups
[0].getChildren();
152 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
154 // Get kernel provider events and select 2 events
155 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
156 assertNotNull(events
);
157 assertEquals(3, events
.length
);
159 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
160 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
162 // Initialize dialog implementations for command execution
163 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
164 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
165 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
167 // ------------------------------------------------------------------------
169 // ------------------------------------------------------------------------
170 // Initialize session handling scenario
171 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
173 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
174 sessionDialogStub
.setSessionPath("/home/user/temp");
175 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
177 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
179 // Verify that session was created
180 assertNotNull(session
);
181 assertEquals("mysession", session
.getName());
182 assertEquals("/home/user/temp", session
.getSessionPath());
183 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
185 // ------------------------------------------------------------------------
186 // Create Channel on UST global domain
187 // ------------------------------------------------------------------------
188 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
189 CreateChannelDialogStub channelDialogStub
= new CreateChannelDialogStub();
190 channelDialogStub
.setIsKernel(false);
191 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
192 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
193 channelDialogStub
.getChannelInfo().setReadTimer(100);
194 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
195 TraceControlDialogFactory
.getInstance().setCreateChannelDialog(channelDialogStub
);
197 fFacility
.executeCommand(session
, "createChannelOnSession");
199 // Verify that UST domain was created
200 ITraceControlComponent
[] domains
= session
.getChildren();
201 assertNotNull(domains
);
202 assertEquals(1, domains
.length
);
204 assertEquals("UST global", domains
[0].getName());
206 // Verify that channel was created with correct data
207 ITraceControlComponent
[]channels
= domains
[0].getChildren();
208 assertNotNull(channels
);
209 assertEquals(1, channels
.length
);
211 assertTrue(channels
[0] instanceof TraceChannelComponent
);
212 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
213 assertEquals("mychannel", channel
.getName());
214 assertEquals(2, channel
.getNumberOfSubBuffers());
215 assertEquals("mmap()", channel
.getOutputType());
216 assertEquals(false, channel
.isOverwriteMode());
217 assertEquals(100, channel
.getReadTimer());
218 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
219 assertEquals(16384, channel
.getSubBufferSize());
220 assertEquals(200, channel
.getSwitchTimer());
222 // ------------------------------------------------------------------------
223 // Enable event on default channel on created session above
224 // ------------------------------------------------------------------------
225 // Get first UST provider
226 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
227 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustProvider
.getName());
228 assertEquals(9379, ustProvider
.getPid());
231 events
= ustProvider
.getChildren();
232 assertNotNull(events
);
233 assertEquals(2, events
.length
);
235 baseEventInfo0
= (BaseEventComponent
) events
[0];
236 baseEventInfo1
= (BaseEventComponent
) events
[1];
238 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
240 fFacility
.executeCommand(ustSelection
, "assign.event");
242 // verify that events were created under the channel
243 // Note that domain and channel has to be re-read because the tree is re-created
245 domains
= session
.getChildren();
247 // Verify that channel was created with correct data
248 channels
= domains
[0].getChildren();
250 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
251 assertEquals(2, ustEvents
.length
);
253 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
254 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
255 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
256 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
257 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
259 event
= (TraceEventComponent
) ustEvents
[1];
260 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
261 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
262 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
263 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
265 // ------------------------------------------------------------------------
266 // Disable event components
267 // ------------------------------------------------------------------------
268 fFacility
.executeCommand(event
, "disableEvent");
270 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
272 // ------------------------------------------------------------------------
273 // Enable event component
274 // ------------------------------------------------------------------------
275 fFacility
.executeCommand(event
, "enableEvent");
277 // Verify event state
278 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
280 // ------------------------------------------------------------------------
282 // ------------------------------------------------------------------------
284 // Initialize session handling scenario
285 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
287 fFacility
.destroySession(session
);
289 // Verify that no more session components exist
290 assertEquals(0, groups
[1].getChildren().length
);
292 //-------------------------------------------------------------------------
294 //-------------------------------------------------------------------------
295 fFacility
.executeCommand(node
, "disconnect");
296 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
298 //-------------------------------------------------------------------------
300 //-------------------------------------------------------------------------
301 fFacility
.executeCommand(node
, "delete");
302 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);