1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
17 import junit
.framework
.Test
;
18 import junit
.framework
.TestCase
;
19 import junit
.framework
.TestSuite
;
21 import org
.eclipse
.core
.runtime
.FileLocator
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceEventComponent
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
40 import org
.eclipse
.rse
.core
.RSECorePlugin
;
41 import org
.eclipse
.rse
.core
.model
.IHost
;
42 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
43 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
44 import org
.junit
.After
;
45 import org
.junit
.Before
;
46 import org
.osgi
.framework
.FrameworkUtil
;
49 * The class <code>TraceControlKernelProviderTests</code> contains UST provider handling
52 @SuppressWarnings("nls")
53 public class TraceControlKernelProviderTests
extends TestCase
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
58 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
59 private static final String SCEN_SCENARIO1_TEST
= "Scenario1";
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
64 private TraceControlTestFacility fFacility
;
65 private TestRemoteSystemProxy fProxy
;
66 private String fTestFile
;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Returns test setup used when executing test case stand-alone.
74 * @return Test setup class
76 public static Test
suite() {
77 return new ModelImplTestSetup(new TestSuite(TraceControlKernelProviderTests
.class));
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * Perform pre-test initialization.
88 * if the initialization fails for some reason
93 public void setUp() throws Exception
{
94 fFacility
= TraceControlTestFacility
.getInstance();
95 fProxy
= new TestRemoteSystemProxy();
96 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
97 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
98 fTestFile
= testfile
.getAbsolutePath();
102 * Perform post-test clean-up.
105 * if the clean-up fails for some reason
110 public void tearDown() throws Exception
{
111 fFacility
.waitForJobs();
115 * Run the TraceControlComponent.
117 public void testKernelProviderTree() throws Exception
{
120 fProxy
.setTestFile(fTestFile
);
121 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
123 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
125 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
126 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
127 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
129 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
133 fFacility
.waitForJobs();
135 fFacility
.executeCommand(node
, "connect");
137 while ((i
< 20) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
139 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
142 // Verify that node is connected
143 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
145 // Get provider groups
146 ITraceControlComponent
[] groups
= node
.getChildren();
147 assertNotNull(groups
);
148 assertEquals(2, groups
.length
);
150 // Get kernel provider
151 ITraceControlComponent
[] providers
= groups
[0].getChildren();
152 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
154 // Get kernel provider events and select 2 events
155 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
156 assertNotNull(events
);
157 assertEquals(3, events
.length
);
159 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
160 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
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());
167 // Initialize session handling scenario
168 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
170 // ------------------------------------------------------------------------
172 // ------------------------------------------------------------------------
173 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
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());
181 // ------------------------------------------------------------------------
182 // Enable event on default channel on created session above
183 // ------------------------------------------------------------------------
184 // Initialize scenario
185 fProxy
.setScenario(SCEN_SCENARIO1_TEST
);
187 ITraceControlComponent
[] components
= { baseEventInfo0
, baseEventInfo1
};
189 fFacility
.executeCommand(components
, "assign.event");
191 // Verify that kernel domain was created
192 ITraceControlComponent
[] domains
= session
.getChildren();
193 assertNotNull(domains
);
194 assertEquals(1, domains
.length
);
196 assertEquals("Kernel", domains
[0].getName());
198 // Verify that channel0 was created with default values
199 ITraceControlComponent
[] channels
= domains
[0].getChildren();
200 assertNotNull(channels
);
201 assertEquals(1, channels
.length
);
203 assertTrue(channels
[0] instanceof TraceChannelComponent
);
204 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
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());
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
);
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());
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());
233 // ------------------------------------------------------------------------
234 // Disable event components
235 // ------------------------------------------------------------------------
236 ITraceControlComponent
[] selection
= { event
, event1
};
237 fFacility
.executeCommand(selection
, "disableEvent");
239 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
240 assertEquals(TraceEnablement
.DISABLED
, event1
.getState());
242 // ------------------------------------------------------------------------
243 // Enable event component
244 // ------------------------------------------------------------------------
245 fFacility
.executeCommand(event1
, "enableEvent");
247 // Verify event state
248 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
250 // ------------------------------------------------------------------------
252 // ------------------------------------------------------------------------
253 // Initialize session handling scenario
254 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
256 fFacility
.destroySession(session
);
258 // Verify that no more session components exist
259 assertEquals(0, groups
[1].getChildren().length
);
261 //-------------------------------------------------------------------------
263 //-------------------------------------------------------------------------
264 fFacility
.executeCommand(node
, "disconnect");
265 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
267 //-------------------------------------------------------------------------
269 //-------------------------------------------------------------------------
270 fFacility
.executeCommand(node
, "delete");
271 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);