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