lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlUstProviderTests.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
15
16 import static org.junit.Assert.*;
17
18 import java.io.File;
19 import java.net.URL;
20
21 import org.eclipse.core.runtime.FileLocator;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
24 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
25 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.EnableChannelDialogStub;
26 import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
27 import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
28 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
29 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
30 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
31 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
32 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
33 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
34 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
35 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
36 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
37 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
38 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
39 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
40 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
41 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.UstProviderComponent;
42 import org.eclipse.rse.core.RSECorePlugin;
43 import org.eclipse.rse.core.model.IHost;
44 import org.eclipse.rse.core.model.ISystemProfile;
45 import org.eclipse.rse.core.model.ISystemRegistry;
46 import org.junit.After;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.osgi.framework.FrameworkUtil;
50
51 /**
52 * The class <code>TraceControlUstProviderTests</code> contains UST provider
53 * handling test cases.
54 */
55 public class TraceControlUstProviderTests {
56
57 // ------------------------------------------------------------------------
58 // Constants
59 // ------------------------------------------------------------------------
60
61 private static final String TEST_STREAM = "CreateTreeTest.cfg";
62 private static final String SCEN_SCENARIO2_TEST = "Scenario2";
63
64 // ------------------------------------------------------------------------
65 // Test data
66 // ------------------------------------------------------------------------
67
68 private TraceControlTestFacility fFacility;
69 private TestRemoteSystemProxy fProxy;
70 private String fTestFile;
71
72 // ------------------------------------------------------------------------
73 // Housekeeping
74 // ------------------------------------------------------------------------
75
76 /**
77 * Perform pre-test initialization.
78 *
79 * @throws Exception
80 * if the initialization fails for some reason
81 */
82 @Before
83 public void setUp() throws Exception {
84 fFacility = TraceControlTestFacility.getInstance();
85 fFacility.init();
86 fProxy = new TestRemoteSystemProxy();
87 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
88 File testfile = new File(FileLocator.toFileURL(location).toURI());
89 fTestFile = testfile.getAbsolutePath();
90 }
91
92 /**
93 * Perform post-test clean-up.
94 */
95 @After
96 public void tearDown() {
97 fFacility.waitForJobs();
98 fFacility.dispose();
99 }
100
101 /**
102 * Run the TraceControlComponent.
103 *
104 * @throws Exception
105 * This will fail the test
106 */
107 @Test
108 public void testUstProviderTree() throws Exception {
109
110 fProxy.setTestFile(fTestFile);
111 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
112
113 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
114
115 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
116 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
117 IHost host = registry.createLocalHost(profile, "myProfile", "user");
118
119 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
120 root.addChild(node);
121
122 fFacility.waitForJobs();
123
124 fFacility.executeCommand(node, "connect");
125
126 int i = 0;
127 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
128 i++;
129 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
130 }
131
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
144 // Get kernel provider events and select 2 events
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]);
168
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());
174
175 // ------------------------------------------------------------------------
176 // Enable Channel on UST global domain
177 // ------------------------------------------------------------------------
178 fProxy.setScenario(SCEN_SCENARIO2_TEST);
179 EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub();
180 channelDialogStub.setIsKernel(false);
181 channelDialogStub.getChannelInfo().setOverwriteMode(false);
182 channelDialogStub.getChannelInfo().setSwitchTimer(200);
183 channelDialogStub.getChannelInfo().setReadTimer(100);
184 channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2);
185 TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub);
186
187 fFacility.executeCommand(session, "enableChannelOnSession");
188
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());
195
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);
202 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
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];
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.0519 seconds and 5 git commands to generate.