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