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