Merge branch 'master' into lttng_2_0_control_dev
[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.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;
32 /**
33 * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>.
34 */
35 @SuppressWarnings("nls")
36 public class LTTngControlServiceTest extends TestCase {
37 // ------------------------------------------------------------------------
38 // Test data
39 // ------------------------------------------------------------------------
40 private CommandShellFactory fShellFactory;
41
42 // ------------------------------------------------------------------------
43 // Static methods
44 // ------------------------------------------------------------------------
45
46 // ------------------------------------------------------------------------
47 // Housekeeping
48 // ------------------------------------------------------------------------
49 /**
50 * Perform pre-test initialization.
51 *
52 * @throws Exception if the initialization fails for some reason
53 *
54 */
55 @Override
56 public void setUp() throws Exception {
57 super.setUp();
58 fShellFactory = CommandShellFactory.getInstance();
59 }
60
61 /**
62 * Perform post-test clean-up.
63 *
64 * @throws Exception if the clean-up fails for some reason
65 *
66 */
67 @Override
68 public void tearDown() throws Exception {
69 }
70
71 // ------------------------------------------------------------------------
72 // Test Cases
73 // ------------------------------------------------------------------------
74
75 public void testGetSessionNames() {
76 try {
77 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForLttngNotExistsShell());
78 service.getSessionNames();
79 fail("No exeption thrown");
80
81 } catch (ExecutionException e) {
82 // success
83 }
84 }
85
86 public void testGetSessionNames1() {
87 try {
88 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoSessionNames());
89 String[] result = service.getSessionNames();
90
91 assertNotNull(result);
92 assertEquals(0, result.length);
93
94 } catch (ExecutionException e) {
95 fail(e.toString());
96 }
97 }
98
99 public void testGetSessionNames2() {
100 try {
101 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
102 String[] result = service.getSessionNames();
103
104 assertNotNull(result);
105 assertEquals(2, result.length);
106 assertEquals("mysession1", result[0]);
107 assertEquals("mysession", result[1]);
108
109 } catch (ExecutionException e) {
110 fail(e.toString());
111 }
112 }
113
114 public void testGetSessionNotExist() {
115 try {
116 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNotExists());
117 service.getSessionNames();
118 fail("No exeption thrown");
119
120 } catch (ExecutionException e) {
121 // success
122 }
123 }
124
125 public void testGetSessionNameGarbage() {
126 try {
127 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionGarbage());
128 String[] result = service.getSessionNames();
129
130 assertNotNull(result);
131 assertEquals(0, result.length);
132
133 } catch (ExecutionException e) {
134 fail(e.toString());
135 }
136 }
137
138 public void testGetSession1() {
139 try {
140 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
141 ISessionInfo session = service.getSession("mysession");
142
143 // Verify Session
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());
148
149 IDomainInfo[] domains = session.getDomains();
150 assertNotNull(domains);
151 assertEquals(2, domains.length);
152
153 // Verify Kernel domain
154 assertEquals("Kernel", domains[0].getName());
155 IChannelInfo[] channels = domains[0].getChannels();
156 assertNotNull(channels);
157 assertEquals(2, channels.length);
158
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());
168
169 // Verify event info
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());
177
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());
182
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());
192
193 // Verify event info
194 IEventInfo[] channel1Events = channels[1].getEvents();
195 assertEquals(0, channel1Events.length);
196
197 // Verify domain UST global
198 assertEquals("UST global", domains[1].getName());
199
200 IChannelInfo[] ustChannels = domains[1].getChannels();
201
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());
211
212 // Verify event info
213 IEventInfo[] ustEvents = ustChannels[0].getEvents();
214 assertEquals(0, ustEvents.length);
215
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());
225
226 // Verify event info
227 ustEvents = ustChannels[1].getEvents();
228 assertEquals(2, ustEvents.length);
229
230 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName());
231 assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel());
232 assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType());
233 assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState());
234
235 assertEquals("*", ustEvents[1].getName());
236 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, ustEvents[1].getLogLevel());
237 assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType());
238 assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState());
239
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());
246
247 domains = session.getDomains();
248 assertNotNull(domains);
249 assertEquals(0, domains.length);
250 } catch (ExecutionException e) {
251 fail(e.toString());
252 }
253 }
254
255 public void testGetKernelProvider() {
256 try {
257 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
258 List<IBaseEventInfo> events = service.getKernelProvider();
259
260 // Verify event info
261 assertNotNull(events);
262 assertEquals(3, events.size());
263
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());
269
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());
274
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());
279
280 } catch (ExecutionException e) {
281 fail(e.toString());
282 }
283 }
284
285 public void testGetUstProvider() {
286 try {
287 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames());
288 List<IUstProviderInfo> providers = service.getUstProvider();
289
290 // Check all providers
291 assertNotNull(providers);
292 assertEquals(2, providers.size());
293
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());
297
298 // Verify event info
299 IBaseEventInfo[] events = providers.get(0).getEvents();
300 assertNotNull(events);
301 assertEquals(2, events.length);
302
303 IBaseEventInfo baseEventInfo = (IBaseEventInfo) events[0];
304 assertNotNull(baseEventInfo);
305 assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName());
306 assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel());
307 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
308
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());
313
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());
317
318 // Verify event info
319 events = providers.get(1).getEvents();
320 assertNotNull(events);
321 assertEquals(2, events.length);
322
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());
328
329 baseEventInfo = (IBaseEventInfo) events[1];
330 assertEquals("ust_tests_hello:tptest", baseEventInfo.getName());
331 assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel());
332 assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType());
333
334 } catch (ExecutionException e) {
335 fail(e.toString());
336 }
337 }
338
339 public void testUstProvider2() {
340 try {
341 ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoUstProvider());
342 List<IUstProviderInfo> providers = service.getUstProvider();
343
344 assertNotNull(providers);
345 assertEquals(0, providers.size());
346
347 } catch (ExecutionException e) {
348 fail(e.toString());
349 }
350 }
351
352 }
This page took 0.038721 seconds and 6 git commands to generate.