Commit | Line | Data |
---|---|---|
83051fc3 | 1 | /********************************************************************** |
533d0bc3 | 2 | * Copyright (c) 2013, 2015 Ericsson |
83051fc3 BH |
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 | |
b732adaa | 11 | * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE |
83051fc3 BH |
12 | **********************************************************************/ |
13 | ||
9bc60be7 | 14 | package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component; |
83051fc3 BH |
15 | |
16 | import static org.junit.Assert.assertEquals; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | ||
20 | import java.io.File; | |
21 | import java.net.URL; | |
22 | ||
23 | import org.eclipse.core.runtime.FileLocator; | |
24 | import org.eclipse.core.runtime.Path; | |
d8a4fd60 | 25 | import org.eclipse.jdt.annotation.NonNull; |
b732adaa | 26 | import org.eclipse.remote.core.IRemoteConnection; |
9bc60be7 AM |
27 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
28 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.BufferType; | |
29 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ChannelInfo; | |
30 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub; | |
31 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub; | |
32 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.EnableChannelDialogStub; | |
33 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub; | |
34 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy; | |
35 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory; | |
36 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
37 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
38 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent; | |
39 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent; | |
40 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
b6b4e8b4 | 41 | import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory; |
83051fc3 BH |
42 | import org.junit.After; |
43 | import org.junit.Before; | |
44 | import org.junit.Test; | |
45 | import org.osgi.framework.FrameworkUtil; | |
46 | ||
47 | /** | |
48 | * The class <code>TraceControlUstSessionTests</code> contains UST | |
49 | * session/channel/event handling test cases for LTTng 2.2. | |
50 | */ | |
51 | public class TraceControlUstSessionTests2 { | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Constants | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | private static final String TEST_STREAM = "CreateTreeTest2.cfg"; | |
58 | private static final String SCEN_SCEN_PER_UID_TEST = "ScenPerUidTest"; | |
59 | private static final String SCEN_SCEN_PER_PID_TEST = "ScenPerPidTest"; | |
60 | private static final String SCEN_SCEN_BUF_SIZE_TEST = "ScenBufSizeTest"; | |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Test data | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
66 | private TraceControlTestFacility fFacility; | |
b6b4e8b4 | 67 | private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection(); |
d8a4fd60 | 68 | private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost); |
83051fc3 BH |
69 | private String fTestFile; |
70 | ||
71 | // ------------------------------------------------------------------------ | |
72 | // Housekeeping | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
75 | /** | |
76 | * Perform pre-test initialization. | |
77 | * | |
78 | * @throws Exception | |
79 | * if the initialization fails for some reason | |
80 | */ | |
81 | @Before | |
82 | public void setUp() throws Exception { | |
83 | fFacility = TraceControlTestFacility.getInstance(); | |
84 | fFacility.init(); | |
83051fc3 BH |
85 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null); |
86 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
87 | fTestFile = testfile.getAbsolutePath(); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Perform post-test clean-up. | |
92 | */ | |
93 | @After | |
94 | public void tearDown() { | |
83051fc3 BH |
95 | fFacility.dispose(); |
96 | } | |
97 | ||
98 | /** | |
99 | * Run the TraceControlComponent. | |
100 | * | |
101 | * @throws Exception | |
102 | * This will fail the test | |
103 | */ | |
104 | @Test | |
105 | public void testTraceSessionTree() throws Exception { | |
106 | ||
107 | fProxy.setTestFile(fTestFile); | |
108 | fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST); | |
109 | ||
110 | ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot(); | |
111 | ||
d8a4fd60 | 112 | TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy); |
83051fc3 BH |
113 | |
114 | root.addChild(node); | |
115 | fFacility.waitForJobs(); | |
116 | ||
117 | fFacility.executeCommand(node, "connect"); | |
118 | int i = 0; | |
119 | while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) { | |
120 | i++; | |
121 | fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY); | |
122 | } | |
123 | ||
124 | // Get provider groups | |
125 | ITraceControlComponent[] groups = node.getChildren(); | |
126 | assertNotNull(groups); | |
127 | assertEquals(2, groups.length); | |
128 | ||
129 | // Initialize dialog implementations for command execution | |
130 | TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub()); | |
131 | TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub()); | |
132 | TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub()); | |
133 | ||
134 | // Initialize scenario | |
135 | fProxy.setScenario(SCEN_SCEN_PER_UID_TEST); | |
136 | ||
137 | // ------------------------------------------------------------------------ | |
138 | // Create session | |
139 | // ------------------------------------------------------------------------ | |
140 | TraceSessionComponent session = fFacility.createSession(groups[1]); | |
141 | ||
142 | // Verify that session was created | |
143 | assertNotNull(session); | |
144 | assertEquals("mysession", session.getName()); | |
145 | ||
146 | // ------------------------------------------------------------------------ | |
147 | // Enable default channel on created session above | |
148 | // ------------------------------------------------------------------------ | |
149 | EnableChannelDialogStub channelStub = new EnableChannelDialogStub(); | |
150 | channelStub.setIsKernel(false); | |
151 | ChannelInfo info = (ChannelInfo)channelStub.getChannelInfo(); | |
152 | info.setName("mychannel"); | |
153 | info.setOverwriteMode(false); | |
154 | info.setSubBufferSize(-1); | |
155 | info.setNumberOfSubBuffers(-1); | |
156 | info.setSwitchTimer(-1); | |
157 | info.setReadTimer(-1); | |
158 | info.setMaxNumberTraceFiles(-1); | |
159 | info.setMaxSizeTraceFiles(-1); | |
160 | info.setBufferType(BufferType.BUFFER_PER_UID); | |
161 | channelStub.setChannelInfo(info); | |
162 | ||
163 | TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelStub); | |
164 | ||
165 | fFacility.executeCommand(session, "enableChannelOnSession"); | |
166 | ||
167 | // Verify that UST domain was created | |
168 | ITraceControlComponent[] domains = session.getChildren(); | |
169 | assertNotNull(domains); | |
170 | assertEquals(1, domains.length); | |
171 | ||
172 | assertEquals("UST global", domains[0].getName()); | |
173 | assertEquals("Domain buffer Type", BufferType.BUFFER_PER_UID, ((TraceDomainComponent)domains[0]).getBufferType()); | |
174 | ||
175 | // Verify that channel was created with correct data | |
176 | ITraceControlComponent[] channels = domains[0].getChildren(); | |
177 | assertNotNull(channels); | |
178 | assertEquals(1, channels.length); | |
179 | ||
180 | assertTrue(channels[0] instanceof TraceChannelComponent); | |
181 | TraceChannelComponent channel = (TraceChannelComponent) channels[0]; | |
182 | assertEquals("mychannel", channel.getName()); | |
183 | ||
184 | // ------------------------------------------------------------------------ | |
185 | // Destroy session | |
186 | // ------------------------------------------------------------------------ | |
187 | fFacility.destroySession(session); | |
188 | ||
189 | // Verify that no more session components exist | |
190 | assertEquals(0, groups[1].getChildren().length); | |
191 | ||
192 | // ------------------------------------------------------------------------ | |
193 | // Create session (per-pid buffers) | |
194 | // ------------------------------------------------------------------------ | |
195 | ||
196 | // Initialize scenario | |
197 | fProxy.setScenario(SCEN_SCEN_PER_PID_TEST); | |
198 | ||
199 | session = fFacility.createSession(groups[1]); | |
200 | ||
201 | // Verify that session was created | |
202 | assertNotNull(session); | |
203 | assertEquals("mysession", session.getName()); | |
204 | ||
205 | // ------------------------------------------------------------------------ | |
206 | // Enable default channel on created session above | |
207 | // ------------------------------------------------------------------------ | |
208 | info = (ChannelInfo)channelStub.getChannelInfo(); | |
209 | info.setName("mychannel"); | |
210 | info.setBufferType(BufferType.BUFFER_PER_PID); | |
211 | channelStub.setChannelInfo(info); | |
212 | ||
213 | fFacility.executeCommand(session, "enableChannelOnSession"); | |
214 | ||
215 | // Verify that UST domain was created | |
216 | domains = session.getChildren(); | |
217 | assertNotNull(domains); | |
218 | assertEquals(1, domains.length); | |
219 | ||
220 | assertEquals("UST global", domains[0].getName()); | |
221 | assertEquals("Domain buffer Type", BufferType.BUFFER_PER_PID, ((TraceDomainComponent)domains[0]).getBufferType()); | |
222 | ||
223 | // Verify that channel was created with correct data | |
224 | channels = domains[0].getChildren(); | |
225 | assertNotNull(channels); | |
226 | assertEquals(1, channels.length); | |
227 | ||
228 | assertTrue(channels[0] instanceof TraceChannelComponent); | |
229 | channel = (TraceChannelComponent) channels[0]; | |
230 | assertEquals("mychannel", channel.getName()); | |
231 | ||
232 | // ------------------------------------------------------------------------ | |
233 | // Destroy session | |
234 | // ------------------------------------------------------------------------ | |
235 | fFacility.destroySession(session); | |
236 | ||
237 | // Verify that no more session components exist | |
238 | assertEquals(0, groups[1].getChildren().length); | |
239 | ||
240 | // ------------------------------------------------------------------------ | |
241 | // Create session (configured file size and number of files) | |
242 | // ------------------------------------------------------------------------ | |
243 | ||
244 | // Initialize scenario | |
245 | fProxy.setScenario(SCEN_SCEN_BUF_SIZE_TEST); | |
246 | ||
247 | session = fFacility.createSession(groups[1]); | |
248 | ||
249 | // Verify that session was created | |
250 | assertNotNull(session); | |
251 | assertEquals("mysession", session.getName()); | |
252 | ||
253 | // ------------------------------------------------------------------------ | |
254 | // Enable default channel on created session above | |
255 | // ------------------------------------------------------------------------ | |
256 | info = (ChannelInfo)channelStub.getChannelInfo(); | |
257 | info.setName("mychannel"); | |
258 | info.setMaxNumberTraceFiles(10); | |
259 | info.setMaxSizeTraceFiles(1024); | |
260 | info.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); | |
261 | channelStub.setChannelInfo(info); | |
262 | ||
263 | fFacility.executeCommand(session, "enableChannelOnSession"); | |
264 | ||
265 | // Verify that UST domain was created | |
266 | domains = session.getChildren(); | |
267 | assertNotNull(domains); | |
268 | assertEquals(1, domains.length); | |
269 | ||
270 | assertEquals("UST global", domains[0].getName()); | |
271 | assertEquals("Domain buffer Type", BufferType.BUFFER_PER_PID, ((TraceDomainComponent)domains[0]).getBufferType()); | |
272 | ||
273 | // Verify that channel was created with correct data | |
274 | channels = domains[0].getChildren(); | |
275 | assertNotNull(channels); | |
276 | assertEquals(1, channels.length); | |
277 | ||
278 | assertTrue(channels[0] instanceof TraceChannelComponent); | |
279 | channel = (TraceChannelComponent) channels[0]; | |
280 | assertEquals("mychannel", channel.getName()); | |
281 | ||
282 | // ------------------------------------------------------------------------ | |
283 | // Destroy session | |
284 | // ------------------------------------------------------------------------ | |
285 | fFacility.destroySession(session); | |
286 | ||
287 | // Verify that no more session components exist | |
288 | assertEquals(0, groups[1].getChildren().length); | |
289 | ||
290 | //------------------------------------------------------------------------- | |
291 | // Disconnect node | |
292 | //------------------------------------------------------------------------- | |
293 | fFacility.executeCommand(node, "disconnect"); | |
294 | assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); | |
295 | ||
296 | //------------------------------------------------------------------------- | |
297 | // Delete node | |
298 | //------------------------------------------------------------------------- | |
299 | ||
300 | fFacility.executeCommand(node, "delete"); | |
83051fc3 BH |
301 | assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length); |
302 | } | |
303 | } |