Add some more model test cases for LTTng 2.0 control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / component / TraceControlUstSessionTests.java
CommitLineData
a26d90be
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
13
14import java.io.File;
15import java.net.URL;
16import java.util.ArrayList;
17import java.util.List;
18
19import junit.framework.Test;
20import junit.framework.TestCase;
21import junit.framework.TestSuite;
22
23import org.eclipse.core.runtime.FileLocator;
24import org.eclipse.core.runtime.Path;
25import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateChannelDialogStub;
26import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
27import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
28import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableEventsDialogStub;
29import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
30import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
31import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
32import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
33import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType;
34import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
35import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement;
36import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType;
37import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel;
38import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
39import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ChannelInfo;
40import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
41import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
42import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
43import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
44import org.eclipse.linuxtools.lttng2.ui.tests.Activator;
45import org.eclipse.rse.core.model.Host;
46import org.eclipse.rse.core.model.IHost;
47import org.eclipse.rse.internal.core.model.SystemProfile;
48import org.junit.After;
49import org.junit.Before;
50
51/**
52 * The class <code>TraceControlUstSessionTests</code> contains UST session/channel/event
53 * handling test cases.
54 */
55@SuppressWarnings("nls")
56public class TraceControlUstSessionTests extends TestCase {
57
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61 private static final String TEST_STREAM = "CreateTreeTest.cfg";
62 private static final String SCEN_SCENARIO4_TEST = "Scenario4";
63
64 // ------------------------------------------------------------------------
65 // Test data
66 // ------------------------------------------------------------------------
67 private TraceControlTestFacility fFacility;
68 private TestRemoteSystemProxy fProxy;
69 private String fTestFile;
70
71 // ------------------------------------------------------------------------
72 // Static methods
73 // ------------------------------------------------------------------------
74
75 /**
76 * Returns test setup used when executing test case stand-alone.
77 * @return Test setup class
78 */
79 public static Test suite() {
80 return new ModelImplTestSetup(new TestSuite(TraceControlUstSessionTests.class));
81 }
82
83 // ------------------------------------------------------------------------
84 // Housekeeping
85 // ------------------------------------------------------------------------
86
87 /**
88 * Perform pre-test initialization.
89 *
90 * @throws Exception
91 * if the initialization fails for some reason
92 *
93 */
94 @Override
95 @Before
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();
102 }
103
104 /**
105 * Perform post-test clean-up.
106 *
107 * @throws Exception
108 * if the clean-up fails for some reason
109 *
110 */
111 @Override
112 @After
113 public void tearDown() throws Exception {
114 }
115
116 /**
117 * Run the TraceControlComponent.
118 */
119 public void testTraceSessionTree() throws Exception {
120
121 fProxy.setTestFile(fTestFile);
122 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
123
124 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
125
126 @SuppressWarnings("restriction")
127 IHost host = new Host(new SystemProfile("myProfile", true));
128 host.setHostName("127.0.0.1");
129
130 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
131
132 root.addChild(node);
133 node.connect();
134
135 fFacility.waitForJobs();
136
137 // Verify that node is connected
138 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
139
140 // Get provider groups
141 ITraceControlComponent[] groups = node.getChildren();
142 assertNotNull(groups);
143 assertEquals(2, groups.length);
144
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());
149
150 // Initialize session handling scenario
151 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
152
153 // ------------------------------------------------------------------------
154 // Create session
155 // ------------------------------------------------------------------------
156 TraceSessionComponent session = fFacility.createSession(groups[1]);
157
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());
163
164 // Initialize scenario
165 fProxy.setScenario(SCEN_SCENARIO4_TEST);
166
167 // ------------------------------------------------------------------------
168 // Enable default channel on created session above
169 // ------------------------------------------------------------------------
170 CreateChannelDialogStub channelStub = new CreateChannelDialogStub();
171 channelStub.setIsKernel(false);
172 TraceControlDialogFactory.getInstance().setCreateChannelDialog(channelStub);
173
174 fFacility.executeCommand(session, "createChannelOnSession");
175
176 // Verify that Kernel domain was created
177 ITraceControlComponent[] domains = session.getChildren();
178 assertNotNull(domains);
179 assertEquals(1, domains.length);
180
181 assertEquals("UST global", domains[0].getName());
182
183 // Verify that channel was created with correct data
184 ITraceControlComponent[] channels = domains[0].getChildren();
185 assertNotNull(channels);
186 assertEquals(1, channels.length);
187
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());
198
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);
210
211 fFacility.executeCommand(domains[0], "createChannelOnDomain");
212
213 // Get Kernel domain component instance
214 domains = session.getChildren();
215 assertNotNull(domains);
216 assertEquals(1, domains.length);
217
218 // Verify that channel was created with correct data
219 channels = domains[0].getChildren();
220 assertNotNull(channels);
221 assertEquals(2, channels.length);
222
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());
233
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);
244
245 fFacility.executeCommand(session, "enableEventOnSession");
246
247 // Get Kernel domain component instance
248 domains = session.getChildren();
249 assertNotNull(domains);
250 assertEquals(1, domains.length);
251
252 // Verify that channel was created with correct data
253 channels = domains[0].getChildren();
254 assertNotNull(channels);
255 assertEquals(3, channels.length);
256
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
261
262 ITraceControlComponent[] channel0Events = channel.getChildren();
263 assertEquals(1, channel0Events.length);
264
265 assertTrue(channel0Events[0] instanceof TraceEventComponent);
266
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());
272
273 // ------------------------------------------------------------------------
274 // Enable event (tracepoint) on domain and default channel
275 // ------------------------------------------------------------------------
276 events.clear();
277 events.add("ust_tests_hello:tptest");
278 eventsDialogStub.setNames(events);
279
280 fFacility.executeCommand(domains[0], "enableEventOnDomain");
281
282 // Get Kernel domain component instance
283 domains = session.getChildren();
284 assertNotNull(domains);
285 assertEquals(1, domains.length);
286
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
291
292 channel0Events = channel.getChildren();
293 assertEquals(2, channel0Events.length);
294
295 assertTrue(channel0Events[1] instanceof TraceEventComponent);
296
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());
302
303 // ------------------------------------------------------------------------
304 // Enable event (all tracepoints) on specific channel
305 // ------------------------------------------------------------------------
306 events.clear();
307 eventsDialogStub.setNames(events);
308 eventsDialogStub.setIsAllTracePoints(true);
309
310 fFacility.executeCommand(channels[1], "enableEventOnChannel");
311
312 // Get Kernel domain component instance
313 domains = session.getChildren();
314 assertNotNull(domains);
315 assertEquals(1, domains.length);
316
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
321
322 channel = (TraceChannelComponent) channels[1];
323
324 channel0Events = channel.getChildren();
325 assertEquals(1, channel0Events.length);
326
327 assertTrue(channel0Events[0] instanceof TraceEventComponent);
328
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());
334
335 // ------------------------------------------------------------------------
336 // Enable event (wildcard) on specific channel
337 // ------------------------------------------------------------------------
338 events.clear();
339 eventsDialogStub.setIsTracePoints(false);
340 eventsDialogStub.setIsAllTracePoints(false);
341 eventsDialogStub.setIsWildcard(true);
342 eventsDialogStub.setWildcard("ust*");
343
344 fFacility.executeCommand(channels[0], "enableEventOnChannel");
345
346 // Get Kernel domain component instance
347 domains = session.getChildren();
348 assertNotNull(domains);
349 assertEquals(1, domains.length);
350
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
355
356 channel0Events = channel.getChildren();
357 assertEquals(1, channel0Events.length);
358
359 assertTrue(channel0Events[0] instanceof TraceEventComponent);
360
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());
366
367 // ------------------------------------------------------------------------
368 // Enable event (wildcard) on domain
369 // ------------------------------------------------------------------------
370 events.clear();
371 eventsDialogStub.setIsTracePoints(false);
372 eventsDialogStub.setIsAllTracePoints(false);
373 eventsDialogStub.setIsWildcard(true);
374 eventsDialogStub.setWildcard("ust*");
375
376 fFacility.executeCommand(domains[0], "enableEventOnDomain");
377
378 // Get Kernel domain component instance
379 domains = session.getChildren();
380 assertNotNull(domains);
381 assertEquals(1, domains.length);
382
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
387
388 channel0Events = channel.getChildren();
389 assertEquals(1, channel0Events.length);
390
391 assertTrue(channel0Events[0] instanceof TraceEventComponent);
392
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());
398
399 // ------------------------------------------------------------------------
400 // Enable event (wildcard) on session
401 // ------------------------------------------------------------------------
402 events.clear();
403 eventsDialogStub.setIsTracePoints(false);
404 eventsDialogStub.setIsAllTracePoints(false);
405 eventsDialogStub.setIsWildcard(true);
406 eventsDialogStub.setWildcard("ust*");
407
408 fFacility.executeCommand(domains[0], "enableEventOnDomain");
409
410 // Get Kernel domain component instance
411 domains = session.getChildren();
412 assertNotNull(domains);
413 assertEquals(1, domains.length);
414
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
419
420 channel0Events = channel.getChildren();
421 assertEquals(4, channel0Events.length);
422
423 assertTrue(channel0Events[0] instanceof TraceEventComponent);
424
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());
430
431 // ------------------------------------------------------------------------
432 // Enable event (loglevel) on domain
433 // ------------------------------------------------------------------------
434 events.clear();
435 eventsDialogStub.setIsWildcard(false);
436 eventsDialogStub.setIsLogLevel(true);
437 eventsDialogStub.setLogLevelEventName("myevent1");
438 eventsDialogStub.setLogLevelType(LogLevelType.LOGLEVEL);
439 eventsDialogStub.setLogLevel(TraceLogLevel.TRACE_WARNING);
440
441 fFacility.executeCommand(domains[0], "enableEventOnDomain");
442
443 // Get Kernel domain component instance
444 domains = session.getChildren();
445 assertNotNull(domains);
446 assertEquals(1, domains.length);
447
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
452
453 channel0Events = channel.getChildren();
454 assertEquals(5, channel0Events.length);
455
456 assertTrue(channel0Events[0] instanceof TraceEventComponent);
457
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());
463
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);
470
471 fFacility.executeCommand(session, "enableEventOnSession");
472
473 // Get Kernel domain component instance
474 domains = session.getChildren();
475 assertNotNull(domains);
476 assertEquals(1, domains.length);
477
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
482
483 channel0Events = channel.getChildren();
484 assertEquals(6, channel0Events.length);
485
486 assertTrue(channel0Events[0] instanceof TraceEventComponent);
487
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());
493
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);
500
501 fFacility.executeCommand(channels[0], "enableEventOnChannel");
502
503 // Get Kernel domain component instance
504 domains = session.getChildren();
505 assertNotNull(domains);
506 assertEquals(1, domains.length);
507
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
512
513 channel0Events = channel.getChildren();
514 assertEquals(2, channel0Events.length);
515
516 assertTrue(channel0Events[0] instanceof TraceEventComponent);
517
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());
523
524 // ------------------------------------------------------------------------
525 // Destroy session
526 // ------------------------------------------------------------------------
527 // Initialize session handling scenario
528 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
529
530 fFacility.destroySession(session);
531
532 // Verify that no more session components exist
533 assertEquals(0, groups[1].getChildren().length);
534
535 //-------------------------------------------------------------------------
536 // Disconnect node
537 //-------------------------------------------------------------------------
538 fFacility.executeCommand(node, "disconnect");
539 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
540
541 //-------------------------------------------------------------------------
542 // Delete node
543 //-------------------------------------------------------------------------
544
545 fFacility.executeCommand(node, "delete");
546
547 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
548 }
549}
This page took 0.046338 seconds and 5 git commands to generate.