1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.kernel
.ui
.swtbot
.tests
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.fail
;
16 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
18 import java
.nio
.file
.Paths
;
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
;
35 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
36 import org
.hamcrest
.Matcher
;
37 import org
.junit
.Before
;
38 import org
.junit
.Test
;
39 import org
.swtchart
.Chart
;
42 * SWTBot tests for Resources view
44 * @author Matthew Khouzam
46 public class ResourcesAndCpuViewTest
extends KernelTestBase
{
48 private SWTBotView fViewBotRv
;
49 private SWTBotView fViewBotCpu
;
56 public void before() {
57 fViewBotRv
= fBot
.viewByPartName("Resources");
58 SWTBotUtils
.openView(CpuUsageView
.ID
);
59 fViewBotCpu
= fBot
.viewById(CpuUsageView
.ID
);
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
) {
67 SWTBotUtils
.activateEditor(fBot
, "bug446190");
68 fViewBotRv
.setFocus();
72 * Simple test to check the CPU Usage view after getting signals.
75 public void testSignals() {
76 Widget widget
= fViewBotRv
.getWidget();
77 assertNotNull(widget
);
78 ITmfTrace activeTrace
= TmfTraceManager
.getInstance().getActiveTrace();
79 assertNotNull(activeTrace
);
82 TmfCpuSelectedSignal signal
= new TmfCpuSelectedSignal(widget
, -1, activeTrace
);
84 assertEquals("Before signal - CPU Usage Title", "CPU Usage", getTitle());
85 assertEquals("Before signal - Thread Table", 12, getTableCount());
86 fViewBotRv
.setFocus();
89 signal
= new TmfCpuSelectedSignal(widget
, 1, activeTrace
);
91 assertEquals("After signal - CPU Usage Title", "CPU Usage 1", getTitle());
92 assertEquals("After signal - Thread Table", 4, getTableCount());
95 signal
= new TmfCpuSelectedSignal(widget
, 3, activeTrace
);
97 assertEquals("After signal 2 - CPU Usage Title", "CPU Usage 1, 3", getTitle());
98 assertEquals("After signal 2 - Thread Table", 8, getTableCount());
101 signal
= new TmfCpuSelectedSignal(widget
, -1, activeTrace
);
103 assertEquals("After signal clear - CPU Usage Title", "CPU Usage", getTitle());
104 assertEquals("After signal clear - Thread Table", 12, getTableCount());
107 private static void broadcast(TmfCpuSelectedSignal signal
) {
108 UIThreadRunnable
.syncExec(() -> TmfSignalManager
.dispatchSignal(signal
));
109 WaitUtils
.waitForJobs();
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();
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
));
126 for (SWTBotTreeItem bot
: treeBot
.getAllItems()) {
127 final String text
= bot
.getText();
128 if (!text
.isEmpty()) {