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