tmf: Mark TmfTraceManager @NonNullByDefault
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / CriticalPathTest.java
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.jdt.annotation.NonNull;
22 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
23 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
24 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
25 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
26 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
27 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
28 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowView;
29 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
30 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
31 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
32 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
33 import org.junit.Before;
34 import org.junit.Test;
35
36 /**
37 * SWTBot tests for Critical Flow view. This test also tests the control flow
38 * view's thread selection as the two views are tightly coupled.
39 *
40 * @author Matthew Khouzam
41 */
42 public class CriticalPathTest extends KernelTestBase {
43
44 private static final int TID_NO = 338;
45 private static final String TID = String.valueOf(TID_NO);
46 private static final String PROCESS = "weston";
47 private static final @NonNull String CP_ID = "org.eclipse.linuxtools.tmf.analysis.graph.ui.criticalpath.view.criticalpathview";
48 private SWTBotView fViewBotCfv;
49 private SWTBotView fViewBotCp;
50
51 /**
52 * Before Test
53 */
54 @Override
55 @Before
56 public void before() {
57 try {
58 String traceName = Paths.get(FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).toURI()).toString();
59 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, traceName, KERNEL_TRACE_TYPE);
60 } catch (IOException | URISyntaxException e) {
61 fail(e.getMessage());
62 }
63 SWTBotUtils.activateEditor(fBot, "bug446190");
64 fViewBotCfv = fBot.viewById(ControlFlowView.ID);
65 SWTBotUtils.openView(CP_ID);
66 fViewBotCp = fBot.viewById(CP_ID);
67 fViewBotCp.show();
68 fViewBotCfv.show();
69 fViewBotCfv.setFocus();
70 }
71
72 /**
73 * test the behavior of the critical path for a thread selection signal from
74 * the control flow view
75 */
76 @Test
77 public void testFull() {
78 SWTBotTree treeCfv = fViewBotCfv.bot().tree();
79 SWTBotTree treeCp = fViewBotCp.bot().tree();
80 assertNotNull(treeCfv.widget);
81 assertNotNull(treeCp.widget);
82 SWTBotTreeItem[] allItems = treeCp.getAllItems();
83 for (int i = 0; i < allItems.length; i++) {
84 assertEquals(0, allItems[i].getNodes().size());
85 }
86
87 ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
88 assertNotNull(trace);
89 SWTBotTreeItem item = treeCfv.getTreeItem(trace.getName());
90 assertNotNull(item);
91 item = item.getNode("systemd");
92 assertNotNull(item);
93 item = item.getNode("we");
94 assertNotNull(item);
95 item = item.getNode(PROCESS);
96 assertNotNull(item);
97 final SWTBotTreeItem treeItem = item;
98 UIThreadRunnable.syncExec(() -> treeCfv.widget.setTopItem(treeItem.widget));
99 item.click();
100
101 SWTBotMenu menu = item.contextMenu("Follow " + PROCESS + "/" + TID);
102 assertEquals("Follow " + PROCESS + "/" + TID, menu.getText());
103 menu.click();
104 fBot.waitUntil(new DefaultCondition() {
105
106 private final String EXPECTED_TREE_TEXT = "[" + PROCESS + "," + TID + "]";
107
108 @Override
109 public boolean test() throws Exception {
110 SWTBotTreeItem[] items = treeCp.getAllItems();
111 return EXPECTED_TREE_TEXT.equals(items[0].getNode(0).getText());
112 }
113
114 @Override
115 public String getFailureMessage() {
116 return "Could not find " + EXPECTED_TREE_TEXT + " in Critical Path view";
117 }
118 });
119 }
120 }
This page took 0.033071 seconds and 5 git commands to generate.