1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import junit
.framework
.Test
;
20 import junit
.framework
.TestCase
;
21 import junit
.framework
.TestSuite
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateChannelDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.EnableEventsDialogStub
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TargetNodeState
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEnablement
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceSessionState
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ChannelInfo
;
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
.linuxtools
.lttng2
.ui
.tests
.Activator
;
45 import org
.eclipse
.rse
.core
.model
.Host
;
46 import org
.eclipse
.rse
.core
.model
.IHost
;
47 import org
.eclipse
.rse
.internal
.core
.model
.SystemProfile
;
48 import org
.junit
.After
;
49 import org
.junit
.Before
;
52 * The class <code>TraceControlUstSessionTests</code> contains UST session/channel/event
53 * handling test cases.
55 @SuppressWarnings("nls")
56 public class TraceControlUstSessionTests
extends TestCase
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
61 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
62 private static final String SCEN_SCENARIO4_TEST
= "Scenario4";
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
67 private TraceControlTestFacility fFacility
;
68 private TestRemoteSystemProxy fProxy
;
69 private String fTestFile
;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * Returns test setup used when executing test case stand-alone.
77 * @return Test setup class
79 public static Test
suite() {
80 return new ModelImplTestSetup(new TestSuite(TraceControlUstSessionTests
.class));
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * Perform pre-test initialization.
91 * if the initialization fails for some reason
96 public void setUp() throws Exception
{
97 fFacility
= TraceControlTestFacility
.getInstance();
98 fProxy
= new TestRemoteSystemProxy();
99 URL location
= FileLocator
.find(Activator
.getDefault().getBundle(), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
100 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
101 fTestFile
= testfile
.getAbsolutePath();
105 * Perform post-test clean-up.
108 * if the clean-up fails for some reason
113 public void tearDown() throws Exception
{
114 fFacility
.waitForJobs();
118 * Run the TraceControlComponent.
120 public void testTraceSessionTree() throws Exception
{
122 fProxy
.setTestFile(fTestFile
);
123 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
125 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
127 @SuppressWarnings("restriction")
128 IHost host
= new Host(new SystemProfile("myProfile", true));
129 host
.setHostName("127.0.0.1");
131 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
134 fFacility
.waitForJobs();
136 fFacility
.executeCommand(node
, "connect");
138 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
140 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
143 // Get provider groups
144 ITraceControlComponent
[] groups
= node
.getChildren();
145 assertNotNull(groups
);
146 assertEquals(2, groups
.length
);
148 // Initialize dialog implementations for command execution
149 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
150 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
151 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
153 // Initialize session handling scenario
154 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
159 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
161 // Verify that session was created
162 assertNotNull(session
);
163 assertEquals("mysession", session
.getName());
164 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
165 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
167 // Initialize scenario
168 fProxy
.setScenario(SCEN_SCENARIO4_TEST
);
170 // ------------------------------------------------------------------------
171 // Enable default channel on created session above
172 // ------------------------------------------------------------------------
173 CreateChannelDialogStub channelStub
= new CreateChannelDialogStub();
174 channelStub
.setIsKernel(false);
175 TraceControlDialogFactory
.getInstance().setCreateChannelDialog(channelStub
);
177 fFacility
.executeCommand(session
, "createChannelOnSession");
179 // Verify that Kernel domain was created
180 ITraceControlComponent
[] domains
= session
.getChildren();
181 assertNotNull(domains
);
182 assertEquals(1, domains
.length
);
184 assertEquals("UST global", domains
[0].getName());
186 // Verify that channel was created with correct data
187 ITraceControlComponent
[] channels
= domains
[0].getChildren();
188 assertNotNull(channels
);
189 assertEquals(1, channels
.length
);
191 assertTrue(channels
[0] instanceof TraceChannelComponent
);
192 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
193 assertEquals("mychannel", channel
.getName());
194 assertEquals(4, channel
.getNumberOfSubBuffers());
195 assertEquals("mmap()", channel
.getOutputType());
196 assertEquals(true, channel
.isOverwriteMode());
197 assertEquals(200, channel
.getReadTimer());
198 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
199 assertEquals(16384, channel
.getSubBufferSize());
200 assertEquals(100, channel
.getSwitchTimer());
202 // ------------------------------------------------------------------------
203 // Enable channel on domain
204 // ------------------------------------------------------------------------
205 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
206 info
.setName("mychannel2");
207 info
.setOverwriteMode(false);
208 info
.setSubBufferSize(32768);
209 info
.setNumberOfSubBuffers(2);
210 info
.setSwitchTimer(100);
211 info
.setReadTimer(200);
212 channelStub
.setChannelInfo(info
);
214 fFacility
.executeCommand(domains
[0], "createChannelOnDomain");
216 // Get Kernel domain component instance
217 domains
= session
.getChildren();
218 assertNotNull(domains
);
219 assertEquals(1, domains
.length
);
221 // Verify that channel was created with correct data
222 channels
= domains
[0].getChildren();
223 assertNotNull(channels
);
224 assertEquals(2, channels
.length
);
226 assertTrue(channels
[1] instanceof TraceChannelComponent
);
227 channel
= (TraceChannelComponent
) channels
[1];
228 assertEquals("mychannel2", channel
.getName());
229 assertEquals(2, channel
.getNumberOfSubBuffers());
230 assertEquals("mmap()", channel
.getOutputType());
231 assertEquals(false, channel
.isOverwriteMode());
232 assertEquals(200, channel
.getReadTimer());
233 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
234 assertEquals(32768, channel
.getSubBufferSize());
235 assertEquals(100, channel
.getSwitchTimer());
237 // ------------------------------------------------------------------------
238 // Enable event (tracepoint) on session and default channel
239 // ------------------------------------------------------------------------
240 EnableEventsDialogStub eventsDialogStub
= new EnableEventsDialogStub();
241 eventsDialogStub
.setIsTracePoints(true);
242 List
<String
> events
= new ArrayList
<String
>();
243 events
.add("ust_tests_hello:tptest_sighandler");
244 eventsDialogStub
.setNames(events
);
245 eventsDialogStub
.setIsKernel(false);
246 TraceControlDialogFactory
.getInstance().setEnableEventsDialog(eventsDialogStub
);
248 fFacility
.executeCommand(session
, "enableEventOnSession");
250 // Get Kernel domain component instance
251 domains
= session
.getChildren();
252 assertNotNull(domains
);
253 assertEquals(1, domains
.length
);
255 // Verify that channel was created with correct data
256 channels
= domains
[0].getChildren();
257 assertNotNull(channels
);
258 assertEquals(3, channels
.length
);
260 assertTrue(channels
[2] instanceof TraceChannelComponent
);
261 channel
= (TraceChannelComponent
) channels
[2];
262 assertEquals("channel0", channel
.getName());
263 // No need to check parameters of default channel because that has been done in other tests
265 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
266 assertEquals(1, channel0Events
.length
);
268 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
270 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
271 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
272 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
273 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
274 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
276 // ------------------------------------------------------------------------
277 // Enable event (tracepoint) on domain and default channel
278 // ------------------------------------------------------------------------
280 events
.add("ust_tests_hello:tptest");
281 eventsDialogStub
.setNames(events
);
283 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
285 // Get Kernel domain component instance
286 domains
= session
.getChildren();
287 assertNotNull(domains
);
288 assertEquals(1, domains
.length
);
290 // Verify that channel was created with correct data
291 channels
= domains
[0].getChildren();
292 channel
= (TraceChannelComponent
) channels
[2];
293 // No need to check parameters of default channel because that has been done in other tests
295 channel0Events
= channel
.getChildren();
296 assertEquals(2, channel0Events
.length
);
298 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
300 event
= (TraceEventComponent
) channel0Events
[1];
301 assertEquals("ust_tests_hello:tptest", event
.getName());
302 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
303 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
304 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
306 // ------------------------------------------------------------------------
307 // Enable event (all tracepoints) on specific channel
308 // ------------------------------------------------------------------------
310 eventsDialogStub
.setNames(events
);
311 eventsDialogStub
.setIsAllTracePoints(true);
313 fFacility
.executeCommand(channels
[1], "enableEventOnChannel");
315 // Get Kernel domain component instance
316 domains
= session
.getChildren();
317 assertNotNull(domains
);
318 assertEquals(1, domains
.length
);
320 // Verify that channel was created with correct data
321 channels
= domains
[0].getChildren();
322 channel
= (TraceChannelComponent
) channels
[1];
323 // No need to check parameters of default channel because that has been done in other tests
325 channel
= (TraceChannelComponent
) channels
[1];
327 channel0Events
= channel
.getChildren();
328 assertEquals(1, channel0Events
.length
);
330 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
332 event
= (TraceEventComponent
) channel0Events
[0];
333 assertEquals("*", event
.getName());
334 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
335 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
336 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
338 // ------------------------------------------------------------------------
339 // Enable event (wildcard) on specific channel
340 // ------------------------------------------------------------------------
342 eventsDialogStub
.setIsTracePoints(false);
343 eventsDialogStub
.setIsAllTracePoints(false);
344 eventsDialogStub
.setIsWildcard(true);
345 eventsDialogStub
.setWildcard("ust*");
347 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
349 // Get Kernel domain component instance
350 domains
= session
.getChildren();
351 assertNotNull(domains
);
352 assertEquals(1, domains
.length
);
354 // Verify that channel was created with correct data
355 channels
= domains
[0].getChildren();
356 channel
= (TraceChannelComponent
) channels
[0];
357 // No need to check parameters of default channel because that has been done in other tests
359 channel0Events
= channel
.getChildren();
360 assertEquals(1, channel0Events
.length
);
362 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
364 event
= (TraceEventComponent
) channel0Events
[0];
365 assertEquals("ust*", event
.getName());
366 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
367 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
368 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
370 // ------------------------------------------------------------------------
371 // Enable event (wildcard) on domain
372 // ------------------------------------------------------------------------
374 eventsDialogStub
.setIsTracePoints(false);
375 eventsDialogStub
.setIsAllTracePoints(false);
376 eventsDialogStub
.setIsWildcard(true);
377 eventsDialogStub
.setWildcard("ust*");
379 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
381 // Get Kernel domain component instance
382 domains
= session
.getChildren();
383 assertNotNull(domains
);
384 assertEquals(1, domains
.length
);
386 // Verify that channel was created with correct data
387 channels
= domains
[0].getChildren();
388 channel
= (TraceChannelComponent
) channels
[0];
389 // No need to check parameters of default channel because that has been done in other tests
391 channel0Events
= channel
.getChildren();
392 assertEquals(1, channel0Events
.length
);
394 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
396 event
= (TraceEventComponent
) channel0Events
[0];
397 assertEquals("ust*", event
.getName());
398 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
399 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
400 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
402 // ------------------------------------------------------------------------
403 // Enable event (wildcard) on session
404 // ------------------------------------------------------------------------
406 eventsDialogStub
.setIsTracePoints(false);
407 eventsDialogStub
.setIsAllTracePoints(false);
408 eventsDialogStub
.setIsWildcard(true);
409 eventsDialogStub
.setWildcard("ust*");
411 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
413 // Get Kernel domain component instance
414 domains
= session
.getChildren();
415 assertNotNull(domains
);
416 assertEquals(1, domains
.length
);
418 // Verify that channel was created with correct data
419 channels
= domains
[0].getChildren();
420 channel
= (TraceChannelComponent
) channels
[2];
421 // No need to check parameters of default channel because that has been done in other tests
423 channel0Events
= channel
.getChildren();
424 assertEquals(4, channel0Events
.length
);
426 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
428 event
= (TraceEventComponent
) channel0Events
[0];
429 assertEquals("u*", event
.getName());
430 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
431 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
432 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
434 // ------------------------------------------------------------------------
435 // Enable event (loglevel) on domain
436 // ------------------------------------------------------------------------
438 eventsDialogStub
.setIsWildcard(false);
439 eventsDialogStub
.setIsLogLevel(true);
440 eventsDialogStub
.setLogLevelEventName("myevent1");
441 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL
);
442 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_WARNING
);
444 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
446 // Get Kernel domain component instance
447 domains
= session
.getChildren();
448 assertNotNull(domains
);
449 assertEquals(1, domains
.length
);
451 // Verify that channel was created with correct data
452 channels
= domains
[0].getChildren();
453 channel
= (TraceChannelComponent
) channels
[2];
454 // No need to check parameters of default channel because that has been done in other tests
456 channel0Events
= channel
.getChildren();
457 assertEquals(5, channel0Events
.length
);
459 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
461 event
= (TraceEventComponent
) channel0Events
[0];
462 assertEquals("myevent1", event
.getName());
463 assertEquals(TraceLogLevel
.TRACE_WARNING
, event
.getLogLevel());
464 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
465 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
467 // ------------------------------------------------------------------------
468 // Enable event (loglevel) on session
469 // ------------------------------------------------------------------------
470 eventsDialogStub
.setLogLevelEventName("myevent2");
471 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
472 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
474 fFacility
.executeCommand(session
, "enableEventOnSession");
476 // Get Kernel domain component instance
477 domains
= session
.getChildren();
478 assertNotNull(domains
);
479 assertEquals(1, domains
.length
);
481 // Verify that channel was created with correct data
482 channels
= domains
[0].getChildren();
483 channel
= (TraceChannelComponent
) channels
[2];
484 // No need to check parameters of default channel because that has been done in other tests
486 channel0Events
= channel
.getChildren();
487 assertEquals(6, channel0Events
.length
);
489 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
491 event
= (TraceEventComponent
) channel0Events
[0];
492 assertEquals("myevent2", event
.getName());
493 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
494 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
495 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
497 // ------------------------------------------------------------------------
498 // Enable event (loglevel) on channel
499 // ------------------------------------------------------------------------
500 eventsDialogStub
.setLogLevelEventName("myevent0");
501 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
502 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
504 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
506 // Get Kernel domain component instance
507 domains
= session
.getChildren();
508 assertNotNull(domains
);
509 assertEquals(1, domains
.length
);
511 // Verify that channel was created with correct data
512 channels
= domains
[0].getChildren();
513 channel
= (TraceChannelComponent
) channels
[0];
514 // No need to check parameters of default channel because that has been done in other tests
516 channel0Events
= channel
.getChildren();
517 assertEquals(2, channel0Events
.length
);
519 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
521 event
= (TraceEventComponent
) channel0Events
[0];
522 assertEquals("myevent0", event
.getName());
523 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
524 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
525 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
527 // ------------------------------------------------------------------------
529 // ------------------------------------------------------------------------
530 // Initialize session handling scenario
531 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
533 fFacility
.destroySession(session
);
535 // Verify that no more session components exist
536 assertEquals(0, groups
[1].getChildren().length
);
538 //-------------------------------------------------------------------------
540 //-------------------------------------------------------------------------
541 fFacility
.executeCommand(node
, "disconnect");
542 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
544 //-------------------------------------------------------------------------
546 //-------------------------------------------------------------------------
548 fFacility
.executeCommand(node
, "delete");
550 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);