tests: Add expected failure test to test_dwarf
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 29 May 2019 19:17:31 +0000 (15:17 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Jun 2019 21:24:21 +0000 (17:24 -0400)
Add a test to make sure we fail when opening an ELF file with no DWARF
information.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Change-Id: I59419a94fa0bca5589600e7b0691d291531cfa51
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1349
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
tests/plugins/test_dwarf.c

index e4485846b9acdfd48f6fd57c5a81c002703f94a5..fa475e104069c38c706e40b42654087f1ca48753 100644 (file)
 #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)
 {
@@ -45,6 +81,7 @@ void test_bt_dwarf(const char *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);
        }
 
@@ -118,6 +155,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.025299 seconds and 4 git commands to generate.