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
.*;
20 import java
.util
.ArrayList
;
21 import java
.util
.HashSet
;
22 import java
.util
.List
;
25 import org
.eclipse
.core
.commands
.ExecutionException
;
26 import org
.eclipse
.core
.runtime
.FileLocator
;
27 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.Path
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IBaseEventInfo
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IFieldInfo
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.ISessionInfo
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IUstProviderInfo
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
41 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
42 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.CommandShellFactory
;
43 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.shells
.LTTngToolsFileShell
;
44 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
45 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlService
;
46 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlServiceFactory
;
47 import org
.junit
.Before
;
48 import org
.junit
.Test
;
49 import org
.osgi
.framework
.FrameworkUtil
;
52 * The class <code>LTTngControlServiceTest</code> contains test for the class
53 * <code>{@link LTTngControlService}</code>.
55 @SuppressWarnings({"nls", "javadoc"})
56 public class LTTngControlServiceTest
{
58 private static final String DIRECTORY
= "testfiles";
59 private static final String TEST_STREAM
= "LTTngServiceTest.cfg";
61 private static final String SCEN_LTTNG_NOT_INSTALLED
= "LttngNotInstalled";
62 private static final String SCEN_LTTNG_VERSION
= "LttngVersion";
63 private static final String SCEN_LTTNG_VERSION_WITH_PROMPT
= "LttngVersionWithPrompt";
64 private static final String SCEN_LTTNG_UNSUPPORTED_VERSION
= "LttngUnsupportedVersion";
65 private static final String SCEN_LTTNG_NO_VERSION
= "LttngNoVersion";
66 private static final String SCEN_NO_SESSION_AVAILABLE
= "NoSessionAvailable";
67 private static final String SCEN_GET_SESSION_NAMES1
= "GetSessionNames1";
68 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST
= "GetSessionNameNotExist";
69 private static final String SCEN_GET_SESSION_GARBAGE_OUT
= "GetSessionGarbageOut";
70 private static final String SCEN_GET_SESSION1
= "GetSession1";
71 private static final String SCEN_GET_KERNEL_PROVIDER1
= "GetKernelProvider1";
72 private static final String SCEN_LIST_WITH_NO_KERNEL1
= "ListWithNoKernel1";
73 private static final String SCEN_LIST_WITH_NO_KERNEL2
= "ListWithNoKernel2";
74 private static final String SCEN_GET_UST_PROVIDER1
= "GetUstProvider1";
75 private static final String SCEN_GET_UST_PROVIDER2
= "GetUstProvider2";
76 private static final String SCEN_GET_UST_PROVIDER3
= "GetUstProvider3";
77 private static final String SCEN_CREATE_SESSION1
= "CreateSession1";
78 private static final String SCEN_CREATE_SESSION_WITH_PROMPT
= "CreateSessionWithPrompt";
79 private static final String SCEN_CREATE_SESSION_VARIANTS
= "CreateSessionVariants";
80 private static final String SCEN_DESTROY_SESSION1
= "DestroySession1";
81 private static final String SCEN_CHANNEL_HANDLING
= "ChannelHandling";
82 private static final String SCEN_EVENT_HANDLING
= "EventHandling";
83 private static final String SCEN_CONTEXT_HANDLING
= "ContextHandling";
84 private static final String SCEN_CONTEXT_ERROR_HANDLING
= "ContextErrorHandling";
85 private static final String SCEN_CALIBRATE_HANDLING
= "CalibrateHandling";
86 private static final String SCEN_CREATE_SESSION_2_1
= "CreateSessionLttng2.1";
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
92 private CommandShellFactory fShellFactory
;
93 private String fTestfile
;
94 private LTTngToolsFileShell fShell
;
95 private ILttngControlService fService
;
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
102 * Perform pre-test initialization.
105 * if the initialization fails for some reason
108 public void setUp() throws Exception
{
109 fShellFactory
= CommandShellFactory
.getInstance();
111 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
112 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
113 fTestfile
= testfile
.getAbsolutePath();
115 fShell
= fShellFactory
.getFileShell();
116 fShell
.loadScenarioFile(fTestfile
);
117 fService
= new LTTngControlService(fShell
);
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
125 public void testVersion() {
127 fShell
.setScenario(SCEN_LTTNG_VERSION
);
128 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
129 assertNotNull(service
);
130 assertEquals("2.1.0", service
.getVersion());
131 } catch (ExecutionException e
) {
132 fail("Exeption thrown " + e
);
137 public void testVersionWithPrompt() {
139 fShell
.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT
);
140 ILttngControlService service
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
141 assertNotNull(service
);
142 assertEquals("2.0.0", service
.getVersion());
143 } catch (ExecutionException e
) {
144 fail("Exeption thrown " + e
);
149 public void testUnsupportedVersion() {
151 fShell
.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION
);
152 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
153 fail("No exeption thrown");
154 } catch (ExecutionException e
) {
160 public void testNoVersion() {
162 fShell
.setScenario(SCEN_LTTNG_NO_VERSION
);
163 LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
164 fail("No exeption thrown");
165 } catch (ExecutionException e
) {
171 public void testLttngNotInstalled() {
173 fShell
.setScenario(SCEN_LTTNG_NOT_INSTALLED
);
174 fService
.getSessionNames(new NullProgressMonitor());
175 fail("No exeption thrown");
176 } catch (ExecutionException e
) {
182 public void testGetSessionNames1() {
184 fShell
.setScenario(SCEN_NO_SESSION_AVAILABLE
);
185 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
187 assertNotNull(result
);
188 assertEquals(0, result
.length
);
190 } catch (ExecutionException e
) {
196 public void testGetSessionNames2() {
198 fShell
.setScenario(SCEN_GET_SESSION_NAMES1
);
199 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
201 assertNotNull(result
);
202 assertEquals(2, result
.length
);
203 assertEquals("mysession1", result
[0]);
204 assertEquals("mysession", result
[1]);
206 } catch (ExecutionException e
) {
212 public void testGetSessionNotExist() {
214 fShell
.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST
);
215 fService
.getSessionNames(new NullProgressMonitor());
216 fail("No exeption thrown");
218 } catch (ExecutionException e
) {
224 public void testGetSessionNameGarbage() {
226 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
227 String
[] result
= fService
.getSessionNames(new NullProgressMonitor());
229 assertNotNull(result
);
230 assertEquals(0, result
.length
);
232 } catch (ExecutionException e
) {
238 public void testGetSession1() {
240 fShell
.setScenario(SCEN_GET_SESSION1
);
241 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
244 assertNotNull(session
);
245 assertEquals("mysession", session
.getName());
246 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
247 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
249 IDomainInfo
[] domains
= session
.getDomains();
250 assertNotNull(domains
);
251 assertEquals(2, domains
.length
);
253 // Verify Kernel domain
254 assertEquals("Kernel", domains
[0].getName());
255 IChannelInfo
[] channels
= domains
[0].getChannels();
256 assertNotNull(channels
);
257 assertEquals(2, channels
.length
);
259 // Verify Kernel's channel0
260 assertEquals("channel0", channels
[0].getName());
261 assertEquals(4, channels
[0].getNumberOfSubBuffers());
262 assertEquals("splice()", channels
[0].getOutputType());
263 assertEquals(false, channels
[0].isOverwriteMode());
264 assertEquals(200, channels
[0].getReadTimer());
265 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
266 assertEquals(262144, channels
[0].getSubBufferSize());
267 assertEquals(0, channels
[0].getSwitchTimer());
270 IEventInfo
[] channel0Events
= channels
[0].getEvents();
271 assertNotNull(channel0Events
);
272 assertEquals(2, channel0Events
.length
);
273 assertEquals("block_rq_remap", channel0Events
[0].getName());
274 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[0].getLogLevel());
275 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[0].getEventType());
276 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
278 assertEquals("block_bio_remap", channel0Events
[1].getName());
279 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
280 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
281 assertEquals(TraceEnablement
.DISABLED
, channel0Events
[1].getState());
283 // Verify Kernel's channel1
284 assertEquals("channel1", channels
[1].getName());
285 assertEquals(4, channels
[1].getNumberOfSubBuffers());
286 assertEquals("splice()", channels
[1].getOutputType());
287 assertEquals(true, channels
[1].isOverwriteMode());
288 assertEquals(400, channels
[1].getReadTimer());
289 assertEquals(TraceEnablement
.DISABLED
, channels
[1].getState());
290 assertEquals(524288, channels
[1].getSubBufferSize());
291 assertEquals(100, channels
[1].getSwitchTimer());
294 IEventInfo
[] channel1Events
= channels
[1].getEvents();
295 assertEquals(0, channel1Events
.length
);
297 // Verify domain UST global
298 assertEquals("UST global", domains
[1].getName());
300 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
302 // Verify UST global's mychannel1
303 assertEquals("mychannel1", ustChannels
[0].getName());
304 assertEquals(8, ustChannels
[0].getNumberOfSubBuffers());
305 assertEquals("mmap()", ustChannels
[0].getOutputType());
306 assertEquals(true, ustChannels
[0].isOverwriteMode());
307 assertEquals(100, ustChannels
[0].getReadTimer());
308 assertEquals(TraceEnablement
.DISABLED
, ustChannels
[0].getState());
309 assertEquals(8192, ustChannels
[0].getSubBufferSize());
310 assertEquals(200, ustChannels
[0].getSwitchTimer());
313 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
314 assertEquals(0, ustEvents
.length
);
316 // Verify UST global's channel0
317 assertEquals("channel0", ustChannels
[1].getName());
318 assertEquals(4, ustChannels
[1].getNumberOfSubBuffers());
319 assertEquals("mmap()", ustChannels
[1].getOutputType());
320 assertEquals(false, ustChannels
[1].isOverwriteMode());
321 assertEquals(200, ustChannels
[1].getReadTimer());
322 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[1].getState());
323 assertEquals(4096, ustChannels
[1].getSubBufferSize());
324 assertEquals(0, ustChannels
[1].getSwitchTimer());
327 ustEvents
= ustChannels
[1].getEvents();
328 assertEquals(2, ustEvents
.length
);
330 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents
[0].getName());
331 assertEquals(TraceLogLevel
.TRACE_DEBUG_LINE
, ustEvents
[0].getLogLevel());
332 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
333 assertEquals(TraceEnablement
.DISABLED
, ustEvents
[0].getState());
335 assertEquals("*", ustEvents
[1].getName());
336 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, ustEvents
[1].getLogLevel());
337 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[1].getEventType());
338 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[1].getState());
340 // next session (no detailed information available)
341 session
= fService
.getSession("mysession1", new NullProgressMonitor());
342 assertNotNull(session
);
343 assertEquals("mysession1", session
.getName());
344 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session
.getSessionPath());
345 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
347 domains
= session
.getDomains();
348 assertNotNull(domains
);
349 assertEquals(0, domains
.length
);
350 } catch (ExecutionException e
) {
355 public void testGetKernelProvider() {
357 fShell
.setScenario(SCEN_GET_KERNEL_PROVIDER1
);
358 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
361 assertNotNull(events
);
362 assertEquals(3, events
.size());
364 IBaseEventInfo baseEventInfo
= events
.get(0);
365 assertNotNull(baseEventInfo
);
366 assertEquals("sched_kthread_stop", baseEventInfo
.getName());
367 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
368 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
370 baseEventInfo
= events
.get(1);
371 assertEquals("sched_kthread_stop_ret", baseEventInfo
.getName());
372 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
373 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
375 baseEventInfo
= events
.get(2);
376 assertEquals("sched_wakeup_new", baseEventInfo
.getName());
377 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
378 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
380 } catch (ExecutionException e
) {
386 public void testGetKernelProviderNoKernel1() {
388 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL1
);
389 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
392 assertNotNull(events
);
393 assertEquals(0, events
.size());
395 } catch (ExecutionException e
) {
401 public void testGetKernelProviderNoKernel2() {
403 fShell
.setScenario(SCEN_LIST_WITH_NO_KERNEL2
);
404 List
<IBaseEventInfo
> events
= fService
.getKernelProvider(new NullProgressMonitor());
407 assertNotNull(events
);
408 assertEquals(0, events
.size());
410 } catch (ExecutionException e
) {
416 public void testGetUstProvider() {
418 fShell
.setScenario(SCEN_GET_UST_PROVIDER1
);
419 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
421 // Check all providers
422 assertNotNull(providers
);
423 assertEquals(2, providers
.size());
425 //Verify first provider
426 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
427 assertEquals(9379, providers
.get(0).getPid());
430 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
431 assertNotNull(events
);
432 assertEquals(2, events
.length
);
434 IBaseEventInfo baseEventInfo
= events
[0];
435 assertNotNull(baseEventInfo
);
436 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
437 assertEquals(TraceLogLevel
.TRACE_DEBUG_MODULE
, baseEventInfo
.getLogLevel());
438 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
440 baseEventInfo
= events
[1];
441 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
442 assertEquals(TraceLogLevel
.TRACE_INFO
, baseEventInfo
.getLogLevel());
443 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
445 //Verify second provider
446 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
447 assertEquals(4852, providers
.get(1).getPid());
450 events
= providers
.get(1).getEvents();
451 assertNotNull(events
);
452 assertEquals(2, events
.length
);
454 baseEventInfo
= events
[0];
455 assertNotNull(baseEventInfo
);
456 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
457 assertEquals(TraceLogLevel
.TRACE_WARNING
, baseEventInfo
.getLogLevel());
458 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
460 baseEventInfo
= events
[1];
461 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
462 assertEquals(TraceLogLevel
.TRACE_DEBUG_FUNCTION
, baseEventInfo
.getLogLevel());
463 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
465 } catch (ExecutionException e
) {
471 public void testUstProvider2() {
473 fShell
.setScenario(SCEN_GET_UST_PROVIDER2
);
474 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
476 assertNotNull(providers
);
477 assertEquals(0, providers
.size());
479 } catch (ExecutionException e
) {
485 public void testGetUstProvider3() {
487 fShell
.setScenario(SCEN_GET_UST_PROVIDER3
);
489 ((LTTngControlService
)fService
).setVersion("2.1.0");
490 List
<IUstProviderInfo
> providers
= fService
.getUstProvider();
492 // Check all providers
493 assertNotNull(providers
);
494 assertEquals(2, providers
.size());
496 //Verify first provider
497 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
498 assertEquals(9379, providers
.get(0).getPid());
501 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
502 assertNotNull(events
);
503 assertEquals(2, events
.length
);
505 IBaseEventInfo baseEventInfo
= events
[0];
506 assertNotNull(baseEventInfo
);
507 IFieldInfo
[] fields
= baseEventInfo
.getFields();
508 assertNotNull(fields
);
509 assertEquals(0, fields
.length
);
511 baseEventInfo
= events
[1];
512 fields
= baseEventInfo
.getFields();
513 assertNotNull(fields
);
514 assertEquals(3, fields
.length
);
515 assertEquals("doublefield", fields
[0].getName());
516 assertEquals("float", fields
[0].getFieldType());
518 assertEquals("floatfield", fields
[1].getName());
519 assertEquals("float", fields
[1].getFieldType());
521 assertEquals("stringfield", fields
[2].getName());
522 assertEquals("string", fields
[2].getFieldType());
524 //Verify second provider
525 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
526 assertEquals(4852, providers
.get(1).getPid());
529 events
= providers
.get(1).getEvents();
530 assertNotNull(events
);
531 assertEquals(2, events
.length
);
533 baseEventInfo
= events
[0];
534 assertNotNull(baseEventInfo
);
535 fields
= baseEventInfo
.getFields();
536 assertNotNull(fields
);
537 assertEquals(0, fields
.length
);
539 baseEventInfo
= events
[1];
540 fields
= baseEventInfo
.getFields();
541 assertNotNull(fields
);
542 assertEquals(3, fields
.length
);
544 assertEquals("doublefield", fields
[0].getName());
545 assertEquals("float", fields
[0].getFieldType());
547 assertEquals("floatfield", fields
[1].getName());
548 assertEquals("float", fields
[1].getFieldType());
550 assertEquals("stringfield", fields
[2].getName());
551 assertEquals("string", fields
[2].getFieldType());
554 ((LTTngControlService
)fService
).setVersion("2.0.0");
556 } catch (ExecutionException e
) {
562 public void testCreateSession() {
564 fShell
.setScenario(SCEN_CREATE_SESSION1
);
566 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
568 assertEquals("mysession2", info
.getName());
569 assertNotNull(info
.getSessionPath());
570 assertTrue(info
.getSessionPath().contains("mysession2"));
571 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
572 } catch (ExecutionException e
) {
578 public void testCreateSessionWithPrompt() {
580 // First line has the shell prompt before the command output
581 // This can happen in a real application if the command line is not echoed by the shell.
582 fShell
.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT
);
584 // First line has no shell prompt before the output
585 ISessionInfo info
= fService
.createSession("mysession2", null, new NullProgressMonitor());
587 assertEquals("mysession2", info
.getName());
588 assertNotNull(info
.getSessionPath());
589 assertTrue(info
.getSessionPath().contains("mysession2"));
590 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
591 } catch (ExecutionException e
) {
597 public void testCreateSessionVariants() {
599 fShell
.setScenario(SCEN_CREATE_SESSION_VARIANTS
);
602 fService
.createSession("alreadyExist", null, new NullProgressMonitor());
603 fail("No exeption thrown");
604 } catch (ExecutionException e
) {
609 fService
.createSession("wrongName", null, new NullProgressMonitor());
610 fail("No exeption thrown");
611 } catch (ExecutionException e
) {
616 fService
.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
617 fail("No exeption thrown");
618 } catch (ExecutionException e
) {
623 ISessionInfo info
= fService
.createSession("session with spaces", null, new NullProgressMonitor());
625 assertEquals("session with spaces", info
.getName());
626 assertNotNull(info
.getSessionPath());
627 assertTrue(info
.getSessionPath().contains("session with spaces"));
628 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
630 } catch (ExecutionException e
) {
635 ISessionInfo info
= fService
.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
637 assertEquals("pathWithSpaces", info
.getName());
638 assertNotNull(info
.getSessionPath());
639 assertTrue(info
.getSessionPath().contains("/home/user/hallo user/here"));
640 assertEquals(TraceSessionState
.INACTIVE
, info
.getSessionState());
642 } catch (ExecutionException e
) {
648 public void testDestroySession() {
650 fShell
.setScenario(SCEN_DESTROY_SESSION1
);
651 fService
.destroySession("mysession2", new NullProgressMonitor());
652 } catch (ExecutionException e
) {
658 public void testCreateChannel() {
661 String sessionName
= "mysession2";
662 List
<String
> list
= new ArrayList
<String
>();
663 String kernelChannel0
= "mychannel0";
664 String kernelChannel1
= "mychannel1";
665 list
.add(kernelChannel0
);
666 list
.add(kernelChannel1
);
668 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
670 // Create/enable/configure 2 kernel channels
671 ChannelInfo chanInfo
= new ChannelInfo("");
672 chanInfo
.setOverwriteMode(true);
673 chanInfo
.setSubBufferSize(16384);
674 chanInfo
.setReadTimer(100);
675 chanInfo
.setSwitchTimer(200);
676 chanInfo
.setNumberOfSubBuffers(2);
677 fService
.enableChannels(sessionName
, list
, true, chanInfo
, new NullProgressMonitor());
679 // Create/enable/configure 1 UST channel
681 list
.add("ustChannel");
683 chanInfo
= new ChannelInfo("");
684 chanInfo
.setOverwriteMode(true);
685 chanInfo
.setSubBufferSize(32768);
686 chanInfo
.setReadTimer(200);
687 chanInfo
.setSwitchTimer(100);
688 chanInfo
.setNumberOfSubBuffers(1);
689 fService
.enableChannels(sessionName
, list
, false, chanInfo
, new NullProgressMonitor());
691 } catch (ExecutionException e
) {
697 public void testDisableChannel() {
700 String sessionName
= "mysession2";
701 List
<String
> list
= new ArrayList
<String
>();
702 String kernelChannel0
= "mychannel0";
703 String kernelChannel1
= "mychannel1";
704 list
.add(kernelChannel0
);
705 list
.add(kernelChannel1
);
707 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
708 fService
.disableChannels(sessionName
, list
, true, new NullProgressMonitor());
711 list
.add("ustChannel");
712 fService
.disableChannels(sessionName
, list
, false, new NullProgressMonitor());
714 } catch (ExecutionException e
) {
720 public void testEnableChannel() {
723 String sessionName
= "mysession2";
724 List
<String
> list
= new ArrayList
<String
>();
725 String kernelChannel0
= "mychannel0";
726 String kernelChannel1
= "mychannel1";
727 list
.add(kernelChannel0
);
728 list
.add(kernelChannel1
);
730 fShell
.setScenario(SCEN_CHANNEL_HANDLING
);
731 fService
.enableChannels(sessionName
, list
, true, null, new NullProgressMonitor());
733 // Create/enable/configure 1 UST channel
735 list
.add("ustChannel");
737 fService
.enableChannels(sessionName
, list
, false, null, new NullProgressMonitor());
739 } catch (ExecutionException e
) {
744 // public void tesEnableChannelNoTracer() {
746 // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
747 // service.getSessionNames(new NullProgressMonitor());
748 // fail("No exeption thrown");
750 // } catch (ExecutionException e) {
756 public void testEnableEvents() {
758 // 1) session name, channel = null, 3 event names, kernel
759 String sessionName
= "mysession2";
760 List
<String
> list
= new ArrayList
<String
>();
761 String eventName0
= "block_rq_remap";
762 String eventName1
= "block_bio_remap";
763 String eventName2
= "softirq_entry";
764 list
.add(eventName0
);
765 list
.add(eventName1
);
766 list
.add(eventName2
);
767 fShell
.setScenario(SCEN_EVENT_HANDLING
);
768 fService
.enableEvents(sessionName
, null, list
, true, null, new NullProgressMonitor());
770 // 2) session name, channel=mychannel, event name= null, kernel
771 String channelName
= "mychannel";
772 fService
.enableEvents(sessionName
, channelName
, null, true, null, new NullProgressMonitor());
774 // 3) session name, channel=mychannel, 1 event name, ust, no filter
775 String ustEventName
= "ust_tests_hello:tptest_sighandler";
777 list
.add(ustEventName
);
778 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
780 // 4) session name, channel = mychannel, no event name, ust, with filter
781 fService
.enableEvents(sessionName
, channelName
, list
, false, "intfield==10", new NullProgressMonitor());
783 // 5) session name, channel = mychannel, no event name, ust, no filter
785 fService
.enableEvents(sessionName
, channelName
, list
, false, null, new NullProgressMonitor());
787 // TODO add test with filters
789 } catch (ExecutionException e
) {
795 public void testEnableSyscalls() {
797 // 1) session name, channel = null, 3 event names, kernel
798 String sessionName
= "mysession2";
799 String channelName
= "mychannel";
801 fShell
.setScenario(SCEN_EVENT_HANDLING
);
803 // 1) session name, channel = null
804 fService
.enableSyscalls(sessionName
, null, new NullProgressMonitor());
806 // 2) session name, channel = mychannel
807 fService
.enableSyscalls(sessionName
, channelName
, new NullProgressMonitor());
809 } catch (ExecutionException e
) {
815 public void testDynamicProbe() {
817 // 1) session name, channel = null, 3 event names, kernel
818 String sessionName
= "mysession2";
819 String channelName
= "mychannel";
820 String eventName0
= "myevent0";
821 String eventName1
= "myevent1";
822 String functionProbe
= "0xc0101340";
823 String dynProbe
= "init_post";
825 fShell
.setScenario(SCEN_EVENT_HANDLING
);
827 // 1) session name, channel = null, event name, function probe, probe
828 fService
.enableProbe(sessionName
, null, eventName0
, true, functionProbe
, new NullProgressMonitor());
830 // 2) session name, channel = mychannel
831 fService
.enableProbe(sessionName
, channelName
, eventName1
, false, dynProbe
, new NullProgressMonitor());
833 } catch (ExecutionException e
) {
839 public void testEnableLogLevel() {
841 // 1) session name, channel = null, 3 event names, kernel
842 String sessionName
= "mysession2";
843 String channelName
= "mychannel";
844 String eventName4
= "myevent4";
845 String eventName5
= "myevent5";
847 fShell
.setScenario(SCEN_EVENT_HANDLING
);
849 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
850 fService
.enableLogLevel(sessionName
, null, eventName4
, LogLevelType
.LOGLEVEL_ONLY
, TraceLogLevel
.TRACE_DEBUG
, null, new NullProgressMonitor());
852 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
853 fService
.enableLogLevel(sessionName
, channelName
, eventName5
, LogLevelType
.LOGLEVEL
, TraceLogLevel
.TRACE_DEBUG_FUNCTION
, null, new NullProgressMonitor());
855 // TODO add test with filters
857 } catch (ExecutionException e
) {
863 public void testAddContext() {
865 // 1) session name, channel = null, 3 event names, kernel
866 String sessionName
= "mysession2";
867 String channelName
= "mychannel";
868 String eventName
= "ust_tests_hello:tptest_sighandler";
869 List
<String
> contexts
= new ArrayList
<String
>();
870 contexts
.add("prio");
873 fShell
.setScenario(SCEN_CONTEXT_HANDLING
);
875 List
<String
> availContexts
= fService
.getContextList(new NullProgressMonitor());
876 assertNotNull(availContexts
);
877 assertEquals(12, availContexts
.size());
879 // A very "hard-coded" way to verify but it works ...
880 Set
<String
> expectedContexts
= new HashSet
<String
>();
881 expectedContexts
.add("pid");
882 expectedContexts
.add("procname");
883 expectedContexts
.add("prio");
884 expectedContexts
.add("nice");
885 expectedContexts
.add("vpid");
886 expectedContexts
.add("tid");
887 expectedContexts
.add("pthread_id");
888 expectedContexts
.add("vtid");
889 expectedContexts
.add("ppid");
890 expectedContexts
.add("vppid");
891 expectedContexts
.add("perf:cpu-cycles");
892 expectedContexts
.add("perf:cycles");
894 assertTrue(expectedContexts
.containsAll(availContexts
));
896 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
897 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
899 } catch (ExecutionException e
) {
905 public void testAddContextFailure() {
907 // 1) session name, channel = null, 3 event names, kernel
908 String sessionName
= "mysession2";
909 String channelName
= "mychannel";
910 String eventName
= "ust_tests_hello:tptest_sighandler";
911 List
<String
> contexts
= new ArrayList
<String
>();
912 contexts
.add("prio");
914 fShell
.setScenario(SCEN_CONTEXT_ERROR_HANDLING
);
916 fService
.getContextList(new NullProgressMonitor());
917 fail("No exeption generated");
918 } catch (ExecutionException e
) {
922 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
923 fService
.addContexts(sessionName
, channelName
, eventName
, false, contexts
, new NullProgressMonitor());
924 fail("No exeption generated");
925 } catch (ExecutionException e
) {
931 public void testCalibrate() {
933 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
934 fService
.calibrate(true, new NullProgressMonitor());
936 } catch (ExecutionException e
) {
942 public void testCalibrateFailure() {
944 fShell
.setScenario(SCEN_CALIBRATE_HANDLING
);
945 fService
.calibrate(false, new NullProgressMonitor());
946 fail("No exeption generated");
947 } catch (ExecutionException e
) {
953 public void testCreateSession2_1() {
956 fShell
.setScenario(SCEN_CREATE_SESSION_2_1
);
958 ISessionInfo info
= fService
.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
960 assertEquals("mysession", info
.getName());
961 assertEquals("net://172.0.0.1", info
.getSessionPath());
962 assertTrue(info
.isStreamedTrace());
963 fService
.destroySession("mysession", new NullProgressMonitor());
965 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
967 assertEquals("mysession", info
.getName());
968 assertEquals("file:///tmp", info
.getSessionPath());
969 assertTrue(info
.isStreamedTrace());
970 fService
.destroySession("mysession", new NullProgressMonitor());
972 info
= fService
.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
974 assertEquals("mysession", info
.getName());
975 assertEquals("file:///tmp", info
.getSessionPath());
976 assertTrue(info
.isStreamedTrace());
977 fService
.destroySession("mysession", new NullProgressMonitor());
979 info
= fService
.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
981 assertEquals("mysession", info
.getName());
982 assertEquals("", info
.getSessionPath()); // TODO: currently there is a bug in LTTng tracer and it returns string null
983 assertTrue(info
.isStreamedTrace());
984 fService
.destroySession("mysession", new NullProgressMonitor());
986 info
= fService
.createSession("mysession", "net://172.0.0.1:1234:2345", null, null, new NullProgressMonitor());
988 assertEquals("mysession", info
.getName());
989 assertEquals("net://172.0.0.1:1234:2345", info
.getSessionPath());
990 assertTrue(info
.isStreamedTrace());
991 fService
.destroySession("mysession", new NullProgressMonitor());
993 } catch (ExecutionException e
) {