lttng.ui: Add test in symbol map test to verify names
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / ust / ui / swtbot / tests / CallStackViewTest.java
index 5228de6017124c973af2d68325ae1cb93335d941..de4ce52a3f7d1aaba00b00d4b05cb9885be5b6b3 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -15,34 +15,45 @@ package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 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.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory;
 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.tests.shared.WaitUtils;
 import org.eclipse.tracecompass.tmf.ui.views.callstack.CallStackView;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -65,7 +76,7 @@ public class CallStackViewTest {
     /**
      * Timestamps of consecutive events in the trace
      */
-    private static final long TIMESTAMPS[] =  new long[] {
+    private static final long TIMESTAMPS[] = new long[] {
             1378850463804898643l,
             1378850463804899057l,
             1378850463804900219l,
@@ -83,44 +94,55 @@ public class CallStackViewTest {
      * Stack frames of consecutive events in the trace
      */
     private static final String[] STACK_FRAMES[] = new String[][] {
-        {"40472b", "4045c8", "404412", "", ""},
-        {"40472b", "4045c8", "404412", "40392b", ""},
-        {"40472b", "4045c8", "404412", "", ""},
-        {"40472b", "4045c8", "", "", ""},
-        {"40472b", "4045c8", "404412", "", ""},
-        {"40472b", "4045c8", "404412", "40392b", ""},
-        {"40472b", "4045c8", "404412", "", ""},
-        {"40472b", "4045c8", "", "", ""},
-        {"40472b", "4045c8", "404412", "", ""},
-        {"40472b", "4045c8", "404412", "40392b", ""},
-        {"40472b", "4045c8", "404412", "", ""},
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "0x40392b", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
+            { "0x40472b", "0x4045c8", "", "", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "0x40392b", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
+            { "0x40472b", "0x4045c8", "", "", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "0x40392b", "" },
+            { "0x40472b", "0x4045c8", "0x404412", "", "" },
     };
 
     /** Tooltips of the toolbar buttons */
 
-    private static final String ALIGN_VIEWS = "Align Views";
-    private static final String IMPORT_BINARY = "Import a binary file containing debugging symbols";
-    private static final String IMPORT_TEXT = "Import a text file containing the mapping between addresses and function names";
+    private static final @NonNull String ALIGN_VIEWS = "Align Views";
+    private static final @NonNull String CONFIGURE_SYMBOL_PROVIDERS = "Configure how the addresses are mapped to function names";
     // Separator
-    private static final String SORT_BY_NAME = "Sort threads by thread name";
-    private static final String SORT_BY_ID = "Sort threads by thread id";
-    private static final String SORT_BY_START = "Sort threads by start time";
+    private static final @NonNull String SORT_BY_NAME = "Sort threads by thread name";
+    private static final @NonNull String SORT_BY_ID = "Sort threads by thread id";
+    private static final @NonNull String SORT_BY_START = "Sort threads by start time";
     // Separator
-    private static final String RESET_TIME_SCALE = "Reset the Time Scale to Default";
-    private static final String SELECT_PREVIOUS_EVENT = "Select Previous Event";
-    private static final String SELECT_NEXT_EVENT = "Select Next Event";
-    private static final String SELECT_PREVIOUS_ITEM = "Select Previous Item";
-    private static final String SELECT_NEXT_ITEM = "Select Next Item";
-    private static final String ZOOM_IN = "Zoom In";
-    private static final String ZOOM_OUT = "Zoom Out";
+    private static final @NonNull String SHOW_VIEW_FILTERS = "Show View Filters";
+    // Separator
+    private static final @NonNull String RESET_TIME_SCALE = "Reset the Time Scale to Default";
+    private static final @NonNull String SELECT_PREVIOUS_STATE_CHANGE = "Select Previous State Change";
+    private static final @NonNull String SELECT_NEXT_STATE_CHANGE = "Select Next State Change";
+    // Separator
+    private static final @NonNull String ADD_BOOKMARK = "Add Bookmark...";
+    private static final @NonNull String PREVIOUS_MARKER = "Previous Marker";
+    private static final @NonNull String NEXT_MARKER = "Next Marker";
+    // Separator
+    private static final @NonNull String SELECT_PREVIOUS_ITEM = "Select Previous Item";
+    private static final @NonNull String SELECT_NEXT_ITEM = "Select Next Item";
+    private static final @NonNull String ZOOM_IN = "Zoom In";
+    private static final @NonNull String ZOOM_OUT = "Zoom Out";
     // Separator
     private static final String PIN_VIEW = "Pin View";
     private static final List<String> TOOLBAR_BUTTONS_TOOLTIPS = ImmutableList.of(
-            ALIGN_VIEWS, IMPORT_BINARY, IMPORT_TEXT,
+            ALIGN_VIEWS, CONFIGURE_SYMBOL_PROVIDERS,
             "",
             SORT_BY_NAME, SORT_BY_ID, SORT_BY_START,
             "",
-            RESET_TIME_SCALE, SELECT_PREVIOUS_EVENT, SELECT_NEXT_EVENT,
+            SHOW_VIEW_FILTERS,
+            "",
+            RESET_TIME_SCALE, SELECT_PREVIOUS_STATE_CHANGE, SELECT_NEXT_STATE_CHANGE,
+            "",
+            ADD_BOOKMARK, PREVIOUS_MARKER, NEXT_MARKER,
+            "",
             SELECT_PREVIOUS_ITEM, SELECT_NEXT_ITEM, ZOOM_IN, ZOOM_OUT,
             "",
             PIN_VIEW);
@@ -130,7 +152,7 @@ public class CallStackViewTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
@@ -142,7 +164,7 @@ public class CallStackViewTest {
 
         SWTBotUtils.switchToTracingPerspective();
         /* finish waiting for eclipse to load */
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
     }
 
     /**
@@ -153,12 +175,11 @@ public class CallStackViewTest {
         SWTBotUtils.createProject(PROJECT_NAME);
         SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
         assertNotNull(treeItem);
-        final CtfTmfTestTrace cygProfile = CtfTmfTestTrace.CYG_PROFILE;
-        assumeTrue(cygProfile.exists());
-        final File file = new File(cygProfile.getTrace().getPath());
+        final CtfTestTrace cygProfile = CtfTestTrace.CYG_PROFILE;
+        final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath());
         SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID);
         SWTBotUtils.openView(CallStackView.ID);
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
     }
 
     /**
@@ -176,14 +197,15 @@ public class CallStackViewTest {
     @Test
     public void testOpenCallstack() {
         String node = "glxgears-cyg-profile";
+        String processName = "UNKNOWN";
         String childName = "glxgears-16073";
-        List<String> expected = ImmutableList.of("40472b", "", "", "", "");
+        List<String> expected = ImmutableList.of("0x40472b", "", "", "", "");
 
         SWTBotView viewBot = fBot.viewById(CallStackView.ID);
         viewBot.setFocus();
         final SWTBotView viewBot1 = viewBot;
         SWTBotTree tree = viewBot1.bot().tree();
-        SWTBotTreeItem treeItem = tree.getTreeItem(node);
+        SWTBotTreeItem treeItem = tree.getTreeItem(node).getNode(processName);
         assertEquals(childName, treeItem.getNodes().get(0));
         List<String> names = treeItem.getNode(childName).getNodes();
         assertEquals(expected, names);
@@ -198,7 +220,7 @@ public class CallStackViewTest {
 
         final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
         viewBot.setFocus();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
         List<String> names = getVisibleStackFrames(viewBot);
         assertArrayEquals(STACK_FRAMES[0], names.toArray());
     }
@@ -214,32 +236,32 @@ public class CallStackViewTest {
         final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
         // forward 10 times
         for (int i = 0; i < 10; i++) {
-            viewBot.toolbarPushButton(SELECT_NEXT_EVENT).click();
+            viewBot.toolbarPushButton(SELECT_NEXT_STATE_CHANGE).click();
             currentEventOffset++;
             fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
-            SWTBotUtils.waitForJobs();
+            WaitUtils.waitForJobs();
             assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
 
         }
         // back twice
         for (int i = 0; i < 2; i++) {
-            viewBot.toolbarPushButton(SELECT_PREVIOUS_EVENT).click();
+            viewBot.toolbarPushButton(SELECT_PREVIOUS_STATE_CHANGE).click();
             currentEventOffset--;
             fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
-            SWTBotUtils.waitForJobs();
+            WaitUtils.waitForJobs();
             assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
         }
         // move up and down once to make sure it doesn't explode
         viewBot.toolbarPushButton(SELECT_PREVIOUS_ITEM).click();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
         viewBot.toolbarPushButton(SELECT_NEXT_ITEM).click();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
 
         // Zoom in and out too
         viewBot.toolbarPushButton(ZOOM_IN).click();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
         viewBot.toolbarPushButton(ZOOM_OUT).click();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
     }
 
     /**
@@ -255,44 +277,63 @@ public class CallStackViewTest {
         viewBot.toolbarToggleButton(SORT_BY_ID).click();
         viewBot.toolbarToggleButton(SORT_BY_START).click();
         viewBot.setFocus();
-        SWTBotUtils.waitForJobs();
+        WaitUtils.waitForJobs();
         List<String> names = getVisibleStackFrames(viewBot);
         assertArrayEquals(STACK_FRAMES[0], names.toArray());
     }
 
     private static List<String> getVisibleStackFrames(final SWTBotView viewBot) {
         SWTBotTree tree = viewBot.bot().tree();
-        List<String> names = new ArrayList<>();
-        for (SWTBotTreeItem swtBotTreeItem : tree.getAllItems()) {
-            for (SWTBotTreeItem items : swtBotTreeItem.getItems()) {
-                for (SWTBotTreeItem item : items.getItems()) {
-                    names.add(item.cell(0));
-                }
-            }
-        }
-        return names;
+        return Arrays.stream(tree.getAllItems())
+                // Process entries
+                .flatMap(item -> Arrays.stream(item.getItems()))
+                // Thread entries
+                .flatMap(item -> Arrays.stream(item.getItems()))
+                // Callstack entries
+                .flatMap(item -> Arrays.stream(item.getItems()))
+                .map(item -> item.cell(0))
+                .collect(Collectors.toList());
     }
 
     private static void goToTime(long timestamp) {
         SWTBotTable table = fBot.activeEditor().bot().table();
         table.setFocus();
-        TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table.widget, new TmfNanoTimestamp(timestamp)));
+        TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table.widget, TmfTimestamp.fromNanos(timestamp)));
         fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, timestamp));
     }
 
     /**
      * Test check callstack at a time with function map
+     *
+     * @throws IOException
+     *             Missing file
      */
-    @Ignore
     @Test
-    public void testGoToTimeAndCheckStackWithNames() {
+    public void testGoToTimeAndCheckStackWithNames() throws IOException {
         goToTime(TIMESTAMPS[0]);
         final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
         viewBot.setFocus();
-        // no way to load mappings yet! :(
         SWTBotTree tree = viewBot.bot().tree();
-        SWTBotUtils.waitForJobs();
+        Object mapObj = CtfTmfTestTraceUtils.class.getResource("cyg-profile-mapping.txt");
+        assertTrue(mapObj instanceof URL);
+        URL mapUrl = (URL) mapObj;
+
+        String absoluteFile = FileLocator.toFileURL(mapUrl).getFile();
+        TmfFileDialogFactory.setOverrideFiles(absoluteFile);
+        viewBot.toolbarButton("Configure how the addresses are mapped to function names").click();
+        String shellTitle = "Symbol mapping";
+        fBot.waitUntil(Conditions.shellIsActive(shellTitle));
+        SWTBot shellBot = fBot.shell(shellTitle).bot();
+        SWTBotShell activeShell = shellBot.activeShell();
+        shellBot.radio(1).click();
+        shellBot.button("Browse...", 1).click();
+        shellBot.button("OK").click();
+        shellBot.waitUntil(Conditions.shellCloses(activeShell));
+        // FIXME: remove when updates are propagated
+        goToTime(TIMESTAMPS[0]);
+        WaitUtils.waitForJobs();
         List<String> names = new ArrayList<>();
+
         for (SWTBotTreeItem swtBotTreeItem : tree.getAllItems()) {
             for (SWTBotTreeItem items : swtBotTreeItem.getItems()) {
                 for (SWTBotTreeItem item : items.getItems()) {
@@ -300,6 +341,9 @@ public class CallStackViewTest {
                 }
             }
         }
+        List<String> functions = getVisibleStackFrames(viewBot);
+        assertEquals(ImmutableList.of("glxgears-16073"), names);
+        assertEquals(ImmutableList.of("main", "event_loop", "handle_event", "", ""), functions);
     }
 
     /**
This page took 0.028166 seconds and 5 git commands to generate.