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