1 /**********************************************************************
2 * Copyright (c) 2014 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 * Jonathan Rajotte - Support of machine interface
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.service
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
20 import java
.util
.HashSet
;
21 import java
.util
.List
;
24 import org
.eclipse
.core
.commands
.ExecutionException
;
25 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceChannelOutputType
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlService
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceMI
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LttngVersion
;
41 import org
.junit
.Ignore
;
42 import org
.junit
.Test
;
48 @SuppressWarnings("javadoc")
49 public class LTTngControlServiceMiTest
extends LTTngControlServiceTest
{
51 private static final String MI_TEST_STREAM
= "LTTngServiceMiTest.cfg";
53 private static final String SCEN_SESSION_WITH_SYSCALLS
= "GetSessionWithSyscalls";
54 private static final String SCEN_LIST_SESSION_2_7_COMPAT
= "ListSession2.7Compat";
55 private static final String SCEN_GET_SESSION_FILTER_EXPRESSION
= "GetSessionFilterExpression";
56 private static final String SCEN_LIST_CONTEXT_28
= "ListContext28";
59 protected ILttngControlService
getControlService() {
61 return new LTTngControlServiceMI(getShell(), new LttngVersion("2.7.0"));
62 } catch (ExecutionException e
) {
68 public void testGetSessionNameGarbage() {
70 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
71 fService
.getSessionNames(new NullProgressMonitor());
72 } catch (ExecutionException e
) {
73 // Success. Parsing of garbage result in an ExecutionException
74 // generated by the XML document parser: Unable to parse the xml
81 public void testCreateLiveSession() throws ExecutionException
{
82 fShell
.setScenario(SCEN_CREATE_LIVE_SESSION
);
84 ISessionInfo params
= new SessionInfo("mysession");
86 params
.setStreamedTrace(true);
87 params
.setNetworkUrl("net://127.0.0.1");
88 ISessionInfo sessionInfo
= fService
.createSession(params
, new NullProgressMonitor());
89 assertNotNull(sessionInfo
);
90 assertEquals("mysession", sessionInfo
.getName());
91 assertEquals(TraceSessionState
.INACTIVE
, sessionInfo
.getSessionState());
92 assertTrue(sessionInfo
.isStreamedTrace());
93 assertTrue(sessionInfo
.isLive());
94 assertEquals("tcp4://127.0.0.1:5342/ [data: 5343]", sessionInfo
.getSessionPath());
95 List
<String
> names
= fService
.getSessionNames(new NullProgressMonitor());
96 assertEquals(names
.get(0), "mysession");
97 fService
.destroySession("mysession", new NullProgressMonitor());
101 protected String
getTestStream() {
102 return MI_TEST_STREAM
;
106 protected TraceLogLevel
getAllEventTraceLogLevel() {
107 return TraceLogLevel
.TRACE_DEBUG
;
111 public void testGetKernelProviderNoUstVerbose() {
112 // Verbose mode in machine interface is deactivated. This test is
117 public void testCreateSession2_1() {
118 // 2.1 is not supported by mi. This test is ignored.
122 public void testGetKernelProviderNoUst3() {
123 // Verbose mode in machine interface is deactivated. This test is
128 public void testGetKernelProviderNoKernelVerbose() {
129 // Verbose mode in machine interface is deactivated. This test is
134 public void testCreateSessionVerbose2_1() {
135 // Verbose mode in machine interface is deactivated. This test is
140 public void testDestroySessionVerbose() {
141 // Verbose mode in machine interface is deactivated. This test is
146 public void testCreateSessionWithPrompt() {
147 // TODO Investigate if this case can happen in production. If yes than
148 // we need to rethinks the MI fetching and parsing.
152 public void testAddContext() {
153 // TODO This does not use mi feature.And currently the context enabling
158 public void testAddContextFailure() {
159 // TODO This does not use mi feature.And currently the context enabling
164 public void testListContext28() throws ExecutionException
{
165 ((LTTngControlService
)fService
).setVersion("2.8.0");
166 fShell
.setScenario(SCEN_LIST_CONTEXT_28
);
168 List
<String
> availContexts
= fService
.getContextList(new NullProgressMonitor());
169 assertNotNull(availContexts
);
170 assertEquals(12, availContexts
.size());
172 Set
<String
> expectedContexts
= new HashSet
<>();
173 expectedContexts
.add("pid");
174 expectedContexts
.add("procname");
175 expectedContexts
.add("prio");
176 expectedContexts
.add("nice");
177 expectedContexts
.add("vpid");
178 expectedContexts
.add("tid");
179 expectedContexts
.add("pthread_id");
180 expectedContexts
.add("vtid");
181 expectedContexts
.add("ppid");
182 expectedContexts
.add("vppid");
183 expectedContexts
.add("perf:cpu:cpu-cycles");
184 expectedContexts
.add("perf:cpu:cycles");
186 assertTrue(expectedContexts
.containsAll(availContexts
));
190 public void testCreateSnapshotSession2_5() {
191 // not applicable for MI
195 * Tests the listing of syscalls
198 public void testListSycallEvents() {
200 fShell
.setScenario(SCEN_SESSION_WITH_SYSCALLS
);
201 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
204 assertNotNull(session
);
205 assertEquals("mysession", session
.getName());
206 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
207 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
209 IDomainInfo
[] domains
= session
.getDomains();
210 assertNotNull(domains
);
211 assertEquals(1, domains
.length
);
213 // Verify Kernel domain
214 assertEquals("Kernel", domains
[0].getName());
215 IChannelInfo
[] channels
= domains
[0].getChannels();
216 assertNotNull(channels
);
217 assertEquals(1, channels
.length
);
219 // Verify Kernel's channel0
220 assertEquals("channel0", channels
[0].getName());
221 assertEquals(4, channels
[0].getNumberOfSubBuffers());
222 assertEquals("splice()", channels
[0].getOutputType().getInName());
223 assertEquals(TraceChannelOutputType
.SPLICE
, channels
[0].getOutputType());
224 assertEquals(false, channels
[0].isOverwriteMode());
225 assertEquals(200, channels
[0].getReadTimer());
226 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
227 assertEquals(262144, channels
[0].getSubBufferSize());
228 assertEquals(0, channels
[0].getSwitchTimer());
231 IEventInfo
[] channel0Events
= channels
[0].getEvents();
232 assertNotNull(channel0Events
);
233 assertEquals(2, channel0Events
.length
);
234 assertEquals("read", channel0Events
[0].getName());
235 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[0].getEventType());
236 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
238 assertEquals("write", channel0Events
[1].getName());
239 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[1].getEventType());
240 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[1].getState());
241 } catch (ExecutionException e
) {
247 * Test List session for lttng 2.7.
249 * This is to make sure that it is possible to parse the output of a session
250 * create on a target with LTTng 2.7 installed.
255 public void testListSessionCompatibility_2_7() {
258 Note the session was created with basic commands:
259 lttng create mysession
260 lttng enable-event -a -k -s mysession
261 lttng enable-channel channel0 -u -s mysession --buffers-pid
262 lttng enable-event -a -u -s mysession -c channel0 --tracepoint
263 lttng add-context -u -t vtid -t procname
267 fShell
.setScenario(SCEN_LIST_SESSION_2_7_COMPAT
);
268 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
271 assertNotNull(session
);
272 assertEquals("mysession", session
.getName());
273 assertEquals("/home/user/lttng-traces/mysession-20151020-085614", session
.getSessionPath());
274 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
276 IDomainInfo
[] domains
= session
.getDomains();
277 assertNotNull(domains
);
278 assertEquals(2, domains
.length
);
280 // Verify Kernel domain
281 assertEquals("Kernel", domains
[0].getName());
282 IChannelInfo
[] channels
= domains
[0].getChannels();
283 assertNotNull(channels
);
284 assertEquals(1, channels
.length
);
286 // Verify Kernel's channel0
287 assertEquals("channel0", channels
[0].getName());
288 assertEquals(4, channels
[0].getNumberOfSubBuffers());
289 assertEquals("splice()", channels
[0].getOutputType().getInName());
290 assertEquals(TraceChannelOutputType
.SPLICE
, channels
[0].getOutputType());
291 assertEquals(false, channels
[0].isOverwriteMode());
292 assertEquals(200000, channels
[0].getReadTimer());
293 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
294 assertEquals(262144, channels
[0].getSubBufferSize());
295 assertEquals(0, channels
[0].getSwitchTimer());
298 IEventInfo
[] channel0Events
= channels
[0].getEvents();
299 assertNotNull(channel0Events
);
300 assertEquals(2, channel0Events
.length
);
301 assertEquals("*", channel0Events
[0].getName());
302 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[0].getEventType());
303 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
305 assertEquals("*", channel0Events
[1].getName());
306 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
307 assertEquals(LogLevelType
.LOGLEVEL_ALL
, channel0Events
[1].getLogLevelType());
308 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
309 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[1].getState());
311 // Verify domain UST global
312 assertEquals("UST global", domains
[1].getName());
314 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
316 // Verify UST global's channel0
317 assertEquals("channel0", ustChannels
[0].getName());
318 assertEquals(4, ustChannels
[0].getNumberOfSubBuffers());
319 assertEquals("mmap()", ustChannels
[0].getOutputType().getInName());
320 assertEquals(TraceChannelOutputType
.MMAP
, ustChannels
[0].getOutputType());
321 assertEquals(false, ustChannels
[0].isOverwriteMode());
322 assertEquals(0, ustChannels
[0].getReadTimer());
323 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[0].getState());
324 assertEquals(4096, ustChannels
[0].getSubBufferSize());
325 assertEquals(0, ustChannels
[0].getSwitchTimer());
328 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
329 assertEquals(1, ustEvents
.length
);
331 assertEquals("*", ustEvents
[0].getName());
332 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
333 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[0].getState());
335 } catch (ExecutionException e
) {
341 public void testGetSessionWithFilterExpression() throws ExecutionException
{
342 // FIXME: Disable scheme validation for now until MI 3.0 is integrated
343 LTTngControlServiceMI service
= new LTTngControlServiceMI(getShell(), null);
345 fShell
.setScenario(SCEN_GET_SESSION_FILTER_EXPRESSION
);
346 ISessionInfo session
= service
.getSession("mysession", new NullProgressMonitor());
349 assertNotNull(session
);
350 assertEquals("mysession", session
.getName());
351 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
352 assertEquals(TraceSessionState
.ACTIVE
, session
.getSessionState());
354 IDomainInfo
[] domains
= session
.getDomains();
355 assertNotNull(domains
);
356 assertEquals(2, domains
.length
);
358 // Verify Kernel domain
359 assertEquals("Kernel", domains
[0].getName());
360 IChannelInfo
[] channels
= domains
[0].getChannels();
361 assertNotNull(channels
);
362 assertEquals(1, channels
.length
);
364 // Verify Kernel's channel0
365 assertEquals("channel0", channels
[0].getName());
366 assertEquals(4, channels
[0].getNumberOfSubBuffers());
367 assertEquals("splice()", channels
[0].getOutputType().getInName());
368 assertEquals(TraceChannelOutputType
.SPLICE
, channels
[0].getOutputType());
369 assertEquals(false, channels
[0].isOverwriteMode());
370 assertEquals(200, channels
[0].getReadTimer());
371 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
372 assertEquals(262144, channels
[0].getSubBufferSize());
373 assertEquals(0, channels
[0].getSwitchTimer());
376 IEventInfo
[] channel0Events
= channels
[0].getEvents();
377 assertNotNull(channel0Events
);
378 assertEquals(1, channel0Events
.length
);
379 assertEquals("block_rq_remap", channel0Events
[0].getName());
380 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[0].getLogLevel());
381 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[0].getEventType());
382 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
383 assertEquals("foo > 10", channel0Events
[0].getFilterExpression());
385 // Verify domain UST global
386 assertEquals("UST global", domains
[1].getName());
388 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
390 // Verify UST global's channel0
391 assertEquals("channel0", ustChannels
[0].getName());
392 assertEquals(4, ustChannels
[0].getNumberOfSubBuffers());
393 assertEquals("mmap()", ustChannels
[0].getOutputType().getInName());
394 assertEquals(TraceChannelOutputType
.MMAP
, ustChannels
[0].getOutputType());
395 assertEquals(false, ustChannels
[0].isOverwriteMode());
396 assertEquals(200, ustChannels
[0].getReadTimer());
397 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[0].getState());
398 assertEquals(4096, ustChannels
[0].getSubBufferSize());
399 assertEquals(0, ustChannels
[0].getSwitchTimer());
402 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
403 assertEquals(1, ustEvents
.length
);
405 assertEquals("ust_tests_hello:tptest_sighandler", ustEvents
[0].getName());
406 assertEquals(TraceLogLevel
.TRACE_DEBUG_LINE
, ustEvents
[0].getLogLevel());
407 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
408 assertEquals(TraceEnablement
.DISABLED
, ustEvents
[0].getState());
409 assertEquals("foo > 10", ustEvents
[0].getFilterExpression());