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
.EnableChannelDialogStub
;
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
.TraceSessionComponent
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
48 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
49 import org
.junit
.After
;
50 import org
.junit
.Before
;
51 import org
.junit
.Test
;
52 import org
.osgi
.framework
.FrameworkUtil
;
55 * The class <code>TraceControlUstProviderTests</code> contains UST provider
56 * handling test cases.
58 public class TraceControlUstProviderTests
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
65 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
70 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
71 private TraceControlTestFacility fFacility
;
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 fProxy
= new TestRemoteSystemProxy(fHost
);
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 * This will fail the test
110 public void testUstProviderTree() 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
);
120 fFacility
.waitForJobs();
122 fFacility
.executeCommand(node
, "connect");
125 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
127 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
130 // Verify that node is connected
131 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
133 // Get provider groups
134 ITraceControlComponent
[] groups
= node
.getChildren();
135 assertNotNull(groups
);
136 assertEquals(2, groups
.length
);
138 // Get kernel provider
139 ITraceControlComponent
[] providers
= groups
[0].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 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
158 // Initialize session handling scenario
159 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
161 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
162 sessionDialogStub
.setSessionPath("/home/user/temp");
163 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
165 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
167 // Verify that session was created
168 assertNotNull(session
);
169 assertEquals("mysession", session
.getName());
170 assertEquals("/home/user/temp", session
.getSessionPath());
171 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
173 // ------------------------------------------------------------------------
174 // Enable Channel on UST global domain
175 // ------------------------------------------------------------------------
176 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
177 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
178 channelDialogStub
.setIsKernel(false);
179 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
180 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
181 channelDialogStub
.getChannelInfo().setReadTimer(100);
182 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
183 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
185 fFacility
.executeCommand(session
, "enableChannelOnSession");
187 // Verify that UST domain was created
188 ITraceControlComponent
[] domains
= session
.getChildren();
189 assertNotNull(domains
);
190 assertEquals(1, domains
.length
);
192 assertEquals("UST global", domains
[0].getName());
194 // Verify that channel was created with correct data
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("mychannel", channel
.getName());
202 assertEquals(2, channel
.getNumberOfSubBuffers());
203 assertEquals("mmap()", channel
.getOutputType().getInName());
204 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
205 assertEquals(false, channel
.isOverwriteMode());
206 assertEquals(100, channel
.getReadTimer());
207 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
208 assertEquals(16384, channel
.getSubBufferSize());
209 assertEquals(200, channel
.getSwitchTimer());
211 // ------------------------------------------------------------------------
212 // Enable event on default channel on created session above
213 // ------------------------------------------------------------------------
214 // Get first UST provider
215 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
216 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
217 assertEquals(9379, ustProvider
.getPid());
220 events
= ustProvider
.getChildren();
221 assertNotNull(events
);
222 assertEquals(2, events
.length
);
224 baseEventInfo0
= (BaseEventComponent
) events
[0];
225 baseEventInfo1
= (BaseEventComponent
) events
[1];
227 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
229 fFacility
.executeCommand(ustSelection
, "assign.event");
231 // verify that events were created under the channel
232 // Note that domain and channel has to be re-read because the tree is re-created
234 domains
= session
.getChildren();
236 // Verify that channel was created with correct data
237 channels
= domains
[0].getChildren();
239 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
240 assertEquals(2, ustEvents
.length
);
242 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
243 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
244 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
245 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
246 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
248 event
= (TraceEventComponent
) ustEvents
[1];
249 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
250 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
251 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
252 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
254 // ------------------------------------------------------------------------
255 // Disable event components
256 // ------------------------------------------------------------------------
257 fFacility
.executeCommand(event
, "disableEvent");
259 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
261 // ------------------------------------------------------------------------
262 // Enable event component
263 // ------------------------------------------------------------------------
264 fFacility
.executeCommand(event
, "enableEvent");
266 // Verify event state
267 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
273 // Initialize session handling scenario
274 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
276 fFacility
.destroySession(session
);
278 // Verify that no more session components exist
279 assertEquals(0, groups
[1].getChildren().length
);
281 //-------------------------------------------------------------------------
283 //-------------------------------------------------------------------------
284 fFacility
.executeCommand(node
, "disconnect");
285 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
287 //-------------------------------------------------------------------------
289 //-------------------------------------------------------------------------
290 fFacility
.executeCommand(node
, "delete");
291 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);