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