Commit | Line | Data |
---|---|---|
723a1d49 BH |
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.lttng2.kernel.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.fail; | |
14 | ||
15 | import java.io.IOException; | |
16 | ||
17 | import org.eclipse.core.runtime.FileLocator; | |
18 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | |
19 | import org.eclipse.core.runtime.preferences.InstanceScope; | |
20 | import org.eclipse.osgi.util.NLS; | |
21 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
22 | import org.eclipse.swtbot.swt.finder.SWTBot; | |
23 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
24 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
25 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
26 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; | |
27 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
28 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeColumn; | |
29 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
30 | import org.eclipse.tracecompass.internal.tmf.core.Activator; | |
31 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; | |
32 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants; | |
9bb4b61e | 33 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimePreferences; |
723a1d49 BH |
34 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; |
35 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.SWTBotTestCondition; | |
36 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
37 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils; | |
38 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; | |
39 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
40 | import org.junit.Before; | |
41 | import org.junit.Test; | |
42 | import org.junit.runner.RunWith; | |
43 | ||
44 | /** | |
45 | * SWTBot tests for column sorting in the Control Flow view. | |
46 | * | |
47 | * @author Bernd Hufmann | |
48 | */ | |
49 | @SuppressWarnings("restriction") | |
50 | @RunWith(SWTBotJunit4ClassRunner.class) | |
51 | public class ControlFlowViewSortingTest extends KernelTestBase { | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Constants | |
55 | // ------------------------------------------------------------------------ | |
56 | private static final String FILTER_ACTION = "Show View Filters"; | |
57 | private static final String FILTER_DIALOG_TITLE = "Filter"; | |
58 | private static final String UNCHECK_ALL = "Uncheck all"; | |
59 | private static final String CHECK_SUBTREE = "Check subtree"; | |
60 | private static final String OK_BUTTON = "OK"; | |
61 | ||
62 | private static final String PROCESS_COLUMN = "Process"; | |
63 | private static final int PROCESS_COLUMN_ID = 0; | |
64 | private static final String TID_COLUMN = "TID"; | |
65 | private static final int TID_COLUMN_ID = 1; | |
66 | private static final String PTID_COLUMN = "PTID"; | |
67 | private static final String BIRTH_COLUMN = "Birth time"; | |
68 | private static final int BIRTH_COLUMN_ID = 3; | |
69 | private static final String TRACE_COLUMN = "Trace"; | |
70 | ||
71 | private static final String SYSTEMD_PROCESS_NAME = "systemd"; | |
72 | private static final long SYSTEMD_BIRTHTIME = 1361214078967531336L; | |
73 | private static final String SYSTEMD_TID = "1"; | |
74 | ||
75 | private static final String KTHREAD_PROCESS_NAME = "kthreadd"; | |
76 | private static final long KTHREAD_BIRTHTIME = 1361214078967533536L; | |
77 | private static final String KTHREAD_TID = "2"; | |
78 | ||
79 | private static final String LTTNG_CONSUMER_PROCESS_NAME = "lttng-consumerd"; | |
80 | private static final long LTTNG_CONSUMER_BIRTHTIME = 1361214078963717040L; | |
81 | private static final String LTTNG_CONSUMER_TID = "4034"; | |
82 | ||
83 | // ------------------------------------------------------------------------ | |
84 | // Attributes | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | private SWTBotView fViewBot; | |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Housekeeping | |
91 | // ------------------------------------------------------------------------ | |
92 | /** | |
93 | * Before Test | |
94 | */ | |
95 | @Override | |
96 | @Before | |
97 | public void before() { | |
98 | ||
99 | try { | |
100 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
101 | defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00"); | |
102 | TmfTimestampFormat.updateDefaultFormats(); | |
103 | ||
104 | String tracePath = FileLocator.toFileURL(CtfTestTrace.SYNC_DEST.getTraceURL()).getPath(); | |
105 | SWTBotUtils.openTrace(TRACE_PROJECT_NAME, tracePath, KERNEL_TRACE_TYPE); | |
106 | fViewBot = fBot.viewByTitle("Control Flow"); | |
107 | fViewBot.show(); | |
108 | fViewBot.setFocus(); | |
109 | } catch (IOException e) { | |
110 | fail(); | |
111 | } | |
112 | } | |
113 | ||
114 | @Override | |
115 | public void after() { | |
116 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
9bb4b61e | 117 | defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, TmfTimePreferences.getDefaultPreferenceMap().get(ITmfTimePreferencesConstants.TIME_ZONE)); |
723a1d49 BH |
118 | TmfTimestampFormat.updateDefaultFormats(); |
119 | super.after(); | |
120 | } | |
121 | ||
122 | // ------------------------------------------------------------------------ | |
123 | // Test case(s) | |
124 | // ------------------------------------------------------------------------ | |
125 | /** | |
126 | * UI test of sorting of processes in CFV based on column selection. To verify that the sorting | |
127 | * was executed correctly, the test will use bot.waitUntil() the column content has the right | |
128 | * order. | |
129 | */ | |
130 | @Test | |
131 | public void testColumnSorting() { | |
132 | // Create a known state | |
133 | applyFilter(); | |
134 | final SWTBotTree tree = fViewBot.bot().tree(); | |
135 | SWTBotTreeItem item = SWTBotUtils.getTreeItem(fBot, tree, SYSTEMD_PROCESS_NAME); | |
136 | item.select(); | |
137 | ||
138 | testProcessSorting(tree); | |
139 | testTidSorting(tree); | |
140 | testPidSorting(tree); | |
141 | testBirthtimeSorting(tree); | |
142 | testTraceSorting(tree); | |
143 | } | |
144 | ||
145 | // ------------------------------------------------------------------------ | |
146 | // Helpers | |
147 | // ------------------------------------------------------------------------ | |
148 | private void applyFilter() { | |
149 | // Select only certain root nodes and their children but filter out rest | |
150 | SWTBotToolbarButton filterButton = fViewBot.toolbarButton(FILTER_ACTION); | |
151 | filterButton.click(); | |
152 | SWTBotShell shell = fBot.shell(FILTER_DIALOG_TITLE).activate(); | |
153 | ||
154 | SWTBot bot = shell.bot(); | |
155 | SWTBotTree treeBot = bot.tree(); | |
156 | bot.button(UNCHECK_ALL).click(); | |
157 | ||
158 | TreeCheckedCounter treeCheckCounter = new TreeCheckedCounter(treeBot); | |
159 | Integer checked = UIThreadRunnable.syncExec(treeCheckCounter); | |
160 | assertEquals("default", 0, checked.intValue()); | |
161 | ||
162 | // select root nodes and their children | |
d1a3f3fb BH |
163 | checkFilterTreeItems(bot, treeBot, SYSTEMD_PROCESS_NAME); |
164 | checkFilterTreeItems(bot, treeBot, KTHREAD_PROCESS_NAME); | |
165 | checkFilterTreeItems(bot, treeBot, LTTNG_CONSUMER_PROCESS_NAME); | |
723a1d49 BH |
166 | |
167 | bot.button(OK_BUTTON).click(); | |
168 | } | |
169 | ||
d1a3f3fb | 170 | private static void checkFilterTreeItems(SWTBot bot, SWTBotTree treeBot, String process) { |
723a1d49 BH |
171 | SWTBotTreeItem item = SWTBotUtils.getTreeItem(bot, treeBot, process); |
172 | item.select(); | |
173 | bot.button(CHECK_SUBTREE).click(); | |
174 | TreeCheckedCounter treeCheckCounter = new TreeCheckedCounter(treeBot); | |
d1a3f3fb | 175 | UIThreadRunnable.syncExec(treeCheckCounter); |
723a1d49 BH |
176 | } |
177 | ||
178 | private static void testProcessSorting(final SWTBotTree tree) { | |
179 | SWTBotTreeColumn column = tree.header(PROCESS_COLUMN); | |
180 | String[] expected = { KTHREAD_PROCESS_NAME, LTTNG_CONSUMER_PROCESS_NAME, SYSTEMD_PROCESS_NAME }; | |
181 | ||
182 | /* Sort direction Up */ | |
183 | SWTBotTestCondition condition = getSortCondition(PROCESS_COLUMN, PROCESS_COLUMN_ID, expected, tree, false); | |
184 | clickColumn(tree, column, condition); | |
185 | ||
186 | /* Sort direction Down */ | |
187 | condition = getSortCondition(PROCESS_COLUMN, 0, expected, tree, true); | |
188 | clickColumn(tree, column, condition); | |
189 | } | |
190 | ||
191 | private static void testTidSorting(final SWTBotTree tree) { | |
192 | String[] expected = { SYSTEMD_TID, KTHREAD_TID, LTTNG_CONSUMER_TID }; | |
193 | SWTBotTreeColumn column = tree.header(TID_COLUMN); | |
194 | /* Sort direction Up */ | |
195 | SWTBotTestCondition condition = getSortCondition(TID_COLUMN, TID_COLUMN_ID, expected, tree, false); | |
196 | clickColumn(tree, column, condition); | |
197 | ||
198 | /* Sort direction Down */ | |
199 | condition = getSortCondition(TID_COLUMN, TID_COLUMN_ID, expected, tree, true); | |
200 | clickColumn(tree, column, condition); | |
201 | } | |
202 | ||
203 | /* | |
204 | * Note: In this test systemd and kthreadd have PTID 0 where | |
205 | * lttng-consumerd has PTID -1 that is unknown. Currently | |
206 | * in CFV PTID is only shown when it's greater than 0. | |
207 | */ | |
208 | private static void testPidSorting(final SWTBotTree tree) { | |
209 | SWTBotTreeColumn column = tree.header(PTID_COLUMN); | |
210 | String[] expected = { LTTNG_CONSUMER_PROCESS_NAME, SYSTEMD_PROCESS_NAME, KTHREAD_PROCESS_NAME }; | |
211 | /* Sort direction Up */ | |
212 | SWTBotTestCondition condition = getSortCondition(PTID_COLUMN, PROCESS_COLUMN_ID, expected, tree, false); | |
213 | clickColumn(tree, column, condition); | |
214 | ||
215 | /* Sort direction Down */ | |
216 | String[] expected2 = { SYSTEMD_PROCESS_NAME, KTHREAD_PROCESS_NAME, LTTNG_CONSUMER_PROCESS_NAME }; | |
217 | condition = getSortCondition(PTID_COLUMN, PROCESS_COLUMN_ID, expected2, tree, false); | |
218 | clickColumn(tree, column, condition); | |
219 | } | |
220 | ||
221 | private static void testBirthtimeSorting(final SWTBotTree tree) { | |
222 | SWTBotTreeColumn column = tree.header(BIRTH_COLUMN); | |
223 | String[] expected = { | |
224 | Utils.formatTime(LTTNG_CONSUMER_BIRTHTIME, TimeFormat.CALENDAR, Resolution.NANOSEC), | |
225 | Utils.formatTime(SYSTEMD_BIRTHTIME, TimeFormat.CALENDAR, Resolution.NANOSEC), | |
226 | Utils.formatTime(KTHREAD_BIRTHTIME, TimeFormat.CALENDAR, Resolution.NANOSEC) }; | |
227 | ||
228 | /* Sort direction Up */ | |
229 | SWTBotTestCondition condition = getSortCondition(BIRTH_COLUMN, BIRTH_COLUMN_ID, expected, tree, false); | |
230 | clickColumn(tree, column, condition); | |
231 | ||
232 | /* Sort direction Down */ | |
233 | condition = getSortCondition(BIRTH_COLUMN, BIRTH_COLUMN_ID, expected, tree, true); | |
234 | clickColumn(tree, column, condition); | |
235 | } | |
236 | ||
237 | /* | |
238 | * Note: In this test only one trace is visualized in CFV. | |
239 | * Sorting is done based on birth time (up direction). | |
240 | * The implementation in CFV won't change the order when changing | |
241 | * the direction. | |
242 | */ | |
243 | private static void testTraceSorting(final SWTBotTree tree) { | |
244 | SWTBotTreeColumn column = tree.header(TRACE_COLUMN); | |
245 | String[] expected = { LTTNG_CONSUMER_PROCESS_NAME, SYSTEMD_PROCESS_NAME, KTHREAD_PROCESS_NAME }; | |
246 | ||
247 | /* Sort direction Up */ | |
248 | SWTBotTestCondition condition = getSortCondition(TRACE_COLUMN, PROCESS_COLUMN_ID, expected, tree, false); | |
249 | clickColumn(tree, column, condition); | |
250 | ||
251 | /* Sort direction Down */ | |
252 | condition = getSortCondition(TRACE_COLUMN, PROCESS_COLUMN_ID, expected, tree, false); | |
253 | clickColumn(tree, column, condition); | |
254 | } | |
255 | ||
256 | private static void clickColumn(final SWTBotTree tree, SWTBotTreeColumn processColumn, SWTBotTestCondition condition) { | |
257 | processColumn.click(); | |
258 | fBot.waitUntil(condition); | |
259 | } | |
260 | ||
261 | private static SWTBotTestCondition getSortCondition(final String testCase, final int cell, final String[] expected, final SWTBotTree tree, final boolean reverse) { | |
262 | return new SWTBotTestCondition() { | |
263 | @Override | |
264 | public boolean test() throws Exception { | |
265 | SWTBotTreeItem[] items = tree.getAllItems(); | |
266 | if (reverse) { | |
267 | for (int i = expected.length - 1; i > 0; i--) { | |
268 | if (!expected[i].equals(items[expected.length - (i + 1)].cell(cell))) { | |
269 | return false; | |
270 | } | |
271 | } | |
272 | } else { | |
273 | for (int i = 0; i < expected.length; i++) { | |
274 | if (!expected[i].equals(items[i].cell(cell))) { | |
275 | return false; | |
276 | } | |
277 | } | |
278 | } | |
279 | return true; | |
280 | } | |
281 | @Override | |
282 | public String getFailureMessage() { | |
283 | return NLS.bind("Test Case: \'{0}\' failed!", testCase); | |
284 | } | |
285 | }; | |
286 | } | |
287 | ||
288 | } |