lttng: Add Lttng Execution Graph analysis benchmarks
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / ust / ui / swtbot / tests / MemoryUsageViewTest.java
CommitLineData
7b583932
BH
1/*******************************************************************************
2 * Copyright (c) 2015 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
10package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests;
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertNotNull;
14import static org.junit.Assert.assertTrue;
15
16import java.io.File;
17
18import org.apache.log4j.ConsoleAppender;
19import org.apache.log4j.Logger;
20import org.apache.log4j.SimpleLayout;
21import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
22import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
23import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
24import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
25import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
b2d6540e 26import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
7b583932
BH
27import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
28import org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage.MemoryUsageView;
29import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
30import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
31import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
32import org.hamcrest.Matcher;
33import org.junit.After;
34import org.junit.Before;
35import org.junit.BeforeClass;
36import org.junit.Test;
37import org.junit.runner.RunWith;
38import org.swtchart.Chart;
39import org.swtchart.ILineSeries;
40import org.swtchart.ISeries;
41import org.swtchart.ISeriesSet;
42
43/**
44 * Test for the Memory Usage view in trace compass
45 */
46@RunWith(SWTBotJunit4ClassRunner.class)
47public class MemoryUsageViewTest {
48
b2d6540e
MAL
49 private static final int EXPECTED_NUM_SERIES = 4;
50
7b583932
BH
51 private static final String UST_ID = "org.eclipse.linuxtools.lttng2.ust.tracetype";
52
53 private static final String PROJECT_NAME = "TestForMemory";
54
55 /** The Log4j logger instance. */
56 private static final Logger fLogger = Logger.getRootLogger();
57 private static SWTWorkbenchBot fBot;
58
59 /**
60 * Initialization
61 */
62 @BeforeClass
63 public static void init() {
64 SWTBotUtils.initialize();
65
66 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
67 /* set up for swtbot */
68 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
69 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
70 fBot = new SWTWorkbenchBot();
71
72 SWTBotUtils.closeView("welcome", fBot);
73
74 SWTBotUtils.switchToTracingPerspective();
75
76 /* finish waiting for eclipse to load */
77 SWTBotUtils.waitForJobs();
78 }
79
80 /**
81 * Open a trace in an editor
82 */
83 @Before
84 public void beforeTest() {
85 SWTBotUtils.createProject(PROJECT_NAME);
86 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
87 assertNotNull(treeItem);
88 final CtfTestTrace cygProfile = CtfTestTrace.MEMORY_ANALYSIS;
89 final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath());
90 SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID);
91 SWTBotUtils.openView(MemoryUsageView.ID);
92 SWTBotUtils.waitForJobs();
93 }
94
95 /**
96 * Close the editor
97 */
98 @After
99 public void tearDown() {
100 fBot.closeAllEditors();
101 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
102 }
103
104 /**
105 * Test if Memory Usage is populated
106 */
107 @Test
108 public void testOpenMemoryUsage() {
109 SWTBotView viewBot = fBot.viewById(MemoryUsageView.ID);
110 viewBot.setFocus();
111
112 // Do some basic validation
113 Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class);
114 Chart chart = viewBot.bot().widget(matcher);
7b583932
BH
115
116 // Verify that the chart has 4 series
b2d6540e
MAL
117 fBot.waitUntil(new DefaultCondition() {
118 private String fFailureMessage;
119
120 @Override
121 public boolean test() throws Exception {
122 int length = chart.getSeriesSet().getSeries().length;
123 if (length != EXPECTED_NUM_SERIES){
124 fFailureMessage = "Chart did not contain the expected number series. Actual " + length + ", expected " + EXPECTED_NUM_SERIES;
125 return false;
126 }
127
128 return true;
129 }
130
131 @Override
132 public String getFailureMessage() {
133 return fFailureMessage;
134 }
135 });
136
137 ISeriesSet seriesSet = chart.getSeriesSet();
138 ISeries[] series = seriesSet.getSeries();
139 assertEquals(EXPECTED_NUM_SERIES, series.length);
7b583932
BH
140 // Verify that each series is a ILineSeries
141 for (int i = 0; i < series.length; i++) {
142 assertTrue(series[i] instanceof ILineSeries);
143 }
144 }
145
146}
This page took 0.038872 seconds and 5 git commands to generate.