1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.swtbot
.tests
.latency
;
12 import static org
.junit
.Assert
.fail
;
14 import java
.io
.IOException
;
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
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
31 import org
.junit
.After
;
32 import org
.junit
.Before
;
33 import org
.junit
.BeforeClass
;
34 import org
.junit
.runner
.RunWith
;
37 * Base class for pattern latency view test
39 * @author Jean-Christian Kouame
41 @RunWith(SWTBotJunit4ClassRunner
.class)
42 public abstract class PatternLatencyViewTestBase
{
44 private static final String PROJECT_NAME
= "test";
45 private static final String TRACE_TYPE
= "org.eclipse.linuxtools.lttng2.kernel.tracetype";
46 private static final String TRACE_NAME
= "bug446190";
48 /** The Log4j logger instance. */
49 private static final Logger fLogger
= Logger
.getRootLogger();
53 protected static SWTWorkbenchBot fBot
;
59 public static void beforeClass() {
61 SWTBotUtils
.initialize();
62 Thread
.currentThread().setName("SWTBotTest");
63 /* set up for swtbot */
64 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
65 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
66 fLogger
.removeAllAppenders();
67 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
68 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
69 SWTBotUtils
.closeView("welcome", bot
);
70 /* Switch perspectives */
71 SWTBotUtils
.switchToTracingPerspective();
72 /* Finish waiting for eclipse to load */
73 WaitUtils
.waitForJobs();
75 fBot
= new SWTWorkbenchBot();
82 * Create a tracing project and open the test trace
84 private static void openTrace() {
86 String tracePath
= FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).getPath();
87 SWTBotUtils
.createProject(PROJECT_NAME
);
88 SWTBotUtils
.openTrace(PROJECT_NAME
, tracePath
, TRACE_TYPE
);
89 WaitUtils
.waitForJobs();
90 } catch (IOException e
) {
91 fail("Failed to get the trace.");
96 * Bypassing the native import wizard and programmatically load the XML
99 private static void loadXmlFile() {
100 XmlUtils
.addXmlFile(TmfXmlTestFiles
.VALID_PATTERN_FILE
.getFile());
101 XmlAnalysisModuleSource
.notifyModuleChange();
105 * set up before the test and open the latency view
108 public void before() {
109 openView(getViewTitle());
116 public void closeView() {
117 fBot
.closeAllEditors();
118 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
120 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
121 SWTBotView viewBot
= swtWorkbenchBot
.viewById(getViewId());
126 * Open a pattern latency view
131 private static void openView(final String viewTitle
) {
132 SWTBotTreeItem treeItem
= SWTBotUtils
.selectTracesFolder(fBot
, PROJECT_NAME
);
133 treeItem
= SWTBotUtils
.getTreeItem(fBot
, treeItem
, TRACE_NAME
, "Views", "XML system call analysis", viewTitle
);
134 treeItem
.doubleClick();
138 * Get the id of the latency view tested
140 * @return The view id
142 protected abstract String
getViewId();
145 * Get the the latency view title
147 * @return The view title
149 protected abstract String
getViewTitle();