lttng: Rename packages to org.eclipse.tracecompass.*
[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, 2013 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 **********************************************************************/
13
14 package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19
20 import java.io.File;
21 import java.net.URL;
22
23 import org.eclipse.core.runtime.FileLocator;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.rse.core.RSECorePlugin;
26 import org.eclipse.rse.core.model.IHost;
27 import org.eclipse.rse.core.model.ISystemProfile;
28 import org.eclipse.rse.core.model.ISystemRegistry;
29 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
30 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceChannelOutputType;
31 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement;
32 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType;
33 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
34 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
35 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
36 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
37 import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
38 import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
39 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
40 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
41 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.BaseEventComponent;
42 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.KernelProviderComponent;
43 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
44 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
45 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
46 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
47 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
48 import org.junit.After;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.osgi.framework.FrameworkUtil;
52
53 /**
54 * The class <code>TraceControlKernelProviderTests</code> contains UST provider
55 * handling test cases.
56 */
57 public class TraceControlKernelProviderTests {
58
59 // ------------------------------------------------------------------------
60 // Constants
61 // ------------------------------------------------------------------------
62
63 private static final String TEST_STREAM = "CreateTreeTest.cfg";
64 private static final String SCEN_SCENARIO1_TEST = "Scenario1";
65
66 // ------------------------------------------------------------------------
67 // Test data
68 // ------------------------------------------------------------------------
69
70 private TraceControlTestFacility fFacility;
71 private TestRemoteSystemProxy fProxy;
72 private String fTestFile;
73
74 // ------------------------------------------------------------------------
75 // Housekeeping
76 // ------------------------------------------------------------------------
77
78 /**
79 * Perform pre-test initialization.
80 *
81 * @throws Exception
82 * if the initialization fails for some reason
83 */
84 @Before
85 public void setUp() throws Exception {
86 fFacility = TraceControlTestFacility.getInstance();
87 fFacility.init();
88 fProxy = new TestRemoteSystemProxy();
89 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
90 File testfile = new File(FileLocator.toFileURL(location).toURI());
91 fTestFile = testfile.getAbsolutePath();
92 }
93
94 /**
95 * Perform post-test clean-up.
96 */
97 @After
98 public void tearDown() {
99 fFacility.waitForJobs();
100 fFacility.dispose();
101 }
102
103 /**
104 * Run the TraceControlComponent.
105 *
106 * @throws Exception
107 * Would fail the test
108 */
109 @Test
110 public void testKernelProviderTree() throws Exception {
111
112 fProxy.setTestFile(fTestFile);
113 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
114
115 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
116
117 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
118 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
119 IHost host = registry.createLocalHost(profile, "myProfile", "user");
120
121 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
122
123 root.addChild(node);
124
125 fFacility.waitForJobs();
126
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
134 // Verify that node is connected
135 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
136
137 // Get provider and session group
138 ITraceControlComponent[] groups = node.getChildren();
139 assertNotNull(groups);
140 assertEquals(2, groups.length);
141
142 // Check for kernel provider
143 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
144 assertTrue(providerGroup.hasKernelProvider());
145
146 // Get kernel provider
147 ITraceControlComponent[] providers = providerGroup.getChildren();
148 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
149
150 // Get kernel provider events and select 2 events
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);
165
166 // ------------------------------------------------------------------------
167 // Create session
168 // ------------------------------------------------------------------------
169 TraceSessionComponent session = fFacility.createSession(groups[1]);
170
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");
186
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());
193
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);
200 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
201 assertEquals("channel0", channel.getName());
202 assertEquals(4, channel.getNumberOfSubBuffers());
203 assertEquals("splice()", channel.getOutputType().getInName());
204 assertEquals(TraceChannelOutputType.SPLICE, channel.getOutputType());
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 // ------------------------------------------------------------------------
231 // Disable event components
232 // ------------------------------------------------------------------------
233 ITraceControlComponent[] selection = { event, event1 };
234 fFacility.executeCommand(selection, "disableEvent");
235
236 assertEquals(TraceEnablement.DISABLED, event.getState());
237 assertEquals(TraceEnablement.DISABLED, event1.getState());
238
239 // ------------------------------------------------------------------------
240 // Enable event component
241 // ------------------------------------------------------------------------
242 fFacility.executeCommand(event1, "enableEvent");
243
244 // Verify event state
245 assertEquals(TraceEnablement.ENABLED, event1.getState());
246
247 // ------------------------------------------------------------------------
248 // Destroy session
249 // ------------------------------------------------------------------------
250 // Initialize session handling scenario
251 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
252
253 fFacility.destroySession(session);
254
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());
263
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.041921 seconds and 5 git commands to generate.