1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertTrue
;
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
;
54 * The class <code>TraceControlKernelProviderTests</code> contains UST provider
55 * handling test cases.
57 public class TraceControlKernelProviderTests
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
64 private static final String SCEN_SCENARIO1_TEST
= "Scenario1";
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 private TraceControlTestFacility fFacility
;
71 private TestRemoteSystemProxy fProxy
;
72 private String fTestFile
;
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * Perform pre-test initialization.
82 * if the initialization fails for some reason
85 public void setUp() throws Exception
{
86 fFacility
= TraceControlTestFacility
.getInstance();
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();
95 * Perform post-test clean-up.
98 public void tearDown() {
99 fFacility
.waitForJobs();
104 * Run the TraceControlComponent.
107 * Would fail the test
110 public void testKernelProviderTree() throws Exception
{
112 fProxy
.setTestFile(fTestFile
);
113 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
115 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
117 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
118 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
119 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
121 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
125 fFacility
.waitForJobs();
127 fFacility
.executeCommand(node
, "connect");
129 while ((i
< 20) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
131 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
134 // Verify that node is connected
135 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
137 // Get provider and session group
138 ITraceControlComponent
[] groups
= node
.getChildren();
139 assertNotNull(groups
);
140 assertEquals(2, groups
.length
);
142 // Check for kernel provider
143 TraceProviderGroup providerGroup
= (TraceProviderGroup
) groups
[0];
144 assertTrue(providerGroup
.hasKernelProvider());
146 // Get kernel provider
147 ITraceControlComponent
[] providers
= providerGroup
.getChildren();
148 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
150 // Get kernel provider events and select 2 events
151 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
152 assertNotNull(events
);
153 assertEquals(3, events
.length
);
155 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
156 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
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());
163 // Initialize session handling scenario
164 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
169 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
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());
177 // ------------------------------------------------------------------------
178 // Enable event on default channel on created session above
179 // ------------------------------------------------------------------------
180 // Initialize scenario
181 fProxy
.setScenario(SCEN_SCENARIO1_TEST
);
183 ITraceControlComponent
[] components
= { baseEventInfo0
, baseEventInfo1
};
185 fFacility
.executeCommand(components
, "assign.event");
187 // Verify that kernel domain was created
188 ITraceControlComponent
[] domains
= session
.getChildren();
189 assertNotNull(domains
);
190 assertEquals(1, domains
.length
);
192 assertEquals("Kernel", domains
[0].getName());
194 // Verify that channel0 was created with default values
195 ITraceControlComponent
[] channels
= domains
[0].getChildren();
196 assertNotNull(channels
);
197 assertEquals(1, channels
.length
);
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());
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
);
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());
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());
230 // ------------------------------------------------------------------------
231 // Disable event components
232 // ------------------------------------------------------------------------
233 ITraceControlComponent
[] selection
= { event
, event1
};
234 fFacility
.executeCommand(selection
, "disableEvent");
236 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
237 assertEquals(TraceEnablement
.DISABLED
, event1
.getState());
239 // ------------------------------------------------------------------------
240 // Enable event component
241 // ------------------------------------------------------------------------
242 fFacility
.executeCommand(event1
, "enableEvent");
244 // Verify event state
245 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
247 // ------------------------------------------------------------------------
249 // ------------------------------------------------------------------------
250 // Initialize session handling scenario
251 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
253 fFacility
.destroySession(session
);
255 // Verify that no more session components exist
256 assertEquals(0, groups
[1].getChildren().length
);
258 //-------------------------------------------------------------------------
260 //-------------------------------------------------------------------------
261 fFacility
.executeCommand(node
, "disconnect");
262 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
264 //-------------------------------------------------------------------------
266 //-------------------------------------------------------------------------
267 fFacility
.executeCommand(node
, "delete");
268 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);