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
.TraceDomainType
;
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
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
43 import org
.junit
.After
;
44 import org
.junit
.Before
;
45 import org
.junit
.Test
;
46 import org
.osgi
.framework
.FrameworkUtil
;
49 * The class {@link TraceControlUstSession2Test} contains UST
50 * session/channel/event handling test cases for LTTng 2.2.
52 public class TraceControlUstSession2Test
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 private static final String TEST_STREAM
= "CreateTreeTest2.cfg";
59 private static final String SCEN_SCEN_PER_UID_TEST
= "ScenPerUidTest";
60 private static final String SCEN_SCEN_PER_PID_TEST
= "ScenPerPidTest";
61 private static final String SCEN_SCEN_BUF_SIZE_TEST
= "ScenBufSizeTest";
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 private TraceControlTestFacility fFacility
;
68 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
69 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
70 private String fTestFile
;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * Perform pre-test initialization.
80 * if the initialization fails for some reason
83 public void setUp() throws Exception
{
84 fFacility
= TraceControlTestFacility
.getInstance();
86 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
87 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
88 fTestFile
= testfile
.getAbsolutePath();
92 * Perform post-test clean-up.
95 public void tearDown() {
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 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
116 fFacility
.waitForJobs();
118 fFacility
.executeCommand(node
, "connect");
120 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
122 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
125 // Get provider groups
126 ITraceControlComponent
[] groups
= node
.getChildren();
127 assertNotNull(groups
);
128 assertEquals(2, groups
.length
);
130 // Initialize dialog implementations for command execution
131 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
132 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
133 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
135 // Initialize scenario
136 fProxy
.setScenario(SCEN_SCEN_PER_UID_TEST
);
138 // ------------------------------------------------------------------------
140 // ------------------------------------------------------------------------
141 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
143 // Verify that session was created
144 assertNotNull(session
);
145 assertEquals("mysession", session
.getName());
147 // ------------------------------------------------------------------------
148 // Enable default channel on created session above
149 // ------------------------------------------------------------------------
150 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
151 channelStub
.setDomain(TraceDomainType
.UST
);
152 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
153 info
.setName("mychannel");
154 info
.setOverwriteMode(false);
155 info
.setSubBufferSize(-1);
156 info
.setNumberOfSubBuffers(-1);
157 info
.setSwitchTimer(-1);
158 info
.setReadTimer(-1);
159 info
.setMaxNumberTraceFiles(-1);
160 info
.setMaxSizeTraceFiles(-1);
161 info
.setBufferType(BufferType
.BUFFER_PER_UID
);
162 channelStub
.setChannelInfo(info
);
164 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
166 fFacility
.executeCommand(session
, "enableChannelOnSession");
168 // Verify that UST domain was created
169 ITraceControlComponent
[] domains
= session
.getChildren();
170 assertNotNull(domains
);
171 assertEquals(1, domains
.length
);
173 assertEquals("UST global", domains
[0].getName());
174 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_UID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
176 // Verify that channel was created with correct data
177 ITraceControlComponent
[] channels
= domains
[0].getChildren();
178 assertNotNull(channels
);
179 assertEquals(1, channels
.length
);
181 assertTrue(channels
[0] instanceof TraceChannelComponent
);
182 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
183 assertEquals("mychannel", channel
.getName());
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
188 fFacility
.destroySession(session
);
190 // Verify that no more session components exist
191 assertEquals(0, groups
[1].getChildren().length
);
193 // ------------------------------------------------------------------------
194 // Create session (per-pid buffers)
195 // ------------------------------------------------------------------------
197 // Initialize scenario
198 fProxy
.setScenario(SCEN_SCEN_PER_PID_TEST
);
200 session
= fFacility
.createSession(groups
[1]);
202 // Verify that session was created
203 assertNotNull(session
);
204 assertEquals("mysession", session
.getName());
206 // ------------------------------------------------------------------------
207 // Enable default channel on created session above
208 // ------------------------------------------------------------------------
209 info
= (ChannelInfo
)channelStub
.getChannelInfo();
210 info
.setName("mychannel");
211 info
.setBufferType(BufferType
.BUFFER_PER_PID
);
212 channelStub
.setChannelInfo(info
);
214 fFacility
.executeCommand(session
, "enableChannelOnSession");
216 // Verify that UST domain was created
217 domains
= session
.getChildren();
218 assertNotNull(domains
);
219 assertEquals(1, domains
.length
);
221 assertEquals("UST global", domains
[0].getName());
222 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
224 // Verify that channel was created with correct data
225 channels
= domains
[0].getChildren();
226 assertNotNull(channels
);
227 assertEquals(1, channels
.length
);
229 assertTrue(channels
[0] instanceof TraceChannelComponent
);
230 channel
= (TraceChannelComponent
) channels
[0];
231 assertEquals("mychannel", channel
.getName());
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
236 fFacility
.destroySession(session
);
238 // Verify that no more session components exist
239 assertEquals(0, groups
[1].getChildren().length
);
241 // ------------------------------------------------------------------------
242 // Create session (configured file size and number of files)
243 // ------------------------------------------------------------------------
245 // Initialize scenario
246 fProxy
.setScenario(SCEN_SCEN_BUF_SIZE_TEST
);
248 session
= fFacility
.createSession(groups
[1]);
250 // Verify that session was created
251 assertNotNull(session
);
252 assertEquals("mysession", session
.getName());
254 // ------------------------------------------------------------------------
255 // Enable default channel on created session above
256 // ------------------------------------------------------------------------
257 info
= (ChannelInfo
)channelStub
.getChannelInfo();
258 info
.setName("mychannel");
259 info
.setMaxNumberTraceFiles(10);
260 info
.setMaxSizeTraceFiles(1024);
261 info
.setBufferType(BufferType
.BUFFER_TYPE_UNKNOWN
);
262 channelStub
.setChannelInfo(info
);
264 fFacility
.executeCommand(session
, "enableChannelOnSession");
266 // Verify that UST domain was created
267 domains
= session
.getChildren();
268 assertNotNull(domains
);
269 assertEquals(1, domains
.length
);
271 assertEquals("UST global", domains
[0].getName());
272 assertEquals("Domain buffer Type", BufferType
.BUFFER_PER_PID
, ((TraceDomainComponent
)domains
[0]).getBufferType());
274 // Verify that channel was created with correct data
275 channels
= domains
[0].getChildren();
276 assertNotNull(channels
);
277 assertEquals(1, channels
.length
);
279 assertTrue(channels
[0] instanceof TraceChannelComponent
);
280 channel
= (TraceChannelComponent
) channels
[0];
281 assertEquals("mychannel", channel
.getName());
283 // ------------------------------------------------------------------------
285 // ------------------------------------------------------------------------
286 fFacility
.destroySession(session
);
288 // Verify that no more session components exist
289 assertEquals(0, groups
[1].getChildren().length
);
291 //-------------------------------------------------------------------------
293 //-------------------------------------------------------------------------
294 fFacility
.executeCommand(node
, "disconnect");
295 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
297 //-------------------------------------------------------------------------
299 //-------------------------------------------------------------------------
301 fFacility
.executeCommand(node
, "delete");
302 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);