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