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