Add new LTTng commands (create/destroy/start/stop session,
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / src / org / eclipse / linuxtools / lttng / ui / tests / control / service / LTTngControlServiceTest.java
1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.tests.control.service;
13
14 import java.util.List;
15
16 import junit.framework.TestCase;
17
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.NullProgressMonitor;
21 import org.eclipse.linuxtools.lttng.stubs.service.CommandShellFactory;
22 import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo;
23 import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo;
24 import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo;
25 import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo;
26 import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo;
27 import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo;
28 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement;
29 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType;
30 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel;
31 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
32 import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService;
33 import org.eclipse.linuxtools.lttng.ui.views.control.service.LTTngControlService;
34 /**
35 * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>.
36 */
37 @SuppressWarnings("nls")
38 public class LTTngControlServiceTest extends TestCase {
39 // ------------------------------------------------------------------------
40 // Test data
41 // ------------------------------------------------------------------------
42 private CommandShellFactory fShellFactory;
43
44 // ------------------------------------------------------------------------
45 // Static methods
46 // ------------------------------------------------------------------------
47
48 // ------------------------------------------------------------------------
49 // Housekeeping
50 // ------------------------------------------------------------------------
51 /**
52 * Perform pre-test initialization.
53 *
54 * @throws Exception if the initialization fails for some reason
55 *
56 */
57 @Override
58 public void setUp() throws Exception {
59 super.setUp();
60 fShellFactory = CommandShellFactory.getInstance();
61 }
62
63 /**
64 * Perform post-test clean-up.
65 *
66 * @throws Exception if the clean-up fails for some reason
67 *
68 */
69 @Override
70 public void tearDown() throws Exception {
71 }
72
73 // ------------------------------------------------------------------------
74 // Test Cases
75 // ------------------------------------------------------------------------
76
77 public void testGetSessionNames() {
78 try {
79 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForLttngNotExistsShell());
80 service.getSessionNames(new NullProgressMonitor());
81 fail("No exeption thrown");
82
83 } catch (ExecutionException e) {
84 // success
85 }
86 }
87
88 public void testGetSessionNames1() {
89 try {
90 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoSessionNames());
91 String[] result = service.getSessionNames(new NullProgressMonitor());
92
93 assertNotNull(result);
94 assertEquals(0, result.length);
95
96 } catch (ExecutionException e) {
97 fail(e.toString());
98 }
99 }
100
101 public void testGetSessionNames2() {
102 try {
103 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
104 String[] result = service.getSessionNames(new NullProgressMonitor());
105
106 assertNotNull(result);
107 assertEquals(2, result.length);
108 assertEquals("mysession1", result[0]);
109 assertEquals("mysession", result[1]);
110
111 } catch (ExecutionException e) {
112 fail(e.toString());
113 }
114 }
115
116 public void testGetSessionNotExist() {
117 try {
118 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNotExists());
119 service.getSessionNames(new NullProgressMonitor());
120 fail("No exeption thrown");
121
122 } catch (ExecutionException e) {
123 // success
124 }
125 }
126
127 public void testGetSessionNameGarbage() {
128 try {
129 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionGarbage());
130 String[] result = service.getSessionNames(new NullProgressMonitor());
131
132 assertNotNull(result);
133 assertEquals(0, result.length);
134
135 } catch (ExecutionException e) {
136 fail(e.toString());
137 }
138 }
139
140 public void testGetSession1() {
141 try {
142 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
143 ISessionInfo session = service.getSession("mysession", new NullProgressMonitor());
144
145 // Verify Session
146 assertNotNull(session);
147 assertEquals("mysession", session.getName());
148 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath());
149 assertEquals(TraceSessionState.ACTIVE, session.getSessionState());
150
151 IDomainInfo[] domains = session.getDomains();
152 assertNotNull(domains);
153 assertEquals(2, domains.length);
154
155 // Verify Kernel domain
156 assertEquals("Kernel", domains[0].getName());
157 IChannelInfo[] channels = domains[0].getChannels();
158 assertNotNull(channels);
159 assertEquals(2, channels.length);
160
161 // Verify Kernel's channel0
162 assertEquals("channel0", channels[0].getName());
163 assertEquals(4, channels[0].getNumberOfSubBuffers());
164 assertEquals("splice()", channels[0].getOutputType());
165 assertEquals(false, channels[0].isOverwriteMode());
166 assertEquals(200, channels[0].getReadTimer());
167 assertEquals(TraceEnablement.ENABLED, channels[0].getState());
168 assertEquals(262144, channels[0].getSubBufferSize());
169 assertEquals(0, channels[0].getSwitchTimer());
170
171 // Verify event info
172 IEventInfo[] channel0Events = channels[0].getEvents();
173 assertNotNull(channel0Events);
174 assertEquals(2, channel0Events.length);
175 assertEquals("block_rq_remap", channel0Events[0].getName());
176 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel());
177 assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType());
178 assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState());
179
180 assertEquals("block_bio_remap", channel0Events[1].getName());
181 assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel());
182 assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType());
183 assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState());
184
185 // Verify Kernel's channel1
186 assertEquals("channel1", channels[1].getName());
187 assertEquals(4, channels[1].getNumberOfSubBuffers());
188 assertEquals("splice()", channels[1].getOutputType());
189 assertEquals(true, channels[1].isOverwriteMode());
190 assertEquals(400, channels[1].getReadTimer());
191 assertEquals(TraceEnablement.DISABLED, channels[1].getState());
192 assertEquals(524288, channels[1].getSubBufferSize());
193 assertEquals(100, channels[1].getSwitchTimer());
194
195 // Verify event info
196 IEventInfo[] channel1Events = channels[1].getEvents();
197 assertEquals(0, channel1Events.length);
198
199 // Verify domain UST global
200 assertEquals("UST global", domains[1].getName());
201
202 IChannelInfo[] ustChannels = domains[1].getChannels();
203
204 // Verify UST global's mychannel1
205 assertEquals("mychannel1", ustChannels[0].getName());
206 assertEquals(8, ustChannels[0].getNumberOfSubBuffers());
207 assertEquals("mmap()", ustChannels[0].getOutputType());
208 assertEquals(true, ustChannels[0].isOverwriteMode());
209 assertEquals(100, ustChannels[0].getReadTimer());
210 assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState());
211 assertEquals(8192, ustChannels[0].getSubBufferSize());
212 assertEquals(200, ustChannels[0].getSwitchTimer());
213
214 // Verify event info
215 IEventInfo[] ustEvents = ustChannels[0].getEvents();
216 assertEquals(0, ustEvents.length);
217
218 // Verify UST global's channel0
219 assertEquals("channel0", ustChannels[1].getName());
220 assertEquals(4, ustChannels[1].getNumberOfSubBuffers());
221 assertEquals("mmap()", ustChannels[1].getOutputType());
222 assertEquals(false, ustChannels[1].isOverwriteMode());
223 assertEquals(200, ustChannels[1].getReadTimer());
224 assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState());
225 assertEquals(4096, ustChannels[1].getSubBufferSize());
226 assertEquals(0, ustChannels[1].getSwitchTimer());
227
228 // Verify event info
229 ustEvents = ustChannels[1].getEvents();
230 assertEquals(2, ustEvents.length);
231
232 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName());
233 assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel());
234 assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType());
235 assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState());
236
237 assertEquals("*", ustEvents[1].getName());
238 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, ustEvents[1].getLogLevel());
239 assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType());
240 assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState());
241
242 // next session (no detailed information available)
243 session = service.getSession("mysession1", new NullProgressMonitor());
244 assertNotNull(session);
245 assertEquals("mysession1", session.getName());
246 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath());
247 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
248
249 domains = session.getDomains();
250 assertNotNull(domains);
251 assertEquals(0, domains.length);
252 } catch (ExecutionException e) {
253 fail(e.toString());
254 }
255 }
256
257 public void testGetKernelProvider() {
258 try {
259 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
260 List<IBaseEventInfo> events = service.getKernelProvider(new NullProgressMonitor());
261
262 // Verify event info
263 assertNotNull(events);
264 assertEquals(3, events.size());
265
266 IBaseEventInfo baseEventInfo = (IBaseEventInfo) events.get(0);
267 assertNotNull(baseEventInfo);
268 assertEquals("sched_kthread_stop", baseEventInfo.getName());
269 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
270 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
271
272 baseEventInfo = (IBaseEventInfo) events.get(1);
273 assertEquals("sched_kthread_stop_ret", baseEventInfo.getName());
274 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
275 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
276
277 baseEventInfo = (IBaseEventInfo) events.get(2);
278 assertEquals("sched_wakeup_new", baseEventInfo.getName());
279 assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel());
280 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
281
282 } catch (ExecutionException e) {
283 fail(e.toString());
284 }
285 }
286
287 public void testGetUstProvider() {
288 try {
289 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
290 List<IUstProviderInfo> providers = service.getUstProvider();
291
292 // Check all providers
293 assertNotNull(providers);
294 assertEquals(2, providers.size());
295
296 //Verify first provider
297 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName());
298 assertEquals(9379, providers.get(0).getPid());
299
300 // Verify event info
301 IBaseEventInfo[] events = providers.get(0).getEvents();
302 assertNotNull(events);
303 assertEquals(2, events.length);
304
305 IBaseEventInfo baseEventInfo = (IBaseEventInfo) events[0];
306 assertNotNull(baseEventInfo);
307 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
308 assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel());
309 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
310
311 baseEventInfo = (IBaseEventInfo) events[1];
312 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
313 assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel());
314 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
315
316 //Verify second provider
317 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName());
318 assertEquals(4852, providers.get(1).getPid());
319
320 // Verify event info
321 events = providers.get(1).getEvents();
322 assertNotNull(events);
323 assertEquals(2, events.length);
324
325 baseEventInfo = (IBaseEventInfo) events[0];
326 assertNotNull(baseEventInfo);
327 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
328 assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel());
329 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
330
331 baseEventInfo = (IBaseEventInfo) events[1];
332 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
333 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel());
334 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
335
336 } catch (ExecutionException e) {
337 fail(e.toString());
338 }
339 }
340
341 public void testUstProvider2() {
342 try {
343 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoUstProvider());
344 List<IUstProviderInfo> providers = service.getUstProvider();
345
346 assertNotNull(providers);
347 assertEquals(0, providers.size());
348
349 } catch (ExecutionException e) {
350 fail(e.toString());
351 }
352 }
353
354 public void testCreateSession() {
355 try {
356 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
357 ISessionInfo info = service.createSession("mysession2", null, new NullProgressMonitor());
358 assertNotNull(info);
359 assertEquals("mysession2", info.getName());
360 assertNotNull(info.getSessionPath());
361 assertTrue(info.getSessionPath().contains("mysession2"));
362 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
363 } catch (ExecutionException e) {
364 fail(e.toString());
365 }
366 }
367
368 public void testCreateSessionErrors() {
369 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionErrors());
370 try {
371 service.createSession("alreadyExist", null, new NullProgressMonitor());
372 fail("No exeption thrown");
373 } catch (ExecutionException e) {
374 // success
375 }
376
377 try {
378 service.createSession("wrongName", null, new NullProgressMonitor());
379 fail("No exeption thrown");
380 } catch (ExecutionException e) {
381 // success
382 }
383
384 try {
385 service.createSession("wrongPath", "/home/user/hallo", new NullProgressMonitor());
386 fail("No exeption thrown");
387 } catch (ExecutionException e) {
388 // success
389 }
390
391 try {
392 ISessionInfo info = service.createSession("session with spaces", null, new NullProgressMonitor());
393 assertNotNull(info);
394 assertEquals("session with spaces", info.getName());
395 assertNotNull(info.getSessionPath());
396 assertTrue(info.getSessionPath().contains("session with spaces"));
397 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
398
399 } catch (ExecutionException e) {
400 fail(e.toString());
401 }
402
403 try {
404 ISessionInfo info = service.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
405 assertNotNull(info);
406 assertEquals("pathWithSpaces", info.getName());
407 assertNotNull(info.getSessionPath());
408 assertTrue(info.getSessionPath().contains("/home/user/hallo user/here"));
409 assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
410
411 } catch (ExecutionException e) {
412 fail(e.toString());
413 }
414 }
415
416 void testDestroySession() {
417 try {
418 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionErrors());
419 service.destroySession("mysession2", new NullProgressMonitor());
420 } catch (ExecutionException e) {
421 fail(e.toString());
422 }
423 }
424
425 // public void testCreateChannel() {
426 // try {
427 //
428 //// public void enableChannel(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor);
429 // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
430 //
431 //
432 // ISessionInfo info = service.createSession("mysession2", null, new NullProgressMonitor());
433 // assertNotNull(info);
434 // assertEquals("mysession2", info.getName());
435 // assertNotNull(info.getSessionPath());
436 // assertTrue(info.getSessionPath().contains("mysession2"));
437 // assertEquals(TraceSessionState.INACTIVE, info.getSessionState());
438 // } catch (ExecutionException e) {
439 // fail(e.toString());
440 // }
441 // }
442
443
444
445 }
This page took 0.039611 seconds and 5 git commands to generate.