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
.BufferType
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.CommandShellFactory
;
47 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.shells
.LTTngToolsFileShell
;
48 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
49 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.logging
.ControlCommandLogger
;
50 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
51 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
52 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlService
;
53 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlServiceFactory
;
54 import org
.junit
.After
;
55 import org
.junit
.Before
;
56 import org
.junit
.Test
;
57 import org
.osgi
.framework
.FrameworkUtil
;
60 * The class <code>LTTngControlServiceTest</code> contains test for the class
61 * <code>{@link LTTngControlService}</code>.
63 @SuppressWarnings("javadoc")
64 public class LTTngControlServiceTest
{
66 private static final String DIRECTORY
= "testfiles";
67 private static final String TEST_STREAM
= "LTTngServiceTest.cfg";
69 private static final String SCEN_LTTNG_NOT_INSTALLED
= "LttngNotInstalled";
70 private static final String SCEN_LTTNG_VERSION
= "LttngVersion";
71 private static final String SCEN_LTTNG_VERSION_WITH_PROMPT
= "LttngVersionWithPrompt";
72 private static final String SCEN_LTTNG_UNSUPPORTED_VERSION
= "LttngUnsupportedVersion";
73 private static final String SCEN_LTTNG_NO_VERSION
= "LttngNoVersion";
74 private static final String SCEN_NO_SESSION_AVAILABLE
= "NoSessionAvailable";
75 private static final String SCEN_GET_SESSION_NAMES1
= "GetSessionNames1";
76 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST
= "GetSessionNameNotExist";
77 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE
= "GetSessionNameNotExistVerbose";
78 private static final String SCEN_GET_SESSION_GARBAGE_OUT
= "GetSessionGarbageOut";
79 private static final String SCEN_GET_SESSION1
= "GetSession1";
80 private static final String SCEN_GET_KERNEL_PROVIDER1
= "GetKernelProvider1";
81 private static final String SCEN_LIST_WITH_NO_KERNEL1
= "ListWithNoKernel1";
82 private static final String SCEN_LIST_WITH_NO_KERNEL2
= "ListWithNoKernel2";
83 private static final String SCEN_LIST_WITH_NO_KERNEL_VERBOSE
= "ListWithNoKernelVerbose";
84 private static final String SCEN_GET_UST_PROVIDER1
= "GetUstProvider1";
85 private static final String SCEN_GET_UST_PROVIDER2
= "GetUstProvider2";
86 private static final String SCEN_GET_UST_PROVIDER3
= "GetUstProvider3";
87 private static final String SCEN_LIST_WITH_NO_UST1
= "ListWithNoUst1";
88 private static final String SCEN_LIST_WITH_NO_UST2
= "ListWithNoUst2";
89 private static final String SCEN_LIST_WITH_NO_UST3
= "ListWithNoUst3";
90 private static final String SCEN_LIST_WITH_NO_UST_VERBOSE
= "ListWithNoUstVerbose";
91 private static final String SCEN_CREATE_SESSION1
= "CreateSession1";
92 private static final String SCEN_CREATE_SESSION_WITH_PROMPT
= "CreateSessionWithPrompt";
93 private static final String SCEN_CREATE_SESSION_VARIANTS
= "CreateSessionVariants";
94 private static final String SCEN_DESTROY_SESSION1
= "DestroySession1";
95 private static final String SCEN_DESTROY_SESSION_VERBOSE
= "DestroySessionVerbose";
96 private static final String SCEN_CHANNEL_HANDLING
= "ChannelHandling";
97 private static final String SCEN_EVENT_HANDLING
= "EventHandling";
98 private static final String SCEN_CONTEXT_HANDLING
= "ContextHandling";
99 private static final String SCEN_CONTEXT_ERROR_HANDLING
= "ContextErrorHandling";
100 private static final String SCEN_CALIBRATE_HANDLING
= "CalibrateHandling";
101 private static final String SCEN_CREATE_SESSION_2_1
= "CreateSessionLttng2.1";
102 private static final String SCEN_CREATE_SESSION_VERBOSE_2_1
= "CreateSessionLttngVerbose2.1";
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
108 private CommandShellFactory fShellFactory
;
109 private String fTestfile
;
110 private LTTngToolsFileShell fShell
;
111 private ILttngControlService fService
;
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
118 * Perform pre-test initialization.
121 * if the initialization fails for some reason
124 public void setUp() throws Exception
{
125 fShellFactory
= CommandShellFactory
.getInstance();
127 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
128 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
129 fTestfile
= testfile
.getAbsolutePath();
131 fShell
= fShellFactory
.getFileShell();
132 fShell
.loadScenarioFile(fTestfile
);
133 fService
= new LTTngControlService(fShell
);
135 ControlPreferences
.getInstance().init(Activator
.getDefault().getPreferenceStore());
139 public void tearDown() {
141 ControlPreferences
.getInstance().dispose();
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 public void testVersion() {
151 fShell
.setScenario(SCEN_LTTNG_VERSION
);
152 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
153 assertNotNull(service
);
154 assertEquals("2.1.0", service
.getVersion());
155 } catch (ExecutionException e
) {
156 fail("Exeption thrown " + e
);
161 public void testVersionWithPrompt() {
163 fShell
.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT
);
164 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
165 assertNotNull(service
);
166 assertEquals("2.0.0", service
.getVersion());
167 } catch (ExecutionException e
) {
168 fail("Exeption thrown " + e
);
173 public void testUnsupportedVersion() {
175 fShell
.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION
);
176 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
177 fail("No exeption thrown");
178 } catch (ExecutionException e
) {
184 public void testNoVersion() {
186 fShell
.setScenario(SCEN_LTTNG_NO_VERSION
);
187 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
188 fail("No exeption thrown");
189 } catch (ExecutionException e
) {
195 public void testLttngNotInstalled() {
197 fShell
.setScenario(SCEN_LTTNG_NOT_INSTALLED
);
198 fService
.getSessionNames(new NullProgressMonitor());
199 fail("No exeption thrown");
200 } catch (ExecutionException e
) {
206 public void testGetSessionNames1() {
208 fShell
.setScenario(SCEN_NO_SESSION_AVAILABLE
);
209 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
211 assertNotNull(result
);
212 assertEquals(0, result
.length
);
214 } catch (ExecutionException e
) {
220 public void testGetSessionNames2() {
222 fShell
.setScenario(SCEN_GET_SESSION_NAMES1
);
223 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
225 assertNotNull(result
);
226 assertEquals(2, result
.length
);
227 assertEquals("mysession1", result
[0]);
228 assertEquals("mysession", result
[1]);
230 } catch (ExecutionException e
) {
236 public void testGetSessionNotExist() {
238 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST
);
239 fService
.getSessionNames(new NullProgressMonitor());
240 fail("No exeption thrown");
242 } catch (ExecutionException e
) {
248 public void testGetSessionNotExistVerbose() {
251 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE
);
252 fService
.getSessionNames(new NullProgressMonitor());
253 fail("No exeption thrown");
255 } catch (ExecutionException e
) {
263 public void testGetSessionNameGarbage() {
265 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
266 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
268 assertNotNull(result
);
269 assertEquals(0, result
.length
);
271 } catch (ExecutionException e
) {
277 public void testGetSession1() {
279 fShell
.setScenario(SCEN_GET_SESSION1
);
280 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
283 assertNotNull(session
);
284 assertEquals("mysession", session
.getName());
285 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
286 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
288 IDomainInfo
[] domains
= session
.getDomains();
289 assertNotNull(domains
);
290 assertEquals(2, domains
.length
);
292 // Verify Kernel domain
293 assertEquals("Kernel", domains
[0].getName());
294 IChannelInfo
[] channels
= domains
[0].getChannels();
295 assertNotNull(channels
);
296 assertEquals(2, channels
.length
);
298 // Verify Kernel's channel0
299 assertEquals("channel0", channels
[0].getName());
300 assertEquals(4, channels
[0].getNumberOfSubBuffers());
301 assertEquals("splice()", channels
[0].getOutputType());
302 assertEquals(false, channels
[0].isOverwriteMode());
303 assertEquals(200, channels
[0].getReadTimer());
304 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
305 assertEquals(262144, channels
[0].getSubBufferSize());
306 assertEquals(0, channels
[0].getSwitchTimer());
309 IEventInfo
[] channel0Events
= channels
[0].getEvents();
310 assertNotNull(channel0Events
);
311 assertEquals(2, channel0Events
.length
);
312 assertEquals("block_rq_remap", channel0Events
[0].getName());
313 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[0].getLogLevel());
314 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[0].getEventType());
315 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
317 assertEquals("block_bio_remap", channel0Events
[1].getName());
318 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
319 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
320 assertEquals(TraceEnablement
.DISABLED
, channel0Events
[1].getState());
322 // Verify Kernel's channel1
323 assertEquals("channel1", channels
[1].getName());
324 assertEquals(4, channels
[1].getNumberOfSubBuffers());
325 assertEquals("splice()", channels
[1].getOutputType());
326 assertEquals(true, channels
[1].isOverwriteMode());
327 assertEquals(400, channels
[1].getReadTimer());
328 assertEquals(TraceEnablement
.DISABLED
, channels
[1].getState());
329 assertEquals(524288, channels
[1].getSubBufferSize());
330 assertEquals(100, channels
[1].getSwitchTimer());
333 IEventInfo
[] channel1Events
= channels
[1].getEvents();
334 assertEquals(0, channel1Events
.length
);
336 // Verify domain UST global
337 assertEquals("UST global", domains
[1].getName());
339 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
341 // Verify UST global's mychannel1
342 assertEquals("mychannel1", ustChannels
[0].getName());
343 assertEquals(8, ustChannels
[0].getNumberOfSubBuffers());
344 assertEquals("mmap()", ustChannels
[0].getOutputType());
345 assertEquals(true, ustChannels
[0].isOverwriteMode());
346 assertEquals(100, ustChannels
[0].getReadTimer());
347 assertEquals(TraceEnablement
.DISABLED
, ustChannels
[0].getState());
348 assertEquals(8192, ustChannels
[0].getSubBufferSize());
349 assertEquals(200, ustChannels
[0].getSwitchTimer());
352 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
353 assertEquals(0, ustEvents
.length
);
355 // Verify UST global's channel0
356 assertEquals("channel0", ustChannels
[1].getName());
357 assertEquals(4, ustChannels
[1].getNumberOfSubBuffers());
358 assertEquals("mmap()", ustChannels
[1].getOutputType());
359 assertEquals(false, ustChannels
[1].isOverwriteMode());
360 assertEquals(200, ustChannels
[1].getReadTimer());
361 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[1].getState());
362 assertEquals(4096, ustChannels
[1].getSubBufferSize());
363 assertEquals(0, ustChannels
[1].getSwitchTimer());
366 ustEvents
= ustChannels
[1].getEvents();
367 assertEquals(2, ustEvents
.length
);
369 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents
[0].getName());
370 assertEquals(TraceLogLevel
.TRACE_DEBUG_LINE
, ustEvents
[0].getLogLevel());
371 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
372 assertEquals(TraceEnablement
.DISABLED
, ustEvents
[0].getState());
374 assertEquals("*", ustEvents
[1].getName());
375 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, ustEvents
[1].getLogLevel());
376 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[1].getEventType());
377 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[1].getState());
379 // next session (no detailed information available)
380 session
= fService
.getSession("mysession1", new NullProgressMonitor());
381 assertNotNull(session
);
382 assertEquals("mysession1", session
.getName());
383 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session
.getSessionPath());
384 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
386 domains
= session
.getDomains();
387 assertNotNull(domains
);
388 assertEquals(0, domains
.length
);
389 } catch (ExecutionException e
) {
394 public void testGetKernelProvider() {
396 fShell
.setScenario(SCEN_GET_KERNEL_PROVIDER1
);
397 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
400 assertNotNull(events
);
401 assertEquals(3, events
.size());
403 IBaseEventInfo baseEventInfo
= events
.get(0);
404 assertNotNull(baseEventInfo
);
405 assertEquals("sched_kthread_stop", baseEventInfo
.getName());
406 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
407 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
409 baseEventInfo
= events
.get(1);
410 assertEquals("sched_kthread_stop_ret", baseEventInfo
.getName());
411 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
412 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
414 baseEventInfo
= events
.get(2);
415 assertEquals("sched_wakeup_new", baseEventInfo
.getName());
416 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
417 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
419 } catch (ExecutionException e
) {
425 public void testGetKernelProviderNoKernel1() {
427 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL1
);
428 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
431 assertNotNull(events
);
432 assertEquals(0, events
.size());
434 } catch (ExecutionException e
) {
440 public void testGetKernelProviderNoKernel2() {
442 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL2
);
443 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
446 assertNotNull(events
);
447 assertEquals(0, events
.size());
449 } catch (ExecutionException e
) {
455 public void testGetKernelProviderNoKernelVerbose() {
458 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE
);
459 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
462 assertNotNull(events
);
463 assertEquals(0, events
.size());
465 } catch (ExecutionException e
) {
473 public void testGetUstProvider() {
475 fShell
.setScenario(SCEN_GET_UST_PROVIDER1
);
476 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
478 // Check all providers
479 assertNotNull(providers
);
480 assertEquals(2, providers
.size());
482 //Verify first provider
483 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
484 assertEquals(9379, providers
.get(0).getPid());
487 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
488 assertNotNull(events
);
489 assertEquals(2, events
.length
);
491 IBaseEventInfo baseEventInfo
= events
[0];
492 assertNotNull(baseEventInfo
);
493 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
494 assertEquals(TraceLogLevel
.TRACE_DEBUG_MODULE
, baseEventInfo
.getLogLevel());
495 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
497 baseEventInfo
= events
[1];
498 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
499 assertEquals(TraceLogLevel
.TRACE_INFO
, baseEventInfo
.getLogLevel());
500 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
502 //Verify second provider
503 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
504 assertEquals(4852, providers
.get(1).getPid());
507 events
= providers
.get(1).getEvents();
508 assertNotNull(events
);
509 assertEquals(2, events
.length
);
511 baseEventInfo
= events
[0];
512 assertNotNull(baseEventInfo
);
513 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
514 assertEquals(TraceLogLevel
.TRACE_WARNING
, baseEventInfo
.getLogLevel());
515 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
517 baseEventInfo
= events
[1];
518 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
519 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, baseEventInfo
.getLogLevel());
520 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
522 } catch (ExecutionException e
) {
528 public void testUstProvider2() {
530 fShell
.setScenario(SCEN_GET_UST_PROVIDER2
);
531 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
533 assertNotNull(providers
);
534 assertEquals(0, providers
.size());
536 } catch (ExecutionException e
) {
542 public void testGetUstProvider3() {
544 fShell
.setScenario(SCEN_GET_UST_PROVIDER3
);
546 ((LTTngControlService
)fService
).setVersion("2.1.0");
547 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
549 // Check all providers
550 assertNotNull(providers
);
551 assertEquals(2, providers
.size());
553 //Verify first provider
554 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
555 assertEquals(9379, providers
.get(0).getPid());
558 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
559 assertNotNull(events
);
560 assertEquals(2, events
.length
);
562 IBaseEventInfo baseEventInfo
= events
[0];
563 assertNotNull(baseEventInfo
);
564 IFieldInfo
[] fields
= baseEventInfo
.getFields();
565 assertNotNull(fields
);
566 assertEquals(0, fields
.length
);
568 baseEventInfo
= events
[1];
569 fields
= baseEventInfo
.getFields();
570 assertNotNull(fields
);
571 assertEquals(3, fields
.length
);
572 assertEquals("doublefield", fields
[0].getName());
573 assertEquals("float", fields
[0].getFieldType());
575 assertEquals("floatfield", fields
[1].getName());
576 assertEquals("float", fields
[1].getFieldType());
578 assertEquals("stringfield", fields
[2].getName());
579 assertEquals("string", fields
[2].getFieldType());
581 //Verify second provider
582 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
583 assertEquals(4852, providers
.get(1).getPid());
586 events
= providers
.get(1).getEvents();
587 assertNotNull(events
);
588 assertEquals(2, events
.length
);
590 baseEventInfo
= events
[0];
591 assertNotNull(baseEventInfo
);
592 fields
= baseEventInfo
.getFields();
593 assertNotNull(fields
);
594 assertEquals(0, fields
.length
);
596 baseEventInfo
= events
[1];
597 fields
= baseEventInfo
.getFields();
598 assertNotNull(fields
);
599 assertEquals(3, fields
.length
);
601 assertEquals("doublefield", fields
[0].getName());
602 assertEquals("float", fields
[0].getFieldType());
604 assertEquals("floatfield", fields
[1].getName());
605 assertEquals("float", fields
[1].getFieldType());
607 assertEquals("stringfield", fields
[2].getName());
608 assertEquals("string", fields
[2].getFieldType());
611 ((LTTngControlService
)fService
).setVersion("2.0.0");
613 } catch (ExecutionException e
) {
620 public void testGetKernelProviderNoUst1() {
622 fShell
.setScenario(SCEN_LIST_WITH_NO_UST1
);
623 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
625 // Verify Provider info
626 assertNotNull(providerList
);
627 assertEquals(0, providerList
.size());
629 } catch (ExecutionException e
) {
636 public void testGetKernelProviderNoUst2() {
639 ((LTTngControlService
)fService
).setVersion("2.1.0");
641 fShell
.setScenario(SCEN_LIST_WITH_NO_UST2
);
642 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
644 // Verify Provider info
645 assertNotNull(providerList
);
646 assertEquals(0, providerList
.size());
649 ((LTTngControlService
)fService
).setVersion("2.0.0");
651 } catch (ExecutionException e
) {
657 public void testGetKernelProviderNoUst3() {
661 ((LTTngControlService
)fService
).setVersion("2.1.0");
663 fShell
.setScenario(SCEN_LIST_WITH_NO_UST3
);
664 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
666 // Verify provider info
667 assertNotNull(providerList
);
668 assertEquals(0, providerList
.size());
671 ((LTTngControlService
)fService
).setVersion("2.0.0");
673 } catch (ExecutionException e
) {
679 public void testGetKernelProviderNoUstVerbose() {
684 ((LTTngControlService
)fService
).setVersion("2.1.0");
686 fShell
.setScenario(SCEN_LIST_WITH_NO_UST_VERBOSE
);
687 List
<IUstProviderInfo
> providerList
= fService
.getUstProvider(new NullProgressMonitor());
689 // Verify provider info
690 assertNotNull(providerList
);
691 assertEquals(0, providerList
.size());
694 ((LTTngControlService
)fService
).setVersion("2.0.0");
696 } catch (ExecutionException e
) {
706 public void testCreateSession() {
708 fShell
.setScenario(SCEN_CREATE_SESSION1
);
710 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
712 assertEquals("mysession2", info
.getName());
713 assertNotNull(info
.getSessionPath());
714 assertTrue(info
.getSessionPath().contains("mysession2"));
715 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
716 } catch (ExecutionException e
) {
722 public void testCreateSessionWithPrompt() {
724 // First line has the shell prompt before the command output
725 // This can happen in a real application if the command line is not echoed by the shell.
726 fShell
.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT
);
728 // First line has no shell prompt before the output
729 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
731 assertEquals("mysession2", info
.getName());
732 assertNotNull(info
.getSessionPath());
733 assertTrue(info
.getSessionPath().contains("mysession2"));
734 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
735 } catch (ExecutionException e
) {
741 public void testCreateSessionVariants() {
743 fShell
.setScenario(SCEN_CREATE_SESSION_VARIANTS
);
746 fService
.createSession("alreadyExist", null, new NullProgressMonitor());
747 fail("No exeption thrown");
748 } catch (ExecutionException e
) {
753 fService
.createSession("wrongName", null, new NullProgressMonitor());
754 fail("No exeption thrown");
755 } catch (ExecutionException e
) {
760 fService
.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
761 fail("No exeption thrown");
762 } catch (ExecutionException e
) {
767 ISessionInfo info
= fService
.createSession("session with spaces", null, new NullProgressMonitor());
769 assertEquals("session with spaces", info
.getName());
770 assertNotNull(info
.getSessionPath());
771 assertTrue(info
.getSessionPath().contains("session with spaces"));
772 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
774 } catch (ExecutionException e
) {
779 ISessionInfo info
= fService
.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
781 assertEquals("pathWithSpaces", info
.getName());
782 assertNotNull(info
.getSessionPath());
783 assertTrue(info
.getSessionPath().contains("/home/user/hallo user/here"));
784 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
786 } catch (ExecutionException e
) {
792 public void testDestroySession() {
794 fShell
.setScenario(SCEN_DESTROY_SESSION1
);
795 fService
.destroySession("mysession2", new NullProgressMonitor());
796 } catch (ExecutionException e
) {
802 public void testDestroySessionVerbose() {
805 fShell
.setScenario(SCEN_DESTROY_SESSION_VERBOSE
);
806 fService
.destroySession("mysession2", new NullProgressMonitor());
807 } catch (ExecutionException e
) {
815 public void testCreateChannel() {
817 ((LTTngControlService
)fService
).setVersion("2.2.0");
818 String sessionName
= "mysession2";
819 List
<String
> list
= new ArrayList
<String
>();
820 String kernelChannel0
= "mychannel0";
821 String kernelChannel1
= "mychannel1";
822 list
.add(kernelChannel0
);
823 list
.add(kernelChannel1
);
825 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
827 // Create/enable/configure 2 kernel channels
828 ChannelInfo chanInfo
= new ChannelInfo("");
829 chanInfo
.setOverwriteMode(true);
830 chanInfo
.setSubBufferSize(16384);
831 chanInfo
.setReadTimer(100);
832 chanInfo
.setSwitchTimer(200);
833 chanInfo
.setNumberOfSubBuffers(2);
834 chanInfo
.setMaxNumberTraceFiles(10);
835 chanInfo
.setMaxSizeTraceFiles(0);
836 fService
.enableChannels(sessionName
, list
, true, chanInfo
, new NullProgressMonitor());
838 // Create/enable/configure 1 UST channel
840 list
.add("ustChannel");
842 chanInfo
= new ChannelInfo("");
843 chanInfo
.setOverwriteMode(true);
844 chanInfo
.setSubBufferSize(32768);
845 chanInfo
.setReadTimer(200);
846 chanInfo
.setSwitchTimer(100);
847 chanInfo
.setNumberOfSubBuffers(1);
848 chanInfo
.setMaxNumberTraceFiles(20);
849 chanInfo
.setMaxSizeTraceFiles(0);
850 fService
.enableChannels(sessionName
, list
, false, chanInfo
, new NullProgressMonitor());
851 ((LTTngControlService
)fService
).setVersion("2.0.0");
853 } catch (ExecutionException e
) {
859 public void testCreateChannelUIDBuffer() {
861 ((LTTngControlService
)fService
).setVersion("2.2.0");
862 String sessionName
= "mysession2";
863 List
<String
> list
= new ArrayList
<String
>();
864 String USTChannel
= "ustChannel";
865 list
.add(USTChannel
);
866 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
868 ChannelInfo chanInfo
= new ChannelInfo("");
869 chanInfo
.setOverwriteMode(true);
870 chanInfo
.setSubBufferSize(32768);
871 chanInfo
.setReadTimer(200);
872 chanInfo
.setSwitchTimer(100);
873 chanInfo
.setNumberOfSubBuffers(1);
874 chanInfo
.setMaxNumberTraceFiles(20);
875 chanInfo
.setMaxSizeTraceFiles(0);
876 chanInfo
.setBufferType(BufferType
.BUFFER_PER_UID
);
877 fService
.enableChannels(sessionName
, list
, false, chanInfo
, new NullProgressMonitor());
878 ((LTTngControlService
)fService
).setVersion("2.0.0");
880 } catch (ExecutionException e
) {
886 public void testCreateChannelPIDBuffer() {
888 ((LTTngControlService
)fService
).setVersion("2.2.0");
889 String sessionName
= "mysession2";
890 List
<String
> list
= new ArrayList
<String
>();
891 String USTChannel
= "ustChannel";
892 list
.add(USTChannel
);
893 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
896 ChannelInfo chanInfo
= new ChannelInfo("");
897 chanInfo
.setOverwriteMode(true);
898 chanInfo
.setSubBufferSize(-1);
899 chanInfo
.setReadTimer(-1);
900 chanInfo
.setSwitchTimer(-1);
901 chanInfo
.setNumberOfSubBuffers(-1);
902 chanInfo
.setMaxNumberTraceFiles(-1);
903 chanInfo
.setMaxSizeTraceFiles(-1);
904 chanInfo
.setBufferType(BufferType
.BUFFER_PER_PID
);
906 fService
.enableChannels(sessionName
, list
, false, chanInfo
, new NullProgressMonitor());
907 ((LTTngControlService
)fService
).setVersion("2.0.0");
909 } catch (ExecutionException e
) {
915 public void testDisableChannel() {
918 String sessionName
= "mysession2";
919 List
<String
> list
= new ArrayList
<String
>();
920 String kernelChannel0
= "mychannel0";
921 String kernelChannel1
= "mychannel1";
922 list
.add(kernelChannel0
);
923 list
.add(kernelChannel1
);
925 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
926 fService
.disableChannels(sessionName
, list
, true, new NullProgressMonitor());
929 list
.add("ustChannel");
930 fService
.disableChannels(sessionName
, list
, false, new NullProgressMonitor());
932 } catch (ExecutionException e
) {
938 public void testEnableChannel() {
941 String sessionName
= "mysession2";
942 List
<String
> list
= new ArrayList
<String
>();
943 String kernelChannel0
= "mychannel0";
944 String kernelChannel1
= "mychannel1";
945 list
.add(kernelChannel0
);
946 list
.add(kernelChannel1
);
948 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
949 fService
.enableChannels(sessionName
, list
, true, null, new NullProgressMonitor());
951 // Create/enable/configure 1 UST channel
953 list
.add("ustChannel");
955 fService
.enableChannels(sessionName
, list
, false, null, new NullProgressMonitor());
957 } catch (ExecutionException e
) {
963 public void testEnableEvents() {
965 // 1) session name, channel = null, 3 event names, kernel
966 String sessionName
= "mysession2";
967 List
<String
> list
= new ArrayList
<String
>();
968 String eventName0
= "block_rq_remap";
969 String eventName1
= "block_bio_remap";
970 String eventName2
= "softirq_entry";
971 list
.add(eventName0
);
972 list
.add(eventName1
);
973 list
.add(eventName2
);
974 fShell
.setScenario(SCEN_EVENT_HANDLING
);
975 fService
.enableEvents(sessionName
, null, list
, true, null, new NullProgressMonitor());
977 // 2) session name, channel=mychannel, event name= null, kernel
978 String channelName
= "mychannel";
979 fService
.enableEvents(sessionName
, channelName
, null, true, null, new NullProgressMonitor());
981 // 3) session name, channel=mychannel, 1 event name, ust, no filter
982 String ustEventName
= "ust_tests_hello:tptest_sighandler";
984 list
.add(ustEventName
);
985 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
987 // 4) session name, channel = mychannel, no event name, ust, with filter
988 fService
.enableEvents(sessionName
, channelName
, list
, false, "intfield==10", new NullProgressMonitor());
990 // 5) session name, channel = mychannel, no event name, ust, no filter
992 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
994 // TODO add test with filters
996 } catch (ExecutionException e
) {
1002 public void testEnableSyscalls() {
1004 // 1) session name, channel = null, 3 event names, kernel
1005 String sessionName
= "mysession2";
1006 String channelName
= "mychannel";
1008 fShell
.setScenario(SCEN_EVENT_HANDLING
);
1010 // 1) session name, channel = null
1011 fService
.enableSyscalls(sessionName
, null, new NullProgressMonitor());
1013 // 2) session name, channel = mychannel
1014 fService
.enableSyscalls(sessionName
, channelName
, new NullProgressMonitor());
1016 } catch (ExecutionException e
) {
1022 public void testDynamicProbe() {
1024 // 1) session name, channel = null, 3 event names, kernel
1025 String sessionName
= "mysession2";
1026 String channelName
= "mychannel";
1027 String eventName0
= "myevent0";
1028 String eventName1
= "myevent1";
1029 String functionProbe
= "0xc0101340";
1030 String dynProbe
= "init_post";
1032 fShell
.setScenario(SCEN_EVENT_HANDLING
);
1034 // 1) session name, channel = null, event name, function probe, probe
1035 fService
.enableProbe(sessionName
, null, eventName0
, true, functionProbe
, new NullProgressMonitor());
1037 // 2) session name, channel = mychannel
1038 fService
.enableProbe(sessionName
, channelName
, eventName1
, false, dynProbe
, new NullProgressMonitor());
1040 } catch (ExecutionException e
) {
1046 public void testEnableLogLevel() {
1048 // 1) session name, channel = null, 3 event names, kernel
1049 String sessionName
= "mysession2";
1050 String channelName
= "mychannel";
1051 String eventName4
= "myevent4";
1052 String eventName5
= "myevent5";
1054 fShell
.setScenario(SCEN_EVENT_HANDLING
);
1056 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1057 fService
.enableLogLevel(sessionName
, null, eventName4
, LogLevelType
.LOGLEVEL_ONLY
, TraceLogLevel
.TRACE_DEBUG
, null, new NullProgressMonitor());
1059 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
1060 fService
.enableLogLevel(sessionName
, channelName
, eventName5
, LogLevelType
.LOGLEVEL
, TraceLogLevel
.TRACE_DEBUG_FUNCTION
, null, new NullProgressMonitor());
1062 // TODO add test with filters
1064 } catch (ExecutionException e
) {
1070 public void testAddContext() {
1072 // 1) session name, channel = null, 3 event names, kernel
1073 String sessionName
= "mysession2";
1074 String channelName
= "mychannel";
1075 String eventName
= "ust_tests_hello:tptest_sighandler";
1076 List
<String
> contexts
= new ArrayList
<String
>();
1077 contexts
.add("prio");
1078 contexts
.add("pid");
1080 fShell
.setScenario(SCEN_CONTEXT_HANDLING
);
1082 List
<String
> availContexts
= fService
.getContextList(new NullProgressMonitor());
1083 assertNotNull(availContexts
);
1084 assertEquals(12, availContexts
.size());
1086 // A very "hard-coded" way to verify but it works ...
1087 Set
<String
> expectedContexts
= new HashSet
<String
>();
1088 expectedContexts
.add("pid");
1089 expectedContexts
.add("procname");
1090 expectedContexts
.add("prio");
1091 expectedContexts
.add("nice");
1092 expectedContexts
.add("vpid");
1093 expectedContexts
.add("tid");
1094 expectedContexts
.add("pthread_id");
1095 expectedContexts
.add("vtid");
1096 expectedContexts
.add("ppid");
1097 expectedContexts
.add("vppid");
1098 expectedContexts
.add("perf:cpu-cycles");
1099 expectedContexts
.add("perf:cycles");
1101 assertTrue(expectedContexts
.containsAll(availContexts
));
1103 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1104 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
1106 } catch (ExecutionException e
) {
1112 public void testAddContextFailure() {
1114 // 1) session name, channel = null, 3 event names, kernel
1115 String sessionName
= "mysession2";
1116 String channelName
= "mychannel";
1117 String eventName
= "ust_tests_hello:tptest_sighandler";
1118 List
<String
> contexts
= new ArrayList
<String
>();
1119 contexts
.add("prio");
1120 contexts
.add("pid");
1121 fShell
.setScenario(SCEN_CONTEXT_ERROR_HANDLING
);
1123 fService
.getContextList(new NullProgressMonitor());
1124 fail("No exeption generated");
1125 } catch (ExecutionException e
) {
1129 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1130 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
1131 fail("No exeption generated");
1132 } catch (ExecutionException e
) {
1138 public void testCalibrate() {
1140 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
1141 fService
.calibrate(true, new NullProgressMonitor());
1143 } catch (ExecutionException e
) {
1149 public void testCalibrateFailure() {
1151 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
1152 fService
.calibrate(false, new NullProgressMonitor());
1153 fail("No exeption generated");
1154 } catch (ExecutionException e
) {
1160 public void testCreateSession2_1() {
1163 fShell
.setScenario(SCEN_CREATE_SESSION_2_1
);
1165 ISessionInfo info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1166 assertNotNull(info
);
1167 assertEquals("mysession", info
.getName());
1168 assertEquals("net://172.0.0.1", info
.getSessionPath());
1169 assertTrue(info
.isStreamedTrace());
1170 fService
.destroySession("mysession", new NullProgressMonitor());
1172 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
1173 assertNotNull(info
);
1174 assertEquals("mysession", info
.getName());
1175 assertEquals("file:///tmp", info
.getSessionPath());
1176 assertTrue(!info
.isStreamedTrace());
1177 fService
.destroySession("mysession", new NullProgressMonitor());
1179 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
1180 assertNotNull(info
);
1181 assertEquals("mysession", info
.getName());
1182 assertEquals("file:///tmp", info
.getSessionPath());
1183 assertTrue(!info
.isStreamedTrace());
1184 fService
.destroySession("mysession", new NullProgressMonitor());
1186 info
= fService
.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
1187 assertNotNull(info
);
1188 assertEquals("mysession", info
.getName());
1189 assertEquals("", info
.getSessionPath()); // the complete network path is not available at this point
1190 assertTrue(info
.isStreamedTrace());
1191 fService
.destroySession("mysession", new NullProgressMonitor());
1193 info
= fService
.createSession("mysession", "net://172.0.0.1:1234:2345", null, null, new NullProgressMonitor());
1194 assertNotNull(info
);
1195 assertEquals("mysession", info
.getName());
1196 assertEquals("net://172.0.0.1:1234:2345", info
.getSessionPath());
1197 assertTrue(info
.isStreamedTrace());
1198 fService
.destroySession("mysession", new NullProgressMonitor());
1202 info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1203 assertNotNull(info
);
1204 assertEquals("mysession", info
.getName());
1205 assertEquals("net://172.0.0.1", info
.getSessionPath());
1206 assertTrue(info
.isStreamedTrace());
1208 fService
.destroySession("mysession", new NullProgressMonitor());
1211 } catch (ExecutionException e
) {
1217 public void testCreateSessionVerbose2_1() {
1219 fShell
.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1
);
1222 ISessionInfo info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1223 assertNotNull(info
);
1224 assertEquals("mysession", info
.getName());
1225 assertEquals("net://172.0.0.1", info
.getSessionPath());
1226 assertTrue(info
.isStreamedTrace());
1227 fService
.destroySession("mysession", new NullProgressMonitor());
1228 } catch (ExecutionException e
) {
1235 private static void enableVerbose() {
1237 ControlCommandLogger
.init(ControlPreferences
.getInstance().getLogfilePath(), false);
1238 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
, true);
1239 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_PREF
, ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
);
1242 private static void disableVerbose() {
1243 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
, false);