Commit | Line | Data |
---|---|---|
3162c616 MK |
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 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.analysis.os.linux.ui.swtbot.tests.latency; | |
14 | ||
c6dd173d | 15 | import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible; |
b2c971ec MK |
16 | import static org.junit.Assert.assertEquals; |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | import static org.junit.Assert.fail; | |
3162c616 MK |
20 | |
21 | import java.io.IOException; | |
22 | import java.lang.reflect.Field; | |
23 | ||
24 | import org.apache.log4j.ConsoleAppender; | |
25 | import org.apache.log4j.Logger; | |
26 | import org.apache.log4j.SimpleLayout; | |
27 | import org.eclipse.core.runtime.FileLocator; | |
28 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
29 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
c6dd173d | 30 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
3162c616 MK |
31 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
32 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
c6dd173d | 33 | import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; |
3162c616 MK |
34 | import org.eclipse.swtbot.swt.finder.results.Result; |
35 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
c6dd173d | 36 | import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl; |
3162c616 | 37 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; |
3162c616 | 38 | import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityView; |
edded5c1 | 39 | import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer; |
3162c616 MK |
40 | import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.SystemCallLatencyDensityView; |
41 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; | |
42 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; | |
43 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
f0beeb4a | 44 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
3162c616 MK |
45 | import org.eclipse.ui.IViewPart; |
46 | import org.eclipse.ui.IViewReference; | |
47 | import org.junit.After; | |
48 | import org.junit.Before; | |
49 | import org.junit.BeforeClass; | |
50 | import org.junit.Test; | |
51 | import org.junit.runner.RunWith; | |
c6dd173d MK |
52 | import org.swtchart.Chart; |
53 | import org.swtchart.Range; | |
3162c616 MK |
54 | |
55 | /** | |
56 | * Tests of the density view | |
57 | * | |
58 | * @author Matthew Khouzam | |
59 | */ | |
60 | @RunWith(SWTBotJunit4ClassRunner.class) | |
61 | public class SystemCallLatencyDensityViewTest { | |
62 | ||
63 | private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype"; | |
64 | private static final String PROJECT_NAME = "test"; | |
65 | private static final String VIEW_ID = SystemCallLatencyDensityView.ID; | |
66 | ||
67 | /** The Log4j logger instance. */ | |
68 | private static final Logger fLogger = Logger.getRootLogger(); | |
69 | private AbstractSegmentStoreDensityView fDensityView; | |
70 | private AbstractSegmentStoreTableViewer fDensityViewer; | |
c6dd173d | 71 | private Chart fDensityChart; |
3162c616 MK |
72 | |
73 | /** | |
74 | * Things to setup | |
75 | */ | |
76 | @BeforeClass | |
77 | public static void beforeClass() { | |
78 | ||
79 | SWTBotUtils.initialize(); | |
80 | Thread.currentThread().setName("SWTBotTest"); | |
81 | /* set up for swtbot */ | |
82 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
83 | SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; | |
84 | fLogger.removeAllAppenders(); | |
85 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); | |
86 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
87 | SWTBotUtils.closeView("welcome", bot); | |
88 | /* Switch perspectives */ | |
89 | SWTBotUtils.switchToTracingPerspective(); | |
90 | /* Finish waiting for eclipse to load */ | |
f0beeb4a | 91 | WaitUtils.waitForJobs(); |
3162c616 MK |
92 | |
93 | } | |
94 | ||
95 | /** | |
96 | * Opens a latency table | |
97 | * | |
98 | * @throws SecurityException | |
99 | * If a security manager is present and any the wrong class is | |
100 | * loaded or the class loader is not the same as its ancestor's | |
101 | * loader. | |
102 | * | |
103 | * @throws NoSuchFieldException | |
104 | * Field not available | |
105 | * @throws IllegalAccessException | |
106 | * Field is inaccessible | |
107 | * @throws IllegalArgumentException | |
108 | * the object is not the correct class type | |
109 | * | |
110 | * | |
111 | */ | |
112 | @Before | |
113 | public void createDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
114 | /* | |
115 | * Open latency view | |
116 | */ | |
117 | SWTBotUtils.openView(VIEW_ID); | |
118 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
119 | SWTBotView viewBot = bot.viewById(VIEW_ID); | |
120 | final IViewReference viewReference = viewBot.getViewReference(); | |
121 | IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() { | |
122 | @Override | |
123 | public IViewPart run() { | |
124 | return viewReference.getView(true); | |
125 | } | |
126 | }); | |
127 | assertNotNull(viewPart); | |
128 | if (!(viewPart instanceof SystemCallLatencyDensityView)) { | |
129 | fail("Could not instanciate view"); | |
130 | } | |
131 | fDensityView = (SystemCallLatencyDensityView) viewPart; | |
132 | ||
133 | /* | |
134 | * Use reflection to access the table viewer | |
135 | */ | |
136 | final Field field = AbstractSegmentStoreDensityView.class.getDeclaredField("fTableViewer"); | |
137 | field.setAccessible(true); | |
138 | fDensityViewer = (AbstractSegmentStoreTableViewer) field.get(fDensityView); | |
c6dd173d | 139 | fDensityChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class)); |
3162c616 MK |
140 | assertNotNull(fDensityViewer); |
141 | } | |
142 | ||
143 | /** | |
144 | * Closes the view | |
145 | */ | |
146 | @After | |
147 | public void closeDensityViewer() { | |
148 | final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); | |
149 | SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID); | |
150 | viewBot.close(); | |
151 | } | |
152 | ||
153 | /** | |
154 | * Test with an actual trace, this is more of an integration test than a | |
155 | * unit test. This test is a slow one too. If some analyses are not well | |
156 | * configured, this test will also generates null pointer exceptions. These | |
157 | * will be logged. | |
158 | * | |
159 | * @throws IOException | |
160 | * trace not found? | |
161 | * @throws SecurityException | |
162 | * If a security manager is present and any the wrong class is | |
163 | * loaded or the class loader is not the same as its ancestor's | |
164 | * loader. | |
165 | * | |
166 | * @throws NoSuchFieldException | |
167 | * Field not available | |
168 | * @throws IllegalAccessException | |
169 | * Field is inaccessible | |
170 | * @throws IllegalArgumentException | |
171 | * the object is not the correct class type | |
172 | * | |
173 | */ | |
174 | @Test | |
175 | public void testWithTrace() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
176 | String tracePath; | |
177 | tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath(); | |
178 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
179 | SWTBotView view = bot.viewById(VIEW_ID); | |
180 | view.close(); | |
181 | bot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
182 | SWTBotUtils.createProject(PROJECT_NAME); | |
183 | SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE); | |
f0beeb4a | 184 | WaitUtils.waitForJobs(); |
3162c616 | 185 | createDensityViewer(); |
f0beeb4a | 186 | WaitUtils.waitForJobs(); |
3162c616 | 187 | SWTBotTable tableBot = new SWTBotTable(fDensityViewer.getTableViewer().getTable()); |
ef47abba | 188 | bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1,600", 0, 2)); |
3162c616 | 189 | tableBot.header("Duration").click(); |
ef47abba | 190 | bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1,600", 0, 2)); |
3162c616 | 191 | tableBot.header("Duration").click(); |
ef47abba | 192 | bot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1,001,046,400", 0, 2)); |
c6dd173d MK |
193 | final Chart densityChart = fDensityChart; |
194 | assertNotNull(densityChart); | |
aa5b9bd6 MAL |
195 | bot.waitUntil(ConditionHelpers.numberOfSeries(densityChart, 1)); |
196 | ||
c6dd173d MK |
197 | SWTBotChart chartBot = new SWTBotChart(densityChart); |
198 | assertVisible(chartBot); | |
199 | assertEquals("", chartBot.getToolTipText()); | |
200 | final Range range = densityChart.getAxisSet().getXAxes()[0].getRange(); | |
201 | assertTrue(0 > range.lower); | |
202 | assertTrue(1001046400 < range.upper); | |
3162c616 MK |
203 | bot.closeAllEditors(); |
204 | SWTBotUtils.deleteProject(PROJECT_NAME, bot); | |
205 | } | |
c6dd173d MK |
206 | |
207 | private static class SWTBotChart extends AbstractSWTBotControl<Chart> { | |
208 | public SWTBotChart(Chart w) throws WidgetNotFoundException { | |
209 | super(w); | |
210 | } | |
211 | } | |
3162c616 | 212 | } |