Commit | Line | Data |
---|---|---|
e5e5b3db JRJ |
1 | /********************************************************************** |
2 | * Copyright (c) 2014 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 | * Jonathan Rajotte - Support of machine interface | |
11 | **********************************************************************/ | |
12 | ||
9bc60be7 | 13 | package org.eclipse.tracecompass.lttng2.control.ui.tests.service; |
e5e5b3db JRJ |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.assertTrue; | |
7e3d8120 | 18 | import static org.junit.Assert.fail; |
e5e5b3db | 19 | |
182e9b8f | 20 | import java.util.HashSet; |
cbc46cc9 | 21 | import java.util.List; |
182e9b8f | 22 | import java.util.Set; |
e5e5b3db JRJ |
23 | |
24 | import org.eclipse.core.commands.ExecutionException; | |
25 | import org.eclipse.core.runtime.NullProgressMonitor; | |
7e3d8120 BH |
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; | |
9bc60be7 | 29 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISessionInfo; |
43412c29 | 30 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType; |
7e3d8120 BH |
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; | |
9bc60be7 AM |
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; | |
182e9b8f | 38 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlService; |
9bc60be7 | 39 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceMI; |
ce709731 | 40 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LttngVersion; |
ee8d0c40 | 41 | import org.junit.Ignore; |
7e3d8120 | 42 | import org.junit.Test; |
e5e5b3db JRJ |
43 | |
44 | /** | |
45 | * @author ejorajo | |
46 | * | |
47 | */ | |
182e9b8f | 48 | @SuppressWarnings("javadoc") |
e5e5b3db JRJ |
49 | public class LTTngControlServiceMiTest extends LTTngControlServiceTest { |
50 | ||
51 | private static final String MI_TEST_STREAM = "LTTngServiceMiTest.cfg"; | |
52 | ||
7e3d8120 | 53 | private static final String SCEN_SESSION_WITH_SYSCALLS = "GetSessionWithSyscalls"; |
43412c29 | 54 | private static final String SCEN_LIST_SESSION_2_7_COMPAT = "ListSession2.7Compat"; |
adecf0a7 | 55 | private static final String SCEN_GET_SESSION_FILTER_EXPRESSION = "GetSessionFilterExpression"; |
182e9b8f | 56 | private static final String SCEN_LIST_CONTEXT_28 = "ListContext28"; |
7e3d8120 | 57 | |
e5e5b3db JRJ |
58 | @Override |
59 | protected ILttngControlService getControlService() { | |
60 | try { | |
ce709731 | 61 | return new LTTngControlServiceMI(getShell(), new LttngVersion("2.7.0")); |
e5e5b3db JRJ |
62 | } catch (ExecutionException e) { |
63 | return null; | |
64 | } | |
65 | } | |
66 | ||
67 | @Override | |
68 | public void testGetSessionNameGarbage() { | |
69 | try { | |
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 | |
75 | // document. | |
76 | } | |
77 | } | |
78 | ||
79 | @Override | |
ee8d0c40 | 80 | @Ignore |
e5e5b3db JRJ |
81 | public void testCreateLiveSession() throws ExecutionException { |
82 | fShell.setScenario(SCEN_CREATE_LIVE_SESSION); | |
83 | ||
84 | ISessionInfo params = new SessionInfo("mysession"); | |
85 | params.setLive(true); | |
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()); | |
cbc46cc9 BH |
95 | List<String> names = fService.getSessionNames(new NullProgressMonitor()); |
96 | assertEquals(names.get(0), "mysession"); | |
e5e5b3db JRJ |
97 | fService.destroySession("mysession", new NullProgressMonitor()); |
98 | } | |
99 | ||
100 | @Override | |
101 | protected String getTestStream() { | |
102 | return MI_TEST_STREAM; | |
103 | } | |
104 | ||
105 | @Override | |
106 | protected TraceLogLevel getAllEventTraceLogLevel() { | |
107 | return TraceLogLevel.TRACE_DEBUG; | |
108 | } | |
109 | ||
110 | @Override | |
111 | public void testGetKernelProviderNoUstVerbose() { | |
112 | // Verbose mode in machine interface is deactivated. This test is | |
113 | // ignored. | |
114 | } | |
115 | ||
116 | @Override | |
117 | public void testCreateSession2_1() { | |
118 | // 2.1 is not supported by mi. This test is ignored. | |
119 | } | |
120 | ||
121 | @Override | |
122 | public void testGetKernelProviderNoUst3() { | |
123 | // Verbose mode in machine interface is deactivated. This test is | |
124 | // ignored. | |
125 | } | |
126 | ||
127 | @Override | |
128 | public void testGetKernelProviderNoKernelVerbose() { | |
129 | // Verbose mode in machine interface is deactivated. This test is | |
130 | // ignored. | |
131 | } | |
132 | ||
133 | @Override | |
134 | public void testCreateSessionVerbose2_1() { | |
135 | // Verbose mode in machine interface is deactivated. This test is | |
136 | // ignored. | |
137 | } | |
138 | ||
139 | @Override | |
140 | public void testDestroySessionVerbose() { | |
141 | // Verbose mode in machine interface is deactivated. This test is | |
142 | // ignored. | |
143 | } | |
144 | ||
145 | @Override | |
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. | |
149 | } | |
150 | ||
151 | @Override | |
152 | public void testAddContext() { | |
153 | // TODO This does not use mi feature.And currently the context enabling | |
154 | // is wrong for 2.6. | |
155 | } | |
156 | ||
157 | @Override | |
158 | public void testAddContextFailure() { | |
159 | // TODO This does not use mi feature.And currently the context enabling | |
160 | // is wrong for 2.6. | |
161 | } | |
ad311f36 | 162 | |
182e9b8f MAL |
163 | @Test |
164 | public void testListContext28() throws ExecutionException { | |
165 | ((LTTngControlService)fService).setVersion("2.8.0"); | |
166 | fShell.setScenario(SCEN_LIST_CONTEXT_28); | |
167 | ||
168 | List<String> availContexts = fService.getContextList(new NullProgressMonitor()); | |
169 | assertNotNull(availContexts); | |
170 | assertEquals(12, availContexts.size()); | |
171 | ||
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"); | |
185 | ||
186 | assertTrue(expectedContexts.containsAll(availContexts)); | |
187 | } | |
188 | ||
ad311f36 BH |
189 | @Override |
190 | public void testCreateSnapshotSession2_5() { | |
191 | // not applicable for MI | |
192 | } | |
7e3d8120 BH |
193 | |
194 | /** | |
195 | * Tests the listing of syscalls | |
196 | */ | |
197 | @Test | |
198 | public void testListSycallEvents() { | |
199 | try { | |
200 | fShell.setScenario(SCEN_SESSION_WITH_SYSCALLS); | |
201 | ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor()); | |
202 | ||
203 | // Verify Session | |
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()); | |
208 | ||
209 | IDomainInfo[] domains = session.getDomains(); | |
210 | assertNotNull(domains); | |
211 | assertEquals(1, domains.length); | |
212 | ||
213 | // Verify Kernel domain | |
214 | assertEquals("Kernel", domains[0].getName()); | |
215 | IChannelInfo[] channels = domains[0].getChannels(); | |
216 | assertNotNull(channels); | |
217 | assertEquals(1, channels.length); | |
218 | ||
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()); | |
229 | ||
230 | // Verify event info | |
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()); | |
237 | ||
238 | assertEquals("write", channel0Events[1].getName()); | |
239 | assertEquals(TraceEventType.SYSCALL, channel0Events[1].getEventType()); | |
240 | assertEquals(TraceEnablement.ENABLED, channel0Events[1].getState()); | |
241 | } catch (ExecutionException e) { | |
242 | fail(e.toString()); | |
243 | } | |
244 | } | |
43412c29 BH |
245 | |
246 | /** | |
247 | * Test List session for lttng 2.7. | |
248 | * | |
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. | |
251 | * | |
252 | * | |
253 | */ | |
254 | @Test | |
255 | public void testListSessionCompatibility_2_7() { | |
256 | ||
257 | /* | |
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 | |
264 | */ | |
265 | ||
266 | try { | |
267 | fShell.setScenario(SCEN_LIST_SESSION_2_7_COMPAT); | |
268 | ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor()); | |
269 | ||
270 | // Verify Session | |
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()); | |
275 | ||
276 | IDomainInfo[] domains = session.getDomains(); | |
277 | assertNotNull(domains); | |
278 | assertEquals(2, domains.length); | |
279 | ||
280 | // Verify Kernel domain | |
281 | assertEquals("Kernel", domains[0].getName()); | |
282 | IChannelInfo[] channels = domains[0].getChannels(); | |
283 | assertNotNull(channels); | |
284 | assertEquals(1, channels.length); | |
285 | ||
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()); | |
296 | ||
297 | // Verify event info | |
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()); | |
304 | ||
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()); | |
310 | ||
311 | // Verify domain UST global | |
312 | assertEquals("UST global", domains[1].getName()); | |
313 | ||
314 | IChannelInfo[] ustChannels = domains[1].getChannels(); | |
315 | ||
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()); | |
326 | ||
327 | // Verify event info | |
328 | IEventInfo[] ustEvents = ustChannels[0].getEvents(); | |
329 | assertEquals(1, ustEvents.length); | |
330 | ||
331 | assertEquals("*", ustEvents[0].getName()); | |
332 | assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType()); | |
333 | assertEquals(TraceEnablement.ENABLED, ustEvents[0].getState()); | |
334 | ||
335 | } catch (ExecutionException e) { | |
336 | fail(e.toString()); | |
337 | } | |
338 | } | |
adecf0a7 MAL |
339 | |
340 | @Test | |
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); | |
344 | ||
345 | fShell.setScenario(SCEN_GET_SESSION_FILTER_EXPRESSION); | |
346 | ISessionInfo session = service.getSession("mysession", new NullProgressMonitor()); | |
347 | ||
348 | // Verify Session | |
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()); | |
353 | ||
354 | IDomainInfo[] domains = session.getDomains(); | |
355 | assertNotNull(domains); | |
356 | assertEquals(2, domains.length); | |
357 | ||
358 | // Verify Kernel domain | |
359 | assertEquals("Kernel", domains[0].getName()); | |
360 | IChannelInfo[] channels = domains[0].getChannels(); | |
361 | assertNotNull(channels); | |
362 | assertEquals(1, channels.length); | |
363 | ||
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()); | |
374 | ||
375 | // Verify event info | |
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()); | |
384 | ||
385 | // Verify domain UST global | |
386 | assertEquals("UST global", domains[1].getName()); | |
387 | ||
388 | IChannelInfo[] ustChannels = domains[1].getChannels(); | |
389 | ||
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()); | |
400 | ||
401 | // Verify event info | |
402 | IEventInfo[] ustEvents = ustChannels[0].getEvents(); | |
403 | assertEquals(1, ustEvents.length); | |
404 | ||
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()); | |
410 | } | |
e5e5b3db | 411 | } |