gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlUstSessionTests.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
15
16 import static org.junit.Assert.*;
17
18 import java.io.File;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.List;
22
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;
55
56 /**
57 * The class <code>TraceControlUstSessionTests</code> contains UST
58 * session/channel/event handling test cases.
59 */
60 public class TraceControlUstSessionTests {
61
62 // ------------------------------------------------------------------------
63 // Constants
64 // ------------------------------------------------------------------------
65
66 private static final String TEST_STREAM = "CreateTreeTest.cfg";
67 private static final String SCEN_SCENARIO4_TEST = "Scenario4";
68
69 // ------------------------------------------------------------------------
70 // Test data
71 // ------------------------------------------------------------------------
72
73 private TraceControlTestFacility fFacility;
74 private TestRemoteSystemProxy fProxy;
75 private String fTestFile;
76
77 // ------------------------------------------------------------------------
78 // Housekeeping
79 // ------------------------------------------------------------------------
80
81 /**
82 * Perform pre-test initialization.
83 *
84 * @throws Exception
85 * if the initialization fails for some reason
86 */
87 @Before
88 public void setUp() throws Exception {
89 fFacility = TraceControlTestFacility.getInstance();
90 fFacility.init();
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();
95 }
96
97 /**
98 * Perform post-test clean-up.
99 */
100 @After
101 public void tearDown() {
102 fFacility.waitForJobs();
103 fFacility.dispose();
104 }
105
106 /**
107 * Run the TraceControlComponent.
108 *
109 * @throws Exception
110 * This will fail the test
111 */
112 @Test
113 public void testTraceSessionTree() throws Exception {
114
115 fProxy.setTestFile(fTestFile);
116 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
117
118 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
119
120 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
121 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
122 IHost host = registry.createLocalHost(profile, "myProfile", "user");
123
124 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
125
126 root.addChild(node);
127 fFacility.waitForJobs();
128
129 fFacility.executeCommand(node, "connect");
130 int i = 0;
131 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
132 i++;
133 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
134 }
135
136 // Get provider groups
137 ITraceControlComponent[] groups = node.getChildren();
138 assertNotNull(groups);
139 assertEquals(2, groups.length);
140
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());
145
146 // Initialize session handling scenario
147 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
148
149 // ------------------------------------------------------------------------
150 // Create session
151 // ------------------------------------------------------------------------
152 TraceSessionComponent session = fFacility.createSession(groups[1]);
153
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());
159
160 // Initialize scenario
161 fProxy.setScenario(SCEN_SCENARIO4_TEST);
162
163 // ------------------------------------------------------------------------
164 // Enable default channel on created session above
165 // ------------------------------------------------------------------------
166 EnableChannelDialogStub channelStub = new EnableChannelDialogStub();
167 channelStub.setIsKernel(false);
168 TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelStub);
169
170 fFacility.executeCommand(session, "enableChannelOnSession");
171
172 // Verify that Kernel domain was created
173 ITraceControlComponent[] domains = session.getChildren();
174 assertNotNull(domains);
175 assertEquals(1, domains.length);
176
177 assertEquals("UST global", domains[0].getName());
178 assertEquals("Domain buffer Type", BufferType.BUFFER_TYPE_UNKNOWN, ((TraceDomainComponent)domains[0]).getBufferType());
179
180 // Verify that channel was created with correct data
181 ITraceControlComponent[] channels = domains[0].getChildren();
182 assertNotNull(channels);
183 assertEquals(1, channels.length);
184
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());
196
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);
208
209 fFacility.executeCommand(domains[0], "enableChannelOnDomain");
210
211 // Get Kernel domain component instance
212 domains = session.getChildren();
213 assertNotNull(domains);
214 assertEquals(1, domains.length);
215
216 // Verify that channel was created with correct data
217 channels = domains[0].getChildren();
218 assertNotNull(channels);
219 assertEquals(2, channels.length);
220
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());
232
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);
243
244 fFacility.executeCommand(session, "enableEventOnSession");
245
246 // Get Kernel domain component instance
247 domains = session.getChildren();
248 assertNotNull(domains);
249 assertEquals(1, domains.length);
250
251 // Verify that channel was created with correct data
252 channels = domains[0].getChildren();
253 assertNotNull(channels);
254 assertEquals(3, channels.length);
255
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
260
261 ITraceControlComponent[] channel0Events = channel.getChildren();
262 assertEquals(1, channel0Events.length);
263
264 assertTrue(channel0Events[0] instanceof TraceEventComponent);
265
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());
271
272 // ------------------------------------------------------------------------
273 // Enable event (tracepoint) on domain and default channel
274 // ------------------------------------------------------------------------
275 events.clear();
276 events.add("ust_tests_hello:tptest");
277 eventsDialogStub.setNames(events);
278
279 fFacility.executeCommand(domains[0], "enableEventOnDomain");
280
281 // Get Kernel domain component instance
282 domains = session.getChildren();
283 assertNotNull(domains);
284 assertEquals(1, domains.length);
285
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
290
291 channel0Events = channel.getChildren();
292 assertEquals(2, channel0Events.length);
293
294 assertTrue(channel0Events[1] instanceof TraceEventComponent);
295
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());
301
302 // ------------------------------------------------------------------------
303 // Enable event (all tracepoints) on specific channel
304 // ------------------------------------------------------------------------
305 events.clear();
306 eventsDialogStub.setNames(events);
307 eventsDialogStub.setIsAllTracePoints(true);
308
309 fFacility.executeCommand(channels[1], "enableEventOnChannel");
310
311 // Get Kernel domain component instance
312 domains = session.getChildren();
313 assertNotNull(domains);
314 assertEquals(1, domains.length);
315
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
320
321 channel = (TraceChannelComponent) channels[1];
322
323 channel0Events = channel.getChildren();
324 assertEquals(1, channel0Events.length);
325
326 assertTrue(channel0Events[0] instanceof TraceEventComponent);
327
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());
333
334 // ------------------------------------------------------------------------
335 // Enable event (wildcard) on specific channel
336 // ------------------------------------------------------------------------
337 events.clear();
338 eventsDialogStub.setIsTracePoints(false);
339 eventsDialogStub.setIsAllTracePoints(false);
340 eventsDialogStub.setIsWildcard(true);
341 eventsDialogStub.setWildcard("ust*");
342
343 fFacility.executeCommand(channels[0], "enableEventOnChannel");
344
345 // Get Kernel domain component instance
346 domains = session.getChildren();
347 assertNotNull(domains);
348 assertEquals(1, domains.length);
349
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
354
355 channel0Events = channel.getChildren();
356 assertEquals(1, channel0Events.length);
357
358 assertTrue(channel0Events[0] instanceof TraceEventComponent);
359
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());
365
366 // ------------------------------------------------------------------------
367 // Enable event (wildcard) on domain
368 // ------------------------------------------------------------------------
369 events.clear();
370 eventsDialogStub.setIsTracePoints(false);
371 eventsDialogStub.setIsAllTracePoints(false);
372 eventsDialogStub.setIsWildcard(true);
373 eventsDialogStub.setWildcard("ust*");
374
375 fFacility.executeCommand(domains[0], "enableEventOnDomain");
376
377 // Get Kernel domain component instance
378 domains = session.getChildren();
379 assertNotNull(domains);
380 assertEquals(1, domains.length);
381
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
386
387 channel0Events = channel.getChildren();
388 assertEquals(1, channel0Events.length);
389
390 assertTrue(channel0Events[0] instanceof TraceEventComponent);
391
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());
397
398 // ------------------------------------------------------------------------
399 // Enable event (wildcard) on session
400 // ------------------------------------------------------------------------
401 events.clear();
402 eventsDialogStub.setIsTracePoints(false);
403 eventsDialogStub.setIsAllTracePoints(false);
404 eventsDialogStub.setIsWildcard(true);
405 eventsDialogStub.setWildcard("ust*");
406
407 fFacility.executeCommand(domains[0], "enableEventOnDomain");
408
409 // Get Kernel domain component instance
410 domains = session.getChildren();
411 assertNotNull(domains);
412 assertEquals(1, domains.length);
413
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
418
419 channel0Events = channel.getChildren();
420 assertEquals(4, channel0Events.length);
421
422 assertTrue(channel0Events[0] instanceof TraceEventComponent);
423
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());
429
430 // ------------------------------------------------------------------------
431 // Enable event (loglevel) on domain
432 // ------------------------------------------------------------------------
433 events.clear();
434 eventsDialogStub.setIsWildcard(false);
435 eventsDialogStub.setIsLogLevel(true);
436 eventsDialogStub.setLogLevelEventName("myevent1");
437 eventsDialogStub.setLogLevelType(LogLevelType.LOGLEVEL);
438 eventsDialogStub.setLogLevel(TraceLogLevel.TRACE_WARNING);
439
440 fFacility.executeCommand(domains[0], "enableEventOnDomain");
441
442 // Get Kernel domain component instance
443 domains = session.getChildren();
444 assertNotNull(domains);
445 assertEquals(1, domains.length);
446
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
451
452 channel0Events = channel.getChildren();
453 assertEquals(5, channel0Events.length);
454
455 assertTrue(channel0Events[0] instanceof TraceEventComponent);
456
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());
462
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);
469
470 fFacility.executeCommand(session, "enableEventOnSession");
471
472 // Get Kernel domain component instance
473 domains = session.getChildren();
474 assertNotNull(domains);
475 assertEquals(1, domains.length);
476
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
481
482 channel0Events = channel.getChildren();
483 assertEquals(6, channel0Events.length);
484
485 assertTrue(channel0Events[0] instanceof TraceEventComponent);
486
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());
492
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);
499
500 fFacility.executeCommand(channels[0], "enableEventOnChannel");
501
502 // Get Kernel domain component instance
503 domains = session.getChildren();
504 assertNotNull(domains);
505 assertEquals(1, domains.length);
506
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
511
512 channel0Events = channel.getChildren();
513 assertEquals(2, channel0Events.length);
514
515 assertTrue(channel0Events[0] instanceof TraceEventComponent);
516
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());
522
523 // ------------------------------------------------------------------------
524 // Destroy session
525 // ------------------------------------------------------------------------
526 // Initialize session handling scenario
527 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
528
529 fFacility.destroySession(session);
530
531 // Verify that no more session components exist
532 assertEquals("Session components still exist.", 0, groups[1].getChildren().length);
533
534 //-------------------------------------------------------------------------
535 // Disconnect node
536 //-------------------------------------------------------------------------
537 fFacility.executeCommand(node, "disconnect");
538 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
539
540 //-------------------------------------------------------------------------
541 // Delete node
542 //-------------------------------------------------------------------------
543
544 fFacility.executeCommand(node, "delete");
545
546 assertEquals("Node not deleted.", 0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
547 }
548 }
This page took 0.046327 seconds and 5 git commands to generate.