| 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; |
| 14 | import static org.junit.Assert.assertTrue; |
| 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; |
| 22 | import org.eclipse.core.resources.IProject; |
| 23 | import org.eclipse.core.resources.IWorkspace; |
| 24 | import org.eclipse.core.resources.ResourcesPlugin; |
| 25 | import org.eclipse.core.runtime.FileLocator; |
| 26 | import org.eclipse.core.runtime.IPath; |
| 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; |
| 32 | import org.eclipse.swtbot.swt.finder.SWTBot; |
| 33 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| 34 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; |
| 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; |
| 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; |
| 43 | import org.eclipse.tracecompass.ctf.core.tests.shared.LttngKernelTraceGenerator; |
| 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; |
| 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; |
| 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 | /** |
| 67 | * Test for the LTTng Control view in Trace Compass |
| 68 | * |
| 69 | * @author Bernd Hufmann |
| 70 | */ |
| 71 | @RunWith(SWTBotJunit4ClassRunner.class) |
| 72 | public class ControlViewTest { |
| 73 | |
| 74 | |
| 75 | // ------------------------------------------------------------------------ |
| 76 | // Constants |
| 77 | // ------------------------------------------------------------------------ |
| 78 | private static final String TEST_STREAM = "CreateSessionTestLTTng2_7.cfg"; |
| 79 | /** The initialize scenario name */ |
| 80 | protected static final String INIT_SCENARIO_NAME = "Initialize"; |
| 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; |
| 85 | private static final String NODE_NAME = "myNode"; |
| 86 | |
| 87 | // ------------------------------------------------------------------------ |
| 88 | // Test data |
| 89 | // ------------------------------------------------------------------------ |
| 90 | |
| 91 | /** The Log4j logger instance. */ |
| 92 | protected static final Logger fLogger = Logger.getRootLogger(); |
| 93 | /** The workbench bot */ |
| 94 | protected static SWTWorkbenchBot fBot; |
| 95 | private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection(); |
| 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 | |
| 105 | /** The test file */ |
| 106 | protected String fTestFile; |
| 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(); |
| 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(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Close the editor |
| 160 | */ |
| 161 | @After |
| 162 | public void tearDown() { |
| 163 | fBot.closeAllEditors(); |
| 164 | if (fRoot != null) { |
| 165 | fRoot.removeAllChildren(); |
| 166 | } |
| 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 | |
| 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 | |
| 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 | |
| 205 | testConnectToNode(); |
| 206 | // Set the scenario |
| 207 | fProxy.setScenario(CREATE_SESSION_WITH_LTTNG_2_7_SCENARIO_NAME); |
| 208 | testCreateSession(); |
| 209 | testEnableKernelEvent(); |
| 210 | testEnableSyscalls(); |
| 211 | testEnableUstChannel(); |
| 212 | testEnableUstEvents(); |
| 213 | testStartStopTracing(TraceSessionState.ACTIVE); |
| 214 | testStartStopTracing(TraceSessionState.INACTIVE); |
| 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); |
| 227 | testDestroySession(); |
| 228 | testDisconnectFromNode(); |
| 229 | SWTBotUtils.deleteProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT, fBot); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Test connect to node |
| 234 | */ |
| 235 | protected void testConnectToNode() { |
| 236 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); |
| 237 | nodeItem.select(); |
| 238 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.CONNECT_MENU_ITEM); |
| 239 | menuBot.click(); |
| 240 | SWTBotUtils.waitForJobs(); |
| 241 | |
| 242 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.SESSION_GROUP_NAME, nodeItem)); |
| 243 | |
| 244 | // Verify that node is connected |
| 245 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.CONNECTED)); |
| 246 | assertEquals(TargetNodeState.CONNECTED, fNode.getTargetNodeState()); |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Test create session |
| 251 | */ |
| 252 | protected void testCreateSession() { |
| 253 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); |
| 254 | |
| 255 | SWTBotTreeItem sessionGroupItem = nodeItem.getNode(ControlViewSwtBotUtil.SESSION_GROUP_NAME); |
| 256 | |
| 257 | sessionGroupItem.select(); |
| 258 | SWTBotMenu menuBot = sessionGroupItem.contextMenu(ControlViewSwtBotUtil.CREATE_SESSION_MENU_ITEM); |
| 259 | menuBot.click(); |
| 260 | |
| 261 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.CREATE_SESSION_DIALOG_TITLE).activate(); |
| 262 | |
| 263 | SWTBotText sessionText = shell.bot().textWithLabel(ControlViewSwtBotUtil.SESSION_NAME_LABEL); |
| 264 | sessionText.setText(SESSION_NAME); |
| 265 | |
| 266 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
| 267 | SWTBotUtils.waitForJobs(); |
| 268 | |
| 269 | sessionGroupItem.expand(); |
| 270 | |
| 271 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(getSessionName(), sessionGroupItem)); |
| 272 | assertEquals(1, sessionGroupItem.getNodes().size()); |
| 273 | |
| 274 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 275 | getNodeName(), |
| 276 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 277 | getSessionName()); |
| 278 | assertEquals(getSessionName(), sessionItem.getText()); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Test enable event (all kernel tracepoints) on session level |
| 283 | */ |
| 284 | protected void testEnableKernelEvent() { |
| 285 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 286 | getNodeName(), |
| 287 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 288 | getSessionName()); |
| 289 | |
| 290 | sessionItem.select(); |
| 291 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); |
| 292 | menuBot.click(); |
| 293 | |
| 294 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); |
| 295 | |
| 296 | SWTBotTree tracepointsTree = shell.bot().tree(); |
| 297 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); |
| 298 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
| 299 | SWTBotUtils.waitForJobs(); |
| 300 | |
| 301 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, sessionItem)); |
| 302 | |
| 303 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 304 | getNodeName(), |
| 305 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 306 | getSessionName(), |
| 307 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
| 308 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME); |
| 309 | assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText()); |
| 310 | |
| 311 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 312 | getNodeName(), |
| 313 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 314 | getSessionName(), |
| 315 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, |
| 316 | ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, |
| 317 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); |
| 318 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); |
| 319 | |
| 320 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 321 | getNodeName(), |
| 322 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 323 | getSessionName(), |
| 324 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
| 325 | assertEquals(ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME, kernelDomainItem.getText()); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Test enable Event (syscall) on domain level |
| 330 | */ |
| 331 | protected void testEnableSyscalls() { |
| 332 | SWTBotTreeItem kernelDomainItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 333 | getNodeName(), |
| 334 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 335 | getSessionName(), |
| 336 | ControlViewSwtBotUtil.KERNEL_DOMAIN_NAME); |
| 337 | kernelDomainItem.select(); |
| 338 | SWTBotMenu menuBot = kernelDomainItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); |
| 339 | menuBot.click(); |
| 340 | |
| 341 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); |
| 342 | shell.bot().radioInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.SYSCALL_GROUP_NAME).click(); |
| 343 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
| 344 | SWTBotUtils.waitForJobs(); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Test enable UST channel on session level (default values) |
| 349 | */ |
| 350 | protected void testEnableUstChannel() { |
| 351 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 352 | getNodeName(), |
| 353 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 354 | getSessionName()); |
| 355 | sessionItem.select(); |
| 356 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_CHANNEL_MENU_ITEM); |
| 357 | menuBot.click(); |
| 358 | |
| 359 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_CHANNEL_DIALOG_TITLE).activate(); |
| 360 | SWTBotText channelText = shell.bot().textWithLabel(ControlViewSwtBotUtil.CHANNEL_NAME_LABEL); |
| 361 | channelText.setText(UST_CHANNEL_NAME); |
| 362 | |
| 363 | shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); |
| 364 | shell.bot().radioInGroup(ControlViewSwtBotUtil.BUFFERTYPE_PER_UID, ControlViewSwtBotUtil.BUFFERTYPE_GROUP_NAME).click(); |
| 365 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
| 366 | SWTBotUtils.waitForJobs(); |
| 367 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem)); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Test enable event (all tracepoints) on channel level |
| 372 | */ |
| 373 | protected void testEnableUstEvents() { |
| 374 | SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 375 | getNodeName(), |
| 376 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 377 | getSessionName(), ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
| 378 | UST_CHANNEL_NAME); |
| 379 | assertEquals(UST_CHANNEL_NAME, channelItem.getText()); |
| 380 | |
| 381 | channelItem.select(); |
| 382 | SWTBotMenu menuBot = channelItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_MENU_ITEM); |
| 383 | menuBot.click(); |
| 384 | |
| 385 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); |
| 386 | SWTBotTree tracepointsTree = shell.bot().tree(); |
| 387 | tracepointsTree.select(ControlViewSwtBotUtil.ALL_TREE_NODE); |
| 388 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); |
| 389 | SWTBotUtils.waitForJobs(); |
| 390 | |
| 391 | SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 392 | getNodeName(), |
| 393 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 394 | getSessionName(), |
| 395 | ControlViewSwtBotUtil.UST_DOMAIN_NAME, |
| 396 | UST_CHANNEL_NAME, |
| 397 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); |
| 398 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText()); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Test start or stop tracing |
| 403 | * |
| 404 | * @param state |
| 405 | * the state to change to |
| 406 | */ |
| 407 | protected void testStartStopTracing(TraceSessionState state) { |
| 408 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 409 | getNodeName(), |
| 410 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 411 | getSessionName()); |
| 412 | sessionItem.select(); |
| 413 | |
| 414 | if (state == TraceSessionState.ACTIVE) { |
| 415 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.START_MENU_ITEM); |
| 416 | menuBot.click(); |
| 417 | SWTBotUtils.waitForJobs(); |
| 418 | } else { |
| 419 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.STOP_MENU_ITEM); |
| 420 | menuBot.click(); |
| 421 | SWTBotUtils.waitForJobs(); |
| 422 | } |
| 423 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
| 424 | |
| 425 | fBot.waitUntil(ControlViewSwtBotUtil.isSessionStateChanged(sessionComp, state)); |
| 426 | assertEquals(state, sessionComp.getSessionState()); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Test destroy session |
| 431 | */ |
| 432 | protected void testDestroySession() { |
| 433 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 434 | getNodeName(), |
| 435 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 436 | getSessionName()); |
| 437 | |
| 438 | sessionItem.select(); |
| 439 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.DESTROY_MENU_ITEM); |
| 440 | menuBot.click(); |
| 441 | |
| 442 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.DESTROY_CONFIRM_DIALOG_TITLE).activate(); |
| 443 | shell.bot().button(ControlViewSwtBotUtil.CONFIRM_DIALOG_OK_BUTTON).click(); |
| 444 | SWTBotUtils.waitForJobs(); |
| 445 | |
| 446 | SWTBotTreeItem sessionGroupItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 447 | getNodeName(), ControlViewSwtBotUtil.SESSION_GROUP_NAME); |
| 448 | |
| 449 | fBot.waitUntil(ConditionHelpers.isTreeChildNodeRemoved(0, sessionGroupItem)); |
| 450 | assertEquals(0, sessionGroupItem.getNodes().size()); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Test disconnect from node |
| 455 | */ |
| 456 | protected void testDisconnectFromNode() { |
| 457 | SWTBotTreeItem nodeItem = SWTBotUtils.getTreeItem(fBot, fTree, getNodeName()); |
| 458 | nodeItem.select(); |
| 459 | SWTBotMenu menuBot = nodeItem.contextMenu(ControlViewSwtBotUtil.DISCONNECT_MENU_ITEM); |
| 460 | menuBot.click(); |
| 461 | SWTBotUtils.waitForJobs(); |
| 462 | |
| 463 | // Verify that node is connected |
| 464 | fBot.waitUntil(ControlViewSwtBotUtil.isStateChanged(fNode, TargetNodeState.DISCONNECTED)); |
| 465 | assertEquals(TargetNodeState.DISCONNECTED, fNode.getTargetNodeState()); |
| 466 | assertEquals(0, nodeItem.getNodes().size()); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Test import |
| 471 | * |
| 472 | * @param createExperiment |
| 473 | * flag to indicate to create an experiment or not |
| 474 | * @param defaultExperiment |
| 475 | * flag to indicate to use default experiment or not |
| 476 | */ |
| 477 | protected void testImport(boolean createExperiment, boolean defaultExperiment) { |
| 478 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, |
| 479 | getNodeName(), |
| 480 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, |
| 481 | getSessionName()); |
| 482 | sessionItem.select(); |
| 483 | TraceSessionComponent sessionComp = ControlViewSwtBotUtil.getSessionComponent(fNode, getSessionName()); |
| 484 | |
| 485 | String pathString = sessionComp.isSnapshotSession() ? sessionComp.getSnapshotInfo().getSnapshotPath() : sessionComp.getSessionPath(); |
| 486 | IPath path = new Path(pathString); |
| 487 | |
| 488 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 489 | |
| 490 | //get location of workspace (java.io.File) |
| 491 | File workspaceDirectory = workspace.getRoot().getLocation().toFile(); |
| 492 | Path workspacePath = new Path(workspaceDirectory.toString()); |
| 493 | |
| 494 | // Only do tests if session path is in workspace |
| 495 | if (workspacePath.isPrefixOf(path)) { |
| 496 | |
| 497 | generateTrace(path); |
| 498 | |
| 499 | // Open import wizard |
| 500 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); |
| 501 | menuBot.click(); |
| 502 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); |
| 503 | |
| 504 | // This will create the Remote project if needed |
| 505 | closeImportWizard(shell, ControlViewSwtBotUtil.CANCEL_BUTTON); |
| 506 | |
| 507 | // Verify that remote project was created by import wizard |
| 508 | TmfProjectElement tmfProject = verifyRemoteProject(); |
| 509 | |
| 510 | // Re-open import wizard |
| 511 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.IMPORT_MENU_ITEM); |
| 512 | menuBot.click(); |
| 513 | shell = fBot.shell(ControlViewSwtBotUtil.IMPORT_WIZARD_TITLE).activate(); |
| 514 | |
| 515 | // Prepare and verify experiment handling |
| 516 | String experimentName = prepareAndVerifyExperimentHandling(shell.bot(), createExperiment, defaultExperiment, path); |
| 517 | |
| 518 | // Finish and import |
| 519 | closeImportWizard(shell, ControlViewSwtBotUtil.FINISH_BUTTON); |
| 520 | |
| 521 | // Verify experiment folder |
| 522 | verifyExperimentFolder(createExperiment, tmfProject, experimentName); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | |
| 527 | private static TmfProjectElement verifyRemoteProject() { |
| 528 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(ControlViewSwtBotUtil.DEFAULT_REMOTE_PROJECT); |
| 529 | // verify that project was created |
| 530 | assertTrue(project.exists()); |
| 531 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); |
| 532 | return tmfProject; |
| 533 | } |
| 534 | |
| 535 | private static void verifyExperimentFolder(boolean createExperiment, TmfProjectElement tmfProject, String experimentName) { |
| 536 | TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); |
| 537 | if (createExperiment) { |
| 538 | if (experimentName != null) { |
| 539 | TmfExperimentElement expElement = expFolder.getExperiment(experimentName); |
| 540 | assertNotNull(expElement); |
| 541 | assertEquals(1, expElement.getTraces().size()); |
| 542 | } |
| 543 | } else { |
| 544 | assertTrue(expFolder.getExperiments().size() == 0); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | private static void generateTrace(IPath path) { |
| 549 | File traceParent = path.toFile(); |
| 550 | traceParent.mkdirs(); |
| 551 | LttngKernelTraceGenerator.generateLttngKernelTrace(path.append(ControlViewSwtBotUtil.KERNEL_TRACE_NAME).toFile()); |
| 552 | } |
| 553 | |
| 554 | private static void closeImportWizard(SWTBotShell shell, String buttonName) { |
| 555 | SWTBotButton button = shell.bot().button(buttonName); |
| 556 | shell.bot().waitUntil(Conditions.widgetIsEnabled(button)); |
| 557 | button.click(); |
| 558 | fBot.waitUntil(Conditions.shellCloses(shell)); |
| 559 | SWTBotUtils.waitForJobs(); |
| 560 | } |
| 561 | |
| 562 | private static String prepareAndVerifyExperimentHandling(SWTBot bot, boolean createExperiment, boolean defaultExperiment, IPath path) { |
| 563 | String experimentName = path.lastSegment(); |
| 564 | if (createExperiment) { |
| 565 | SWTBotCheckBox checkBox = bot.checkBox(); |
| 566 | checkBox.click(); |
| 567 | if (!defaultExperiment) { |
| 568 | experimentName = verifyExperimentNameHandling(bot, experimentName); |
| 569 | } |
| 570 | } |
| 571 | return experimentName; |
| 572 | } |
| 573 | |
| 574 | private static @NonNull String verifyExperimentNameHandling(SWTBot bot, String aExperimentName) { |
| 575 | String experimentName = aExperimentName; |
| 576 | |
| 577 | // experiment already exists |
| 578 | checkFinishButton(bot, false); |
| 579 | |
| 580 | SWTBotText expText = bot.textInGroup(ControlViewSwtBotUtil.OPTION_GROUP_NAME); |
| 581 | |
| 582 | // Invalid experiment name (only whitespaces) |
| 583 | expText.setText(String.valueOf(' ')); |
| 584 | checkFinishButton(bot, false); |
| 585 | |
| 586 | // Invalid experiment name |
| 587 | expText.setText(String.valueOf('/')); |
| 588 | checkFinishButton(bot, false); |
| 589 | |
| 590 | // Set valid experiment name |
| 591 | experimentName += '_'; |
| 592 | expText.setText(experimentName); |
| 593 | return experimentName; |
| 594 | } |
| 595 | |
| 596 | private static void checkFinishButton(SWTBot bot, boolean isEnabled) { |
| 597 | final SWTBotButton finishButton = bot.button(ControlViewSwtBotUtil.FINISH_BUTTON); |
| 598 | assertTrue(finishButton.isEnabled() == isEnabled); |
| 599 | } |
| 600 | |
| 601 | } |