1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.*;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.EnableChannelDialogStub
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.EnableEventsDialogStub
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceChannelOutputType
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.BufferType
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.impl
.ChannelInfo
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceEventComponent
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
47 import org
.eclipse
.rse
.core
.RSECorePlugin
;
48 import org
.eclipse
.rse
.core
.model
.IHost
;
49 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
50 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
51 import org
.junit
.After
;
52 import org
.junit
.Before
;
53 import org
.junit
.Test
;
54 import org
.osgi
.framework
.FrameworkUtil
;
57 * The class <code>TraceControlUstSessionTests</code> contains UST
58 * session/channel/event handling test cases.
60 public class TraceControlUstSessionTests
{
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
67 private static final String SCEN_SCENARIO4_TEST
= "Scenario4";
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 private TraceControlTestFacility fFacility
;
74 private TestRemoteSystemProxy fProxy
;
75 private String fTestFile
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * Perform pre-test initialization.
85 * if the initialization fails for some reason
88 public void setUp() throws Exception
{
89 fFacility
= TraceControlTestFacility
.getInstance();
91 fProxy
= new TestRemoteSystemProxy();
92 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
93 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
94 fTestFile
= testfile
.getAbsolutePath();
98 * Perform post-test clean-up.
101 public void tearDown() {
102 fFacility
.waitForJobs();
107 * Run the TraceControlComponent.
110 * This will fail the test
113 public void testTraceSessionTree() throws Exception
{
115 fProxy
.setTestFile(fTestFile
);
116 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
118 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
120 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
121 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
122 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
124 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
127 fFacility
.waitForJobs();
129 fFacility
.executeCommand(node
, "connect");
131 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
133 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
136 // Get provider groups
137 ITraceControlComponent
[] groups
= node
.getChildren();
138 assertNotNull(groups
);
139 assertEquals(2, groups
.length
);
141 // Initialize dialog implementations for command execution
142 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
143 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
144 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
146 // Initialize session handling scenario
147 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
152 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
154 // Verify that session was created
155 assertNotNull(session
);
156 assertEquals("mysession", session
.getName());
157 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
158 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
160 // Initialize scenario
161 fProxy
.setScenario(SCEN_SCENARIO4_TEST
);
163 // ------------------------------------------------------------------------
164 // Enable default channel on created session above
165 // ------------------------------------------------------------------------
166 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
167 channelStub
.setIsKernel(false);
168 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
170 fFacility
.executeCommand(session
, "enableChannelOnSession");
172 // Verify that Kernel 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_TYPE_UNKNOWN
, ((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());
188 assertEquals(4, channel
.getNumberOfSubBuffers());
189 assertEquals("mmap()", channel
.getOutputType().getInName());
190 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
191 assertEquals(true, channel
.isOverwriteMode());
192 assertEquals(200, channel
.getReadTimer());
193 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
194 assertEquals(16384, channel
.getSubBufferSize());
195 assertEquals(100, channel
.getSwitchTimer());
197 // ------------------------------------------------------------------------
198 // Enable channel on domain
199 // ------------------------------------------------------------------------
200 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
201 info
.setName("mychannel2");
202 info
.setOverwriteMode(false);
203 info
.setSubBufferSize(32768);
204 info
.setNumberOfSubBuffers(2);
205 info
.setSwitchTimer(100);
206 info
.setReadTimer(200);
207 channelStub
.setChannelInfo(info
);
209 fFacility
.executeCommand(domains
[0], "enableChannelOnDomain");
211 // Get Kernel domain component instance
212 domains
= session
.getChildren();
213 assertNotNull(domains
);
214 assertEquals(1, domains
.length
);
216 // Verify that channel was created with correct data
217 channels
= domains
[0].getChildren();
218 assertNotNull(channels
);
219 assertEquals(2, channels
.length
);
221 assertTrue(channels
[1] instanceof TraceChannelComponent
);
222 channel
= (TraceChannelComponent
) channels
[1];
223 assertEquals("mychannel2", channel
.getName());
224 assertEquals(2, channel
.getNumberOfSubBuffers());
225 assertEquals("mmap()", channel
.getOutputType().getInName());
226 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
227 assertEquals(false, channel
.isOverwriteMode());
228 assertEquals(200, channel
.getReadTimer());
229 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
230 assertEquals(32768, channel
.getSubBufferSize());
231 assertEquals(100, channel
.getSwitchTimer());
233 // ------------------------------------------------------------------------
234 // Enable event (tracepoint) on session and default channel
235 // ------------------------------------------------------------------------
236 EnableEventsDialogStub eventsDialogStub
= new EnableEventsDialogStub();
237 eventsDialogStub
.setIsTracePoints(true);
238 List
<String
> events
= new ArrayList
<>();
239 events
.add("ust_tests_hello:tptest_sighandler");
240 eventsDialogStub
.setNames(events
);
241 eventsDialogStub
.setIsKernel(false);
242 TraceControlDialogFactory
.getInstance().setEnableEventsDialog(eventsDialogStub
);
244 fFacility
.executeCommand(session
, "enableEventOnSession");
246 // Get Kernel domain component instance
247 domains
= session
.getChildren();
248 assertNotNull(domains
);
249 assertEquals(1, domains
.length
);
251 // Verify that channel was created with correct data
252 channels
= domains
[0].getChildren();
253 assertNotNull(channels
);
254 assertEquals(3, channels
.length
);
256 assertTrue(channels
[2] instanceof TraceChannelComponent
);
257 channel
= (TraceChannelComponent
) channels
[2];
258 assertEquals("channel0", channel
.getName());
259 // No need to check parameters of default channel because that has been done in other tests
261 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
262 assertEquals(1, channel0Events
.length
);
264 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
266 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
267 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
268 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
269 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
270 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
272 // ------------------------------------------------------------------------
273 // Enable event (tracepoint) on domain and default channel
274 // ------------------------------------------------------------------------
276 events
.add("ust_tests_hello:tptest");
277 eventsDialogStub
.setNames(events
);
279 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
281 // Get Kernel domain component instance
282 domains
= session
.getChildren();
283 assertNotNull(domains
);
284 assertEquals(1, domains
.length
);
286 // Verify that channel was created with correct data
287 channels
= domains
[0].getChildren();
288 channel
= (TraceChannelComponent
) channels
[2];
289 // No need to check parameters of default channel because that has been done in other tests
291 channel0Events
= channel
.getChildren();
292 assertEquals(2, channel0Events
.length
);
294 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
296 event
= (TraceEventComponent
) channel0Events
[1];
297 assertEquals("ust_tests_hello:tptest", event
.getName());
298 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
299 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
300 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
302 // ------------------------------------------------------------------------
303 // Enable event (all tracepoints) on specific channel
304 // ------------------------------------------------------------------------
306 eventsDialogStub
.setNames(events
);
307 eventsDialogStub
.setIsAllTracePoints(true);
309 fFacility
.executeCommand(channels
[1], "enableEventOnChannel");
311 // Get Kernel domain component instance
312 domains
= session
.getChildren();
313 assertNotNull(domains
);
314 assertEquals(1, domains
.length
);
316 // Verify that channel was created with correct data
317 channels
= domains
[0].getChildren();
318 channel
= (TraceChannelComponent
) channels
[1];
319 // No need to check parameters of default channel because that has been done in other tests
321 channel
= (TraceChannelComponent
) channels
[1];
323 channel0Events
= channel
.getChildren();
324 assertEquals(1, channel0Events
.length
);
326 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
328 event
= (TraceEventComponent
) channel0Events
[0];
329 assertEquals("*", event
.getName());
330 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
331 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
332 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
334 // ------------------------------------------------------------------------
335 // Enable event (wildcard) on specific channel
336 // ------------------------------------------------------------------------
338 eventsDialogStub
.setIsTracePoints(false);
339 eventsDialogStub
.setIsAllTracePoints(false);
340 eventsDialogStub
.setIsWildcard(true);
341 eventsDialogStub
.setWildcard("ust*");
343 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
345 // Get Kernel domain component instance
346 domains
= session
.getChildren();
347 assertNotNull(domains
);
348 assertEquals(1, domains
.length
);
350 // Verify that channel was created with correct data
351 channels
= domains
[0].getChildren();
352 channel
= (TraceChannelComponent
) channels
[0];
353 // No need to check parameters of default channel because that has been done in other tests
355 channel0Events
= channel
.getChildren();
356 assertEquals(1, channel0Events
.length
);
358 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
360 event
= (TraceEventComponent
) channel0Events
[0];
361 assertEquals("ust*", event
.getName());
362 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
363 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
364 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
366 // ------------------------------------------------------------------------
367 // Enable event (wildcard) on domain
368 // ------------------------------------------------------------------------
370 eventsDialogStub
.setIsTracePoints(false);
371 eventsDialogStub
.setIsAllTracePoints(false);
372 eventsDialogStub
.setIsWildcard(true);
373 eventsDialogStub
.setWildcard("ust*");
375 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
377 // Get Kernel domain component instance
378 domains
= session
.getChildren();
379 assertNotNull(domains
);
380 assertEquals(1, domains
.length
);
382 // Verify that channel was created with correct data
383 channels
= domains
[0].getChildren();
384 channel
= (TraceChannelComponent
) channels
[0];
385 // No need to check parameters of default channel because that has been done in other tests
387 channel0Events
= channel
.getChildren();
388 assertEquals(1, channel0Events
.length
);
390 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
392 event
= (TraceEventComponent
) channel0Events
[0];
393 assertEquals("ust*", event
.getName());
394 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
395 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
396 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
398 // ------------------------------------------------------------------------
399 // Enable event (wildcard) on session
400 // ------------------------------------------------------------------------
402 eventsDialogStub
.setIsTracePoints(false);
403 eventsDialogStub
.setIsAllTracePoints(false);
404 eventsDialogStub
.setIsWildcard(true);
405 eventsDialogStub
.setWildcard("ust*");
407 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
409 // Get Kernel domain component instance
410 domains
= session
.getChildren();
411 assertNotNull(domains
);
412 assertEquals(1, domains
.length
);
414 // Verify that channel was created with correct data
415 channels
= domains
[0].getChildren();
416 channel
= (TraceChannelComponent
) channels
[2];
417 // No need to check parameters of default channel because that has been done in other tests
419 channel0Events
= channel
.getChildren();
420 assertEquals(4, channel0Events
.length
);
422 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
424 event
= (TraceEventComponent
) channel0Events
[0];
425 assertEquals("u*", event
.getName());
426 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
427 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
428 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
430 // ------------------------------------------------------------------------
431 // Enable event (loglevel) on domain
432 // ------------------------------------------------------------------------
434 eventsDialogStub
.setIsWildcard(false);
435 eventsDialogStub
.setIsLogLevel(true);
436 eventsDialogStub
.setLogLevelEventName("myevent1");
437 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL
);
438 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_WARNING
);
440 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
442 // Get Kernel domain component instance
443 domains
= session
.getChildren();
444 assertNotNull(domains
);
445 assertEquals(1, domains
.length
);
447 // Verify that channel was created with correct data
448 channels
= domains
[0].getChildren();
449 channel
= (TraceChannelComponent
) channels
[2];
450 // No need to check parameters of default channel because that has been done in other tests
452 channel0Events
= channel
.getChildren();
453 assertEquals(5, channel0Events
.length
);
455 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
457 event
= (TraceEventComponent
) channel0Events
[0];
458 assertEquals("myevent1", event
.getName());
459 assertEquals(TraceLogLevel
.TRACE_WARNING
, event
.getLogLevel());
460 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
461 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
463 // ------------------------------------------------------------------------
464 // Enable event (loglevel) on session
465 // ------------------------------------------------------------------------
466 eventsDialogStub
.setLogLevelEventName("myevent2");
467 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
468 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
470 fFacility
.executeCommand(session
, "enableEventOnSession");
472 // Get Kernel domain component instance
473 domains
= session
.getChildren();
474 assertNotNull(domains
);
475 assertEquals(1, domains
.length
);
477 // Verify that channel was created with correct data
478 channels
= domains
[0].getChildren();
479 channel
= (TraceChannelComponent
) channels
[2];
480 // No need to check parameters of default channel because that has been done in other tests
482 channel0Events
= channel
.getChildren();
483 assertEquals(6, channel0Events
.length
);
485 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
487 event
= (TraceEventComponent
) channel0Events
[0];
488 assertEquals("myevent2", event
.getName());
489 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
490 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
491 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
493 // ------------------------------------------------------------------------
494 // Enable event (loglevel) on channel
495 // ------------------------------------------------------------------------
496 eventsDialogStub
.setLogLevelEventName("myevent0");
497 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
498 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
500 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
502 // Get Kernel domain component instance
503 domains
= session
.getChildren();
504 assertNotNull(domains
);
505 assertEquals(1, domains
.length
);
507 // Verify that channel was created with correct data
508 channels
= domains
[0].getChildren();
509 channel
= (TraceChannelComponent
) channels
[0];
510 // No need to check parameters of default channel because that has been done in other tests
512 channel0Events
= channel
.getChildren();
513 assertEquals(2, channel0Events
.length
);
515 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
517 event
= (TraceEventComponent
) channel0Events
[0];
518 assertEquals("myevent0", event
.getName());
519 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
520 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
521 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
523 // ------------------------------------------------------------------------
525 // ------------------------------------------------------------------------
526 // Initialize session handling scenario
527 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
529 fFacility
.destroySession(session
);
531 // Verify that no more session components exist
532 assertEquals("Session components still exist.", 0, groups
[1].getChildren().length
);
534 //-------------------------------------------------------------------------
536 //-------------------------------------------------------------------------
537 fFacility
.executeCommand(node
, "disconnect");
538 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
540 //-------------------------------------------------------------------------
542 //-------------------------------------------------------------------------
544 fFacility
.executeCommand(node
, "delete");
546 assertEquals("Node not deleted.", 0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);