Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b57a1f07a37b70c79fe34a57c26c09b229614a3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
 * Copyright (c) 2015, 2017 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage.UstMemoryUsageView;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.XYDataProviderBaseTest;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXAxisChartViewer;
import org.eclipse.ui.IViewPart;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.swtchart.Chart;
import org.swtchart.ILineSeries;
import org.swtchart.ISeries;
import org.swtchart.ISeriesSet;
import org.swtchart.LineStyle;

/**
 * Test for the {@link UstMemoryUsageView} in trace compass
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class MemoryUsageViewTest extends XYDataProviderBaseTest {

    private static final int EXPECTED_NUM_SERIES = 4;

    private static final RGB RED = new RGB(255, 0, 0);
    private static final RGB GREEN_BLUE = new RGB(0, 255, 255);
    private static final RGB GREEN = new RGB(0, 255, 0);
    private static final RGB MAGENTA = new RGB(255, 0, 255);

    private static final @NonNull String TITLE = "Relative Kernel Memory Usage";

    private static final @NonNull String FIRST_SERIES_NAME = "memory:10611";
    private static final @NonNull String SECOND_SERIES_NAME = "memory:10618";
    private static final @NonNull String THIRD_SERIES_NAME = "memory:10604";
    private static final @NonNull String FOURTH_SERIES_NAME = "memory:10613";

    /**
     * Test if Memory Usage is populated
     */
    @Test
    public void testOpenMemoryUsage() {
        SWTBotView viewBot = fBot.viewById(UstMemoryUsageView.ID);
        viewBot.setFocus();

        // Do some basic validation
        Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class);
        Chart chart = viewBot.bot().widget(matcher);

        checkAllEntries();

        // Verify that the chart has 4 series
        fBot.waitUntil(ConditionHelpers.numberOfSeries(chart, EXPECTED_NUM_SERIES));

        ISeriesSet seriesSet = chart.getSeriesSet();
        ISeries[] series = seriesSet.getSeries();
        // Verify that each series is a ILineSeries
        for (ISeries serie : series) {
            assertTrue(serie instanceof ILineSeries);
        }
    }

    /**
     * Test Memory Usage data model
     *
     * @throws NoSuchMethodException
     *             Reflection exception should not happen
     * @throws SecurityException
     *             Reflection exception should not happen
     * @throws IllegalAccessException
     *             Reflection exception should not happen
     * @throws IllegalArgumentException
     *             Reflection exception should not happen
     * @throws InvocationTargetException
     *             Reflection exception should not happen
     */
    @Test
    public void testMemoryUsage() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        IViewPart viewSite = getSWTBotView().getViewReference().getView(true);
        assertTrue(viewSite instanceof UstMemoryUsageView);
        final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewSite);
        assertNotNull(chartViewer);
        fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

        final Chart chart = getChart();
        assertNotNull(chart);

        checkAllEntries();

        SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 3, chart, "No data available");
        chartViewer.setNbPoints(50);

        /* Test data model*/
        SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, FIRST_SERIES_NAME, SECOND_SERIES_NAME, THIRD_SERIES_NAME, FOURTH_SERIES_NAME), "resources/memory-res50.json", "Chart data is not valid");

        /* Test type, style and color of series */
        verifyChartStyle();
    }

    private void verifyChartStyle() {
        verifySeriesStyle(FIRST_SERIES_NAME, ISeries.SeriesType.LINE, RED, LineStyle.SOLID, false);
        verifySeriesStyle(SECOND_SERIES_NAME, ISeries.SeriesType.LINE, MAGENTA, LineStyle.SOLID, false);
        verifySeriesStyle(THIRD_SERIES_NAME, ISeries.SeriesType.LINE, GREEN, LineStyle.SOLID, false);
        verifySeriesStyle(FOURTH_SERIES_NAME, ISeries.SeriesType.LINE, GREEN_BLUE, LineStyle.SOLID, false);
    }

    /**
     * Ensure that the tree is loaded and then check all entries
     */
    private void checkAllEntries() {
        SWTBot bot = getSWTBotView().bot();

        SWTBotUtils.waitUntil(b -> b.tree().visibleRowCount() == 5, bot,
                "Incorrect number of tree entries, expected 5, was " + bot.tree().visibleRowCount());

        for (SWTBotTreeItem entry : bot.tree().getAllItems()) {
            entry.check();
        }
    }

    @Override
    protected @NonNull String getMainSeriesName() {
        return FIRST_SERIES_NAME;
    }

    @Override
    protected @NonNull String getTitle() {
        return TITLE;
    }

    @Override
    protected String getViewID() {
        return UstMemoryUsageView.ID;
    }

    @Override
    protected ITmfTrace getTestTrace() {
        return CtfTmfTestTraceUtils.getTrace(CtfTestTrace.MEMORY_ANALYSIS);
    }

    @Override
    protected void disposeTestTrace() {
        CtfTmfTestTraceUtils.dispose(CtfTestTrace.MEMORY_ANALYSIS);
    }
}

Back to the top