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
1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Alexandre Montplaisir - Port to JUnit4
12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 **********************************************************************/
14
15 package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.io.File;
22 import java.net.URL;
23
24 import org.eclipse.core.runtime.FileLocator;
25 import org.eclipse.core.runtime.Path;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.eclipse.remote.core.IRemoteConnection;
28 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
29 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceChannelOutputType;
30 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
31 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement;
32 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType;
33 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
34 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
35 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
36 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
37 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.EnableChannelDialogStub;
38 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
39 import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
40 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
41 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
42 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
43 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
44 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
45 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
46 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
47 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
48 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.UstProviderComponent;
49 import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory;
50 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
51 import org.junit.After;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.osgi.framework.FrameworkUtil;
55
56 /**
57 * The class {@link TraceControlUstProviderTest} contains UST provider
58 * handling test cases.
59 */
60 public class TraceControlUstProviderTest {
61
62 // ------------------------------------------------------------------------
63 // Constants
64 // ------------------------------------------------------------------------
65
66 private static final String TEST_STREAM = "CreateTreeTest.cfg";
67 private static final String SCEN_SCENARIO2_TEST = "Scenario2";
68
69 // ------------------------------------------------------------------------
70 // Test data
71 // ------------------------------------------------------------------------
72 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
73 private TraceControlTestFacility fFacility;
74 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
75 private String fTestFile;
76
77 // ------------------------------------------------------------------------
78 // Housekeeping
79 // ------------------------------------------------------------------------
80
81 /**
82 * Perform pre-test initialization.
83 *
84 * @throws Exception
85 * if the initialization fails for some reason
86 */
87 @Before
88 public void setUp() throws Exception {
89 fFacility = TraceControlTestFacility.getInstance();
90 fFacility.init();
91 fProxy = new TestRemoteSystemProxy(fHost);
92 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
93 File testfile = new File(FileLocator.toFileURL(location).toURI());
94 fTestFile = testfile.getAbsolutePath();
95 }
96
97 /**
98 * Perform post-test clean-up.
99 */
100 @After
101 public void tearDown() {
102 fFacility.dispose();
103 }
104
105 /**
106 * Run the TraceControlComponent.
107 *
108 * @throws Exception
109 * This will fail the test
110 */
111 @Test
112 public void testUstProviderTree() throws Exception {
113
114 fProxy.setTestFile(fTestFile);
115 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
116
117 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
118
119 TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
120 root.addChild(node);
121
122 fFacility.waitForJobs();
123
124 fFacility.executeCommand(node, "connect");
125 WaitUtils.waitUntil(new TargetNodeConnectedCondition(node));
126
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
139 // Get kernel provider events and select 2 events
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]);
163
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());
169
170 // ------------------------------------------------------------------------
171 // Enable Channel on UST global domain
172 // ------------------------------------------------------------------------
173 fProxy.setScenario(SCEN_SCENARIO2_TEST);
174 EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub();
175 channelDialogStub.setDomain(TraceDomainType.UST);
176 channelDialogStub.getChannelInfo().setOverwriteMode(false);
177 channelDialogStub.getChannelInfo().setSwitchTimer(200);
178 channelDialogStub.getChannelInfo().setReadTimer(100);
179 channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2);
180 TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub);
181
182 fFacility.executeCommand(session, "enableChannelOnSession");
183
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());
190
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);
197 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
198 assertEquals("mychannel", channel.getName());
199 assertEquals(2, channel.getNumberOfSubBuffers());
200 assertEquals("mmap()", channel.getOutputType().getInName());
201 assertEquals(TraceChannelOutputType.MMAP, channel.getOutputType());
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];
213 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName());
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");
227
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 // ------------------------------------------------------------------------
252 // Disable event components
253 // ------------------------------------------------------------------------
254 fFacility.executeCommand(event, "disableEvent");
255
256 assertEquals(TraceEnablement.DISABLED, event.getState());
257
258 // ------------------------------------------------------------------------
259 // Enable event component
260 // ------------------------------------------------------------------------
261 fFacility.executeCommand(event, "enableEvent");
262
263 // Verify event state
264 assertEquals(TraceEnablement.ENABLED, event.getState());
265
266 // ------------------------------------------------------------------------
267 // Destroy session
268 // ------------------------------------------------------------------------
269
270 // Initialize session handling scenario
271 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
272
273 fFacility.destroySession(session);
274
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.053138 seconds and 5 git commands to generate.