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