lttng2.ust.ui: test symbol loading from conflicting mapping files

Add new SWTBot test which resolves symbols from two files who share the
same addresses.

Change-Id: I68633ab55c5bed2bee3bbb234ecd79c96fa17d87
Signed-off-by: Mikael Ferland <mikael.ferland@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/99031
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/cyg-profile-mapping.txt b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/cyg-profile-mapping.txt
index 7960d50..81249c8 100644
--- a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/cyg-profile-mapping.txt
+++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/cyg-profile-mapping.txt
@@ -13,7 +13,6 @@
 00000000004019f0 t deregister_tm_clones
 0000000000401a60 t __do_global_dtors_aux
 0000000000605de8 t __do_global_dtors_aux_fini_array_entry
-00000000004033a7 t draw
 0000000000403760 t draw_frame
 000000000040357a t draw_gears
 0000000000606238 D __dso_handle
diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/dummy-mapping.txt b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/dummy-mapping.txt
index 90010cb..e370562 100644
--- a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/dummy-mapping.txt
+++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/shared/org/eclipse/tracecompass/tmf/ctf/core/tests/shared/dummy-mapping.txt
@@ -8,3 +8,8 @@
 0000000000401aac t current_time
                  U __cyg_profile_func_enter@@GLIBC_2.2.5
                  U __cyg_profile_func_exit@@GLIBC_2.2.5
+000000000040472b T mainB
+00000000004045c8 t event_loopB
+0000000000403760 t draw_frameB
+000000000040357a t draw_gearsB
+00000000004033a7 t drawB
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/CallStackViewTest.java b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/CallStackViewTest.java
index 7c9d61e..ffd856b 100644
--- a/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/CallStackViewTest.java
+++ b/lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/CallStackViewTest.java
@@ -8,7 +8,7 @@
  *
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
- *   Mikael Ferland - Add test for BasicSymbolProvider dialog
+ *   Mikael Ferland - Add tests for BasicSymbolProvider dialog
  *******************************************************************************/
 
 package org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests;
@@ -78,6 +78,11 @@
     private static SWTWorkbenchBot fBot;
 
     /**
+     * Timestamp for loading mapping files test
+     */
+    private static final long TIMESTAMP = 1378850463804917148l;
+
+    /**
      * Timestamps of consecutive events in the trace
      */
     private static final long TIMESTAMPS[] = new long[] {
@@ -91,7 +96,7 @@
             1378850463804903168l,
             1378850463804903766l,
             1378850463804904165l,
-            1378850463804904970l,
+            1378850463804904970l
     };
 
     /**
@@ -303,29 +308,17 @@
      *
      * @throws IOException
      *             Missing file
-     *
-     * @author Mikael Ferland
      */
     @Test
     public void testManipulatingMappingFiles() throws IOException {
-        // 1- Open symbol provider dialog
-        final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
-        viewBot.setFocus();
-        viewBot.toolbarButton(CONFIGURE_SYMBOL_PROVIDERS).click();
-        String shellTitle = "Symbol mapping";
-        fBot.waitUntil(Conditions.shellIsActive(shellTitle));
+        openSymbolProviderDialog();
 
-        // 2- Open valid mapping files and invalid mapping file
+        // 1- Open valid mapping files and invalid mapping file
         Object mapObjA = CtfTmfTestTraceUtils.class.getResource("cyg-profile-mapping.txt");
         Object mapObjB = CtfTmfTestTraceUtils.class.getResource("dummy-mapping.txt");
         Object mapObjC = CtfTmfTestTraceUtils.class.getResource("invalid-cyg-profile-mapping.txt");
         Object mapObjD = CtfTmfTestTraceUtils.class.getResource("random.out");
         Object mapObjE = CtfTmfTestTraceUtils.class.getResource("win32Random.exe");
-        assertTrue(mapObjA instanceof URL);
-        assertTrue(mapObjB instanceof URL);
-        assertTrue(mapObjC instanceof URL);
-        assertTrue(mapObjD instanceof URL);
-        assertTrue(mapObjE instanceof URL);
         URL mapUrlA = (URL) mapObjA;
         URL mapUrlB = (URL) mapObjB;
         URL mapUrlC = (URL) mapObjC;
@@ -339,7 +332,7 @@
         String[] overrideFiles = { absoluteFileA, absoluteFileA, absoluteFileB, absoluteFileC, absoluteFileD, absoluteFileE };
         TmfFileDialogFactory.setOverrideFiles(overrideFiles);
 
-        final SWTBot symbolDialog = fBot.shell(shellTitle).bot();
+        final SWTBot symbolDialog = fBot.shell("Symbol mapping").bot();
         symbolDialog.button("Add...").click();
         final SWTBot errorDialog = fBot.shell("Import failure").bot();
         errorDialog.button("OK").click();
@@ -350,7 +343,7 @@
         assertEquals(table.getTableItem(2).getText(), absoluteFileD);
         assertEquals(table.getTableItem(3).getText(), absoluteFileE);
 
-        // 3- Change priority of mapping files
+        // 2- Change priority of mapping files
         table.select(0);
         symbolDialog.button("Down").click().click().click();
         assertEquals(table.getTableItem(0).getText(), absoluteFileB);
@@ -363,16 +356,51 @@
         assertEquals(table.getTableItem(2).getText(), absoluteFileD);
         assertEquals(table.getTableItem(3).getText(), absoluteFileE);
 
-        // 4- Remove multiple mapping files
+        // 3- Remove multiple mapping files
         table.select(0, 1);
         symbolDialog.button("Remove").click();
         assertEquals(table.rowCount(), 2);
 
-        // 5- Close symbol provider dialog
+        // 4- Close symbol provider dialog
         symbolDialog.button("Cancel").click();
     }
 
     /**
+     * Test loading conflicting mapping files.
+     *
+     * @throws IOException
+     *             Missing file
+     */
+    @Test
+    public void testLoadingMappingFiles() throws IOException {
+        openSymbolProviderDialog();
+
+        // 1- Open conflicting mapping files
+        Object mapObjA = CtfTmfTestTraceUtils.class.getResource("cyg-profile-mapping.txt");
+        Object mapObjB = CtfTmfTestTraceUtils.class.getResource("dummy-mapping.txt");
+        URL mapUrlA = (URL) mapObjA;
+        URL mapUrlB = (URL) mapObjB;
+        String absoluteFileA = FileLocator.toFileURL(mapUrlA).getFile();
+        String absoluteFileB = FileLocator.toFileURL(mapUrlB).getFile();
+        String[] overrideFiles = { absoluteFileA, absoluteFileB };
+        TmfFileDialogFactory.setOverrideFiles(overrideFiles);
+        final SWTBot symbolDialog = fBot.shell("Symbol mapping").bot();
+        symbolDialog.button("Add...").click();
+        symbolDialog.button("OK").click();
+
+        // 2- Ensure symbols are loaded and prioritized
+        goToTime(TIMESTAMP);
+        assertEquals(Arrays.asList("main", "event_loop", "draw_frame", "draw_gears", "drawB"), getVisibleStackFrames(fBot.viewById(CallStackView.ID)));
+    }
+
+    private static void openSymbolProviderDialog() {
+        final SWTBotView viewBot = fBot.viewById(CallStackView.ID);
+        viewBot.setFocus();
+        viewBot.toolbarButton(CONFIGURE_SYMBOL_PROVIDERS).click();
+        fBot.waitUntil(Conditions.shellIsActive("Symbol mapping"));
+    }
+
+    /**
      * Test check callstack at a time with function map
      *
      * @throws IOException