tests: Build new x86_64-linux-gnu debug-info artifacts
[babeltrace.git] / tests / plugins / test_bin_info.c
index b32f64fa16632dc951ab6b5499823c27130a40cf..5bf43da020d1f249f20fdb8b5d8d4316e6e92888 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include <babeltrace/assert-internal.h>
 #include <lttng-utils/debug-info/bin-info.h>
+
 #include "tap/tap.h"
 
 #define NR_TESTS 36
 #define SO_NAME "libhello_so"
-#define SO_NAME_ELF "libhello_elf_so"
-#define SO_NAME_BUILD_ID "libhello_build_id_so"
-#define SO_NAME_DEBUG_LINK "libhello_debug_link_so"
+
+#define DWARF_DIR_NAME "dwarf_full"
+#define ELF_DIR_NAME "elf_only"
+#define BUILDID_DIR_NAME "build_id"
+#define DEBUGLINK_DIR_NAME "debug_link"
+
 #define SO_LOW_ADDR 0x400000
 #define SO_MEMSZ 0x400000
-#define FUNC_FOO_ADDR 0x4014ee
-#define FUNC_FOO_LINE_NO 8
-#define FUNC_FOO_FILENAME "/efficios/libhello.c"
-#define FUNC_FOO_TP_ADDR 0x4014d3
-#define FUNC_FOO_TP_LINE_NO 7
-#define FUNC_FOO_TP_FILENAME "/efficios/libhello.c"
-#define FUNC_FOO_ADDR_ELF 0x4013ef
-#define FUNC_FOO_ADDR_DBG_LINK 0x40148e
-#define FUNC_FOO_NAME "foo+0xc3"
-#define FUNC_FOO_NAME_ELF "foo+0x24"
+#define FUNC_FOO_ADDR 0x402367
+#define FUNC_FOO_LINE_NO 36
+#define FUNC_FOO_FILENAME "./libhello.c"
+#define FUNC_FOO_TP_ADDR 0x402300
+#define FUNC_FOO_TP_LINE_NO 35
+#define FUNC_FOO_TP_FILENAME "./libhello.c"
+#define FUNC_FOO_ADDR_ELF 0x402367
+#define FUNC_FOO_ADDR_DBG_LINK 0x402367
+#define FUNC_FOO_NAME "foo+0xf0"
+#define FUNC_FOO_NAME_ELF "foo+0xf0"
 #define BUILD_ID_LEN 20
 
 char *opt_debug_info_dir;
 char *opt_debug_info_target_prefix;
 
 static
-void test_bin_info_build_id(const char *data_dir)
+void test_bin_info_build_id(const char *bin_info_dir)
 {
        int ret;
-       char path[PATH_MAX];
+       char *data_dir, *bin_path;
        char *func_name = NULL;
        struct bin_info *bin = NULL;
        struct source_location *src_loc = NULL;
+       struct bt_fd_cache fdc;
        uint8_t build_id[BUILD_ID_LEN] = {
                0xcd, 0xd9, 0x8c, 0xdd, 0x87, 0xf7, 0xfe, 0x64, 0xc1, 0x3b,
                0x6d, 0xaa, 0xd5, 0x53, 0x98, 0x7e, 0xaf, 0xd4, 0x0c, 0xbb
@@ -63,9 +70,16 @@ void test_bin_info_build_id(const char *data_dir)
 
        diag("bin-info tests - separate DWARF via build ID");
 
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_BUILD_ID);
+       data_dir = g_build_filename(bin_info_dir, BUILDID_DIR_NAME, NULL);
+       bin_path = g_build_filename(bin_info_dir, BUILDID_DIR_NAME, SO_NAME, NULL);
 
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       if (data_dir == NULL || bin_path == NULL) {
+               exit(EXIT_FAILURE);
+       }
+
+       ret = bt_fd_cache_init(&fdc);
+       BT_ASSERT(ret == 0);
+       bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
        ok(bin != NULL, "bin_info_create successful");
 
        /* Test setting build_id */
@@ -97,24 +111,36 @@ void test_bin_info_build_id(const char *data_dir)
        }
 
        bin_info_destroy(bin);
+       bt_fd_cache_fini(&fdc);
+       g_free(data_dir);
+       g_free(bin_path);
 }
 
 static
