Commit | Line | Data |
---|---|---|
4d760144 JCK |
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; | |
f0beeb4a | 30 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
4d760144 JCK |
31 | import org.junit.After; |
32 | import org.junit.Before; | |
33 | import org.junit.BeforeClass; | |
34 | import org.junit.runner.RunWith; | |
35 | ||
36 | /** | |
37 | * Base class for pattern latency view test | |
38 | * | |
39 | * @author Jean-Christian Kouame | |
40 | */ | |
41 | @RunWith(SWTBotJunit4ClassRunner.class) | |
42 | public abstract class PatternLatencyViewTestBase { | |
43 | ||
44 | private static final String PROJECT_NAME = "test"; | |
45 | private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype"; | |
1b9a8a8c | 46 | private static final String TRACE_NAME = "bug446190"; |
4d760144 JCK |
47 | |
48 | /** The Log4j logger instance. */ | |
49 | private static final Logger fLogger = Logger.getRootLogger(); | |
50 | /** | |
51 | * The workbench bot | |
52 | */ | |
53 | protected static SWTWorkbenchBot fBot; | |
54 | ||
55 | /** | |
56 | * Things to setup | |
57 | */ | |
58 | @BeforeClass | |
59 | public static void beforeClass() { | |
60 | ||
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 */ | |
f0beeb4a | 73 | WaitUtils.waitForJobs(); |
4d760144 JCK |
74 | |
75 | fBot = new SWTWorkbenchBot(); | |
76 | ||
77 | loadXmlFile(); | |
78 | openTrace(); | |
79 | } | |
80 | ||
81 | /** | |
82 | * Create a tracing project and open the test trace | |
83 | */ | |
84 | private static void openTrace() { | |
85 | try { | |
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); | |
f0beeb4a | 89 | WaitUtils.waitForJobs(); |
4d760144 JCK |
90 | } catch (IOException e) { |
91 | fail("Failed to get the trace."); | |
92 | } | |
93 | } | |
94 | ||
95 | /** | |
96 | * Bypassing the native import wizard and programmatically load the XML | |
97 | * analysis | |
98 | */ | |
99 | private static void loadXmlFile() { | |
100 | XmlUtils.addXmlFile(TmfXmlTestFiles.VALID_PATTERN_FILE.getFile()); | |
101 | XmlAnalysisModuleSource.notifyModuleChange(); | |
102 | } | |
103 | ||
104 | /** | |
105 | * set up before the test and open the latency view | |
106 | */ | |
107 | @Before | |
108 | public void before() { | |
109 | openView(getViewTitle()); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Closes the view | |
114 | */ | |
115 | @After | |
116 | public void closeView() { | |
117 | fBot.closeAllEditors(); | |
118 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); | |
119 | ||
120 | final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); | |
121 | SWTBotView viewBot = swtWorkbenchBot.viewById(getViewId()); | |
122 | viewBot.close(); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Open a pattern latency view | |
127 | * | |
128 | * @param viewTitle | |
129 | * The view title | |
130 | */ | |
131 | private static void openView(final String viewTitle) { | |
132 | SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); | |
1b9a8a8c | 133 | treeItem = SWTBotUtils.getTreeItem(fBot, treeItem, TRACE_NAME, "Views", "XML system call analysis", viewTitle); |
4d760144 | 134 | treeItem.doubleClick(); |
4d760144 JCK |
135 | } |
136 | ||
137 | /** | |
138 | * Get the id of the latency view tested | |
139 | * | |
140 | * @return The view id | |
141 | */ | |
142 | protected abstract String getViewId(); | |
143 | ||
144 | /** | |
145 | * Get the the latency view title | |
146 | * | |
147 | * @return The view title | |
148 | */ | |
149 | protected abstract String getViewTitle(); | |
150 | } |