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
.linuxtools
.lttng
.stubs
.service
.CommandShellFactory
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IBaseEventInfo
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IChannelInfo
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IDomainInfo
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IEventInfo
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ISessionInfo
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IUstProviderInfo
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceEnablement
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceEventType
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceLogLevel
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceSessionState
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ILttngControlService
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.LTTngControlService
;
33 * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>.
35 @SuppressWarnings("nls")
36 public class LTTngControlServiceTest
extends TestCase
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
40 private CommandShellFactory fShellFactory
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * Perform pre-test initialization.
52 * @throws Exception if the initialization fails for some reason
56 public void setUp() throws Exception
{
58 fShellFactory
= CommandShellFactory
.getInstance();
62 * Perform post-test clean-up.
64 * @throws Exception if the clean-up fails for some reason
68 public void tearDown() throws Exception
{
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 public void testGetSessionNames() {
77 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForLttngNotExistsShell());
78 service
.getSessionNames();
79 fail("No exeption thrown");
81 } catch (ExecutionException e
) {
86 public void testGetSessionNames1() {
88 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForNoSessionNames());
89 String
[] result
= service
.getSessionNames();
91 assertNotNull(result
);
92 assertEquals(0, result
.length
);
94 } catch (ExecutionException e
) {
99 public void testGetSessionNames2() {
101 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
102 String
[] result
= service
.getSessionNames();
104 assertNotNull(result
);
105 assertEquals(2, result
.length
);
106 assertEquals("mysession1", result
[0]);
107 assertEquals("mysession", result
[1]);
109 } catch (ExecutionException e
) {
114 public void testGetSessionNotExist() {
116 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNotExists());
117 service
.getSessionNames();
118 fail("No exeption thrown");
120 } catch (ExecutionException e
) {
125 public void testGetSessionNameGarbage() {
127 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionGarbage());
128 String
[] result
= service
.getSessionNames();
130 assertNotNull(result
);
131 assertEquals(0, result
.length
);
133 } catch (ExecutionException e
) {
138 public void testGetSession1() {
140 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
141 ISessionInfo session
= service
.getSession("mysession");
144 assertNotNull(session
);
145 assertEquals("mysession", session
.getName());
146 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
147 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
149 IDomainInfo
[] domains
= session
.getDomains();
150 assertNotNull(domains
);
151 assertEquals(2, domains
.length
);
153 // Verify Kernel domain
154 assertEquals("Kernel", domains
[0].getName());
155 IChannelInfo
[] channels
= domains
[0].getChannels();
156 assertNotNull(channels
);
157 assertEquals(2, channels
.length
);
159 // Verify Kernel's channel0
160 assertEquals("channel0", channels
[0].getName());
161 assertEquals(4, channels
[0].getNumberOfSubBuffers());
162 assertEquals("splice()", channels
[0].getOutputType());
163 assertEquals(false, channels
[0].isOverwriteMode());
164 assertEquals(200, channels
[0].getReadTimer());
165 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
166 assertEquals(262144, channels
[0].getSubBufferSize());
167 assertEquals(0, channels
[0].getSwitchTimer());
170 IEventInfo
[] channel0Events
= channels
[0].getEvents();
171 assertNotNull(channel0Events
);
172 assertEquals(2, channel0Events
.length
);
173 assertEquals("block_rq_remap", channel0Events
[0].getName());
174 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[0].getLogLevel());
175 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[0].getEventType());
176 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
178 assertEquals("block_bio_remap", channel0Events
[1].getName());
179 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
180 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
181 assertEquals(TraceEnablement
.DISABLED
, channel0Events
[1].getState());
183 // Verify Kernel's channel1
184 assertEquals("channel1", channels
[1].getName());
185 assertEquals(4, channels
[1].getNumberOfSubBuffers());
186 assertEquals("splice()", channels
[1].getOutputType());
187 assertEquals(true, channels
[1].isOverwriteMode());
188 assertEquals(400, channels
[1].getReadTimer());
189 assertEquals(TraceEnablement
.DISABLED
, channels
[1].getState());
190 assertEquals(524288, channels
[1].getSubBufferSize());
191 assertEquals(100, channels
[1].getSwitchTimer());
194 IEventInfo
[] channel1Events
= channels
[1].getEvents();
195 assertEquals(0, channel1Events
.length
);
197 // Verify domain UST global
198 assertEquals("UST global", domains
[1].getName());
200 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
202 // Verify UST global's mychannel1
203 assertEquals("mychannel1", ustChannels
[0].getName());
204 assertEquals(8, ustChannels
[0].getNumberOfSubBuffers());
205 assertEquals("mmap()", ustChannels
[0].getOutputType());
206 assertEquals(true, ustChannels
[0].isOverwriteMode());
207 assertEquals(100, ustChannels
[0].getReadTimer());
208 assertEquals(TraceEnablement
.DISABLED
, ustChannels
[0].getState());
209 assertEquals(8192, ustChannels
[0].getSubBufferSize());
210 assertEquals(200, ustChannels
[0].getSwitchTimer());
213 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
214 assertEquals(0, ustEvents
.length
);
216 // Verify UST global's channel0
217 assertEquals("channel0", ustChannels
[1].getName());
218 assertEquals(4, ustChannels
[1].getNumberOfSubBuffers());
219 assertEquals("mmap()", ustChannels
[1].getOutputType());
220 assertEquals(false, ustChannels
[1].isOverwriteMode());
221 assertEquals(200, ustChannels
[1].getReadTimer());
222 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[1].getState());
223 assertEquals(4096, ustChannels
[1].getSubBufferSize());
224 assertEquals(0, ustChannels
[1].getSwitchTimer());
227 ustEvents
= ustChannels
[1].getEvents();
228 assertEquals(2, ustEvents
.length
);
230 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents
[0].getName());
231 assertEquals(TraceLogLevel
.TRACE_DEFAULT
, ustEvents
[0].getLogLevel());
232 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
233 assertEquals(TraceEnablement
.DISABLED
, ustEvents
[0].getState());
235 assertEquals("*", ustEvents
[1].getName());
236 assertEquals(TraceLogLevel
.TRACE_EMERG
, ustEvents
[1].getLogLevel());
237 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[1].getEventType());
238 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[1].getState());
240 // next session (no detailed information available)
241 session
= service
.getSession("mysession1");
242 assertNotNull(session
);
243 assertEquals("mysession1", session
.getName());
244 assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session
.getSessionPath());
245 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
247 domains
= session
.getDomains();
248 assertNotNull(domains
);
249 assertEquals(0, domains
.length
);
250 } catch (ExecutionException e
) {
255 public void testGetKernelProvider() {
257 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
258 List
<IBaseEventInfo
> events
= service
.getKernelProvider();
261 assertNotNull(events
);
262 assertEquals(3, events
.size());
264 IBaseEventInfo baseEventInfo
= (IBaseEventInfo
) events
.get(0);
265 assertNotNull(baseEventInfo
);
266 assertEquals("sched_kthread_stop", baseEventInfo
.getName());
267 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
268 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
270 baseEventInfo
= (IBaseEventInfo
) events
.get(1);
271 assertEquals("sched_kthread_stop_ret", baseEventInfo
.getName());
272 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
273 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
275 baseEventInfo
= (IBaseEventInfo
) events
.get(2);
276 assertEquals("sched_wakeup_new", baseEventInfo
.getName());
277 assertEquals(TraceLogLevel
.TRACE_EMERG
, baseEventInfo
.getLogLevel());
278 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
280 } catch (ExecutionException e
) {
285 public void testGetUstProvider() {
287 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForSessionNames());
288 List
<IUstProviderInfo
> providers
= service
.getUstProvider();
290 // Check all providers
291 assertNotNull(providers
);
292 assertEquals(2, providers
.size());
294 //Verify first provider
295 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(0).getName());
296 assertEquals(9379, providers
.get(0).getPid());
299 IBaseEventInfo
[] events
= providers
.get(0).getEvents();
300 assertNotNull(events
);
301 assertEquals(2, events
.length
);
303 IBaseEventInfo baseEventInfo
= (IBaseEventInfo
) events
[0];
304 assertNotNull(baseEventInfo
);
305 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
306 assertEquals(TraceLogLevel
.TRACE_MODULE
, baseEventInfo
.getLogLevel());
307 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
309 baseEventInfo
= (IBaseEventInfo
) events
[1];
310 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
311 assertEquals(TraceLogLevel
.TRACE_INFO
, baseEventInfo
.getLogLevel());
312 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
314 //Verify second provider
315 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers
.get(1).getName());
316 assertEquals(4852, providers
.get(1).getPid());
319 events
= providers
.get(1).getEvents();
320 assertNotNull(events
);
321 assertEquals(2, events
.length
);
323 baseEventInfo
= (IBaseEventInfo
) events
[0];
324 assertNotNull(baseEventInfo
);
325 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo
.getName());
326 assertEquals(TraceLogLevel
.TRACE_WARNING
, baseEventInfo
.getLogLevel());
327 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
329 baseEventInfo
= (IBaseEventInfo
) events
[1];
330 assertEquals("ust_tests_hello:tptest", baseEventInfo
.getName());
331 assertEquals(TraceLogLevel
.TRACE_FUNCTION
, baseEventInfo
.getLogLevel());
332 assertEquals(TraceEventType
.TRACEPOINT
, baseEventInfo
.getEventType());
334 } catch (ExecutionException e
) {
339 public void testUstProvider2() {
341 ILttngControlService service
= new LTTngControlService(fShellFactory
.getShellForNoUstProvider());
342 List
<IUstProviderInfo
> providers
= service
.getUstProvider();
344 assertNotNull(providers
);
345 assertEquals(0, providers
.size());
347 } catch (ExecutionException e
) {