lttng: Fix ControlViewTest
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlKernelProviderTest.java
CommitLineData
a26d90be 1/**********************************************************************
533d0bc3 2 * Copyright (c) 2012, 2015 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
b732adaa 12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
a26d90be 13 **********************************************************************/
2ba3d0a1 14
9bc60be7 15package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
a26d90be 16
2ba3d0a1
AM
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertTrue;
20
a26d90be
BH
21import java.io.File;
22import java.net.URL;
23
a26d90be
BH
24import org.eclipse.core.runtime.FileLocator;
25import org.eclipse.core.runtime.Path;
d8a4fd60 26import org.eclipse.jdt.annotation.NonNull;
b732adaa 27import org.eclipse.remote.core.IRemoteConnection;
9bc60be7
AM
28import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
29import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceChannelOutputType;
30import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement;
31import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType;
32import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
33import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
34import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
35import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
36import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
37import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
38import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
39import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
40import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
41import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
42import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
43import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
44import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
45import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
46import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
b6b4e8b4 47import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory;
f3023b37 48import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
a26d90be
BH
49import org.junit.After;
50import org.junit.Before;
2ba3d0a1 51import org.junit.Test;
9269df72 52import org.osgi.framework.FrameworkUtil;
a26d90be
BH
53
54/**
b0d2c558 55 * The class {@link TraceControlKernelProviderTest} contains UST provider
2ba3d0a1 56 * handling test cases.
a26d90be 57 */
b0d2c558 58public class TraceControlKernelProviderTest {
a26d90be
BH
59
60 // ------------------------------------------------------------------------
61 // Constants
62 // ------------------------------------------------------------------------
2ba3d0a1 63
a26d90be
BH
64 private static final String TEST_STREAM = "CreateTreeTest.cfg";
65 private static final String SCEN_SCENARIO1_TEST = "Scenario1";
66
67 // ------------------------------------------------------------------------
68 // Test data
69 // ------------------------------------------------------------------------
2ba3d0a1 70
a26d90be 71 private TraceControlTestFacility fFacility;
b6b4e8b4 72 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
d8a4fd60 73 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
cfdb727a
AM
74 private String fTestFile;
75
a26d90be
BH
76 // ------------------------------------------------------------------------
77 // Housekeeping
78 // ------------------------------------------------------------------------
79
80 /**
81 * Perform pre-test initialization.
82 *
83 * @throws Exception
84 * if the initialization fails for some reason
a26d90be 85 */
a26d90be
BH
86 @Before
87 public void setUp() throws Exception {
88 fFacility = TraceControlTestFacility.getInstance();
1c3c5807 89 fFacility.init();
9269df72 90 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
a26d90be
BH
91 File testfile = new File(FileLocator.toFileURL(location).toURI());
92 fTestFile = testfile.getAbsolutePath();
93 }
94
95 /**
96 * Perform post-test clean-up.
a26d90be 97 */
a26d90be 98 @After
2ba3d0a1 99 public void tearDown() {
1c3c5807 100 fFacility.dispose();
a26d90be 101 }
cfdb727a 102
a26d90be
BH
103 /**
104 * Run the TraceControlComponent.
2ba3d0a1
AM
105 *
106 * @throws Exception
107 * Would fail the test
a26d90be 108 */
2ba3d0a1 109 @Test
a26d90be 110 public void testKernelProviderTree() throws Exception {
cfdb727a 111
a26d90be
BH
112 fProxy.setTestFile(fTestFile);
113 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
cfdb727a 114
1c3c5807 115 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
a26d90be 116
d8a4fd60 117 TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
a26d90be
BH
118
119 root.addChild(node);
a26d90be
BH
120
121 fFacility.waitForJobs();
122
b957fb8c 123 fFacility.executeCommand(node, "connect");
f3023b37 124 WaitUtils.waitUntil(new TargetNodeConnectedCondition(node));
b957fb8c 125
a26d90be
BH
126 // Verify that node is connected
127 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
128
a07c7629 129 // Get provider and session group
a26d90be
BH
130 ITraceControlComponent[] groups = node.getChildren();
131 assertNotNull(groups);
132 assertEquals(2, groups.length);
133
a07c7629
BH
134 // Check for kernel provider
135 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
136 assertTrue(providerGroup.hasKernelProvider());
137
a26d90be 138 // Get kernel provider
a07c7629 139 ITraceControlComponent[] providers = providerGroup.getChildren();
a26d90be
BH
140 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
141
cfdb727a 142 // Get kernel provider events and select 2 events
a26d90be
BH
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 // Initialize session handling scenario
156 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 157
a26d90be
BH
158 // ------------------------------------------------------------------------
159 // Create session
160 // ------------------------------------------------------------------------
161 TraceSessionComponent session = fFacility.createSession(groups[1]);
cfdb727a 162
a26d90be
BH
163 // Verify that session was created
164 assertNotNull(session);
165 assertEquals("mysession", session.getName());
166 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session.getSessionPath());
167 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
168
169 // ------------------------------------------------------------------------
170 // Enable event on default channel on created session above
171 // ------------------------------------------------------------------------
172 // Initialize scenario
173 fProxy.setScenario(SCEN_SCENARIO1_TEST);
174
175 ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 };
176
177 fFacility.executeCommand(components, "assign.event");
cfdb727a 178
a26d90be
BH
179 // Verify that kernel domain was created
180 ITraceControlComponent[] domains = session.getChildren();
181 assertNotNull(domains);
182 assertEquals(1, domains.length);
183
184 assertEquals("Kernel", domains[0].getName());
cfdb727a 185
a26d90be
BH
186 // Verify that channel0 was created with default values
187 ITraceControlComponent[] channels = domains[0].getChildren();
188 assertNotNull(channels);
189 assertEquals(1, channels.length);
190
191 assertTrue(channels[0] instanceof TraceChannelComponent);
cfdb727a 192 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
a26d90be
BH
193 assertEquals("channel0", channel.getName());
194 assertEquals(4, channel.getNumberOfSubBuffers());
0ad9fc89
JRJ
195 assertEquals("splice()", channel.getOutputType().getInName());
196 assertEquals(TraceChannelOutputType.SPLICE, channel.getOutputType());
a26d90be
BH
197 assertEquals(false, channel.isOverwriteMode());
198 assertEquals(200, channel.getReadTimer());
199 assertEquals(TraceEnablement.ENABLED, channel.getState());
200 assertEquals(262144, channel.getSubBufferSize());
201 assertEquals(0, channel.getSwitchTimer());
202
203 // Verify that event components were created
204 ITraceControlComponent[] channel0Events = channel.getChildren();
205 assertNotNull(channel0Events);
206 assertEquals(2, channel0Events.length);
207 assertTrue(channel0Events[0] instanceof TraceEventComponent);
208 assertTrue(channel0Events[1] instanceof TraceEventComponent);
209
210 TraceEventComponent event = (TraceEventComponent) channel0Events[0];
211 assertEquals("sched_kthread_stop_ret", event.getName());
212 assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel());
213 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
214 assertEquals(TraceEnablement.ENABLED, event.getState());
215
216 TraceEventComponent event1 = (TraceEventComponent) channel0Events[1];
217 assertEquals("sched_kthread_stop", event1.getName());
218 assertEquals(TraceLogLevel.TRACE_EMERG, event1.getLogLevel());
219 assertEquals(TraceEventType.TRACEPOINT, event1.getEventType());
220 assertEquals(TraceEnablement.ENABLED, event1.getState());
221
222 // ------------------------------------------------------------------------
cfdb727a 223 // Disable event components
a26d90be
BH
224 // ------------------------------------------------------------------------
225 ITraceControlComponent[] selection = { event, event1 };
226 fFacility.executeCommand(selection, "disableEvent");
cfdb727a 227
a26d90be
BH
228 assertEquals(TraceEnablement.DISABLED, event.getState());
229 assertEquals(TraceEnablement.DISABLED, event1.getState());
230
231 // ------------------------------------------------------------------------
cfdb727a 232 // Enable event component
a26d90be
BH
233 // ------------------------------------------------------------------------
234 fFacility.executeCommand(event1, "enableEvent");
cfdb727a 235
a26d90be
BH
236 // Verify event state
237 assertEquals(TraceEnablement.ENABLED, event1.getState());
cfdb727a 238
a26d90be 239 // ------------------------------------------------------------------------
cfdb727a 240 // Destroy session
a26d90be
BH
241 // ------------------------------------------------------------------------
242 // Initialize session handling scenario
243 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 244
a26d90be 245 fFacility.destroySession(session);
cfdb727a 246
a26d90be
BH
247 // Verify that no more session components exist
248 assertEquals(0, groups[1].getChildren().length);
249
250 //-------------------------------------------------------------------------
251 // Disconnect node
252 //-------------------------------------------------------------------------
253 fFacility.executeCommand(node, "disconnect");
254 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
cfdb727a 255
a26d90be
BH
256 //-------------------------------------------------------------------------
257 // Delete node
258 //-------------------------------------------------------------------------
259 fFacility.executeCommand(node, "delete");
260 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
261
262 }
263}
This page took 0.092333 seconds and 5 git commands to generate.