gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlCreateSessionTests.java
1 /**********************************************************************
2 * Copyright (c) 2013, 2014 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 * Jonathan Rajotte - Support for LTTng 2.6
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.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.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
26 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
27 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
28 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
29 import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
30 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
31 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
32 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
33 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
34 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.ILttngControlService;
35 import org.eclipse.rse.core.RSECorePlugin;
36 import org.eclipse.rse.core.model.IHost;
37 import org.eclipse.rse.core.model.ISystemProfile;
38 import org.eclipse.rse.core.model.ISystemRegistry;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.osgi.framework.FrameworkUtil;
43
44 /**
45 * The class {@link TraceControlKernelSessionTests} contains Kernel
46 * session/channel/event handling test cases.
47 */
48 public class TraceControlCreateSessionTests {
49
50 // ------------------------------------------------------------------------
51 // Constants
52 // ------------------------------------------------------------------------
53 private static final String TEST_STREAM = "CreateSessionTest.cfg";
54 private static final String SCEN_SCENARIO_FILE_PROTO_TEST = "CreateSessionFileProto";
55 private static final String SCEN_SCENARIO_CONTROL_DATA_TEST = "CreateSessionControlData";
56 private static final String SCEN_SCENARIO_NETWORK_TEST = "CreateSessionNetwork";
57 private static final String SCEN_SCENARIO_NETWORK2_TEST = "CreateSessionNetwork2";
58
59 private static final String SESSION = "mysession";
60
61 // ------------------------------------------------------------------------
62 // Test data
63 // ------------------------------------------------------------------------
64 private TraceControlTestFacility fFacility;
65 private TestRemoteSystemProxy fProxy;
66 private String fTestFile;
67
68 // ------------------------------------------------------------------------
69 // Housekeeping
70 // ------------------------------------------------------------------------
71
72 /**
73 * Perform pre-test initialization.
74 *
75 * @throws Exception
76 * if the initialization fails for some reason
77 */
78 @Before
79 public void setUp() throws Exception {
80 fFacility = TraceControlTestFacility.getInstance();
81 fFacility.init();
82 fProxy = new TestRemoteSystemProxy();
83 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + getTestStream()), null);
84 File testfile = new File(FileLocator.toFileURL(location).toURI());
85 fTestFile = testfile.getAbsolutePath();
86 }
87
88 /**
89 * Get the test stream file name to use for the test suite
90 *
91 * @return the name of the test stream file
92 */
93 protected String getTestStream() {
94 return TEST_STREAM;
95 }
96
97 /**
98 * Perform post-test clean-up.
99 */
100 @After
101 public void tearDown() {
102 fFacility.waitForJobs();
103 }
104
105 /**
106 * Run the TraceControlComponent.
107 *
108 * @throws Exception
109 * on internal error
110 */
111 @Test
112 public void testTraceSessionTree() throws Exception {
113
114 fProxy.setTestFile(fTestFile);
115 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
116
117 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
118
119 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
120 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
121 IHost host = registry.createLocalHost(profile, "myProfile", "user");
122
123 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
124
125 root.addChild(node);
126 fFacility.waitForJobs();
127
128 fFacility.executeCommand(node, "connect");
129 int i = 0;
130 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
131 i++;
132 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
133 }
134
135 // Verify that node is connected
136 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
137
138 ILttngControlService controleService = node.getControlService();
139
140 // Get provider groups
141 ITraceControlComponent[] groups = node.getChildren();
142 assertNotNull(groups);
143 assertEquals(2, groups.length);
144
145 // Initialize dialog implementations for command execution
146 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
147 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
148 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
149
150 // ------------------------------------------------------------------------
151 // Create session (--U file://...) and destroy
152 // ------------------------------------------------------------------------
153 // Initialize session handling scenario
154 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
155
156 sessionDialogStub.setNetworkUrl("file:///tmp");
157 sessionDialogStub.setStreamedTrace(true);
158 TraceSessionComponent session = fFacility.createSession(groups[1]);
159
160 // Verify that session was created
161 assertNotNull(session);
162 assertEquals(getSessionName(), session.getName());
163 if (controleService.isVersionSupported("2.6.0")) {
164 assertEquals("/tmp", session.getSessionPath());
165 } else {
166 assertEquals("file:///tmp", session.getSessionPath());
167 }
168
169 assertTrue(!session.isStreamedTrace());
170 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
171 sessionDialogStub.setNetworkUrl(null);
172 sessionDialogStub.setStreamedTrace(false);
173
174 fFacility.destroySession(session);
175
176 // Verify that no more session components exist
177 assertEquals(0, groups[1].getChildren().length);
178
179 // ------------------------------------------------------------------------
180 // Create session (--U file://,,, and destroy
181 // ------------------------------------------------------------------------
182 // Initialize session handling scenario
183 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
184
185 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
186 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
187 sessionDialogStub.setStreamedTrace(true);
188
189 session = fFacility.createSession(groups[1]);
190
191 // Verify that session was created
192 assertNotNull(session);
193 assertEquals(getSessionName(), session.getName());
194 if (controleService.isVersionSupported("2.6.0")) {
195 assertEquals("tcp4://172.0.0.1:5342/ [data: 5343]", session.getSessionPath());
196 } else {
197 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath());
198 }
199 assertTrue(session.isStreamedTrace());
200 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
201 sessionDialogStub.setControlUrl(null);
202 sessionDialogStub.setDataUrl(null);
203 sessionDialogStub.setStreamedTrace(false);
204
205 fFacility.destroySession(session);
206
207 // Verify that no more session components exist
208 assertEquals(0, groups[1].getChildren().length);
209
210 // ------------------------------------------------------------------------
211 // Create session (--U file://... and destroy
212 // ------------------------------------------------------------------------
213 // Initialize session handling scenario
214 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
215
216 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
217 sessionDialogStub.setStreamedTrace(true);
218
219 session = fFacility.createSession(groups[1]);
220
221 // Verify that session was created
222 assertNotNull(session);
223 assertEquals(getSessionName(), session.getName());
224 if (controleService.isVersionSupported("2.6.0")) {
225 assertEquals("tcp4://172.0.0.1:1234/mysession-20140820-153527 [data: 2345]", session.getSessionPath());
226 } else {
227 assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath());
228 }
229 assertTrue(session.isStreamedTrace());
230 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
231 sessionDialogStub.setNetworkUrl(null);
232
233 fFacility.destroySession(session);
234
235 // Verify that no more session components exist
236 assertEquals(0, groups[1].getChildren().length);
237
238 // ------------------------------------------------------------------------
239 // Create session (--U net6://[...] and destroy
240 // ------------------------------------------------------------------------
241 // Initialize session handling scenario
242 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
243
244 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
245 sessionDialogStub.setStreamedTrace(true);
246
247 session = fFacility.createSession(groups[1]);
248
249 // Verify that session was created
250 assertNotNull(session);
251 assertEquals(getSessionName(), session.getName());
252 if (controleService.isVersionSupported("2.6.0")) {
253 assertEquals("tcp6://[ffff::eeee:dddd:cccc:0]:5342/mysession-20140820-153801 [data: 5343]", session.getSessionPath());
254 } else {
255 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath());
256 }
257 assertTrue(session.isStreamedTrace());
258 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
259 sessionDialogStub.setNetworkUrl(null);
260
261 fFacility.destroySession(session);
262
263 // Verify that no more session components exist
264 assertEquals(0, groups[1].getChildren().length);
265
266 // -------------------------------------------------------------------------
267 // Disconnect node
268 // -------------------------------------------------------------------------
269 fFacility.executeCommand(node, "disconnect");
270 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
271
272 // -------------------------------------------------------------------------
273 // Delete node
274 // -------------------------------------------------------------------------
275
276 fFacility.executeCommand(node, "delete");
277 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
278 }
279
280 private static String getSessionName() {
281 return SESSION;
282 }
283
284 }
This page took 0.037678 seconds and 5 git commands to generate.