From 98702638206e1245ea50dfb2ed668ed7d9e1fcf3 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 29 May 2019 15:17:31 -0400 Subject: [PATCH] tests: Add expected failure test to test_dwarf Add a test to make sure we fail when opening an ELF file with no DWARF information. Signed-off-by: Michael Jeanson Change-Id: I59419a94fa0bca5589600e7b0691d291531cfa51 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1349 Tested-by: jenkins Reviewed-by: Philippe Proulx Reviewed-by: Francis Deslauriers --- tests/plugins/test_dwarf.c | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/plugins/test_dwarf.c b/tests/plugins/test_dwarf.c index e4485846..fa475e10 100644 --- a/tests/plugins/test_dwarf.c +++ b/tests/plugins/test_dwarf.c @@ -28,11 +28,47 @@ #include #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; -- 2.34.1