2d23d2c3b3d4ac8db0f8c5f1434b92bbce173826
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / service / LTTngControlServiceTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
15
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;
20
21 import java.io.File;
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27
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;
57
58 /**
59 * The class <code>LTTngControlServiceTest</code> contains test for the class
60 * <code>{@link LTTngControlService}</code>.
61 */
62 @SuppressWarnings({"nls", "javadoc"})
63 public class LTTngControlServiceTest {
64
65 private static final String DIRECTORY = "testfiles";
66 private static final String TEST_STREAM = "LTTngServiceTest.cfg";
67
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";
98
99 // ------------------------------------------------------------------------
100 // Test data
101 // ------------------------------------------------------------------------
102
103 private CommandShellFactory fShellFactory;
104 private String fTestfile;
105 private LTTngToolsFileShell fShell;
106 private ILttngControlService fService;
107
108 // ------------------------------------------------------------------------
109 // Housekeeping
110 // ------------------------------------------------------------------------
111
112 /**
113 * Perform pre-test initialization.
114 *
115 * @throws Exception
116 * if the initialization fails for some reason
117 */
118 @Before
119 public void setUp() throws Exception {
120 fShellFactory = CommandShellFactory.getInstance();
121
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();
125
126 fShell = fShellFactory.getFileShell();
127 fShell.loadScenarioFile(fTestfile);
128 fService = new LTTngControlService(fShell);
129
130 ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
131 }
132
133 @After
134 public void tearDown() {
135 disableVerbose();
136 ControlPreferences.getInstance().dispose();
137 }
138
139 // ------------------------------------------------------------------------
140 // Test Cases
141 // ------------------------------------------------------------------------
142
143 @Test
144 public void testVersion() {
145 try {
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);
152 }
153 }
154
155 @Test
156 public void testVersionWithPrompt() {
157 try {
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);
164 }
165 }
166
167 @Test
168 public void testUnsupportedVersion() {
169 try {
170 fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION);
171 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
172 fail("No exeption thrown");
173 } catch (ExecutionException e) {
174 // success
175 }
176 }
177
178 @Test
179 public void testNoVersion() {
180 try {
181 fShell.setScenario(SCEN_LTTNG_NO_VERSION);
182 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
183 fail("No exeption thrown");
184 } catch (ExecutionException e) {
185 // success
186 }
187 }
188
189 @Test
190 public void testLttngNotInstalled() {
191 try {
192 fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED);
193 fService.getSessionNames(new NullProgressMonitor());
194 fail("No exeption thrown");
195 } catch (ExecutionException e) {
196 // success
197 }
198 }
199
200 @Test
201 public void testGetSessionNames1() {
202 try {
203 fShell.setScenario(SCEN_NO_SESSION_AVAILABLE);
204 String[] result = fService.getSessionNames(new NullProgressMonitor());
205
206 assertNotNull(result);
207 assertEquals(0, result.length);
208
209 } catch (ExecutionException e) {
210 fail(e.toString());
211 }
212 }
213
214 @Test
215 public void testGetSessionNames2() {
216 try {
217 fShell.setScenario(SCEN_GET_SESSION_NAMES1);
218 String[] result = fService.getSessionNames(new NullProgressMonitor());
219
220 assertNotNull(result);
221 assertEquals(2, result.length);
222 assertEquals("mysession1", result[0]);
223 assertEquals("mysession", result[1]);
224
225 } catch (ExecutionException e) {
226 fail(e.toString());
227 }
228 }
229
230 @Test
231 public void testGetSessionNotExist() {
232 try {
233 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST);
234 fService.getSessionNames(new NullProgressMonitor());
235 fail("No exeption thrown");
236
237 } catch (ExecutionException e) {
238 // success
239 }
240 }
241
242 @Test
243 public void testGetSessionNotExistVerbose() {
244 try {
245 enableVerbose();
246 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE);
247 fService.getSessionNames(new NullProgressMonitor());
248 fail("No exeption thrown");
249
250 } catch (ExecutionException e) {
251 // success
252 } finally {
253 disableVerbose();
254 }
255 }
256
257 @Test
258 public void testGetSessionNameGarbage() {
259 try {
260 fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
261 String[] result = fService.getSessionNames(new NullProgressMonitor());
262
263 assertNotNull(result);
264 assertEquals(0, result.length);
265
266 } catch (ExecutionException e) {
267 fail(e.toString());
268 }
269 }
270
271 @Test
272 public void testGetSession1() {
273 try {
274 fShell.setScenario(SCEN_GET_SESSION1);
275 ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor());
276
277 // Verify Session
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());
282
283 IDomainInfo[] domains = session.getDomains();
284 assertNotNull(domains);
285 assertEquals(2, domains.length);
286
287 // Verify Kernel domain
288 assertEquals("Kernel", domains[0].getName());
289 IChannelInfo[] channels = domains[0].getChannels();
290 assertNotNull(channels);
291 assertEquals(2, channels.length);
292
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());
302
303 // Verify event info
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());
311
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());
316
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());
326
327 // Verify event info
328 IEventInfo[] channel1Events = channels[1].getEvents();
329 assertEquals(0, channel1Events.length);
330
331 // Verify domain UST global
332 assertEquals("UST global", domains[1].getName());
333
334 IChannelInfo[] ustChannels = domains[1].getChannels();
335
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());
345
346 // Verify event info
347 IEventInfo[] ustEvents = ustChannels[0].getEvents();
348 assertEquals(0, ustEvents.length);
349
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());
359
360 // Verify event info
361 ustEvents = ustChannels[1].getEvents();
362 assertEquals(2, ustEvents.length);
363
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());
368
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());
373
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());
380
381 domains = session.getDomains();
382 assertNotNull(domains);
383 assertEquals(0, domains.length);
384 } catch (ExecutionException e) {
385 fail(e.toString());
386 }
387 }
388
389 public void testGetKernelProvider() {
390 try {
391 fShell.setScenario(SCEN_GET_KERNEL_PROVIDER1);
392 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
393
394 // Verify event info
395 assertNotNull(events);
396 assertEquals(3, events.size());
397
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());
403
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());
408
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());
413
414 } catch (ExecutionException e) {
415 fail(e.toString());
416 }
417 }
418
419 @Test
420 public void testGetKernelProviderNoKernel1() {
421 try {
422 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1);
423 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
424
425 // Verify event info
426 assertNotNull(events);
427 assertEquals(0, events.size());
428
429 } catch (ExecutionException e) {
430 fail(e.toString());
431 }
432 }
433
434 @Test
435 public void testGetKernelProviderNoKernel2() {
436 try {
437 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2);
438 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
439
440 // Verify event info
441 assertNotNull(events);
442 assertEquals(0, events.size());
443
444 } catch (ExecutionException e) {
445 fail(e.toString());
446 }
447 }
448
449 @Test
450 public void testGetKernelProviderNoKernelVerbose() {
451 try {
452 enableVerbose();
453 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE);
454 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
455
456 // Verify event info
457 assertNotNull(events);
458 assertEquals(0, events.size());
459
460 } catch (ExecutionException e) {
461 fail(e.toString());
462 } finally {
463 disableVerbose();
464 }
465 }
466
467 @Test
468 public void testGetUstProvider() {
469 try {
470 fShell.setScenario(SCEN_GET_UST_PROVIDER1);
471 List<IUstProviderInfo> providers = fService.getUstProvider();
472
473 // Check all providers
474 assertNotNull(providers);
475 assertEquals(2, providers.size());
476
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());
480
481 // Verify event info
482 IBaseEventInfo[] events = providers.get(0).getEvents();
483 assertNotNull(events);
484 assertEquals(2, events.length);
485
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());
491
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());
496
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());
500
501 // Verify event info
502 events = providers.get(1).getEvents();
503 assertNotNull(events);
504 assertEquals(2, events.length);
505
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());
511
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());
516
517 } catch (ExecutionException e) {
518 fail(e.toString());
519 }
520 }
521
522 @Test
523 public void testUstProvider2() {
524 try {
525 fShell.setScenario(SCEN_GET_UST_PROVIDER2);
526 List<IUstProviderInfo> providers = fService.getUstProvider();
527
528 assertNotNull(providers);
529 assertEquals(0, providers.size());
530
531 } catch (ExecutionException e) {
532 fail(e.toString());
533 }
534 }
535
536 @Test
537 public void testGetUstProvider3() {
538 try {
539 fShell.setScenario(SCEN_GET_UST_PROVIDER3);
540 // Set version
541 ((LTTngControlService)fService).setVersion("2.1.0");
542 List<IUstProviderInfo> providers = fService.getUstProvider();
543
544 // Check all providers
545 assertNotNull(providers);
546 assertEquals(2, providers.size());
547
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());
551
552 // Verify event info
553 IBaseEventInfo[] events = providers.get(0).getEvents();
554 assertNotNull(events);
555 assertEquals(2, events.length);
556
557 IBaseEventInfo baseEventInfo = events[0];
558 assertNotNull(baseEventInfo);
559 IFieldInfo[] fields = baseEventInfo.getFields();
560 assertNotNull(fields);
561 assertEquals(0, fields.length);
562
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());
569
570 assertEquals("floatfield", fields[1].getName());
571 assertEquals("float", fields[1].getFieldType());
572
573 assertEquals("stringfield", fields[2].getName());
574 assertEquals("string", fields[2].getFieldType());
575
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());
579
580 // Verify event info
581 events = providers.get(1).getEvents();
582 assertNotNull(events);
583 assertEquals(2, events.length);
584
585 baseEventInfo = events[0];
586 assertNotNull(baseEventInfo);
587 fields = baseEventInfo.getFields();
588 assertNotNull(fields);
589 assertEquals(0, fields.length);
590
591 baseEventInfo = events[1];
592 fields = baseEventInfo.getFields();
593 assertNotNull(fields);
594 assertEquals(3, fields.length);
595
596 assertEquals("doublefield", fields[0].getName());
597 assertEquals("float", fields[0].getFieldType());
598
599 assertEquals("floatfield", fields[1].getName());
600 assertEquals("float", fields[1].getFieldType());
601
602 assertEquals("stringfield", fields[2].getName());
603 assertEquals("string", fields[2].getFieldType());
604
605 // Reset version
606 ((LTTngControlService)fService).setVersion("2.0.0");
607
608 } catch (ExecutionException e) {
609 fail(e.toString());
610 }
611 }
612
613 @Test
614 public void testCreateSession() {
615 try {
616 fShell.setScenario(SCEN_CREATE_SESSION1);
617
618 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
619 assertNotNull(info);
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) {
625 fail(e.toString());
626 }
627 }
628
629 @Test
630 public void testCreateSessionWithPrompt() {
631 try {
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);
635
636 // First line has no shell prompt before the output
637 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
638 assertNotNull(info);
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) {
644 fail(e.toString());
645 }
646 }
647
648 @Test
649 public void testCreateSessionVariants() {
650
651 fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
652
653 try {
654 fService.createSession("alreadyExist", null, new NullProgressMonitor());
655 fail("No exeption thrown");
656 } catch (ExecutionException e) {
657 // success
658 }
659
660 try {
661 fService.createSession("wrongName", null, new NullProgressMonitor());
662 fail("No exeption thrown");
663 } catch (ExecutionException e) {
664 // success
665 }
666
667 try {
668 fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
669 fail("No exeption thrown");
670 } catch (ExecutionException e) {
671 // success
672 }
673
674 try {
675 ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor());
676 assertNotNull(info);
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());
681
682 } catch (ExecutionException e) {
683 fail(e.toString());
684 }
685
686 try {
687 ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
688 assertNotNull(info);
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());
693
694 } catch (ExecutionException e) {
695 fail(e.toString());
696 }
697 }
698
699 @Test
700 public void testDestroySession() {
701 try {
702 fShell.setScenario(SCEN_DESTROY_SESSION1);
703 fService.destroySession("mysession2", new NullProgressMonitor());
704 } catch (ExecutionException e) {
705 fail(e.toString());
706 }
707 }
708
709 @Test
710 public void testDestroySessionVerbose() {
711 try {
712 enableVerbose();
713 fShell.setScenario(SCEN_DESTROY_SESSION_VERBOSE);
714 fService.destroySession("mysession2", new NullProgressMonitor());
715 } catch (ExecutionException e) {
716 fail(e.toString());
717 } finally {
718 disableVerbose();
719 }
720 }
721
722 @Test
723 public void testCreateChannel() {
724 try {
725
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);
732
733 fShell.setScenario(SCEN_CHANNEL_HANDLING);
734
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());
743
744 // Create/enable/configure 1 UST channel
745 list.clear();
746 list.add("ustChannel");
747
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());
755
756 } catch (ExecutionException e) {
757 fail(e.toString());
758 }
759 }
760
761 @Test
762 public void testDisableChannel() {
763 try {
764
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);
771
772 fShell.setScenario(SCEN_CHANNEL_HANDLING);
773 fService.disableChannels(sessionName, list, true, new NullProgressMonitor());
774
775 list.clear();
776 list.add("ustChannel");
777 fService.disableChannels(sessionName, list, false, new NullProgressMonitor());
778
779 } catch (ExecutionException e) {
780 fail(e.toString());
781 }
782 }
783
784 @Test
785 public void testEnableChannel() {
786 try {
787
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);
794
795 fShell.setScenario(SCEN_CHANNEL_HANDLING);
796 fService.enableChannels(sessionName, list, true, null, new NullProgressMonitor());
797
798 // Create/enable/configure 1 UST channel
799 list.clear();
800 list.add("ustChannel");
801
802 fService.enableChannels(sessionName, list, false, null, new NullProgressMonitor());
803
804 } catch (ExecutionException e) {
805 fail(e.toString());
806 }
807 }
808
809 @Test
810 public void testEnableEvents() {
811 try {
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());
823
824 // 2) session name, channel=mychannel, event name= null, kernel
825 String channelName = "mychannel";
826 fService.enableEvents(sessionName, channelName, null, true, null, new NullProgressMonitor());
827
828 // 3) session name, channel=mychannel, 1 event name, ust, no filter
829 String ustEventName = "ust_tests_hello:tptest_sighandler";
830 list.clear();
831 list.add(ustEventName);
832 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
833
834 // 4) session name, channel = mychannel, no event name, ust, with filter
835 fService.enableEvents(sessionName, channelName, list, false, "intfield==10", new NullProgressMonitor());
836
837 // 5) session name, channel = mychannel, no event name, ust, no filter
838 list.clear();
839 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
840
841 // TODO add test with filters
842
843 } catch (ExecutionException e) {
844 fail(e.toString());
845 }
846 }
847
848 @Test
849 public void testEnableSyscalls() {
850 try {
851 // 1) session name, channel = null, 3 event names, kernel
852 String sessionName = "mysession2";
853 String channelName = "mychannel";
854
855 fShell.setScenario(SCEN_EVENT_HANDLING);
856
857 // 1) session name, channel = null
858 fService.enableSyscalls(sessionName, null, new NullProgressMonitor());
859
860 // 2) session name, channel = mychannel
861 fService.enableSyscalls(sessionName, channelName, new NullProgressMonitor());
862
863 } catch (ExecutionException e) {
864 fail(e.toString());
865 }
866 }
867
868 @Test
869 public void testDynamicProbe() {
870 try {
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";
878
879 fShell.setScenario(SCEN_EVENT_HANDLING);
880
881 // 1) session name, channel = null, event name, function probe, probe
882 fService.enableProbe(sessionName, null, eventName0, true, functionProbe, new NullProgressMonitor());
883
884 // 2) session name, channel = mychannel
885 fService.enableProbe(sessionName, channelName, eventName1, false, dynProbe, new NullProgressMonitor());
886
887 } catch (ExecutionException e) {
888 fail(e.toString());
889 }
890 }
891
892 @Test
893 public void testEnableLogLevel() {
894 try {
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";
900
901 fShell.setScenario(SCEN_EVENT_HANDLING);
902
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());
905
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());
908
909 // TODO add test with filters
910
911 } catch (ExecutionException e) {
912 fail(e.toString());
913 }
914 }
915
916 @Test
917 public void testAddContext() {
918 try {
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");
925 contexts.add("pid");
926
927 fShell.setScenario(SCEN_CONTEXT_HANDLING);
928
929 List<String> availContexts = fService.getContextList(new NullProgressMonitor());
930 assertNotNull(availContexts);
931 assertEquals(12, availContexts.size());
932
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");
947
948 assertTrue(expectedContexts.containsAll(availContexts));
949
950 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
951 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
952
953 } catch (ExecutionException e) {
954 fail(e.toString());
955 }
956 }
957
958 @Test
959 public void testAddContextFailure() {
960
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");
967 contexts.add("pid");
968 fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
969 try {
970 fService.getContextList(new NullProgressMonitor());
971 fail("No exeption generated");
972 } catch (ExecutionException e) {
973 // success
974 }
975 try {
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) {
980 // success
981 }
982 }
983
984 @Test
985 public void testCalibrate() {
986 try {
987 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
988 fService.calibrate(true, new NullProgressMonitor());
989
990 } catch (ExecutionException e) {
991 fail(e.toString());
992 }
993 }
994
995 @Test
996 public void testCalibrateFailure() {
997 try {
998 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
999 fService.calibrate(false, new NullProgressMonitor());
1000 fail("No exeption generated");
1001 } catch (ExecutionException e) {
1002 // success
1003 }
1004 }
1005
1006 @Test
1007 public void testCreateSession2_1() {
1008
1009 try {
1010 fShell.setScenario(SCEN_CREATE_SESSION_2_1);
1011
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());
1018
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());
1025
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());
1032
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());
1039
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());
1046
1047 // verbose
1048 enableVerbose();
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());
1054 disableVerbose();
1055 fService.destroySession("mysession", new NullProgressMonitor());
1056
1057
1058 } catch (ExecutionException e) {
1059 fail(e.toString());
1060 }
1061 }
1062
1063 @Test
1064 public void testCreateSessionVerbose2_1() {
1065 try {
1066 fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
1067
1068 enableVerbose();
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) {
1076 fail(e.toString());
1077 } finally {
1078 disableVerbose();
1079 }
1080 }
1081
1082 private static void enableVerbose() {
1083 // verbose
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);
1087 }
1088
1089 private static void disableVerbose() {
1090 ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false);
1091 }
1092
1093
1094 }
This page took 0.071676 seconds and 5 git commands to generate.