| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2016 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.tmf.analysis.xml.ui.swtbot.tests.latency; |
| 11 | |
| 12 | import static org.junit.Assert.fail; |
| 13 | |
| 14 | import java.io.IOException; |
| 15 | |
| 16 | import org.apache.log4j.ConsoleAppender; |
| 17 | import org.apache.log4j.Logger; |
| 18 | import org.apache.log4j.SimpleLayout; |
| 19 | import org.eclipse.core.runtime.FileLocator; |
| 20 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
| 21 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
| 22 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| 23 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; |
| 24 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; |
| 25 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlAnalysisModuleSource; |
| 26 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; |
| 27 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
| 28 | import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles; |
| 29 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
| 30 | import org.junit.After; |
| 31 | import org.junit.Before; |
| 32 | import org.junit.BeforeClass; |
| 33 | import org.junit.runner.RunWith; |
| 34 | |
| 35 | /** |
| 36 | * Base class for pattern latency view test |
| 37 | * |
| 38 | * @author Jean-Christian Kouame |
| 39 | */ |
| 40 | @RunWith(SWTBotJunit4ClassRunner.class) |
| 41 | public abstract class PatternLatencyViewTestBase { |
| 42 | |
| 43 | private static final String PROJECT_NAME = "test"; |
| 44 | private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype"; |
| 45 | private static final String TRACE_NAME = "bug446190"; |
| 46 | |
| 47 | /** The Log4j logger instance. */ |
| 48 | private static final Logger fLogger = Logger.getRootLogger(); |
| 49 | /** |
| 50 | * The workbench bot |
| 51 | */ |
| 52 | protected static SWTWorkbenchBot fBot; |
| 53 | |
| 54 | /** |
| 55 | * Things to setup |
| 56 | */ |
| 57 | @BeforeClass |
| 58 | public static void beforeClass() { |
| 59 | |
| 60 | SWTBotUtils.initialize(); |
| 61 | Thread.currentThread().setName("SWTBotTest"); |
| 62 | /* set up for swtbot */ |
| 63 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ |
| 64 | SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; |
| 65 | fLogger.removeAllAppenders(); |
| 66 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); |
| 67 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); |
| 68 | SWTBotUtils.closeView("welcome", bot); |
| 69 | /* Switch perspectives */ |
| 70 | SWTBotUtils.switchToTracingPerspective(); |
| 71 | /* Finish waiting for eclipse to load */ |
| 72 | SWTBotUtils.waitForJobs(); |
| 73 | |
| 74 | fBot = new SWTWorkbenchBot(); |
| 75 | |
| 76 | loadXmlFile(); |
| 77 | openTrace(); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Create a tracing project and open the test trace |
| 82 | */ |
| 83 | private static void openTrace() { |
| 84 | try { |
| 85 | String tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath(); |
| 86 | SWTBotUtils.createProject(PROJECT_NAME); |
| 87 | SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE); |
| 88 | SWTBotUtils.waitForJobs(); |
| 89 | } catch (IOException e) { |
| 90 | fail("Failed to get the trace."); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Bypassing the native import wizard and programmatically load the XML |
| 96 | * analysis |
| 97 | */ |
| 98 | private static void loadXmlFile() { |
| 99 | XmlUtils.addXmlFile(TmfXmlTestFiles.VALID_PATTERN_FILE.getFile()); |
| 100 | XmlAnalysisModuleSource.notifyModuleChange(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * set up before the test and open the latency view |
| 105 | */ |
| 106 | @Before |
| 107 | public void before() { |
| 108 | openView(getViewTitle()); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Closes the view |
| 113 | */ |
| 114 | @After |
| 115 | public void closeView() { |
| 116 | fBot.closeAllEditors(); |
| 117 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); |
| 118 | |
| 119 | final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); |
| 120 | SWTBotView viewBot = swtWorkbenchBot.viewById(getViewId()); |
| 121 | viewBot.close(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Open a pattern latency view |
| 126 | * |
| 127 | * @param viewTitle |
| 128 | * The view title |
| 129 | */ |
| 130 | private static void openView(final String viewTitle) { |
| 131 | SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); |
| 132 | treeItem = SWTBotUtils.getTreeItem(fBot, treeItem, TRACE_NAME, "Views", "XML system call analysis", viewTitle); |
| 133 | treeItem.doubleClick(); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Get the id of the latency view tested |
| 138 | * |
| 139 | * @return The view id |
| 140 | */ |
| 141 | protected abstract String getViewId(); |
| 142 | |
| 143 | /** |
| 144 | * Get the the latency view title |
| 145 | * |
| 146 | * @return The view title |
| 147 | */ |
| 148 | protected abstract String getViewTitle(); |
| 149 | } |