lttng: Port unit tests to JUnit4
[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.*;
17
18 import java.io.File;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.eclipse.core.commands.ExecutionException;
26 import org.eclipse.core.runtime.FileLocator;
27 import org.eclipse.core.runtime.NullProgressMonitor;
28 import org.eclipse.core.runtime.Path;
29 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo;
30 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
31 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
32 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
33 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
34 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
35 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo;
36 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
37 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
38 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
39 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
40 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
41 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
42 import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
43 import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
44 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
45 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService;
46 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.osgi.framework.FrameworkUtil;
50
51 /**
52 * The class <code>LTTngControlServiceTest</code> contains test for the class
53 * <code>{@link LTTngControlService}</code>.
54 */
55 @SuppressWarnings({"nls", "javadoc"})
56 public class LTTngControlServiceTest {
57
58 private static final String DIRECTORY = "testfiles";
59 private static final String TEST_STREAM = "LTTngServiceTest.cfg";
60
61 private static final String SCEN_LTTNG_NOT_INSTALLED = "LttngNotInstalled";
62 private static final String SCEN_LTTNG_VERSION = "LttngVersion";
63 private static final String SCEN_LTTNG_VERSION_WITH_PROMPT = "LttngVersionWithPrompt";
64 private static final String SCEN_LTTNG_UNSUPPORTED_VERSION = "LttngUnsupportedVersion";
65 private static final String SCEN_LTTNG_NO_VERSION = "LttngNoVersion";
66 private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
67 private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
68 private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
69 private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
70 private static final String SCEN_GET_SESSION1 = "GetSession1";
71 private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
72 private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
73 private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
74 private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
75 private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
76 private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
77 private static final String SCEN_CREATE_SESSION1 = "CreateSession1";
78 private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
79 private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
80 private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
81 private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
82 private static final String SCEN_EVENT_HANDLING = "EventHandling";
83 private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
84 private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
85 private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
86
87 // ------------------------------------------------------------------------
88 // Test data
89 // ------------------------------------------------------------------------
90
91 private CommandShellFactory fShellFactory;
92 private String fTestfile;
93 private LTTngToolsFileShell fShell;
94 private ILttngControlService fService;
95
96 // ------------------------------------------------------------------------
97 // Housekeeping
98 // ------------------------------------------------------------------------
99
100 /**
101 * Perform pre-test initialization.
102 *
103 * @throws Exception
104 * if the initialization fails for some reason
105 */
106 @Before
107 public void setUp() throws Exception {
108 fShellFactory = CommandShellFactory.getInstance();
109
110 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(DIRECTORY + File.separator + TEST_STREAM), null);
111 File testfile = new File(FileLocator.toFileURL(location).toURI());
112 fTestfile = testfile.getAbsolutePath();
113
114 fShell = fShellFactory.getFileShell();
115 fShell.loadScenarioFile(fTestfile);
116 fService = new LTTngControlService(fShell);
117 }
118
119 // ------------------------------------------------------------------------
120 // Test Cases
121 // ------------------------------------------------------------------------
122
123 @Test
124 public void testVersion() {
125 try {
126 fShell.setScenario(SCEN_LTTNG_VERSION);
127 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
128 assertNotNull(service);
129 assertEquals("2.1.0", service.getVersion());
130 } catch (ExecutionException e) {
131 fail("Exeption thrown " + e);
132 }
133 }
134
135 @Test
136 public void testVersionWithPrompt() {
137 try {
138 fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT);
139 ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
140 assertNotNull(service);
141 assertEquals("2.0.0", service.getVersion());
142 } catch (ExecutionException e) {
143 fail("Exeption thrown " + e);
144 }
145 }
146
147 @Test
148 public void testUnsupportedVersion() {
149 try {
150 fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION);
151 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
152 fail("No exeption thrown");
153 } catch (ExecutionException e) {
154 // success
155 }
156 }
157
158 @Test
159 public void testNoVersion() {
160 try {
161 fShell.setScenario(SCEN_LTTNG_NO_VERSION);
162 LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
163 fail("No exeption thrown");
164 } catch (ExecutionException e) {
165 // success
166 }
167 }
168
169 @Test
170 public void testLttngNotInstalled() {
171 try {
172 fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED);
173 fService.getSessionNames(new NullProgressMonitor());
174 fail("No exeption thrown");
175 } catch (ExecutionException e) {
176 // success
177 }
178 }
179
180 @Test
181 public void testGetSessionNames1() {
182 try {
183 fShell.setScenario(SCEN_NO_SESSION_AVAILABLE);
184 String[] result = fService.getSessionNames(new NullProgressMonitor());
185
186 assertNotNull(result);
187 assertEquals(0, result.length);
188
189 } catch (ExecutionException e) {
190 fail(e.toString());
191 }
192 }
193
194 @Test
195 public void testGetSessionNames2() {
196 try {
197 fShell.setScenario(SCEN_GET_SESSION_NAMES1);
198 String[] result = fService.getSessionNames(new NullProgressMonitor());
199
200 assertNotNull(result);
201 assertEquals(2, result.length);
202 assertEquals("mysession1", result[0]);
203 assertEquals("mysession", result[1]);
204
205 } catch (ExecutionException e) {
206 fail(e.toString());
207 }
208 }
209
210 @Test
211 public void testGetSessionNotExist() {
212 try {
213 fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST);
214 fService.getSessionNames(new NullProgressMonitor());
215 fail("No exeption thrown");
216
217 } catch (ExecutionException e) {
218 // success
219 }
220 }
221
222 @Test
223 public void testGetSessionNameGarbage() {
224 try {
225 fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
226 String[] result = fService.getSessionNames(new NullProgressMonitor());
227
228 assertNotNull(result);
229 assertEquals(0, result.length);
230
231 } catch (ExecutionException e) {
232 fail(e.toString());
233 }
234 }
235
236 @Test
237 public void testGetSession1() {
238 try {
239 fShell.setScenario(SCEN_GET_SESSION1);
240 ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor());
241
242 // Verify Session
243 assertNotNull(session);
244 assertEquals("mysession", session.getName());
245 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath());
246 assertEquals(TraceSessionState.ACTIVE, session.getSessionState());
247
248 IDomainInfo[] domains = session.getDomains();
249 assertNotNull(domains);
250 assertEquals(2, domains.length);
251
252 // Verify Kernel domain
253 assertEquals("Kernel", domains[0].getName());
254 IChannelInfo[] channels = domains[0].getChannels();
255 assertNotNull(channels);
256 assertEquals(2, channels.length);
257
258 // Verify Kernel's channel0
259 assertEquals("channel0", channels[0].getName());
260 assertEquals(4, channels[0].getNumberOfSubBuffers());
261 assertEquals("splice()", channels[0].getOutputType());
262 assertEquals(false, channels[0].isOverwriteMode());
263 assertEquals(200, channels[0].getReadTimer());
264 assertEquals(TraceEnablement.ENABLED, channels[0].getState());
265 assertEquals(262144, channels[0].getSubBufferSize());
266 assertEquals(0, channels[0].getSwitchTimer());
267
268 // Verify event info
269 IEventInfo[] channel0Events = channels[0].getEvents();
270 assertNotNull(channel0Events);
271 assertEquals(2, channel0Events.length);
272 assertEquals("block_rq_remap", channel0Events[0].getName());
273 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel());
274 assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType());
275 assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState());
276
277 assertEquals("block_bio_remap", channel0Events[1].getName());
278 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel());
279 assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType());
280 assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState());
281
282 // Verify Kernel's channel1
283 assertEquals("channel1", channels[1].getName());
284 assertEquals(4, channels[1].getNumberOfSubBuffers());
285 assertEquals("splice()", channels[1].getOutputType());
286 assertEquals(true, channels[1].isOverwriteMode());
287 assertEquals(400, channels[1].getReadTimer());
288 assertEquals(TraceEnablement.DISABLED, channels[1].getState());
289 assertEquals(524288, channels[1].getSubBufferSize());
290 assertEquals(100, channels[1].getSwitchTimer());
291
292 // Verify event info
293 IEventInfo[] channel1Events = channels[1].getEvents();
294 assertEquals(0, channel1Events.length);
295
296 // Verify domain UST global
297 assertEquals("UST global", domains[1].getName());
298
299 IChannelInfo[] ustChannels = domains[1].getChannels();
300
301 // Verify UST global's mychannel1
302 assertEquals("mychannel1", ustChannels[0].getName());
303 assertEquals(8, ustChannels[0].getNumberOfSubBuffers());
304 assertEquals("mmap()", ustChannels[0].getOutputType());
305 assertEquals(true, ustChannels[0].isOverwriteMode());
306 assertEquals(100, ustChannels[0].getReadTimer());
307 assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState());
308 assertEquals(8192, ustChannels[0].getSubBufferSize());
309 assertEquals(200, ustChannels[0].getSwitchTimer());
310
311 // Verify event info
312 IEventInfo[] ustEvents = ustChannels[0].getEvents();
313 assertEquals(0, ustEvents.length);
314
315 // Verify UST global's channel0
316 assertEquals("channel0", ustChannels[1].getName());
317 assertEquals(4, ustChannels[1].getNumberOfSubBuffers());
318 assertEquals("mmap()", ustChannels[1].getOutputType());
319 assertEquals(false, ustChannels[1].isOverwriteMode());
320 assertEquals(200, ustChannels[1].getReadTimer());
321 assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState());
322 assertEquals(4096, ustChannels[1].getSubBufferSize());
323 assertEquals(0, ustChannels[1].getSwitchTimer());
324
325 // Verify event info
326 ustEvents = ustChannels[1].getEvents();
327 assertEquals(2, ustEvents.length);
328
329 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName());
330 assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel());
331 assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType());
332 assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState());
333
334 assertEquals("*", ustEvents[1].getName());
335 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, ustEvents[1].getLogLevel());
336 assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType());
337 assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState());
338
339 // next session (no detailed information available)
340 session = fService.getSession("mysession1", new NullProgressMonitor());
341 assertNotNull(session);
342 assertEquals("mysession1", session.getName());
343 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath());
344 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
345
346 domains = session.getDomains();
347 assertNotNull(domains);
348 assertEquals(0, domains.length);
349 } catch (ExecutionException e) {
350 fail(e.toString());
351 }
352 }
353
354 public void testGetKernelProvider() {
355 try {
356 fShell.setScenario(SCEN_GET_KERNEL_PROVIDER1);
357 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
358
359 // Verify event info
360 assertNotNull(events);
361 assertEquals(3, events.size());
362
363 IBaseEventInfo baseEventInfo = events.get(0);
364 assertNotNull(baseEventInfo);
365 assertEquals("sched_kthread_stop", baseEventInfo.getName());
366 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
367 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
368
369 baseEventInfo = events.get(1);
370 assertEquals("sched_kthread_stop_ret", baseEventInfo.getName());
371 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
372 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
373
374 baseEventInfo = events.get(2);
375 assertEquals("sched_wakeup_new", baseEventInfo.getName());
376 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
377 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
378
379 } catch (ExecutionException e) {
380 fail(e.toString());
381 }
382 }
383
384 @Test
385 public void testGetKernelProviderNoKernel1() {
386 try {
387 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1);
388 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
389
390 // Verify event info
391 assertNotNull(events);
392 assertEquals(0, events.size());
393
394 } catch (ExecutionException e) {
395 fail(e.toString());
396 }
397 }
398
399 @Test
400 public void testGetKernelProviderNoKernel2() {
401 try {
402 fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2);
403 List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
404
405 // Verify event info
406 assertNotNull(events);
407 assertEquals(0, events.size());
408
409 } catch (ExecutionException e) {
410 fail(e.toString());
411 }
412 }
413
414 @Test
415 public void testGetUstProvider() {
416 try {
417 fShell.setScenario(SCEN_GET_UST_PROVIDER1);
418 List<IUstProviderInfo> providers = fService.getUstProvider();
419
420 // Check all providers
421 assertNotNull(providers);
422 assertEquals(2, providers.size());
423
424 //Verify first provider
425 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
426 assertEquals(9379, providers.get(0).getPid());
427
428 // Verify event info
429 IBaseEventInfo[] events = providers.get(0).getEvents();
430 assertNotNull(events);
431 assertEquals(2, events.length);
432
433 IBaseEventInfo baseEventInfo = events[0];
434 assertNotNull(baseEventInfo);
435 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
436 assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel());
437 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
438
439 baseEventInfo = events[1];
440 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
441 assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel());
442 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
443
444 //Verify second provider
445 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
446 assertEquals(4852, providers.get(1).getPid());
447
448 // Verify event info
449 events = providers.get(1).getEvents();
450 assertNotNull(events);
451 assertEquals(2, events.length);
452
453 baseEventInfo = events[0];
454 assertNotNull(baseEventInfo);
455 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
456 assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel());
457 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
458
459 baseEventInfo = events[1];
460 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
461 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel());
462 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
463
464 } catch (ExecutionException e) {
465 fail(e.toString());
466 }
467 }
468
469 @Test
470 public void testUstProvider2() {
471 try {
472 fShell.setScenario(SCEN_GET_UST_PROVIDER2);
473 List<IUstProviderInfo> providers = fService.getUstProvider();
474
475 assertNotNull(providers);
476 assertEquals(0, providers.size());
477
478 } catch (ExecutionException e) {
479 fail(e.toString());
480 }
481 }
482
483 @Test
484 public void testGetUstProvider3() {
485 try {
486 fShell.setScenario(SCEN_GET_UST_PROVIDER3);
487 // Set version
488 ((LTTngControlService)fService).setVersion("2.1.0");
489 List<IUstProviderInfo> providers = fService.getUstProvider();
490
491 // Check all providers
492 assertNotNull(providers);
493 assertEquals(2, providers.size());
494
495 //Verify first provider
496 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
497 assertEquals(9379, providers.get(0).getPid());
498
499 // Verify event info
500 IBaseEventInfo[] events = providers.get(0).getEvents();
501 assertNotNull(events);
502 assertEquals(2, events.length);
503
504 IBaseEventInfo baseEventInfo = events[0];
505 assertNotNull(baseEventInfo);
506 IFieldInfo[] fields = baseEventInfo.getFields();
507 assertNotNull(fields);
508 assertEquals(0, fields.length);
509
510 baseEventInfo = events[1];
511 fields = baseEventInfo.getFields();
512 assertNotNull(fields);
513 assertEquals(3, fields.length);
514 assertEquals("doublefield", fields[0].getName());
515 assertEquals("float", fields[0].getFieldType());
516
517 assertEquals("floatfield", fields[1].getName());
518 assertEquals("float", fields[1].getFieldType());
519
520 assertEquals("stringfield", fields[2].getName());
521 assertEquals("string", fields[2].getFieldType());
522
523 //Verify second provider
524 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
525 assertEquals(4852, providers.get(1).getPid());
526
527 // Verify event info
528 events = providers.get(1).getEvents();
529 assertNotNull(events);
530 assertEquals(2, events.length);
531
532 baseEventInfo = events[0];
533 assertNotNull(baseEventInfo);
534 fields = baseEventInfo.getFields();
535 assertNotNull(fields);
536 assertEquals(0, fields.length);
537
538 baseEventInfo = events[1];
539 fields = baseEventInfo.getFields();
540 assertNotNull(fields);
541 assertEquals(3, fields.length);
542
543 assertEquals("doublefield", fields[0].getName());
544 assertEquals("float", fields[0].getFieldType());
545
546 assertEquals("floatfield", fields[1].getName());
547 assertEquals("float", fields[1].getFieldType());
548
549 assertEquals("stringfield", fields[2].getName());
550 assertEquals("string", fields[2].getFieldType());
551
552 // Reset version
553 ((LTTngControlService)fService).setVersion("2.0.0");
554
555 } catch (ExecutionException e) {
556 fail(e.toString());
557 }
558 }
559
560 @Test
561 public void testCreateSession() {
562 try {
563 fShell.setScenario(SCEN_CREATE_SESSION1);
564
565 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
566 assertNotNull(info);
567 assertEquals("mysession2", info.getName());
568 assertNotNull(info.getSessionPath());
569 assertTrue(info.getSessionPath().contains("mysession2"));
570 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
571 } catch (ExecutionException e) {
572 fail(e.toString());
573 }
574 }
575
576 @Test
577 public void testCreateSessionWithPrompt() {
578 try {
579 // First line has the shell prompt before the command output
580 // This can happen in a real application if the command line is not echoed by the shell.
581 fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT);
582
583 // First line has no shell prompt before the output
584 ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor());
585 assertNotNull(info);
586 assertEquals("mysession2", info.getName());
587 assertNotNull(info.getSessionPath());
588 assertTrue(info.getSessionPath().contains("mysession2"));
589 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
590 } catch (ExecutionException e) {
591 fail(e.toString());
592 }
593 }
594
595 @Test
596 public void testCreateSessionVariants() {
597
598 fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS);
599
600 try {
601 fService.createSession("alreadyExist", null, new NullProgressMonitor());
602 fail("No exeption thrown");
603 } catch (ExecutionException e) {
604 // success
605 }
606
607 try {
608 fService.createSession("wrongName", null, new NullProgressMonitor());
609 fail("No exeption thrown");
610 } catch (ExecutionException e) {
611 // success
612 }
613
614 try {
615 fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor());
616 fail("No exeption thrown");
617 } catch (ExecutionException e) {
618 // success
619 }
620
621 try {
622 ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor());
623 assertNotNull(info);
624 assertEquals("session with spaces", info.getName());
625 assertNotNull(info.getSessionPath());
626 assertTrue(info.getSessionPath().contains("session with spaces"));
627 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
628
629 } catch (ExecutionException e) {
630 fail(e.toString());
631 }
632
633 try {
634 ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
635 assertNotNull(info);
636 assertEquals("pathWithSpaces", info.getName());
637 assertNotNull(info.getSessionPath());
638 assertTrue(info.getSessionPath().contains("/home/user/hallo user/here"));
639 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
640
641 } catch (ExecutionException e) {
642 fail(e.toString());
643 }
644 }
645
646 @Test
647 public void testDestroySession() {
648 try {
649 fShell.setScenario(SCEN_DESTROY_SESSION1);
650 fService.destroySession("mysession2", new NullProgressMonitor());
651 } catch (ExecutionException e) {
652 fail(e.toString());
653 }
654 }
655
656 @Test
657 public void testCreateChannel() {
658 try {
659
660 String sessionName = "mysession2";
661 List<String> list = new ArrayList<String>();
662 String kernelChannel0 = "mychannel0";
663 String kernelChannel1 = "mychannel1";
664 list.add(kernelChannel0);
665 list.add(kernelChannel1);
666
667 fShell.setScenario(SCEN_CHANNEL_HANDLING);
668
669 // Create/enable/configure 2 kernel channels
670 ChannelInfo chanInfo = new ChannelInfo("");
671 chanInfo.setOverwriteMode(true);
672 chanInfo.setSubBufferSize(16384);
673 chanInfo.setReadTimer(100);
674 chanInfo.setSwitchTimer(200);
675 chanInfo.setNumberOfSubBuffers(2);
676 fService.enableChannels(sessionName, list, true, chanInfo, new NullProgressMonitor());
677
678 // Create/enable/configure 1 UST channel
679 list.clear();
680 list.add("ustChannel");
681
682 chanInfo = new ChannelInfo("");
683 chanInfo.setOverwriteMode(true);
684 chanInfo.setSubBufferSize(32768);
685 chanInfo.setReadTimer(200);
686 chanInfo.setSwitchTimer(100);
687 chanInfo.setNumberOfSubBuffers(1);
688 fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor());
689
690 } catch (ExecutionException e) {
691 fail(e.toString());
692 }
693 }
694
695 @Test
696 public void testDisableChannel() {
697 try {
698
699 String sessionName = "mysession2";
700 List<String> list = new ArrayList<String>();
701 String kernelChannel0 = "mychannel0";
702 String kernelChannel1 = "mychannel1";
703 list.add(kernelChannel0);
704 list.add(kernelChannel1);
705
706 fShell.setScenario(SCEN_CHANNEL_HANDLING);
707 fService.disableChannels(sessionName, list, true, new NullProgressMonitor());
708
709 list.clear();
710 list.add("ustChannel");
711 fService.disableChannels(sessionName, list, false, new NullProgressMonitor());
712
713 } catch (ExecutionException e) {
714 fail(e.toString());
715 }
716 }
717
718 @Test
719 public void testEnableChannel() {
720 try {
721
722 String sessionName = "mysession2";
723 List<String> list = new ArrayList<String>();
724 String kernelChannel0 = "mychannel0";
725 String kernelChannel1 = "mychannel1";
726 list.add(kernelChannel0);
727 list.add(kernelChannel1);
728
729 fShell.setScenario(SCEN_CHANNEL_HANDLING);
730 fService.enableChannels(sessionName, list, true, null, new NullProgressMonitor());
731
732 // Create/enable/configure 1 UST channel
733 list.clear();
734 list.add("ustChannel");
735
736 fService.enableChannels(sessionName, list, false, null, new NullProgressMonitor());
737
738 } catch (ExecutionException e) {
739 fail(e.toString());
740 }
741 }
742
743 // public void tesEnableChannelNoTracer() {
744 // try {
745 // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
746 // service.getSessionNames(new NullProgressMonitor());
747 // fail("No exeption thrown");
748 //
749 // } catch (ExecutionException e) {
750 // // success
751 // }
752 // }
753
754 @Test
755 public void testEnableEvents() {
756 try {
757 // 1) session name, channel = null, 3 event names, kernel
758 String sessionName = "mysession2";
759 List<String> list = new ArrayList<String>();
760 String eventName0 = "block_rq_remap";
761 String eventName1 = "block_bio_remap";
762 String eventName2 = "softirq_entry";
763 list.add(eventName0);
764 list.add(eventName1);
765 list.add(eventName2);
766 fShell.setScenario(SCEN_EVENT_HANDLING);
767 fService.enableEvents(sessionName, null, list, true, null, new NullProgressMonitor());
768
769 // 2) session name, channel=mychannel, event name= null, kernel
770 String channelName = "mychannel";
771 fService.enableEvents(sessionName, channelName, null, true, null, new NullProgressMonitor());
772
773 // 3) session name, channel=mychannel, 1 event name, ust, no filter
774 String ustEventName = "ust_tests_hello:tptest_sighandler";
775 list.clear();
776 list.add(ustEventName);
777 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
778
779 // 4) session name, channel = mychannel, no event name, ust, with filter
780 fService.enableEvents(sessionName, channelName, list, false, "intfield==10", new NullProgressMonitor());
781
782 // 5) session name, channel = mychannel, no event name, ust, no filter
783 list.clear();
784 fService.enableEvents(sessionName, channelName, list, false, null, new NullProgressMonitor());
785
786 // TODO add test with filters
787
788 } catch (ExecutionException e) {
789 fail(e.toString());
790 }
791 }
792
793 @Test
794 public void testEnableSyscalls() {
795 try {
796 // 1) session name, channel = null, 3 event names, kernel
797 String sessionName = "mysession2";
798 String channelName = "mychannel";
799
800 fShell.setScenario(SCEN_EVENT_HANDLING);
801
802 // 1) session name, channel = null
803 fService.enableSyscalls(sessionName, null, new NullProgressMonitor());
804
805 // 2) session name, channel = mychannel
806 fService.enableSyscalls(sessionName, channelName, new NullProgressMonitor());
807
808 } catch (ExecutionException e) {
809 fail(e.toString());
810 }
811 }
812
813 @Test
814 public void testDynamicProbe() {
815 try {
816 // 1) session name, channel = null, 3 event names, kernel
817 String sessionName = "mysession2";
818 String channelName = "mychannel";
819 String eventName0 = "myevent0";
820 String eventName1 = "myevent1";
821 String functionProbe = "0xc0101340";
822 String dynProbe = "init_post";
823
824 fShell.setScenario(SCEN_EVENT_HANDLING);
825
826 // 1) session name, channel = null, event name, function probe, probe
827 fService.enableProbe(sessionName, null, eventName0, true, functionProbe, new NullProgressMonitor());
828
829 // 2) session name, channel = mychannel
830 fService.enableProbe(sessionName, channelName, eventName1, false, dynProbe, new NullProgressMonitor());
831
832 } catch (ExecutionException e) {
833 fail(e.toString());
834 }
835 }
836
837 @Test
838 public void testEnableLogLevel() {
839 try {
840 // 1) session name, channel = null, 3 event names, kernel
841 String sessionName = "mysession2";
842 String channelName = "mychannel";
843 String eventName4 = "myevent4";
844 String eventName5 = "myevent5";
845
846 fShell.setScenario(SCEN_EVENT_HANDLING);
847
848 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
849 fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, null, new NullProgressMonitor());
850
851 // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION
852 fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, null, new NullProgressMonitor());
853
854 // TODO add test with filters
855
856 } catch (ExecutionException e) {
857 fail(e.toString());
858 }
859 }
860
861 @Test
862 public void testAddContext() {
863 try {
864 // 1) session name, channel = null, 3 event names, kernel
865 String sessionName = "mysession2";
866 String channelName = "mychannel";
867 String eventName = "ust_tests_hello:tptest_sighandler";
868 List<String> contexts = new ArrayList<String>();
869 contexts.add("prio");
870 contexts.add("pid");
871
872 fShell.setScenario(SCEN_CONTEXT_HANDLING);
873
874 List<String> availContexts = fService.getContextList(new NullProgressMonitor());
875 assertNotNull(availContexts);
876 assertEquals(12, availContexts.size());
877
878 // A very "hard-coded" way to verify but it works ...
879 Set<String> expectedContexts = new HashSet<String>();
880 expectedContexts.add("pid");
881 expectedContexts.add("procname");
882 expectedContexts.add("prio");
883 expectedContexts.add("nice");
884 expectedContexts.add("vpid");
885 expectedContexts.add("tid");
886 expectedContexts.add("pthread_id");
887 expectedContexts.add("vtid");
888 expectedContexts.add("ppid");
889 expectedContexts.add("vppid");
890 expectedContexts.add("perf:cpu-cycles");
891 expectedContexts.add("perf:cycles");
892
893 assertTrue(expectedContexts.containsAll(availContexts));
894
895 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
896 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
897
898 } catch (ExecutionException e) {
899 fail(e.toString());
900 }
901 }
902
903 @Test
904 public void testAddContextFailure() {
905
906 // 1) session name, channel = null, 3 event names, kernel
907 String sessionName = "mysession2";
908 String channelName = "mychannel";
909 String eventName = "ust_tests_hello:tptest_sighandler";
910 List<String> contexts = new ArrayList<String>();
911 contexts.add("prio");
912 contexts.add("pid");
913 fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING);
914 try {
915 fService.getContextList(new NullProgressMonitor());
916 fail("No exeption generated");
917 } catch (ExecutionException e) {
918 // success
919 }
920 try {
921 // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG
922 fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor());
923 fail("No exeption generated");
924 } catch (ExecutionException e) {
925 // success
926 }
927 }
928
929 @Test
930 public void testCalibrate() {
931 try {
932 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
933 fService.calibrate(true, new NullProgressMonitor());
934
935 } catch (ExecutionException e) {
936 fail(e.toString());
937 }
938 }
939
940 @Test
941 public void testCalibrateFailure() {
942 try {
943 fShell.setScenario(SCEN_CALIBRATE_HANDLING);
944 fService.calibrate(false, new NullProgressMonitor());
945 fail("No exeption generated");
946 } catch (ExecutionException e) {
947 // success
948 }
949 }
950
951 }
This page took 0.090278 seconds and 5 git commands to generate.