-void test_bin_info_debug_link(const char *data_dir)
+void test_bin_info_debug_link(const char *bin_info_dir)
 {
        int ret;
-       char path[PATH_MAX];
+       char *data_dir, *bin_path;
        char *func_name = NULL;
        struct bin_info *bin = NULL;
        struct source_location *src_loc = NULL;
-       char *dbg_filename = "libhello_debug_link_so.debug";
-       uint32_t crc = 0xe55c2b98;
+       char *dbg_filename = "libhello_so.debug";
+       uint32_t crc = 0x289a8fdc;
+       struct bt_fd_cache fdc;
 
        diag("bin-info tests - separate DWARF via debug link");
 
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_DEBUG_LINK);
+       data_dir = g_build_filename(bin_info_dir, DEBUGLINK_DIR_NAME, NULL);
+       bin_path = g_build_filename(bin_info_dir, DEBUGLINK_DIR_NAME, SO_NAME, NULL);
 
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       if (data_dir == NULL || bin_path == NULL) {
+               exit(EXIT_FAILURE);
+       }
+
+       ret = bt_fd_cache_init(&fdc);
+       BT_ASSERT(ret == 0);
+       bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir,
+                       NULL);
        ok(bin != NULL, "bin_info_create successful");
 
        /* Test setting debug link */
@@ -148,22 +174,33 @@ void test_bin_info_debug_link(const char *data_dir)
        }
 
        bin_info_destroy(bin);
+       bt_fd_cache_fini(&fdc);
+       g_free(data_dir);
+       g_free(bin_path);
 }
 
 static
-void test_bin_info_elf(const char *data_dir)
+void test_bin_info_elf(const char *bin_info_dir)
 {
        int ret;
-       char path[PATH_MAX];
+       char *data_dir, *bin_path;
        char *func_name = NULL;
        struct bin_info *bin = NULL;
        struct source_location *src_loc = NULL;
+       struct bt_fd_cache fdc;
 
        diag("bin-info tests - ELF only");
 
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_ELF);
+       data_dir = g_build_filename(bin_info_dir, ELF_DIR_NAME, NULL);
+       bin_path = g_build_filename(bin_info_dir, ELF_DIR_NAME, SO_NAME, NULL);
+
+       if (data_dir == NULL || bin_path == NULL) {
+               exit(EXIT_FAILURE);
+       }
 
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       ret = bt_fd_cache_init(&fdc);
+       BT_ASSERT(ret == 0);
+       bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
        ok(bin != NULL, "bin_info_create successful");
 
        /* Test function name lookup (with ELF) */
@@ -189,22 +226,34 @@ void test_bin_info_elf(const char *data_dir)
 
        source_location_destroy(src_loc);
        bin_info_destroy(bin);
+       bt_fd_cache_fini(&fdc);
+       g_free(data_dir);
+       g_free(bin_path);
 }
 
 static
-void test_bin_info(const char *data_dir)
+void test_bin_info(const char *bin_info_dir)
 {
        int ret;
-       char path[PATH_MAX];
+       char *data_dir, *bin_path;
        char *func_name = NULL;
        struct bin_info *bin = NULL;
        struct source_location *src_loc = NULL;
+       struct bt_fd_cache fdc;
 
        diag("bin-info tests - DWARF bundled with SO file");
 
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME);
 
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       data_dir = g_build_filename(bin_info_dir, DWARF_DIR_NAME, NULL);
+       bin_path = g_build_filename(bin_info_dir, DWARF_DIR_NAME, SO_NAME, NULL);
+
+       if (data_dir == NULL || bin_path == NULL) {
+               exit(EXIT_FAILURE);
+       }
+
+       ret = bt_fd_cache_init(&fdc);
+       BT_ASSERT(ret == 0);
+       bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
        ok(bin != NULL, "bin_info_create successful");
 
        /* Test bin_info_has_address */
@@ -271,6 +320,9 @@ void test_bin_info(const char *data_dir)
                "bin_info_lookup_source_location - fail on addr not found");
 
        bin_info_destroy(bin);
+       bt_fd_cache_fini(&fdc);
+       g_free(data_dir);
+       g_free(bin_path);
 }
 
 int main(int argc, char **argv)
This page took 0.026487 seconds and 4 git commands to generate.