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