1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 **********************************************************************/
15 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.tests
.model
.component
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
24 import org
.eclipse
.core
.runtime
.FileLocator
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.jdt
.annotation
.NonNull
;
27 import org
.eclipse
.remote
.core
.IRemoteConnection
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceChannelOutputType
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceEventComponent
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
47 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
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 IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
72 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
73 private String fTestFile
;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * Perform pre-test initialization.
83 * if the initialization fails for some reason
86 public void setUp() throws Exception
{
87 fFacility
= TraceControlTestFacility
.getInstance();
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() {
103 * Run the TraceControlComponent.
106 * Would fail the test
109 public void testKernelProviderTree() throws Exception
{
111 fProxy
.setTestFile(fTestFile
);
112 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
114 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
116 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
120 fFacility
.waitForJobs();
122 fFacility
.executeCommand(node
, "connect");
124 while ((i
< 20) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
126 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
129 // Verify that node is connected
130 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
132 // Get provider and session group
133 ITraceControlComponent
[] groups
= node
.getChildren();
134 assertNotNull(groups
);
135 assertEquals(2, groups
.length
);
137 // Check for kernel provider
138 TraceProviderGroup providerGroup
= (TraceProviderGroup
) groups
[0];
139 assertTrue(providerGroup
.hasKernelProvider());
141 // Get kernel provider
142 ITraceControlComponent
[] providers
= providerGroup
.getChildren();
143 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
145 // Get kernel provider events and select 2 events
146 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
147 assertNotNull(events
);
148 assertEquals(3, events
.length
);
150 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
151 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
153 // Initialize dialog implementations for command execution
154 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
155 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
156 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
158 // Initialize session handling scenario
159 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
161 // ------------------------------------------------------------------------
163 // ------------------------------------------------------------------------
164 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
166 // Verify that session was created
167 assertNotNull(session
);
168 assertEquals("mysession", session
.getName());
169 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
170 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
172 // ------------------------------------------------------------------------
173 // Enable event on default channel on created session above
174 // ------------------------------------------------------------------------
175 // Initialize scenario
176 fProxy
.setScenario(SCEN_SCENARIO1_TEST
);
178 ITraceControlComponent
[] components
= { baseEventInfo0
, baseEventInfo1
};
180 fFacility
.executeCommand(components
, "assign.event");
182 // Verify that kernel domain was created
183 ITraceControlComponent
[] domains
= session
.getChildren();
184 assertNotNull(domains
);
185 assertEquals(1, domains
.length
);
187 assertEquals("Kernel", domains
[0].getName());
189 // Verify that channel0 was created with default values
190 ITraceControlComponent
[] channels
= domains
[0].getChildren();
191 assertNotNull(channels
);
192 assertEquals(1, channels
.length
);
194 assertTrue(channels
[0] instanceof TraceChannelComponent
);
195 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
196 assertEquals("channel0", channel
.getName());
197 assertEquals(4, channel
.getNumberOfSubBuffers());
198 assertEquals("splice()", channel
.getOutputType().getInName());
199 assertEquals(TraceChannelOutputType
.SPLICE
, channel
.getOutputType());
200 assertEquals(false, channel
.isOverwriteMode());
201 assertEquals(200, channel
.getReadTimer());
202 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
203 assertEquals(262144, channel
.getSubBufferSize());
204 assertEquals(0, channel
.getSwitchTimer());
206 // Verify that event components were created
207 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
208 assertNotNull(channel0Events
);
209 assertEquals(2, channel0Events
.length
);
210 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
211 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
213 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
214 assertEquals("sched_kthread_stop_ret", event
.getName());
215 assertEquals(TraceLogLevel
.TRACE_EMERG
, event
.getLogLevel());
216 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
217 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
219 TraceEventComponent event1
= (TraceEventComponent
) channel0Events
[1];
220 assertEquals("sched_kthread_stop", event1
.getName());
221 assertEquals(TraceLogLevel
.TRACE_EMERG
, event1
.getLogLevel());
222 assertEquals(TraceEventType
.TRACEPOINT
, event1
.getEventType());
223 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
225 // ------------------------------------------------------------------------
226 // Disable event components
227 // ------------------------------------------------------------------------
228 ITraceControlComponent
[] selection
= { event
, event1
};
229 fFacility
.executeCommand(selection
, "disableEvent");
231 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
232 assertEquals(TraceEnablement
.DISABLED
, event1
.getState());
234 // ------------------------------------------------------------------------
235 // Enable event component
236 // ------------------------------------------------------------------------
237 fFacility
.executeCommand(event1
, "enableEvent");
239 // Verify event state
240 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
245 // Initialize session handling scenario
246 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
248 fFacility
.destroySession(session
);
250 // Verify that no more session components exist
251 assertEquals(0, groups
[1].getChildren().length
);
253 //-------------------------------------------------------------------------
255 //-------------------------------------------------------------------------
256 fFacility
.executeCommand(node
, "disconnect");
257 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
259 //-------------------------------------------------------------------------
261 //-------------------------------------------------------------------------
262 fFacility
.executeCommand(node
, "delete");
263 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);