1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.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
.core
.control
.model
.LogLevelType
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.EnableChannelDialogStub
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.EnableEventsDialogStub
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceEventComponent
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
44 import org
.eclipse
.rse
.core
.RSECorePlugin
;
45 import org
.eclipse
.rse
.core
.model
.IHost
;
46 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
47 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
48 import org
.junit
.After
;
49 import org
.junit
.Before
;
50 import org
.junit
.Test
;
51 import org
.osgi
.framework
.FrameworkUtil
;
54 * The class <code>TraceControlUstSessionTests</code> contains UST
55 * session/channel/event handling test cases.
57 @SuppressWarnings("nls")
58 public class TraceControlUstSessionTests
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
65 private static final String SCEN_SCENARIO4_TEST
= "Scenario4";
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 private TraceControlTestFacility fFacility
;
72 private TestRemoteSystemProxy fProxy
;
73 private String fTestFile
;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * Perform pre-test initialization.
83 * if the initialization fails for some reason
86 public void setUp() throws Exception
{
87 fFacility
= TraceControlTestFacility
.getInstance();
88 fProxy
= new TestRemoteSystemProxy();
89 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
90 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
91 fTestFile
= testfile
.getAbsolutePath();
95 * Perform post-test clean-up.
98 public void tearDown() {
99 fFacility
.waitForJobs();
103 * Run the TraceControlComponent.
106 * This will fail the test
109 public void testTraceSessionTree() throws Exception
{
111 fProxy
.setTestFile(fTestFile
);
112 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
114 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
116 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
117 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
118 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
120 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
123 fFacility
.waitForJobs();
125 fFacility
.executeCommand(node
, "connect");
127 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
129 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
132 // Get provider groups
133 ITraceControlComponent
[] groups
= node
.getChildren();
134 assertNotNull(groups
);
135 assertEquals(2, groups
.length
);
137 // Initialize dialog implementations for command execution
138 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
139 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
140 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
142 // Initialize session handling scenario
143 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
148 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
150 // Verify that session was created
151 assertNotNull(session
);
152 assertEquals("mysession", session
.getName());
153 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
154 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
156 // Initialize scenario
157 fProxy
.setScenario(SCEN_SCENARIO4_TEST
);
159 // ------------------------------------------------------------------------
160 // Enable default channel on created session above
161 // ------------------------------------------------------------------------
162 EnableChannelDialogStub channelStub
= new EnableChannelDialogStub();
163 channelStub
.setIsKernel(false);
164 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelStub
);
166 fFacility
.executeCommand(session
, "enableChannelOnSession");
168 // Verify that Kernel domain was created
169 ITraceControlComponent
[] domains
= session
.getChildren();
170 assertNotNull(domains
);
171 assertEquals(1, domains
.length
);
173 assertEquals("UST global", domains
[0].getName());
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());
183 assertEquals(4, channel
.getNumberOfSubBuffers());
184 assertEquals("mmap()", channel
.getOutputType());
185 assertEquals(true, channel
.isOverwriteMode());
186 assertEquals(200, channel
.getReadTimer());
187 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
188 assertEquals(16384, channel
.getSubBufferSize());
189 assertEquals(100, channel
.getSwitchTimer());
191 // ------------------------------------------------------------------------
192 // Enable channel on domain
193 // ------------------------------------------------------------------------
194 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
195 info
.setName("mychannel2");
196 info
.setOverwriteMode(false);
197 info
.setSubBufferSize(32768);
198 info
.setNumberOfSubBuffers(2);
199 info
.setSwitchTimer(100);
200 info
.setReadTimer(200);
201 channelStub
.setChannelInfo(info
);
203 fFacility
.executeCommand(domains
[0], "enableChannelOnDomain");
205 // Get Kernel domain component instance
206 domains
= session
.getChildren();
207 assertNotNull(domains
);
208 assertEquals(1, domains
.length
);
210 // Verify that channel was created with correct data
211 channels
= domains
[0].getChildren();
212 assertNotNull(channels
);
213 assertEquals(2, channels
.length
);
215 assertTrue(channels
[1] instanceof TraceChannelComponent
);
216 channel
= (TraceChannelComponent
) channels
[1];
217 assertEquals("mychannel2", channel
.getName());
218 assertEquals(2, channel
.getNumberOfSubBuffers());
219 assertEquals("mmap()", channel
.getOutputType());
220 assertEquals(false, channel
.isOverwriteMode());
221 assertEquals(200, channel
.getReadTimer());
222 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
223 assertEquals(32768, channel
.getSubBufferSize());
224 assertEquals(100, channel
.getSwitchTimer());
226 // ------------------------------------------------------------------------
227 // Enable event (tracepoint) on session and default channel
228 // ------------------------------------------------------------------------
229 EnableEventsDialogStub eventsDialogStub
= new EnableEventsDialogStub();
230 eventsDialogStub
.setIsTracePoints(true);
231 List
<String
> events
= new ArrayList
<String
>();
232 events
.add("ust_tests_hello:tptest_sighandler");
233 eventsDialogStub
.setNames(events
);
234 eventsDialogStub
.setIsKernel(false);
235 TraceControlDialogFactory
.getInstance().setEnableEventsDialog(eventsDialogStub
);
237 fFacility
.executeCommand(session
, "enableEventOnSession");
239 // Get Kernel domain component instance
240 domains
= session
.getChildren();
241 assertNotNull(domains
);
242 assertEquals(1, domains
.length
);
244 // Verify that channel was created with correct data
245 channels
= domains
[0].getChildren();
246 assertNotNull(channels
);
247 assertEquals(3, channels
.length
);
249 assertTrue(channels
[2] instanceof TraceChannelComponent
);
250 channel
= (TraceChannelComponent
) channels
[2];
251 assertEquals("channel0", channel
.getName());
252 // No need to check parameters of default channel because that has been done in other tests
254 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
255 assertEquals(1, channel0Events
.length
);
257 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
259 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
260 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
261 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
262 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
263 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
265 // ------------------------------------------------------------------------
266 // Enable event (tracepoint) on domain and default channel
267 // ------------------------------------------------------------------------
269 events
.add("ust_tests_hello:tptest");
270 eventsDialogStub
.setNames(events
);
272 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
274 // Get Kernel domain component instance
275 domains
= session
.getChildren();
276 assertNotNull(domains
);
277 assertEquals(1, domains
.length
);
279 // Verify that channel was created with correct data
280 channels
= domains
[0].getChildren();
281 channel
= (TraceChannelComponent
) channels
[2];
282 // No need to check parameters of default channel because that has been done in other tests
284 channel0Events
= channel
.getChildren();
285 assertEquals(2, channel0Events
.length
);
287 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
289 event
= (TraceEventComponent
) channel0Events
[1];
290 assertEquals("ust_tests_hello:tptest", event
.getName());
291 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
292 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
293 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
295 // ------------------------------------------------------------------------
296 // Enable event (all tracepoints) on specific channel
297 // ------------------------------------------------------------------------
299 eventsDialogStub
.setNames(events
);
300 eventsDialogStub
.setIsAllTracePoints(true);
302 fFacility
.executeCommand(channels
[1], "enableEventOnChannel");
304 // Get Kernel domain component instance
305 domains
= session
.getChildren();
306 assertNotNull(domains
);
307 assertEquals(1, domains
.length
);
309 // Verify that channel was created with correct data
310 channels
= domains
[0].getChildren();
311 channel
= (TraceChannelComponent
) channels
[1];
312 // No need to check parameters of default channel because that has been done in other tests
314 channel
= (TraceChannelComponent
) channels
[1];
316 channel0Events
= channel
.getChildren();
317 assertEquals(1, channel0Events
.length
);
319 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
321 event
= (TraceEventComponent
) channel0Events
[0];
322 assertEquals("*", event
.getName());
323 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
324 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
325 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
327 // ------------------------------------------------------------------------
328 // Enable event (wildcard) on specific channel
329 // ------------------------------------------------------------------------
331 eventsDialogStub
.setIsTracePoints(false);
332 eventsDialogStub
.setIsAllTracePoints(false);
333 eventsDialogStub
.setIsWildcard(true);
334 eventsDialogStub
.setWildcard("ust*");
336 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
338 // Get Kernel domain component instance
339 domains
= session
.getChildren();
340 assertNotNull(domains
);
341 assertEquals(1, domains
.length
);
343 // Verify that channel was created with correct data
344 channels
= domains
[0].getChildren();
345 channel
= (TraceChannelComponent
) channels
[0];
346 // No need to check parameters of default channel because that has been done in other tests
348 channel0Events
= channel
.getChildren();
349 assertEquals(1, channel0Events
.length
);
351 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
353 event
= (TraceEventComponent
) channel0Events
[0];
354 assertEquals("ust*", event
.getName());
355 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
356 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
357 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
359 // ------------------------------------------------------------------------
360 // Enable event (wildcard) on domain
361 // ------------------------------------------------------------------------
363 eventsDialogStub
.setIsTracePoints(false);
364 eventsDialogStub
.setIsAllTracePoints(false);
365 eventsDialogStub
.setIsWildcard(true);
366 eventsDialogStub
.setWildcard("ust*");
368 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
370 // Get Kernel domain component instance
371 domains
= session
.getChildren();
372 assertNotNull(domains
);
373 assertEquals(1, domains
.length
);
375 // Verify that channel was created with correct data
376 channels
= domains
[0].getChildren();
377 channel
= (TraceChannelComponent
) channels
[0];
378 // No need to check parameters of default channel because that has been done in other tests
380 channel0Events
= channel
.getChildren();
381 assertEquals(1, channel0Events
.length
);
383 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
385 event
= (TraceEventComponent
) channel0Events
[0];
386 assertEquals("ust*", event
.getName());
387 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
388 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
389 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
391 // ------------------------------------------------------------------------
392 // Enable event (wildcard) on session
393 // ------------------------------------------------------------------------
395 eventsDialogStub
.setIsTracePoints(false);
396 eventsDialogStub
.setIsAllTracePoints(false);
397 eventsDialogStub
.setIsWildcard(true);
398 eventsDialogStub
.setWildcard("ust*");
400 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
402 // Get Kernel domain component instance
403 domains
= session
.getChildren();
404 assertNotNull(domains
);
405 assertEquals(1, domains
.length
);
407 // Verify that channel was created with correct data
408 channels
= domains
[0].getChildren();
409 channel
= (TraceChannelComponent
) channels
[2];
410 // No need to check parameters of default channel because that has been done in other tests
412 channel0Events
= channel
.getChildren();
413 assertEquals(4, channel0Events
.length
);
415 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
417 event
= (TraceEventComponent
) channel0Events
[0];
418 assertEquals("u*", event
.getName());
419 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
420 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
421 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
423 // ------------------------------------------------------------------------
424 // Enable event (loglevel) on domain
425 // ------------------------------------------------------------------------
427 eventsDialogStub
.setIsWildcard(false);
428 eventsDialogStub
.setIsLogLevel(true);
429 eventsDialogStub
.setLogLevelEventName("myevent1");
430 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL
);
431 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_WARNING
);
433 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
435 // Get Kernel domain component instance
436 domains
= session
.getChildren();
437 assertNotNull(domains
);
438 assertEquals(1, domains
.length
);
440 // Verify that channel was created with correct data
441 channels
= domains
[0].getChildren();
442 channel
= (TraceChannelComponent
) channels
[2];
443 // No need to check parameters of default channel because that has been done in other tests
445 channel0Events
= channel
.getChildren();
446 assertEquals(5, channel0Events
.length
);
448 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
450 event
= (TraceEventComponent
) channel0Events
[0];
451 assertEquals("myevent1", event
.getName());
452 assertEquals(TraceLogLevel
.TRACE_WARNING
, event
.getLogLevel());
453 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
454 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
456 // ------------------------------------------------------------------------
457 // Enable event (loglevel) on session
458 // ------------------------------------------------------------------------
459 eventsDialogStub
.setLogLevelEventName("myevent2");
460 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
461 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
463 fFacility
.executeCommand(session
, "enableEventOnSession");
465 // Get Kernel domain component instance
466 domains
= session
.getChildren();
467 assertNotNull(domains
);
468 assertEquals(1, domains
.length
);
470 // Verify that channel was created with correct data
471 channels
= domains
[0].getChildren();
472 channel
= (TraceChannelComponent
) channels
[2];
473 // No need to check parameters of default channel because that has been done in other tests
475 channel0Events
= channel
.getChildren();
476 assertEquals(6, channel0Events
.length
);
478 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
480 event
= (TraceEventComponent
) channel0Events
[0];
481 assertEquals("myevent2", event
.getName());
482 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
483 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
484 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
486 // ------------------------------------------------------------------------
487 // Enable event (loglevel) on channel
488 // ------------------------------------------------------------------------
489 eventsDialogStub
.setLogLevelEventName("myevent0");
490 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
491 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
493 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
495 // Get Kernel domain component instance
496 domains
= session
.getChildren();
497 assertNotNull(domains
);
498 assertEquals(1, domains
.length
);
500 // Verify that channel was created with correct data
501 channels
= domains
[0].getChildren();
502 channel
= (TraceChannelComponent
) channels
[0];
503 // No need to check parameters of default channel because that has been done in other tests
505 channel0Events
= channel
.getChildren();
506 assertEquals(2, channel0Events
.length
);
508 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
510 event
= (TraceEventComponent
) channel0Events
[0];
511 assertEquals("myevent0", event
.getName());
512 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
513 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
514 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
516 // ------------------------------------------------------------------------
518 // ------------------------------------------------------------------------
519 // Initialize session handling scenario
520 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
522 fFacility
.destroySession(session
);
524 // Verify that no more session components exist
525 assertEquals(0, groups
[1].getChildren().length
);
527 //-------------------------------------------------------------------------
529 //-------------------------------------------------------------------------
530 fFacility
.executeCommand(node
, "disconnect");
531 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
533 //-------------------------------------------------------------------------
535 //-------------------------------------------------------------------------
537 fFacility
.executeCommand(node
, "delete");
539 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);