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