lttng: update enable channel for UST buffer type
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / component / TraceControlUstSessionTests.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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.ui.tests.control.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.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.BufferType;
32 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
33 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
34 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
35 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableChannelDialogStub;
36 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableEventsDialogStub;
37 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
38 import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
39 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
40 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
41 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
42 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
43 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
44 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
45 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
46 import org.eclipse.rse.core.RSECorePlugin;
47 import org.eclipse.rse.core.model.IHost;
48 import org.eclipse.rse.core.model.ISystemProfile;
49 import org.eclipse.rse.core.model.ISystemRegistry;
50 import org.junit.After;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.osgi.framework.FrameworkUtil;
54
55 /**
56 * The class <code>TraceControlUstSessionTests</code> contains UST
57 * session/channel/event handling test cases.
58 */
59 public class TraceControlUstSessionTests {
60
61 // ------------------------------------------------------------------------
62 // Constants
63 // ------------------------------------------------------------------------
64
65 private static final String TEST_STREAM = "CreateTreeTest.cfg";
66 private static final String SCEN_SCENARIO4_TEST = "Scenario4";
67
68 // ------------------------------------------------------------------------
69 // Test data
70 // ------------------------------------------------------------------------
71
72 private TraceControlTestFacility fFacility;
73 private TestRemoteSystemProxy fProxy;
74 private String fTestFile;
75
76 // ------------------------------------------------------------------------
77 // Housekeeping
78 // ------------------------------------------------------------------------
79
80 /**
81 * Perform pre-test initialization.
82 *
83 * @throws Exception
84 * if the initialization fails for some reason
85 */
86 @Before
87 public void setUp() throws Exception {
88 fFacility = TraceControlTestFacility.getInstance();
89 fFacility.init();
90 fProxy = new TestRemoteSystemProxy();
91 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
92 File testfile = new File(FileLocator.toFileURL(location).toURI());
93 fTestFile = testfile.getAbsolutePath();
94 }
95
96 /**
97 * Perform post-test clean-up.
98 */
99 @After
100 public void tearDown() {
101 fFacility.waitForJobs();
102 fFacility.dispose();
103 }
104
105 /**
106 * Run the TraceControlComponent.
107 *
108 * @throws Exception
109 * This will fail the test
110 */
111 @Test
112 public void testTraceSessionTree() throws Exception {
113
114 fProxy.setTestFile(fTestFile);
115 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
116
117 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
118
119 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
120 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
121 IHost host = registry.createLocalHost(profile, "myProfile", "user");
122
123 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
124
125 root.addChild(node);
126 fFacility.waitForJobs();
127
128 fFacility.executeCommand(node, "connect");
129 int i = 0;
130 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
131 i++;
132 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
133 }
134
135 // Get provider groups
136 ITraceControlComponent[] groups = node.getChildren();
137 assertNotNull(groups);
138 assertEquals(2, groups.length);
139
140 // Initialize dialog implementations for command execution
141 TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
142 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
143 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
144
145 // Initialize session handling scenario
146 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
147
148 // ------------------------------------------------------------------------
149 // Create session
150 // ------------------------------------------------------------------------
151 TraceSessionComponent session = fFacility.createSession(groups[1]);
152
153 // Verify that session was created
154 assertNotNull(session);
155 assertEquals("mysession", session.getName());
156 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session.getSessionPath());
157 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
158
159 // Initialize scenario
160 fProxy.setScenario(SCEN_SCENARIO4_TEST);
161
162 // ------------------------------------------------------------------------
163 // Enable default channel on created session above
164 // ------------------------------------------------------------------------
165 EnableChannelDialogStub channelStub = new EnableChannelDialogStub();
166 channelStub.setIsKernel(false);
167 TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelStub);
168
169 fFacility.executeCommand(session, "enableChannelOnSession");
170
171 // Verify that Kernel domain was created
172 ITraceControlComponent[] domains = session.getChildren();
173 assertNotNull(domains);
174 assertEquals(1, domains.length);
175
176 assertEquals("UST global", domains[0].getName());
177 assertEquals("Domain buffer Type", BufferType.BUFFER_TYPE_UNKNOWN, ((TraceDomainComponent)domains[0]).getBufferType());
178
179 // Verify that channel was created with correct data
180 ITraceControlComponent[] channels = domains[0].getChildren();
181 assertNotNull(channels);
182 assertEquals(1, channels.length);
183
184 assertTrue(channels[0] instanceof TraceChannelComponent);
185 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
186 assertEquals("mychannel", channel.getName());
187 assertEquals(4, channel.getNumberOfSubBuffers());
188 assertEquals("mmap()", channel.getOutputType());
189 assertEquals(true, channel.isOverwriteMode());
190 assertEquals(200, channel.getReadTimer());
191 assertEquals(TraceEnablement.ENABLED, channel.getState());
192 assertEquals(16384, channel.getSubBufferSize());
193 assertEquals(100, channel.getSwitchTimer());
194
195 // ------------------------------------------------------------------------
196 // Enable channel on domain
197 // ------------------------------------------------------------------------
198 ChannelInfo info = (ChannelInfo)channelStub.getChannelInfo();
199 info.setName("mychannel2");
200 info.setOverwriteMode(false);
201 info.setSubBufferSize(32768);
202 info.setNumberOfSubBuffers(2);
203 info.setSwitchTimer(100);
204 info.setReadTimer(200);
205 channelStub.setChannelInfo(info);
206
207 fFacility.executeCommand(domains[0], "enableChannelOnDomain");
208
209 // Get Kernel domain component instance
210 domains = session.getChildren();
211 assertNotNull(domains);
212 assertEquals(1, domains.length);
213
214 // Verify that channel was created with correct data
215 channels = domains[0].getChildren();
216 assertNotNull(channels);
217 assertEquals(2, channels.length);
218
219 assertTrue(channels[1] instanceof TraceChannelComponent);
220 channel = (TraceChannelComponent) channels[1];
221 assertEquals("mychannel2", channel.getName());
222 assertEquals(2, channel.getNumberOfSubBuffers());
223 assertEquals("mmap()", channel.getOutputType());
224 assertEquals(false, channel.isOverwriteMode());
225 assertEquals(200, channel.getReadTimer());
226 assertEquals(TraceEnablement.ENABLED, channel.getState());
227 assertEquals(32768, channel.getSubBufferSize());
228 assertEquals(100, channel.getSwitchTimer());
229
230 // ------------------------------------------------------------------------
231 // Enable event (tracepoint) on session and default channel
232 // ------------------------------------------------------------------------
233 EnableEventsDialogStub eventsDialogStub = new EnableEventsDialogStub();
234 eventsDialogStub.setIsTracePoints(true);
235 List<String> events = new ArrayList<String>();
236 events.add("ust_tests_hello:tptest_sighandler");
237 eventsDialogStub.setNames(events);
238 eventsDialogStub.setIsKernel(false);
239 TraceControlDialogFactory.getInstance().setEnableEventsDialog(eventsDialogStub);
240
241 fFacility.executeCommand(session, "enableEventOnSession");
242
243 // Get Kernel domain component instance
244 domains = session.getChildren();
245 assertNotNull(domains);
246 assertEquals(1, domains.length);
247
248 // Verify that channel was created with correct data
249 channels = domains[0].getChildren();
250 assertNotNull(channels);
251 assertEquals(3, channels.length);
252
253 assertTrue(channels[2] instanceof TraceChannelComponent);
254 channel = (TraceChannelComponent) channels[2];
255 assertEquals("channel0", channel.getName());
256 // No need to check parameters of default channel because that has been done in other tests
257
258 ITraceControlComponent[] channel0Events = channel.getChildren();
259 assertEquals(1, channel0Events.length);
260
261 assertTrue(channel0Events[0] instanceof TraceEventComponent);
262
263 TraceEventComponent event = (TraceEventComponent) channel0Events[0];
264 assertEquals("ust_tests_hello:tptest_sighandler", event.getName());
265 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); // TODO
266 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
267 assertEquals(TraceEnablement.ENABLED, event.getState());
268
269 // ------------------------------------------------------------------------
270 // Enable event (tracepoint) on domain and default channel
271 // ------------------------------------------------------------------------
272 events.clear();
273 events.add("ust_tests_hello:tptest");
274 eventsDialogStub.setNames(events);
275
276 fFacility.executeCommand(domains[0], "enableEventOnDomain");
277
278 // Get Kernel domain component instance
279 domains = session.getChildren();
280 assertNotNull(domains);
281 assertEquals(1, domains.length);
282
283 // Verify that channel was created with correct data
284 channels = domains[0].getChildren();
285 channel = (TraceChannelComponent) channels[2];
286 // No need to check parameters of default channel because that has been done in other tests
287
288 channel0Events = channel.getChildren();
289 assertEquals(2, channel0Events.length);
290
291 assertTrue(channel0Events[1] instanceof TraceEventComponent);
292
293 event = (TraceEventComponent) channel0Events[1];
294 assertEquals("ust_tests_hello:tptest", event.getName());
295 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); // TODO
296 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
297 assertEquals(TraceEnablement.ENABLED, event.getState());
298
299 // ------------------------------------------------------------------------
300 // Enable event (all tracepoints) on specific channel
301 // ------------------------------------------------------------------------
302 events.clear();
303 eventsDialogStub.setNames(events);
304 eventsDialogStub.setIsAllTracePoints(true);
305
306 fFacility.executeCommand(channels[1], "enableEventOnChannel");
307
308 // Get Kernel domain component instance
309 domains = session.getChildren();
310 assertNotNull(domains);
311 assertEquals(1, domains.length);
312
313 // Verify that channel was created with correct data
314 channels = domains[0].getChildren();
315 channel = (TraceChannelComponent) channels[1];
316 // No need to check parameters of default channel because that has been done in other tests
317
318 channel = (TraceChannelComponent) channels[1];
319
320 channel0Events = channel.getChildren();
321 assertEquals(1, channel0Events.length);
322
323 assertTrue(channel0Events[0] instanceof TraceEventComponent);
324
325 event = (TraceEventComponent) channel0Events[0];
326 assertEquals("*", event.getName());
327 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
328 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
329 assertEquals(TraceEnablement.ENABLED, event.getState());
330
331 // ------------------------------------------------------------------------
332 // Enable event (wildcard) on specific channel
333 // ------------------------------------------------------------------------
334 events.clear();
335 eventsDialogStub.setIsTracePoints(false);
336 eventsDialogStub.setIsAllTracePoints(false);
337 eventsDialogStub.setIsWildcard(true);
338 eventsDialogStub.setWildcard("ust*");
339
340 fFacility.executeCommand(channels[0], "enableEventOnChannel");
341
342 // Get Kernel domain component instance
343 domains = session.getChildren();
344 assertNotNull(domains);
345 assertEquals(1, domains.length);
346
347 // Verify that channel was created with correct data
348 channels = domains[0].getChildren();
349 channel = (TraceChannelComponent) channels[0];
350 // No need to check parameters of default channel because that has been done in other tests
351
352 channel0Events = channel.getChildren();
353 assertEquals(1, channel0Events.length);
354
355 assertTrue(channel0Events[0] instanceof TraceEventComponent);
356
357 event = (TraceEventComponent) channel0Events[0];
358 assertEquals("ust*", event.getName());
359 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
360 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
361 assertEquals(TraceEnablement.ENABLED, event.getState());
362
363 // ------------------------------------------------------------------------
364 // Enable event (wildcard) on domain
365 // ------------------------------------------------------------------------
366 events.clear();
367 eventsDialogStub.setIsTracePoints(false);
368 eventsDialogStub.setIsAllTracePoints(false);
369 eventsDialogStub.setIsWildcard(true);
370 eventsDialogStub.setWildcard("ust*");
371
372 fFacility.executeCommand(domains[0], "enableEventOnDomain");
373
374 // Get Kernel domain component instance
375 domains = session.getChildren();
376 assertNotNull(domains);
377 assertEquals(1, domains.length);
378
379 // Verify that channel was created with correct data
380 channels = domains[0].getChildren();
381 channel = (TraceChannelComponent) channels[0];
382 // No need to check parameters of default channel because that has been done in other tests
383
384 channel0Events = channel.getChildren();
385 assertEquals(1, channel0Events.length);
386
387 assertTrue(channel0Events[0] instanceof TraceEventComponent);
388
389 event = (TraceEventComponent) channel0Events[0];
390 assertEquals("ust*", event.getName());
391 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
392 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
393 assertEquals(TraceEnablement.ENABLED, event.getState());
394
395 // ------------------------------------------------------------------------
396 // Enable event (wildcard) on session
397 // ------------------------------------------------------------------------
398 events.clear();
399 eventsDialogStub.setIsTracePoints(false);
400 eventsDialogStub.setIsAllTracePoints(false);
401 eventsDialogStub.setIsWildcard(true);
402 eventsDialogStub.setWildcard("ust*");
403
404 fFacility.executeCommand(domains[0], "enableEventOnDomain");
405
406 // Get Kernel domain component instance
407 domains = session.getChildren();
408 assertNotNull(domains);
409 assertEquals(1, domains.length);
410
411 // Verify that channel was created with correct data
412 channels = domains[0].getChildren();
413 channel = (TraceChannelComponent) channels[2];
414 // No need to check parameters of default channel because that has been done in other tests
415
416 channel0Events = channel.getChildren();
417 assertEquals(4, channel0Events.length);
418
419 assertTrue(channel0Events[0] instanceof TraceEventComponent);
420
421 event = (TraceEventComponent) channel0Events[0];
422 assertEquals("u*", event.getName());
423 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
424 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
425 assertEquals(TraceEnablement.ENABLED, event.getState());
426
427 // ------------------------------------------------------------------------
428 // Enable event (loglevel) on domain
429 // ------------------------------------------------------------------------
430 events.clear();
431 eventsDialogStub.setIsWildcard(false);
432 eventsDialogStub.setIsLogLevel(true);
433 eventsDialogStub.setLogLevelEventName("myevent1");
434 eventsDialogStub.setLogLevelType(LogLevelType.LOGLEVEL);
435 eventsDialogStub.setLogLevel(TraceLogLevel.TRACE_WARNING);
436
437 fFacility.executeCommand(domains[0], "enableEventOnDomain");
438
439 // Get Kernel domain component instance
440 domains = session.getChildren();
441 assertNotNull(domains);
442 assertEquals(1, domains.length);
443
444 // Verify that channel was created with correct data
445 channels = domains[0].getChildren();
446 channel = (TraceChannelComponent) channels[2];
447 // No need to check parameters of default channel because that has been done in other tests
448
449 channel0Events = channel.getChildren();
450 assertEquals(5, channel0Events.length);
451
452 assertTrue(channel0Events[0] instanceof TraceEventComponent);
453
454 event = (TraceEventComponent) channel0Events[0];
455 assertEquals("myevent1", event.getName());
456 assertEquals(TraceLogLevel.TRACE_WARNING, event.getLogLevel());
457 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
458 assertEquals(TraceEnablement.ENABLED, event.getState());
459
460 // ------------------------------------------------------------------------
461 // Enable event (loglevel) on session
462 // ------------------------------------------------------------------------
463 eventsDialogStub.setLogLevelEventName("myevent2");
464 eventsDialogStub.setLogLevelType(LogLevelType.LOGLEVEL_ONLY);
465 eventsDialogStub.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION);
466
467 fFacility.executeCommand(session, "enableEventOnSession");
468
469 // Get Kernel domain component instance
470 domains = session.getChildren();
471 assertNotNull(domains);
472 assertEquals(1, domains.length);
473
474 // Verify that channel was created with correct data
475 channels = domains[0].getChildren();
476 channel = (TraceChannelComponent) channels[2];
477 // No need to check parameters of default channel because that has been done in other tests
478
479 channel0Events = channel.getChildren();
480 assertEquals(6, channel0Events.length);
481
482 assertTrue(channel0Events[0] instanceof TraceEventComponent);
483
484 event = (TraceEventComponent) channel0Events[0];
485 assertEquals("myevent2", event.getName());
486 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, event.getLogLevel());
487 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
488 assertEquals(TraceEnablement.ENABLED, event.getState());
489
490 // ------------------------------------------------------------------------
491 // Enable event (loglevel) on channel
492 // ------------------------------------------------------------------------
493 eventsDialogStub.setLogLevelEventName("myevent0");
494 eventsDialogStub.setLogLevelType(LogLevelType.LOGLEVEL_ONLY);
495 eventsDialogStub.setLogLevel(TraceLogLevel.TRACE_DEBUG_FUNCTION);
496
497 fFacility.executeCommand(channels[0], "enableEventOnChannel");
498
499 // Get Kernel domain component instance
500 domains = session.getChildren();
501 assertNotNull(domains);
502 assertEquals(1, domains.length);
503
504 // Verify that channel was created with correct data
505 channels = domains[0].getChildren();
506 channel = (TraceChannelComponent) channels[0];
507 // No need to check parameters of default channel because that has been done in other tests
508
509 channel0Events = channel.getChildren();
510 assertEquals(2, channel0Events.length);
511
512 assertTrue(channel0Events[0] instanceof TraceEventComponent);
513
514 event = (TraceEventComponent) channel0Events[0];
515 assertEquals("myevent0", event.getName());
516 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, event.getLogLevel());
517 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
518 assertEquals(TraceEnablement.ENABLED, event.getState());
519
520 // ------------------------------------------------------------------------
521 // Destroy session
522 // ------------------------------------------------------------------------
523 // Initialize session handling scenario
524 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
525
526 fFacility.destroySession(session);
527
528 // Verify that no more session components exist
529 assertEquals(0, groups[1].getChildren().length);
530
531 //-------------------------------------------------------------------------
532 // Disconnect node
533 //-------------------------------------------------------------------------
534 fFacility.executeCommand(node, "disconnect");
535 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
536
537 //-------------------------------------------------------------------------
538 // Delete node
539 //-------------------------------------------------------------------------
540
541 fFacility.executeCommand(node, "delete");
542
543 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
544 }
545 }
This page took 0.047053 seconds and 5 git commands to generate.