Add some more model test cases for LTTng 2.0 control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / component / TraceControlUstProviderTests.java
1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
13
14 import java.io.File;
15 import java.net.URL;
16
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import org.eclipse.core.runtime.FileLocator;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateChannelDialogStub;
24 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
25 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
26 import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.GetEventInfoDialogStub;
27 import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
30 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
31 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement;
32 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType;
33 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel;
34 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
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.linuxtools.lttng2.ui.tests.Activator;
43 import org.eclipse.rse.core.model.Host;
44 import org.eclipse.rse.core.model.IHost;
45 import org.eclipse.rse.internal.core.model.SystemProfile;
46 import org.junit.After;
47 import org.junit.Before;
48
49 /**
50 * The class <code>TraceControlUstProviderTests</code> contains UST provider handling
51 * test cases.
52 */
53 @SuppressWarnings("nls")
54 public class TraceControlUstProviderTests extends TestCase {
55
56 // ------------------------------------------------------------------------
57 // Constants
58 // ------------------------------------------------------------------------
59 private static final String TEST_STREAM = "CreateTreeTest.cfg";
60 private static final String SCEN_SCENARIO2_TEST = "Scenario2";
61
62 // ------------------------------------------------------------------------
63 // Test data
64 // ------------------------------------------------------------------------
65 private TraceControlTestFacility fFacility;
66 private TestRemoteSystemProxy fProxy;
67 private String fTestFile;
68
69 // ------------------------------------------------------------------------
70 // Static methods
71 // ------------------------------------------------------------------------
72
73 /**
74 * Returns test setup used when executing test case stand-alone.
75 * @return Test setup class
76 */
77 public static Test suite() {
78 return new ModelImplTestSetup(new TestSuite(TraceControlUstProviderTests.class));
79 }
80
81 // ------------------------------------------------------------------------
82 // Housekeeping
83 // ------------------------------------------------------------------------
84
85 /**
86 * Perform pre-test initialization.
87 *
88 * @throws Exception
89 * if the initialization fails for some reason
90 *
91 */
92 @Override
93 @Before
94 public void setUp() throws Exception {
95 fFacility = TraceControlTestFacility.getInstance();
96 fProxy = new TestRemoteSystemProxy();
97 URL location = FileLocator.find(Activator.getDefault().getBundle(), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
98 File testfile = new File(FileLocator.toFileURL(location).toURI());
99 fTestFile = testfile.getAbsolutePath();
100 }
101
102 /**
103 * Perform post-test clean-up.
104 *
105 * @throws Exception
106 * if the clean-up fails for some reason
107 *
108 */
109 @Override
110 @After
111 public void tearDown() throws Exception {
112 }
113
114 /**
115 * Run the TraceControlComponent.
116 */
117 public void testUstProviderTree() throws Exception {
118
119 fProxy.setTestFile(fTestFile);
120 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
121
122 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
123
124 @SuppressWarnings("restriction")
125 IHost host = new Host(new SystemProfile("myProfile", true));
126 host.setHostName("127.0.0.1");
127
128 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
129 root.addChild(node);
130
131 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
132
133 fFacility.executeCommand(node, "connect");
134
135 // Verify that node is connected
136 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
137
138 // Get provider groups
139 ITraceControlComponent[] groups = node.getChildren();
140 assertNotNull(groups);
141 assertEquals(2, groups.length);
142
143 // Get kernel provider
144 ITraceControlComponent[] providers = groups[0].getChildren();
145 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
146
147 // Get kernel provider events and select 2 events
148 ITraceControlComponent[] events = kernelProvider.getChildren();
149 assertNotNull(events);
150 assertEquals(3, events.length);
151
152 BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
153 BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
154
155 // Initialize dialog implementations for command execution
156 TraceControlDialogFactory.getInstance().setCreateSessionDialog(new CreateSessionDialogStub());
157 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
158 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
159
160 // ------------------------------------------------------------------------
161 // Create session
162 // ------------------------------------------------------------------------
163 // Initialize session handling scenario
164 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH);
165
166 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
167 sessionDialogStub.setSessionPath("/home/user/temp");
168 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
169
170 TraceSessionComponent session = fFacility.createSession(groups[1]);
171
172 // Verify that session was created
173 assertNotNull(session);
174 assertEquals("mysession", session.getName());
175 assertEquals("/home/user/temp", session.getSessionPath());
176 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
177
178 // ------------------------------------------------------------------------
179 // Create Channel on UST global domain
180 // ------------------------------------------------------------------------
181 fProxy.setScenario(SCEN_SCENARIO2_TEST);
182 CreateChannelDialogStub channelDialogStub = new CreateChannelDialogStub();
183 channelDialogStub.setIsKernel(false);
184 channelDialogStub.getChannelInfo().setOverwriteMode(false);
185 channelDialogStub.getChannelInfo().setSwitchTimer(200);
186 channelDialogStub.getChannelInfo().setReadTimer(100);
187 channelDialogStub.getChannelInfo().setNumberOfSubBuffers(2);
188 TraceControlDialogFactory.getInstance().setCreateChannelDialog(channelDialogStub);
189
190 fFacility.executeCommand(session, "createChannelOnSession");
191
192 // Verify that UST domain was created
193 ITraceControlComponent[] domains = session.getChildren();
194 assertNotNull(domains);
195 assertEquals(1, domains.length);
196
197 assertEquals("UST global", domains[0].getName());
198
199 // Verify that channel was created with correct data
200 ITraceControlComponent[]channels = domains[0].getChildren();
201 assertNotNull(channels);
202 assertEquals(1, channels.length);
203
204 assertTrue(channels[0] instanceof TraceChannelComponent);
205 TraceChannelComponent channel = (TraceChannelComponent) channels[0];
206 assertEquals("mychannel", channel.getName());
207 assertEquals(2, channel.getNumberOfSubBuffers());
208 assertEquals("mmap()", channel.getOutputType());
209 assertEquals(false, channel.isOverwriteMode());
210 assertEquals(100, channel.getReadTimer());
211 assertEquals(TraceEnablement.ENABLED, channel.getState());
212 assertEquals(16384, channel.getSubBufferSize());
213 assertEquals(200, channel.getSwitchTimer());
214
215 // ------------------------------------------------------------------------
216 // Enable event on default channel on created session above
217 // ------------------------------------------------------------------------
218 // Get first UST provider
219 UstProviderComponent ustProvider = (UstProviderComponent) providers[1];
220 assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustProvider.getName());
221 assertEquals(9379, ustProvider.getPid());
222
223 // Get events
224 events = ustProvider.getChildren();
225 assertNotNull(events);
226 assertEquals(2, events.length);
227
228 baseEventInfo0 = (BaseEventComponent) events[0];
229 baseEventInfo1 = (BaseEventComponent) events[1];
230
231 ITraceControlComponent[] ustSelection = { baseEventInfo0, baseEventInfo1 };
232
233 fFacility.executeCommand(ustSelection, "assign.event");
234
235 // verify that events were created under the channel
236 // Note that domain and channel has to be re-read because the tree is re-created
237
238 domains = session.getChildren();
239
240 // Verify that channel was created with correct data
241 channels = domains[0].getChildren();
242
243 ITraceControlComponent[] ustEvents = channels[0].getChildren();
244 assertEquals(2, ustEvents.length);
245
246 TraceEventComponent event = (TraceEventComponent) ustEvents[0];
247 assertEquals("ust_tests_hello:tptest_sighandler", event.getName());
248 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
249 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
250 assertEquals(TraceEnablement.ENABLED, event.getState());
251
252 event = (TraceEventComponent) ustEvents[1];
253 assertEquals("ust_tests_hello:tptest", ustEvents[1].getName());
254 assertEquals(TraceLogLevel.LEVEL_UNKNOWN, event.getLogLevel());
255 assertEquals(TraceEventType.TRACEPOINT, event.getEventType());
256 assertEquals(TraceEnablement.ENABLED, event.getState());
257
258 // ------------------------------------------------------------------------
259 // Disable event components
260 // ------------------------------------------------------------------------
261 fFacility.executeCommand(event, "disableEvent");
262
263 assertEquals(TraceEnablement.DISABLED, event.getState());
264
265 // ------------------------------------------------------------------------
266 // Enable event component
267 // ------------------------------------------------------------------------
268 fFacility.executeCommand(event, "enableEvent");
269
270 // Verify event state
271 assertEquals(TraceEnablement.ENABLED, event.getState());
272
273 // ------------------------------------------------------------------------
274 // Destroy session
275 // ------------------------------------------------------------------------
276
277 // Initialize session handling scenario
278 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
279
280 fFacility.destroySession(session);
281
282 // Verify that no more session components exist
283 assertEquals(0, groups[1].getChildren().length);
284
285 //-------------------------------------------------------------------------
286 // Disconnect node
287 //-------------------------------------------------------------------------
288 fFacility.executeCommand(node, "disconnect");
289 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
290
291 //-------------------------------------------------------------------------
292 // Delete node
293 //-------------------------------------------------------------------------
294 fFacility.executeCommand(node, "delete");
295 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
296 }
297 }
This page took 0.037709 seconds and 5 git commands to generate.