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