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