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
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
49 import org
.junit
.After
;
50 import org
.junit
.Before
;
51 import org
.junit
.Test
;
52 import org
.osgi
.framework
.FrameworkUtil
;
55 * The class {@link TraceControlKernelProviderTest} contains UST provider
56 * handling test cases.
58 public class TraceControlKernelProviderTest
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
65 private static final String SCEN_SCENARIO1_TEST
= "Scenario1";
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 private TraceControlTestFacility fFacility
;
72 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
73 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
74 private String fTestFile
;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * Perform pre-test initialization.
84 * if the initialization fails for some reason
87 public void setUp() throws Exception
{
88 fFacility
= TraceControlTestFacility
.getInstance();
90 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
91 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
92 fTestFile
= testfile
.getAbsolutePath();
96 * Perform post-test clean-up.
99 public void tearDown() {
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 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
121 fFacility
.waitForJobs();
123 fFacility
.executeCommand(node
, "connect");
124 WaitUtils
.waitUntil(new TargetNodeConnectedCondition(node
));
126 // Verify that node is connected
127 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
129 // Get provider and session group
130 ITraceControlComponent
[] groups
= node
.getChildren();
131 assertNotNull(groups
);
132 assertEquals(2, groups
.length
);
134 // Check for kernel provider
135 TraceProviderGroup providerGroup
= (TraceProviderGroup
) groups
[0];
136 assertTrue(providerGroup
.hasKernelProvider());
138 // Get kernel provider
139 ITraceControlComponent
[] providers
= providerGroup
.getChildren();
140 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
142 // Get kernel provider events and select 2 events
143 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
144 assertNotNull(events
);
145 assertEquals(3, events
.length
);
147 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
148 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
150 // Initialize dialog implementations for command execution
151 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
152 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
153 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
155 // Initialize session handling scenario
156 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
161 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
163 // Verify that session was created
164 assertNotNull(session
);
165 assertEquals("mysession", session
.getName());
166 assertEquals("/home/user/lttng-traces/mysession-20120314-132824", session
.getSessionPath());
167 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
169 // ------------------------------------------------------------------------
170 // Enable event on default channel on created session above
171 // ------------------------------------------------------------------------
172 // Initialize scenario
173 fProxy
.setScenario(SCEN_SCENARIO1_TEST
);
175 ITraceControlComponent
[] components
= { baseEventInfo0
, baseEventInfo1
};
177 fFacility
.executeCommand(components
, "assign.event");
179 // Verify that kernel domain was created
180 ITraceControlComponent
[] domains
= session
.getChildren();
181 assertNotNull(domains
);
182 assertEquals(1, domains
.length
);
184 assertEquals("Kernel", domains
[0].getName());
186 // Verify that channel0 was created with default values
187 ITraceControlComponent
[] channels
= domains
[0].getChildren();
188 assertNotNull(channels
);
189 assertEquals(1, channels
.length
);
191 assertTrue(channels
[0] instanceof TraceChannelComponent
);
192 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
193 assertEquals("channel0", channel
.getName());
194 assertEquals(4, channel
.getNumberOfSubBuffers());
195 assertEquals("splice()", channel
.getOutputType().getInName());
196 assertEquals(TraceChannelOutputType
.SPLICE
, channel
.getOutputType());
197 assertEquals(false, channel
.isOverwriteMode());
198 assertEquals(200, channel
.getReadTimer());
199 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
200 assertEquals(262144, channel
.getSubBufferSize());
201 assertEquals(0, channel
.getSwitchTimer());
203 // Verify that event components were created
204 ITraceControlComponent
[] channel0Events
= channel
.getChildren();
205 assertNotNull(channel0Events
);
206 assertEquals(2, channel0Events
.length
);
207 assertTrue(channel0Events
[0] instanceof TraceEventComponent
);
208 assertTrue(channel0Events
[1] instanceof TraceEventComponent
);
210 TraceEventComponent event
= (TraceEventComponent
) channel0Events
[0];
211 assertEquals("sched_kthread_stop_ret", event
.getName());
212 assertEquals(TraceLogLevel
.TRACE_EMERG
, event
.getLogLevel());
213 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
214 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
216 TraceEventComponent event1
= (TraceEventComponent
) channel0Events
[1];
217 assertEquals("sched_kthread_stop", event1
.getName());
218 assertEquals(TraceLogLevel
.TRACE_EMERG
, event1
.getLogLevel());
219 assertEquals(TraceEventType
.TRACEPOINT
, event1
.getEventType());
220 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
222 // ------------------------------------------------------------------------
223 // Disable event components
224 // ------------------------------------------------------------------------
225 ITraceControlComponent
[] selection
= { event
, event1
};
226 fFacility
.executeCommand(selection
, "disableEvent");
228 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
229 assertEquals(TraceEnablement
.DISABLED
, event1
.getState());
231 // ------------------------------------------------------------------------
232 // Enable event component
233 // ------------------------------------------------------------------------
234 fFacility
.executeCommand(event1
, "enableEvent");
236 // Verify event state
237 assertEquals(TraceEnablement
.ENABLED
, event1
.getState());
239 // ------------------------------------------------------------------------
241 // ------------------------------------------------------------------------
242 // Initialize session handling scenario
243 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
245 fFacility
.destroySession(session
);
247 // Verify that no more session components exist
248 assertEquals(0, groups
[1].getChildren().length
);
250 //-------------------------------------------------------------------------
252 //-------------------------------------------------------------------------
253 fFacility
.executeCommand(node
, "disconnect");
254 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
256 //-------------------------------------------------------------------------
258 //-------------------------------------------------------------------------
259 fFacility
.executeCommand(node
, "delete");
260 assertEquals(0, fFacility
.getControlView().getTraceControlRoot().getChildren().length
);