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
.TraceDomainType
;
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
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
51 import org
.junit
.After
;
52 import org
.junit
.Before
;
53 import org
.junit
.Test
;
54 import org
.osgi
.framework
.FrameworkUtil
;
57 * The class {@link TraceControlUstProviderTest} contains UST provider
58 * handling test cases.
60 public class TraceControlUstProviderTest
{
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 private static final String TEST_STREAM
= "CreateTreeTest.cfg";
67 private static final String SCEN_SCENARIO2_TEST
= "Scenario2";
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
72 private IRemoteConnection fHost
= TmfRemoteConnectionFactory
.getLocalConnection();
73 private TraceControlTestFacility fFacility
;
74 private @NonNull TestRemoteSystemProxy fProxy
= new TestRemoteSystemProxy(fHost
);
75 private String fTestFile
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * Perform pre-test initialization.
85 * if the initialization fails for some reason
88 public void setUp() throws Exception
{
89 fFacility
= TraceControlTestFacility
.getInstance();
91 fProxy
= new TestRemoteSystemProxy(fHost
);
92 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
93 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
94 fTestFile
= testfile
.getAbsolutePath();
98 * Perform post-test clean-up.
101 public void tearDown() {
106 * Run the TraceControlComponent.
109 * This will fail the test
112 public void testUstProviderTree() throws Exception
{
114 fProxy
.setTestFile(fTestFile
);
115 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
117 ITraceControlComponent root
= fFacility
.getControlView().getTraceControlRoot();
119 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, fProxy
);
122 fFacility
.waitForJobs();
124 fFacility
.executeCommand(node
, "connect");
125 WaitUtils
.waitUntil(new TargetNodeConnectedCondition(node
));
127 // Verify that node is connected
128 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
130 // Get provider groups
131 ITraceControlComponent
[] groups
= node
.getChildren();
132 assertNotNull(groups
);
133 assertEquals(2, groups
.length
);
135 // Get kernel provider
136 ITraceControlComponent
[] providers
= groups
[0].getChildren();
137 KernelProviderComponent kernelProvider
= (KernelProviderComponent
) providers
[0];
139 // Get kernel provider events and select 2 events
140 ITraceControlComponent
[] events
= kernelProvider
.getChildren();
141 assertNotNull(events
);
142 assertEquals(3, events
.length
);
144 BaseEventComponent baseEventInfo0
= (BaseEventComponent
) events
[0];
145 BaseEventComponent baseEventInfo1
= (BaseEventComponent
) events
[1];
147 // Initialize dialog implementations for command execution
148 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
149 TraceControlDialogFactory
.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
150 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
155 // Initialize session handling scenario
156 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
);
158 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
159 sessionDialogStub
.setSessionPath("/home/user/temp");
160 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
162 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
164 // Verify that session was created
165 assertNotNull(session
);
166 assertEquals("mysession", session
.getName());
167 assertEquals("/home/user/temp", session
.getSessionPath());
168 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
170 // ------------------------------------------------------------------------
171 // Enable Channel on UST global domain
172 // ------------------------------------------------------------------------
173 fProxy
.setScenario(SCEN_SCENARIO2_TEST
);
174 EnableChannelDialogStub channelDialogStub
= new EnableChannelDialogStub();
175 channelDialogStub
.setDomain(TraceDomainType
.UST
);
176 channelDialogStub
.getChannelInfo().setOverwriteMode(false);
177 channelDialogStub
.getChannelInfo().setSwitchTimer(200);
178 channelDialogStub
.getChannelInfo().setReadTimer(100);
179 channelDialogStub
.getChannelInfo().setNumberOfSubBuffers(2);
180 TraceControlDialogFactory
.getInstance().setEnableChannelDialog(channelDialogStub
);
182 fFacility
.executeCommand(session
, "enableChannelOnSession");
184 // Verify that UST domain was created
185 ITraceControlComponent
[] domains
= session
.getChildren();
186 assertNotNull(domains
);
187 assertEquals(1, domains
.length
);
189 assertEquals("UST global", domains
[0].getName());
191 // Verify that channel was created with correct data
192 ITraceControlComponent
[]channels
= domains
[0].getChildren();
193 assertNotNull(channels
);
194 assertEquals(1, channels
.length
);
196 assertTrue(channels
[0] instanceof TraceChannelComponent
);
197 TraceChannelComponent channel
= (TraceChannelComponent
) channels
[0];
198 assertEquals("mychannel", channel
.getName());
199 assertEquals(2, channel
.getNumberOfSubBuffers());
200 assertEquals("mmap()", channel
.getOutputType().getInName());
201 assertEquals(TraceChannelOutputType
.MMAP
, channel
.getOutputType());
202 assertEquals(false, channel
.isOverwriteMode());
203 assertEquals(100, channel
.getReadTimer());
204 assertEquals(TraceEnablement
.ENABLED
, channel
.getState());
205 assertEquals(16384, channel
.getSubBufferSize());
206 assertEquals(200, channel
.getSwitchTimer());
208 // ------------------------------------------------------------------------
209 // Enable event on default channel on created session above
210 // ------------------------------------------------------------------------
211 // Get first UST provider
212 UstProviderComponent ustProvider
= (UstProviderComponent
) providers
[1];
213 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider
.getName());
214 assertEquals(9379, ustProvider
.getPid());
217 events
= ustProvider
.getChildren();
218 assertNotNull(events
);
219 assertEquals(2, events
.length
);
221 baseEventInfo0
= (BaseEventComponent
) events
[0];
222 baseEventInfo1
= (BaseEventComponent
) events
[1];
224 ITraceControlComponent
[] ustSelection
= { baseEventInfo0
, baseEventInfo1
};
226 fFacility
.executeCommand(ustSelection
, "assign.event");
228 // verify that events were created under the channel
229 // Note that domain and channel has to be re-read because the tree is re-created
231 domains
= session
.getChildren();
233 // Verify that channel was created with correct data
234 channels
= domains
[0].getChildren();
236 ITraceControlComponent
[] ustEvents
= channels
[0].getChildren();
237 assertEquals(2, ustEvents
.length
);
239 TraceEventComponent event
= (TraceEventComponent
) ustEvents
[0];
240 assertEquals("ust_tests_hello:tptest_sighandler", event
.getName());
241 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
242 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
243 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
245 event
= (TraceEventComponent
) ustEvents
[1];
246 assertEquals("ust_tests_hello:tptest", ustEvents
[1].getName());
247 assertEquals(TraceLogLevel
.LEVEL_UNKNOWN
, event
.getLogLevel());
248 assertEquals(TraceEventType
.TRACEPOINT
, event
.getEventType());
249 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
251 // ------------------------------------------------------------------------
252 // Disable event components
253 // ------------------------------------------------------------------------
254 fFacility
.executeCommand(event
, "disableEvent");
256 assertEquals(TraceEnablement
.DISABLED
, event
.getState());
258 // ------------------------------------------------------------------------
259 // Enable event component
260 // ------------------------------------------------------------------------
261 fFacility
.executeCommand(event
, "enableEvent");
263 // Verify event state
264 assertEquals(TraceEnablement
.ENABLED
, event
.getState());
266 // ------------------------------------------------------------------------
268 // ------------------------------------------------------------------------
270 // Initialize session handling scenario
271 fProxy
.setScenario(TraceControlTestFacility
.SCEN_SCENARIO_SESSION_HANDLING
);
273 fFacility
.destroySession(session
);
275 // Verify that no more session components exist
276 assertEquals(0, groups
[1].getChildren().length
);
278 //-------------------------------------------------------------------------
280 //-------------------------------------------------------------------------
281 fFacility
.executeCommand(node
, "disconnect");
282 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
284 //-------------------------------------------------------------------------
286 //-------------------------------------------------------------------------
287 fFacility
.executeCommand(node
, "delete");
288 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);