From: Philippe Proulx Date: Thu, 13 Jun 2019 15:22:26 +0000 (-0400) Subject: Put `flt.lttng-utils.debug-info` tests into their own directory X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=662514648ee42c5c45fe27a0d4702ef825eb4b16;hp=cb0775f4167b5115ce71cf41d4d94719d08ef763 Put `flt.lttng-utils.debug-info` tests into their own directory The goal is to have each component class tests in their own directory under `tests/plugins`. Signed-off-by: Philippe Proulx Change-Id: I3f68d2af9087690c6a34d238197c9bb9e96b021c Reviewed-on: https://review.lttng.org/c/babeltrace/+/1423 Tested-by: jenkins Reviewed-by: Michael Jeanson --- diff --git a/.gitignore b/.gitignore index 282fec39..ed858915 100644 --- a/.gitignore +++ b/.gitignore @@ -30,17 +30,17 @@ /tests/lib/test_graph_topo /tests/lib/trace-ir/test_trace_ir /tests/lib/ctf-writer/test_ctf_writer -/tests/plugins/test_lttng_utils_debug_info -/tests/plugins/test_bin_info_i386-linux-gnu -/tests/plugins/test_bin_info_powerpc-linux-gnu -/tests/plugins/test_bin_info_powerpc64le-linux-gnu -/tests/plugins/test_bin_info_x86_64-linux-gnu -/tests/plugins/test_bin_info -/tests/plugins/test_dwarf_i386-linux-gnu -/tests/plugins/test_dwarf_powerpc-linux-gnu -/tests/plugins/test_dwarf_powerpc64le-linux-gnu -/tests/plugins/test_dwarf_x86_64-linux-gnu -/tests/plugins/test_dwarf +/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info +/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_bin_info +/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu +/tests/plugins/flt.lttng-utils.debug-info/test_dwarf /tests/plugins/src.ctf.fs/query/test_query /tests/plugins/src.ctf.fs/succeed/test_succeed /tests/plugins/src.ctf.fs/succeed/gen-trace-* diff --git a/configure.ac b/configure.ac index 3d6522db..d6617717 100644 --- a/configure.ac +++ b/configure.ac @@ -785,6 +785,7 @@ AC_CONFIG_FILES([ tests/plugins/Makefile tests/plugins/src.ctf.fs/Makefile tests/plugins/src.ctf.fs/succeed/Makefile + tests/plugins/flt.lttng-utils.debug-info/Makefile tests/utils/common.sh tests/utils/diff.sh tests/utils/Makefile @@ -803,15 +804,15 @@ AC_CONFIG_FILES([tests/lib/test_plugin_complete], [chmod +x tests/lib/test_plugi AC_CONFIG_FILES([tests/lib/trace-ir/test_trace_ir], [chmod +x tests/lib/trace-ir/test_trace_ir]) AC_CONFIG_FILES([tests/plugins/src.ctf.fs/query/test_query], [chmod +x tests/plugins/src.ctf.fs/query/test_query]) AC_CONFIG_FILES([tests/plugins/src.ctf.fs/succeed/test_succeed], [chmod +x tests/plugins/src.ctf.fs/succeed/test_succeed]) -AC_CONFIG_FILES([tests/plugins/test_lttng_utils_debug_info], [chmod +x tests/plugins/test_lttng_utils_debug_info]) -AC_CONFIG_FILES([tests/plugins/test_dwarf_i386-linux-gnu], [chmod +x tests/plugins/test_dwarf_i386-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_dwarf_powerpc-linux-gnu], [chmod +x tests/plugins/test_dwarf_powerpc-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_dwarf_powerpc64le-linux-gnu], [chmod +x tests/plugins/test_dwarf_powerpc64le-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_dwarf_x86_64-linux-gnu], [chmod +x tests/plugins/test_dwarf_x86_64-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_bin_info_i386-linux-gnu], [chmod +x tests/plugins/test_bin_info_i386-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_bin_info_powerpc-linux-gnu], [chmod +x tests/plugins/test_bin_info_powerpc-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_bin_info_powerpc64le-linux-gnu], [chmod +x tests/plugins/test_bin_info_powerpc64le-linux-gnu]) -AC_CONFIG_FILES([tests/plugins/test_bin_info_x86_64-linux-gnu], [chmod +x tests/plugins/test_bin_info_x86_64-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu]) +AC_CONFIG_FILES([tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu], [chmod +x tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu]) AS_IF([test "x$enable_python_bindings" = xyes], [ diff --git a/tests/Makefile.am b/tests/Makefile.am index 842a3858..60694d93 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,21 +71,21 @@ if ENABLE_PYTHON_BINDINGS TESTS_PLUGINS += plugins/src.ctf.fs/query/test_query if ENABLE_DEBUG_INFO -TESTS_PLUGINS += plugins/test_lttng_utils_debug_info +TESTS_PLUGINS += plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info endif endif endif if ENABLE_DEBUG_INFO TESTS_PLUGINS += \ - plugins/test_dwarf_i386-linux-gnu \ - plugins/test_dwarf_powerpc-linux-gnu \ - plugins/test_dwarf_powerpc64le-linux-gnu \ - plugins/test_dwarf_x86_64-linux-gnu \ - plugins/test_bin_info_i386-linux-gnu \ - plugins/test_bin_info_powerpc-linux-gnu \ - plugins/test_bin_info_powerpc64le-linux-gnu \ - plugins/test_bin_info_x86_64-linux-gnu + plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu \ + plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu endif TESTS_PYTHON_PLUGIN_PROVIDER = diff --git a/tests/plugins/Makefile.am b/tests/plugins/Makefile.am index e748d4fe..a44f0695 100644 --- a/tests/plugins/Makefile.am +++ b/tests/plugins/Makefile.am @@ -1,35 +1,3 @@ -SUBDIRS = src.ctf.fs -AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(top_srcdir)/src/plugins - -LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la - -dist_check_SCRIPTS = \ - test_lttng_utils_debug_info.py - -noinst_PROGRAMS = - -if !ENABLE_BUILT_IN_PLUGINS -# plugin tests here -endif # !ENABLE_BUILT_IN_PLUGINS - -if ENABLE_DEBUG_INFO -noinst_PROGRAMS += test_dwarf test_bin_info - -test_dwarf_LDADD = \ - $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ - $(top_builddir)/src/fd-cache/libbabeltrace2-fd-cache.la \ - $(top_builddir)/src/logging/libbabeltrace2-logging.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ - $(ELFUTILS_LIBS) \ - $(LIBTAP) -test_dwarf_SOURCES = test_dwarf.c - -test_bin_info_LDADD = \ - $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ - $(top_builddir)/src/fd-cache/libbabeltrace2-fd-cache.la \ - $(top_builddir)/src/logging/libbabeltrace2-logging.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ - $(ELFUTILS_LIBS) \ - $(LIBTAP) -test_bin_info_SOURCES = test_bin_info.c -endif # ENABLE_DEBUG_INFO +SUBDIRS = \ + src.ctf.fs \ + flt.lttng-utils.debug-info diff --git a/tests/plugins/flt.lttng-utils.debug-info/Makefile.am b/tests/plugins/flt.lttng-utils.debug-info/Makefile.am new file mode 100644 index 00000000..4c2fdb09 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/Makefile.am @@ -0,0 +1,34 @@ +AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(top_srcdir)/src/plugins + +LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la + +dist_check_SCRIPTS = \ + test_lttng_utils_debug_info.py + +noinst_PROGRAMS = + +if !ENABLE_BUILT_IN_PLUGINS +# plugin tests here +endif # !ENABLE_BUILT_IN_PLUGINS + +if ENABLE_DEBUG_INFO +noinst_PROGRAMS += test_dwarf test_bin_info + +test_dwarf_LDADD = \ + $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ + $(top_builddir)/src/fd-cache/libbabeltrace2-fd-cache.la \ + $(top_builddir)/src/logging/libbabeltrace2-logging.la \ + $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(ELFUTILS_LIBS) \ + $(LIBTAP) +test_dwarf_SOURCES = test_dwarf.c + +test_bin_info_LDADD = \ + $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ + $(top_builddir)/src/fd-cache/libbabeltrace2-fd-cache.la \ + $(top_builddir)/src/logging/libbabeltrace2-logging.la \ + $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(ELFUTILS_LIBS) \ + $(LIBTAP) +test_bin_info_SOURCES = test_bin_info.c +endif # ENABLE_DEBUG_INFO diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c new file mode 100644 index 00000000..d681ef56 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c @@ -0,0 +1,447 @@ +/* + * test_bin_info.c + * + * Babeltrace SO info tests + * + * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation + * Copyright (c) 2015 Antoine Busque + * Copyright (c) 2019 Michael Jeanson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include + +#include "common/macros.h" +#include "common/assert.h" +#include + +#include "tap/tap.h" + +#define NR_TESTS 57 + +#define SO_NAME "libhello_so" +#define DEBUG_NAME "libhello_so.debug" +#define FUNC_FOO_FILENAME "./libhello.c" +#define FUNC_FOO_PRINTF_NAME_FMT "foo+0x%" PRIx64 +#define FUNC_FOO_NAME_LEN 64 + +#define DWARF_DIR_NAME "dwarf_full" +#define ELF_DIR_NAME "elf_only" +#define BUILDID_DIR_NAME "build_id" +#define DEBUGLINK_DIR_NAME "debug_link" + +/* Lower bound of PIC address mapping */ +#define SO_LOW_ADDR 0x400000 +/* Size of PIC address mapping */ +#define SO_MEMSZ 0x800000 +/* An address outside the PIC mapping */ +#define SO_INV_ADDR 0x200000 + +#define BUILD_ID_HEX_LEN 20 + +static uint64_t opt_func_foo_addr; +static uint64_t opt_func_foo_printf_offset; +static uint64_t opt_func_foo_printf_line_no; +static uint64_t opt_func_foo_tp_offset; +static uint64_t opt_func_foo_tp_line_no; +static uint64_t opt_debug_link_crc; +static gchar *opt_build_id; +static gchar *opt_debug_info_dir; + +static uint64_t func_foo_printf_addr; +static uint64_t func_foo_tp_addr; +static char func_foo_printf_name[FUNC_FOO_NAME_LEN]; +static uint8_t build_id[BUILD_ID_HEX_LEN]; + +static GOptionEntry entries[] = { + {"foo-addr", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_addr, + "Offset to printf in foo", "0xX"}, + {"printf-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_printf_offset, + "Offset to printf in foo", "0xX"}, + {"printf-lineno", 0, 0, G_OPTION_ARG_INT64, + &opt_func_foo_printf_line_no, "Line number to printf in foo", "N"}, + {"tp-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_offset, + "Offset to tp in foo", "0xX"}, + {"tp-lineno", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_line_no, + "Line number to tp in foo", "N"}, + {"debug-link-crc", 0, 0, G_OPTION_ARG_INT64, &opt_debug_link_crc, + "Debug link CRC", "0xX"}, + {"build-id", 0, 0, G_OPTION_ARG_STRING, &opt_build_id, "Build ID", + "XXXXXXXXXXXXXXX"}, + {"debug-info-dir", 0, 0, G_OPTION_ARG_STRING, &opt_debug_info_dir, + "Debug info directory", NULL}, + {NULL}}; + +static +int build_id_to_bin(void) +{ + int ret, len, i; + + if (opt_build_id == NULL) { + goto error; + } + + len = strnlen(opt_build_id, BUILD_ID_HEX_LEN * 2); + if (len != (BUILD_ID_HEX_LEN * 2)) { + goto error; + } + + for (i = 0; i < (len / 2); i++) { + ret = sscanf(opt_build_id + 2 * i, "%02hhx", &build_id[i]); + if (ret != 1) { + goto error; + } + } + + if (i != BUILD_ID_HEX_LEN) { + goto error; + } + + return 0; +error: + return -1; +} + +static +void subtest_has_address(struct bin_info *bin, uint64_t addr) +{ + int ret; + + ret = bin_info_has_address(bin, SO_LOW_ADDR - 1); + ok(ret == 0, "bin_info_has_address - address under SO's range"); + + ret = bin_info_has_address(bin, SO_LOW_ADDR); + ok(ret == 1, "bin_info_has_address - lower bound of SO's range"); + + ret = bin_info_has_address(bin, addr); + ok(ret == 1, "bin_info_has_address - address in SO's range"); + + ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ - 1); + ok(ret == 1, "bin_info_has_address - upper bound of SO's range"); + + ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ); + ok(ret == 0, "bin_info_has_address - address above SO's range"); +} + +static +void subtest_lookup_function_name(struct bin_info *bin, uint64_t addr, + char *func_name) +{ + int ret; + char *_func_name = NULL; + + ret = bin_info_lookup_function_name(bin, addr, &_func_name); + ok(ret == 0, "bin_info_lookup_function_name successful at 0x%x", addr); + if (_func_name) { + ok(strcmp(_func_name, func_name) == 0, + "bin_info_lookup_function_name - correct function name (%s == %s)", + func_name, _func_name); + free(_func_name); + _func_name = NULL; + } else { + skip(1, + "bin_info_lookup_function_name - function name is NULL"); + } + + /* Test function name lookup - erroneous address */ + ret = bin_info_lookup_function_name(bin, SO_INV_ADDR, &_func_name); + ok(ret == -1 && _func_name == NULL, + "bin_info_lookup_function_name - fail on invalid addr"); + if (_func_name) { + free(_func_name); + } +} + +static +void subtest_lookup_source_location(struct bin_info *bin, uint64_t addr, + uint64_t line_no, char *filename) +{ + int ret; + struct source_location *src_loc = NULL; + + ret = bin_info_lookup_source_location(bin, addr, &src_loc); + ok(ret == 0, "bin_info_lookup_source_location successful at 0x%x", + addr); + if (src_loc) { + ok(src_loc->line_no == line_no, + "bin_info_lookup_source_location - correct line_no (%d == %d)", + line_no, src_loc->line_no); + ok(strcmp(src_loc->filename, filename) == 0, + "bin_info_lookup_source_location - correct filename (%s == %s)", + filename, src_loc->filename); + source_location_destroy(src_loc); + src_loc = NULL; + } else { + fail("bin_info_lookup_source_location - src_loc is NULL"); + fail("bin_info_lookup_source_location - src_loc is NULL"); + } + + /* Test source location lookup - erroneous address */ + ret = bin_info_lookup_source_location(bin, SO_INV_ADDR, &src_loc); + ok(ret == -1 && src_loc == NULL, + "bin_info_lookup_source_location - fail on invalid addr"); + if (src_loc) { + source_location_destroy(src_loc); + } +} + +static +void test_bin_info_build_id(const char *bin_info_dir) +{ + int ret; + char *data_dir, *bin_path; + struct bin_info *bin = NULL; + struct bt_fd_cache fdc; + uint8_t invalid_build_id[BUILD_ID_HEX_LEN] = { + 0xa3, 0xfd, 0x8b, 0xff, 0x45, 0xe1, 0xa9, 0x32, 0x15, 0xdd, + 0x6d, 0xaa, 0xd5, 0x53, 0x98, 0x7e, 0xaf, 0xd4, 0x0c, 0xbb + }; + + diag("bin-info tests - separate DWARF via 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); + + if (data_dir == NULL || bin_path == NULL) { + exit(EXIT_FAILURE); + } + + ret = bt_fd_cache_init(&fdc); + if (ret != 0) { + diag("Failed to initialize FD cache"); + exit(EXIT_FAILURE); + } + + bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, + data_dir, NULL); + ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + + /* Test setting invalid build_id */ + ret = bin_info_set_build_id(bin, invalid_build_id, BUILD_ID_HEX_LEN); + ok(ret == -1, "bin_info_set_build_id fail on invalid build_id"); + + /* Test setting correct build_id */ + ret = bin_info_set_build_id(bin, build_id, BUILD_ID_HEX_LEN); + ok(ret == 0, "bin_info_set_build_id successful"); + + /* Test bin_info_has_address */ + subtest_has_address(bin, func_foo_printf_addr); + + /* Test function name lookup (with DWARF) */ + subtest_lookup_function_name(bin, func_foo_printf_addr, + func_foo_printf_name); + + /* Test source location lookup */ + subtest_lookup_source_location(bin, func_foo_printf_addr, + opt_func_foo_printf_line_no, + FUNC_FOO_FILENAME); + + 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 *bin_info_dir) +{ + int ret; + char *data_dir, *bin_path; + struct bin_info *bin = NULL; + struct bt_fd_cache fdc; + + diag("bin-info tests - separate DWARF via 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); + + if (data_dir == NULL || bin_path == NULL) { + exit(EXIT_FAILURE); + } + + ret = bt_fd_cache_init(&fdc); + if (ret != 0) { + diag("Failed to initialize FD cache"); + exit(EXIT_FAILURE); + } + + bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, + data_dir, NULL); + ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + + /* Test setting debug link */ + ret = bin_info_set_debug_link(bin, DEBUG_NAME, opt_debug_link_crc); + ok(ret == 0, "bin_info_set_debug_link successful"); + + /* Test bin_info_has_address */ + subtest_has_address(bin, func_foo_printf_addr); + + /* Test function name lookup (with DWARF) */ + subtest_lookup_function_name(bin, func_foo_printf_addr, + func_foo_printf_name); + + /* Test source location lookup */ + subtest_lookup_source_location(bin, func_foo_printf_addr, + opt_func_foo_printf_line_no, + FUNC_FOO_FILENAME); + + 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 *bin_info_dir) +{ + int ret; + char *data_dir, *bin_path; + struct bin_info *bin = NULL; + struct source_location *src_loc = NULL; + struct bt_fd_cache fdc; + + diag("bin-info tests - ELF only"); + + 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); + } + + ret = bt_fd_cache_init(&fdc); + if (ret != 0) { + diag("Failed to initialize FD cache"); + exit(EXIT_FAILURE); + } + + bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, + data_dir, NULL); + ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + + /* Test bin_info_has_address */ + subtest_has_address(bin, func_foo_printf_addr); + + /* Test function name lookup (with ELF) */ + subtest_lookup_function_name(bin, func_foo_printf_addr, + func_foo_printf_name); + + /* Test source location location - should fail on ELF only file */ + ret = bin_info_lookup_source_location(bin, func_foo_printf_addr, + &src_loc); + ok(ret == -1, + "bin_info_lookup_source_location - fail on ELF only file"); + + 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_bundled(const char *bin_info_dir) +{ + int ret; + char *data_dir, *bin_path; + struct bin_info *bin = NULL; + struct bt_fd_cache fdc; + + diag("bin-info tests - DWARF bundled in SO file"); + + 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); + if (ret != 0) { + diag("Failed to initialize FD cache"); + exit(EXIT_FAILURE); + } + + bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, + data_dir, NULL); + ok(bin != NULL, "bin_info_create successful (%s)", bin_path); + + /* Test bin_info_has_address */ + subtest_has_address(bin, func_foo_printf_addr); + + /* Test function name lookup (with DWARF) */ + subtest_lookup_function_name(bin, func_foo_printf_addr, + func_foo_printf_name); + + /* Test source location lookup */ + subtest_lookup_source_location(bin, func_foo_printf_addr, + opt_func_foo_printf_line_no, + FUNC_FOO_FILENAME); + + /* Test source location lookup - inlined function */ + subtest_lookup_source_location(bin, func_foo_tp_addr, + opt_func_foo_tp_line_no, + FUNC_FOO_FILENAME); + + bin_info_destroy(bin); + bt_fd_cache_fini(&fdc); + g_free(data_dir); + g_free(bin_path); +} + +int main(int argc, char **argv) +{ + int ret; + GError *error = NULL; + GOptionContext *context; + + context = g_option_context_new("- bin info test"); + g_option_context_add_main_entries(context, entries, NULL); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + fprintf(stderr, "option parsing failed: %s\n", error->message); + exit(EXIT_FAILURE); + } + + g_snprintf(func_foo_printf_name, FUNC_FOO_NAME_LEN, + FUNC_FOO_PRINTF_NAME_FMT, opt_func_foo_printf_offset); + func_foo_printf_addr = + SO_LOW_ADDR + opt_func_foo_addr + opt_func_foo_printf_offset; + func_foo_tp_addr = + SO_LOW_ADDR + opt_func_foo_addr + opt_func_foo_tp_offset; + + if (build_id_to_bin()) { + fprintf(stderr, "Failed to parse / missing build id\n"); + exit(EXIT_FAILURE); + } + + plan_tests(NR_TESTS); + + ret = bin_info_init(); + ok(ret == 0, "bin_info_init successful"); + + test_bin_info_elf(opt_debug_info_dir); + test_bin_info_bundled(opt_debug_info_dir); + test_bin_info_build_id(opt_debug_info_dir); + test_bin_info_debug_link(opt_debug_info_dir); + + return EXIT_SUCCESS; +} diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu.in new file mode 100644 index 00000000..9b58d63c --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu.in @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/i386-linux-gnu" + +"${curdir}/test_bin_info" \ + --foo-addr=0x1c8d \ + --printf-offset=0xda \ + --printf-lineno=36 \ + --tp-offset=0x12 \ + --tp-lineno=35 \ + --debug-link-crc=0xdeead493 \ + --debug-info-dir "$debug_info_data" \ + --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu.in new file mode 100644 index 00000000..d0948aa6 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc-linux-gnu.in @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc-linux-gnu" + +"${curdir}/test_bin_info" \ + --foo-addr=0x23bc \ + --printf-offset=0x114 \ + --printf-lineno=36 \ + --tp-offset=0x28 \ + --tp-lineno=35 \ + --debug-link-crc=0xd7b98958 \ + --debug-info-dir "$debug_info_data" \ + --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu.in new file mode 100644 index 00000000..5e814157 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_powerpc64le-linux-gnu.in @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc64le-linux-gnu" + +"${curdir}/test_bin_info" \ + --foo-addr=0x2e7c \ + --printf-offset=0x190 \ + --printf-lineno=36 \ + --tp-offset=0x1c \ + --tp-lineno=35 \ + --debug-link-crc=0x9b8eb2ff \ + --debug-info-dir "$debug_info_data" \ + --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu.in new file mode 100644 index 00000000..6ed40daf --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info_x86_64-linux-gnu.in @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/x86_64-linux-gnu" + +"${curdir}/test_bin_info" \ + --foo-addr=0x2277 \ + --printf-offset=0xf0 \ + --printf-lineno=36 \ + --tp-offset=0x89 \ + --tp-lineno=35 \ + --debug-link-crc=0x289a8fdc \ + --debug-info-dir "$debug_info_data" \ + --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c new file mode 100644 index 00000000..abb72bba --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c @@ -0,0 +1,163 @@ +/* + * test_dwarf.c + * + * Babeltrace bt_dwarf (DWARF utilities) tests + * + * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation + * Copyright (c) 2015 Antoine Busque + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "tap/tap.h" + +#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; + char *die_name = NULL; + struct bt_dwarf_cu *cu = NULL; + struct bt_dwarf_die *die = NULL; + Dwarf *dwarf_info = NULL; + + 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); + if (fd < 0) { + exit(EXIT_FAILURE); + } + dwarf_info = dwarf_begin(fd, DWARF_C_READ); + ok(dwarf_info != NULL, "dwarf_begin successful"); + cu = bt_dwarf_cu_create(dwarf_info); + ok(cu != NULL, "bt_dwarf_cu_create successful"); + ret = bt_dwarf_cu_next(cu); + ok(ret == 0, "bt_dwarf_cu_next successful"); + die = bt_dwarf_die_create(cu); + ok(die != NULL, "bt_dwarf_die_create successful"); + if (!die) { + exit(EXIT_FAILURE); + } + /* + * Test bt_dwarf_die_next twice, as the code path is different + * for DIEs at depth 0 (just created) and other depths. + */ + ret = bt_dwarf_die_next(die); + ok(ret == 0, "bt_dwarf_die_next from root DIE successful"); + ok(die->depth == 1, + "bt_dwarf_die_next from root DIE - correct depth value"); + ret = bt_dwarf_die_next(die); + ok(ret == 0, + "bt_dwarf_die_next from non-root DIE successful"); + ok(die->depth == 1, + "bt_dwarf_die_next from non-root DIE - correct depth value"); + + /* Reset DIE to test dwarf_child */ + bt_dwarf_die_destroy(die); + die = bt_dwarf_die_create(cu); + if (!die) { + diag("Failed to create bt_dwarf_die"); + exit(EXIT_FAILURE); + } + + ret = bt_dwarf_die_child(die); + ok(ret == 0, "bt_dwarf_die_child successful"); + ok(die->depth == 1, "bt_dwarf_die_child - correct depth value"); + + ret = bt_dwarf_die_get_tag(die, &tag); + ok(ret == 0, "bt_dwarf_die_get_tag successful"); + ok(tag == DW_TAG_typedef, "bt_dwarf_die_get_tag - correct tag value"); + ret = bt_dwarf_die_get_name(die, &die_name); + ok(ret == 0, "bt_dwarf_die_get_name successful"); + ok(strcmp(die_name, "size_t") == 0, + "bt_dwarf_die_get_name - correct name value"); + + bt_dwarf_die_destroy(die); + bt_dwarf_cu_destroy(cu); + dwarf_end(dwarf_info); + free(die_name); + close(fd); + g_free(path); +} + +int main(int argc, char **argv) +{ + const char *data_dir; + + plan_tests(NR_TESTS); + + if (argc != 2) { + return EXIT_FAILURE; + } else { + data_dir = argv[1]; + } + + test_bt_no_dwarf(data_dir); + test_bt_dwarf(data_dir); + + return EXIT_SUCCESS; +} diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu.in new file mode 100644 index 00000000..4c50ecb9 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_i386-linux-gnu.in @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/i386-linux-gnu" + +"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu.in new file mode 100644 index 00000000..1a7b7750 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc-linux-gnu.in @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc-linux-gnu" + +"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu.in new file mode 100644 index 00000000..0a94ff00 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_powerpc64le-linux-gnu.in @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright (C) 2015 Antoine Busque +# Copyright (C) 2019 Michael Jeanson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc64le-linux-gnu" + +"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu.in b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu.in new file mode 100644 index 00000000..9d0c9d88 --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_dwarf_x86_64-linux-gnu.in @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Copyright (C) 2015 - Antoine Busque +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" + +debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/x86_64-linux-gnu" + +"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.in b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.in new file mode 100644 index 00000000..5d02aaee --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.in @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright (C) 2017 - Philippe Proulx +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +NO_SH_TAP=1 +. "@abs_top_builddir@/tests/utils/common.sh" + +PYTHON_BUILD_DIR="${BT_BUILD_PATH}/src/bindings/python/bt2/build/build_lib" +TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python" +TESTRUNNER_PY="${BT_SRC_PATH}/tests/utils/python/testrunner.py" +THIS_DIR="${BT_SRC_PATH}/tests/plugins" +export BABELTRACE_PLUGIN_PATH="${BT_BUILD_PATH}/src/plugins/utils:${BT_BUILD_PATH}/src/plugins/ctf:${BT_BUILD_PATH}/src/plugins/lttng-utils" +export DEBUG_INFO_DATA_DIR="${BT_SRC_PATH}/tests/debug-info-data" + +if [ "x${MSYSTEM}" != "x" ]; then + export PATH="${BT_BUILD_PATH}/src/lib/.libs:${PATH}" +else + export LD_LIBRARY_PATH="${BT_BUILD_PATH}/src/lib/.libs:${LD_LIBRARY_PATH}" +fi + +PYTHONPATH="${PYTHON_BUILD_DIR}:${TESTS_UTILS_PYTHON_DIR}" \ + "@PYTHON@" "${TESTRUNNER_PY}" "${THIS_DIR}" 'test_lttng_utils_debug_info.py' +exit $? diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py new file mode 100644 index 00000000..dd27ec9c --- /dev/null +++ b/tests/plugins/flt.lttng-utils.debug-info/test_lttng_utils_debug_info.py @@ -0,0 +1,27 @@ +import unittest +import os.path +import bt2 +import os + + +@unittest.skip('depends on Python bindings, which are broken') +class LttngUtilsDebugInfoTestCase(unittest.TestCase): + def test_debug_info(self): + debug_info_data_dir = os.environ['DEBUG_INFO_DATA_DIR'] + trace_path = os.path.join(debug_info_data_dir, 'trace') + target_prefix = os.path.join(debug_info_data_dir, '..', '..') + src = bt2.ComponentSpec('ctf', 'fs', trace_path) + flt = bt2.ComponentSpec('lttng-utils', 'debug-info', { + 'target-prefix': target_prefix, + }) + it = bt2.TraceCollectionNotificationIterator(src, flt, + [bt2.EventNotification]) + notifs = list(it) + debug_info = notifs[2].event['debug_info'] + self.assertEqual(debug_info['bin'], 'libhello_so+0x14d4') + self.assertEqual(debug_info['func'], 'foo+0xa9') + self.assertEqual(debug_info['src'], 'libhello.c:7') + debug_info = notifs[3].event['debug_info'] + self.assertEqual(debug_info['bin'], 'libhello_so+0x15a6') + self.assertEqual(debug_info['func'], 'bar+0xa9') + self.assertEqual(debug_info['src'], 'libhello.c:13') diff --git a/tests/plugins/test_bin_info.c b/tests/plugins/test_bin_info.c deleted file mode 100644 index d681ef56..00000000 --- a/tests/plugins/test_bin_info.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * test_bin_info.c - * - * Babeltrace SO info tests - * - * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation - * Copyright (c) 2015 Antoine Busque - * Copyright (c) 2019 Michael Jeanson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include - -#include "common/macros.h" -#include "common/assert.h" -#include - -#include "tap/tap.h" - -#define NR_TESTS 57 - -#define SO_NAME "libhello_so" -#define DEBUG_NAME "libhello_so.debug" -#define FUNC_FOO_FILENAME "./libhello.c" -#define FUNC_FOO_PRINTF_NAME_FMT "foo+0x%" PRIx64 -#define FUNC_FOO_NAME_LEN 64 - -#define DWARF_DIR_NAME "dwarf_full" -#define ELF_DIR_NAME "elf_only" -#define BUILDID_DIR_NAME "build_id" -#define DEBUGLINK_DIR_NAME "debug_link" - -/* Lower bound of PIC address mapping */ -#define SO_LOW_ADDR 0x400000 -/* Size of PIC address mapping */ -#define SO_MEMSZ 0x800000 -/* An address outside the PIC mapping */ -#define SO_INV_ADDR 0x200000 - -#define BUILD_ID_HEX_LEN 20 - -static uint64_t opt_func_foo_addr; -static uint64_t opt_func_foo_printf_offset; -static uint64_t opt_func_foo_printf_line_no; -static uint64_t opt_func_foo_tp_offset; -static uint64_t opt_func_foo_tp_line_no; -static uint64_t opt_debug_link_crc; -static gchar *opt_build_id; -static gchar *opt_debug_info_dir; - -static uint64_t func_foo_printf_addr; -static uint64_t func_foo_tp_addr; -static char func_foo_printf_name[FUNC_FOO_NAME_LEN]; -static uint8_t build_id[BUILD_ID_HEX_LEN]; - -static GOptionEntry entries[] = { - {"foo-addr", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_addr, - "Offset to printf in foo", "0xX"}, - {"printf-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_printf_offset, - "Offset to printf in foo", "0xX"}, - {"printf-lineno", 0, 0, G_OPTION_ARG_INT64, - &opt_func_foo_printf_line_no, "Line number to printf in foo", "N"}, - {"tp-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_offset, - "Offset to tp in foo", "0xX"}, - {"tp-lineno", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_line_no, - "Line number to tp in foo", "N"}, - {"debug-link-crc", 0, 0, G_OPTION_ARG_INT64, &opt_debug_link_crc, - "Debug link CRC", "0xX"}, - {"build-id", 0, 0, G_OPTION_ARG_STRING, &opt_build_id, "Build ID", - "XXXXXXXXXXXXXXX"}, - {"debug-info-dir", 0, 0, G_OPTION_ARG_STRING, &opt_debug_info_dir, - "Debug info directory", NULL}, - {NULL}}; - -static -int build_id_to_bin(void) -{ - int ret, len, i; - - if (opt_build_id == NULL) { - goto error; - } - - len = strnlen(opt_build_id, BUILD_ID_HEX_LEN * 2); - if (len != (BUILD_ID_HEX_LEN * 2)) { - goto error; - } - - for (i = 0; i < (len / 2); i++) { - ret = sscanf(opt_build_id + 2 * i, "%02hhx", &build_id[i]); - if (ret != 1) { - goto error; - } - } - - if (i != BUILD_ID_HEX_LEN) { - goto error; - } - - return 0; -error: - return -1; -} - -static -void subtest_has_address(struct bin_info *bin, uint64_t addr) -{ - int ret; - - ret = bin_info_has_address(bin, SO_LOW_ADDR - 1); - ok(ret == 0, "bin_info_has_address - address under SO's range"); - - ret = bin_info_has_address(bin, SO_LOW_ADDR); - ok(ret == 1, "bin_info_has_address - lower bound of SO's range"); - - ret = bin_info_has_address(bin, addr); - ok(ret == 1, "bin_info_has_address - address in SO's range"); - - ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ - 1); - ok(ret == 1, "bin_info_has_address - upper bound of SO's range"); - - ret = bin_info_has_address(bin, SO_LOW_ADDR + SO_MEMSZ); - ok(ret == 0, "bin_info_has_address - address above SO's range"); -} - -static -void subtest_lookup_function_name(struct bin_info *bin, uint64_t addr, - char *func_name) -{ - int ret; - char *_func_name = NULL; - - ret = bin_info_lookup_function_name(bin, addr, &_func_name); - ok(ret == 0, "bin_info_lookup_function_name successful at 0x%x", addr); - if (_func_name) { - ok(strcmp(_func_name, func_name) == 0, - "bin_info_lookup_function_name - correct function name (%s == %s)", - func_name, _func_name); - free(_func_name); - _func_name = NULL; - } else { - skip(1, - "bin_info_lookup_function_name - function name is NULL"); - } - - /* Test function name lookup - erroneous address */ - ret = bin_info_lookup_function_name(bin, SO_INV_ADDR, &_func_name); - ok(ret == -1 && _func_name == NULL, - "bin_info_lookup_function_name - fail on invalid addr"); - if (_func_name) { - free(_func_name); - } -} - -static -void subtest_lookup_source_location(struct bin_info *bin, uint64_t addr, - uint64_t line_no, char *filename) -{ - int ret; - struct source_location *src_loc = NULL; - - ret = bin_info_lookup_source_location(bin, addr, &src_loc); - ok(ret == 0, "bin_info_lookup_source_location successful at 0x%x", - addr); - if (src_loc) { - ok(src_loc->line_no == line_no, - "bin_info_lookup_source_location - correct line_no (%d == %d)", - line_no, src_loc->line_no); - ok(strcmp(src_loc->filename, filename) == 0, - "bin_info_lookup_source_location - correct filename (%s == %s)", - filename, src_loc->filename); - source_location_destroy(src_loc); - src_loc = NULL; - } else { - fail("bin_info_lookup_source_location - src_loc is NULL"); - fail("bin_info_lookup_source_location - src_loc is NULL"); - } - - /* Test source location lookup - erroneous address */ - ret = bin_info_lookup_source_location(bin, SO_INV_ADDR, &src_loc); - ok(ret == -1 && src_loc == NULL, - "bin_info_lookup_source_location - fail on invalid addr"); - if (src_loc) { - source_location_destroy(src_loc); - } -} - -static -void test_bin_info_build_id(const char *bin_info_dir) -{ - int ret; - char *data_dir, *bin_path; - struct bin_info *bin = NULL; - struct bt_fd_cache fdc; - uint8_t invalid_build_id[BUILD_ID_HEX_LEN] = { - 0xa3, 0xfd, 0x8b, 0xff, 0x45, 0xe1, 0xa9, 0x32, 0x15, 0xdd, - 0x6d, 0xaa, 0xd5, 0x53, 0x98, 0x7e, 0xaf, 0xd4, 0x0c, 0xbb - }; - - diag("bin-info tests - separate DWARF via 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); - - if (data_dir == NULL || bin_path == NULL) { - exit(EXIT_FAILURE); - } - - ret = bt_fd_cache_init(&fdc); - if (ret != 0) { - diag("Failed to initialize FD cache"); - exit(EXIT_FAILURE); - } - - bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, - data_dir, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); - - /* Test setting invalid build_id */ - ret = bin_info_set_build_id(bin, invalid_build_id, BUILD_ID_HEX_LEN); - ok(ret == -1, "bin_info_set_build_id fail on invalid build_id"); - - /* Test setting correct build_id */ - ret = bin_info_set_build_id(bin, build_id, BUILD_ID_HEX_LEN); - ok(ret == 0, "bin_info_set_build_id successful"); - - /* Test bin_info_has_address */ - subtest_has_address(bin, func_foo_printf_addr); - - /* Test function name lookup (with DWARF) */ - subtest_lookup_function_name(bin, func_foo_printf_addr, - func_foo_printf_name); - - /* Test source location lookup */ - subtest_lookup_source_location(bin, func_foo_printf_addr, - opt_func_foo_printf_line_no, - FUNC_FOO_FILENAME); - - 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 *bin_info_dir) -{ - int ret; - char *data_dir, *bin_path; - struct bin_info *bin = NULL; - struct bt_fd_cache fdc; - - diag("bin-info tests - separate DWARF via 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); - - if (data_dir == NULL || bin_path == NULL) { - exit(EXIT_FAILURE); - } - - ret = bt_fd_cache_init(&fdc); - if (ret != 0) { - diag("Failed to initialize FD cache"); - exit(EXIT_FAILURE); - } - - bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, - data_dir, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); - - /* Test setting debug link */ - ret = bin_info_set_debug_link(bin, DEBUG_NAME, opt_debug_link_crc); - ok(ret == 0, "bin_info_set_debug_link successful"); - - /* Test bin_info_has_address */ - subtest_has_address(bin, func_foo_printf_addr); - - /* Test function name lookup (with DWARF) */ - subtest_lookup_function_name(bin, func_foo_printf_addr, - func_foo_printf_name); - - /* Test source location lookup */ - subtest_lookup_source_location(bin, func_foo_printf_addr, - opt_func_foo_printf_line_no, - FUNC_FOO_FILENAME); - - 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 *bin_info_dir) -{ - int ret; - char *data_dir, *bin_path; - struct bin_info *bin = NULL; - struct source_location *src_loc = NULL; - struct bt_fd_cache fdc; - - diag("bin-info tests - ELF only"); - - 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); - } - - ret = bt_fd_cache_init(&fdc); - if (ret != 0) { - diag("Failed to initialize FD cache"); - exit(EXIT_FAILURE); - } - - bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, - data_dir, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); - - /* Test bin_info_has_address */ - subtest_has_address(bin, func_foo_printf_addr); - - /* Test function name lookup (with ELF) */ - subtest_lookup_function_name(bin, func_foo_printf_addr, - func_foo_printf_name); - - /* Test source location location - should fail on ELF only file */ - ret = bin_info_lookup_source_location(bin, func_foo_printf_addr, - &src_loc); - ok(ret == -1, - "bin_info_lookup_source_location - fail on ELF only file"); - - 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_bundled(const char *bin_info_dir) -{ - int ret; - char *data_dir, *bin_path; - struct bin_info *bin = NULL; - struct bt_fd_cache fdc; - - diag("bin-info tests - DWARF bundled in SO file"); - - 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); - if (ret != 0) { - diag("Failed to initialize FD cache"); - exit(EXIT_FAILURE); - } - - bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true, - data_dir, NULL); - ok(bin != NULL, "bin_info_create successful (%s)", bin_path); - - /* Test bin_info_has_address */ - subtest_has_address(bin, func_foo_printf_addr); - - /* Test function name lookup (with DWARF) */ - subtest_lookup_function_name(bin, func_foo_printf_addr, - func_foo_printf_name); - - /* Test source location lookup */ - subtest_lookup_source_location(bin, func_foo_printf_addr, - opt_func_foo_printf_line_no, - FUNC_FOO_FILENAME); - - /* Test source location lookup - inlined function */ - subtest_lookup_source_location(bin, func_foo_tp_addr, - opt_func_foo_tp_line_no, - FUNC_FOO_FILENAME); - - bin_info_destroy(bin); - bt_fd_cache_fini(&fdc); - g_free(data_dir); - g_free(bin_path); -} - -int main(int argc, char **argv) -{ - int ret; - GError *error = NULL; - GOptionContext *context; - - context = g_option_context_new("- bin info test"); - g_option_context_add_main_entries(context, entries, NULL); - if (!g_option_context_parse(context, &argc, &argv, &error)) { - fprintf(stderr, "option parsing failed: %s\n", error->message); - exit(EXIT_FAILURE); - } - - g_snprintf(func_foo_printf_name, FUNC_FOO_NAME_LEN, - FUNC_FOO_PRINTF_NAME_FMT, opt_func_foo_printf_offset); - func_foo_printf_addr = - SO_LOW_ADDR + opt_func_foo_addr + opt_func_foo_printf_offset; - func_foo_tp_addr = - SO_LOW_ADDR + opt_func_foo_addr + opt_func_foo_tp_offset; - - if (build_id_to_bin()) { - fprintf(stderr, "Failed to parse / missing build id\n"); - exit(EXIT_FAILURE); - } - - plan_tests(NR_TESTS); - - ret = bin_info_init(); - ok(ret == 0, "bin_info_init successful"); - - test_bin_info_elf(opt_debug_info_dir); - test_bin_info_bundled(opt_debug_info_dir); - test_bin_info_build_id(opt_debug_info_dir); - test_bin_info_debug_link(opt_debug_info_dir); - - return EXIT_SUCCESS; -} diff --git a/tests/plugins/test_bin_info_i386-linux-gnu.in b/tests/plugins/test_bin_info_i386-linux-gnu.in deleted file mode 100644 index 9b58d63c..00000000 --- a/tests/plugins/test_bin_info_i386-linux-gnu.in +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/i386-linux-gnu" - -"${curdir}/test_bin_info" \ - --foo-addr=0x1c8d \ - --printf-offset=0xda \ - --printf-lineno=36 \ - --tp-offset=0x12 \ - --tp-lineno=35 \ - --debug-link-crc=0xdeead493 \ - --debug-info-dir "$debug_info_data" \ - --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/test_bin_info_powerpc-linux-gnu.in b/tests/plugins/test_bin_info_powerpc-linux-gnu.in deleted file mode 100644 index d0948aa6..00000000 --- a/tests/plugins/test_bin_info_powerpc-linux-gnu.in +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc-linux-gnu" - -"${curdir}/test_bin_info" \ - --foo-addr=0x23bc \ - --printf-offset=0x114 \ - --printf-lineno=36 \ - --tp-offset=0x28 \ - --tp-lineno=35 \ - --debug-link-crc=0xd7b98958 \ - --debug-info-dir "$debug_info_data" \ - --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/test_bin_info_powerpc64le-linux-gnu.in b/tests/plugins/test_bin_info_powerpc64le-linux-gnu.in deleted file mode 100644 index 5e814157..00000000 --- a/tests/plugins/test_bin_info_powerpc64le-linux-gnu.in +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc64le-linux-gnu" - -"${curdir}/test_bin_info" \ - --foo-addr=0x2e7c \ - --printf-offset=0x190 \ - --printf-lineno=36 \ - --tp-offset=0x1c \ - --tp-lineno=35 \ - --debug-link-crc=0x9b8eb2ff \ - --debug-info-dir "$debug_info_data" \ - --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/test_bin_info_x86_64-linux-gnu.in b/tests/plugins/test_bin_info_x86_64-linux-gnu.in deleted file mode 100644 index 6ed40daf..00000000 --- a/tests/plugins/test_bin_info_x86_64-linux-gnu.in +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/x86_64-linux-gnu" - -"${curdir}/test_bin_info" \ - --foo-addr=0x2277 \ - --printf-offset=0xf0 \ - --printf-lineno=36 \ - --tp-offset=0x89 \ - --tp-lineno=35 \ - --debug-link-crc=0x289a8fdc \ - --debug-info-dir "$debug_info_data" \ - --build-id cdd98cdd87f7fe64c13b6daad553987eafd40cbb diff --git a/tests/plugins/test_dwarf.c b/tests/plugins/test_dwarf.c deleted file mode 100644 index abb72bba..00000000 --- a/tests/plugins/test_dwarf.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * test_dwarf.c - * - * Babeltrace bt_dwarf (DWARF utilities) tests - * - * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation - * Copyright (c) 2015 Antoine Busque - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "tap/tap.h" - -#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; - char *die_name = NULL; - struct bt_dwarf_cu *cu = NULL; - struct bt_dwarf_die *die = NULL; - Dwarf *dwarf_info = NULL; - - 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); - if (fd < 0) { - exit(EXIT_FAILURE); - } - dwarf_info = dwarf_begin(fd, DWARF_C_READ); - ok(dwarf_info != NULL, "dwarf_begin successful"); - cu = bt_dwarf_cu_create(dwarf_info); - ok(cu != NULL, "bt_dwarf_cu_create successful"); - ret = bt_dwarf_cu_next(cu); - ok(ret == 0, "bt_dwarf_cu_next successful"); - die = bt_dwarf_die_create(cu); - ok(die != NULL, "bt_dwarf_die_create successful"); - if (!die) { - exit(EXIT_FAILURE); - } - /* - * Test bt_dwarf_die_next twice, as the code path is different - * for DIEs at depth 0 (just created) and other depths. - */ - ret = bt_dwarf_die_next(die); - ok(ret == 0, "bt_dwarf_die_next from root DIE successful"); - ok(die->depth == 1, - "bt_dwarf_die_next from root DIE - correct depth value"); - ret = bt_dwarf_die_next(die); - ok(ret == 0, - "bt_dwarf_die_next from non-root DIE successful"); - ok(die->depth == 1, - "bt_dwarf_die_next from non-root DIE - correct depth value"); - - /* Reset DIE to test dwarf_child */ - bt_dwarf_die_destroy(die); - die = bt_dwarf_die_create(cu); - if (!die) { - diag("Failed to create bt_dwarf_die"); - exit(EXIT_FAILURE); - } - - ret = bt_dwarf_die_child(die); - ok(ret == 0, "bt_dwarf_die_child successful"); - ok(die->depth == 1, "bt_dwarf_die_child - correct depth value"); - - ret = bt_dwarf_die_get_tag(die, &tag); - ok(ret == 0, "bt_dwarf_die_get_tag successful"); - ok(tag == DW_TAG_typedef, "bt_dwarf_die_get_tag - correct tag value"); - ret = bt_dwarf_die_get_name(die, &die_name); - ok(ret == 0, "bt_dwarf_die_get_name successful"); - ok(strcmp(die_name, "size_t") == 0, - "bt_dwarf_die_get_name - correct name value"); - - bt_dwarf_die_destroy(die); - bt_dwarf_cu_destroy(cu); - dwarf_end(dwarf_info); - free(die_name); - close(fd); - g_free(path); -} - -int main(int argc, char **argv) -{ - const char *data_dir; - - plan_tests(NR_TESTS); - - if (argc != 2) { - return EXIT_FAILURE; - } else { - data_dir = argv[1]; - } - - test_bt_no_dwarf(data_dir); - test_bt_dwarf(data_dir); - - return EXIT_SUCCESS; -} diff --git a/tests/plugins/test_dwarf_i386-linux-gnu.in b/tests/plugins/test_dwarf_i386-linux-gnu.in deleted file mode 100644 index 4c50ecb9..00000000 --- a/tests/plugins/test_dwarf_i386-linux-gnu.in +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/i386-linux-gnu" - -"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/test_dwarf_powerpc-linux-gnu.in b/tests/plugins/test_dwarf_powerpc-linux-gnu.in deleted file mode 100644 index 1a7b7750..00000000 --- a/tests/plugins/test_dwarf_powerpc-linux-gnu.in +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc-linux-gnu" - -"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/test_dwarf_powerpc64le-linux-gnu.in b/tests/plugins/test_dwarf_powerpc64le-linux-gnu.in deleted file mode 100644 index 0a94ff00..00000000 --- a/tests/plugins/test_dwarf_powerpc64le-linux-gnu.in +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Antoine Busque -# Copyright (C) 2019 Michael Jeanson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/powerpc64le-linux-gnu" - -"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/test_dwarf_x86_64-linux-gnu.in b/tests/plugins/test_dwarf_x86_64-linux-gnu.in deleted file mode 100644 index 9d0c9d88..00000000 --- a/tests/plugins/test_dwarf_x86_64-linux-gnu.in +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 - Antoine Busque -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -curdir="$(cd -P "$(dirname "$0")" >/dev/null && pwd)" - -debug_info_data="${BT_SRC_PATH}/tests/debug-info-data/x86_64-linux-gnu" - -"${curdir}/test_dwarf" "$debug_info_data" diff --git a/tests/plugins/test_lttng_utils_debug_info.in b/tests/plugins/test_lttng_utils_debug_info.in deleted file mode 100644 index 5d02aaee..00000000 --- a/tests/plugins/test_lttng_utils_debug_info.in +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2017 - Philippe Proulx -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -NO_SH_TAP=1 -. "@abs_top_builddir@/tests/utils/common.sh" - -PYTHON_BUILD_DIR="${BT_BUILD_PATH}/src/bindings/python/bt2/build/build_lib" -TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python" -TESTRUNNER_PY="${BT_SRC_PATH}/tests/utils/python/testrunner.py" -THIS_DIR="${BT_SRC_PATH}/tests/plugins" -export BABELTRACE_PLUGIN_PATH="${BT_BUILD_PATH}/src/plugins/utils:${BT_BUILD_PATH}/src/plugins/ctf:${BT_BUILD_PATH}/src/plugins/lttng-utils" -export DEBUG_INFO_DATA_DIR="${BT_SRC_PATH}/tests/debug-info-data" - -if [ "x${MSYSTEM}" != "x" ]; then - export PATH="${BT_BUILD_PATH}/src/lib/.libs:${PATH}" -else - export LD_LIBRARY_PATH="${BT_BUILD_PATH}/src/lib/.libs:${LD_LIBRARY_PATH}" -fi - -PYTHONPATH="${PYTHON_BUILD_DIR}:${TESTS_UTILS_PYTHON_DIR}" \ - "@PYTHON@" "${TESTRUNNER_PY}" "${THIS_DIR}" 'test_lttng_utils_debug_info.py' -exit $? diff --git a/tests/plugins/test_lttng_utils_debug_info.py b/tests/plugins/test_lttng_utils_debug_info.py deleted file mode 100644 index dd27ec9c..00000000 --- a/tests/plugins/test_lttng_utils_debug_info.py +++ /dev/null @@ -1,27 +0,0 @@ -import unittest -import os.path -import bt2 -import os - - -@unittest.skip('depends on Python bindings, which are broken') -class LttngUtilsDebugInfoTestCase(unittest.TestCase): - def test_debug_info(self): - debug_info_data_dir = os.environ['DEBUG_INFO_DATA_DIR'] - trace_path = os.path.join(debug_info_data_dir, 'trace') - target_prefix = os.path.join(debug_info_data_dir, '..', '..') - src = bt2.ComponentSpec('ctf', 'fs', trace_path) - flt = bt2.ComponentSpec('lttng-utils', 'debug-info', { - 'target-prefix': target_prefix, - }) - it = bt2.TraceCollectionNotificationIterator(src, flt, - [bt2.EventNotification]) - notifs = list(it) - debug_info = notifs[2].event['debug_info'] - self.assertEqual(debug_info['bin'], 'libhello_so+0x14d4') - self.assertEqual(debug_info['func'], 'foo+0xa9') - self.assertEqual(debug_info['src'], 'libhello.c:7') - debug_info = notifs[3].event['debug_info'] - self.assertEqual(debug_info['bin'], 'libhello_so+0x15a6') - self.assertEqual(debug_info['func'], 'bar+0xa9') - self.assertEqual(debug_info['src'], 'libhello.c:13')