Commit | Line | Data |
---|---|---|
2e65d221 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 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 | ||
10 | package org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
325d8cac | 14 | import static org.junit.Assert.assertTrue; |
2e65d221 BH |
15 | |
16 | import java.io.File; | |
17 | import java.net.URL; | |
18 | ||
19 | import org.apache.log4j.ConsoleAppender; | |
20 | import org.apache.log4j.Logger; | |
21 | import org.apache.log4j.SimpleLayout; | |
325d8cac BH |
22 | import org.eclipse.core.resources.IProject; |
23 | import org.eclipse.core.resources.IWorkspace; | |
24 | import org.eclipse.core.resources.ResourcesPlugin; | |
2e65d221 | 25 | import org.eclipse.core.runtime.FileLocator; |
325d8cac | 26 | import org.eclipse.core.runtime.IPath; |
2e65d221 BH |
27 | import org.eclipse.core.runtime.Path; |
28 | import org.eclipse.jdt.annotation.NonNull; | |
29 | import org.eclipse.remote.core.IRemoteConnection; | |
30 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
31 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
325d8cac | 32 | import org.eclipse.swtbot.swt.finder.SWTBot; |
2e65d221 BH |
33 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
34 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
325d8cac BH |
35 | import org.eclipse.swtbot.swt.finder.waits.Conditions; |
36 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; | |
37 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; | |
2e65d221 BH |
38 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; |
39 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
40 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; | |
41 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
42 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
325d8cac | 43 | import org.eclipse.tracecompass.ctf.core.tests.shared.LttngKernelTraceGenerator; |
2e65d221 BH |
44 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
45 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState; | |
46 | import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy; | |
47 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView; | |
48 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
49 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
50 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
51 | import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory; | |
325d8cac BH |
52 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
53 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder; | |
54 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
55 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
2e65d221 BH |
56 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
57 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
58 | import org.eclipse.ui.IViewPart; | |
59 | import org.junit.After; | |
60 | import org.junit.Before; | |
61 | import org.junit.BeforeClass; | |
62 | import org.junit.Test; | |
63 | import org.junit.runner.RunWith; | |
64 | import org.osgi.framework.FrameworkUtil; | |
65 | ||
66 | /** | |
325d8cac | 67 | * Test for the LTTng Control view in Trace Compass |
2e65d221 BH |
68 | * |
69 | * @author Bernd Hufmann | |
70 | */ | |
71 | @RunWith(SWTBotJunit4ClassRunner.class) | |
72 | public class ControlViewTest { | |
73 | ||
2e65d221 BH |
74 | |
75 | // ------------------------------------------------------------------------ | |
76 | // Constants | |
77 | // ------------------------------------------------------------------------ | |
78 | private static final String TEST_STREAM = "CreateSessionTestLTTng2_7.cfg"; | |
3d09f0a5 BH |
79 | /** The initialize scenario name */ |
80 | protected static final String INIT_SCENARIO_NAME = "Initialize"; | |
2e65d221 BH |
81 | private static final String CREATE_SESSION_WITH_LTTNG_2_7_SCENARIO_NAME = "CreateSession_2.7"; |
82 | ||
83 | private static final String SESSION_NAME = "mysession"; | |
84 | private static final String UST_CHANNEL_NAME = ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME; | |
3d09f0a5 | 85 | private static final String NODE_NAME = "myNode"; |
2e65d221 BH |
86 | |
87 | // ------------------------------------------------------------------------ | |
88 | // Test data | |
89 | // ------------------------------------------------------------------------ | |
3d09f0a5 BH |
90 | |
91 | /** The Log4j logger instance. */ | |
92 | protected static final Logger fLogger = Logger.getRootLogger(); | |
93 | /** The workbench bot */ | |
94 | protected static SWTWorkbenchBot fBot; | |
2e65d221 | 95 | private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection(); |
3d09f0a5 BH |
96 | /** The test remote system proxy */ |
97 | protected @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost); | |
98 | /** The trace control tree */ | |
99 | protected SWTBotTree fTree; | |
100 | /** The trace control root component */ | |
101 | protected ITraceControlComponent fRoot; | |
102 | /** The target node component */ | |
103 | protected TargetNodeComponent fNode; | |
104 | ||
3d09f0a5 BH |
105 | /** The test file */ |
106 | protected String fTestFile; | |
2e65d221 BH |
107 | |
108 | // ------------------------------------------------------------------------ | |
109 | // Housekeeping | |
110 | // ------------------------------------------------------------------------ | |
111 | ||
112 | /** | |
113 | * Initialization | |
114 | */ | |
115 | @BeforeClass | |
116 | public static void init() { | |
117 | SWTBotUtils.initialize(); | |
118 | ||
119 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger | |
120 | /* set up for swtbot */ | |
121 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
122 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
123 | fBot = new SWTWorkbenchBot(); | |
124 | ||
125 | SWTBotUtils.closeView("welcome", fBot); | |
126 | ||
127 | /* finish waiting for eclipse to load */ | |
128 | SWTBotUtils.waitForJobs(); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Open a trace in an editor | |
133 | * | |
134 | * @throws Exception | |
135 | * if problem occurs | |
136 | */ | |
137 | @Before | |
138 | public void beforeTest() throws Exception { | |
139 | SWTBotUtils.openView(ControlView.ID); | |
140 | SWTBotUtils.waitForJobs(); | |
141 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("testfiles" + File.separator + getTestStream()), null); | |
142 | File testfile = new File(FileLocator.toFileURL(location).toURI()); | |
143 | fTestFile = testfile.getAbsolutePath(); | |
3d09f0a5 BH |
144 | |
145 | // Create root component | |
146 | SWTBotView viewBot = fBot.viewById(ControlView.ID); | |
147 | viewBot.setFocus(); | |
148 | IViewPart part = viewBot.getViewReference().getView(true); | |
149 | ControlView view = (ControlView) part; | |
150 | fRoot = view.getTraceControlRoot(); | |
151 | ||
152 | // Create node component | |
153 | fNode = new TargetNodeComponent(getNodeName(), fRoot, fProxy); | |
154 | fRoot.addChild(fNode); | |
155 | fTree = viewBot.bot().tree(); | |
2e65d221 BH |
156 | } |
157 | ||
158 | /** | |
159 | * Close the editor | |
160 | */ | |
161 | @After | |
162 | public void tearDown() { | |
163 | fBot.closeAllEditors(); | |
3d09f0a5 BH |
164 | if (fRoot != null) { |
165 | fRoot.removeAllChildren(); | |
166 | } | |
2e65d221 BH |
167 | } |
168 | ||
169 | /** | |
170 | * Get the test stream file name to use for the test suite | |
171 | * | |
172 | * @return the name of the test stream file | |
173 | */ | |
174 | protected String getTestStream() { | |
175 | return TEST_STREAM; | |
176 | } | |
177 | ||
3d09f0a5 BH |
178 | /** |
179 | * Get the session name | |
180 | * | |
181 | * @return the session name for this test | |
182 | */ | |
183 | protected String getSessionName() { | |
184 | return SESSION_NAME; | |
185 | } | |
186 | ||
187 | /** | |
188 | * Get the node name | |
189 | * | |
190 | * @return the node name for the test | |
191 | */ | |
192 | protected String getNodeName() { | |
193 | return NODE_NAME; | |
194 | } | |
195 | ||
2e65d221 BH |
196 | /** |
197 | * Test basic trace session generation. | |
198 | */ | |
199 | @Test | |
200 | public void testTraceSessionTree() { | |
201 | ||
202 | fProxy.setTestFile(fTestFile); | |
203 | fProxy.setScenario(INIT_SCENARIO_NAME); | |
204 | ||
3d09f0a5 | 205 | testConnectToNode(); |
2e65d221 BH |
206 | // Set the scenario |
207 | fProxy.setScenario(CREATE_SESSION_WITH_LTTNG_2_7_SCENARIO_NAME); | |
3d09f0a5 BH |
208 | testCreateSession(); |
209 | testEnableKernelEvent(); | |
210 | testEnableSyscalls(); | |
211 | testEnableUstChannel(); | |
212 | testEnableUstEvents(); | |
213 | testStartStopTracing(TraceSessionState.ACTIVE); | |
214 | testStartStopTracing(TraceSessionState.INACTIVE); | |
325d8cac BH |
215 | // Import without experiment creation |
216 | testImport(false, true); | |
217 | SWTBotUtils.clearTracesFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
218 | // Import with experiment creation (default experiment name) | |
219 | testImport(true, true); | |
220 | SWTBotUtils.clearTracesFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
221 | /* | |
222 | * Import with experiment creation, test experiment already exists and | |
223 | * with experiment name validation | |
224 | */ | |
225 | testImport(true, false); | |
226 | SWTBotUtils.clearExperimentFolder(fBot, ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
3d09f0a5 BH |
227 | testDestroySession(); |
228 | testDisconnectFromNode(); | |
2e65d221 BH |
229 | } |
230 | ||
231 | /** | |
232 | * Test connect to node | |
2e65d221 | 233 | */ |
3d09f0a5 BH |
234 | protected void testConnectToNode() { |
235 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
236 | nodeItem.select(); |
237 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.CONNECT_MENU_ITEM); | |
238 | menuBot.click(); | |
239 | SWTBotUtils.waitForJobs(); | |
240 | ||
241 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.SESSION_GROUP_NAME, nodeItem)); | |
242 | ||
243 | // Verify that node is connected | |
3d09f0a5 BH |
244 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.CONNECTED)); |
245 | assertEquals(TargetNodeState.CONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
246 | } |
247 | ||
248 | /** | |
249 | * Test create session | |
2e65d221 | 250 | */ |
3d09f0a5 BH |
251 | protected void testCreateSession() { |
252 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
253 | |
254 | SWTBotTreeItem sessionGroupItem = nodeItem.getNode(ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
255 | ||
256 | sessionGroupItem.select(); | |
257 | SWTBotMenu menuBot = sessionGroupItem.contextMenu(ControlViewSwtBotUtil.CREATE_SESSION_MENU_ITEM); | |
258 | menuBot.click(); | |
259 | ||
260 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.CREATE_SESSION_DIALOG_TITLE).activate(); | |
261 | ||
262 | SWTBotText sessionText = shell.bot().textWithLabel(ControlViewSwtBotUtil.SESSION_NAME_LABEL); | |
263 | sessionText.setText(SESSION_NAME); | |
264 | ||
265 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
266 | SWTBotUtils.waitForJobs(); | |
267 | ||
268 | sessionGroupItem.expand(); | |
269 | ||
3d09f0a5 | 270 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(getSessionName(), sessionGroupItem)); |
2e65d221 BH |
271 | assertEquals(1, sessionGroupItem.getNodes().size()); |
272 | ||
3d09f0a5 BH |
273 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
274 | getNodeName(), | |
2e65d221 | 275 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 BH |
276 | getSessionName()); |
277 | assertEquals(getSessionName(), sessionItem.getText()); | |
2e65d221 BH |
278 | } |
279 | ||
280 | /** | |
281 | * Test enable event (all kernel tracepoints) on session level | |
2e65d221 | 282 | */ |
3d09f0a5 BH |
283 | protected void testEnableKernelEvent() { |
284 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
285 | getNodeName(), | |
2e65d221 | 286 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 287 | getSessionName()); |
2e65d221 BH |
288 | |
289 | sessionItem.select(); | |
290 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
291 | menuBot.click(); | |
292 | ||
293 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
294 | ||
295 | SWTBotTree tracepointsTree = shell.bot().tree(); | |
296 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
297 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
298 | SWTBotUtils.waitForJobs(); | |
299 | ||
300 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); | |
301 | ||
3d09f0a5 BH |
302 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
303 | getNodeName(), | |
2e65d221 | 304 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 305 | getSessionName(), |
2e65d221 BH |
306 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
307 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); | |
308 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); | |
309 | ||
3d09f0a5 BH |
310 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
311 | getNodeName(), | |
2e65d221 | 312 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 313 | getSessionName(), |
2e65d221 BH |
314 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
315 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, | |
316 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
317 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
318 | ||
3d09f0a5 BH |
319 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
320 | getNodeName(), | |
2e65d221 | 321 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 322 | getSessionName(), |
2e65d221 BH |
323 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
324 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); | |
325 | } | |
326 | ||
327 | /** | |
328 | * Test enable Event (syscall) on domain level | |
2e65d221 | 329 | */ |
3d09f0a5 BH |
330 | protected void testEnableSyscalls() { |
331 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
332 | getNodeName(), | |
2e65d221 | 333 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 334 | getSessionName(), |
2e65d221 BH |
335 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
336 | kernelDomainItem.select(); | |
337 | SWTBotMenu menuBot = kernelDomainItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
338 | menuBot.click(); | |
339 | ||
340 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
341 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); | |
342 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
343 | SWTBotUtils.waitForJobs(); | |
344 | } | |
345 | ||
346 | /** | |
347 | * Test enable UST channel on session level (default values) | |
2e65d221 | 348 | */ |
3d09f0a5 BH |
349 | protected void testEnableUstChannel() { |
350 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
351 | getNodeName(), | |
2e65d221 | 352 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 353 | getSessionName()); |
2e65d221 BH |
354 | sessionItem.select(); |
355 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_CHANNEL_MENU_ITEM); | |
356 | menuBot.click(); | |
357 | ||
358 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_CHANNEL_DIALOG_TITLE).activate(); | |
359 | SWTBotText channelText = shell.bot().textWithLabel(ControlViewSwtBotUtil.CHANNEL_NAME_LABEL); | |
360 | channelText.setText(UST_CHANNEL_NAME); | |
361 | ||
362 | shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
363 | shell.bot().radioInGroup(ControlViewSwtBotUtil.BUFFERTYPE_PER_UID, ControlViewSwtBotUtil.BUFFERTYPE_GROUP_NAME).click(); | |
364 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
365 | SWTBotUtils.waitForJobs(); | |
366 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem)); | |
367 | } | |
368 | ||
369 | /** | |
370 | * Test enable event (all tracepoints) on channel level | |
2e65d221 | 371 | */ |
3d09f0a5 BH |
372 | protected void testEnableUstEvents() { |
373 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
374 | getNodeName(), | |
2e65d221 | 375 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 376 | getSessionName(), ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
2e65d221 BH |
377 | UST_CHANNEL_NAME); |
378 | assertEquals(UST_CHANNEL_NAME, channelItem.getText()); | |
379 | ||
380 | channelItem.select(); | |
381 | SWTBotMenu menuBot = channelItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_MENU_ITEM); | |
382 | menuBot.click(); | |
383 | ||
384 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
385 | SWTBotTree tracepointsTree = shell.bot().tree(); | |
386 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
387 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
388 | SWTBotUtils.waitForJobs(); | |
389 | ||
3d09f0a5 BH |
390 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
391 | getNodeName(), | |
2e65d221 | 392 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 393 | getSessionName(), |
2e65d221 BH |
394 | ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
395 | UST_CHANNEL_NAME, | |
396 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); | |
397 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); | |
398 | } | |
399 | ||
400 | /** | |
401 | * Test start or stop tracing | |
402 | * | |
2e65d221 BH |
403 | * @param state |
404 | * the state to change to | |
405 | */ | |
3d09f0a5 BH |
406 | protected void testStartStopTracing(TraceSessionState state) { |
407 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
408 | getNodeName(), | |
2e65d221 | 409 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 410 | getSessionName()); |
2e65d221 BH |
411 | sessionItem.select(); |
412 | ||
413 | if (state == TraceSessionState.ACTIVE) { | |
414 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.START_MENU_ITEM); | |
415 | menuBot.click(); | |
416 | SWTBotUtils.waitForJobs(); | |
417 | } else { | |
418 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.STOP_MENU_ITEM); | |
419 | menuBot.click(); | |
420 | SWTBotUtils.waitForJobs(); | |
421 | } | |
3d09f0a5 | 422 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
2e65d221 BH |
423 | |
424 | fBot.waitUntil(ControlViewSwtBotUtil.isSessionStateChanged(sessionComp, state)); | |
425 | assertEquals(state, sessionComp.getSessionState()); | |
426 | } | |
427 | ||
428 | /** | |
429 | * Test destroy session | |
2e65d221 | 430 | */ |
3d09f0a5 BH |
431 | protected void testDestroySession() { |
432 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
433 | getNodeName(), | |
2e65d221 | 434 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
3d09f0a5 | 435 | getSessionName()); |
2e65d221 BH |
436 | |
437 | sessionItem.select(); | |
438 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.DESTROY_MENU_ITEM); | |
439 | menuBot.click(); | |
440 | ||
441 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.DESTROY_CONFIRM_DIALOG_TITLE).activate(); | |
442 | shell.bot().button(ControlViewSwtBotUtil.CONFIRM_DIALOG_OK_BUTTON).click(); | |
443 | SWTBotUtils.waitForJobs(); | |
444 | ||
3d09f0a5 BH |
445 | SWTBotTreeItem sessionGroupItem = SWTBotUtils.getTreeItem(fBot, fTree, |
446 | getNodeName(), ControlViewSwtBotUtil.SESSION_GROUP_NAME); | |
2e65d221 BH |
447 | |
448 | fBot.waitUntil(ConditionHelpers.isTreeChildNodeRemoved(0, sessionGroupItem)); | |
449 | assertEquals(0, sessionGroupItem.getNodes().size()); | |
450 | } | |
451 | ||
452 | /** | |
453 | * Test disconnect from node | |
2e65d221 | 454 | */ |
3d09f0a5 BH |
455 | protected void testDisconnectFromNode() { |
456 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); | |
2e65d221 BH |
457 | nodeItem.select(); |
458 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.DISCONNECT_MENU_ITEM); | |
459 | menuBot.click(); | |
460 | SWTBotUtils.waitForJobs(); | |
461 | ||
462 | // Verify that node is connected | |
3d09f0a5 BH |
463 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.DISCONNECTED)); |
464 | assertEquals(TargetNodeState.DISCONNECTED, fNode.getTargetNodeState()); | |
2e65d221 BH |
465 | assertEquals(0, nodeItem.getNodes().size()); |
466 | } | |
325d8cac BH |
467 | |
468 | /** | |
469 | * Test import | |
470 | * | |
471 | * @param createExperiment | |
472 | * flag to indicate to create an experiment or not | |
473 | * @param defaultExperiment | |
474 | * flag to indicate to use default experiment or not | |
475 | */ | |
476 | protected void testImport(boolean createExperiment, boolean defaultExperiment) { | |
477 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
478 | getNodeName(), | |
479 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
480 | getSessionName()); | |
481 | sessionItem.select(); | |
482 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); | |
483 | ||
484 | String pathString = sessionComp.isSnapshotSession() ? sessionComp.getSnapshotInfo().getSnapshotPath() : sessionComp.getSessionPath(); | |
485 | IPath path = new Path(pathString); | |
486 | ||
487 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
488 | ||
489 | //get location of workspace (java.io.File) | |
490 | File workspaceDirectory = workspace.getRoot().getLocation().toFile(); | |
491 | Path workspacePath = new Path(workspaceDirectory.toString()); | |
492 | ||
493 | // Only do tests if session path is in workspace | |
494 | if (workspacePath.isPrefixOf(path)) { | |
495 | ||
496 | generateTrace(path); | |
497 | ||
498 | // Open import wizard | |
499 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
500 | menuBot.click(); | |
501 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
502 | ||
503 | // This will create the Remote project if needed | |
504 | closeImportWizard(shell, ControlViewSwtBotUtil.CANCEL_BUTTON); | |
505 | ||
506 | // Verify that remote project was created by import wizard | |
507 | TmfProjectElement tmfProject = verifyRemoteProject(); | |
508 | ||
509 | // Re-open import wizard | |
510 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); | |
511 | menuBot.click(); | |
512 | shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); | |
513 | ||
514 | // Prepare and verify experiment handling | |
515 | String experimentName = prepareAndVerifyExperimentHandling(shell.bot(), createExperiment, defaultExperiment, path); | |
516 | ||
517 | // Finish and import | |
518 | closeImportWizard(shell, ControlViewSwtBotUtil.FINISH_BUTTON); | |
519 | ||
520 | // Verify experiment folder | |
521 | verifyExperimentFolder(createExperiment, tmfProject, experimentName); | |
522 | } | |
523 | } | |
524 | ||
525 | ||
526 | private static TmfProjectElement verifyRemoteProject() { | |
527 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); | |
528 | // verify that project was created | |
529 | assertTrue(project.exists()); | |
530 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); | |
531 | return tmfProject; | |
532 | } | |
533 | ||
534 | private static void verifyExperimentFolder(boolean createExperiment, TmfProjectElement tmfProject, String experimentName) { | |
535 | TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); | |
536 | if (createExperiment) { | |
537 | if (experimentName != null) { | |
538 | TmfExperimentElement expElement = expFolder.getExperiment(experimentName); | |
539 | assertNotNull(expElement); | |
540 | assertEquals(1, expElement.getTraces().size()); | |
541 | } | |
542 | } else { | |
543 | assertTrue(expFolder.getExperiments().size() == 0); | |
544 | } | |
545 | } | |
546 | ||
547 | private static void generateTrace(IPath path) { | |
548 | File traceParent = path.toFile(); | |
549 | traceParent.mkdirs(); | |
550 | LttngKernelTraceGenerator.generateLttngKernelTrace(path.append(ControlViewSwtBotUtil.KERNEL_TRACE_NAME).toFile()); | |
551 | } | |
552 | ||
553 | private static void closeImportWizard(SWTBotShell shell, String buttonName) { | |
554 | SWTBotButton button = shell.bot().button(buttonName); | |
555 | shell.bot().waitUntil(Conditions.widgetIsEnabled(button)); | |
556 | button.click(); | |
557 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
558 | SWTBotUtils.waitForJobs(); | |
559 | } | |
560 | ||
561 | private static String prepareAndVerifyExperimentHandling(SWTBot bot, boolean createExperiment, boolean defaultExperiment, IPath path) { | |
562 | String experimentName = path.lastSegment(); | |
563 | if (createExperiment) { | |
564 | SWTBotCheckBox checkBox = bot.checkBox(); | |
565 | checkBox.click(); | |
566 | if (!defaultExperiment) { | |
567 | experimentName = verifyExperimentNameHandling(bot, experimentName); | |
568 | } | |
569 | } | |
570 | return experimentName; | |
571 | } | |
572 | ||
573 | private static @NonNull String verifyExperimentNameHandling(SWTBot bot, String aExperimentName) { | |
574 | String experimentName = aExperimentName; | |
575 | ||
576 | // experiment already exists | |
577 | checkFinishButton(bot, false); | |
578 | ||
579 | SWTBotText expText = bot.textInGroup(ControlViewSwtBotUtil.OPTION_GROUP_NAME); | |
580 | ||
581 | // Invalid experiment name (only whitespaces) | |
582 | expText.setText(String.valueOf(' ')); | |
583 | checkFinishButton(bot, false); | |
584 | ||
585 | // Invalid experiment name | |
586 | expText.setText(String.valueOf('/')); | |
587 | checkFinishButton(bot, false); | |
588 | ||
589 | // Set valid experiment name | |
590 | experimentName += '_'; | |
591 | expText.setText(experimentName); | |
592 | return experimentName; | |
593 | } | |
594 | ||
595 | private static void checkFinishButton(SWTBot bot, boolean isEnabled) { | |
596 | final SWTBotButton finishButton = bot.button(ControlViewSwtBotUtil.FINISH_BUTTON); | |
597 | assertTrue(finishButton.isEnabled() == isEnabled); | |
598 | } | |
599 | ||
2e65d221 | 600 | } |