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