1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.service
;
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
;
23 import java
.util
.ArrayList
;
24 import java
.util
.HashSet
;
25 import java
.util
.List
;
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
;
59 * The class <code>LTTngControlServiceTest</code> contains test for the class
60 * <code>{@link LTTngControlService}</code>.
62 @SuppressWarnings("javadoc")
63 public class LTTngControlServiceTest
{
65 private static final String DIRECTORY
= "testfiles";
66 private static final String TEST_STREAM
= "LTTngServiceTest.cfg";
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";
103 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
107 private CommandShellFactory fShellFactory
;
108 private String fTestfile
;
109 private LTTngToolsFileShell fShell
;
110 private ILttngControlService fService
;
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * Perform pre-test initialization.
120 * if the initialization fails for some reason
123 public void setUp() throws Exception
{
124 fShellFactory
= CommandShellFactory
.getInstance();
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();
130 fShell
= fShellFactory
.getFileShell();
131 fShell
.loadScenarioFile(fTestfile
);
132 fService
= new LTTngControlService(fShell
);
134 ControlPreferences
.getInstance().init(Activator
.getDefault().getPreferenceStore());
138 public void tearDown() {
140 ControlPreferences
.getInstance().dispose();
143 // ------------------------------------------------------------------------
145 // ------------------------------------------------------------------------
148 public void testVersion() {
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
);
160 public void testVersionWithPrompt() {
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
);
172 public void testUnsupportedVersion() {
174 fShell
.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION
);
175 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
176 fail("No exeption thrown");
177 } catch (ExecutionException e
) {
183 public void testNoVersion() {
185 fShell
.setScenario(SCEN_LTTNG_NO_VERSION
);
186 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
187 fail("No exeption thrown");
188 } catch (ExecutionException e
) {
194 public void testLttngNotInstalled() {
196 fShell
.setScenario(SCEN_LTTNG_NOT_INSTALLED
);
197 fService
.getSessionNames(new NullProgressMonitor());
198 fail("No exeption thrown");
199 } catch (ExecutionException e
) {
205 public void testGetSessionNames1() {
207 fShell
.setScenario(SCEN_NO_SESSION_AVAILABLE
);
208 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
210 assertNotNull(result
);
211 assertEquals(0, result
.length
);
213 } catch (ExecutionException e
) {
219 public void testGetSessionNames2() {
221 fShell
.setScenario(SCEN_GET_SESSION_NAMES1
);
222 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
224 assertNotNull(result
);
225 assertEquals(2, result
.length
);
226 assertEquals("mysession1", result
[0]);
227 assertEquals("mysession", result
[1]);
229 } catch (ExecutionException e
) {
235 public void testGetSessionNotExist() {
237 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST
);
238 fService
.getSessionNames(new NullProgressMonitor());
239 fail("No exeption thrown");
241 } catch (ExecutionException e
) {
247 public void testGetSessionNotExistVerbose() {
250 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE
);
251 fService
.getSessionNames(new NullProgressMonitor());
252 fail("No exeption thrown");
254 } catch (ExecutionException e
) {
262 public void testGetSessionNameGarbage() {
264 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
265 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
267 assertNotNull(result
);
268 assertEquals(0, result
.length
);
270 } catch (ExecutionException e
) {
276 public void testGetSession1() {
278 fShell
.setScenario(SCEN_GET_SESSION1
);
279 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
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());
287 IDomainInfo
[] domains
= session
.getDomains();
288 assertNotNull(domains
);
289 assertEquals(2, domains
.length
);
291 // Verify Kernel domain
292 assertEquals("Kernel", domains
[0].getName());
293 IChannelInfo
[] channels
= domains
[0].getChannels();
294 assertNotNull(channels
);
295 assertEquals(2, channels
.length
);
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());
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());
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());
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());
332 IEventInfo
[] channel1Events
= channels
[1].getEvents();
333 assertEquals(0, channel1Events
.length
);
335 // Verify domain UST global
336 assertEquals("UST global", domains
[1].getName());
338 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
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());
351 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
352 assertEquals(0, ustEvents
.length
);
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());
365 ustEvents
= ustChannels
[1].getEvents();
366 assertEquals(2, ustEvents
.length
);
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());
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());
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());
385 domains
= session
.getDomains();
386 assertNotNull(domains
);
387 assertEquals(0, domains
.length
);
388 } catch (ExecutionException e
) {
393 public void testGetKernelProvider() {
395 fShell
.setScenario(SCEN_GET_KERNEL_PROVIDER1
);
396 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
399 assertNotNull(events
);
400 assertEquals(3, events
.size());
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());
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());
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());
418 } catch (ExecutionException e
) {
424 public void testGetKernelProviderNoKernel1() {
426 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL1
);
427 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
430 assertNotNull(events
);
431 assertEquals(0, events
.size());
433 } catch (ExecutionException e
) {
439 public void testGetKernelProviderNoKernel2() {
441 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL2
);
442 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
445 assertNotNull(events
);
446 assertEquals(0, events
.size());
448 } catch (ExecutionException e
) {
454 public void testGetKernelProviderNoKernelVerbose() {
457 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE
);
458 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
461 assertNotNull(events
);
462 assertEquals(0, events
.size());
464 } catch (ExecutionException e
) {
472 public void testGetUstProvider() {
474 fShell
.setScenario(SCEN_GET_UST_PROVIDER1
);
475 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
477 // Check all providers
478 assertNotNull(providers
);
479 assertEquals(2, providers
.size());
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());
486 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
487 assertNotNull(events
);
488 assertEquals(2, events
.length
);
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());
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());
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());
506 events
= providers
.get(1).getEvents();
507 assertNotNull(events
);
508 assertEquals(2, events
.length
);
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());
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());
521 } catch (ExecutionException e
) {
527 public void testUstProvider2() {
529 fShell
.setScenario(SCEN_GET_UST_PROVIDER2
);
530 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
532 assertNotNull(providers
);
533 assertEquals(0, providers
.size());
535 } catch (ExecutionException e
) {
541 public void testGetUstProvider3() {
543 fShell
.setScenario(SCEN_GET_UST_PROVIDER3
);
545 ((LTTngControlService
)fService
).setVersion("2.1.0");
546 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
548 // Check all providers
549 assertNotNull(providers
);
550 assertEquals(2, providers
.size());
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());
557 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
558 assertNotNull(events
);
559 assertEquals(2, events
.length
);
561 IBaseEventInfo baseEventInfo
= events
[0];
562 assertNotNull(baseEventInfo
);
563 IFieldInfo
[] fields
= baseEventInfo
.getFields();
564 assertNotNull(fields
);
565 assertEquals(0, fields
.length
);
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());
574 assertEquals("floatfield", fields
[1].getName());
575 assertEquals("float", fields
[1].getFieldType());
577 assertEquals("stringfield", fields
[2].getName());
578 assertEquals("string", fields
[2].getFieldType());
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());
585 events
= providers
.get(1).getEvents();
586 assertNotNull(events
);
587 assertEquals(2, events
.length
);
589 baseEventInfo
= events
[0];
590 assertNotNull(baseEventInfo
);
591 fields
= baseEventInfo
.getFields();
592 assertNotNull(fields
);
593 assertEquals(0, fields
.length
);
595 baseEventInfo
= events
[1];
596 fields
= baseEventInfo
.getFields();
597 assertNotNull(fields
);
598 assertEquals(3, fields
.length
);
600 assertEquals("doublefield", fields
[0].getName());
601 assertEquals("float", fields
[0].getFieldType());
603 assertEquals("floatfield", fields
[1].getName());
604 assertEquals("float", fields
[1].getFieldType());
606 assertEquals("stringfield", fields
[2].getName());
607 assertEquals("string", fields
[2].getFieldType());
610 ((LTTngControlService
)fService
).setVersion("2.0.0");
612 } catch (ExecutionException e
) {
619 public void testGetKernelProviderNoUst1() {
621 fShell
.setScenario(SCEN_LIST_WITH_NO_UST1
);
622 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
624 // Verify Provider info
625 assertNotNull(providerList
);
626 assertEquals(0, providerList
.size());
628 } catch (ExecutionException e
) {
635 public void testGetKernelProviderNoUst2() {
638 ((LTTngControlService
)fService
).setVersion("2.1.0");
640 fShell
.setScenario(SCEN_LIST_WITH_NO_UST2
);
641 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
643 // Verify Provider info
644 assertNotNull(providerList
);
645 assertEquals(0, providerList
.size());
648 ((LTTngControlService
)fService
).setVersion("2.0.0");
650 } catch (ExecutionException e
) {
656 public void testGetKernelProviderNoUst3() {
660 ((LTTngControlService
)fService
).setVersion("2.1.0");
662 fShell
.setScenario(SCEN_LIST_WITH_NO_UST3
);
663 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
665 // Verify provider info
666 assertNotNull(providerList
);
667 assertEquals(0, providerList
.size());
670 ((LTTngControlService
)fService
).setVersion("2.0.0");
672 } catch (ExecutionException e
) {
678 public void testGetKernelProviderNoUstVerbose() {
683 ((LTTngControlService
)fService
).setVersion("2.1.0");
685 fShell
.setScenario(SCEN_LIST_WITH_NO_UST_VERBOSE
);
686 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
688 // Verify provider info
689 assertNotNull(providerList
);
690 assertEquals(0, providerList
.size());
693 ((LTTngControlService
)fService
).setVersion("2.0.0");
695 } catch (ExecutionException e
) {
705 public void testCreateSession() {
707 fShell
.setScenario(SCEN_CREATE_SESSION1
);
709 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
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
) {
721 public void testCreateSessionWithPrompt() {
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
);
727 // First line has no shell prompt before the output
728 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
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
) {
740 public void testCreateSessionVariants() {
742 fShell
.setScenario(SCEN_CREATE_SESSION_VARIANTS
);
745 fService
.createSession("alreadyExist", null, new NullProgressMonitor());
746 fail("No exeption thrown");
747 } catch (ExecutionException e
) {
752 fService
.createSession("wrongName", null, new NullProgressMonitor());
753 fail("No exeption thrown");
754 } catch (ExecutionException e
) {
759 fService
.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
760 fail("No exeption thrown");
761 } catch (ExecutionException e
) {
766 ISessionInfo info
= fService
.createSession("session with spaces", null, new NullProgressMonitor());
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());
773 } catch (ExecutionException e
) {
778 ISessionInfo info
= fService
.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
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());
785 } catch (ExecutionException e
) {
791 public void testDestroySession() {
793 fShell
.setScenario(SCEN_DESTROY_SESSION1
);
794 fService
.destroySession("mysession2", new NullProgressMonitor());
795 } catch (ExecutionException e
) {
801 public void testDestroySessionVerbose() {
804 fShell
.setScenario(SCEN_DESTROY_SESSION_VERBOSE
);
805 fService
.destroySession("mysession2", new NullProgressMonitor());
806 } catch (ExecutionException e
) {
814 public void testCreateChannel() {
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
);
824 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
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());
837 // Create/enable/configure 1 UST channel
839 list
.add("ustChannel");
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());
851 } catch (ExecutionException e
) {
857 public void testCreateChannelUIDBuffer() {
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
);
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());
876 } catch (ExecutionException e
) {
882 public void testDisableChannel() {
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
);
892 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
893 fService
.disableChannels(sessionName
, list
, true, new NullProgressMonitor());
896 list
.add("ustChannel");
897 fService
.disableChannels(sessionName
, list
, false, new NullProgressMonitor());
899 } catch (ExecutionException e
) {
905 public void testEnableChannel() {
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
);
915 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
916 fService
.enableChannels(sessionName
, list
, true, null, new NullProgressMonitor());
918 // Create/enable/configure 1 UST channel
920 list
.add("ustChannel");
922 fService
.enableChannels(sessionName
, list
, false, null, new NullProgressMonitor());
924 } catch (ExecutionException e
) {
930 public void testEnableEvents() {
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());
944 // 2) session name, channel=mychannel, event name= null, kernel
945 String channelName
= "mychannel";
946 fService
.enableEvents(sessionName
, channelName
, null, true, null, new NullProgressMonitor());
948 // 3) session name, channel=mychannel, 1 event name, ust, no filter
949 String ustEventName
= "ust_tests_hello:tptest_sighandler";
951 list
.add(ustEventName
);
952 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
954 // 4) session name, channel = mychannel, no event name, ust, with filter
955 fService
.enableEvents(sessionName
, channelName
, list
, false, "intfield==10", new NullProgressMonitor());
957 // 5) session name, channel = mychannel, no event name, ust, no filter
959 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
961 // TODO add test with filters
963 } catch (ExecutionException e
) {
969 public void testEnableSyscalls() {
971 // 1) session name, channel = null, 3 event names, kernel
972 String sessionName
= "mysession2";
973 String channelName
= "mychannel";
975 fShell
.setScenario(SCEN_EVENT_HANDLING
);
977 // 1) session name, channel = null
978 fService
.enableSyscalls(sessionName
, null, new NullProgressMonitor());
980 // 2) session name, channel = mychannel
981 fService
.enableSyscalls(sessionName
, channelName
, new NullProgressMonitor());
983 } catch (ExecutionException e
) {
989 public void testDynamicProbe() {
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";
999 fShell
.setScenario(SCEN_EVENT_HANDLING
);
1001 // 1) session name, channel = null, event name, function probe, probe
1002 fService
.enableProbe(sessionName
, null, eventName0
, true, functionProbe
, new NullProgressMonitor());
1004 // 2) session name, channel = mychannel
1005 fService
.enableProbe(sessionName
, channelName
, eventName1
, false, dynProbe
, new NullProgressMonitor());
1007 } catch (ExecutionException e
) {
1013 public void testEnableLogLevel() {
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";
1021 fShell
.setScenario(SCEN_EVENT_HANDLING
);
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());
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());
1029 // TODO add test with filters
1031 } catch (ExecutionException e
) {
1037 public void testAddContext() {
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");
1047 fShell
.setScenario(SCEN_CONTEXT_HANDLING
);
1049 List
<String
> availContexts
= fService
.getContextList(new NullProgressMonitor());
1050 assertNotNull(availContexts
);
1051 assertEquals(12, availContexts
.size());
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");
1068 assertTrue(expectedContexts
.containsAll(availContexts
));
1070 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1071 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
1073 } catch (ExecutionException e
) {
1079 public void testAddContextFailure() {
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
);
1090 fService
.getContextList(new NullProgressMonitor());
1091 fail("No exeption generated");
1092 } catch (ExecutionException e
) {
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
) {
1105 public void testCalibrate() {
1107 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
1108 fService
.calibrate(true, new NullProgressMonitor());
1110 } catch (ExecutionException e
) {
1116 public void testCalibrateFailure() {
1118 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
1119 fService
.calibrate(false, new NullProgressMonitor());
1120 fail("No exeption generated");
1121 } catch (ExecutionException e
) {
1127 public void testCreateSession2_1() {
1130 fShell
.setScenario(SCEN_CREATE_SESSION_2_1
);
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());
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());
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());
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());
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());
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());
1175 fService
.destroySession("mysession", new NullProgressMonitor());
1178 } catch (ExecutionException e
) {
1184 public void testCreateSessionVerbose2_1() {
1186 fShell
.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1
);
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
) {
1202 private static void enableVerbose() {
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
);
1209 private static void disableVerbose() {
1210 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
, false);