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
.hamcrest
.Matcher
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
38 import org
.swtchart
.Chart
;
41 * SWTBot tests for Resources view
43 * @author Matthew Khouzam
45 public class ResourcesAndCpuViewTest
extends KernelTestBase
{
47 private SWTBotView fViewBotRv
;
48 private SWTBotView fViewBotCpu
;
55 public void before() {
56 fViewBotRv
= fBot
.viewByPartName("Resources");
57 SWTBotUtils
.openView(CpuUsageView
.ID
);
58 fViewBotCpu
= fBot
.viewById(CpuUsageView
.ID
);
62 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, Paths
.get(FileLocator
.toFileURL(CtfTestTrace
.ARM_64_BIT_HEADER
.getTraceURL()).toURI()).toString(), KERNEL_TRACE_TYPE
);
63 } catch (IOException
| URISyntaxException e
) {
66 SWTBotUtils
.activateEditor(fBot
, "bug446190");
67 fViewBotRv
.setFocus();
71 * Simple test to check the CPU Usage view after getting signals.
74 public void testSignals() {
75 Widget widget
= fViewBotRv
.getWidget();
76 assertNotNull(widget
);
77 ITmfTrace activeTrace
= TmfTraceManager
.getInstance().getActiveTrace();
78 assertNotNull(activeTrace
);
81 TmfCpuSelectedSignal signal
= new TmfCpuSelectedSignal(widget
, -1, activeTrace
);
83 assertEquals("Before signal - CPU Usage Title", "CPU Usage", getTitle());
84 assertEquals("Before signal - Thread Table", 12, getTableCount());
85 fViewBotRv
.setFocus();
88 signal
= new TmfCpuSelectedSignal(widget
, 1, activeTrace
);
90 assertEquals("After signal - CPU Usage Title", "CPU Usage 1", getTitle());
91 assertEquals("After signal - Thread Table", 4, getTableCount());
94 signal
= new TmfCpuSelectedSignal(widget
, 3, activeTrace
);
96 assertEquals("After signal 2 - CPU Usage Title", "CPU Usage 1, 3", getTitle());
97 assertEquals("After signal 2 - Thread Table", 8, getTableCount());
100 signal
= new TmfCpuSelectedSignal(widget
, -1, activeTrace
);
102 assertEquals("After signal clear - CPU Usage Title", "CPU Usage", getTitle());
103 assertEquals("After signal clear - Thread Table", 12, getTableCount());
106 private static void broadcast(TmfCpuSelectedSignal signal
) {
107 UIThreadRunnable
.syncExec(() -> TmfSignalManager
.dispatchSignal(signal
));
108 SWTBotUtils
.waitForJobs();
111 private String
getTitle() {
112 fViewBotCpu
.setFocus();
113 // Do some basic validation
114 Matcher
<Chart
> matcher
= WidgetOfType
.widgetOfType(Chart
.class);
115 Chart chart
= fViewBotCpu
.bot().widget(matcher
);
116 return chart
.getTitle().getText();
119 private int getTableCount() {
120 fViewBotCpu
.setFocus();
121 // Do some basic validation
122 Matcher
<Tree
> matcher
= WidgetOfType
.widgetOfType(Tree
.class);
123 SWTBotTree treeBot
= new SWTBotTree(fViewBotCpu
.bot().widget(matcher
));
125 for (SWTBotTreeItem bot
: treeBot
.getAllItems()) {
126 final String text
= bot
.getText();
127 if (!text
.isEmpty()) {