1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.tests
.control
.service
;
14 import java
.util
.List
;
16 import junit
.framework
.TestCase
;
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
;
35 * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>.
37 @SuppressWarnings("nls")
38 public class LTTngControlServiceTest
extends TestCase
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
42 private CommandShellFactory fShellFactory
;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * Perform pre-test initialization.
54 * @throws Exception if the initialization fails for some reason
58 public void setUp() throws Exception
{
60 fShellFactory
= CommandShellFactory
.getInstance();
64 * Perform post-test clean-up.
66 * @throws Exception if the clean-up fails for some reason
70 public void tearDown() throws Exception
{
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
77 public void testGetSessionNames() {
79 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForLttngNotExistsShell());
80 service
.getSessionNames(new NullProgressMonitor());
81 fail("No exeption thrown");
83 } catch (ExecutionException e
) {
88 public void testGetSessionNames1() {
90 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForNoSessionNames());
91 String
[] result
= service
.getSessionNames(new NullProgressMonitor());
93 assertNotNull(result
);
94 assertEquals(0, result
.length
);
96 } catch (ExecutionException e
) {
101 public void testGetSessionNames2() {
103 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
104 String
[] result
= service
.getSessionNames(new NullProgressMonitor());
106 assertNotNull(result
);
107 assertEquals(2, result
.length
);
108 assertEquals("mysession1", result
[0]);
109 assertEquals("mysession", result
[1]);
111 } catch (ExecutionException e
) {
116 public void testGetSessionNotExist() {
118 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNotExists());
119 service
.getSessionNames(new NullProgressMonitor());
120 fail("No exeption thrown");
122 } catch (ExecutionException e
) {
127 public void testGetSessionNameGarbage() {
129 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionGarbage());
130 String
[] result
= service
.getSessionNames(new NullProgressMonitor());
132 assertNotNull(result
);
133 assertEquals(0, result
.length
);
135 } catch (ExecutionException e
) {
140 public void testGetSession1() {
142 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
143 ISessionInfo session
= service
.getSession("mysession", new NullProgressMonitor());
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());
151 IDomainInfo
[] domains
= session
.getDomains();
152 assertNotNull(domains
);
153 assertEquals(2, domains
.length
);
155 // Verify Kernel domain
156 assertEquals("Kernel", domains
[0].getName());
157 IChannelInfo
[] channels
= domains
[0].getChannels();
158 assertNotNull(channels
);
159 assertEquals(2, channels
.length
);
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());
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());
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());
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());
196 IEventInfo
[] channel1Events
= channels
[1].getEvents();
197 assertEquals(0, channel1Events
.length
);
199 // Verify domain UST global
200 assertEquals("UST global", domains
[1].getName());
202 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
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());
215 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
216 assertEquals(0, ustEvents
.length
);
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());
229 ustEvents
= ustChannels
[1].getEvents();
230 assertEquals(2, ustEvents
.length
);
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());
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());
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());
249 domains
= session
.getDomains();
250 assertNotNull(domains
);
251 assertEquals(0, domains
.length
);
252 } catch (ExecutionException e
) {
257 public void testGetKernelProvider() {
259 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
260 List
<IBaseEventInfo
> events
= service
.getKernelProvider(new NullProgressMonitor());
263 assertNotNull(events
);
264 assertEquals(3, events
.size());
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());
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());
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());
282 } catch (ExecutionException e
) {
287 public void testGetUstProvider() {
289 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
290 List
<IUstProviderInfo
> providers
= service
.getUstProvider();
292 // Check all providers
293 assertNotNull(providers
);
294 assertEquals(2, providers
.size());
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());
301 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
302 assertNotNull(events
);
303 assertEquals(2, events
.length
);
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());
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());
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());
321 events
= providers
.get(1).getEvents();
322 assertNotNull(events
);
323 assertEquals(2, events
.length
);
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());
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());
336 } catch (ExecutionException e
) {
341 public void testUstProvider2() {
343 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForNoUstProvider());
344 List
<IUstProviderInfo
> providers
= service
.getUstProvider();
346 assertNotNull(providers
);
347 assertEquals(0, providers
.size());
349 } catch (ExecutionException e
) {
354 public void testCreateSession() {
356 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
357 ISessionInfo info
= service
.createSession("mysession2", null, new NullProgressMonitor());
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
) {
368 public void testCreateSessionErrors() {
369 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionErrors());
371 service
.createSession("alreadyExist", null, new NullProgressMonitor());
372 fail("No exeption thrown");
373 } catch (ExecutionException e
) {
378 service
.createSession("wrongName", null, new NullProgressMonitor());
379 fail("No exeption thrown");
380 } catch (ExecutionException e
) {
385 service
.createSession("wrongPath", "/home/user/hallo", new NullProgressMonitor());
386 fail("No exeption thrown");
387 } catch (ExecutionException e
) {
392 ISessionInfo info
= service
.createSession("session with spaces", null, new NullProgressMonitor());
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());
399 } catch (ExecutionException e
) {
404 ISessionInfo info
= service
.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor());
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());
411 } catch (ExecutionException e
) {
416 void testDestroySession() {
418 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionErrors());
419 service
.destroySession("mysession2", new NullProgressMonitor());
420 } catch (ExecutionException e
) {
425 // public void testCreateChannel() {
428 //// public void enableChannel(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor);
429 // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
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());