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
{
117 * Run the TraceControlComponent.
119 public void testTraceSessionTree() throws Exception
{
121 fProxy
.setTestFile(fTestFile
);
122 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
124 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
126 @SuppressWarnings("restriction")
127 IHost host
= new Host(new SystemProfile("myProfile", true));
128 host
.setHostName("127.0.0.1");
130 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
135 fFacility
.waitForJobs();
137 // Verify that node is connected
138 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
140 // Get provider groups
141 ITraceControlComponent
[] groups
= node
.getChildren();
142 assertNotNull(groups
);
143 assertEquals(2, groups
.length
);
145 // Initialize dialog implementations for command execution
146 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
147 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
148 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
150 // Initialize session handling scenario
151 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
156 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
158 // Verify that session was created
159 assertNotNull(session
);
160 assertEquals("mysession", session
.getName());
161 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
162 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
164 // Initialize scenario
165 fProxy
.setScenario(SCEN_SCENARIO4_TEST
);
167 // ------------------------------------------------------------------------
168 // Enable default channel on created session above
169 // ------------------------------------------------------------------------
170 CreateChannelDialogStub channelStub
= new CreateChannelDialogStub();
171 channelStub
.setIsKernel(false);
172 TraceControlDialogFactory
.getInstance().setCreateChannelDialog(channelStub
);
174 fFacility
.executeCommand(session
, "createChannelOnSession");
176 // Verify that Kernel domain was created
177 ITraceControlComponent
[] domains
= session
.getChildren();
178 assertNotNull(domains
);
179 assertEquals(1, domains
.length
);
181 assertEquals("UST global", domains
[0].getName());
183 // Verify that channel was created with correct data
184 ITraceControlComponent
[] channels
= domains
[0].getChildren();
185 assertNotNull(channels
);
186 assertEquals(1, channels
.length
);
188 assertTrue(channels
[0] instanceof TraceChannelComponent
);
189 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
190 assertEquals("mychannel", channel
.getName());
191 assertEquals(4, channel
.getNumberOfSubBuffers());
192 assertEquals("mmap()", channel
.getOutputType());
193 assertEquals(true, channel
.isOverwriteMode());
194 assertEquals(200, channel
.getReadTimer());
195 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
196 assertEquals(16384, channel
.getSubBufferSize());
197 assertEquals(100, channel
.getSwitchTimer());
199 // ------------------------------------------------------------------------
200 // Enable channel on domain
201 // ------------------------------------------------------------------------
202 ChannelInfo info
= (ChannelInfo
)channelStub
.getChannelInfo();
203 info
.setName("mychannel2");
204 info
.setOverwriteMode(false);
205 info
.setSubBufferSize(32768);
206 info
.setNumberOfSubBuffers(2);
207 info
.setSwitchTimer(100);
208 info
.setReadTimer(200);
209 channelStub
.setChannelInfo(info
);
211 fFacility
.executeCommand(domains
[0], "createChannelOnDomain");
213 // Get Kernel domain component instance
214 domains
= session
.getChildren();
215 assertNotNull(domains
);
216 assertEquals(1, domains
.length
);
218 // Verify that channel was created with correct data
219 channels
= domains
[0].getChildren();
220 assertNotNull(channels
);
221 assertEquals(2, channels
.length
);
223 assertTrue(channels
[1] instanceof TraceChannelComponent
);
224 channel
= (TraceChannelComponent
) channels
[1];
225 assertEquals("mychannel2", channel
.getName());
226 assertEquals(2, channel
.getNumberOfSubBuffers());
227 assertEquals("mmap()", channel
.getOutputType());
228 assertEquals(false, channel
.isOverwriteMode());
229 assertEquals(200, channel
.getReadTimer());
230 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
231 assertEquals(32768, channel
.getSubBufferSize());
232 assertEquals(100, channel
.getSwitchTimer());
234 // ------------------------------------------------------------------------
235 // Enable event (tracepoint) on session and default channel
236 // ------------------------------------------------------------------------
237 EnableEventsDialogStub eventsDialogStub
= new EnableEventsDialogStub();
238 eventsDialogStub
.setIsTracePoints(true);
239 List
<String
> events
= new ArrayList
<String
>();
240 events
.add("ust_tests_hello:tptest_sighandler");
241 eventsDialogStub
.setNames(events
);
242 eventsDialogStub
.setIsKernel(false);
243 TraceControlDialogFactory
.getInstance().setEnableEventsDialog(eventsDialogStub
);
245 fFacility
.executeCommand(session
, "enableEventOnSession");
247 // Get Kernel domain component instance
248 domains
= session
.getChildren();
249 assertNotNull(domains
);
250 assertEquals(1, domains
.length
);
252 // Verify that channel was created with correct data
253 channels
= domains
[0].getChildren();
254 assertNotNull(channels
);
255 assertEquals(3, channels
.length
);
257 assertTrue(channels
[2] instanceof TraceChannelComponent
);
258 channel
= (TraceChannelComponent
) channels
[2];
259 assertEquals("channel0", channel
.getName());
260 // No need to check parameters of default channel because that has been done in other tests
262 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
263 assertEquals(1, channel0Events
.length
);
265 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
267 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
268 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
269 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
270 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
271 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
273 // ------------------------------------------------------------------------
274 // Enable event (tracepoint) on domain and default channel
275 // ------------------------------------------------------------------------
277 events
.add("ust_tests_hello:tptest");
278 eventsDialogStub
.setNames(events
);
280 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
282 // Get Kernel domain component instance
283 domains
= session
.getChildren();
284 assertNotNull(domains
);
285 assertEquals(1, domains
.length
);
287 // Verify that channel was created with correct data
288 channels
= domains
[0].getChildren();
289 channel
= (TraceChannelComponent
) channels
[2];
290 // No need to check parameters of default channel because that has been done in other tests
292 channel0Events
= channel
.getChildren();
293 assertEquals(2, channel0Events
.length
);
295 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
297 event
= (TraceEventComponent
) channel0Events
[1];
298 assertEquals("ust_tests_hello:tptest", event
.getName());
299 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel()); // TODO
300 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
301 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
303 // ------------------------------------------------------------------------
304 // Enable event (all tracepoints) on specific channel
305 // ------------------------------------------------------------------------
307 eventsDialogStub
.setNames(events
);
308 eventsDialogStub
.setIsAllTracePoints(true);
310 fFacility
.executeCommand(channels
[1], "enableEventOnChannel");
312 // Get Kernel domain component instance
313 domains
= session
.getChildren();
314 assertNotNull(domains
);
315 assertEquals(1, domains
.length
);
317 // Verify that channel was created with correct data
318 channels
= domains
[0].getChildren();
319 channel
= (TraceChannelComponent
) channels
[1];
320 // No need to check parameters of default channel because that has been done in other tests
322 channel
= (TraceChannelComponent
) channels
[1];
324 channel0Events
= channel
.getChildren();
325 assertEquals(1, channel0Events
.length
);
327 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
329 event
= (TraceEventComponent
) channel0Events
[0];
330 assertEquals("*", event
.getName());
331 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
332 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
333 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
335 // ------------------------------------------------------------------------
336 // Enable event (wildcard) on specific channel
337 // ------------------------------------------------------------------------
339 eventsDialogStub
.setIsTracePoints(false);
340 eventsDialogStub
.setIsAllTracePoints(false);
341 eventsDialogStub
.setIsWildcard(true);
342 eventsDialogStub
.setWildcard("ust*");
344 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
346 // Get Kernel domain component instance
347 domains
= session
.getChildren();
348 assertNotNull(domains
);
349 assertEquals(1, domains
.length
);
351 // Verify that channel was created with correct data
352 channels
= domains
[0].getChildren();
353 channel
= (TraceChannelComponent
) channels
[0];
354 // No need to check parameters of default channel because that has been done in other tests
356 channel0Events
= channel
.getChildren();
357 assertEquals(1, channel0Events
.length
);
359 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
361 event
= (TraceEventComponent
) channel0Events
[0];
362 assertEquals("ust*", event
.getName());
363 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
364 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
365 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
367 // ------------------------------------------------------------------------
368 // Enable event (wildcard) on domain
369 // ------------------------------------------------------------------------
371 eventsDialogStub
.setIsTracePoints(false);
372 eventsDialogStub
.setIsAllTracePoints(false);
373 eventsDialogStub
.setIsWildcard(true);
374 eventsDialogStub
.setWildcard("ust*");
376 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
378 // Get Kernel domain component instance
379 domains
= session
.getChildren();
380 assertNotNull(domains
);
381 assertEquals(1, domains
.length
);
383 // Verify that channel was created with correct data
384 channels
= domains
[0].getChildren();
385 channel
= (TraceChannelComponent
) channels
[0];
386 // No need to check parameters of default channel because that has been done in other tests
388 channel0Events
= channel
.getChildren();
389 assertEquals(1, channel0Events
.length
);
391 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
393 event
= (TraceEventComponent
) channel0Events
[0];
394 assertEquals("ust*", event
.getName());
395 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
396 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
397 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
399 // ------------------------------------------------------------------------
400 // Enable event (wildcard) on session
401 // ------------------------------------------------------------------------
403 eventsDialogStub
.setIsTracePoints(false);
404 eventsDialogStub
.setIsAllTracePoints(false);
405 eventsDialogStub
.setIsWildcard(true);
406 eventsDialogStub
.setWildcard("ust*");
408 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
410 // Get Kernel domain component instance
411 domains
= session
.getChildren();
412 assertNotNull(domains
);
413 assertEquals(1, domains
.length
);
415 // Verify that channel was created with correct data
416 channels
= domains
[0].getChildren();
417 channel
= (TraceChannelComponent
) channels
[2];
418 // No need to check parameters of default channel because that has been done in other tests
420 channel0Events
= channel
.getChildren();
421 assertEquals(4, channel0Events
.length
);
423 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
425 event
= (TraceEventComponent
) channel0Events
[0];
426 assertEquals("u*", event
.getName());
427 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
428 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
429 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
431 // ------------------------------------------------------------------------
432 // Enable event (loglevel) on domain
433 // ------------------------------------------------------------------------
435 eventsDialogStub
.setIsWildcard(false);
436 eventsDialogStub
.setIsLogLevel(true);
437 eventsDialogStub
.setLogLevelEventName("myevent1");
438 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL
);
439 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_WARNING
);
441 fFacility
.executeCommand(domains
[0], "enableEventOnDomain");
443 // Get Kernel domain component instance
444 domains
= session
.getChildren();
445 assertNotNull(domains
);
446 assertEquals(1, domains
.length
);
448 // Verify that channel was created with correct data
449 channels
= domains
[0].getChildren();
450 channel
= (TraceChannelComponent
) channels
[2];
451 // No need to check parameters of default channel because that has been done in other tests
453 channel0Events
= channel
.getChildren();
454 assertEquals(5, channel0Events
.length
);
456 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
458 event
= (TraceEventComponent
) channel0Events
[0];
459 assertEquals("myevent1", event
.getName());
460 assertEquals(TraceLogLevel
.TRACE_WARNING
, event
.getLogLevel());
461 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
462 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
464 // ------------------------------------------------------------------------
465 // Enable event (loglevel) on session
466 // ------------------------------------------------------------------------
467 eventsDialogStub
.setLogLevelEventName("myevent2");
468 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
469 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
471 fFacility
.executeCommand(session
, "enableEventOnSession");
473 // Get Kernel domain component instance
474 domains
= session
.getChildren();
475 assertNotNull(domains
);
476 assertEquals(1, domains
.length
);
478 // Verify that channel was created with correct data
479 channels
= domains
[0].getChildren();
480 channel
= (TraceChannelComponent
) channels
[2];
481 // No need to check parameters of default channel because that has been done in other tests
483 channel0Events
= channel
.getChildren();
484 assertEquals(6, channel0Events
.length
);
486 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
488 event
= (TraceEventComponent
) channel0Events
[0];
489 assertEquals("myevent2", event
.getName());
490 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
491 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
492 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
494 // ------------------------------------------------------------------------
495 // Enable event (loglevel) on channel
496 // ------------------------------------------------------------------------
497 eventsDialogStub
.setLogLevelEventName("myevent0");
498 eventsDialogStub
.setLogLevelType(LogLevelType
.LOGLEVEL_ONLY
);
499 eventsDialogStub
.setLogLevel(TraceLogLevel
.TRACE_DEBUG_FUNCTION
);
501 fFacility
.executeCommand(channels
[0], "enableEventOnChannel");
503 // Get Kernel domain component instance
504 domains
= session
.getChildren();
505 assertNotNull(domains
);
506 assertEquals(1, domains
.length
);
508 // Verify that channel was created with correct data
509 channels
= domains
[0].getChildren();
510 channel
= (TraceChannelComponent
) channels
[0];
511 // No need to check parameters of default channel because that has been done in other tests
513 channel0Events
= channel
.getChildren();
514 assertEquals(2, channel0Events
.length
);
516 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
518 event
= (TraceEventComponent
) channel0Events
[0];
519 assertEquals("myevent0", event
.getName());
520 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, event
.getLogLevel());
521 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
522 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
524 // ------------------------------------------------------------------------
526 // ------------------------------------------------------------------------
527 // Initialize session handling scenario
528 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
530 fFacility
.destroySession(session
);
532 // Verify that no more session components exist
533 assertEquals(0, groups
[1].getChildren().length
);
535 //-------------------------------------------------------------------------
537 //-------------------------------------------------------------------------
538 fFacility
.executeCommand(node
, "disconnect");
539 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
541 //-------------------------------------------------------------------------
543 //-------------------------------------------------------------------------
545 fFacility
.executeCommand(node
, "delete");
547 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);