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({"nls", "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_CREATE_SESSION1
= "CreateSession1";
87 private static final String SCEN_CREATE_SESSION_WITH_PROMPT
= "CreateSessionWithPrompt";
88 private static final String SCEN_CREATE_SESSION_VARIANTS
= "CreateSessionVariants";
89 private static final String SCEN_DESTROY_SESSION1
= "DestroySession1";
90 private static final String SCEN_DESTROY_SESSION_VERBOSE
= "DestroySessionVerbose";
91 private static final String SCEN_CHANNEL_HANDLING
= "ChannelHandling";
92 private static final String SCEN_EVENT_HANDLING
= "EventHandling";
93 private static final String SCEN_CONTEXT_HANDLING
= "ContextHandling";
94 private static final String SCEN_CONTEXT_ERROR_HANDLING
= "ContextErrorHandling";
95 private static final String SCEN_CALIBRATE_HANDLING
= "CalibrateHandling";
96 private static final String SCEN_CREATE_SESSION_2_1
= "CreateSessionLttng2.1";
97 private static final String SCEN_CREATE_SESSION_VERBOSE_2_1
= "CreateSessionLttngVerbose2.1";
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
103 private CommandShellFactory fShellFactory
;
104 private String fTestfile
;
105 private LTTngToolsFileShell fShell
;
106 private ILttngControlService fService
;
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
113 * Perform pre-test initialization.
116 * if the initialization fails for some reason
119 public void setUp() throws Exception
{
120 fShellFactory
= CommandShellFactory
.getInstance();
122 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
123 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
124 fTestfile
= testfile
.getAbsolutePath();
126 fShell
= fShellFactory
.getFileShell();
127 fShell
.loadScenarioFile(fTestfile
);
128 fService
= new LTTngControlService(fShell
);
130 ControlPreferences
.getInstance().init(Activator
.getDefault().getPreferenceStore());
134 public void tearDown() {
136 ControlPreferences
.getInstance().dispose();
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
144 public void testVersion() {
146 fShell
.setScenario(SCEN_LTTNG_VERSION
);
147 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
148 assertNotNull(service
);
149 assertEquals("2.1.0", service
.getVersion());
150 } catch (ExecutionException e
) {
151 fail("Exeption thrown " + e
);
156 public void testVersionWithPrompt() {
158 fShell
.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT
);
159 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
160 assertNotNull(service
);
161 assertEquals("2.0.0", service
.getVersion());
162 } catch (ExecutionException e
) {
163 fail("Exeption thrown " + e
);
168 public void testUnsupportedVersion() {
170 fShell
.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION
);
171 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
172 fail("No exeption thrown");
173 } catch (ExecutionException e
) {
179 public void testNoVersion() {
181 fShell
.setScenario(SCEN_LTTNG_NO_VERSION
);
182 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
183 fail("No exeption thrown");
184 } catch (ExecutionException e
) {
190 public void testLttngNotInstalled() {
192 fShell
.setScenario(SCEN_LTTNG_NOT_INSTALLED
);
193 fService
.getSessionNames(new NullProgressMonitor());
194 fail("No exeption thrown");
195 } catch (ExecutionException e
) {
201 public void testGetSessionNames1() {
203 fShell
.setScenario(SCEN_NO_SESSION_AVAILABLE
);
204 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
206 assertNotNull(result
);
207 assertEquals(0, result
.length
);
209 } catch (ExecutionException e
) {
215 public void testGetSessionNames2() {
217 fShell
.setScenario(SCEN_GET_SESSION_NAMES1
);
218 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
220 assertNotNull(result
);
221 assertEquals(2, result
.length
);
222 assertEquals("mysession1", result
[0]);
223 assertEquals("mysession", result
[1]);
225 } catch (ExecutionException e
) {
231 public void testGetSessionNotExist() {
233 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST
);
234 fService
.getSessionNames(new NullProgressMonitor());
235 fail("No exeption thrown");
237 } catch (ExecutionException e
) {
243 public void testGetSessionNotExistVerbose() {
246 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE
);
247 fService
.getSessionNames(new NullProgressMonitor());
248 fail("No exeption thrown");
250 } catch (ExecutionException e
) {
258 public void testGetSessionNameGarbage() {
260 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
261 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
263 assertNotNull(result
);
264 assertEquals(0, result
.length
);
266 } catch (ExecutionException e
) {
272 public void testGetSession1() {
274 fShell
.setScenario(SCEN_GET_SESSION1
);
275 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
278 assertNotNull(session
);
279 assertEquals("mysession", session
.getName());
280 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
281 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
283 IDomainInfo
[] domains
= session
.getDomains();
284 assertNotNull(domains
);
285 assertEquals(2, domains
.length
);
287 // Verify Kernel domain
288 assertEquals("Kernel", domains
[0].getName());
289 IChannelInfo
[] channels
= domains
[0].getChannels();
290 assertNotNull(channels
);
291 assertEquals(2, channels
.length
);
293 // Verify Kernel's channel0
294 assertEquals("channel0", channels
[0].getName());
295 assertEquals(4, channels
[0].getNumberOfSubBuffers());
296 assertEquals("splice()", channels
[0].getOutputType());
297 assertEquals(false, channels
[0].isOverwriteMode());
298 assertEquals(200, channels
[0].getReadTimer());
299 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
300 assertEquals(262144, channels
[0].getSubBufferSize());
301 assertEquals(0, channels
[0].getSwitchTimer());
304 IEventInfo
[] channel0Events
= channels
[0].getEvents();
305 assertNotNull(channel0Events
);
306 assertEquals(2, channel0Events
.length
);
307 assertEquals("block_rq_remap", channel0Events
[0].getName());
308 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[0].getLogLevel());
309 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[0].getEventType());
310 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
312 assertEquals("block_bio_remap", channel0Events
[1].getName());
313 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
314 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
315 assertEquals(TraceEnablement
.DISABLED
, channel0Events
[1].getState());
317 // Verify Kernel's channel1
318 assertEquals("channel1", channels
[1].getName());
319 assertEquals(4, channels
[1].getNumberOfSubBuffers());
320 assertEquals("splice()", channels
[1].getOutputType());
321 assertEquals(true, channels
[1].isOverwriteMode());
322 assertEquals(400, channels
[1].getReadTimer());
323 assertEquals(TraceEnablement
.DISABLED
, channels
[1].getState());
324 assertEquals(524288, channels
[1].getSubBufferSize());
325 assertEquals(100, channels
[1].getSwitchTimer());
328 IEventInfo
[] channel1Events
= channels
[1].getEvents();
329 assertEquals(0, channel1Events
.length
);
331 // Verify domain UST global
332 assertEquals("UST global", domains
[1].getName());
334 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
336 // Verify UST global's mychannel1
337 assertEquals("mychannel1", ustChannels
[0].getName());
338 assertEquals(8, ustChannels
[0].getNumberOfSubBuffers());
339 assertEquals("mmap()", ustChannels
[0].getOutputType());
340 assertEquals(true, ustChannels
[0].isOverwriteMode());
341 assertEquals(100, ustChannels
[0].getReadTimer());
342 assertEquals(TraceEnablement
.DISABLED
, ustChannels
[0].getState());
343 assertEquals(8192, ustChannels
[0].getSubBufferSize());
344 assertEquals(200, ustChannels
[0].getSwitchTimer());
347 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
348 assertEquals(0, ustEvents
.length
);
350 // Verify UST global's channel0
351 assertEquals("channel0", ustChannels
[1].getName());
352 assertEquals(4, ustChannels
[1].getNumberOfSubBuffers());
353 assertEquals("mmap()", ustChannels
[1].getOutputType());
354 assertEquals(false, ustChannels
[1].isOverwriteMode());
355 assertEquals(200, ustChannels
[1].getReadTimer());
356 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[1].getState());
357 assertEquals(4096, ustChannels
[1].getSubBufferSize());
358 assertEquals(0, ustChannels
[1].getSwitchTimer());
361 ustEvents
= ustChannels
[1].getEvents();
362 assertEquals(2, ustEvents
.length
);
364 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents
[0].getName());
365 assertEquals(TraceLogLevel
.TRACE_DEBUG_LINE
, ustEvents
[0].getLogLevel());
366 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
367 assertEquals(TraceEnablement
.DISABLED
, ustEvents
[0].getState());
369 assertEquals("*", ustEvents
[1].getName());
370 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, ustEvents
[1].getLogLevel());
371 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[1].getEventType());
372 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[1].getState());
374 // next session (no detailed information available)
375 session
= fService
.getSession("mysession1", new NullProgressMonitor());
376 assertNotNull(session
);
377 assertEquals("mysession1", session
.getName());
378 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session
.getSessionPath());
379 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
381 domains
= session
.getDomains();
382 assertNotNull(domains
);
383 assertEquals(0, domains
.length
);
384 } catch (ExecutionException e
) {
389 public void testGetKernelProvider() {
391 fShell
.setScenario(SCEN_GET_KERNEL_PROVIDER1
);
392 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
395 assertNotNull(events
);
396 assertEquals(3, events
.size());
398 IBaseEventInfo baseEventInfo
= events
.get(0);
399 assertNotNull(baseEventInfo
);
400 assertEquals("sched_kthread_stop", baseEventInfo
.getName());
401 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
402 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
404 baseEventInfo
= events
.get(1);
405 assertEquals("sched_kthread_stop_ret", baseEventInfo
.getName());
406 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
407 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
409 baseEventInfo
= events
.get(2);
410 assertEquals("sched_wakeup_new", baseEventInfo
.getName());
411 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
412 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
414 } catch (ExecutionException e
) {
420 public void testGetKernelProviderNoKernel1() {
422 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL1
);
423 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
426 assertNotNull(events
);
427 assertEquals(0, events
.size());
429 } catch (ExecutionException e
) {
435 public void testGetKernelProviderNoKernel2() {
437 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL2
);
438 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
441 assertNotNull(events
);
442 assertEquals(0, events
.size());
444 } catch (ExecutionException e
) {
450 public void testGetKernelProviderNoKernelVerbose() {
453 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE
);
454 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
457 assertNotNull(events
);
458 assertEquals(0, events
.size());
460 } catch (ExecutionException e
) {
468 public void testGetUstProvider() {
470 fShell
.setScenario(SCEN_GET_UST_PROVIDER1
);
471 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
473 // Check all providers
474 assertNotNull(providers
);
475 assertEquals(2, providers
.size());
477 //Verify first provider
478 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
479 assertEquals(9379, providers
.get(0).getPid());
482 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
483 assertNotNull(events
);
484 assertEquals(2, events
.length
);
486 IBaseEventInfo baseEventInfo
= events
[0];
487 assertNotNull(baseEventInfo
);
488 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
489 assertEquals(TraceLogLevel
.TRACE_DEBUG_MODULE
, baseEventInfo
.getLogLevel());
490 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
492 baseEventInfo
= events
[1];
493 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
494 assertEquals(TraceLogLevel
.TRACE_INFO
, baseEventInfo
.getLogLevel());
495 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
497 //Verify second provider
498 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
499 assertEquals(4852, providers
.get(1).getPid());
502 events
= providers
.get(1).getEvents();
503 assertNotNull(events
);
504 assertEquals(2, events
.length
);
506 baseEventInfo
= events
[0];
507 assertNotNull(baseEventInfo
);
508 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
509 assertEquals(TraceLogLevel
.TRACE_WARNING
, baseEventInfo
.getLogLevel());
510 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
512 baseEventInfo
= events
[1];
513 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
514 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, baseEventInfo
.getLogLevel());
515 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
517 } catch (ExecutionException e
) {
523 public void testUstProvider2() {
525 fShell
.setScenario(SCEN_GET_UST_PROVIDER2
);
526 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
528 assertNotNull(providers
);
529 assertEquals(0, providers
.size());
531 } catch (ExecutionException e
) {
537 public void testGetUstProvider3() {
539 fShell
.setScenario(SCEN_GET_UST_PROVIDER3
);
541 ((LTTngControlService
)fService
).setVersion("2.1.0");
542 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
544 // Check all providers
545 assertNotNull(providers
);
546 assertEquals(2, providers
.size());
548 //Verify first provider
549 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
550 assertEquals(9379, providers
.get(0).getPid());
553 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
554 assertNotNull(events
);
555 assertEquals(2, events
.length
);
557 IBaseEventInfo baseEventInfo
= events
[0];
558 assertNotNull(baseEventInfo
);
559 IFieldInfo
[] fields
= baseEventInfo
.getFields();
560 assertNotNull(fields
);
561 assertEquals(0, fields
.length
);
563 baseEventInfo
= events
[1];
564 fields
= baseEventInfo
.getFields();
565 assertNotNull(fields
);
566 assertEquals(3, fields
.length
);
567 assertEquals("doublefield", fields
[0].getName());
568 assertEquals("float", fields
[0].getFieldType());
570 assertEquals("floatfield", fields
[1].getName());
571 assertEquals("float", fields
[1].getFieldType());
573 assertEquals("stringfield", fields
[2].getName());
574 assertEquals("string", fields
[2].getFieldType());
576 //Verify second provider
577 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
578 assertEquals(4852, providers
.get(1).getPid());
581 events
= providers
.get(1).getEvents();
582 assertNotNull(events
);
583 assertEquals(2, events
.length
);
585 baseEventInfo
= events
[0];
586 assertNotNull(baseEventInfo
);
587 fields
= baseEventInfo
.getFields();
588 assertNotNull(fields
);
589 assertEquals(0, fields
.length
);
591 baseEventInfo
= events
[1];
592 fields
= baseEventInfo
.getFields();
593 assertNotNull(fields
);
594 assertEquals(3, fields
.length
);
596 assertEquals("doublefield", fields
[0].getName());
597 assertEquals("float", fields
[0].getFieldType());
599 assertEquals("floatfield", fields
[1].getName());
600 assertEquals("float", fields
[1].getFieldType());
602 assertEquals("stringfield", fields
[2].getName());
603 assertEquals("string", fields
[2].getFieldType());
606 ((LTTngControlService
)fService
).setVersion("2.0.0");
608 } catch (ExecutionException e
) {
614 public void testCreateSession() {
616 fShell
.setScenario(SCEN_CREATE_SESSION1
);
618 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
620 assertEquals("mysession2", info
.getName());
621 assertNotNull(info
.getSessionPath());
622 assertTrue(info
.getSessionPath().contains("mysession2"));
623 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
624 } catch (ExecutionException e
) {
630 public void testCreateSessionWithPrompt() {
632 // First line has the shell prompt before the command output
633 // This can happen in a real application if the command line is not echoed by the shell.
634 fShell
.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT
);
636 // First line has no shell prompt before the output
637 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
639 assertEquals("mysession2", info
.getName());
640 assertNotNull(info
.getSessionPath());
641 assertTrue(info
.getSessionPath().contains("mysession2"));
642 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
643 } catch (ExecutionException e
) {
649 public void testCreateSessionVariants() {
651 fShell
.setScenario(SCEN_CREATE_SESSION_VARIANTS
);
654 fService
.createSession("alreadyExist", null, new NullProgressMonitor());
655 fail("No exeption thrown");
656 } catch (ExecutionException e
) {
661 fService
.createSession("wrongName", null, new NullProgressMonitor());
662 fail("No exeption thrown");
663 } catch (ExecutionException e
) {
668 fService
.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
669 fail("No exeption thrown");
670 } catch (ExecutionException e
) {
675 ISessionInfo info
= fService
.createSession("session with spaces", null, new NullProgressMonitor());
677 assertEquals("session with spaces", info
.getName());
678 assertNotNull(info
.getSessionPath());
679 assertTrue(info
.getSessionPath().contains("session with spaces"));
680 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
682 } catch (ExecutionException e
) {
687 ISessionInfo info
= fService
.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
689 assertEquals("pathWithSpaces", info
.getName());
690 assertNotNull(info
.getSessionPath());
691 assertTrue(info
.getSessionPath().contains("/home/user/hallo user/here"));
692 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
694 } catch (ExecutionException e
) {
700 public void testDestroySession() {
702 fShell
.setScenario(SCEN_DESTROY_SESSION1
);
703 fService
.destroySession("mysession2", new NullProgressMonitor());
704 } catch (ExecutionException e
) {
710 public void testDestroySessionVerbose() {
713 fShell
.setScenario(SCEN_DESTROY_SESSION_VERBOSE
);
714 fService
.destroySession("mysession2", new NullProgressMonitor());
715 } catch (ExecutionException e
) {
723 public void testCreateChannel() {
726 String sessionName
= "mysession2";
727 List
<String
> list
= new ArrayList
<String
>();
728 String kernelChannel0
= "mychannel0";
729 String kernelChannel1
= "mychannel1";
730 list
.add(kernelChannel0
);
731 list
.add(kernelChannel1
);
733 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
735 // Create/enable/configure 2 kernel channels
736 ChannelInfo chanInfo
= new ChannelInfo("");
737 chanInfo
.setOverwriteMode(true);
738 chanInfo
.setSubBufferSize(16384);
739 chanInfo
.setReadTimer(100);
740 chanInfo
.setSwitchTimer(200);
741 chanInfo
.setNumberOfSubBuffers(2);
742 fService
.enableChannels(sessionName
, list
, true, chanInfo
, new NullProgressMonitor());
744 // Create/enable/configure 1 UST channel
746 list
.add("ustChannel");
748 chanInfo
= new ChannelInfo("");
749 chanInfo
.setOverwriteMode(true);
750 chanInfo
.setSubBufferSize(32768);
751 chanInfo
.setReadTimer(200);
752 chanInfo
.setSwitchTimer(100);
753 chanInfo
.setNumberOfSubBuffers(1);
754 fService
.enableChannels(sessionName
, list
, false, chanInfo
, new NullProgressMonitor());
756 } catch (ExecutionException e
) {
762 public void testDisableChannel() {
765 String sessionName
= "mysession2";
766 List
<String
> list
= new ArrayList
<String
>();
767 String kernelChannel0
= "mychannel0";
768 String kernelChannel1
= "mychannel1";
769 list
.add(kernelChannel0
);
770 list
.add(kernelChannel1
);
772 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
773 fService
.disableChannels(sessionName
, list
, true, new NullProgressMonitor());
776 list
.add("ustChannel");
777 fService
.disableChannels(sessionName
, list
, false, new NullProgressMonitor());
779 } catch (ExecutionException e
) {
785 public void testEnableChannel() {
788 String sessionName
= "mysession2";
789 List
<String
> list
= new ArrayList
<String
>();
790 String kernelChannel0
= "mychannel0";
791 String kernelChannel1
= "mychannel1";
792 list
.add(kernelChannel0
);
793 list
.add(kernelChannel1
);
795 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
796 fService
.enableChannels(sessionName
, list
, true, null, new NullProgressMonitor());
798 // Create/enable/configure 1 UST channel
800 list
.add("ustChannel");
802 fService
.enableChannels(sessionName
, list
, false, null, new NullProgressMonitor());
804 } catch (ExecutionException e
) {
810 public void testEnableEvents() {
812 // 1) session name, channel = null, 3 event names, kernel
813 String sessionName
= "mysession2";
814 List
<String
> list
= new ArrayList
<String
>();
815 String eventName0
= "block_rq_remap";
816 String eventName1
= "block_bio_remap";
817 String eventName2
= "softirq_entry";
818 list
.add(eventName0
);
819 list
.add(eventName1
);
820 list
.add(eventName2
);
821 fShell
.setScenario(SCEN_EVENT_HANDLING
);
822 fService
.enableEvents(sessionName
, null, list
, true, null, new NullProgressMonitor());
824 // 2) session name, channel=mychannel, event name= null, kernel
825 String channelName
= "mychannel";
826 fService
.enableEvents(sessionName
, channelName
, null, true, null, new NullProgressMonitor());
828 // 3) session name, channel=mychannel, 1 event name, ust, no filter
829 String ustEventName
= "ust_tests_hello:tptest_sighandler";
831 list
.add(ustEventName
);
832 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
834 // 4) session name, channel = mychannel, no event name, ust, with filter
835 fService
.enableEvents(sessionName
, channelName
, list
, false, "intfield==10", new NullProgressMonitor());
837 // 5) session name, channel = mychannel, no event name, ust, no filter
839 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
841 // TODO add test with filters
843 } catch (ExecutionException e
) {
849 public void testEnableSyscalls() {
851 // 1) session name, channel = null, 3 event names, kernel
852 String sessionName
= "mysession2";
853 String channelName
= "mychannel";
855 fShell
.setScenario(SCEN_EVENT_HANDLING
);
857 // 1) session name, channel = null
858 fService
.enableSyscalls(sessionName
, null, new NullProgressMonitor());
860 // 2) session name, channel = mychannel
861 fService
.enableSyscalls(sessionName
, channelName
, new NullProgressMonitor());
863 } catch (ExecutionException e
) {
869 public void testDynamicProbe() {
871 // 1) session name, channel = null, 3 event names, kernel
872 String sessionName
= "mysession2";
873 String channelName
= "mychannel";
874 String eventName0
= "myevent0";
875 String eventName1
= "myevent1";
876 String functionProbe
= "0xc0101340";
877 String dynProbe
= "init_post";
879 fShell
.setScenario(SCEN_EVENT_HANDLING
);
881 // 1) session name, channel = null, event name, function probe, probe
882 fService
.enableProbe(sessionName
, null, eventName0
, true, functionProbe
, new NullProgressMonitor());
884 // 2) session name, channel = mychannel
885 fService
.enableProbe(sessionName
, channelName
, eventName1
, false, dynProbe
, new NullProgressMonitor());
887 } catch (ExecutionException e
) {
893 public void testEnableLogLevel() {
895 // 1) session name, channel = null, 3 event names, kernel
896 String sessionName
= "mysession2";
897 String channelName
= "mychannel";
898 String eventName4
= "myevent4";
899 String eventName5
= "myevent5";
901 fShell
.setScenario(SCEN_EVENT_HANDLING
);
903 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
904 fService
.enableLogLevel(sessionName
, null, eventName4
, LogLevelType
.LOGLEVEL_ONLY
, TraceLogLevel
.TRACE_DEBUG
, null, new NullProgressMonitor());
906 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
907 fService
.enableLogLevel(sessionName
, channelName
, eventName5
, LogLevelType
.LOGLEVEL
, TraceLogLevel
.TRACE_DEBUG_FUNCTION
, null, new NullProgressMonitor());
909 // TODO add test with filters
911 } catch (ExecutionException e
) {
917 public void testAddContext() {
919 // 1) session name, channel = null, 3 event names, kernel
920 String sessionName
= "mysession2";
921 String channelName
= "mychannel";
922 String eventName
= "ust_tests_hello:tptest_sighandler";
923 List
<String
> contexts
= new ArrayList
<String
>();
924 contexts
.add("prio");
927 fShell
.setScenario(SCEN_CONTEXT_HANDLING
);
929 List
<String
> availContexts
= fService
.getContextList(new NullProgressMonitor());
930 assertNotNull(availContexts
);
931 assertEquals(12, availContexts
.size());
933 // A very "hard-coded" way to verify but it works ...
934 Set
<String
> expectedContexts
= new HashSet
<String
>();
935 expectedContexts
.add("pid");
936 expectedContexts
.add("procname");
937 expectedContexts
.add("prio");
938 expectedContexts
.add("nice");
939 expectedContexts
.add("vpid");
940 expectedContexts
.add("tid");
941 expectedContexts
.add("pthread_id");
942 expectedContexts
.add("vtid");
943 expectedContexts
.add("ppid");
944 expectedContexts
.add("vppid");
945 expectedContexts
.add("perf:cpu-cycles");
946 expectedContexts
.add("perf:cycles");
948 assertTrue(expectedContexts
.containsAll(availContexts
));
950 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
951 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
953 } catch (ExecutionException e
) {
959 public void testAddContextFailure() {
961 // 1) session name, channel = null, 3 event names, kernel
962 String sessionName
= "mysession2";
963 String channelName
= "mychannel";
964 String eventName
= "ust_tests_hello:tptest_sighandler";
965 List
<String
> contexts
= new ArrayList
<String
>();
966 contexts
.add("prio");
968 fShell
.setScenario(SCEN_CONTEXT_ERROR_HANDLING
);
970 fService
.getContextList(new NullProgressMonitor());
971 fail("No exeption generated");
972 } catch (ExecutionException e
) {
976 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
977 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
978 fail("No exeption generated");
979 } catch (ExecutionException e
) {
985 public void testCalibrate() {
987 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
988 fService
.calibrate(true, new NullProgressMonitor());
990 } catch (ExecutionException e
) {
996 public void testCalibrateFailure() {
998 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
999 fService
.calibrate(false, new NullProgressMonitor());
1000 fail("No exeption generated");
1001 } catch (ExecutionException e
) {
1007 public void testCreateSession2_1() {
1010 fShell
.setScenario(SCEN_CREATE_SESSION_2_1
);
1012 ISessionInfo info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1013 assertNotNull(info
);
1014 assertEquals("mysession", info
.getName());
1015 assertEquals("net://172.0.0.1", info
.getSessionPath());
1016 assertTrue(info
.isStreamedTrace());
1017 fService
.destroySession("mysession", new NullProgressMonitor());
1019 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
1020 assertNotNull(info
);
1021 assertEquals("mysession", info
.getName());
1022 assertEquals("file:///tmp", info
.getSessionPath());
1023 assertTrue(!info
.isStreamedTrace());
1024 fService
.destroySession("mysession", new NullProgressMonitor());
1026 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
1027 assertNotNull(info
);
1028 assertEquals("mysession", info
.getName());
1029 assertEquals("file:///tmp", info
.getSessionPath());
1030 assertTrue(!info
.isStreamedTrace());
1031 fService
.destroySession("mysession", new NullProgressMonitor());
1033 info
= fService
.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
1034 assertNotNull(info
);
1035 assertEquals("mysession", info
.getName());
1036 assertEquals("", info
.getSessionPath()); // the complete network path is not available at this point
1037 assertTrue(info
.isStreamedTrace());
1038 fService
.destroySession("mysession", new NullProgressMonitor());
1040 info
= fService
.createSession("mysession", "net://172.0.0.1:1234:2345", null, null, new NullProgressMonitor());
1041 assertNotNull(info
);
1042 assertEquals("mysession", info
.getName());
1043 assertEquals("net://172.0.0.1:1234:2345", info
.getSessionPath());
1044 assertTrue(info
.isStreamedTrace());
1045 fService
.destroySession("mysession", new NullProgressMonitor());
1049 info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1050 assertNotNull(info
);
1051 assertEquals("mysession", info
.getName());
1052 assertEquals("net://172.0.0.1", info
.getSessionPath());
1053 assertTrue(info
.isStreamedTrace());
1055 fService
.destroySession("mysession", new NullProgressMonitor());
1058 } catch (ExecutionException e
) {
1064 public void testCreateSessionVerbose2_1() {
1066 fShell
.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1
);
1069 ISessionInfo info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
1070 assertNotNull(info
);
1071 assertEquals("mysession", info
.getName());
1072 assertEquals("net://172.0.0.1", info
.getSessionPath());
1073 assertTrue(info
.isStreamedTrace());
1074 fService
.destroySession("mysession", new NullProgressMonitor());
1075 } catch (ExecutionException e
) {
1082 private static void enableVerbose() {
1084 ControlCommandLogger
.init(ControlPreferences
.getInstance().getLogfilePath(), false);
1085 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
, true);
1086 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_PREF
, ControlPreferences
.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
);
1089 private static void disableVerbose() {
1090 ControlPreferences
.getInstance().getPreferenceStore().setDefault(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
, false);