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
;
21 import java
.util
.List
;
23 import org
.eclipse
.core
.commands
.ExecutionException
;
24 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IDomainInfo
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IEventInfo
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.ISessionInfo
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceChannelOutputType
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.impl
.SessionInfo
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceConstants
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceMI
;
39 import org
.junit
.Ignore
;
40 import org
.junit
.Test
;
46 public class LTTngControlServiceMiTest
extends LTTngControlServiceTest
{
48 private static final String MI_TEST_STREAM
= "LTTngServiceMiTest.cfg";
50 private static final String SCEN_SESSION_WITH_SYSCALLS
= "GetSessionWithSyscalls";
51 private static final String SCEN_LIST_SESSION_2_7_COMPAT
= "ListSession2.7Compat";
54 protected ILttngControlService
getControlService() {
56 URL resource
= LTTngControlServiceMI
.class.getResource(LTTngControlServiceConstants
.MI_XSD_FILENAME
);
57 return new LTTngControlServiceMI(getShell(), resource
);
58 } catch (ExecutionException e
) {
64 public void testGetSessionNameGarbage() {
66 fShell
.setScenario(SCEN_GET_SESSION_GARBAGE_OUT
);
67 fService
.getSessionNames(new NullProgressMonitor());
68 } catch (ExecutionException e
) {
69 // Success. Parsing of garbage result in an ExecutionException
70 // generated by the XML document parser: Unable to parse the xml
77 public void testCreateLiveSession() throws ExecutionException
{
78 fShell
.setScenario(SCEN_CREATE_LIVE_SESSION
);
80 ISessionInfo params
= new SessionInfo("mysession");
82 params
.setStreamedTrace(true);
83 params
.setNetworkUrl("net://127.0.0.1");
84 ISessionInfo sessionInfo
= fService
.createSession(params
, new NullProgressMonitor());
85 assertNotNull(sessionInfo
);
86 assertEquals("mysession", sessionInfo
.getName());
87 assertEquals(TraceSessionState
.INACTIVE
, sessionInfo
.getSessionState());
88 assertTrue(sessionInfo
.isStreamedTrace());
89 assertTrue(sessionInfo
.isLive());
90 assertEquals("tcp4://127.0.0.1:5342/ [data: 5343]", sessionInfo
.getSessionPath());
91 List
<String
> names
= fService
.getSessionNames(new NullProgressMonitor());
92 assertEquals(names
.get(0), "mysession");
93 fService
.destroySession("mysession", new NullProgressMonitor());
97 protected String
getTestStream() {
98 return MI_TEST_STREAM
;
102 protected TraceLogLevel
getAllEventTraceLogLevel() {
103 return TraceLogLevel
.TRACE_DEBUG
;
107 public void testGetKernelProviderNoUstVerbose() {
108 // Verbose mode in machine interface is deactivated. This test is
113 public void testCreateSession2_1() {
114 // 2.1 is not supported by mi. This test is ignored.
118 public void testGetKernelProviderNoUst3() {
119 // Verbose mode in machine interface is deactivated. This test is
124 public void testGetKernelProviderNoKernelVerbose() {
125 // Verbose mode in machine interface is deactivated. This test is
130 public void testCreateSessionVerbose2_1() {
131 // Verbose mode in machine interface is deactivated. This test is
136 public void testDestroySessionVerbose() {
137 // Verbose mode in machine interface is deactivated. This test is
142 public void testCreateSessionWithPrompt() {
143 // TODO Investigate if this case can happen in production. If yes than
144 // we need to rethinks the MI fetching and parsing.
148 public void testAddContext() {
149 // TODO This does not use mi feature.And currently the context enabling
154 public void testAddContextFailure() {
155 // TODO This does not use mi feature.And currently the context enabling
160 public void testCreateSnapshotSession2_5() {
161 // not applicable for MI
165 * Tests the listing of syscalls
168 public void testListSycallEvents() {
170 fShell
.setScenario(SCEN_SESSION_WITH_SYSCALLS
);
171 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
174 assertNotNull(session
);
175 assertEquals("mysession", session
.getName());
176 assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session
.getSessionPath());
177 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
179 IDomainInfo
[] domains
= session
.getDomains();
180 assertNotNull(domains
);
181 assertEquals(1, domains
.length
);
183 // Verify Kernel domain
184 assertEquals("Kernel", domains
[0].getName());
185 IChannelInfo
[] channels
= domains
[0].getChannels();
186 assertNotNull(channels
);
187 assertEquals(1, channels
.length
);
189 // Verify Kernel's channel0
190 assertEquals("channel0", channels
[0].getName());
191 assertEquals(4, channels
[0].getNumberOfSubBuffers());
192 assertEquals("splice()", channels
[0].getOutputType().getInName());
193 assertEquals(TraceChannelOutputType
.SPLICE
, channels
[0].getOutputType());
194 assertEquals(false, channels
[0].isOverwriteMode());
195 assertEquals(200, channels
[0].getReadTimer());
196 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
197 assertEquals(262144, channels
[0].getSubBufferSize());
198 assertEquals(0, channels
[0].getSwitchTimer());
201 IEventInfo
[] channel0Events
= channels
[0].getEvents();
202 assertNotNull(channel0Events
);
203 assertEquals(2, channel0Events
.length
);
204 assertEquals("read", channel0Events
[0].getName());
205 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[0].getEventType());
206 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
208 assertEquals("write", channel0Events
[1].getName());
209 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[1].getEventType());
210 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[1].getState());
211 } catch (ExecutionException e
) {
217 * Test List session for lttng 2.7.
219 * This is to make sure that it is possible to parse the output of a session
220 * create on a target with LTTng 2.7 installed.
225 public void testListSessionCompatibility_2_7() {
228 Note the session was created with basic commands:
229 lttng create mysession
230 lttng enable-event -a -k -s mysession
231 lttng enable-channel channel0 -u -s mysession --buffers-pid
232 lttng enable-event -a -u -s mysession -c channel0 --tracepoint
233 lttng add-context -u -t vtid -t procname
237 fShell
.setScenario(SCEN_LIST_SESSION_2_7_COMPAT
);
238 ISessionInfo session
= fService
.getSession("mysession", new NullProgressMonitor());
241 assertNotNull(session
);
242 assertEquals("mysession", session
.getName());
243 assertEquals("/home/user/lttng-traces/mysession-20151020-085614", session
.getSessionPath());
244 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
246 IDomainInfo
[] domains
= session
.getDomains();
247 assertNotNull(domains
);
248 assertEquals(2, domains
.length
);
250 // Verify Kernel domain
251 assertEquals("Kernel", domains
[0].getName());
252 IChannelInfo
[] channels
= domains
[0].getChannels();
253 assertNotNull(channels
);
254 assertEquals(1, channels
.length
);
256 // Verify Kernel's channel0
257 assertEquals("channel0", channels
[0].getName());
258 assertEquals(4, channels
[0].getNumberOfSubBuffers());
259 assertEquals("splice()", channels
[0].getOutputType().getInName());
260 assertEquals(TraceChannelOutputType
.SPLICE
, channels
[0].getOutputType());
261 assertEquals(false, channels
[0].isOverwriteMode());
262 assertEquals(200000, channels
[0].getReadTimer());
263 assertEquals(TraceEnablement
.ENABLED
, channels
[0].getState());
264 assertEquals(262144, channels
[0].getSubBufferSize());
265 assertEquals(0, channels
[0].getSwitchTimer());
268 IEventInfo
[] channel0Events
= channels
[0].getEvents();
269 assertNotNull(channel0Events
);
270 assertEquals(2, channel0Events
.length
);
271 assertEquals("*", channel0Events
[0].getName());
272 assertEquals(TraceEventType
.SYSCALL
, channel0Events
[0].getEventType());
273 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[0].getState());
275 assertEquals("*", channel0Events
[1].getName());
276 assertEquals(TraceLogLevel
.TRACE_EMERG
, channel0Events
[1].getLogLevel());
277 assertEquals(LogLevelType
.LOGLEVEL_ALL
, channel0Events
[1].getLogLevelType());
278 assertEquals(TraceEventType
.TRACEPOINT
, channel0Events
[1].getEventType());
279 assertEquals(TraceEnablement
.ENABLED
, channel0Events
[1].getState());
281 // Verify domain UST global
282 assertEquals("UST global", domains
[1].getName());
284 IChannelInfo
[] ustChannels
= domains
[1].getChannels();
286 // Verify UST global's channel0
287 assertEquals("channel0", ustChannels
[0].getName());
288 assertEquals(4, ustChannels
[0].getNumberOfSubBuffers());
289 assertEquals("mmap()", ustChannels
[0].getOutputType().getInName());
290 assertEquals(TraceChannelOutputType
.MMAP
, ustChannels
[0].getOutputType());
291 assertEquals(false, ustChannels
[0].isOverwriteMode());
292 assertEquals(0, ustChannels
[0].getReadTimer());
293 assertEquals(TraceEnablement
.ENABLED
, ustChannels
[0].getState());
294 assertEquals(4096, ustChannels
[0].getSubBufferSize());
295 assertEquals(0, ustChannels
[0].getSwitchTimer());
298 IEventInfo
[] ustEvents
= ustChannels
[0].getEvents();
299 assertEquals(1, ustEvents
.length
);
301 assertEquals("*", ustEvents
[0].getName());
302 assertEquals(TraceEventType
.TRACEPOINT
, ustEvents
[0].getEventType());
303 assertEquals(TraceEnablement
.ENABLED
, ustEvents
[0].getState());
305 } catch (ExecutionException e
) {