lttng: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / service / LTTngControlServiceTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 * Marc-Andre Laperle - Support for creating a live session
13 **********************************************************************/
14
15 package org.eclipse.linuxtools.lttng2.control.ui.tests.service;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
21
22 import java.io.File;
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Set;
28
29 import org.eclipse.core.commands.ExecutionException;
30 import org.eclipse.core.runtime.FileLocator;
31 import org.eclipse.core.runtime.NullProgressMonitor;
32 import org.eclipse.core.runtime.Path;
33 import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.CommandShellFactory;
34 import org.eclipse.linuxtools.internal.lttng2.control.stubs.shells.LTTngToolsFileShell;
35 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IBaseEventInfo;
36 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
37 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
38 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IEventInfo;
39 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IFieldInfo;
40 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
41 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
42 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IUstProviderInfo;
43 import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
44 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceChannelOutputType;
45 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
46 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
47 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
48 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
49 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.BufferType;
50 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ChannelInfo;
51 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
52 import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
53 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.logging.ControlCommandLogger;
54 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.preferences.ControlPreferences;
55 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.ILttngControlService;
56 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlService;
57 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceFactory;
58 import org.junit.After;
59 import org.junit.Before;
60 import org.junit.Test;
61 import org.osgi.framework.FrameworkUtil;
62
63 /**
64 * The class <code>LTTngControlServiceTest</code> contains test for the class
65 * <code>{@link LTTngControlService}</code>.
66 */
67 @SuppressWarnings("javadoc")
68 public class LTTngControlServiceTest {
69
70 private static final String DIRECTORY = "testfiles";
71 private static final String TEST_STREAM = "LTTngServiceTest.cfg";
72
73 private static final String SCEN_LTTNG_NOT_INSTALLED = "LttngNotInstalled";
74 private static final String SCEN_LTTNG_VERSION = "LttngVersion";
75 private static final String SCEN_LTTNG_VERSION_WITH_PROMPT = "LttngVersionWithPrompt";
76 private static final String SCEN_LTTNG_UNSUPPORTED_VERSION = "LttngUnsupportedVersion";
77 private static final String SCEN_LTTNG_NO_VERSION = "LttngNoVersion";
78 private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
79 private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
80 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
81 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE = "GetSessionNameNotExistVerbose";
82 protected static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
83 private static final String SCEN_GET_SESSION1 = "GetSession1";
84 private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
85 private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
86 private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
87 private static final String SCEN_LIST_WITH_NO_KERNEL_VERBOSE = "ListWithNoKernelVerbose";
88 private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
89 private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
90 private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
91 private static final String SCEN_LIST_WITH_NO_UST1 = "ListWithNoUst1";
92 private static final String SCEN_LIST_WITH_NO_UST2 = "ListWithNoUst2";
93 private static final String SCEN_LIST_WITH_NO_UST3 = "ListWithNoUst3";
94 private static final String SCEN_LIST_WITH_NO_UST_VERBOSE = "ListWithNoUstVerbose";
95 private static final String SCEN_CREATE_SESSION1 = "CreateSession1";
96 private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
97 private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
98 private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
99 private static final String SCEN_DESTROY_SESSION_VERBOSE = "DestroySessionVerbose";
100 private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
101 private static final String SCEN_EVENT_HANDLING = "EventHandling";
102 private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
103 private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
104 private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
105 private static final String SCEN_CREATE_SESSION_2_1 = "CreateSessionLttng2.1";
106 private static final String SCEN_CREATE_SESSION_VERBOSE_2_1 = "CreateSessionLttngVerbose2.1";
107 private static final String SCEN_CREATE_SNAPSHOT_SESSION = "CreateSessionSnapshot";
108 private static final String SCEN_CREATE_SNAPSHOT_SESSION_2_5 = "CreateSessionSnapshot2.5";
109 private static final String SCEN_CREATE_STREAMED_SNAPSHOT_SESSION = "CreateSessionStreamedSnapshot";
110 private static final String SCEN_CREATE_SNAPSHOT_SESSION_ERRORS = "CreateSessionSnapshotErrors";
111 protected static final String SCEN_CREATE_LIVE_SESSION = "CreateSessionLive";
112 private static final String SCEN_CREATE_LIVE_SESSION_ERRORS = "CreateSessionLiveErrors";
113
114
115 // ------------------------------------------------------------------------
116 // Test data
117 // ------------------------------------------------------------------------
118
119 private CommandShellFactory fShellFactory;
120 private String fTestfile;
121 protected LTTngToolsFileShell fShell;
122 protected ILttngControlService fService;
123
124 // ------------------------------------------------------------------------
125 // Housekeeping
126 // ------------------------------------------------------------------------
127
128 /**
129 * Perform pre-test initialization.
130 *
131 * @throws Exception
132 * if the initialization fails for some reason
133 */
134 @Before
135 public void setUp() throws Exception {
136 fShellFactory = CommandShellFactory.getInstance();
137
138 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(getTestDirectory() + File.separator + getTestStream()), null);
139 File testfile = new File(FileLocator.toFileURL(location).toURI());
140 fTestfile = testfile.getAbsolutePath();
141
142 fShell = fShellFactory.getFileShell();
143 fShell.loadScenarioFile(fTestfile);
144 fService = getControlService();
145 if (fService == null) {
146 throw new Exception("Unable to obtain a valid ControlService");
147 }
148
149 ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
150 }
151
152 /**
153 * @return the string of the test directory to use
154 */
155 protected String getTestDirectory() {
156 return DIRECTORY;
157 }
158
159 /**
160 * @return the LttngCon
161 */
162 protected ILttngControlService getControlService() {
163 return new LTTngControlService(fShell);
164 }
165
166 public LTTngToolsFileShell getfShell() {
167 return fShell;
168 }
169
170 /**
171 * @return
172 */
173 protected String getTestStream() {
174 return TEST_STREAM;
175 }
176
177 @After
178 public void tearDown() {
179 disableVerbose();
180 ControlPreferences.getInstance().dispose();
181 }
182
183 // ------------------------------------------------------------------------
184 // Test Cases
185 // ------------------------------------------------------------------------
186
187 @Test
188 public void testVersion() {
189 try {
190 fShell.setScenario(SCEN_LTTNG_VERSION);
191 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
192 assertNotNull(service);
193 assertEquals("2.1.0", service.getVersionString());
194 } catch (ExecutionException e) {
195 fail("Exeption thrown " + e);
196 }
197 }
198
199 @Test
200 public void testVersionWithPrompt() {
201 try {
202 fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT);
203 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
204 assertNotNull(service);
205 assertEquals("2.0.0", service.getVersionString());
206 } catch (ExecutionException e) {
207 fail("Exeption thrown " + e);
208 }
209 }
210
211 @Test
212 public void testUnsupportedVersion() {
213 try {
214 fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION);
215 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
216 fail("No exeption thrown");
217 } catch (ExecutionException e) {
218 // success
219 }
220 }
221
222 @Test
223 public void testNoVersion() {
224 try {
225 fShell.setScenario(SCEN_LTTNG_NO_VERSION);
226 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
227 fail("No exeption thrown");
228 } catch (ExecutionException e) {
229 // success
230 }
231 }
232
233 @Test
234 public void testLttngNotInstalled() {
235 try {
236 fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED);
237 fService.getSessionNames(new NullProgressMonitor());
238 fail("No exeption thrown");
239 } catch (ExecutionException e) {
240 // success
241 }
242 }
243
244 @Test
245 public void testGetSessionNames1() {
246 try {
247 fShell.setScenario(SCEN_NO_SESSION_AVAILABLE);
248 String[] result = fService.getSessionNames(new NullProgressMonitor());
249
250 assertNotNull(result);
251 assertEquals(0, result.length);
252
253 } catch (ExecutionException e) {
254 fail(e.toString());
255 }
256 }
257
258 @Test
259 public void testGetSessionNames2() {
260 try {
261 fShell.setScenario(SCEN_GET_SESSION_NAMES1);
262 String[] result = fService.getSessionNames(new NullProgressMonitor());
263
264 assertNotNull(result);
265 assertEquals(2, result.length);
266 assertEquals("mysession1", result[0]);
267 assertEquals("mysession", result[1]);
268
269 } catch (ExecutionException e) {
270 fail(e.toString());
271 }
272 }
273
274 @Test
275 public void testGetSessionNotExist() {
276 try {
277 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST);
278 fService.getSessionNames(new NullProgressMonitor());
279 fail("No exeption thrown");
280
281 } catch (ExecutionException e) {
282 // success
283 }
284 }
285
286 @Test
287 public void testGetSessionNotExistVerbose() {
288 try {
289 enableVerbose();
290 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE);
291 fService.getSessionNames(new NullProgressMonitor());
292 fail("No exeption thrown");
293
294 } catch (ExecutionException e) {
295 // success
296 } finally {
297 disableVerbose();
298 }
299 }
300
301 @Test
302 public void testGetSessionNameGarbage() {
303 try {
304 fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
305 String[] result = fService.getSessionNames(new NullProgressMonitor());
306
307 assertNotNull(result);
308 assertEquals(0, result.length);
309
310 } catch (ExecutionException e) {
311 fail(e.toString());
312 }
313 }
314
315 @Test
316 public void testGetSession1() {
317 try {
318 fShell.setScenario(SCEN_GET_SESSION1);
319 ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor());
320
321 // Verify Session
322 assertNotNull(session);
323 assertEquals("mysession", session.getName());
324 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath());
325 assertEquals(TraceSessionState.ACTIVE, session.getSessionState());
326
327 IDomainInfo[] domains = session.getDomains();
328 assertNotNull(domains);
329 assertEquals(2, domains.length);
330
331 // Verify Kernel domain
332 assertEquals("Kernel", domains[0].getName());
333 IChannelInfo[] channels = domains[0].getChannels();
334 assertNotNull(channels);
335 assertEquals(2, channels.length);
336
337 // Verify Kernel's channel0
338 assertEquals("channel0", channels[0].getName());
339 assertEquals(4, channels[0].getNumberOfSubBuffers());
340 assertEquals("splice()", channels[0].getOutputType().getInName());
341 assertEquals(TraceChannelOutputType.SPLICE, channels[0].getOutputType());
342 assertEquals(false, channels[0].isOverwriteMode());
343 assertEquals(200, channels[0].getReadTimer());
344 assertEquals(TraceEnablement.ENABLED, channels[0].getState());
345 assertEquals(262144, channels[0].getSubBufferSize());
346 assertEquals(0, channels[0].getSwitchTimer());
347
348 // Verify event info
349 IEventInfo[] channel0Events = channels[0].getEvents();
350 assertNotNull(channel0Events);
351 assertEquals(2, channel0Events.length);
352 assertEquals("block_rq_remap", channel0Events[0].getName());
353 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel());
354 assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType());
355 assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState());
356
357 assertEquals("block_bio_remap", channel0Events[1].getName());
358 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel());
359 assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType());
360 assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState());
361
362 // Verify Kernel's channel1
363 assertEquals("channel1", channels[1].getName());
364 assertEquals(4, channels[1].getNumberOfSubBuffers());
365 assertEquals("splice()", channels[1].getOutputType().getInName());
366 assertEquals(TraceChannelOutputType.SPLICE, channels[1].getOutputType());
367 assertEquals(true, channels[1].isOverwriteMode());
368 assertEquals(400, channels[1].getReadTimer());
369 assertEquals(TraceEnablement.DISABLED, channels[1].getState());
370 assertEquals(524288, channels[1].getSubBufferSize());
371 assertEquals(100, channels[1].getSwitchTimer());
372
373 // Verify event info
374 IEventInfo[] channel1Events = channels[1].getEvents();
375 assertEquals(0, channel1Events.length);
376
377 // Verify domain UST global
378 assertEquals("UST global", domains[1].getName());
379
380 IChannelInfo[] ustChannels = domains[1].getChannels();
381
382 // Verify UST global's mychannel1
383 assertEquals("mychannel1", ustChannels[0].getName());
384 assertEquals(8, ustChannels[0].getNumberOfSubBuffers());
385 assertEquals("mmap()", ustChannels[0].getOutputType().getInName());
386 assertEquals(TraceChannelOutputType.MMAP, ustChannels[0].getOutputType());
387 assertEquals(true, ustChannels[0].isOverwriteMode());
388 assertEquals(100, ustChannels[0].getReadTimer());
389 assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState());
390 assertEquals(8192, ustChannels[0].getSubBufferSize());
391 assertEquals(200, ustChannels[0].getSwitchTimer());
392
393 // Verify event info
394 IEventInfo[] ustEvents = ustChannels[0].getEvents();
395 assertEquals(0, ustEvents.length);
396
397 // Verify UST global's channel0
398 assertEquals("channel0", ustChannels[1].getName());
399 assertEquals(4, ustChannels[1].getNumberOfSubBuffers());
400 assertEquals("mmap()", ustChannels[1].getOutputType().getInName());
401 assertEquals(TraceChannelOutputType.MMAP, ustChannels[1].getOutputType());
402 assertEquals(false, ustChannels[1].isOverwriteMode());
403 assertEquals(200, ustChannels[1].getReadTimer());
404 assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState());
405 assertEquals(4096, ustChannels[1].getSubBufferSize());
406 assertEquals(0, ustChannels[1].getSwitchTimer());
407
408 // Verify event info
409 ustEvents = ustChannels[1].getEvents();
410 assertEquals(2, ustEvents.length);
411
412 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName());
413 assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel());
414 assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType());
415 assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState());
416
417 assertEquals("*", ustEvents[1].getName());
418 assertEquals(getAllEventTraceLogLevel(), ustEvents[1].getLogLevel());
419 assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType());
420 assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState());
421
422 // next session (no detailed information available)
423 session = fService.getSession("mysession1", new NullProgressMonitor());
424 assertNotNull(session);
425 assertEquals("mysession1", session.getName());
426 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath());
427 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
428
429 domains = session.getDomains();
430 assertNotNull(domains);
431 assertEquals(0, domains.length);
432 } catch (ExecutionException e) {
433 fail(e.toString());
434 }
435 }
436
437 /**
438 * @return
439 */
440 protected TraceLogLevel getAllEventTraceLogLevel() {
441 return TraceLogLevel.LEVEL_UNKNOWN;
442 }
443
444 public void testGetKernelProvider() {
445 try {
446 fShell.setScenario(SCEN_GET_KERNEL_PROVIDER1);
447 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
448
449 // Verify event info
450 assertNotNull(events);
451 assertEquals(3, events.size());
452
453 IBaseEventInfo baseEventInfo = events.get(0);
454 assertNotNull(baseEventInfo);
455 assertEquals("sched_kthread_stop", baseEventInfo.getName());
456 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
457 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
458
459 baseEventInfo = events.get(1);
460 assertEquals("sched_kthread_stop_ret", baseEventInfo.getName());
461 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
462 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
463
464 baseEventInfo = events.get(2);
465 assertEquals("sched_wakeup_new", baseEventInfo.getName());
466 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
467 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
468
469 } catch (ExecutionException e) {
470 fail(e.toString());
471 }
472 }
473
474 @Test
475 public void testGetKernelProviderNoKernel1() {
476 try {
477 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1);
478 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
479
480 // Verify event info
481 assertNotNull(events);
482 assertEquals(0, events.size());
483
484 } catch (ExecutionException e) {
485 fail(e.toString());
486 }
487 }
488
489 @Test
490 public void testGetKernelProviderNoKernel2() {
491 try {
492 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2);
493 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
494
495 // Verify event info
496 assertNotNull(events);
497 assertEquals(0, events.size());
498
499 } catch (ExecutionException e) {
500 fail(e.toString());
501 }
502 }
503
504 @Test
505 public void testGetKernelProviderNoKernelVerbose() {
506 try {
507 enableVerbose();
508 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE);
509 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
510
511 // Verify event info
512 assertNotNull(events);
513 assertEquals(0, events.size());
514
515 } catch (ExecutionException e) {
516 fail(e.toString());
517 } finally {
518 disableVerbose();
519 }
520 }
521
522 @Test
523 public void testGetUstProvider() {
524 try {
525 fShell.setScenario(SCEN_GET_UST_PROVIDER1);
526 List<IUstProviderInfo> providers = fService.getUstProvider();
527
528 // Check all providers
529 assertNotNull(providers);
530 assertEquals(2, providers.size());
531
532 //Verify first provider
533 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
534 assertEquals(9379, providers.get(0).getPid());
535
536 // Verify event info
537 IBaseEventInfo[] events = providers.get(0).getEvents();
538 assertNotNull(events);
539 assertEquals(2, events.length);
540
541 IBaseEventInfo baseEventInfo = events[0];
542 assertNotNull(baseEventInfo);
543 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
544 assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel());
545 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
546
547 baseEventInfo = events[1];
548 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
549 assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel());
550 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
551
552 //Verify second provider
553 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
554 assertEquals(4852, providers.get(1).getPid());
555
556 // Verify event info
557 events = providers.get(1).getEvents();
558 assertNotNull(events);
559 assertEquals(2, events.length);
560
561 baseEventInfo = events[0];
562 assertNotNull(baseEventInfo);
563 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
564 assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel());
565 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
566
567 baseEventInfo = events[1];
568 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
569 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel());
570 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
571
572 } catch (ExecutionException e) {
573 fail(e.toString());
574 }
575 }
576
577 @Test
578 public void testUstProvider2() {
579 try {
580 fShell.setScenario(SCEN_GET_UST_PROVIDER2);
581 List<IUstProviderInfo> providers = fService.getUstProvider();
582
583 assertNotNull(providers);
584 assertEquals(0, providers.size());
585
586 } catch (ExecutionException e) {
587 fail(e.toString());
588 }
589 }
590
591 @Test
592 public void testGetUstProvider3() {
593 try {
594 fShell.setScenario(SCEN_GET_UST_PROVIDER3);
595 // Set version
596 ((LTTngControlService)fService).setVersion("2.1.0");
597 List<IUstProviderInfo> providers = fService.getUstProvider();
598
599 // Check all providers
600 assertNotNull(providers);
601 assertEquals(2, providers.size());
602
603 //Verify first provider
604 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
605 assertEquals(9379, providers.get(0).getPid());
606
607 // Verify event info
608 IBaseEventInfo[] events = providers.get(0).getEvents();
609 assertNotNull(events);
610 assertEquals(2, events.length);
611
612 IBaseEventInfo baseEventInfo = events[0];
613 assertNotNull(baseEventInfo);
614 IFieldInfo[] fields = baseEventInfo.getFields();
615 assertNotNull(fields);
616 assertEquals(0, fields.length);
617
618 baseEventInfo = events[1];
619 fields = baseEventInfo.getFields();
620 assertNotNull(fields);
621 assertEquals(3, fields.length);
622 assertEquals("doublefield", fields[0].getName());
623 assertEquals("float", fields[0].getFieldType());
624
625 assertEquals("floatfield", fields[1].getName());
626 assertEquals("float", fields[1].getFieldType());
627
628 assertEquals("stringfield", fields[2].getName());
629 assertEquals("string", fields[2].getFieldType());
630
631 //Verify second provider
632 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
633 assertEquals(4852, providers.get(1).getPid());
634
635 // Verify event info
636 events = providers.get(1).getEvents();
637 assertNotNull(events);
638 assertEquals(2, events.length);
639
640 baseEventInfo = events[0];
641 assertNotNull(baseEventInfo);
642 fields = baseEventInfo.getFields();
643 assertNotNull(fields);
644 assertEquals(0, fields.length);
645
646 baseEventInfo = events[1];
647 fields = baseEventInfo.getFields();
648 assertNotNull(fields);
649 assertEquals(3, fields.length);
650
651 assertEquals("doublefield", fields[0].getName());
652 assertEquals("float", fields[0].getFieldType());
653
654 assertEquals("floatfield", fields[1].getName());
655 assertEquals("float", fields[1].getFieldType());
656
657 assertEquals("stringfield", fields[2].getName());
658 assertEquals("string", fields[2].getFieldType());
659
660 // Reset version
661 ((LTTngControlService)fService).setVersion("2.0.0");
662
663 } catch (ExecutionException e) {
664 fail(e.toString());
665 }
666 }
667
668
669 @Test
670 public void testGetKernelProviderNoUst1() {
671 try {
672 fShell.setScenario(SCEN_LIST_WITH_NO_UST1);
673 List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
674
675 // Verify Provider info
676 assertNotNull(providerList);
677 assertEquals(0, providerList.size());
678
679 } catch (ExecutionException e) {
680 fail(e.toString());
681 }
682 }
683
684
685 @Test
686 public void testGetKernelProviderNoUst2() {
687 try {
688 // Set version
689 ((LTTngControlService)fService).setVersion("2.1.0");
690
691 fShell.setScenario(SCEN_LIST_WITH_NO_UST2);
692 List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
693
694 // Verify Provider info
695 assertNotNull(providerList);
696 assertEquals(0, providerList.size());
697
698 // Reset version
699 ((LTTngControlService)fService).setVersion("2.0.0");
700
701 } catch (ExecutionException e) {
702 fail(e.toString());
703 }
704 }
705
706 @Test
707 public void testGetKernelProviderNoUst3() {
708 try {
709
710 // Set version
711 ((LTTngControlService)fService).setVersion("2.1.0");
712
713 fShell.setScenario(SCEN_LIST_WITH_NO_UST3);
714 List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
715
716 // Verify provider info
717 assertNotNull(providerList);
718 assertEquals(0, providerList.size());
719
720 // Reset version
721 ((LTTngControlService)fService).setVersion("2.0.0");
722
723 } catch (ExecutionException e) {
724 fail(e.toString());
725 }
726 }
727
728 @Test
729 public void testGetKernelProviderNoUstVerbose() {
730 try {
731 enableVerbose();
732
733 // Set version
734 ((LTTngControlService)fService).setVersion("2.1.0");
735
736 fShell.setScenario(SCEN_LIST_WITH_NO_UST_VERBOSE);
737 List<IUstProviderInfo> providerList = fService.getUstProvider(new NullProgressMonitor());
738
739 // Verify provider info
740 assertNotNull(providerList);
741 assertEquals(0, providerList.size());
742
743 // Reset version
744 ((LTTngControlService)fService).setVersion("2.0.0");
745
746 } catch (ExecutionException e) {
747 fail(e.toString());
748 } finally {
749 disableVerbose();
750 }
751 }
752
753
754
755 @Test
756 public void testCreateSession() {
757 try {
758 fShell.setScenario(SCEN_CREATE_SESSION1);
759
760 ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
761 assertNotNull(info);
762 assertEquals("mysession2", info.getName());
763 assertNotNull(info.getSessionPath());
764 assertTrue(info.getSessionPath().contains("mysession2"));
765 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
766 } catch (ExecutionException e) {
767 fail(e.toString());
768 }
769 }
770
771 @Test
772 public void testCreateSessionWithPrompt() {
773 try {
774 // First line has the shell prompt before the command output
775 // This can happen in a real application if the command line is not echoed by the shell.
776 fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT);
777
778 // First line has no shell prompt before the output
779 ISessionInfo info = fService.createSession(new SessionInfo("mysession2"), new NullProgressMonitor());
780 assertNotNull(info);
781 assertEquals("mysession2", info.getName());
782 assertNotNull(info.getSessionPath());
783 assertTrue(info.getSessionPath().contains("mysession2"));
784 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
785 } catch (ExecutionException e) {
786 fail(e.toString());
787 }
788 }
789
790 @Test
791 public void testCreateSessionVariants() {
792
793 fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
794
795 try {
796 fService.createSession(new SessionInfo("alreadyExist"), new NullProgressMonitor());
797 fail("No exeption thrown");
798 } catch (ExecutionException e) {
799 // success
800 }
801
802 try {
803 fService.createSession(new SessionInfo("wrongName"), new NullProgressMonitor());
804 fail("No exeption thrown");
805 } catch (ExecutionException e) {
806 // success
807 }
808
809 try {
810 ISessionInfo sessionInfo = new SessionInfo("withPath");
811 sessionInfo.setSessionPath("/home/user/hallo");
812 fService.createSession(sessionInfo, new NullProgressMonitor());
813 fail("No exeption thrown");
814 } catch (ExecutionException e) {
815 // success
816 }
817
818 try {
819 ISessionInfo info = fService.createSession(new SessionInfo("session with spaces"), new NullProgressMonitor());
820 assertNotNull(info);
821 assertEquals("session with spaces", info.getName());
822 assertNotNull(info.getSessionPath());
823 assertTrue(info.getSessionPath().contains("session with spaces"));
824 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
825
826 } catch (ExecutionException e) {
827 fail(e.toString());
828 }
829
830 try {
831 ISessionInfo sessionInfo = new SessionInfo("pathWithSpaces");
832 sessionInfo.setSessionPath("/home/user/hallo user/here");
833 ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
834 assertNotNull(info);
835 assertEquals("pathWithSpaces", info.getName());
836 assertNotNull(info.getSessionPath());
837 assertTrue(info.getSessionPath().contains("/home/user/hallo user/here"));
838 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
839
840 } catch (ExecutionException e) {
841 fail(e.toString());
842 }
843 }
844
845 @Test
846 public void testDestroySession() {
847 try {
848 fShell.setScenario(SCEN_DESTROY_SESSION1);
849 fService.destroySession("mysession2", new NullProgressMonitor());
850 } catch (ExecutionException e) {
851 fail(e.toString());
852 }
853 }
854
855 @Test
856 public void testDestroySessionVerbose() {
857 try {
858 enableVerbose();
859 fShell.setScenario(SCEN_DESTROY_SESSION_VERBOSE);
860 fService.destroySession("mysession2", new NullProgressMonitor());
861 } catch (ExecutionException e) {
862 fail(e.toString());
863 } finally {
864 disableVerbose();
865 }
866 }
867
868 @Test
869 public void testCreateChannel() {
870 try {
871 ((LTTngControlService)fService).setVersion("2.2.0");
872 String sessionName = "mysession2";
873 List<String> list = new ArrayList<>();
874 String kernelChannel0 = "mychannel0";
875 String kernelChannel1 = "mychannel1";
876 list.add(kernelChannel0);
877 list.add(kernelChannel1);
878
879 fShell.setScenario(SCEN_CHANNEL_HANDLING);
880
881 // Create/enable/configure 2 kernel channels
882 ChannelInfo chanInfo = new ChannelInfo("");
883 chanInfo.setOverwriteMode(true);
884 chanInfo.setSubBufferSize(16384);
885 chanInfo.setReadTimer(100);
886 chanInfo.setSwitchTimer(200);
887 chanInfo.setNumberOfSubBuffers(2);
888 chanInfo.setMaxNumberTraceFiles(10);
889 chanInfo.setMaxSizeTraceFiles(0);
890 fService.enableChannels(sessionName, list, true, chanInfo, new NullProgressMonitor());
891
892 // Create/enable/configure 1 UST channel
893 list.clear();
894 list.add("ustChannel");
895
896 chanInfo = new ChannelInfo("");
897 chanInfo.setOverwriteMode(true);
898 chanInfo.setSubBufferSize(32768);
899 chanInfo.setReadTimer(200);
900 chanInfo.setSwitchTimer(100);
901 chanInfo.setNumberOfSubBuffers(1);
902 chanInfo.setMaxNumberTraceFiles(20);
903 chanInfo.setMaxSizeTraceFiles(0);
904 fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
905 ((LTTngControlService)fService).setVersion("2.0.0");
906
907 } catch (ExecutionException e) {
908 fail(e.toString());
909 }
910 }
911
912 @Test
913 public void testCreateChannelUIDBuffer() {
914 try {
915 ((LTTngControlService)fService).setVersion("2.2.0");
916 String sessionName = "mysession2";
917 List<String> list = new ArrayList<>();
918 String USTChannel = "ustChannel";
919 list.add(USTChannel);
920 fShell.setScenario(SCEN_CHANNEL_HANDLING);
921
922 ChannelInfo chanInfo = new ChannelInfo("");
923 chanInfo.setOverwriteMode(true);
924 chanInfo.setSubBufferSize(32768);
925 chanInfo.setReadTimer(200);
926 chanInfo.setSwitchTimer(100);
927 chanInfo.setNumberOfSubBuffers(1);
928 chanInfo.setMaxNumberTraceFiles(20);
929 chanInfo.setMaxSizeTraceFiles(0);
930 chanInfo.setBufferType(BufferType.BUFFER_PER_UID);
931 fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
932 ((LTTngControlService)fService).setVersion("2.0.0");
933
934 } catch (ExecutionException e) {
935 fail(e.toString());
936 }
937 }
938
939 @Test
940 public void testCreateChannelPIDBuffer() {
941 try {
942 ((LTTngControlService)fService).setVersion("2.2.0");
943 String sessionName = "mysession2";
944 List<String> list = new ArrayList<>();
945 String USTChannel = "ustChannel";
946 list.add(USTChannel);
947 fShell.setScenario(SCEN_CHANNEL_HANDLING);
948
949
950 ChannelInfo chanInfo = new ChannelInfo("");
951 chanInfo.setOverwriteMode(true);
952 chanInfo.setSubBufferSize(-1);
953 chanInfo.setReadTimer(-1);
954 chanInfo.setSwitchTimer(-1);
955 chanInfo.setNumberOfSubBuffers(-1);
956 chanInfo.setMaxNumberTraceFiles(-1);
957 chanInfo.setMaxSizeTraceFiles(-1);
958 chanInfo.setBufferType(BufferType.BUFFER_PER_PID);
959
960 fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
961 ((LTTngControlService)fService).setVersion("2.0.0");
962
963 } catch (ExecutionException e) {
964 fail(e.toString());
965 }
966 }
967
968 @Test
969 public void testDisableChannel() {
970 try {
971
972 String sessionName = "mysession2";
973 List<String> list = new ArrayList<>();
974 String kernelChannel0 = "mychannel0";
975 String kernelChannel1 = "mychannel1";
976 list.add(kernelChannel0);
977 list.add(kernelChannel1);
978
979 fShell.setScenario(SCEN_CHANNEL_HANDLING);
980 fService.disableChannels(sessionName, list, true, new NullProgressMonitor());
981
982 list.clear();
983 list.add("ustChannel");
984 fService.disableChannels(sessionName, list, false, new NullProgressMonitor());
985
986 } catch (ExecutionException e) {
987 fail(e.toString());
988 }
989 }
990
991 @Test
992 public void testEnableChannel() {
993 try {
994
995 String sessionName = "mysession2";
996 List<String> list = new ArrayList<>();
997 String kernelChannel0 = "mychannel0";
998 String kernelChannel1 = "mychannel1";
999 list.add(kernelChannel0);
1000 list.add(kernelChannel1);
1001
1002 fShell.setScenario(SCEN_CHANNEL_HANDLING);
1003 fService.enableChannels(sessionName, list, true, null, new NullProgressMonitor());
1004
1005 // Create/enable/configure 1 UST channel
1006 list.clear();
1007 list.add("ustChannel");
1008
1009 fService.enableChannels(sessionName, list, false, null, new NullProgressMonitor());
1010
1011 } catch (ExecutionException e) {
1012 fail(e.toString());
1013 }
1014 }
1015
1016 @Test
1017 public void testEnableEvents() {
1018 try {
1019 // 1) session name, channel = null, 3 event names, kernel
1020 String sessionName = "mysession2";
1021 List<String> list = new ArrayList<>();
1022 String eventName0 = "block_rq_remap";
1023 String eventName1 = "block_bio_remap";
1024 String eventName2 = "softirq_entry";
1025 list.add(eventName0);
1026 list.add(eventName1);
1027 list.add(eventName2);
1028 fShell.setScenario(SCEN_EVENT_HANDLING);
1029 fService.enableEvents(sessionName, null, list, true, null, new NullProgressMonitor());
1030
1031 // 2) session name, channel=mychannel, event name= null, kernel
1032 String channelName = "mychannel";
1033 fService.enableEvents(sessionName, channelName, null, true, null, new NullProgressMonitor());
1034
1035 // 3) session name, channel=mychannel, 1 event name, ust, no filter
1036 String ustEventName = "ust_tests_hello:tptest_sighandler";
1037 list.clear();
1038 list.add(ustEventName);
1039 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
1040
1041 // 4) session name, channel = mychannel, no event name, ust, with filter
1042 fService.enableEvents(sessionName, channelName, list, false, "intfield==10", new NullProgressMonitor());
1043
1044 // 5) session name, channel = mychannel, no event name, ust, no filter
1045 list.clear();
1046 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
1047
1048 // TODO add test with filters
1049
1050 } catch (ExecutionException e) {
1051 fail(e.toString());
1052 }
1053 }
1054
1055 @Test
1056 public void testEnableSyscalls() {
1057 try {
1058 // 1) session name, channel = null, 3 event names, kernel
1059 String sessionName = "mysession2";
1060 String channelName = "mychannel";
1061
1062 fShell.setScenario(SCEN_EVENT_HANDLING);
1063
1064 // 1) session name, channel = null
1065 fService.enableSyscalls(sessionName, null, new NullProgressMonitor());
1066
1067 // 2) session name, channel = mychannel
1068 fService.enableSyscalls(sessionName, channelName, new NullProgressMonitor());
1069
1070 } catch (ExecutionException e) {
1071 fail(e.toString());
1072 }
1073 }
1074
1075 @Test
1076 public void testDynamicProbe() {
1077 try {
1078 // 1) session name, channel = null, 3 event names, kernel
1079 String sessionName = "mysession2";
1080 String channelName = "mychannel";
1081 String eventName0 = "myevent0";
1082 String eventName1 = "myevent1";
1083 String functionProbe = "0xc0101340";
1084 String dynProbe = "init_post";
1085
1086 fShell.setScenario(SCEN_EVENT_HANDLING);
1087
1088 // 1) session name, channel = null, event name, function probe, probe
1089 fService.enableProbe(sessionName, null, eventName0, true, functionProbe, new NullProgressMonitor());
1090
1091 // 2) session name, channel = mychannel
1092 fService.enableProbe(sessionName, channelName, eventName1, false, dynProbe, new NullProgressMonitor());
1093
1094 } catch (ExecutionException e) {
1095 fail(e.toString());
1096 }
1097 }
1098
1099 @Test
1100 public void testEnableLogLevel() {
1101 try {
1102 // 1) session name, channel = null, 3 event names, kernel
1103 String sessionName = "mysession2";
1104 String channelName = "mychannel";
1105 String eventName4 = "myevent4";
1106 String eventName5 = "myevent5";
1107
1108 fShell.setScenario(SCEN_EVENT_HANDLING);
1109
1110 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1111 fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, null, new NullProgressMonitor());
1112
1113 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
1114 fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, null, new NullProgressMonitor());
1115
1116 // TODO add test with filters
1117
1118 } catch (ExecutionException e) {
1119 fail(e.toString());
1120 }
1121 }
1122
1123 @Test
1124 public void testAddContext() {
1125 try {
1126 // 1) session name, channel = null, 3 event names, kernel
1127 String sessionName = "mysession2";
1128 String channelName = "mychannel";
1129 String eventName = "ust_tests_hello:tptest_sighandler";
1130 List<String> contexts = new ArrayList<>();
1131 contexts.add("prio");
1132 contexts.add("pid");
1133
1134 fShell.setScenario(SCEN_CONTEXT_HANDLING);
1135
1136 List<String> availContexts = fService.getContextList(new NullProgressMonitor());
1137 assertNotNull(availContexts);
1138 assertEquals(12, availContexts.size());
1139
1140 // A very "hard-coded" way to verify but it works ...
1141 Set<String> expectedContexts = new HashSet<>();
1142 expectedContexts.add("pid");
1143 expectedContexts.add("procname");
1144 expectedContexts.add("prio");
1145 expectedContexts.add("nice");
1146 expectedContexts.add("vpid");
1147 expectedContexts.add("tid");
1148 expectedContexts.add("pthread_id");
1149 expectedContexts.add("vtid");
1150 expectedContexts.add("ppid");
1151 expectedContexts.add("vppid");
1152 expectedContexts.add("perf:cpu-cycles");
1153 expectedContexts.add("perf:cycles");
1154
1155 assertTrue(expectedContexts.containsAll(availContexts));
1156
1157 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1158 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
1159
1160 } catch (ExecutionException e) {
1161 fail(e.toString());
1162 }
1163 }
1164
1165 @Test
1166 public void testAddContextFailure() {
1167
1168 // 1) session name, channel = null, 3 event names, kernel
1169 String sessionName = "mysession2";
1170 String channelName = "mychannel";
1171 String eventName = "ust_tests_hello:tptest_sighandler";
1172 List<String> contexts = new ArrayList<>();
1173 contexts.add("prio");
1174 contexts.add("pid");
1175 fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
1176 try {
1177 fService.getContextList(new NullProgressMonitor());
1178 fail("No exeption generated");
1179 } catch (ExecutionException e) {
1180 // success
1181 }
1182 try {
1183 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
1184 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
1185 fail("No exeption generated");
1186 } catch (ExecutionException e) {
1187 // success
1188 }
1189 }
1190
1191 @Test
1192 public void testCalibrate() {
1193 try {
1194 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
1195 fService.calibrate(true, new NullProgressMonitor());
1196
1197 } catch (ExecutionException e) {
1198 fail(e.toString());
1199 }
1200 }
1201
1202 @Test
1203 public void testCalibrateFailure() {
1204 try {
1205 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
1206 fService.calibrate(false, new NullProgressMonitor());
1207 fail("No exeption generated");
1208 } catch (ExecutionException e) {
1209 // success
1210 }
1211 }
1212
1213 @Test
1214 public void testCreateSession2_1() {
1215
1216 try {
1217 fShell.setScenario(SCEN_CREATE_SESSION_2_1);
1218
1219 ISessionInfo sessionInfo = new SessionInfo("mysession");
1220 sessionInfo.setNetworkUrl("net://172.0.0.1");
1221 sessionInfo.setStreamedTrace(true);
1222 ISessionInfo info = fService.createSession(sessionInfo, 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
1229 sessionInfo = new SessionInfo("mysession");
1230 sessionInfo.setStreamedTrace(true);
1231 sessionInfo.setNetworkUrl("file:///tmp");
1232 info = fService.createSession(sessionInfo, new NullProgressMonitor());
1233 assertNotNull(info);
1234 assertEquals("mysession", info.getName());
1235 assertEquals("file:///tmp", info.getSessionPath());
1236 assertTrue(!info.isStreamedTrace());
1237 fService.destroySession("mysession", new NullProgressMonitor());
1238
1239 sessionInfo = new SessionInfo("mysession");
1240 sessionInfo.setStreamedTrace(true);
1241 sessionInfo.setNetworkUrl("file:///tmp");
1242 info = fService.createSession(sessionInfo, new NullProgressMonitor());
1243 assertNotNull(info);
1244 assertEquals("mysession", info.getName());
1245 assertEquals("file:///tmp", info.getSessionPath());
1246 assertTrue(!info.isStreamedTrace());
1247 fService.destroySession("mysession", new NullProgressMonitor());
1248
1249 sessionInfo = new SessionInfo("mysession");
1250 sessionInfo.setStreamedTrace(true);
1251 sessionInfo.setControlUrl("tcp://172.0.0.1");
1252 sessionInfo.setDataUrl("tcp://172.0.0.1:5343");
1253 info = fService.createSession(sessionInfo, new NullProgressMonitor());
1254 assertNotNull(info);
1255 assertEquals("mysession", info.getName());
1256 assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
1257 assertTrue(info.isStreamedTrace());
1258 fService.destroySession("mysession", new NullProgressMonitor());
1259
1260 sessionInfo = new SessionInfo("mysession");
1261 sessionInfo.setStreamedTrace(true);
1262 sessionInfo.setNetworkUrl("net://172.0.0.1:1234:2345");
1263 info = fService.createSession(sessionInfo, new NullProgressMonitor());
1264 assertNotNull(info);
1265 assertEquals("mysession", info.getName());
1266 assertEquals("net://172.0.0.1:1234:2345", info.getSessionPath());
1267 assertTrue(info.isStreamedTrace());
1268 fService.destroySession("mysession", new NullProgressMonitor());
1269
1270 // verbose
1271 enableVerbose();
1272 sessionInfo = new SessionInfo("mysession");
1273 sessionInfo.setStreamedTrace(true);
1274 sessionInfo.setNetworkUrl("net://172.0.0.1");
1275 info = fService.createSession(sessionInfo, new NullProgressMonitor());
1276 assertNotNull(info);
1277 assertEquals("mysession", info.getName());
1278 assertEquals("net://172.0.0.1", info.getSessionPath());
1279 assertTrue(info.isStreamedTrace());
1280 disableVerbose();
1281 fService.destroySession("mysession", new NullProgressMonitor());
1282
1283
1284 } catch (ExecutionException e) {
1285 fail(e.toString());
1286 }
1287 }
1288
1289 @Test
1290 public void testCreateSessionVerbose2_1() {
1291 try {
1292 fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
1293
1294 enableVerbose();
1295 ISessionInfo sessionInfo = new SessionInfo("mysession");
1296 sessionInfo.setStreamedTrace(true);
1297 sessionInfo.setNetworkUrl("net://172.0.0.1");
1298 ISessionInfo info = fService.createSession(sessionInfo, new NullProgressMonitor());
1299 assertNotNull(info);
1300 assertEquals("mysession", info.getName());
1301 assertEquals("net://172.0.0.1", info.getSessionPath());
1302 assertTrue(info.isStreamedTrace());
1303 fService.destroySession("mysession", new NullProgressMonitor());
1304 } catch (ExecutionException e) {
1305 fail(e.toString());
1306 } finally {
1307 disableVerbose();
1308 }
1309 }
1310
1311 @Test
1312 public void testCreateSnapshotSession() {
1313 try {
1314 fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION);
1315 ISessionInfo params = new SessionInfo("mysession");
1316 params.setSnapshot(true);
1317 ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
1318 assertNotNull(sessionInfo);
1319 assertEquals("mysession", sessionInfo.getName());
1320 assertTrue(sessionInfo.isSnapshotSession());
1321 assertEquals("", sessionInfo.getSessionPath());
1322 assertTrue(!sessionInfo.isStreamedTrace());
1323
1324 assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
1325
1326 String[] names = fService.getSessionNames(new NullProgressMonitor());
1327 assertEquals(names[0], "mysession");
1328
1329 ISnapshotInfo snapshotInfo = fService.getSnapshotInfo("mysession", new NullProgressMonitor());
1330 assertNotNull(snapshotInfo);
1331 assertEquals("snapshot-1", snapshotInfo.getName());
1332 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", snapshotInfo.getSnapshotPath());
1333 assertEquals(1, snapshotInfo.getId());
1334 assertTrue(!snapshotInfo.isStreamedSnapshot());
1335
1336 // we need to set the snapshotInfo to so that the session path is set correctly
1337 sessionInfo.setSnapshotInfo(snapshotInfo);
1338 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", sessionInfo.getSessionPath());
1339
1340 fService.recordSnapshot("mysession", new NullProgressMonitor());
1341
1342 fService.destroySession("mysession", new NullProgressMonitor());
1343
1344 } catch (ExecutionException e) {
1345 fail(e.toString());
1346 }
1347 }
1348
1349 @Test
1350 public void testCreateSnapshotSession2_5() {
1351 try {
1352 fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION_2_5);
1353 ISessionInfo params = new SessionInfo("mysession");
1354 params.setSnapshot(true);
1355 ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
1356 assertNotNull(sessionInfo);
1357 assertEquals("mysession", sessionInfo.getName());
1358 assertTrue(sessionInfo.isSnapshotSession());
1359 assertEquals("", sessionInfo.getSessionPath());
1360 assertTrue(!sessionInfo.isStreamedTrace());
1361
1362 assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
1363
1364 String[] names = fService.getSessionNames(new NullProgressMonitor());
1365 assertEquals(names[0], "mysession");
1366
1367 ISnapshotInfo snapshotInfo = fService.getSnapshotInfo("mysession", new NullProgressMonitor());
1368 assertNotNull(snapshotInfo);
1369 assertEquals("snapshot-1", snapshotInfo.getName());
1370 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", snapshotInfo.getSnapshotPath());
1371 assertEquals(1, snapshotInfo.getId());
1372 assertTrue(!snapshotInfo.isStreamedSnapshot());
1373
1374 // we need to set the snapshotInfo to so that the session path is set correctly
1375 sessionInfo.setSnapshotInfo(snapshotInfo);
1376 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", sessionInfo.getSessionPath());
1377
1378 fService.recordSnapshot("mysession", new NullProgressMonitor());
1379
1380 fService.destroySession("mysession", new NullProgressMonitor());
1381
1382 } catch (ExecutionException e) {
1383 fail(e.toString());
1384 }
1385 }
1386
1387 public void testCreateStreamedSnapshotSession() {
1388 try {
1389 fShell.setScenario(SCEN_CREATE_STREAMED_SNAPSHOT_SESSION);
1390
1391 ISessionInfo params = new SessionInfo("mysession");
1392 params.setNetworkUrl("net://172.0.0.1");
1393 ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
1394 assertNotNull(sessionInfo);
1395 assertEquals("mysession", sessionInfo.getName());
1396 assertTrue(sessionInfo.isSnapshotSession());
1397
1398 assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
1399 assertTrue(sessionInfo.isStreamedTrace());
1400
1401 String[] names = fService.getSessionNames(new NullProgressMonitor());
1402 assertEquals(names[0], "mysession");
1403
1404 ISnapshotInfo snapshotInfo = sessionInfo.getSnapshotInfo();
1405 assertNotNull(sessionInfo);
1406 assertEquals("snapshot-2", snapshotInfo.getName());
1407 assertEquals("net4://172.0.0.1:5342/", snapshotInfo.getSnapshotPath());
1408 assertEquals(2, snapshotInfo.getId());
1409 assertTrue(snapshotInfo.isStreamedSnapshot());
1410
1411 // we need to set the snapshotInfo to so that the session path is set correctly
1412 sessionInfo.setSnapshotInfo(snapshotInfo);
1413 assertEquals("net4://172.0.0.1:5342/", sessionInfo.getSessionPath());
1414
1415 fService.recordSnapshot("mysession", new NullProgressMonitor());
1416
1417 fService.destroySession("mysession", new NullProgressMonitor());
1418
1419 } catch (ExecutionException e) {
1420 fail(e.toString());
1421 }
1422 }
1423
1424 @Test
1425 public void testCreateSnapshotSessionErrors() {
1426 try {
1427 fShell.setScenario(SCEN_CREATE_SNAPSHOT_SESSION_ERRORS);
1428
1429 String[] names = fService.getSessionNames(new NullProgressMonitor());
1430 assertEquals(names[0], "mysession");
1431 } catch (ExecutionException e) {
1432 fail(e.toString());
1433 }
1434
1435 try {
1436 fService.getSnapshotInfo("blabla", new NullProgressMonitor());
1437 fail("getSnapshoInfo() didn't fail");
1438 } catch (ExecutionException e) {
1439 // successful
1440 }
1441
1442 try {
1443 fService.recordSnapshot("blabla", new NullProgressMonitor());
1444 fail("getSnapshoInfo() didn't fail");
1445 } catch (ExecutionException e) {
1446 // successful
1447 }
1448
1449 try {
1450 fService.recordSnapshot("mysession", new NullProgressMonitor());
1451 fail("getSnapshoInfo() didn't fail");
1452 } catch (ExecutionException e) {
1453 // successful
1454 }
1455 }
1456
1457 @Test
1458 public void testCreateLiveSession() throws ExecutionException {
1459 fShell.setScenario(SCEN_CREATE_LIVE_SESSION);
1460
1461 ISessionInfo params = new SessionInfo("mysession");
1462 params.setLive(true);
1463 params.setStreamedTrace(true);
1464 params.setNetworkUrl("net://127.0.0.1");
1465 ISessionInfo sessionInfo = fService.createSession(params, new NullProgressMonitor());
1466 assertNotNull(sessionInfo);
1467 assertEquals("mysession", sessionInfo.getName());
1468 assertEquals(TraceSessionState.INACTIVE, sessionInfo.getSessionState());
1469 assertTrue(sessionInfo.isStreamedTrace());
1470 assertTrue(sessionInfo.isLive());
1471 assertEquals("net://127.0.0.1", sessionInfo.getSessionPath());
1472 String[] names = fService.getSessionNames(new NullProgressMonitor());
1473 assertEquals(names[0], "mysession");
1474 fService.destroySession("mysession", new NullProgressMonitor());
1475 }
1476
1477 @Test
1478 public void testCreateLiveSessionErrors() {
1479 try {
1480 fShell.setScenario(SCEN_CREATE_LIVE_SESSION_ERRORS);
1481
1482 ISessionInfo parameters = new SessionInfo("mysession");
1483 parameters.setLive(true);
1484 parameters.setSnapshot(true);
1485 fService.createSession(parameters, new NullProgressMonitor());
1486 fail("createSession() didn't fail");
1487 } catch (ExecutionException e) {
1488 // successful
1489 }
1490
1491 try {
1492 ISessionInfo parameters = new SessionInfo("mysession");
1493 parameters.setNetworkUrl("blah");
1494 parameters.setLive(true);
1495 fService.createSession(parameters, new NullProgressMonitor());
1496 fail("createSession() didn't fail");
1497 } catch (ExecutionException e) {
1498 // successful
1499 }
1500
1501 try {
1502 ISessionInfo parameters = new SessionInfo("mysession");
1503 parameters.setControlUrl("net://127.0.0.1");
1504 parameters.setLive(true);
1505 fService.createSession(parameters, new NullProgressMonitor());
1506 fail("createSession() didn't fail");
1507 } catch (ExecutionException e) {
1508 // successful
1509 }
1510 }
1511
1512 private static void enableVerbose() {
1513 // verbose
1514 ControlCommandLogger.init(ControlPreferences.getInstance().getLogfilePath(), false);
1515 ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, true);
1516 ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE);
1517 }
1518
1519 private static void disableVerbose() {
1520 ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false);
1521 }
1522
1523
1524 }
This page took 0.06761 seconds and 5 git commands to generate.