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
.TraceDomainType
;
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
.EnableChannelDialogStub
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.dialogs
.GetEventInfoDialogStub
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceEventComponent
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
49 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
50 import org
.junit
.After
;
51 import org
.junit
.Before
;
52 import org
.junit
.Test
;
53 import org
.osgi
.framework
.FrameworkUtil
;
56 * The class {@link TraceControlUstProviderTest} contains UST provider
57 * handling test cases.
59 public class TraceControlUstProviderTest
{
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
66 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
71 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
72 private TraceControlTestFacility fFacility
;
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 fProxy
= new TestRemoteSystemProxy(fHost
);
91 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
92 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
93 fTestFile
= testfile
.getAbsolutePath();
97 * Perform post-test clean-up.
100 public void tearDown() {
105 * Run the TraceControlComponent.
108 * This will fail the test
111 public void testUstProviderTree() throws Exception
{
113 fProxy
.setTestFile(fTestFile
);
114 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
116 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
118 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
121 fFacility
.waitForJobs();
123 fFacility
.executeCommand(node
, "connect");
126 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
128 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
131 // Verify that node is connected
132 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
134 // Get provider groups
135 ITraceControlComponent
[] groups
= node
.getChildren();
136 assertNotNull(groups
);
137 assertEquals(2, groups
.length
);
139 // Get kernel provider
140 ITraceControlComponent
[] providers
= groups
[0].getChildren();
141 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
143 // Get kernel provider events and select 2 events
144 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
145 assertNotNull(events
);
146 assertEquals(3, events
.length
);
148 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
149 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
151 // Initialize dialog implementations for command execution
152 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
153 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
154 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
159 // Initialize session handling scenario
160 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
162 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
163 sessionDialogStub
.setSessionPath("/home/user/temp");
164 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
166 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
168 // Verify that session was created
169 assertNotNull(session
);
170 assertEquals("mysession", session
.getName());
171 assertEquals("/home/user/temp", session
.getSessionPath());
172 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
174 // ------------------------------------------------------------------------
175 // Enable Channel on UST global domain
176 // ------------------------------------------------------------------------
177 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
178 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
179 channelDialogStub
.setDomain(TraceDomainType
.UST
);
180 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
181 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
182 channelDialogStub
.getChannelInfo().setReadTimer(100);
183 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
184 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
186 fFacility
.executeCommand(session
, "enableChannelOnSession");
188 // Verify that UST domain was created
189 ITraceControlComponent
[] domains
= session
.getChildren();
190 assertNotNull(domains
);
191 assertEquals(1, domains
.length
);
193 assertEquals("UST global", domains
[0].getName());
195 // Verify that channel was created with correct data
196 ITraceControlComponent
[]channels
= domains
[0].getChildren();
197 assertNotNull(channels
);
198 assertEquals(1, channels
.length
);
200 assertTrue(channels
[0] instanceof TraceChannelComponent
);
201 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
202 assertEquals("mychannel", channel
.getName());
203 assertEquals(2, channel
.getNumberOfSubBuffers());
204 assertEquals("mmap()", channel
.getOutputType().getInName());
205 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
206 assertEquals(false, channel
.isOverwriteMode());
207 assertEquals(100, channel
.getReadTimer());
208 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
209 assertEquals(16384, channel
.getSubBufferSize());
210 assertEquals(200, channel
.getSwitchTimer());
212 // ------------------------------------------------------------------------
213 // Enable event on default channel on created session above
214 // ------------------------------------------------------------------------
215 // Get first UST provider
216 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
217 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
218 assertEquals(9379, ustProvider
.getPid());
221 events
= ustProvider
.getChildren();
222 assertNotNull(events
);
223 assertEquals(2, events
.length
);
225 baseEventInfo0
= (BaseEventComponent
) events
[0];
226 baseEventInfo1
= (BaseEventComponent
) events
[1];
228 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
230 fFacility
.executeCommand(ustSelection
, "assign.event");
232 // verify that events were created under the channel
233 // Note that domain and channel has to be re-read because the tree is re-created
235 domains
= session
.getChildren();
237 // Verify that channel was created with correct data
238 channels
= domains
[0].getChildren();
240 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
241 assertEquals(2, ustEvents
.length
);
243 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
244 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
245 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
246 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
247 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
249 event
= (TraceEventComponent
) ustEvents
[1];
250 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
251 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
252 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
253 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
255 // ------------------------------------------------------------------------
256 // Disable event components
257 // ------------------------------------------------------------------------
258 fFacility
.executeCommand(event
, "disableEvent");
260 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
262 // ------------------------------------------------------------------------
263 // Enable event component
264 // ------------------------------------------------------------------------
265 fFacility
.executeCommand(event
, "enableEvent");
267 // Verify event state
268 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
270 // ------------------------------------------------------------------------
272 // ------------------------------------------------------------------------
274 // Initialize session handling scenario
275 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
277 fFacility
.destroySession(session
);
279 // Verify that no more session components exist
280 assertEquals(0, groups
[1].getChildren().length
);
282 //-------------------------------------------------------------------------
284 //-------------------------------------------------------------------------
285 fFacility
.executeCommand(node
, "disconnect");
286 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
288 //-------------------------------------------------------------------------
290 //-------------------------------------------------------------------------
291 fFacility
.executeCommand(node
, "delete");
292 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);