tmf: lttngControl: show error output first when handling error
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlUstProviderTests.java
CommitLineData
a26d90be 1/**********************************************************************
2ba3d0a1 2 * Copyright (c) 2012, 2013 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
a26d90be 12 **********************************************************************/
2ba3d0a1 13
8e8c0226 14package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
a26d90be 15
2ba3d0a1
AM
16import static org.junit.Assert.*;
17
a26d90be
BH
18import java.io.File;
19import java.net.URL;
20
a26d90be
BH
21import org.eclipse.core.runtime.FileLocator;
22import org.eclipse.core.runtime.Path;
8e8c0226
AM
23import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
24import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
25import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.EnableChannelDialogStub;
26import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
27import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
28import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
29import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
30import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
31import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
32import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
33import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
34import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
35import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
36import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
37import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
38import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
39import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
40import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
41import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.UstProviderComponent;
8577ed1e 42import org.eclipse.rse.core.RSECorePlugin;
a26d90be 43import org.eclipse.rse.core.model.IHost;
8577ed1e
BH
44import org.eclipse.rse.core.model.ISystemProfile;
45import org.eclipse.rse.core.model.ISystemRegistry;
a26d90be
BH
46import org.junit.After;
47import org.junit.Before;
2ba3d0a1 48import org.junit.Test;
9269df72 49import org.osgi.framework.FrameworkUtil;
a26d90be
BH
50
51/**
2ba3d0a1
AM
52 * The class <code>TraceControlUstProviderTests</code> contains UST provider
53 * handling test cases.
a26d90be 54 */
2ba3d0a1 55public class TraceControlUstProviderTests {
a26d90be
BH
56
57 // ------------------------------------------------------------------------
58 // Constants
59 // ------------------------------------------------------------------------
2ba3d0a1 60
a26d90be
BH
61 private static final String TEST_STREAM = "CreateTreeTest.cfg";
62 private static final String SCEN_SCENARIO2_TEST = "Scenario2";
63
64 // ------------------------------------------------------------------------
65 // Test data
66 // ------------------------------------------------------------------------
2ba3d0a1 67
a26d90be
BH
68 private TraceControlTestFacility fFacility;
69 private TestRemoteSystemProxy fProxy;
cfdb727a
AM
70 private String fTestFile;
71
a26d90be
BH
72 // ------------------------------------------------------------------------
73 // Housekeeping
74 // ------------------------------------------------------------------------
75
76 /**
77 * Perform pre-test initialization.
78 *
79 * @throws Exception
80 * if the initialization fails for some reason
a26d90be 81 */
a26d90be
BH
82 @Before
83 public void setUp() throws Exception {
84 fFacility = TraceControlTestFacility.getInstance();
1c3c5807 85 fFacility.init();
a26d90be 86 fProxy = new TestRemoteSystemProxy();
9269df72 87 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
a26d90be
BH
88 File testfile = new File(FileLocator.toFileURL(location).toURI());
89 fTestFile = testfile.getAbsolutePath();
90 }
91
92 /**
93 * Perform post-test clean-up.
a26d90be 94 */
a26d90be 95 @After
2ba3d0a1 96 public void tearDown() {
b957fb8c 97 fFacility.waitForJobs();
1c3c5807 98 fFacility.dispose();
a26d90be 99 }
cfdb727a 100
a26d90be
BH
101 /**
102 * Run the TraceControlComponent.
cfdb727a
AM
103 *
104 * @throws Exception
105 * This will fail the test
a26d90be 106 */
2ba3d0a1 107 @Test
a26d90be 108 public void testUstProviderTree() throws Exception {
cfdb727a 109
a26d90be
BH
110 fProxy.setTestFile(fTestFile);
111 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
cfdb727a 112
1c3c5807 113 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
a26d90be 114
8577ed1e
BH
115 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
116 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
117 IHost host = registry.createLocalHost(profile, "myProfile", "user");
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());
205 assertEquals("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];
2e74131b 217 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName());
a26d90be
BH
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");
cfdb727a 231
a26d90be
BH
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 // ------------------------------------------------------------------------
cfdb727a 256 // Disable event components
a26d90be
BH
257 // ------------------------------------------------------------------------
258 fFacility.executeCommand(event, "disableEvent");
cfdb727a 259
a26d90be
BH
260 assertEquals(TraceEnablement.DISABLED, event.getState());
261
262 // ------------------------------------------------------------------------
cfdb727a 263 // Enable event component
a26d90be
BH
264 // ------------------------------------------------------------------------
265 fFacility.executeCommand(event, "enableEvent");
266
267 // Verify event state
268 assertEquals(TraceEnablement.ENABLED, event.getState());
cfdb727a 269
a26d90be 270 // ------------------------------------------------------------------------
cfdb727a 271 // Destroy session
a26d90be
BH
272 // ------------------------------------------------------------------------
273
274 // Initialize session handling scenario
275 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
276
277 fFacility.destroySession(session);
cfdb727a 278
a26d90be
BH
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.068328 seconds and 5 git commands to generate.