Commit | Line | Data |
---|---|---|
a26d90be | 1 | /********************************************************************** |
2ba3d0a1 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
a26d90be 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: | |
a26d90be | 10 | * Bernd Hufmann - Initial API and implementation |
2ba3d0a1 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
a26d90be | 12 | **********************************************************************/ |
2ba3d0a1 | 13 | |
a26d90be BH |
14 | package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component; |
15 | ||
2ba3d0a1 AM |
16 | import static org.junit.Assert.*; |
17 | ||
a26d90be BH |
18 | import java.io.File; |
19 | import java.net.URL; | |
20 | ||
a26d90be BH |
21 | import org.eclipse.core.runtime.FileLocator; |
22 | import org.eclipse.core.runtime.Path; | |
9315aeee BH |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
27 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
a26d90be BH |
28 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub; |
29 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub; | |
8577ed1e | 30 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableChannelDialogStub; |
a26d90be BH |
31 | import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub; |
32 | import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy; | |
33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; | |
34 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; | |
a26d90be BH |
35 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent; |
36 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent; | |
37 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; | |
38 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; | |
39 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; | |
40 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
41 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent; | |
8577ed1e | 42 | import org.eclipse.rse.core.RSECorePlugin; |
a26d90be | 43 | import org.eclipse.rse.core.model.IHost; |
8577ed1e BH |
44 | import org.eclipse.rse.core.model.ISystemProfile; |
45 | import org.eclipse.rse.core.model.ISystemRegistry; | |
a26d90be BH |
46 | import org.junit.After; |
47 | import org.junit.Before; | |
2ba3d0a1 | 48 | import org.junit.Test; |
9269df72 | 49 | import org.osgi.framework.FrameworkUtil; |
a26d90be BH |
50 | |
51 | /** | |
2ba3d0a1 AM |
52 | * The class <code>TraceControlUstProviderTests</code> contains UST provider |
53 | * handling test cases. | |
a26d90be BH |
54 | */ |
55 | @SuppressWarnings("nls") | |
2ba3d0a1 | 56 | public class TraceControlUstProviderTests { |
a26d90be BH |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Constants | |
60 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 61 | |
a26d90be BH |
62 | private static final String TEST_STREAM = "CreateTreeTest.cfg"; |
63 | private static final String SCEN_SCENARIO2_TEST = "Scenario2"; | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Test data | |
67 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 68 | |
a26d90be BH |
69 | private TraceControlTestFacility fFacility; |
70 | private TestRemoteSystemProxy fProxy; | |
cfdb727a AM |
71 | private String fTestFile; |
72 | ||
a26d90be BH |
73 | // ------------------------------------------------------------------------ |
74 | // Housekeeping | |
75 | // ------------------------------------------------------------------------ | |
76 | ||
77 | /** | |
78 | * Perform pre-test initialization. | |
79 | * | |
80 | * @throws Exception | |
81 | * if the initialization fails for some reason | |
a26d90be | 82 | */ |
a26d90be BH |
83 | @Before |
84 | public void setUp() throws Exception { | |
85 | fFacility = TraceControlTestFacility.getInstance(); | |
86 | fProxy = new TestRemoteSystemProxy(); | |
9269df72 | 87 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); |
a26d90be BH |
88 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
89 | fTestFile = testfile.getAbsolutePath(); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Perform post-test clean-up. | |
a26d90be | 94 | */ |
a26d90be | 95 | @After |
2ba3d0a1 | 96 | public void tearDown() { |
b957fb8c | 97 | fFacility.waitForJobs(); |
a26d90be | 98 | } |
cfdb727a | 99 | |
a26d90be BH |
100 | /** |
101 | * Run the TraceControlComponent. | |
cfdb727a AM |
102 | * |
103 | * @throws Exception | |
104 | * This will fail the test | |
a26d90be | 105 | */ |
2ba3d0a1 | 106 | @Test |
a26d90be | 107 | public void testUstProviderTree() throws Exception { |
cfdb727a | 108 | |
a26d90be BH |
109 | fProxy.setTestFile(fTestFile); |
110 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); | |
cfdb727a | 111 | |
a26d90be BH |
112 | ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); |
113 | ||
8577ed1e BH |
114 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); |
115 | ISystemProfile profile = registry.createSystemProfile("myProfile", true); | |
116 | IHost host = registry.createLocalHost(profile, "myProfile", "user"); | |
a26d90be BH |
117 | |
118 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy); | |
119 | root.addChild(node); | |
cfdb727a | 120 | |
b957fb8c | 121 | fFacility.waitForJobs(); |
cfdb727a | 122 | |
a26d90be | 123 | fFacility.executeCommand(node, "connect"); |
b957fb8c BH |
124 | |
125 | int i = 0; | |
126 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
127 | i++; | |
128 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
129 | } | |
cfdb727a | 130 | |
a26d90be BH |
131 | // Verify that node is connected |
132 | assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); | |
133 | ||
134 | // Get provider groups | |
135 | ITraceControlComponent[] groups = node.getChildren(); | |
136 | assertNotNull(groups); | |
137 | assertEquals(2, groups.length); | |
138 | ||
139 | // Get kernel provider | |
140 | ITraceControlComponent[] providers = groups[0].getChildren(); | |
141 | KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0]; | |
142 | ||
cfdb727a | 143 | // Get kernel provider events and select 2 events |
a26d90be BH |
144 | ITraceControlComponent[] events = kernelProvider.getChildren(); |
145 | assertNotNull(events); | |
146 | assertEquals(3, events.length); | |
147 | ||
148 | BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0]; | |
149 | BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1]; | |
150 | ||
151 | // Initialize dialog implementations for command execution | |
152 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub()); | |
153 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); | |
154 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
155 | ||
156 | // ------------------------------------------------------------------------ | |
157 | // Create session | |
158 | // ------------------------------------------------------------------------ | |
159 | // Initialize session handling scenario | |
160 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH); | |
161 | ||
162 | CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub(); | |
163 | sessionDialogStub.setSessionPath("/home/user/temp"); | |
164 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub); | |
165 | ||
166 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
cfdb727a | 167 | |
a26d90be BH |
168 | // Verify that session was created |
169 | assertNotNull(session); | |
170 | assertEquals("mysession", session.getName()); | |
171 | assertEquals("/home/user/temp", session.getSessionPath()); | |
172 | assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); | |
cfdb727a | 173 | |
a26d90be | 174 | // ------------------------------------------------------------------------ |
d62bfa55 | 175 | // Enable Channel on UST global domain |
a26d90be BH |
176 | // ------------------------------------------------------------------------ |
177 | fProxy.setScenario(SCEN_SCENARIO2_TEST); | |
d62bfa55 | 178 | EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub(); |
a26d90be BH |
179 | channelDialogStub.setIsKernel(false); |
180 | channelDialogStub.getChannelInfo().setOverwriteMode(false); | |
181 | channelDialogStub.getChannelInfo().setSwitchTimer(200); | |
182 | channelDialogStub.getChannelInfo().setReadTimer(100); | |
183 | channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2); | |
d62bfa55 | 184 | TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub); |
a26d90be | 185 | |
d62bfa55 | 186 | fFacility.executeCommand(session, "enableChannelOnSession"); |
cfdb727a | 187 | |
a26d90be BH |
188 | // Verify that UST domain was created |
189 | ITraceControlComponent[] domains = session.getChildren(); | |
190 | assertNotNull(domains); | |
191 | assertEquals(1, domains.length); | |
192 | ||
193 | assertEquals("UST global", domains[0].getName()); | |
cfdb727a | 194 | |
a26d90be BH |
195 | // Verify that channel was created with correct data |
196 | ITraceControlComponent[]channels = domains[0].getChildren(); | |
197 | assertNotNull(channels); | |
198 | assertEquals(1, channels.length); | |
199 | ||
200 | assertTrue(channels[0] instanceof TraceChannelComponent); | |
cfdb727a | 201 | TraceChannelComponent channel = (TraceChannelComponent) channels[0]; |
a26d90be BH |
202 | assertEquals("mychannel", channel.getName()); |
203 | assertEquals(2, channel.getNumberOfSubBuffers()); | |
204 | assertEquals("mmap()", channel.getOutputType()); | |
205 | assertEquals(false, channel.isOverwriteMode()); | |
206 | assertEquals(100, channel.getReadTimer()); | |
207 | assertEquals(TraceEnablement.ENABLED, channel.getState()); | |
208 | assertEquals(16384, channel.getSubBufferSize()); | |
209 | assertEquals(200, channel.getSwitchTimer()); | |
210 | ||
211 | // ------------------------------------------------------------------------ | |
212 | // Enable event on default channel on created session above | |
213 | // ------------------------------------------------------------------------ | |
214 | // Get first UST provider | |
215 | UstProviderComponent ustProvider = (UstProviderComponent) providers[1]; | |
2e74131b | 216 | assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName()); |
a26d90be BH |
217 | assertEquals(9379, ustProvider.getPid()); |
218 | ||
219 | // Get events | |
220 | events = ustProvider.getChildren(); | |
221 | assertNotNull(events); | |
222 | assertEquals(2, events.length); | |
223 | ||
224 | baseEventInfo0 = (BaseEventComponent) events[0]; | |
225 | baseEventInfo1 = (BaseEventComponent) events[1]; | |
226 | ||
227 | ITraceControlComponent[] ustSelection = { baseEventInfo0, baseEventInfo1 }; | |
228 | ||
229 | fFacility.executeCommand(ustSelection, "assign.event"); | |
cfdb727a | 230 | |
a26d90be BH |
231 | // verify that events were created under the channel |
232 | // Note that domain and channel has to be re-read because the tree is re-created | |
233 | ||
234 | domains = session.getChildren(); | |
235 | ||
236 | // Verify that channel was created with correct data | |
237 | channels = domains[0].getChildren(); | |
238 | ||
239 | ITraceControlComponent[] ustEvents = channels[0].getChildren(); | |
240 | assertEquals(2, ustEvents.length); | |
241 | ||
242 | TraceEventComponent event = (TraceEventComponent) ustEvents[0]; | |
243 | assertEquals("ust_tests_hello:tptest_sighandler", event.getName()); | |
244 | assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); | |
245 | assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); | |
246 | assertEquals(TraceEnablement.ENABLED, event.getState()); | |
247 | ||
248 | event = (TraceEventComponent) ustEvents[1]; | |
249 | assertEquals("ust_tests_hello:tptest", ustEvents[1].getName()); | |
250 | assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel()); | |
251 | assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); | |
252 | assertEquals(TraceEnablement.ENABLED, event.getState()); | |
253 | ||
254 | // ------------------------------------------------------------------------ | |
cfdb727a | 255 | // Disable event components |
a26d90be BH |
256 | // ------------------------------------------------------------------------ |
257 | fFacility.executeCommand(event, "disableEvent"); | |
cfdb727a | 258 | |
a26d90be BH |
259 | assertEquals(TraceEnablement.DISABLED, event.getState()); |
260 | ||
261 | // ------------------------------------------------------------------------ | |
cfdb727a | 262 | // Enable event component |
a26d90be BH |
263 | // ------------------------------------------------------------------------ |
264 | fFacility.executeCommand(event, "enableEvent"); | |
265 | ||
266 | // Verify event state | |
267 | assertEquals(TraceEnablement.ENABLED, event.getState()); | |
cfdb727a | 268 | |
a26d90be | 269 | // ------------------------------------------------------------------------ |
cfdb727a | 270 | // Destroy session |
a26d90be BH |
271 | // ------------------------------------------------------------------------ |
272 | ||
273 | // Initialize session handling scenario | |
274 | fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING); | |
275 | ||
276 | fFacility.destroySession(session); | |
cfdb727a | 277 | |
a26d90be BH |
278 | // Verify that no more session components exist |
279 | assertEquals(0, groups[1].getChildren().length); | |
280 | ||
281 | //------------------------------------------------------------------------- | |
282 | // Disconnect node | |
283 | //------------------------------------------------------------------------- | |
284 | fFacility.executeCommand(node, "disconnect"); | |
285 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
286 | ||
287 | //------------------------------------------------------------------------- | |
288 | // Delete node | |
289 | //------------------------------------------------------------------------- | |
290 | fFacility.executeCommand(node, "delete"); | |
291 | assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length); | |
292 | } | |
293 | } |