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
.linuxtools
.lttng2
.ui
.tests
.Activator
;
43 import org
.eclipse
.rse
.core
.model
.Host
;
44 import org
.eclipse
.rse
.core
.model
.IHost
;
45 import org
.eclipse
.rse
.internal
.core
.model
.SystemProfile
;
46 import org
.junit
.After
;
47 import org
.junit
.Before
;
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(Activator
.getDefault().getBundle(), 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
{
115 * Run the TraceControlComponent.
117 public void testUstProviderTree() throws Exception
{
119 fProxy
.setTestFile(fTestFile
);
120 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
122 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
124 @SuppressWarnings("restriction")
125 IHost host
= new Host(new SystemProfile("myProfile", true));
126 host
.setHostName("127.0.0.1");
128 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
131 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
133 fFacility
.executeCommand(node
, "connect");
135 // Verify that node is connected
136 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
138 // Get provider groups
139 ITraceControlComponent
[] groups
= node
.getChildren();
140 assertNotNull(groups
);
141 assertEquals(2, groups
.length
);
143 // Get kernel provider
144 ITraceControlComponent
[] providers
= groups
[0].getChildren();
145 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
147 // Get kernel provider events and select 2 events
148 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
149 assertNotNull(events
);
150 assertEquals(3, events
.length
);
152 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
153 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
155 // Initialize dialog implementations for command execution
156 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
157 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
158 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
160 // ------------------------------------------------------------------------
162 // ------------------------------------------------------------------------
163 // Initialize session handling scenario
164 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
166 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
167 sessionDialogStub
.setSessionPath("/home/user/temp");
168 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
170 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
172 // Verify that session was created
173 assertNotNull(session
);
174 assertEquals("mysession", session
.getName());
175 assertEquals("/home/user/temp", session
.getSessionPath());
176 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
178 // ------------------------------------------------------------------------
179 // Create Channel on UST global domain
180 // ------------------------------------------------------------------------
181 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
182 CreateChannelDialogStub channelDialogStub
= new CreateChannelDialogStub();
183 channelDialogStub
.setIsKernel(false);
184 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
185 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
186 channelDialogStub
.getChannelInfo().setReadTimer(100);
187 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
188 TraceControlDialogFactory
.getInstance().setCreateChannelDialog(channelDialogStub
);
190 fFacility
.executeCommand(session
, "createChannelOnSession");
192 // Verify that UST domain was created
193 ITraceControlComponent
[] domains
= session
.getChildren();
194 assertNotNull(domains
);
195 assertEquals(1, domains
.length
);
197 assertEquals("UST global", domains
[0].getName());
199 // Verify that channel was created with correct data
200 ITraceControlComponent
[]channels
= domains
[0].getChildren();
201 assertNotNull(channels
);
202 assertEquals(1, channels
.length
);
204 assertTrue(channels
[0] instanceof TraceChannelComponent
);
205 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
206 assertEquals("mychannel", channel
.getName());
207 assertEquals(2, channel
.getNumberOfSubBuffers());
208 assertEquals("mmap()", channel
.getOutputType());
209 assertEquals(false, channel
.isOverwriteMode());
210 assertEquals(100, channel
.getReadTimer());
211 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
212 assertEquals(16384, channel
.getSubBufferSize());
213 assertEquals(200, channel
.getSwitchTimer());
215 // ------------------------------------------------------------------------
216 // Enable event on default channel on created session above
217 // ------------------------------------------------------------------------
218 // Get first UST provider
219 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
220 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustProvider
.getName());
221 assertEquals(9379, ustProvider
.getPid());
224 events
= ustProvider
.getChildren();
225 assertNotNull(events
);
226 assertEquals(2, events
.length
);
228 baseEventInfo0
= (BaseEventComponent
) events
[0];
229 baseEventInfo1
= (BaseEventComponent
) events
[1];
231 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
233 fFacility
.executeCommand(ustSelection
, "assign.event");
235 // verify that events were created under the channel
236 // Note that domain and channel has to be re-read because the tree is re-created
238 domains
= session
.getChildren();
240 // Verify that channel was created with correct data
241 channels
= domains
[0].getChildren();
243 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
244 assertEquals(2, ustEvents
.length
);
246 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
247 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
248 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
249 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
250 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
252 event
= (TraceEventComponent
) ustEvents
[1];
253 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
254 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
255 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
256 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
258 // ------------------------------------------------------------------------
259 // Disable event components
260 // ------------------------------------------------------------------------
261 fFacility
.executeCommand(event
, "disableEvent");
263 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
265 // ------------------------------------------------------------------------
266 // Enable event component
267 // ------------------------------------------------------------------------
268 fFacility
.executeCommand(event
, "enableEvent");
270 // Verify event state
271 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
273 // ------------------------------------------------------------------------
275 // ------------------------------------------------------------------------
277 // Initialize session handling scenario
278 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
280 fFacility
.destroySession(session
);
282 // Verify that no more session components exist
283 assertEquals(0, groups
[1].getChildren().length
);
285 //-------------------------------------------------------------------------
287 //-------------------------------------------------------------------------
288 fFacility
.executeCommand(node
, "disconnect");
289 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
291 //-------------------------------------------------------------------------
293 //-------------------------------------------------------------------------
294 fFacility
.executeCommand(node
, "delete");
295 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);