lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / component / TraceControlKernelProviderTests.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
a26d90be
BH
14package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
15
2ba3d0a1
AM
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19
a26d90be
BH
20import java.io.File;
21import java.net.URL;
22
a26d90be
BH
23import org.eclipse.core.runtime.FileLocator;
24import org.eclipse.core.runtime.Path;
9315aeee
BH
25import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
26import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
27import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
28import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
29import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
a26d90be
BH
30import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
31import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
32import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
33import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
34import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
35import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
a26d90be
BH
36import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent;
37import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent;
38import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
39import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
40import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
a07c7629 41import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
a26d90be 42import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
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>TraceControlKernelProviderTests</code> contains UST provider
54 * handling test cases.
a26d90be 55 */
2ba3d0a1 56public class TraceControlKernelProviderTests {
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_SCENARIO1_TEST = "Scenario1";
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.
2ba3d0a1
AM
104 *
105 * @throws Exception
106 * Would fail the test
a26d90be 107 */
2ba3d0a1 108 @Test
a26d90be 109 public void testKernelProviderTree() 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");
cfdb727a 119
a26d90be
BH
120 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
121
122 root.addChild(node);
a26d90be
BH
123
124 fFacility.waitForJobs();
125
b957fb8c
BH
126 fFacility.executeCommand(node, "connect");
127 int i = 0;
128 while ((i < 20) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
129 i++;
130 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
131 }
132
a26d90be
BH
133 // Verify that node is connected
134 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
135
a07c7629 136 // Get provider and session group
a26d90be
BH
137 ITraceControlComponent[] groups = node.getChildren();
138 assertNotNull(groups);
139 assertEquals(2, groups.length);
140
a07c7629
BH
141 // Check for kernel provider
142 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
143 assertTrue(providerGroup.hasKernelProvider());
144
a26d90be 145 // Get kernel provider
a07c7629 146 ITraceControlComponent[] providers = providerGroup.getChildren();
a26d90be
BH
147 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
148
cfdb727a 149 // Get kernel provider events and select 2 events
a26d90be
BH
150 ITraceControlComponent[] events = kernelProvider.getChildren();
151 assertNotNull(events);
152 assertEquals(3, events.length);
153
154 BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
155 BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
156
157 // Initialize dialog implementations for command execution
158 TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
159 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
160 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
161
162 // Initialize session handling scenario
163 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 164
a26d90be
BH
165 // ------------------------------------------------------------------------
166 // Create session
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/lttng-traces/mysession-20120314-132824", session.getSessionPath());
174 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
175
176 // ------------------------------------------------------------------------
177 // Enable event on default channel on created session above
178 // ------------------------------------------------------------------------
179 // Initialize scenario
180 fProxy.setScenario(SCEN_SCENARIO1_TEST);
181
182 ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 };
183
184 fFacility.executeCommand(components, "assign.event");
cfdb727a 185
a26d90be
BH
186 // Verify that kernel domain was created
187 ITraceControlComponent[] domains = session.getChildren();
188 assertNotNull(domains);
189 assertEquals(1, domains.length);
190
191 assertEquals("Kernel", domains[0].getName());
cfdb727a 192
a26d90be
BH
193 // Verify that channel0 was created with default values
194 ITraceControlComponent[] channels = domains[0].getChildren();
195 assertNotNull(channels);
196 assertEquals(1, channels.length);
197
198 assertTrue(channels[0] instanceof TraceChannelComponent);
cfdb727a 199 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
a26d90be
BH
200 assertEquals("channel0", channel.getName());
201 assertEquals(4, channel.getNumberOfSubBuffers());
202 assertEquals("splice()", channel.getOutputType());
203 assertEquals(false, channel.isOverwriteMode());
204 assertEquals(200, channel.getReadTimer());
205 assertEquals(TraceEnablement.ENABLED, channel.getState());
206 assertEquals(262144, channel.getSubBufferSize());
207 assertEquals(0, channel.getSwitchTimer());
208
209 // Verify that event components were created
210 ITraceControlComponent[] channel0Events = channel.getChildren();
211 assertNotNull(channel0Events);
212 assertEquals(2, channel0Events.length);
213 assertTrue(channel0Events[0] instanceof TraceEventComponent);
214 assertTrue(channel0Events[1] instanceof TraceEventComponent);
215
216 TraceEventComponent event = (TraceEventComponent) channel0Events[0];
217 assertEquals("sched_kthread_stop_ret", event.getName());
218 assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel());
219 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
220 assertEquals(TraceEnablement.ENABLED, event.getState());
221
222 TraceEventComponent event1 = (TraceEventComponent) channel0Events[1];
223 assertEquals("sched_kthread_stop", event1.getName());
224 assertEquals(TraceLogLevel.TRACE_EMERG, event1.getLogLevel());
225 assertEquals(TraceEventType.TRACEPOINT, event1.getEventType());
226 assertEquals(TraceEnablement.ENABLED, event1.getState());
227
228 // ------------------------------------------------------------------------
cfdb727a 229 // Disable event components
a26d90be
BH
230 // ------------------------------------------------------------------------
231 ITraceControlComponent[] selection = { event, event1 };
232 fFacility.executeCommand(selection, "disableEvent");
cfdb727a 233
a26d90be
BH
234 assertEquals(TraceEnablement.DISABLED, event.getState());
235 assertEquals(TraceEnablement.DISABLED, event1.getState());
236
237 // ------------------------------------------------------------------------
cfdb727a 238 // Enable event component
a26d90be
BH
239 // ------------------------------------------------------------------------
240 fFacility.executeCommand(event1, "enableEvent");
cfdb727a 241
a26d90be
BH
242 // Verify event state
243 assertEquals(TraceEnablement.ENABLED, event1.getState());
cfdb727a 244
a26d90be 245 // ------------------------------------------------------------------------
cfdb727a 246 // Destroy session
a26d90be
BH
247 // ------------------------------------------------------------------------
248 // Initialize session handling scenario
249 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 250
a26d90be 251 fFacility.destroySession(session);
cfdb727a 252
a26d90be
BH
253 // Verify that no more session components exist
254 assertEquals(0, groups[1].getChildren().length);
255
256 //-------------------------------------------------------------------------
257 // Disconnect node
258 //-------------------------------------------------------------------------
259 fFacility.executeCommand(node, "disconnect");
260 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
cfdb727a 261
a26d90be
BH
262 //-------------------------------------------------------------------------
263 // Delete node
264 //-------------------------------------------------------------------------
265 fFacility.executeCommand(node, "delete");
266 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
267
268 }
269}
This page took 0.111685 seconds and 5 git commands to generate.