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