Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
cfdb727a | 3 | * |
eb1bab5b BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.lttng2.ui.tests.control.service; |
eb1bab5b | 13 | |
d132bcc7 BH |
14 | import java.io.File; |
15 | import java.net.URL; | |
16 | import java.util.ArrayList; | |
4ea599a5 | 17 | import java.util.HashSet; |
eb1bab5b | 18 | import java.util.List; |
4ea599a5 | 19 | import java.util.Set; |
eb1bab5b BH |
20 | |
21 | import junit.framework.TestCase; | |
22 | ||
23 | import org.eclipse.core.commands.ExecutionException; | |
d132bcc7 | 24 | import org.eclipse.core.runtime.FileLocator; |
bbb3538a | 25 | import org.eclipse.core.runtime.NullProgressMonitor; |
d132bcc7 | 26 | import org.eclipse.core.runtime.Path; |
9315aeee BH |
27 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo; |
28 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; | |
29 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo; | |
30 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; | |
31 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; | |
32 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IUstProviderInfo; | |
33 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType; | |
34 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
35 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
36 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
37 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
38 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo; | |
115b4a01 BH |
39 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory; |
40 | import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell; | |
115b4a01 BH |
41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService; |
42 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService; | |
276c17e7 | 43 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory; |
9269df72 | 44 | import org.osgi.framework.FrameworkUtil; |
eb1bab5b BH |
45 | /** |
46 | * The class <code>LTTngControlServiceTest</code> contains test for the class <code>{@link LTTngControlService}</code>. | |
47 | */ | |
cfdb727a | 48 | @SuppressWarnings({"nls", "javadoc"}) |
eb1bab5b | 49 | public class LTTngControlServiceTest extends TestCase { |
d132bcc7 BH |
50 | |
51 | private static final String DIRECTORY = "testfiles"; | |
52 | private static final String TEST_STREAM = "LTTngServiceTest.cfg"; | |
cfdb727a | 53 | |
d132bcc7 | 54 | private static final String SCEN_LTTNG_NOT_INSTALLED = "LttngNotInstalled"; |
276c17e7 | 55 | private static final String SCEN_LTTNG_VERSION = "LttngVersion"; |
d6fc6e1b | 56 | private static final String SCEN_LTTNG_VERSION_WITH_PROMPT = "LttngVersionWithPrompt"; |
276c17e7 BH |
57 | private static final String SCEN_LTTNG_UNSUPPORTED_VERSION = "LttngUnsupportedVersion"; |
58 | private static final String SCEN_LTTNG_NO_VERSION = "LttngNoVersion"; | |
d132bcc7 BH |
59 | private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable"; |
60 | private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1"; | |
61 | private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist"; | |
62 | private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut"; | |
63 | private static final String SCEN_GET_SESSION1 = "GetSession1"; | |
64 | private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1"; | |
a07c7629 BH |
65 | private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1"; |
66 | private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2"; | |
d132bcc7 BH |
67 | private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1"; |
68 | private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2"; | |
69 | private static final String SCEN_CREATE_SESSION1 = "CreateSession1"; | |
d6fc6e1b | 70 | private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt"; |
d132bcc7 BH |
71 | private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants"; |
72 | private static final String SCEN_DESTROY_SESSION1 = "DestroySession1"; | |
73 | private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling"; | |
74 | private static final String SCEN_EVENT_HANDLING = "EventHandling"; | |
4ea599a5 BH |
75 | private static final String SCEN_CONTEXT_HANDLING = "ContextHandling"; |
76 | private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling"; | |
77 | private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling"; | |
d132bcc7 | 78 | |
eb1bab5b BH |
79 | // ------------------------------------------------------------------------ |
80 | // Test data | |
81 | // ------------------------------------------------------------------------ | |
d132bcc7 BH |
82 | private CommandShellFactory fShellFactory; |
83 | private String fTestfile; | |
84 | private LTTngToolsFileShell fShell; | |
85 | private ILttngControlService fService; | |
86 | ||
cfdb727a | 87 | |
eb1bab5b BH |
88 | // ------------------------------------------------------------------------ |
89 | // Static methods | |
90 | // ------------------------------------------------------------------------ | |
91 | ||
92 | // ------------------------------------------------------------------------ | |
93 | // Housekeeping | |
94 | // ------------------------------------------------------------------------ | |
95 | /** | |
96 | * Perform pre-test initialization. | |
97 | * | |
98 | * @throws Exception if the initialization fails for some reason | |
99 | * | |
100 | */ | |
101 | @Override | |
102 | public void setUp() throws Exception { | |
103 | super.setUp(); | |
104 | fShellFactory = CommandShellFactory.getInstance(); | |
d132bcc7 | 105 | |
9269df72 | 106 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(DIRECTORY + File.separator + TEST_STREAM), null); |
d132bcc7 BH |
107 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
108 | fTestfile = testfile.getAbsolutePath(); | |
cfdb727a | 109 | |
d132bcc7 BH |
110 | fShell = fShellFactory.getFileShell(); |
111 | fShell.loadScenarioFile(fTestfile); | |
112 | fService = new LTTngControlService(fShell); | |
eb1bab5b BH |
113 | } |
114 | ||
115 | /** | |
116 | * Perform post-test clean-up. | |
117 | * | |
118 | * @throws Exception if the clean-up fails for some reason | |
119 | * | |
120 | */ | |
121 | @Override | |
122 | public void tearDown() throws Exception { | |
123 | } | |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // Test Cases | |
127 | // ------------------------------------------------------------------------ | |
cfdb727a | 128 | |
276c17e7 BH |
129 | public void testVersion() { |
130 | try { | |
131 | fShell.setScenario(SCEN_LTTNG_VERSION); | |
cfdb727a | 132 | ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); |
276c17e7 BH |
133 | assertNotNull(service); |
134 | assertEquals("2.0.0", service.getVersion()); | |
135 | } catch (ExecutionException e) { | |
136 | fail("Exeption thrown " + e); | |
137 | } | |
138 | } | |
cfdb727a | 139 | |
d6fc6e1b BH |
140 | public void testVersionWithPrompt() { |
141 | try { | |
142 | fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT); | |
143 | ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); | |
144 | assertNotNull(service); | |
145 | assertEquals("2.0.0", service.getVersion()); | |
146 | } catch (ExecutionException e) { | |
147 | fail("Exeption thrown " + e); | |
148 | } | |
149 | } | |
a07c7629 | 150 | |
276c17e7 BH |
151 | public void testUnsupportedVersion() { |
152 | try { | |
153 | fShell.setScenario(SCEN_LTTNG_UNSUPPORTED_VERSION); | |
cfdb727a | 154 | LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); |
276c17e7 BH |
155 | fail("No exeption thrown"); |
156 | } catch (ExecutionException e) { | |
157 | // success | |
158 | } | |
159 | } | |
160 | ||
161 | public void testNoVersion() { | |
162 | try { | |
163 | fShell.setScenario(SCEN_LTTNG_NO_VERSION); | |
cfdb727a | 164 | LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); |
276c17e7 BH |
165 | fail("No exeption thrown"); |
166 | } catch (ExecutionException e) { | |
167 | // success | |
168 | } | |
169 | } | |
170 | ||
171 | public void testLttngNotInstalled() { | |
eb1bab5b | 172 | try { |
d132bcc7 BH |
173 | fShell.setScenario(SCEN_LTTNG_NOT_INSTALLED); |
174 | fService.getSessionNames(new NullProgressMonitor()); | |
eb1bab5b | 175 | fail("No exeption thrown"); |
eb1bab5b BH |
176 | } catch (ExecutionException e) { |
177 | // success | |
178 | } | |
179 | } | |
cfdb727a | 180 | |
eb1bab5b BH |
181 | public void testGetSessionNames1() { |
182 | try { | |
d132bcc7 BH |
183 | fShell.setScenario(SCEN_NO_SESSION_AVAILABLE); |
184 | String[] result = fService.getSessionNames(new NullProgressMonitor()); | |
eb1bab5b BH |
185 | |
186 | assertNotNull(result); | |
187 | assertEquals(0, result.length); | |
cfdb727a | 188 | |
eb1bab5b BH |
189 | } catch (ExecutionException e) { |
190 | fail(e.toString()); | |
191 | } | |
192 | } | |
d132bcc7 | 193 | |
eb1bab5b BH |
194 | public void testGetSessionNames2() { |
195 | try { | |
d132bcc7 BH |
196 | fShell.setScenario(SCEN_GET_SESSION_NAMES1); |
197 | String[] result = fService.getSessionNames(new NullProgressMonitor()); | |
eb1bab5b BH |
198 | |
199 | assertNotNull(result); | |
200 | assertEquals(2, result.length); | |
201 | assertEquals("mysession1", result[0]); | |
202 | assertEquals("mysession", result[1]); | |
cfdb727a | 203 | |
eb1bab5b BH |
204 | } catch (ExecutionException e) { |
205 | fail(e.toString()); | |
206 | } | |
207 | } | |
d132bcc7 | 208 | |
eb1bab5b BH |
209 | public void testGetSessionNotExist() { |
210 | try { | |
d132bcc7 BH |
211 | fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST); |
212 | fService.getSessionNames(new NullProgressMonitor()); | |
eb1bab5b | 213 | fail("No exeption thrown"); |
cfdb727a | 214 | |
eb1bab5b BH |
215 | } catch (ExecutionException e) { |
216 | // success | |
217 | } | |
218 | } | |
cfdb727a | 219 | |
eb1bab5b BH |
220 | public void testGetSessionNameGarbage() { |
221 | try { | |
d132bcc7 BH |
222 | fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT); |
223 | String[] result = fService.getSessionNames(new NullProgressMonitor()); | |
eb1bab5b BH |
224 | |
225 | assertNotNull(result); | |
226 | assertEquals(0, result.length); | |
cfdb727a | 227 | |
eb1bab5b BH |
228 | } catch (ExecutionException e) { |
229 | fail(e.toString()); | |
230 | } | |
231 | } | |
cfdb727a | 232 | |
eb1bab5b BH |
233 | public void testGetSession1() { |
234 | try { | |
d132bcc7 BH |
235 | fShell.setScenario(SCEN_GET_SESSION1); |
236 | ISessionInfo session = fService.getSession("mysession", new NullProgressMonitor()); | |
eb1bab5b BH |
237 | |
238 | // Verify Session | |
239 | assertNotNull(session); | |
240 | assertEquals("mysession", session.getName()); | |
241 | assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath()); | |
242 | assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); | |
cfdb727a | 243 | |
eb1bab5b BH |
244 | IDomainInfo[] domains = session.getDomains(); |
245 | assertNotNull(domains); | |
246 | assertEquals(2, domains.length); | |
cfdb727a | 247 | |
eb1bab5b BH |
248 | // Verify Kernel domain |
249 | assertEquals("Kernel", domains[0].getName()); | |
250 | IChannelInfo[] channels = domains[0].getChannels(); | |
251 | assertNotNull(channels); | |
252 | assertEquals(2, channels.length); | |
253 | ||
cfdb727a | 254 | // Verify Kernel's channel0 |
eb1bab5b BH |
255 | assertEquals("channel0", channels[0].getName()); |
256 | assertEquals(4, channels[0].getNumberOfSubBuffers()); | |
257 | assertEquals("splice()", channels[0].getOutputType()); | |
258 | assertEquals(false, channels[0].isOverwriteMode()); | |
259 | assertEquals(200, channels[0].getReadTimer()); | |
260 | assertEquals(TraceEnablement.ENABLED, channels[0].getState()); | |
261 | assertEquals(262144, channels[0].getSubBufferSize()); | |
262 | assertEquals(0, channels[0].getSwitchTimer()); | |
cfdb727a | 263 | |
eb1bab5b BH |
264 | // Verify event info |
265 | IEventInfo[] channel0Events = channels[0].getEvents(); | |
266 | assertNotNull(channel0Events); | |
267 | assertEquals(2, channel0Events.length); | |
268 | assertEquals("block_rq_remap", channel0Events[0].getName()); | |
269 | assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel()); | |
270 | assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType()); | |
271 | assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState()); | |
cfdb727a | 272 | |
eb1bab5b BH |
273 | assertEquals("block_bio_remap", channel0Events[1].getName()); |
274 | assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel()); | |
275 | assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType()); | |
276 | assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState()); | |
cfdb727a AM |
277 | |
278 | // Verify Kernel's channel1 | |
eb1bab5b BH |
279 | assertEquals("channel1", channels[1].getName()); |
280 | assertEquals(4, channels[1].getNumberOfSubBuffers()); | |
281 | assertEquals("splice()", channels[1].getOutputType()); | |
282 | assertEquals(true, channels[1].isOverwriteMode()); | |
283 | assertEquals(400, channels[1].getReadTimer()); | |
284 | assertEquals(TraceEnablement.DISABLED, channels[1].getState()); | |
285 | assertEquals(524288, channels[1].getSubBufferSize()); | |
286 | assertEquals(100, channels[1].getSwitchTimer()); | |
cfdb727a | 287 | |
eb1bab5b BH |
288 | // Verify event info |
289 | IEventInfo[] channel1Events = channels[1].getEvents(); | |
290 | assertEquals(0, channel1Events.length); | |
cfdb727a | 291 | |
eb1bab5b BH |
292 | // Verify domain UST global |
293 | assertEquals("UST global", domains[1].getName()); | |
cfdb727a | 294 | |
eb1bab5b | 295 | IChannelInfo[] ustChannels = domains[1].getChannels(); |
cfdb727a AM |
296 | |
297 | // Verify UST global's mychannel1 | |
eb1bab5b BH |
298 | assertEquals("mychannel1", ustChannels[0].getName()); |
299 | assertEquals(8, ustChannels[0].getNumberOfSubBuffers()); | |
300 | assertEquals("mmap()", ustChannels[0].getOutputType()); | |
301 | assertEquals(true, ustChannels[0].isOverwriteMode()); | |
302 | assertEquals(100, ustChannels[0].getReadTimer()); | |
303 | assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState()); | |
304 | assertEquals(8192, ustChannels[0].getSubBufferSize()); | |
305 | assertEquals(200, ustChannels[0].getSwitchTimer()); | |
cfdb727a | 306 | |
eb1bab5b BH |
307 | // Verify event info |
308 | IEventInfo[] ustEvents = ustChannels[0].getEvents(); | |
309 | assertEquals(0, ustEvents.length); | |
310 | ||
cfdb727a | 311 | // Verify UST global's channel0 |
eb1bab5b BH |
312 | assertEquals("channel0", ustChannels[1].getName()); |
313 | assertEquals(4, ustChannels[1].getNumberOfSubBuffers()); | |
314 | assertEquals("mmap()", ustChannels[1].getOutputType()); | |
315 | assertEquals(false, ustChannels[1].isOverwriteMode()); | |
316 | assertEquals(200, ustChannels[1].getReadTimer()); | |
317 | assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState()); | |
318 | assertEquals(4096, ustChannels[1].getSubBufferSize()); | |
319 | assertEquals(0, ustChannels[1].getSwitchTimer()); | |
cfdb727a | 320 | |
eb1bab5b BH |
321 | // Verify event info |
322 | ustEvents = ustChannels[1].getEvents(); | |
323 | assertEquals(2, ustEvents.length); | |
cfdb727a | 324 | |
eb1bab5b | 325 | assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName()); |
4775bcbf | 326 | assertEquals(TraceLogLevel.TRACE_DEBUG_LINE, ustEvents[0].getLogLevel()); |
eb1bab5b BH |
327 | assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType()); |
328 | assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState()); | |
cfdb727a | 329 | |
eb1bab5b | 330 | assertEquals("*", ustEvents[1].getName()); |
4775bcbf | 331 | assertEquals(TraceLogLevel.LEVEL_UNKNOWN, ustEvents[1].getLogLevel()); |
eb1bab5b BH |
332 | assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType()); |
333 | assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState()); | |
cfdb727a | 334 | |
eb1bab5b | 335 | // next session (no detailed information available) |
d132bcc7 | 336 | session = fService.getSession("mysession1", new NullProgressMonitor()); |
eb1bab5b BH |
337 | assertNotNull(session); |
338 | assertEquals("mysession1", session.getName()); | |
339 | assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath()); | |
340 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
cfdb727a | 341 | |
eb1bab5b BH |
342 | domains = session.getDomains(); |
343 | assertNotNull(domains); | |
344 | assertEquals(0, domains.length); | |
345 | } catch (ExecutionException e) { | |
346 | fail(e.toString()); | |
347 | } | |
348 | } | |
349 | ||
350 | public void testGetKernelProvider() { | |
351 | try { | |
d132bcc7 BH |
352 | fShell.setScenario(SCEN_GET_KERNEL_PROVIDER1); |
353 | List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor()); | |
eb1bab5b BH |
354 | |
355 | // Verify event info | |
356 | assertNotNull(events); | |
357 | assertEquals(3, events.size()); | |
cfdb727a AM |
358 | |
359 | IBaseEventInfo baseEventInfo = events.get(0); | |
eb1bab5b BH |
360 | assertNotNull(baseEventInfo); |
361 | assertEquals("sched_kthread_stop", baseEventInfo.getName()); | |
362 | assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); | |
363 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); | |
cfdb727a AM |
364 | |
365 | baseEventInfo = events.get(1); | |
eb1bab5b BH |
366 | assertEquals("sched_kthread_stop_ret", baseEventInfo.getName()); |
367 | assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); | |
368 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); | |
cfdb727a AM |
369 | |
370 | baseEventInfo = events.get(2); | |
eb1bab5b BH |
371 | assertEquals("sched_wakeup_new", baseEventInfo.getName()); |
372 | assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); | |
373 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); | |
374 | ||
375 | } catch (ExecutionException e) { | |
376 | fail(e.toString()); | |
377 | } | |
378 | } | |
379 | ||
a07c7629 BH |
380 | public void testGetKernelProviderNoKernel1() { |
381 | try { | |
382 | fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL1); | |
383 | List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor()); | |
384 | ||
385 | // Verify event info | |
386 | assertNotNull(events); | |
387 | assertEquals(0, events.size()); | |
388 | ||
389 | } catch (ExecutionException e) { | |
390 | fail(e.toString()); | |
391 | } | |
392 | } | |
393 | ||
394 | public void testGetKernelProviderNoKernel2() { | |
395 | try { | |
396 | fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL2); | |
397 | List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor()); | |
398 | ||
399 | // Verify event info | |
400 | assertNotNull(events); | |
401 | assertEquals(0, events.size()); | |
402 | ||
403 | } catch (ExecutionException e) { | |
404 | fail(e.toString()); | |
405 | } | |
406 | } | |
407 | ||
408 | ||
eb1bab5b BH |
409 | public void testGetUstProvider() { |
410 | try { | |
d132bcc7 BH |
411 | fShell.setScenario(SCEN_GET_UST_PROVIDER1); |
412 | List<IUstProviderInfo> providers = fService.getUstProvider(); | |
eb1bab5b BH |
413 | |
414 | // Check all providers | |
415 | assertNotNull(providers); | |
416 | assertEquals(2, providers.size()); | |
cfdb727a | 417 | |
eb1bab5b BH |
418 | //Verify first provider |
419 | assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName()); | |
420 | assertEquals(9379, providers.get(0).getPid()); | |
cfdb727a | 421 | |
eb1bab5b BH |
422 | // Verify event info |
423 | IBaseEventInfo[] events = providers.get(0).getEvents(); | |
424 | assertNotNull(events); | |
425 | assertEquals(2, events.length); | |
426 | ||
cfdb727a | 427 | IBaseEventInfo baseEventInfo = events[0]; |
eb1bab5b BH |
428 | assertNotNull(baseEventInfo); |
429 | assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); | |
4775bcbf | 430 | assertEquals(TraceLogLevel.TRACE_DEBUG_MODULE, baseEventInfo.getLogLevel()); |
eb1bab5b | 431 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); |
cfdb727a AM |
432 | |
433 | baseEventInfo = events[1]; | |
eb1bab5b BH |
434 | assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); |
435 | assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel()); | |
436 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); | |
437 | ||
438 | //Verify second provider | |
439 | assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName()); | |
440 | assertEquals(4852, providers.get(1).getPid()); | |
cfdb727a | 441 | |
eb1bab5b BH |
442 | // Verify event info |
443 | events = providers.get(1).getEvents(); | |
444 | assertNotNull(events); | |
445 | assertEquals(2, events.length); | |
446 | ||
cfdb727a | 447 | baseEventInfo = events[0]; |
eb1bab5b BH |
448 | assertNotNull(baseEventInfo); |
449 | assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); | |
450 | assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel()); | |
451 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); | |
cfdb727a AM |
452 | |
453 | baseEventInfo = events[1]; | |
eb1bab5b | 454 | assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); |
4775bcbf | 455 | assertEquals(TraceLogLevel.TRACE_DEBUG_FUNCTION, baseEventInfo.getLogLevel()); |
eb1bab5b BH |
456 | assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); |
457 | ||
458 | } catch (ExecutionException e) { | |
459 | fail(e.toString()); | |
460 | } | |
461 | } | |
d132bcc7 | 462 | |
eb1bab5b BH |
463 | public void testUstProvider2() { |
464 | try { | |
d132bcc7 BH |
465 | fShell.setScenario(SCEN_GET_UST_PROVIDER2); |
466 | List<IUstProviderInfo> providers = fService.getUstProvider(); | |
eb1bab5b BH |
467 | |
468 | assertNotNull(providers); | |
469 | assertEquals(0, providers.size()); | |
cfdb727a | 470 | |
eb1bab5b BH |
471 | } catch (ExecutionException e) { |
472 | fail(e.toString()); | |
473 | } | |
474 | } | |
d132bcc7 | 475 | |
bbb3538a BH |
476 | public void testCreateSession() { |
477 | try { | |
d132bcc7 BH |
478 | fShell.setScenario(SCEN_CREATE_SESSION1); |
479 | ||
480 | ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor()); | |
bbb3538a BH |
481 | assertNotNull(info); |
482 | assertEquals("mysession2", info.getName()); | |
483 | assertNotNull(info.getSessionPath()); | |
484 | assertTrue(info.getSessionPath().contains("mysession2")); | |
485 | assertEquals(TraceSessionState.INACTIVE, info.getSessionState()); | |
486 | } catch (ExecutionException e) { | |
487 | fail(e.toString()); | |
488 | } | |
489 | } | |
d132bcc7 | 490 | |
d6fc6e1b BH |
491 | public void testCreateSessionWithPrompt() { |
492 | try { | |
a07c7629 | 493 | // First line has the shell prompt before the command output |
d6fc6e1b BH |
494 | // This can happen in a real application if the command line is not echoed by the shell. |
495 | fShell.setScenario(SCEN_CREATE_SESSION_WITH_PROMPT); | |
496 | ||
497 | // First line has no shell prompt before the output | |
498 | ISessionInfo info = fService.createSession("mysession2", null, new NullProgressMonitor()); | |
499 | assertNotNull(info); | |
500 | assertEquals("mysession2", info.getName()); | |
501 | assertNotNull(info.getSessionPath()); | |
502 | assertTrue(info.getSessionPath().contains("mysession2")); | |
503 | assertEquals(TraceSessionState.INACTIVE, info.getSessionState()); | |
504 | } catch (ExecutionException e) { | |
505 | fail(e.toString()); | |
506 | } | |
507 | } | |
508 | ||
a07c7629 | 509 | |
d132bcc7 BH |
510 | public void testCreateSessionVariants() { |
511 | ||
512 | fShell.setScenario(SCEN_CREATE_SESSION_VARIANTS); | |
513 | ||
bbb3538a | 514 | try { |
d132bcc7 | 515 | fService.createSession("alreadyExist", null, new NullProgressMonitor()); |
bbb3538a BH |
516 | fail("No exeption thrown"); |
517 | } catch (ExecutionException e) { | |
518 | // success | |
519 | } | |
cfdb727a | 520 | |
bbb3538a | 521 | try { |
d132bcc7 | 522 | fService.createSession("wrongName", null, new NullProgressMonitor()); |
bbb3538a BH |
523 | fail("No exeption thrown"); |
524 | } catch (ExecutionException e) { | |
525 | // success | |
cfdb727a | 526 | } |
bbb3538a BH |
527 | |
528 | try { | |
d132bcc7 | 529 | fService.createSession("withPath", "/home/user/hallo", new NullProgressMonitor()); |
bbb3538a BH |
530 | fail("No exeption thrown"); |
531 | } catch (ExecutionException e) { | |
532 | // success | |
cfdb727a | 533 | } |
bbb3538a BH |
534 | |
535 | try { | |
d132bcc7 | 536 | ISessionInfo info = fService.createSession("session with spaces", null, new NullProgressMonitor()); |
bbb3538a BH |
537 | assertNotNull(info); |
538 | assertEquals("session with spaces", info.getName()); | |
539 | assertNotNull(info.getSessionPath()); | |
540 | assertTrue(info.getSessionPath().contains("session with spaces")); | |
541 | assertEquals(TraceSessionState.INACTIVE, info.getSessionState()); | |
cfdb727a | 542 | |
bbb3538a BH |
543 | } catch (ExecutionException e) { |
544 | fail(e.toString()); | |
cfdb727a | 545 | } |
bbb3538a BH |
546 | |
547 | try { | |
d132bcc7 | 548 | ISessionInfo info = fService.createSession("pathWithSpaces", "/home/user/hallo user/here", new NullProgressMonitor()); |
bbb3538a BH |
549 | assertNotNull(info); |
550 | assertEquals("pathWithSpaces", info.getName()); | |
551 | assertNotNull(info.getSessionPath()); | |
552 | assertTrue(info.getSessionPath().contains("/home/user/hallo user/here")); | |
553 | assertEquals(TraceSessionState.INACTIVE, info.getSessionState()); | |
cfdb727a | 554 | |
bbb3538a BH |
555 | } catch (ExecutionException e) { |
556 | fail(e.toString()); | |
cfdb727a | 557 | } |
bbb3538a BH |
558 | } |
559 | ||
9d8a90ad | 560 | public void testDestroySession() { |
bbb3538a | 561 | try { |
d132bcc7 BH |
562 | fShell.setScenario(SCEN_DESTROY_SESSION1); |
563 | fService.destroySession("mysession2", new NullProgressMonitor()); | |
bbb3538a BH |
564 | } catch (ExecutionException e) { |
565 | fail(e.toString()); | |
cfdb727a | 566 | } |
bbb3538a | 567 | } |
d132bcc7 BH |
568 | |
569 | public void testCreateChannel() { | |
570 | try { | |
571 | ||
572 | String sessionName = "mysession2"; | |
573 | List<String> list = new ArrayList<String>(); | |
574 | String kernelChannel0 = "mychannel0"; | |
575 | String kernelChannel1 = "mychannel1"; | |
576 | list.add(kernelChannel0); | |
577 | list.add(kernelChannel1); | |
cfdb727a | 578 | |
d132bcc7 | 579 | fShell.setScenario(SCEN_CHANNEL_HANDLING); |
cfdb727a | 580 | |
d132bcc7 BH |
581 | // Create/enable/configure 2 kernel channels |
582 | ChannelInfo chanInfo = new ChannelInfo(""); | |
583 | chanInfo.setOverwriteMode(true); | |
584 | chanInfo.setSubBufferSize(16384); | |
585 | chanInfo.setReadTimer(100); | |
586 | chanInfo.setSwitchTimer(200); | |
587 | chanInfo.setNumberOfSubBuffers(2); | |
588 | fService.enableChannels(sessionName, list, true, chanInfo, new NullProgressMonitor()); | |
cfdb727a | 589 | |
d132bcc7 BH |
590 | // Create/enable/configure 1 UST channel |
591 | list.clear(); | |
592 | list.add("ustChannel"); | |
cfdb727a | 593 | |
d132bcc7 BH |
594 | chanInfo = new ChannelInfo(""); |
595 | chanInfo.setOverwriteMode(true); | |
596 | chanInfo.setSubBufferSize(32768); | |
597 | chanInfo.setReadTimer(200); | |
598 | chanInfo.setSwitchTimer(100); | |
599 | chanInfo.setNumberOfSubBuffers(1); | |
600 | fService.enableChannels(sessionName, list, false, chanInfo, new NullProgressMonitor()); | |
601 | ||
602 | } catch (ExecutionException e) { | |
603 | fail(e.toString()); | |
604 | } | |
605 | } | |
606 | ||
607 | public void testDisableChannel() { | |
608 | try { | |
609 | ||
610 | String sessionName = "mysession2"; | |
611 | List<String> list = new ArrayList<String>(); | |
612 | String kernelChannel0 = "mychannel0"; | |
613 | String kernelChannel1 = "mychannel1"; | |
614 | list.add(kernelChannel0); | |
615 | list.add(kernelChannel1); | |
cfdb727a | 616 | |
d132bcc7 BH |
617 | fShell.setScenario(SCEN_CHANNEL_HANDLING); |
618 | fService.disableChannels(sessionName, list, true, new NullProgressMonitor()); | |
cfdb727a | 619 | |
d132bcc7 BH |
620 | list.clear(); |
621 | list.add("ustChannel"); | |
622 | fService.disableChannels(sessionName, list, false, new NullProgressMonitor()); | |
623 | ||
624 | } catch (ExecutionException e) { | |
625 | fail(e.toString()); | |
626 | } | |
627 | } | |
cfdb727a | 628 | |
d132bcc7 BH |
629 | public void testEnableChannel() { |
630 | try { | |
631 | ||
632 | String sessionName = "mysession2"; | |
633 | List<String> list = new ArrayList<String>(); | |
634 | String kernelChannel0 = "mychannel0"; | |
635 | String kernelChannel1 = "mychannel1"; | |
636 | list.add(kernelChannel0); | |
637 | list.add(kernelChannel1); | |
cfdb727a | 638 | |
d132bcc7 BH |
639 | fShell.setScenario(SCEN_CHANNEL_HANDLING); |
640 | fService.enableChannels(sessionName, list, true, null, new NullProgressMonitor()); | |
cfdb727a | 641 | |
d132bcc7 BH |
642 | // Create/enable/configure 1 UST channel |
643 | list.clear(); | |
644 | list.add("ustChannel"); | |
cfdb727a | 645 | |
d132bcc7 BH |
646 | fService.enableChannels(sessionName, list, false, null, new NullProgressMonitor()); |
647 | ||
648 | } catch (ExecutionException e) { | |
649 | fail(e.toString()); | |
650 | } | |
651 | } | |
cfdb727a | 652 | |
d132bcc7 | 653 | // public void tesEnableChannelNoTracer() { |
bbb3538a | 654 | // try { |
d132bcc7 BH |
655 | // ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer()); |
656 | // service.getSessionNames(new NullProgressMonitor()); | |
657 | // fail("No exeption thrown"); | |
cfdb727a | 658 | // |
bbb3538a | 659 | // } catch (ExecutionException e) { |
d132bcc7 | 660 | // // success |
bbb3538a | 661 | // } |
cfdb727a AM |
662 | // } |
663 | ||
d132bcc7 BH |
664 | public void testEnableEvents() { |
665 | try { | |
666 | // 1) session name, channel = null, 3 event names, kernel | |
667 | String sessionName = "mysession2"; | |
668 | List<String> list = new ArrayList<String>(); | |
669 | String eventName0 = "block_rq_remap"; | |
670 | String eventName1 = "block_bio_remap"; | |
671 | String eventName2 = "softirq_entry"; | |
672 | list.add(eventName0); | |
673 | list.add(eventName1); | |
674 | list.add(eventName2); | |
675 | fShell.setScenario(SCEN_EVENT_HANDLING); | |
676 | fService.enableEvents(sessionName, null, list, true, new NullProgressMonitor()); | |
cfdb727a | 677 | |
d132bcc7 BH |
678 | // 2) session name, channel=mychannel, event name= null, kernel |
679 | String channelName = "mychannel"; | |
680 | fService.enableEvents(sessionName, channelName, null, true, new NullProgressMonitor()); | |
bbb3538a | 681 | |
d132bcc7 BH |
682 | // 3) session name, channel=mychannel, 1 event name, ust |
683 | String ustEventName = "ust_tests_hello:tptest_sighandler"; | |
684 | list.clear(); | |
685 | list.add(ustEventName); | |
686 | fService.enableEvents(sessionName, channelName, list, false, new NullProgressMonitor()); | |
cfdb727a | 687 | |
d132bcc7 BH |
688 | // 4) session name, channel = mychannel, no event name, ust |
689 | list.clear(); | |
690 | fService.enableEvents(sessionName, channelName, list, false, new NullProgressMonitor()); | |
cfdb727a | 691 | |
d132bcc7 BH |
692 | } catch (ExecutionException e) { |
693 | fail(e.toString()); | |
694 | } | |
695 | } | |
cfdb727a | 696 | |
d132bcc7 BH |
697 | public void testEnableSyscalls() { |
698 | try { | |
699 | // 1) session name, channel = null, 3 event names, kernel | |
700 | String sessionName = "mysession2"; | |
701 | String channelName = "mychannel"; | |
cfdb727a | 702 | |
d132bcc7 BH |
703 | fShell.setScenario(SCEN_EVENT_HANDLING); |
704 | ||
cfdb727a | 705 | // 1) session name, channel = null |
d132bcc7 BH |
706 | fService.enableSyscalls(sessionName, null, new NullProgressMonitor()); |
707 | ||
708 | // 2) session name, channel = mychannel | |
709 | fService.enableSyscalls(sessionName, channelName, new NullProgressMonitor()); | |
cfdb727a | 710 | |
d132bcc7 BH |
711 | } catch (ExecutionException e) { |
712 | fail(e.toString()); | |
713 | } | |
714 | } | |
715 | ||
716 | public void testDynamicProbe() { | |
717 | try { | |
718 | // 1) session name, channel = null, 3 event names, kernel | |
719 | String sessionName = "mysession2"; | |
720 | String channelName = "mychannel"; | |
721 | String eventName0 = "myevent0"; | |
722 | String eventName1 = "myevent1"; | |
723 | String functionProbe = "0xc0101340"; | |
724 | String dynProbe = "init_post"; | |
cfdb727a | 725 | |
d132bcc7 BH |
726 | fShell.setScenario(SCEN_EVENT_HANDLING); |
727 | ||
cfdb727a | 728 | // 1) session name, channel = null, event name, function probe, probe |
d132bcc7 BH |
729 | fService.enableProbe(sessionName, null, eventName0, true, functionProbe, new NullProgressMonitor()); |
730 | ||
731 | // 2) session name, channel = mychannel | |
732 | fService.enableProbe(sessionName, channelName, eventName1, false, dynProbe, new NullProgressMonitor()); | |
cfdb727a | 733 | |
d132bcc7 BH |
734 | } catch (ExecutionException e) { |
735 | fail(e.toString()); | |
736 | } | |
737 | } | |
738 | ||
739 | public void testEnableLogLevel() { | |
740 | try { | |
741 | // 1) session name, channel = null, 3 event names, kernel | |
742 | String sessionName = "mysession2"; | |
743 | String channelName = "mychannel"; | |
744 | String eventName4 = "myevent4"; | |
745 | String eventName5 = "myevent5"; | |
cfdb727a | 746 | |
d132bcc7 | 747 | fShell.setScenario(SCEN_EVENT_HANDLING); |
cfdb727a | 748 | |
d132bcc7 BH |
749 | // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG |
750 | fService.enableLogLevel(sessionName, null, eventName4, LogLevelType.LOGLEVEL_ONLY, TraceLogLevel.TRACE_DEBUG, new NullProgressMonitor()); | |
751 | ||
752 | // 2) session name, channel = mychannel, null, loglevel, TRACE_DEBUG_FUNCTION | |
753 | fService.enableLogLevel(sessionName, channelName, eventName5, LogLevelType.LOGLEVEL, TraceLogLevel.TRACE_DEBUG_FUNCTION, new NullProgressMonitor()); | |
754 | ||
755 | } catch (ExecutionException e) { | |
756 | fail(e.toString()); | |
757 | } | |
758 | } | |
cfdb727a | 759 | |
4ea599a5 BH |
760 | public void testAddContext() { |
761 | try { | |
762 | // 1) session name, channel = null, 3 event names, kernel | |
763 | String sessionName = "mysession2"; | |
764 | String channelName = "mychannel"; | |
765 | String eventName = "ust_tests_hello:tptest_sighandler"; | |
766 | List<String> contexts = new ArrayList<String>(); | |
767 | contexts.add("prio"); | |
768 | contexts.add("pid"); | |
769 | ||
770 | fShell.setScenario(SCEN_CONTEXT_HANDLING); | |
771 | ||
772 | List<String> availContexts = fService.getContextList(new NullProgressMonitor()); | |
773 | assertNotNull(availContexts); | |
774 | assertEquals(12, availContexts.size()); | |
775 | ||
cfdb727a | 776 | // A very "hard-coded" way to verify but it works ... |
4ea599a5 BH |
777 | Set<String> expectedContexts = new HashSet<String>(); |
778 | expectedContexts.add("pid"); | |
779 | expectedContexts.add("procname"); | |
780 | expectedContexts.add("prio"); | |
781 | expectedContexts.add("nice"); | |
782 | expectedContexts.add("vpid"); | |
783 | expectedContexts.add("tid"); | |
784 | expectedContexts.add("pthread_id"); | |
785 | expectedContexts.add("vtid"); | |
786 | expectedContexts.add("ppid"); | |
787 | expectedContexts.add("vppid"); | |
788 | expectedContexts.add("perf:cpu-cycles"); | |
789 | expectedContexts.add("perf:cycles"); | |
cfdb727a | 790 | |
4ea599a5 | 791 | assertTrue(expectedContexts.containsAll(availContexts)); |
cfdb727a | 792 | |
4ea599a5 BH |
793 | // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG |
794 | fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor()); | |
795 | ||
796 | } catch (ExecutionException e) { | |
797 | fail(e.toString()); | |
798 | } | |
799 | } | |
800 | ||
801 | public void testAddContextFailure() { | |
802 | ||
803 | // 1) session name, channel = null, 3 event names, kernel | |
804 | String sessionName = "mysession2"; | |
805 | String channelName = "mychannel"; | |
806 | String eventName = "ust_tests_hello:tptest_sighandler"; | |
807 | List<String> contexts = new ArrayList<String>(); | |
808 | contexts.add("prio"); | |
809 | contexts.add("pid"); | |
810 | fShell.setScenario(SCEN_CONTEXT_ERROR_HANDLING); | |
811 | try { | |
812 | fService.getContextList(new NullProgressMonitor()); | |
813 | fail("No exeption generated"); | |
814 | } catch (ExecutionException e) { | |
815 | // success | |
cfdb727a | 816 | } |
4ea599a5 BH |
817 | try { |
818 | // 1) session name, channel = null, event name, loglevel-only, TRACE_DEBUG | |
819 | fService.addContexts(sessionName, channelName, eventName, false, contexts, new NullProgressMonitor()); | |
820 | fail("No exeption generated"); | |
821 | } catch (ExecutionException e) { | |
822 | // success | |
cfdb727a | 823 | } |
4ea599a5 BH |
824 | } |
825 | ||
826 | public void testCalibrate() { | |
827 | try { | |
828 | fShell.setScenario(SCEN_CALIBRATE_HANDLING); | |
829 | fService.calibrate(true, new NullProgressMonitor()); | |
830 | ||
831 | } catch (ExecutionException e) { | |
832 | fail(e.toString()); | |
833 | } | |
834 | } | |
835 | ||
836 | public void testCalibrateFailure() { | |
837 | ||
838 | try { | |
839 | fShell.setScenario(SCEN_CALIBRATE_HANDLING); | |
840 | fService.calibrate(false, new NullProgressMonitor()); | |
841 | fail("No exeption generated"); | |
842 | } catch (ExecutionException e) { | |
843 | // success | |
cfdb727a | 844 | } |
4ea599a5 | 845 | } |
cfdb727a | 846 | |
eb1bab5b | 847 | } |