ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlKernelProviderTests.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;
a26d90be
BH
48import org.junit.After;
49import org.junit.Before;
2ba3d0a1 50import org.junit.Test;
9269df72 51import org.osgi.framework.FrameworkUtil;
a26d90be
BH
52
53/**
2ba3d0a1
AM
54 * The class <code>TraceControlKernelProviderTests</code> contains UST provider
55 * handling test cases.
a26d90be 56 */
2ba3d0a1 57public class TraceControlKernelProviderTests {
a26d90be
BH
58
59 // ------------------------------------------------------------------------
60 // Constants
61 // ------------------------------------------------------------------------
2ba3d0a1 62
a26d90be
BH
63 private static final String TEST_STREAM = "CreateTreeTest.cfg";
64 private static final String SCEN_SCENARIO1_TEST = "Scenario1";
65
66 // ------------------------------------------------------------------------
67 // Test data
68 // ------------------------------------------------------------------------
2ba3d0a1 69
a26d90be 70 private TraceControlTestFacility fFacility;
b6b4e8b4 71 private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
d8a4fd60 72 private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
cfdb727a
AM
73 private String fTestFile;
74
a26d90be
BH
75 // ------------------------------------------------------------------------
76 // Housekeeping
77 // ------------------------------------------------------------------------
78
79 /**
80 * Perform pre-test initialization.
81 *
82 * @throws Exception
83 * if the initialization fails for some reason
a26d90be 84 */
a26d90be
BH
85 @Before
86 public void setUp() throws Exception {
87 fFacility = TraceControlTestFacility.getInstance();
1c3c5807 88 fFacility.init();
9269df72 89 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
a26d90be
BH
90 File testfile = new File(FileLocator.toFileURL(location).toURI());
91 fTestFile = testfile.getAbsolutePath();
92 }
93
94 /**
95 * Perform post-test clean-up.
a26d90be 96 */
a26d90be 97 @After
2ba3d0a1 98 public void tearDown() {
b957fb8c 99 fFacility.waitForJobs();
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
BH
123 fFacility.executeCommand(node, "connect");
124 int i = 0;
125 while ((i < 20) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
126 i++;
127 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
128 }
129
a26d90be
BH
130 // Verify that node is connected
131 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
132
a07c7629 133 // Get provider and session group
a26d90be
BH
134 ITraceControlComponent[] groups = node.getChildren();
135 assertNotNull(groups);
136 assertEquals(2, groups.length);
137
a07c7629
BH
138 // Check for kernel provider
139 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
140 assertTrue(providerGroup.hasKernelProvider());
141
a26d90be 142 // Get kernel provider
a07c7629 143 ITraceControlComponent[] providers = providerGroup.getChildren();
a26d90be
BH
144 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
145
cfdb727a 146 // Get kernel provider events and select 2 events
a26d90be
BH
147 ITraceControlComponent[] events = kernelProvider.getChildren();
148 assertNotNull(events);
149 assertEquals(3, events.length);
150
151 BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
152 BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
153
154 // Initialize dialog implementations for command execution
155 TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
156 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
157 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
158
159 // Initialize session handling scenario
160 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 161
a26d90be
BH
162 // ------------------------------------------------------------------------
163 // Create session
164 // ------------------------------------------------------------------------
165 TraceSessionComponent session = fFacility.createSession(groups[1]);
cfdb727a 166
a26d90be
BH
167 // Verify that session was created
168 assertNotNull(session);
169 assertEquals("mysession", session.getName());
170 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session.getSessionPath());
171 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
172
173 // ------------------------------------------------------------------------
174 // Enable event on default channel on created session above
175 // ------------------------------------------------------------------------
176 // Initialize scenario
177 fProxy.setScenario(SCEN_SCENARIO1_TEST);
178
179 ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 };
180
181 fFacility.executeCommand(components, "assign.event");
cfdb727a 182
a26d90be
BH
183 // Verify that kernel domain was created
184 ITraceControlComponent[] domains = session.getChildren();
185 assertNotNull(domains);
186 assertEquals(1, domains.length);
187
188 assertEquals("Kernel", domains[0].getName());
cfdb727a 189
a26d90be
BH
190 // Verify that channel0 was created with default values
191 ITraceControlComponent[] channels = domains[0].getChildren();
192 assertNotNull(channels);
193 assertEquals(1, channels.length);
194
195 assertTrue(channels[0] instanceof TraceChannelComponent);
cfdb727a 196 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
a26d90be
BH
197 assertEquals("channel0", channel.getName());
198 assertEquals(4, channel.getNumberOfSubBuffers());
0ad9fc89
JRJ
199 assertEquals("splice()", channel.getOutputType().getInName());
200 assertEquals(TraceChannelOutputType.SPLICE, channel.getOutputType());
a26d90be
BH
201 assertEquals(false, channel.isOverwriteMode());
202 assertEquals(200, channel.getReadTimer());
203 assertEquals(TraceEnablement.ENABLED, channel.getState());
204 assertEquals(262144, channel.getSubBufferSize());
205 assertEquals(0, channel.getSwitchTimer());
206
207 // Verify that event components were created
208 ITraceControlComponent[] channel0Events = channel.getChildren();
209 assertNotNull(channel0Events);
210 assertEquals(2, channel0Events.length);
211 assertTrue(channel0Events[0] instanceof TraceEventComponent);
212 assertTrue(channel0Events[1] instanceof TraceEventComponent);
213
214 TraceEventComponent event = (TraceEventComponent) channel0Events[0];
215 assertEquals("sched_kthread_stop_ret", event.getName());
216 assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel());
217 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
218 assertEquals(TraceEnablement.ENABLED, event.getState());
219
220 TraceEventComponent event1 = (TraceEventComponent) channel0Events[1];
221 assertEquals("sched_kthread_stop", event1.getName());
222 assertEquals(TraceLogLevel.TRACE_EMERG, event1.getLogLevel());
223 assertEquals(TraceEventType.TRACEPOINT, event1.getEventType());
224 assertEquals(TraceEnablement.ENABLED, event1.getState());
225
226 // ------------------------------------------------------------------------
cfdb727a 227 // Disable event components
a26d90be
BH
228 // ------------------------------------------------------------------------
229 ITraceControlComponent[] selection = { event, event1 };
230 fFacility.executeCommand(selection, "disableEvent");
cfdb727a 231
a26d90be
BH
232 assertEquals(TraceEnablement.DISABLED, event.getState());
233 assertEquals(TraceEnablement.DISABLED, event1.getState());
234
235 // ------------------------------------------------------------------------
cfdb727a 236 // Enable event component
a26d90be
BH
237 // ------------------------------------------------------------------------
238 fFacility.executeCommand(event1, "enableEvent");
cfdb727a 239
a26d90be
BH
240 // Verify event state
241 assertEquals(TraceEnablement.ENABLED, event1.getState());
cfdb727a 242
a26d90be 243 // ------------------------------------------------------------------------
cfdb727a 244 // Destroy session
a26d90be
BH
245 // ------------------------------------------------------------------------
246 // Initialize session handling scenario
247 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 248
a26d90be 249 fFacility.destroySession(session);
cfdb727a 250
a26d90be
BH
251 // Verify that no more session components exist
252 assertEquals(0, groups[1].getChildren().length);
253
254 //-------------------------------------------------------------------------
255 // Disconnect node
256 //-------------------------------------------------------------------------
257 fFacility.executeCommand(node, "disconnect");
258 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
cfdb727a 259
a26d90be
BH
260 //-------------------------------------------------------------------------
261 // Delete node
262 //-------------------------------------------------------------------------
263 fFacility.executeCommand(node, "delete");
264 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
265
266 }
267}
This page took 0.077201 seconds and 5 git commands to generate.