lttng: Port unit tests to JUnit4
[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, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
15
16 import static org.junit.Assert.*;
17
18 import java.io.File;
19 import java.net.URL;
20
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.junit.Test;
49 import org.osgi.framework.FrameworkUtil;
50
51 /**
52 * The class <code>TraceControlUstProviderTests</code> contains UST provider
53 * handling test cases.
54 */
55 @SuppressWarnings("nls")
56 public class TraceControlUstProviderTests {
57
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61
62 private static final String TEST_STREAM = "CreateTreeTest.cfg";
63 private static final String SCEN_SCENARIO2_TEST = "Scenario2";
64
65 // ------------------------------------------------------------------------
66 // Test data
67 // ------------------------------------------------------------------------
68
69 private TraceControlTestFacility fFacility;
70 private TestRemoteSystemProxy fProxy;
71 private String fTestFile;
72
73 // ------------------------------------------------------------------------
74 // Housekeeping
75 // ------------------------------------------------------------------------
76
77 /**
78 * Perform pre-test initialization.
79 *
80 * @throws Exception
81 * if the initialization fails for some reason
82 */
83 @Before
84 public void setUp() throws Exception {
85 fFacility = TraceControlTestFacility.getInstance();
86 fProxy = new TestRemoteSystemProxy();
87 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
88 File testfile = new File(FileLocator.toFileURL(location).toURI());
89 fTestFile = testfile.getAbsolutePath();
90 }
91
92 /**
93 * Perform post-test clean-up.
94 */
95 @After
96 public void tearDown() {
97 fFacility.waitForJobs();
98 }
99
100 /**
101 * Run the TraceControlComponent.
102 *
103 * @throws Exception
104 * This will fail the test
105 */
106 @Test
107 public void testUstProviderTree() throws Exception {
108
109 fProxy.setTestFile(fTestFile);
110 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
111
112 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
113
114 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
115 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
116 IHost host = registry.createLocalHost(profile, "myProfile", "user");
117
118 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
119 root.addChild(node);
120
121 fFacility.waitForJobs();
122
123 fFacility.executeCommand(node, "connect");
124
125 int i = 0;
126 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
127 i++;
128 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
129 }
130
131 // Verify that node is connected
132 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
133
134 // Get provider groups
135 ITraceControlComponent[] groups = node.getChildren();
136 assertNotNull(groups);
137 assertEquals(2, groups.length);
138
139 // Get kernel provider
140 ITraceControlComponent[] providers = groups[0].getChildren();
141 KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
142
143 // Get kernel provider events and select 2 events
144 ITraceControlComponent[] events = kernelProvider.getChildren();
145 assertNotNull(events);
146 assertEquals(3, events.length);
147
148 BaseEventComponent baseEventInfo0 = (BaseEventComponent) events[0];
149 BaseEventComponent baseEventInfo1 = (BaseEventComponent) events[1];
150
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());
155
156 // ------------------------------------------------------------------------
157 // Create session
158 // ------------------------------------------------------------------------
159 // Initialize session handling scenario
160 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH);
161
162 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
163 sessionDialogStub.setSessionPath("/home/user/temp");
164 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
165
166 TraceSessionComponent session = fFacility.createSession(groups[1]);
167
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());
173
174 // ------------------------------------------------------------------------
175 // Enable Channel on UST global domain
176 // ------------------------------------------------------------------------
177 fProxy.setScenario(SCEN_SCENARIO2_TEST);
178 EnableChannelDialogStub channelDialogStub = new EnableChannelDialogStub();
179 channelDialogStub.setIsKernel(false);
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);
185
186 fFacility.executeCommand(session, "enableChannelOnSession");
187
188 // Verify that UST domain was created
189 ITraceControlComponent[] domains = session.getChildren();
190 assertNotNull(domains);
191 assertEquals(1, domains.length);
192
193 assertEquals("UST global", domains[0].getName());
194
195 // Verify that channel was created with correct data
196 ITraceControlComponent[]channels = domains[0].getChildren();
197 assertNotNull(channels);
198 assertEquals(1, channels.length);
199
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());
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());
210
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());
218
219 // Get events
220 events = ustProvider.getChildren();
221 assertNotNull(events);
222 assertEquals(2, events.length);
223
224 baseEventInfo0 = (BaseEventComponent) events[0];
225 baseEventInfo1 = (BaseEventComponent) events[1];
226
227 ITraceControlComponent[] ustSelection = { baseEventInfo0, baseEventInfo1 };
228
229 fFacility.executeCommand(ustSelection, "assign.event");
230
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
233
234 domains = session.getChildren();
235
236 // Verify that channel was created with correct data
237 channels = domains[0].getChildren();
238
239 ITraceControlComponent[] ustEvents = channels[0].getChildren();
240 assertEquals(2, ustEvents.length);
241
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());
247
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());
253
254 // ------------------------------------------------------------------------
255 // Disable event components
256 // ------------------------------------------------------------------------
257 fFacility.executeCommand(event, "disableEvent");
258
259 assertEquals(TraceEnablement.DISABLED, event.getState());
260
261 // ------------------------------------------------------------------------
262 // Enable event component
263 // ------------------------------------------------------------------------
264 fFacility.executeCommand(event, "enableEvent");
265
266 // Verify event state
267 assertEquals(TraceEnablement.ENABLED, event.getState());
268
269 // ------------------------------------------------------------------------
270 // Destroy session
271 // ------------------------------------------------------------------------
272
273 // Initialize session handling scenario
274 fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
275
276 fFacility.destroySession(session);
277
278 // Verify that no more session components exist
279 assertEquals(0, groups[1].getChildren().length);
280
281 //-------------------------------------------------------------------------
282 // Disconnect node
283 //-------------------------------------------------------------------------
284 fFacility.executeCommand(node, "disconnect");
285 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
286
287 //-------------------------------------------------------------------------
288 // Delete node
289 //-------------------------------------------------------------------------
290 fFacility.executeCommand(node, "delete");
291 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
292 }
293 }
This page took 0.046355 seconds and 5 git commands to generate.