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