Commit | Line | Data |
---|---|---|
da875976 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 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.fail; | |
18 | ||
19 | import java.io.IOException; | |
20 | import java.util.List; | |
21 | ||
22 | import org.apache.log4j.ConsoleAppender; | |
23 | import org.apache.log4j.Logger; | |
24 | import org.apache.log4j.SimpleLayout; | |
25 | import org.eclipse.core.runtime.FileLocator; | |
26 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
27 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
28 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
29 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
30 | import org.eclipse.swtbot.swt.finder.results.BoolResult; | |
31 | import org.eclipse.swtbot.swt.finder.results.Result; | |
32 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
33 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
34 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
35 | import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics.SystemCallLatencyStatisticsView; | |
36 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; | |
37 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; | |
38 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
39 | import org.eclipse.ui.IViewPart; | |
40 | import org.eclipse.ui.IViewReference; | |
41 | import org.eclipse.ui.PlatformUI; | |
42 | import org.eclipse.ui.WorkbenchException; | |
43 | import org.junit.After; | |
44 | import org.junit.Before; | |
45 | import org.junit.BeforeClass; | |
46 | import org.junit.Test; | |
47 | import org.junit.runner.RunWith; | |
48 | ||
49 | /** | |
50 | * Tests of the latency table | |
51 | * | |
52 | * @author Matthew Khouzam | |
53 | */ | |
54 | @RunWith(SWTBotJunit4ClassRunner.class) | |
55 | public class SystemCallLatencyStatisticsTableAnalysisTest { | |
56 | ||
57 | private static final int MIN_COL = 1; | |
58 | private static final int MAX_COL = 2; | |
59 | private static final int AVERAGE_COL = 3; | |
60 | private static final int STDEV_COL = 4; | |
61 | private static final int COUNT_COL = 5; | |
62 | private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype"; | |
63 | private static final String PROJECT_NAME = "test"; | |
64 | private static final String VIEW_ID = SystemCallLatencyStatisticsView.ID; | |
65 | private static final String TRACING_PERSPECTIVE_ID = "org.eclipse.linuxtools.tmf.ui.perspective"; | |
66 | ||
67 | /** The Log4j logger instance. */ | |
68 | private static final Logger fLogger = Logger.getRootLogger(); | |
69 | private SWTBotTree fTreeBot; | |
70 | ||
71 | /** | |
72 | * Things to setup | |
73 | */ | |
74 | @BeforeClass | |
75 | public static void beforeClass() { | |
76 | SWTBotUtils.initialize(); | |
77 | Thread.currentThread().setName("SWTBotTest"); | |
78 | /* set up for swtbot */ | |
79 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
80 | SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; | |
81 | fLogger.removeAllAppenders(); | |
82 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); | |
83 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
84 | final List<SWTBotView> openViews = bot.views(); | |
85 | for (SWTBotView view : openViews) { | |
86 | if (view.getTitle().equals("Welcome")) { | |
87 | view.close(); | |
88 | bot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
89 | } | |
90 | } | |
91 | /* Switch perspectives */ | |
92 | switchTracingPerspective(); | |
93 | /* Finish waiting for eclipse to load */ | |
94 | SWTBotUtils.waitForJobs(); | |
95 | ||
96 | } | |
97 | ||
98 | /** | |
99 | * Opens a latency table | |
100 | */ | |
101 | @Before | |
102 | public void createTree() { | |
103 | /* | |
104 | * Open latency view | |
105 | */ | |
106 | SWTBotUtils.openView(VIEW_ID); | |
107 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
108 | SWTBotView viewBot = bot.viewById(VIEW_ID); | |
109 | final IViewReference viewReference = viewBot.getViewReference(); | |
110 | IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() { | |
111 | @Override | |
112 | public IViewPart run() { | |
113 | return viewReference.getView(true); | |
114 | } | |
115 | }); | |
116 | assertNotNull(viewPart); | |
117 | if (!(viewPart instanceof SystemCallLatencyStatisticsView)) { | |
118 | fail("Could not instanciate view"); | |
119 | } | |
120 | fTreeBot = viewBot.bot().tree(); | |
121 | assertNotNull(fTreeBot); | |
122 | } | |
123 | ||
124 | /** | |
125 | * Closes the view | |
126 | */ | |
127 | @After | |
128 | public void closeTree() { | |
129 | final SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot(); | |
130 | SWTBotView viewBot = swtWorkbenchBot.viewById(VIEW_ID); | |
131 | viewBot.close(); | |
132 | } | |
133 | ||
134 | private static void switchTracingPerspective() { | |
135 | final Exception retE[] = new Exception[1]; | |
136 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
137 | @Override | |
138 | public Boolean run() { | |
139 | try { | |
140 | PlatformUI.getWorkbench().showPerspective(TRACING_PERSPECTIVE_ID, | |
141 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
142 | } catch (WorkbenchException e) { | |
143 | retE[0] = e; | |
144 | return false; | |
145 | } | |
146 | return true; | |
147 | } | |
148 | })) { | |
149 | fail(retE[0].getMessage()); | |
150 | } | |
151 | ||
152 | } | |
153 | ||
154 | /** | |
155 | * Test with an actual trace, this is more of an integration test than a | |
156 | * unit test. This test is a slow one too. If some analyses are not well | |
157 | * configured, this test will also generates null pointer exceptions. These | |
158 | * are will be logged. | |
159 | * | |
160 | * @throws IOException | |
161 | * trace not found? | |
162 | */ | |
163 | @Test | |
164 | public void testWithTrace() throws IOException { | |
165 | String tracePath; | |
166 | tracePath = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath(); | |
167 | SWTWorkbenchBot bot = new SWTWorkbenchBot(); | |
168 | SWTBotView view = bot.viewById(VIEW_ID); | |
169 | view.close(); | |
170 | bot.waitUntil(ConditionHelpers.ViewIsClosed(view)); | |
171 | SWTBotUtils.createProject(PROJECT_NAME); | |
172 | SWTBotUtils.openTrace(PROJECT_NAME, tracePath, TRACE_TYPE); | |
173 | SWTBotUtils.waitForJobs(); | |
174 | createTree(); | |
175 | SWTBotUtils.waitForJobs(); | |
176 | assertEquals("1.000 µs", fTreeBot.cell(0, MIN_COL)); | |
177 | assertEquals("5.904 s", fTreeBot.cell(0, MAX_COL)); | |
178 | assertEquals("15.628 ms", fTreeBot.cell(0, AVERAGE_COL)); // double | |
179 | assertEquals("175.875 ms", fTreeBot.cell(0, STDEV_COL)); | |
180 | assertEquals("1801", fTreeBot.cell(0, COUNT_COL)); | |
181 | SWTBotTreeItem treeItem = fTreeBot.getTreeItem("Total"); | |
182 | treeItem = treeItem.getNode(0); | |
183 | assertEquals(55, treeItem.getNodes().size()); | |
184 | validate(treeItem.getNode(2), "select", "13.600 µs", "1.509 s", "192.251 ms", "386.369 ms", "58"); | |
185 | validate(treeItem.getNode(3), "poll", "6.300 µs", "6.800 µs", "6.550 µs", "---", "2"); | |
186 | validate(treeItem.getNode(5), "set_tid_address", "2.300 µs", "2.300 µs", "2.300 µs", "---", "1"); | |
187 | validate(treeItem.getNode(7), "pipe", "27.900 µs", "29.700 µs", "28.800 µs", "---", "2"); | |
188 | ||
189 | bot.closeAllEditors(); | |
190 | SWTBotUtils.deleteProject(PROJECT_NAME, bot); | |
191 | } | |
192 | ||
193 | private static void validate(SWTBotTreeItem treeItem, final String nodeName, final String min, final String max, final String avg, final String stdev, final String count) { | |
194 | assertEquals(nodeName, treeItem.cell(0)); | |
195 | assertEquals(min, treeItem.cell(MIN_COL)); | |
196 | assertEquals(max, treeItem.cell(MAX_COL)); | |
197 | assertEquals(avg, treeItem.cell(AVERAGE_COL)); // double | |
198 | assertEquals(stdev, treeItem.cell(STDEV_COL)); | |
199 | assertEquals(count, treeItem.cell(COUNT_COL)); | |
200 | } | |
201 | } |