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