1 /**********************************************************************
2 * Copyright (c) 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 **********************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
22 import org
.eclipse
.core
.runtime
.FileLocator
;
23 import org
.eclipse
.core
.runtime
.Path
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BufferType
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.EnableChannelDialogStub
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
38 import org
.eclipse
.rse
.core
.RSECorePlugin
;
39 import org
.eclipse
.rse
.core
.model
.IHost
;
40 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
41 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
42 import org
.junit
.After
;
43 import org
.junit
.Before
;
44 import org
.junit
.Test
;
45 import org
.osgi
.framework
.FrameworkUtil
;
48 * The class <code>TraceControlUstSessionTests</code> contains UST
49 * session/channel/event handling test cases for LTTng 2.2.
51 public class TraceControlUstSessionTests2
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 private static final String TEST_STREAM
= "CreateTreeTest2.cfg";
58 private static final String SCEN_SCEN_PER_UID_TEST
= "ScenPerUidTest";
59 private static final String SCEN_SCEN_PER_PID_TEST
= "ScenPerPidTest";
60 private static final String SCEN_SCEN_BUF_SIZE_TEST
= "ScenBufSizeTest";
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 private TraceControlTestFacility fFacility
;
67 private TestRemoteSystemProxy fProxy
;
68 private String fTestFile
;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 * Perform pre-test initialization.
78 * if the initialization fails for some reason
81 public void setUp() throws Exception
{
82 fFacility
= TraceControlTestFacility
.getInstance();
84 fProxy
= new TestRemoteSystemProxy();
85 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
86 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
87 fTestFile
= testfile
.getAbsolutePath();
91 * Perform post-test clean-up.
94 public void tearDown() {
95 fFacility
.waitForJobs();
100 * Run the TraceControlComponent.
103 * This will fail the test
106 public void testTraceSessionTree() throws Exception
{
108 fProxy
.setTestFile(fTestFile
);
109 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
111 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
113 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
114 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
115 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
117 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
120 fFacility
.waitForJobs();
122 fFacility
.executeCommand(node
, "connect");
124 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
126 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
129 // Get provider groups
130 ITraceControlComponent
[] groups
= node
.getChildren();
131 assertNotNull(groups
);
132 assertEquals(2, groups
.length
);
134 // Initialize dialog implementations for command execution
135 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
136 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
137 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
139 // Initialize scenario
140 fProxy
.setScenario(SCEN_SCEN_PER_UID_TEST
);
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
145 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
147 // Verify that session was created
148 assertNotNull(session
);
149 assertEquals("mysession", session
.getName());
151 // ------------------------------------------------------------------------
152 // Enable default channel on created session above
153 // ------------------------------------------------------------------------
154 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
155 channelStub
.setIsKernel(false);
156 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
157 info
.setName("mychannel");
158 info
.setOverwriteMode(false);
159 info
.setSubBufferSize(-1);
160 info
.setNumberOfSubBuffers(-1);
161 info
.setSwitchTimer(-1);
162 info
.setReadTimer(-1);
163 info
.setMaxNumberTraceFiles(-1);
164 info
.setMaxSizeTraceFiles(-1);
165 info
.setBufferType(BufferType
.BUFFER_PER_UID
);
166 channelStub
.setChannelInfo(info
);
168 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
170 fFacility
.executeCommand(session
, "enableChannelOnSession");
172 // Verify that UST domain was created
173 ITraceControlComponent
[] domains
= session
.getChildren();
174 assertNotNull(domains
);
175 assertEquals(1, domains
.length
);
177 assertEquals("UST global", domains
[0].getName());
178 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_UID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
180 // Verify that channel was created with correct data
181 ITraceControlComponent
[] channels
= domains
[0].getChildren();
182 assertNotNull(channels
);
183 assertEquals(1, channels
.length
);
185 assertTrue(channels
[0] instanceof TraceChannelComponent
);
186 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
187 assertEquals("mychannel", channel
.getName());
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
192 fFacility
.destroySession(session
);
194 // Verify that no more session components exist
195 assertEquals(0, groups
[1].getChildren().length
);
197 // ------------------------------------------------------------------------
198 // Create session (per-pid buffers)
199 // ------------------------------------------------------------------------
201 // Initialize scenario
202 fProxy
.setScenario(SCEN_SCEN_PER_PID_TEST
);
204 session
= fFacility
.createSession(groups
[1]);
206 // Verify that session was created
207 assertNotNull(session
);
208 assertEquals("mysession", session
.getName());
210 // ------------------------------------------------------------------------
211 // Enable default channel on created session above
212 // ------------------------------------------------------------------------
213 info
= (ChannelInfo
)channelStub
.getChannelInfo();
214 info
.setName("mychannel");
215 info
.setBufferType(BufferType
.BUFFER_PER_PID
);
216 channelStub
.setChannelInfo(info
);
218 fFacility
.executeCommand(session
, "enableChannelOnSession");
220 // Verify that UST domain was created
221 domains
= session
.getChildren();
222 assertNotNull(domains
);
223 assertEquals(1, domains
.length
);
225 assertEquals("UST global", domains
[0].getName());
226 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
228 // Verify that channel was created with correct data
229 channels
= domains
[0].getChildren();
230 assertNotNull(channels
);
231 assertEquals(1, channels
.length
);
233 assertTrue(channels
[0] instanceof TraceChannelComponent
);
234 channel
= (TraceChannelComponent
) channels
[0];
235 assertEquals("mychannel", channel
.getName());
237 // ------------------------------------------------------------------------
239 // ------------------------------------------------------------------------
240 fFacility
.destroySession(session
);
242 // Verify that no more session components exist
243 assertEquals(0, groups
[1].getChildren().length
);
245 // ------------------------------------------------------------------------
246 // Create session (configured file size and number of files)
247 // ------------------------------------------------------------------------
249 // Initialize scenario
250 fProxy
.setScenario(SCEN_SCEN_BUF_SIZE_TEST
);
252 session
= fFacility
.createSession(groups
[1]);
254 // Verify that session was created
255 assertNotNull(session
);
256 assertEquals("mysession", session
.getName());
258 // ------------------------------------------------------------------------
259 // Enable default channel on created session above
260 // ------------------------------------------------------------------------
261 info
= (ChannelInfo
)channelStub
.getChannelInfo();
262 info
.setName("mychannel");
263 info
.setMaxNumberTraceFiles(10);
264 info
.setMaxSizeTraceFiles(1024);
265 info
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
266 channelStub
.setChannelInfo(info
);
268 fFacility
.executeCommand(session
, "enableChannelOnSession");
270 // Verify that UST domain was created
271 domains
= session
.getChildren();
272 assertNotNull(domains
);
273 assertEquals(1, domains
.length
);
275 assertEquals("UST global", domains
[0].getName());
276 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
278 // Verify that channel was created with correct data
279 channels
= domains
[0].getChildren();
280 assertNotNull(channels
);
281 assertEquals(1, channels
.length
);
283 assertTrue(channels
[0] instanceof TraceChannelComponent
);
284 channel
= (TraceChannelComponent
) channels
[0];
285 assertEquals("mychannel", channel
.getName());
287 // ------------------------------------------------------------------------
289 // ------------------------------------------------------------------------
290 fFacility
.destroySession(session
);
292 // Verify that no more session components exist
293 assertEquals(0, groups
[1].getChildren().length
);
295 //-------------------------------------------------------------------------
297 //-------------------------------------------------------------------------
298 fFacility
.executeCommand(node
, "disconnect");
299 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
301 //-------------------------------------------------------------------------
303 //-------------------------------------------------------------------------
305 fFacility
.executeCommand(node
, "delete");
307 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);