1 /**********************************************************************
2 * Copyright (c) 2013, 2015 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
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.remote
.core
.IRemoteConnection
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.EnableChannelDialogStub
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
41 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
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 IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
68 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
69 private String fTestFile
;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * Perform pre-test initialization.
79 * if the initialization fails for some reason
82 public void setUp() throws Exception
{
83 fFacility
= TraceControlTestFacility
.getInstance();
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() {
99 * Run the TraceControlComponent.
102 * This will fail the test
105 public void testTraceSessionTree() throws Exception
{
107 fProxy
.setTestFile(fTestFile
);
108 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
110 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
112 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
115 fFacility
.waitForJobs();
117 fFacility
.executeCommand(node
, "connect");
119 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
121 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
124 // Get provider groups
125 ITraceControlComponent
[] groups
= node
.getChildren();
126 assertNotNull(groups
);
127 assertEquals(2, groups
.length
);
129 // Initialize dialog implementations for command execution
130 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
131 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
132 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
134 // Initialize scenario
135 fProxy
.setScenario(SCEN_SCEN_PER_UID_TEST
);
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
140 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
142 // Verify that session was created
143 assertNotNull(session
);
144 assertEquals("mysession", session
.getName());
146 // ------------------------------------------------------------------------
147 // Enable default channel on created session above
148 // ------------------------------------------------------------------------
149 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
150 channelStub
.setIsKernel(false);
151 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
152 info
.setName("mychannel");
153 info
.setOverwriteMode(false);
154 info
.setSubBufferSize(-1);
155 info
.setNumberOfSubBuffers(-1);
156 info
.setSwitchTimer(-1);
157 info
.setReadTimer(-1);
158 info
.setMaxNumberTraceFiles(-1);
159 info
.setMaxSizeTraceFiles(-1);
160 info
.setBufferType(BufferType
.BUFFER_PER_UID
);
161 channelStub
.setChannelInfo(info
);
163 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
165 fFacility
.executeCommand(session
, "enableChannelOnSession");
167 // Verify that UST domain was created
168 ITraceControlComponent
[] domains
= session
.getChildren();
169 assertNotNull(domains
);
170 assertEquals(1, domains
.length
);
172 assertEquals("UST global", domains
[0].getName());
173 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_UID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
175 // Verify that channel was created with correct data
176 ITraceControlComponent
[] channels
= domains
[0].getChildren();
177 assertNotNull(channels
);
178 assertEquals(1, channels
.length
);
180 assertTrue(channels
[0] instanceof TraceChannelComponent
);
181 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
182 assertEquals("mychannel", channel
.getName());
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
187 fFacility
.destroySession(session
);
189 // Verify that no more session components exist
190 assertEquals(0, groups
[1].getChildren().length
);
192 // ------------------------------------------------------------------------
193 // Create session (per-pid buffers)
194 // ------------------------------------------------------------------------
196 // Initialize scenario
197 fProxy
.setScenario(SCEN_SCEN_PER_PID_TEST
);
199 session
= fFacility
.createSession(groups
[1]);
201 // Verify that session was created
202 assertNotNull(session
);
203 assertEquals("mysession", session
.getName());
205 // ------------------------------------------------------------------------
206 // Enable default channel on created session above
207 // ------------------------------------------------------------------------
208 info
= (ChannelInfo
)channelStub
.getChannelInfo();
209 info
.setName("mychannel");
210 info
.setBufferType(BufferType
.BUFFER_PER_PID
);
211 channelStub
.setChannelInfo(info
);
213 fFacility
.executeCommand(session
, "enableChannelOnSession");
215 // Verify that UST domain was created
216 domains
= session
.getChildren();
217 assertNotNull(domains
);
218 assertEquals(1, domains
.length
);
220 assertEquals("UST global", domains
[0].getName());
221 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
223 // Verify that channel was created with correct data
224 channels
= domains
[0].getChildren();
225 assertNotNull(channels
);
226 assertEquals(1, channels
.length
);
228 assertTrue(channels
[0] instanceof TraceChannelComponent
);
229 channel
= (TraceChannelComponent
) channels
[0];
230 assertEquals("mychannel", channel
.getName());
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
235 fFacility
.destroySession(session
);
237 // Verify that no more session components exist
238 assertEquals(0, groups
[1].getChildren().length
);
240 // ------------------------------------------------------------------------
241 // Create session (configured file size and number of files)
242 // ------------------------------------------------------------------------
244 // Initialize scenario
245 fProxy
.setScenario(SCEN_SCEN_BUF_SIZE_TEST
);
247 session
= fFacility
.createSession(groups
[1]);
249 // Verify that session was created
250 assertNotNull(session
);
251 assertEquals("mysession", session
.getName());
253 // ------------------------------------------------------------------------
254 // Enable default channel on created session above
255 // ------------------------------------------------------------------------
256 info
= (ChannelInfo
)channelStub
.getChannelInfo();
257 info
.setName("mychannel");
258 info
.setMaxNumberTraceFiles(10);
259 info
.setMaxSizeTraceFiles(1024);
260 info
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
261 channelStub
.setChannelInfo(info
);
263 fFacility
.executeCommand(session
, "enableChannelOnSession");
265 // Verify that UST domain was created
266 domains
= session
.getChildren();
267 assertNotNull(domains
);
268 assertEquals(1, domains
.length
);
270 assertEquals("UST global", domains
[0].getName());
271 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
273 // Verify that channel was created with correct data
274 channels
= domains
[0].getChildren();
275 assertNotNull(channels
);
276 assertEquals(1, channels
.length
);
278 assertTrue(channels
[0] instanceof TraceChannelComponent
);
279 channel
= (TraceChannelComponent
) channels
[0];
280 assertEquals("mychannel", channel
.getName());
282 // ------------------------------------------------------------------------
284 // ------------------------------------------------------------------------
285 fFacility
.destroySession(session
);
287 // Verify that no more session components exist
288 assertEquals(0, groups
[1].getChildren().length
);
290 //-------------------------------------------------------------------------
292 //-------------------------------------------------------------------------
293 fFacility
.executeCommand(node
, "disconnect");
294 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
296 //-------------------------------------------------------------------------
298 //-------------------------------------------------------------------------
300 fFacility
.executeCommand(node
, "delete");
301 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);