Commit | Line | Data |
---|---|---|
1d9948f9 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 | ||
10 | package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.fail; | |
15 | ||
16 | import java.io.IOException; | |
17 | import java.net.URISyntaxException; | |
18 | import java.nio.file.Paths; | |
19 | ||
20 | import org.eclipse.core.runtime.FileLocator; | |
21 | import org.eclipse.swt.widgets.Tree; | |
22 | import org.eclipse.swt.widgets.Widget; | |
23 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
24 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
25 | import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType; | |
26 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
27 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
28 | import org.eclipse.tracecompass.analysis.os.linux.core.signals.TmfCpuSelectedSignal; | |
29 | import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.cpuusage.CpuUsageView; | |
30 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; | |
31 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; | |
32 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
33 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; | |
34 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
f0beeb4a | 35 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
1d9948f9 MK |
36 | import org.hamcrest.Matcher; |
37 | import org.junit.Before; | |
38 | import org.junit.Test; | |
39 | import org.swtchart.Chart; | |
40 | ||
41 | /** | |
42 | * SWTBot tests for Resources view | |
43 | * | |
44 | * @author Matthew Khouzam | |
45 | */ | |
46 | public class ResourcesAndCpuViewTest extends KernelTestBase { | |
47 | ||
48 | private SWTBotView fViewBotRv; | |
49 | private SWTBotView fViewBotCpu; | |
50 | ||
51 | /** | |
52 | * Before Test | |
53 | */ | |
54 | @Override | |
55 | @Before | |
56 | public void before() { | |
57 | fViewBotRv = fBot.viewByPartName("Resources"); | |
58 | SWTBotUtils.openView(CpuUsageView.ID); | |
59 | fViewBotCpu = fBot.viewById(CpuUsageView.ID); | |
60 | fViewBotCpu.show(); | |
61 | fViewBotRv.show(); | |
62 | try { | |
63 | SWTBotUtils.openTrace(TRACE_PROJECT_NAME, Paths.get(FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).toURI()).toString(), KERNEL_TRACE_TYPE); | |
64 | } catch (IOException | URISyntaxException e) { | |
65 | fail(e.getMessage()); | |
66 | } | |
67 | SWTBotUtils.activateEditor(fBot, "bug446190"); | |
68 | fViewBotRv.setFocus(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * Simple test to check the CPU Usage view after getting signals. | |
73 | */ | |
74 | @Test | |
75 | public void testSignals() { | |
76 | Widget widget = fViewBotRv.getWidget(); | |
77 | assertNotNull(widget); | |
78 | ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace(); | |
79 | assertNotNull(activeTrace); | |
80 | ||
81 | // clear everything | |
82 | TmfCpuSelectedSignal signal = new TmfCpuSelectedSignal(widget, -1, activeTrace); | |
83 | broadcast(signal); | |
84 | assertEquals("Before signal - CPU Usage Title", "CPU Usage", getTitle()); | |
85 | assertEquals("Before signal - Thread Table", 12, getTableCount()); | |
86 | fViewBotRv.setFocus(); | |
87 | ||
88 | // select cpu 1 | |
89 | signal = new TmfCpuSelectedSignal(widget, 1, activeTrace); | |
90 | broadcast(signal); | |
91 | assertEquals("After signal - CPU Usage Title", "CPU Usage 1", getTitle()); | |
92 | assertEquals("After signal - Thread Table", 4, getTableCount()); | |
93 | ||
94 | // select cpu 3 and 1 | |
95 | signal = new TmfCpuSelectedSignal(widget, 3, activeTrace); | |
96 | broadcast(signal); | |
97 | assertEquals("After signal 2 - CPU Usage Title", "CPU Usage 1, 3", getTitle()); | |
98 | assertEquals("After signal 2 - Thread Table", 8, getTableCount()); | |
99 | ||
100 | // reset | |
101 | signal = new TmfCpuSelectedSignal(widget, -1, activeTrace); | |
102 | broadcast(signal); | |
103 | assertEquals("After signal clear - CPU Usage Title", "CPU Usage", getTitle()); | |
104 | assertEquals("After signal clear - Thread Table", 12, getTableCount()); | |
105 | } | |
106 | ||
107 | private static void broadcast(TmfCpuSelectedSignal signal) { | |
108 | UIThreadRunnable.syncExec(() -> TmfSignalManager.dispatchSignal(signal)); | |
f0beeb4a | 109 | WaitUtils.waitForJobs(); |
1d9948f9 MK |
110 | } |
111 | ||
112 | private String getTitle() { | |
113 | fViewBotCpu.setFocus(); | |
114 | // Do some basic validation | |
115 | Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class); | |
116 | Chart chart = fViewBotCpu.bot().widget(matcher); | |
117 | return chart.getTitle().getText(); | |
118 | } | |
119 | ||
120 | private int getTableCount() { | |
121 | fViewBotCpu.setFocus(); | |
122 | // Do some basic validation | |
123 | Matcher<Tree> matcher = WidgetOfType.widgetOfType(Tree.class); | |
124 | SWTBotTree treeBot = new SWTBotTree(fViewBotCpu.bot().widget(matcher)); | |
125 | int count = 0; | |
126 | for (SWTBotTreeItem bot : treeBot.getAllItems()) { | |
127 | final String text = bot.getText(); | |
128 | if (!text.isEmpty()) { | |
129 | count++; | |
130 | } | |
131 | } | |
132 | return count; | |
133 | } | |
134 | } |