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