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
.stubs
.dialogs
.CreateSessionDialogStub
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.GetEventInfoDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TargetNodeState
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEnablement
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceSessionState
;
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
.linuxtools
.lttng2
.ui
.tests
.Activator
;
41 import org
.eclipse
.rse
.core
.model
.Host
;
42 import org
.eclipse
.rse
.core
.model
.IHost
;
43 import org
.eclipse
.rse
.internal
.core
.model
.SystemProfile
;
44 import org
.junit
.After
;
45 import org
.junit
.Before
;
48 * The class <code>TraceControlKernelProviderTests</code> contains UST provider handling
51 @SuppressWarnings("nls")
52 public class TraceControlKernelProviderTests
extends TestCase
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
57 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
58 private static final String SCEN_SCENARIO1_TEST
= "Scenario1";
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
63 private TraceControlTestFacility fFacility
;
64 private TestRemoteSystemProxy fProxy
;
65 private String fTestFile
;
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * Returns test setup used when executing test case stand-alone.
73 * @return Test setup class
75 public static Test
suite() {
76 return new ModelImplTestSetup(new TestSuite(TraceControlKernelProviderTests
.class));
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
84 * Perform pre-test initialization.
87 * if the initialization fails for some reason
92 public void setUp() throws Exception
{
93 fFacility
= TraceControlTestFacility
.getInstance();
94 fProxy
= new TestRemoteSystemProxy();
95 URL location
= FileLocator
.find(Activator
.getDefault().getBundle(), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
96 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
97 fTestFile
= testfile
.getAbsolutePath();
101 * Perform post-test clean-up.
104 * if the clean-up fails for some reason
109 public void tearDown() throws Exception
{
110 fFacility
.waitForJobs();
114 * Run the TraceControlComponent.
116 public void testKernelProviderTree() throws Exception
{
119 fProxy
.setTestFile(fTestFile
);
120 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
122 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
124 @SuppressWarnings("restriction")
125 IHost host
= new Host(new SystemProfile("myProfile", true));
126 host
.setHostName("127.0.0.1");
128 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
132 fFacility
.waitForJobs();
134 fFacility
.executeCommand(node
, "connect");
136 while ((i
< 20) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
138 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
141 // Verify that node is connected
142 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
144 // Get provider groups
145 ITraceControlComponent
[] groups
= node
.getChildren();
146 assertNotNull(groups
);
147 assertEquals(2, groups
.length
);
149 // Get kernel provider
150 ITraceControlComponent
[] providers
= groups
[0].getChildren();
151 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
153 // Get kernel provider events and select 2 events
154 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
155 assertNotNull(events
);
156 assertEquals(3, events
.length
);
158 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
159 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
161 // Initialize dialog implementations for command execution
162 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
163 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
164 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
166 // Initialize session handling scenario
167 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
169 // ------------------------------------------------------------------------
171 // ------------------------------------------------------------------------
172 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
174 // Verify that session was created
175 assertNotNull(session
);
176 assertEquals("mysession", session
.getName());
177 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
178 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
180 // ------------------------------------------------------------------------
181 // Enable event on default channel on created session above
182 // ------------------------------------------------------------------------
183 // Initialize scenario
184 fProxy
.setScenario(SCEN_SCENARIO1_TEST
);
186 ITraceControlComponent
[] components
= { baseEventInfo0
, baseEventInfo1
};
188 fFacility
.executeCommand(components
, "assign.event");
190 // Verify that kernel domain was created
191 ITraceControlComponent
[] domains
= session
.getChildren();
192 assertNotNull(domains
);
193 assertEquals(1, domains
.length
);
195 assertEquals("Kernel", domains
[0].getName());
197 // Verify that channel0 was created with default values
198 ITraceControlComponent
[] channels
= domains
[0].getChildren();
199 assertNotNull(channels
);
200 assertEquals(1, channels
.length
);
202 assertTrue(channels
[0] instanceof TraceChannelComponent
);
203 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
204 assertEquals("channel0", channel
.getName());
205 assertEquals(4, channel
.getNumberOfSubBuffers());
206 assertEquals("splice()", channel
.getOutputType());
207 assertEquals(false, channel
.isOverwriteMode());
208 assertEquals(200, channel
.getReadTimer());
209 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
210 assertEquals(262144, channel
.getSubBufferSize());
211 assertEquals(0, channel
.getSwitchTimer());
213 // Verify that event components were created
214 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
215 assertNotNull(channel0Events
);
216 assertEquals(2, channel0Events
.length
);
217 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
218 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
220 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
221 assertEquals("sched_kthread_stop_ret", event
.getName());
222 assertEquals(TraceLogLevel
.TRACE_EMERG
, event
.getLogLevel());
223 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
224 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
226 TraceEventComponent event1
= (TraceEventComponent
) channel0Events
[1];
227 assertEquals("sched_kthread_stop", event1
.getName());
228 assertEquals(TraceLogLevel
.TRACE_EMERG
, event1
.getLogLevel());
229 assertEquals(TraceEventType
.TRACEPOINT
, event1
.getEventType());
230 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
232 // ------------------------------------------------------------------------
233 // Disable event components
234 // ------------------------------------------------------------------------
235 ITraceControlComponent
[] selection
= { event
, event1
};
236 fFacility
.executeCommand(selection
, "disableEvent");
238 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
239 assertEquals(TraceEnablement
.DISABLED
, event1
.getState());
241 // ------------------------------------------------------------------------
242 // Enable event component
243 // ------------------------------------------------------------------------
244 fFacility
.executeCommand(event1
, "enableEvent");
246 // Verify event state
247 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
249 // ------------------------------------------------------------------------
251 // ------------------------------------------------------------------------
252 // Initialize session handling scenario
253 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
255 fFacility
.destroySession(session
);
257 // Verify that no more session components exist
258 assertEquals(0, groups
[1].getChildren().length
);
260 //-------------------------------------------------------------------------
262 //-------------------------------------------------------------------------
263 fFacility
.executeCommand(node
, "disconnect");
264 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
266 //-------------------------------------------------------------------------
268 //-------------------------------------------------------------------------
269 fFacility
.executeCommand(node
, "delete");
270 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);