Cleanup: remove private babeltrace.h
[babeltrace.git] / tests / plugins / test_dwarf.c
index 59a892dd28cdfaa6e87f90055e8049b716a96ea9..abb72bba6051e516404fb16b6140a9ac4c97150a 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <fcntl.h>
+#include <glib.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
 #include <lttng-utils/debug-info/dwarf.h>
 #include "tap/tap.h"
 
-#define NR_TESTS 15
+#define NR_TESTS 17
 
+#define SO_NAME "libhello_so"
+#define DWARF_DIR_NAME "dwarf_full"
+#define ELF_DIR_NAME "elf_only"
+
+/*
+ * Test that we fail on an ELF file without DWARF.
+ */
+static
+void test_bt_no_dwarf(const char *data_dir)
+{
+       int fd;
+       char *path;
+       Dwarf *dwarf_info = NULL;
+
+       path = g_build_filename(data_dir, ELF_DIR_NAME, SO_NAME, NULL);
+       if (path == NULL) {
+               diag("Failed to allocate memory for path");
+               exit(EXIT_FAILURE);
+       }
+
+       fd = open(path, O_RDONLY);
+       ok(fd >= 0, "Open ELF file %s", path);
+       if (fd < 0) {
+               skip(1, "dwarf_begin failed as expected");
+       } else {
+               dwarf_info = dwarf_begin(fd, DWARF_C_READ);
+               ok(dwarf_info == NULL, "dwarf_begin failed as expected");
+       }
+
+       if (dwarf_info != NULL) {
+               dwarf_end(dwarf_info);
+       }
+       close(fd);
+       g_free(path);
+}
+
+/*
+ * Test with a proper ELF file with DWARF.
+ */
 static
 void test_bt_dwarf(const char *data_dir)
 {
        int fd, ret, tag;
-       char path[PATH_MAX];
+       char *path;
        char *die_name = NULL;
        struct bt_dwarf_cu *cu = NULL;
        struct bt_dwarf_die *die = NULL;
        Dwarf *dwarf_info = NULL;
 
-       snprintf(path, PATH_MAX, "%s/libhello_so", data_dir);
+       path = g_build_filename(data_dir, DWARF_DIR_NAME, SO_NAME, NULL);
+       if (path == NULL) {
+               diag("Failed to allocate memory for path");
+               exit(EXIT_FAILURE);
+       }
 
        fd = open(path, O_RDONLY);
        ok(fd >= 0, "Open DWARF file %s", path);
@@ -97,6 +141,7 @@ void test_bt_dwarf(const char *data_dir)
        dwarf_end(dwarf_info);
        free(die_name);
        close(fd);
+       g_free(path);
 }
 
 int main(int argc, char **argv)
@@ -111,6 +156,7 @@ int main(int argc, char **argv)
                data_dir = argv[1];
        }
 
+       test_bt_no_dwarf(data_dir);
        test_bt_dwarf(data_dir);
 
        return EXIT_SUCCESS;
This page took 0.025603 seconds and 4 git commands to generate.