Add support for filter feature of LTTng Tools 2.1
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / service / LTTngControlServiceTest.java
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 **********************************************************************/
12 package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
13
14 import java.io.File;
15 import java.net.URL;
16 import java.util.ArrayList;
17 import java.util.HashSet;
18 import java.util.List;
19 import java.util.Set;
20
21 import junit.framework.TestCase;
22
23 import org.eclipse.core.commands.ExecutionException;
24 import org.eclipse.core.runtime.FileLocator;
25 import org.eclipse.core.runtime.NullProgressMonitor;
26 import org.eclipse.core.runtime.Path;
27 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo;
28 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
29 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
30 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
31 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
32 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
33 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo;
34 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
35 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
36 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
37 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
38 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
39 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
40 import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
41 import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
42 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
43 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService;
44 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
45 import org.osgi.framework.FrameworkUtil;
46 /**
47 * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>.
48 */
49 @SuppressWarnings({"nls", "javadoc"})
50 public class LTTngControlServiceTest extends TestCase {
51
52 private static final String DIRECTORY = "testfiles";
53 private static final String TEST_STREAM = "LTTngServiceTest.cfg";
54
55 private static final String SCEN_LTTNG_NOT_INSTALLED = "LttngNotInstalled";
56 private static final String SCEN_LTTNG_VERSION = "LttngVersion";
57 private static final String SCEN_LTTNG_VERSION_WITH_PROMPT = "LttngVersionWithPrompt";
58 private static final String SCEN_LTTNG_UNSUPPORTED_VERSION = "LttngUnsupportedVersion";
59 private static final String SCEN_LTTNG_NO_VERSION = "LttngNoVersion";
60 private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
61 private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
62 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
63 private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
64 private static final String SCEN_GET_SESSION1 = "GetSession1";
65 private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
66 private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
67 private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
68 private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
69 private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
70 private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
71 private static final String SCEN_CREATE_SESSION1 = "CreateSession1";
72 private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
73 private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
74 private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
75 private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
76 private static final String SCEN_EVENT_HANDLING = "EventHandling";
77 private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
78 private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
79 private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
80
81 // ------------------------------------------------------------------------
82 // Test data
83 // ------------------------------------------------------------------------
84 private CommandShellFactory fShellFactory;
85 private String fTestfile;
86 private LTTngToolsFileShell fShell;
87 private ILttngControlService fService;
88
89
90 // ------------------------------------------------------------------------
91 // Static methods
92 // ------------------------------------------------------------------------
93
94 // ------------------------------------------------------------------------
95 // Housekeeping
96 // ------------------------------------------------------------------------
97 /**
98 * Perform pre-test initialization.
99 *
100 * @throws Exception if the initialization fails for some reason
101 *
102 */
103 @Override
104 public void setUp() throws Exception {
105 super.setUp();
106 fShellFactory = CommandShellFactory.getInstance();
107
108 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
109 File testfile = new File(FileLocator.toFileURL(location).toURI());
110 fTestfile = testfile.getAbsolutePath();
111
112 fShell = fShellFactory.getFileShell();
113 fShell.loadScenarioFile(fTestfile);
114 fService = new LTTngControlService(fShell);
115 }
116
117 /**
118 * Perform post-test clean-up.
119 *
120 * @throws Exception if the clean-up fails for some reason
121 *
122 */
123 @Override
124 public void tearDown() throws Exception {
125 }
126
127 // ------------------------------------------------------------------------
128 // Test Cases
129 // ------------------------------------------------------------------------
130
131 public void testVersion() {
132 try {
133 fShell.setScenario(SCEN_LTTNG_VERSION);
134 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
135 assertNotNull(service);
136 assertEquals("2.1.0", service.getVersion());
137 } catch (ExecutionException e) {
138 fail("Exeption thrown " + e);
139 }
140 }
141
142 public void testVersionWithPrompt() {
143 try {
144 fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT);
145 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
146 assertNotNull(service);
147 assertEquals("2.0.0", service.getVersion());
148 } catch (ExecutionException e) {
149 fail("Exeption thrown " + e);
150 }
151 }
152
153 public void testUnsupportedVersion() {
154 try {
155 fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION);
156 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
157 fail("No exeption thrown");
158 } catch (ExecutionException e) {
159 // success
160 }
161 }
162
163 public void testNoVersion() {
164 try {
165 fShell.setScenario(SCEN_LTTNG_NO_VERSION);
166 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
167 fail("No exeption thrown");
168 } catch (ExecutionException e) {
169 // success
170 }
171 }
172
173 public void testLttngNotInstalled() {
174 try {
175 fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED);
176 fService.getSessionNames(new NullProgressMonitor());
177 fail("No exeption thrown");
178 } catch (ExecutionException e) {
179 // success
180 }
181 }
182
183 public void testGetSessionNames1() {
184 try {
185 fShell.setScenario(SCEN_NO_SESSION_AVAILABLE);
186 String[] result = fService.getSessionNames(new NullProgressMonitor());
187
188 assertNotNull(result);
189 assertEquals(0, result.length);
190
191 } catch (ExecutionException e) {
192 fail(e.toString());
193 }
194 }
195
196 public void testGetSessionNames2() {
197 try {
198 fShell.setScenario(SCEN_GET_SESSION_NAMES1);
199 String[] result = fService.getSessionNames(new NullProgressMonitor());
200
201 assertNotNull(result);
202 assertEquals(2, result.length);
203 assertEquals("mysession1", result[0]);
204 assertEquals("mysession", result[1]);
205
206 } catch (ExecutionException e) {
207 fail(e.toString());
208 }
209 }
210
211 public void testGetSessionNotExist() {
212 try {
213 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST);
214 fService.getSessionNames(new NullProgressMonitor());
215 fail("No exeption thrown");
216
217 } catch (ExecutionException e) {
218 // success
219 }
220 }
221
222 public void testGetSessionNameGarbage() {
223 try {
224 fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
225 String[] result = fService.getSessionNames(new NullProgressMonitor());
226
227 assertNotNull(result);
228 assertEquals(0, result.length);
229
230 } catch (ExecutionException e) {
231 fail(e.toString());
232 }
233 }
234
235 public void testGetSession1() {
236 try {
237 fShell.setScenario(SCEN_GET_SESSION1);
238 ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor());
239
240 // Verify Session
241 assertNotNull(session);
242 assertEquals("mysession", session.getName());
243 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath());
244 assertEquals(TraceSessionState.ACTIVE, session.getSessionState());
245
246 IDomainInfo[] domains = session.getDomains();
247 assertNotNull(domains);
248 assertEquals(2, domains.length);
249
250 // Verify Kernel domain
251 assertEquals("Kernel", domains[0].getName());
252 IChannelInfo[] channels = domains[0].getChannels();
253 assertNotNull(channels);
254 assertEquals(2, channels.length);
255
256 // Verify Kernel's channel0
257 assertEquals("channel0", channels[0].getName());
258 assertEquals(4, channels[0].getNumberOfSubBuffers());
259 assertEquals("splice()", channels[0].getOutputType());
260 assertEquals(false, channels[0].isOverwriteMode());
261 assertEquals(200, channels[0].getReadTimer());
262 assertEquals(TraceEnablement.ENABLED, channels[0].getState());
263 assertEquals(262144, channels[0].getSubBufferSize());
264 assertEquals(0, channels[0].getSwitchTimer());
265
266 // Verify event info
267 IEventInfo[] channel0Events = channels[0].getEvents();
268 assertNotNull(channel0Events);
269 assertEquals(2, channel0Events.length);
270 assertEquals("block_rq_remap", channel0Events[0].getName());
271 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel());
272 assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType());
273 assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState());
274
275 assertEquals("block_bio_remap", channel0Events[1].getName());
276 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel());
277 assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType());
278 assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState());
279
280 // Verify Kernel's channel1
281 assertEquals("channel1", channels[1].getName());
282 assertEquals(4, channels[1].getNumberOfSubBuffers());
283 assertEquals("splice()", channels[1].getOutputType());
284 assertEquals(true, channels[1].isOverwriteMode());
285 assertEquals(400, channels[1].getReadTimer());
286 assertEquals(TraceEnablement.DISABLED, channels[1].getState());
287 assertEquals(524288, channels[1].getSubBufferSize());
288 assertEquals(100, channels[1].getSwitchTimer());
289
290 // Verify event info
291 IEventInfo[] channel1Events = channels[1].getEvents();
292 assertEquals(0, channel1Events.length);
293
294 // Verify domain UST global
295 assertEquals("UST global", domains[1].getName());
296
297 IChannelInfo[] ustChannels = domains[1].getChannels();
298
299 // Verify UST global's mychannel1
300 assertEquals("mychannel1", ustChannels[0].getName());
301 assertEquals(8, ustChannels[0].getNumberOfSubBuffers());
302 assertEquals("mmap()", ustChannels[0].getOutputType());
303 assertEquals(true, ustChannels[0].isOverwriteMode());
304 assertEquals(100, ustChannels[0].getReadTimer());
305 assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState());
306 assertEquals(8192, ustChannels[0].getSubBufferSize());
307 assertEquals(200, ustChannels[0].getSwitchTimer());
308
309 // Verify event info
310 IEventInfo[] ustEvents = ustChannels[0].getEvents();
311 assertEquals(0, ustEvents.length);
312
313 // Verify UST global's channel0
314 assertEquals("channel0", ustChannels[1].getName());
315 assertEquals(4, ustChannels[1].getNumberOfSubBuffers());
316 assertEquals("mmap()", ustChannels[1].getOutputType());
317 assertEquals(false, ustChannels[1].isOverwriteMode());
318 assertEquals(200, ustChannels[1].getReadTimer());
319 assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState());
320 assertEquals(4096, ustChannels[1].getSubBufferSize());
321 assertEquals(0, ustChannels[1].getSwitchTimer());
322
323 // Verify event info
324 ustEvents = ustChannels[1].getEvents();
325 assertEquals(2, ustEvents.length);
326
327 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName());
328 assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel());
329 assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType());
330 assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState());
331
332 assertEquals("*", ustEvents[1].getName());
333 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, ustEvents[1].getLogLevel());
334 assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType());
335 assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState());
336
337 // next session (no detailed information available)
338 session = fService.getSession("mysession1", new NullProgressMonitor());
339 assertNotNull(session);
340 assertEquals("mysession1", session.getName());
341 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath());
342 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
343
344 domains = session.getDomains();
345 assertNotNull(domains);
346 assertEquals(0, domains.length);
347 } catch (ExecutionException e) {
348 fail(e.toString());
349 }
350 }
351
352 public void testGetKernelProvider() {
353 try {
354 fShell.setScenario(SCEN_GET_KERNEL_PROVIDER1);
355 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
356
357 // Verify event info
358 assertNotNull(events);
359 assertEquals(3, events.size());
360
361 IBaseEventInfo baseEventInfo = events.get(0);
362 assertNotNull(baseEventInfo);
363 assertEquals("sched_kthread_stop", baseEventInfo.getName());
364 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
365 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
366
367 baseEventInfo = events.get(1);
368 assertEquals("sched_kthread_stop_ret", baseEventInfo.getName());
369 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
370 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
371
372 baseEventInfo = events.get(2);
373 assertEquals("sched_wakeup_new", baseEventInfo.getName());
374 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
375 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
376
377 } catch (ExecutionException e) {
378 fail(e.toString());
379 }
380 }
381
382 public void testGetKernelProviderNoKernel1() {
383 try {
384 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1);
385 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
386
387 // Verify event info
388 assertNotNull(events);
389 assertEquals(0, events.size());
390
391 } catch (ExecutionException e) {
392 fail(e.toString());
393 }
394 }
395
396 public void testGetKernelProviderNoKernel2() {
397 try {
398 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2);
399 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
400
401 // Verify event info
402 assertNotNull(events);
403 assertEquals(0, events.size());
404
405 } catch (ExecutionException e) {
406 fail(e.toString());
407 }
408 }
409
410
411 public void testGetUstProvider() {
412 try {
413 fShell.setScenario(SCEN_GET_UST_PROVIDER1);
414 List<IUstProviderInfo> providers = fService.getUstProvider();
415
416 // Check all providers
417 assertNotNull(providers);
418 assertEquals(2, providers.size());
419
420 //Verify first provider
421 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
422 assertEquals(9379, providers.get(0).getPid());
423
424 // Verify event info
425 IBaseEventInfo[] events = providers.get(0).getEvents();
426 assertNotNull(events);
427 assertEquals(2, events.length);
428
429 IBaseEventInfo baseEventInfo = events[0];
430 assertNotNull(baseEventInfo);
431 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
432 assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel());
433 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
434
435 baseEventInfo = events[1];
436 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
437 assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel());
438 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
439
440 //Verify second provider
441 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
442 assertEquals(4852, providers.get(1).getPid());
443
444 // Verify event info
445 events = providers.get(1).getEvents();
446 assertNotNull(events);
447 assertEquals(2, events.length);
448
449 baseEventInfo = events[0];
450 assertNotNull(baseEventInfo);
451 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
452 assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel());
453 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
454
455 baseEventInfo = events[1];
456 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
457 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel());
458 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
459
460 } catch (ExecutionException e) {
461 fail(e.toString());
462 }
463 }
464
465 public void testUstProvider2() {
466 try {
467 fShell.setScenario(SCEN_GET_UST_PROVIDER2);
468 List<IUstProviderInfo> providers = fService.getUstProvider();
469
470 assertNotNull(providers);
471 assertEquals(0, providers.size());
472
473 } catch (ExecutionException e) {
474 fail(e.toString());
475 }
476 }
477
478 public void testGetUstProvider3() {
479 try {
480 fShell.setScenario(SCEN_GET_UST_PROVIDER3);
481 // Set version
482 ((LTTngControlService)fService).setVersion("2.1.0");
483 List<IUstProviderInfo> providers = fService.getUstProvider();
484
485 // Check all providers
486 assertNotNull(providers);
487 assertEquals(2, providers.size());
488
489 //Verify first provider
490 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
491 assertEquals(9379, providers.get(0).getPid());
492
493 // Verify event info
494 IBaseEventInfo[] events = providers.get(0).getEvents();
495 assertNotNull(events);
496 assertEquals(2, events.length);
497
498 IBaseEventInfo baseEventInfo = events[0];
499 assertNotNull(baseEventInfo);
500 IFieldInfo[] fields = baseEventInfo.getFields();
501 assertNotNull(fields);
502 assertEquals(0, fields.length);
503
504 baseEventInfo = events[1];
505 fields = baseEventInfo.getFields();
506 assertNotNull(fields);
507 assertEquals(3, fields.length);
508 assertEquals("doublefield", fields[0].getName());
509 assertEquals("float", fields[0].getFieldType());
510
511 assertEquals("floatfield", fields[1].getName());
512 assertEquals("float", fields[1].getFieldType());
513
514 assertEquals("stringfield", fields[2].getName());
515 assertEquals("string", fields[2].getFieldType());
516
517 //Verify second provider
518 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
519 assertEquals(4852, providers.get(1).getPid());
520
521 // Verify event info
522 events = providers.get(1).getEvents();
523 assertNotNull(events);
524 assertEquals(2, events.length);
525
526 baseEventInfo = events[0];
527 assertNotNull(baseEventInfo);
528 fields = baseEventInfo.getFields();
529 assertNotNull(fields);
530 assertEquals(0, fields.length);
531
532 baseEventInfo = events[1];
533 fields = baseEventInfo.getFields();
534 assertNotNull(fields);
535 assertEquals(3, fields.length);
536
537 assertEquals("doublefield", fields[0].getName());
538 assertEquals("float", fields[0].getFieldType());
539
540 assertEquals("floatfield", fields[1].getName());
541 assertEquals("float", fields[1].getFieldType());
542
543 assertEquals("stringfield", fields[2].getName());
544 assertEquals("string", fields[2].getFieldType());
545
546 // Reset version
547 ((LTTngControlService)fService).setVersion("2.0.0");
548
549 } catch (ExecutionException e) {
550 fail(e.toString());
551 }
552 }
553
554 public void testCreateSession() {
555 try {
556 fShell.setScenario(SCEN_CREATE_SESSION1);
557
558 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
559 assertNotNull(info);
560 assertEquals("mysession2", info.getName());
561 assertNotNull(info.getSessionPath());
562 assertTrue(info.getSessionPath().contains("mysession2"));
563 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
564 } catch (ExecutionException e) {
565 fail(e.toString());
566 }
567 }
568
569 public void testCreateSessionWithPrompt() {
570 try {
571 // First line has the shell prompt before the command output
572 // This can happen in a real application if the command line is not echoed by the shell.
573 fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT);
574
575 // First line has no shell prompt before the output
576 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
577 assertNotNull(info);
578 assertEquals("mysession2", info.getName());
579 assertNotNull(info.getSessionPath());
580 assertTrue(info.getSessionPath().contains("mysession2"));
581 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
582 } catch (ExecutionException e) {
583 fail(e.toString());
584 }
585 }
586
587
588 public void testCreateSessionVariants() {
589
590 fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
591
592 try {
593 fService.createSession("alreadyExist", null, new NullProgressMonitor());
594 fail("No exeption thrown");
595 } catch (ExecutionException e) {
596 // success
597 }
598
599 try {
600 fService.createSession("wrongName", null, new NullProgressMonitor());
601 fail("No exeption thrown");
602 } catch (ExecutionException e) {
603 // success
604 }
605
606 try {
607 fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
608 fail("No exeption thrown");
609 } catch (ExecutionException e) {
610 // success
611 }
612
613 try {
614 ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor());
615 assertNotNull(info);
616 assertEquals("session with spaces", info.getName());
617 assertNotNull(info.getSessionPath());
618 assertTrue(info.getSessionPath().contains("session with spaces"));
619 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
620
621 } catch (ExecutionException e) {
622 fail(e.toString());
623 }
624
625 try {
626 ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
627 assertNotNull(info);
628 assertEquals("pathWithSpaces", info.getName());
629 assertNotNull(info.getSessionPath());
630 assertTrue(info.getSessionPath().contains("/home/user/hallo user/here"));
631 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
632
633 } catch (ExecutionException e) {
634 fail(e.toString());
635 }
636 }
637
638 public void testDestroySession() {
639 try {
640 fShell.setScenario(SCEN_DESTROY_SESSION1);
641 fService.destroySession("mysession2", new NullProgressMonitor());
642 } catch (ExecutionException e) {
643 fail(e.toString());
644 }
645 }
646
647 public void testCreateChannel() {
648 try {
649
650 String sessionName = "mysession2";
651 List<String> list = new ArrayList<String>();
652 String kernelChannel0 = "mychannel0";
653 String kernelChannel1 = "mychannel1";
654 list.add(kernelChannel0);
655 list.add(kernelChannel1);
656
657 fShell.setScenario(SCEN_CHANNEL_HANDLING);
658
659 // Create/enable/configure 2 kernel channels
660 ChannelInfo chanInfo = new ChannelInfo("");
661 chanInfo.setOverwriteMode(true);
662 chanInfo.setSubBufferSize(16384);
663 chanInfo.setReadTimer(100);
664 chanInfo.setSwitchTimer(200);
665 chanInfo.setNumberOfSubBuffers(2);
666 fService.enableChannels(sessionName, list, true, chanInfo, new NullProgressMonitor());
667
668 // Create/enable/configure 1 UST channel
669 list.clear();
670 list.add("ustChannel");
671
672 chanInfo = new ChannelInfo("");
673 chanInfo.setOverwriteMode(true);
674 chanInfo.setSubBufferSize(32768);
675 chanInfo.setReadTimer(200);
676 chanInfo.setSwitchTimer(100);
677 chanInfo.setNumberOfSubBuffers(1);
678 fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
679
680 } catch (ExecutionException e) {
681 fail(e.toString());
682 }
683 }
684
685 public void testDisableChannel() {
686 try {
687
688 String sessionName = "mysession2";
689 List<String> list = new ArrayList<String>();
690 String kernelChannel0 = "mychannel0";
691 String kernelChannel1 = "mychannel1";
692 list.add(kernelChannel0);
693 list.add(kernelChannel1);
694
695 fShell.setScenario(SCEN_CHANNEL_HANDLING);
696 fService.disableChannels(sessionName, list, true, new NullProgressMonitor());
697
698 list.clear();
699 list.add("ustChannel");
700 fService.disableChannels(sessionName, list, false, new NullProgressMonitor());
701
702 } catch (ExecutionException e) {
703 fail(e.toString());
704 }
705 }
706
707 public void testEnableChannel() {
708 try {
709
710 String sessionName = "mysession2";
711 List<String> list = new ArrayList<String>();
712 String kernelChannel0 = "mychannel0";
713 String kernelChannel1 = "mychannel1";
714 list.add(kernelChannel0);
715 list.add(kernelChannel1);
716
717 fShell.setScenario(SCEN_CHANNEL_HANDLING);
718 fService.enableChannels(sessionName, list, true, null, new NullProgressMonitor());
719
720 // Create/enable/configure 1 UST channel
721 list.clear();
722 list.add("ustChannel");
723
724 fService.enableChannels(sessionName, list, false, null, new NullProgressMonitor());
725
726 } catch (ExecutionException e) {
727 fail(e.toString());
728 }
729 }
730
731 // public void tesEnableChannelNoTracer() {
732 // try {
733 // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
734 // service.getSessionNames(new NullProgressMonitor());
735 // fail("No exeption thrown");
736 //
737 // } catch (ExecutionException e) {
738 // // success
739 // }
740 // }
741
742 public void testEnableEvents() {
743 try {
744 // 1) session name, channel = null, 3 event names, kernel
745 String sessionName = "mysession2";
746 List<String> list = new ArrayList<String>();
747 String eventName0 = "block_rq_remap";
748 String eventName1 = "block_bio_remap";
749 String eventName2 = "softirq_entry";
750 list.add(eventName0);
751 list.add(eventName1);
752 list.add(eventName2);
753 fShell.setScenario(SCEN_EVENT_HANDLING);
754 fService.enableEvents(sessionName, null, list, true, null, new NullProgressMonitor());
755
756 // 2) session name, channel=mychannel, event name= null, kernel
757 String channelName = "mychannel";
758 fService.enableEvents(sessionName, channelName, null, true, null, new NullProgressMonitor());
759
760 // 3) session name, channel=mychannel, 1 event name, ust, no filter
761 String ustEventName = "ust_tests_hello:tptest_sighandler";
762 list.clear();
763 list.add(ustEventName);
764 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
765
766 // 4) session name, channel = mychannel, no event name, ust, with filter
767 fService.enableEvents(sessionName, channelName, list, false, "intfield==10", new NullProgressMonitor());
768
769 // 5) session name, channel = mychannel, no event name, ust, no filter
770 list.clear();
771 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
772
773 // TODO add test with filters
774
775 } catch (ExecutionException e) {
776 fail(e.toString());
777 }
778 }
779
780 public void testEnableSyscalls() {
781 try {
782 // 1) session name, channel = null, 3 event names, kernel
783 String sessionName = "mysession2";
784 String channelName = "mychannel";
785
786 fShell.setScenario(SCEN_EVENT_HANDLING);
787
788 // 1) session name, channel = null
789 fService.enableSyscalls(sessionName, null, new NullProgressMonitor());
790
791 // 2) session name, channel = mychannel
792 fService.enableSyscalls(sessionName, channelName, new NullProgressMonitor());
793
794 } catch (ExecutionException e) {
795 fail(e.toString());
796 }
797 }
798
799 public void testDynamicProbe() {
800 try {
801 // 1) session name, channel = null, 3 event names, kernel
802 String sessionName = "mysession2";
803 String channelName = "mychannel";
804 String eventName0 = "myevent0";
805 String eventName1 = "myevent1";
806 String functionProbe = "0xc0101340";
807 String dynProbe = "init_post";
808
809 fShell.setScenario(SCEN_EVENT_HANDLING);
810
811 // 1) session name, channel = null, event name, function probe, probe
812 fService.enableProbe(sessionName, null, eventName0, true, functionProbe, new NullProgressMonitor());
813
814 // 2) session name, channel = mychannel
815 fService.enableProbe(sessionName, channelName, eventName1, false, dynProbe, new NullProgressMonitor());
816
817 } catch (ExecutionException e) {
818 fail(e.toString());
819 }
820 }
821
822 public void testEnableLogLevel() {
823 try {
824 // 1) session name, channel = null, 3 event names, kernel
825 String sessionName = "mysession2";
826 String channelName = "mychannel";
827 String eventName4 = "myevent4";
828 String eventName5 = "myevent5";
829
830 fShell.setScenario(SCEN_EVENT_HANDLING);
831
832 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
833 fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, null, new NullProgressMonitor());
834
835 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
836 fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, null, new NullProgressMonitor());
837
838 // TODO add test with filters
839
840 } catch (ExecutionException e) {
841 fail(e.toString());
842 }
843 }
844
845 public void testAddContext() {
846 try {
847 // 1) session name, channel = null, 3 event names, kernel
848 String sessionName = "mysession2";
849 String channelName = "mychannel";
850 String eventName = "ust_tests_hello:tptest_sighandler";
851 List<String> contexts = new ArrayList<String>();
852 contexts.add("prio");
853 contexts.add("pid");
854
855 fShell.setScenario(SCEN_CONTEXT_HANDLING);
856
857 List<String> availContexts = fService.getContextList(new NullProgressMonitor());
858 assertNotNull(availContexts);
859 assertEquals(12, availContexts.size());
860
861 // A very "hard-coded" way to verify but it works ...
862 Set<String> expectedContexts = new HashSet<String>();
863 expectedContexts.add("pid");
864 expectedContexts.add("procname");
865 expectedContexts.add("prio");
866 expectedContexts.add("nice");
867 expectedContexts.add("vpid");
868 expectedContexts.add("tid");
869 expectedContexts.add("pthread_id");
870 expectedContexts.add("vtid");
871 expectedContexts.add("ppid");
872 expectedContexts.add("vppid");
873 expectedContexts.add("perf:cpu-cycles");
874 expectedContexts.add("perf:cycles");
875
876 assertTrue(expectedContexts.containsAll(availContexts));
877
878 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
879 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
880
881 } catch (ExecutionException e) {
882 fail(e.toString());
883 }
884 }
885
886 public void testAddContextFailure() {
887
888 // 1) session name, channel = null, 3 event names, kernel
889 String sessionName = "mysession2";
890 String channelName = "mychannel";
891 String eventName = "ust_tests_hello:tptest_sighandler";
892 List<String> contexts = new ArrayList<String>();
893 contexts.add("prio");
894 contexts.add("pid");
895 fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
896 try {
897 fService.getContextList(new NullProgressMonitor());
898 fail("No exeption generated");
899 } catch (ExecutionException e) {
900 // success
901 }
902 try {
903 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
904 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
905 fail("No exeption generated");
906 } catch (ExecutionException e) {
907 // success
908 }
909 }
910
911 public void testCalibrate() {
912 try {
913 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
914 fService.calibrate(true, new NullProgressMonitor());
915
916 } catch (ExecutionException e) {
917 fail(e.toString());
918 }
919 }
920
921 public void testCalibrateFailure() {
922
923 try {
924 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
925 fService.calibrate(false, new NullProgressMonitor());
926 fail("No exeption generated");
927 } catch (ExecutionException e) {
928 // success
929 }
930 }
931
932 }
This page took 0.052604 seconds and 6 git commands to generate.