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
.junit
.After
;
31 import org
.junit
.Before
;
32 import org
.junit
.BeforeClass
;
33 import org
.junit
.runner
.RunWith
;
36 * Base class for pattern latency view test
38 * @author Jean-Christian Kouame
40 @RunWith(SWTBotJunit4ClassRunner
.class)
41 public abstract class PatternLatencyViewTestBase
{
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";
47 /** The Log4j logger instance. */
48 private static final Logger fLogger
= Logger
.getRootLogger();
52 protected static SWTWorkbenchBot fBot
;
58 public static void beforeClass() {
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();
74 fBot
= new SWTWorkbenchBot();
81 * Create a tracing project and open the test trace
83 private static void openTrace() {
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.");
95 * Bypassing the native import wizard and programmatically load the XML
98 private static void loadXmlFile() {
99 XmlUtils
.addXmlFile(TmfXmlTestFiles
.VALID_PATTERN_FILE
.getFile());
100 XmlAnalysisModuleSource
.notifyModuleChange();
104 * set up before the test and open the latency view
107 public void before() {
108 openView(getViewTitle());
115 public void closeView() {
116 fBot
.closeAllEditors();
117 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
119 final SWTWorkbenchBot swtWorkbenchBot
= new SWTWorkbenchBot();
120 SWTBotView viewBot
= swtWorkbenchBot
.viewById(getViewId());
125 * Open a pattern latency view
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();
137 * Get the id of the latency view tested
139 * @return The view id
141 protected abstract String
getViewId();
144 * Get the the latency view title
146 * @return The view title
148 protected abstract String
getViewTitle();