1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 **********************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.remote
.core
.IRemoteConnection
;
26 import org
.eclipse
.remote
.core
.IRemoteConnectionManager
;
27 import org
.eclipse
.remote
.core
.RemoteServices
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.EnableChannelDialogStub
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
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 IRemoteConnectionManager cm
= RemoteServices
.getLocalServices().getConnectionManager();
114 IRemoteConnection host
= cm
.getConnection(IRemoteConnectionManager
.LOCAL_CONNECTION_NAME
);
115 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
118 fFacility
.waitForJobs();
120 fFacility
.executeCommand(node
, "connect");
122 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
124 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
127 // Get provider groups
128 ITraceControlComponent
[] groups
= node
.getChildren();
129 assertNotNull(groups
);
130 assertEquals(2, groups
.length
);
132 // Initialize dialog implementations for command execution
133 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
134 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
135 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
137 // Initialize scenario
138 fProxy
.setScenario(SCEN_SCEN_PER_UID_TEST
);
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
143 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
145 // Verify that session was created
146 assertNotNull(session
);
147 assertEquals("mysession", session
.getName());
149 // ------------------------------------------------------------------------
150 // Enable default channel on created session above
151 // ------------------------------------------------------------------------
152 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
153 channelStub
.setIsKernel(false);
154 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
155 info
.setName("mychannel");
156 info
.setOverwriteMode(false);
157 info
.setSubBufferSize(-1);
158 info
.setNumberOfSubBuffers(-1);
159 info
.setSwitchTimer(-1);
160 info
.setReadTimer(-1);
161 info
.setMaxNumberTraceFiles(-1);
162 info
.setMaxSizeTraceFiles(-1);
163 info
.setBufferType(BufferType
.BUFFER_PER_UID
);
164 channelStub
.setChannelInfo(info
);
166 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
168 fFacility
.executeCommand(session
, "enableChannelOnSession");
170 // Verify that UST domain was created
171 ITraceControlComponent
[] domains
= session
.getChildren();
172 assertNotNull(domains
);
173 assertEquals(1, domains
.length
);
175 assertEquals("UST global", domains
[0].getName());
176 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_UID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
178 // Verify that channel was created with correct data
179 ITraceControlComponent
[] channels
= domains
[0].getChildren();
180 assertNotNull(channels
);
181 assertEquals(1, channels
.length
);
183 assertTrue(channels
[0] instanceof TraceChannelComponent
);
184 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
185 assertEquals("mychannel", channel
.getName());
187 // ------------------------------------------------------------------------
189 // ------------------------------------------------------------------------
190 fFacility
.destroySession(session
);
192 // Verify that no more session components exist
193 assertEquals(0, groups
[1].getChildren().length
);
195 // ------------------------------------------------------------------------
196 // Create session (per-pid buffers)
197 // ------------------------------------------------------------------------
199 // Initialize scenario
200 fProxy
.setScenario(SCEN_SCEN_PER_PID_TEST
);
202 session
= fFacility
.createSession(groups
[1]);
204 // Verify that session was created
205 assertNotNull(session
);
206 assertEquals("mysession", session
.getName());
208 // ------------------------------------------------------------------------
209 // Enable default channel on created session above
210 // ------------------------------------------------------------------------
211 info
= (ChannelInfo
)channelStub
.getChannelInfo();
212 info
.setName("mychannel");
213 info
.setBufferType(BufferType
.BUFFER_PER_PID
);
214 channelStub
.setChannelInfo(info
);
216 fFacility
.executeCommand(session
, "enableChannelOnSession");
218 // Verify that UST domain was created
219 domains
= session
.getChildren();
220 assertNotNull(domains
);
221 assertEquals(1, domains
.length
);
223 assertEquals("UST global", domains
[0].getName());
224 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
226 // Verify that channel was created with correct data
227 channels
= domains
[0].getChildren();
228 assertNotNull(channels
);
229 assertEquals(1, channels
.length
);
231 assertTrue(channels
[0] instanceof TraceChannelComponent
);
232 channel
= (TraceChannelComponent
) channels
[0];
233 assertEquals("mychannel", channel
.getName());
235 // ------------------------------------------------------------------------
237 // ------------------------------------------------------------------------
238 fFacility
.destroySession(session
);
240 // Verify that no more session components exist
241 assertEquals(0, groups
[1].getChildren().length
);
243 // ------------------------------------------------------------------------
244 // Create session (configured file size and number of files)
245 // ------------------------------------------------------------------------
247 // Initialize scenario
248 fProxy
.setScenario(SCEN_SCEN_BUF_SIZE_TEST
);
250 session
= fFacility
.createSession(groups
[1]);
252 // Verify that session was created
253 assertNotNull(session
);
254 assertEquals("mysession", session
.getName());
256 // ------------------------------------------------------------------------
257 // Enable default channel on created session above
258 // ------------------------------------------------------------------------
259 info
= (ChannelInfo
)channelStub
.getChannelInfo();
260 info
.setName("mychannel");
261 info
.setMaxNumberTraceFiles(10);
262 info
.setMaxSizeTraceFiles(1024);
263 info
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
264 channelStub
.setChannelInfo(info
);
266 fFacility
.executeCommand(session
, "enableChannelOnSession");
268 // Verify that UST domain was created
269 domains
= session
.getChildren();
270 assertNotNull(domains
);
271 assertEquals(1, domains
.length
);
273 assertEquals("UST global", domains
[0].getName());
274 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
276 // Verify that channel was created with correct data
277 channels
= domains
[0].getChildren();
278 assertNotNull(channels
);
279 assertEquals(1, channels
.length
);
281 assertTrue(channels
[0] instanceof TraceChannelComponent
);
282 channel
= (TraceChannelComponent
) channels
[0];
283 assertEquals("mychannel", channel
.getName());
285 // ------------------------------------------------------------------------
287 // ------------------------------------------------------------------------
288 fFacility
.destroySession(session
);
290 // Verify that no more session components exist
291 assertEquals(0, groups
[1].getChildren().length
);
293 //-------------------------------------------------------------------------
295 //-------------------------------------------------------------------------
296 fFacility
.executeCommand(node
, "disconnect");
297 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
299 //-------------------------------------------------------------------------
301 //-------------------------------------------------------------------------
303 fFacility
.executeCommand(node
, "delete");
305 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);