pcap: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / 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
8e8c0226 14package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
a26d90be 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;
8e8c0226
AM
25import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
26import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
27import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
28import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
29import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
0ad9fc89 30import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceChannelOutputType;
8e8c0226
AM
31import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
32import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
33import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
34import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
35import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
36import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
37import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
38import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
39import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
40import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
41import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
42import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
43import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
8577ed1e 44import org.eclipse.rse.core.RSECorePlugin;
a26d90be 45import org.eclipse.rse.core.model.IHost;
8577ed1e
BH
46import org.eclipse.rse.core.model.ISystemProfile;
47import org.eclipse.rse.core.model.ISystemRegistry;
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
BH
70 private TraceControlTestFacility fFacility;
71 private TestRemoteSystemProxy fProxy;
cfdb727a
AM
72 private String fTestFile;
73
a26d90be
BH
74 // ------------------------------------------------------------------------
75 // Housekeeping
76 // ------------------------------------------------------------------------
77
78 /**
79 * Perform pre-test initialization.
80 *
81 * @throws Exception
82 * if the initialization fails for some reason
a26d90be 83 */
a26d90be
BH
84 @Before
85 public void setUp() throws Exception {
86 fFacility = TraceControlTestFacility.getInstance();
1c3c5807 87 fFacility.init();
a26d90be 88 fProxy = new TestRemoteSystemProxy();
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
8577ed1e
BH
117 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
118 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
119 IHost host = registry.createLocalHost(profile, "myProfile", "user");
cfdb727a 120
a26d90be
BH
121 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
122
123 root.addChild(node);
a26d90be
BH
124
125 fFacility.waitForJobs();
126
b957fb8c
BH
127 fFacility.executeCommand(node, "connect");
128 int i = 0;
129 while ((i < 20) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
130 i++;
131 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
132 }
133
a26d90be
BH
134 // Verify that node is connected
135 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
136
a07c7629 137 // Get provider and session group
a26d90be
BH
138 ITraceControlComponent[] groups = node.getChildren();
139 assertNotNull(groups);
140 assertEquals(2, groups.length);
141
a07c7629
BH
142 // Check for kernel provider
143 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
144 assertTrue(providerGroup.hasKernelProvider());
145
a26d90be 146 // Get kernel provider
a07c7629 147 ITraceControlComponent[] providers = providerGroup.getChildren();
a26d90be
BH
148 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
149
cfdb727a 150 // Get kernel provider events and select 2 events
a26d90be
BH
151 ITraceControlComponent[] events = kernelProvider.getChildren();
152 assertNotNull(events);
153 assertEquals(3, events.length);
154
155 BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
156 BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
157
158 // Initialize dialog implementations for command execution
159 TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
160 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
161 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
162
163 // Initialize session handling scenario
164 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 165
a26d90be
BH
166 // ------------------------------------------------------------------------
167 // Create session
168 // ------------------------------------------------------------------------
169 TraceSessionComponent session = fFacility.createSession(groups[1]);
cfdb727a 170
a26d90be
BH
171 // Verify that session was created
172 assertNotNull(session);
173 assertEquals("mysession", session.getName());
174 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session.getSessionPath());
175 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
176
177 // ------------------------------------------------------------------------
178 // Enable event on default channel on created session above
179 // ------------------------------------------------------------------------
180 // Initialize scenario
181 fProxy.setScenario(SCEN_SCENARIO1_TEST);
182
183 ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 };
184
185 fFacility.executeCommand(components, "assign.event");
cfdb727a 186
a26d90be
BH
187 // Verify that kernel domain was created
188 ITraceControlComponent[] domains = session.getChildren();
189 assertNotNull(domains);
190 assertEquals(1, domains.length);
191
192 assertEquals("Kernel", domains[0].getName());
cfdb727a 193
a26d90be
BH
194 // Verify that channel0 was created with default values
195 ITraceControlComponent[] channels = domains[0].getChildren();
196 assertNotNull(channels);
197 assertEquals(1, channels.length);
198
199 assertTrue(channels[0] instanceof TraceChannelComponent);
cfdb727a 200 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
a26d90be
BH
201 assertEquals("channel0", channel.getName());
202 assertEquals(4, channel.getNumberOfSubBuffers());
0ad9fc89
JRJ
203 assertEquals("splice()", channel.getOutputType().getInName());
204 assertEquals(TraceChannelOutputType.SPLICE, channel.getOutputType());
a26d90be
BH
205 assertEquals(false, channel.isOverwriteMode());
206 assertEquals(200, channel.getReadTimer());
207 assertEquals(TraceEnablement.ENABLED, channel.getState());
208 assertEquals(262144, channel.getSubBufferSize());
209 assertEquals(0, channel.getSwitchTimer());
210
211 // Verify that event components were created
212 ITraceControlComponent[] channel0Events = channel.getChildren();
213 assertNotNull(channel0Events);
214 assertEquals(2, channel0Events.length);
215 assertTrue(channel0Events[0] instanceof TraceEventComponent);
216 assertTrue(channel0Events[1] instanceof TraceEventComponent);
217
218 TraceEventComponent event = (TraceEventComponent) channel0Events[0];
219 assertEquals("sched_kthread_stop_ret", event.getName());
220 assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel());
221 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
222 assertEquals(TraceEnablement.ENABLED, event.getState());
223
224 TraceEventComponent event1 = (TraceEventComponent) channel0Events[1];
225 assertEquals("sched_kthread_stop", event1.getName());
226 assertEquals(TraceLogLevel.TRACE_EMERG, event1.getLogLevel());
227 assertEquals(TraceEventType.TRACEPOINT, event1.getEventType());
228 assertEquals(TraceEnablement.ENABLED, event1.getState());
229
230 // ------------------------------------------------------------------------
cfdb727a 231 // Disable event components
a26d90be
BH
232 // ------------------------------------------------------------------------
233 ITraceControlComponent[] selection = { event, event1 };
234 fFacility.executeCommand(selection, "disableEvent");
cfdb727a 235
a26d90be
BH
236 assertEquals(TraceEnablement.DISABLED, event.getState());
237 assertEquals(TraceEnablement.DISABLED, event1.getState());
238
239 // ------------------------------------------------------------------------
cfdb727a 240 // Enable event component
a26d90be
BH
241 // ------------------------------------------------------------------------
242 fFacility.executeCommand(event1, "enableEvent");
cfdb727a 243
a26d90be
BH
244 // Verify event state
245 assertEquals(TraceEnablement.ENABLED, event1.getState());
cfdb727a 246
a26d90be 247 // ------------------------------------------------------------------------
cfdb727a 248 // Destroy session
a26d90be
BH
249 // ------------------------------------------------------------------------
250 // Initialize session handling scenario
251 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
cfdb727a 252
a26d90be 253 fFacility.destroySession(session);
cfdb727a 254
a26d90be
BH
255 // Verify that no more session components exist
256 assertEquals(0, groups[1].getChildren().length);
257
258 //-------------------------------------------------------------------------
259 // Disconnect node
260 //-------------------------------------------------------------------------
261 fFacility.executeCommand(node, "disconnect");
262 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
cfdb727a 263
a26d90be
BH
264 //-------------------------------------------------------------------------
265 // Delete node
266 //-------------------------------------------------------------------------
267 fFacility.executeCommand(node, "delete");
268 assertEquals(0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
269
270 }
271}
This page took 0.059532 seconds and 5 git commands to generate.