1
/**********************************************************************
2
* Copyright (c) 2012 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
**********************************************************************/
12
package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
17
import junit.framework.Test;
18
import junit.framework.TestCase;
19
import junit.framework.TestSuite;
21
import org.eclipse.core.runtime.FileLocator;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
24
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
25
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType;
26
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
27
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
28
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
29
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
30
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.EnableChannelDialogStub;
31
import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
32
import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
33
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
34
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
35
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventComponent;
36
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.KernelProviderComponent;
37
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
38
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
39
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
40
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
41
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent;
42
import org.eclipse.rse.core.RSECorePlugin;
43
import org.eclipse.rse.core.model.IHost;
44
import org.eclipse.rse.core.model.ISystemProfile;
45
import org.eclipse.rse.core.model.ISystemRegistry;
46
import org.junit.After;
47
import org.junit.Before;
48
import org.osgi.framework.FrameworkUtil;
51
* The class <code>TraceControlUstProviderTests</code> contains UST provider handling
54
@SuppressWarnings("nls")
55
public class TraceControlUstProviderTests extends TestCase {
57
// ------------------------------------------------------------------------
59
// ------------------------------------------------------------------------
60
private static final String TEST_STREAM = "CreateTreeTest.cfg";
61
private static final String SCEN_SCENARIO2_TEST = "Scenario2";
63
// ------------------------------------------------------------------------
65
// ------------------------------------------------------------------------
66
private TraceControlTestFacility fFacility;
67
private TestRemoteSystemProxy fProxy;
68
private String fTestFile;
70
// ------------------------------------------------------------------------
72
// ------------------------------------------------------------------------
75
* Returns test setup used when executing test case stand-alone.
76
* @return Test setup class
78
public static Test suite() {
79
return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests.class));
82
// ------------------------------------------------------------------------
84
// ------------------------------------------------------------------------
87
* Perform pre-test initialization.
90
* if the initialization fails for some reason
95
public void setUp() throws Exception {
96
fFacility = TraceControlTestFacility.getInstance();
97
fProxy = new TestRemoteSystemProxy();
98
URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
99
File testfile = new File(FileLocator.toFileURL(location).toURI());
100
fTestFile = testfile.getAbsolutePath();
104
* Perform post-test clean-up.
107
* if the clean-up fails for some reason
112
public void tearDown() throws Exception {
113
fFacility.waitForJobs();
117
* Run the TraceControlComponent.
119
public void testUstProviderTree() throws Exception {
121
fProxy.setTestFile(fTestFile);
122
fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
124
ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
126
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
127
ISystemProfile profile = registry.createSystemProfile("myProfile", true);
128
IHost host = registry.createLocalHost(profile, "myProfile", "user");
130
TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
133
fFacility.waitForJobs();
135
fFacility.executeCommand(node, "connect");
138
while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
140
fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
143
// Verify that node is connected
144
assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
146
// Get provider groups
147
ITraceControlComponent[] groups = node.getChildren();
148
assertNotNull(groups);
149
assertEquals(2, groups.length);
151
// Get kernel provider
152
ITraceControlComponent[] providers = groups[0].getChildren();
153
KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
155
// Get kernel provider events and select 2 events
156
ITraceControlComponent[] events = kernelProvider.getChildren();
157
assertNotNull(events);
158
assertEquals(3, events.length);
160
BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
161
BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
163
// Initialize dialog implementations for command execution
164
TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
165
TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
166
TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
168
// ------------------------------------------------------------------------
170
// ------------------------------------------------------------------------
171
// Initialize session handling scenario
172
fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH);
174
CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
175
sessionDialogStub.setSessionPath("/home/user/temp");
176
TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
178
TraceSessionComponent session = fFacility.createSession(groups[1]);
180
// Verify that session was created
181
assertNotNull(session);
182
assertEquals("mysession", session.getName());
183
assertEquals("/home/user/temp", session.getSessionPath());
184
assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
186
// ------------------------------------------------------------------------
187
// Enable Channel on UST global domain
188
// ------------------------------------------------------------------------
189
fProxy.setScenario(SCEN_SCENARIO2_TEST);
190
EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub();
191
channelDialogStub.setIsKernel(false);
192
channelDialogStub.getChannelInfo().setOverwriteMode(false);
193
channelDialogStub.getChannelInfo().setSwitchTimer(200);
194
channelDialogStub.getChannelInfo().setReadTimer(100);
195
channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2);
196
TraceControlDialogFactory.getInstance().setEnableChannelDialog(channelDialogStub);
198
fFacility.executeCommand(session, "enableChannelOnSession");
200
// Verify that UST domain was created
201
ITraceControlComponent[] domains = session.getChildren();
202
assertNotNull(domains);
203
assertEquals(1, domains.length);
205
assertEquals("UST global", domains[0].getName());
207
// Verify that channel was created with correct data
208
ITraceControlComponent[]channels = domains[0].getChildren();
209
assertNotNull(channels);
210
assertEquals(1, channels.length);
212
assertTrue(channels[0] instanceof TraceChannelComponent);
213
TraceChannelComponent channel = (TraceChannelComponent) channels[0];
214
assertEquals("mychannel", channel.getName());
215
assertEquals(2, channel.getNumberOfSubBuffers());
216
assertEquals("mmap()", channel.getOutputType());
217
assertEquals(false, channel.isOverwriteMode());
218
assertEquals(100, channel.getReadTimer());
219
assertEquals(TraceEnablement.ENABLED, channel.getState());
220
assertEquals(16384, channel.getSubBufferSize());
221
assertEquals(200, channel.getSwitchTimer());
223
// ------------------------------------------------------------------------
224
// Enable event on default channel on created session above
225
// ------------------------------------------------------------------------
226
// Get first UST provider
227
UstProviderComponent ustProvider = (UstProviderComponent) providers[1];
228
assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello [PID=9379]", ustProvider.getName());
229
assertEquals(9379, ustProvider.getPid());
232
events = ustProvider.getChildren();
233
assertNotNull(events);
234
assertEquals(2, events.length);
236
baseEventInfo0 = (BaseEventComponent) events[0];
237
baseEventInfo1 = (BaseEventComponent) events[1];
239
ITraceControlComponent[] ustSelection = { baseEventInfo0, baseEventInfo1 };
241
fFacility.executeCommand(ustSelection, "assign.event");
243
// verify that events were created under the channel
244
// Note that domain and channel has to be re-read because the tree is re-created
246
domains = session.getChildren();
248
// Verify that channel was created with correct data
249
channels = domains[0].getChildren();
251
ITraceControlComponent[] ustEvents = channels[0].getChildren();
252
assertEquals(2, ustEvents.length);
254
TraceEventComponent event = (TraceEventComponent) ustEvents[0];
255
assertEquals("ust_tests_hello:tptest_sighandler", event.getName());
256
assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
257
assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
258
assertEquals(TraceEnablement.ENABLED, event.getState());
260
event = (TraceEventComponent) ustEvents[1];
261
assertEquals("ust_tests_hello:tptest", ustEvents[1].getName());
262
assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
263
assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
264
assertEquals(TraceEnablement.ENABLED, event.getState());
266
// ------------------------------------------------------------------------
267
// Disable event components
268
// ------------------------------------------------------------------------
269
fFacility.executeCommand(event, "disableEvent");
271
assertEquals(TraceEnablement.DISABLED, event.getState());
273
// ------------------------------------------------------------------------
274
// Enable event component
275
// ------------------------------------------------------------------------
276
fFacility.executeCommand(event, "enableEvent");
278
// Verify event state
279
assertEquals(TraceEnablement.ENABLED, event.getState());
281
// ------------------------------------------------------------------------
283
// ------------------------------------------------------------------------
285
// Initialize session handling scenario
286
fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
288
fFacility.destroySession(session);
290
// Verify that no more session components exist
291
assertEquals(0, groups[1].getChildren().length);
293
//-------------------------------------------------------------------------
295
//-------------------------------------------------------------------------
296
fFacility.executeCommand(node, "disconnect");
297
assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
299
//-------------------------------------------------------------------------
301
//-------------------------------------------------------------------------
302
fFacility.executeCommand(node, "delete");
303
assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
b'\\ No newline at end of file'