Re-enable the bin-info and dward tests
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 8 Aug 2017 20:02:35 +0000 (16:02 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 10 Aug 2017 19:19:55 +0000 (15:19 -0400)
During the development of the debug-info plugin, the old tests were
disabled. Re-adapt them to the new tree and re-enable them in the test
suite.

Reported-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
tests/lib/Makefile.am
tests/lib/test_bin_info.c [deleted file]
tests/lib/test_bin_info_complete.in [deleted file]
tests/lib/test_dwarf.c [deleted file]
tests/lib/test_dwarf_complete.in [deleted file]
tests/plugins/Makefile.am
tests/plugins/test_bin_info.c [new file with mode: 0644]
tests/plugins/test_bin_info_complete.in [new file with mode: 0755]
tests/plugins/test_dwarf.c [new file with mode: 0644]
tests/plugins/test_dwarf_complete.in [new file with mode: 0755]

index 6625b58b7935cec2f6442e52100003b6bccfb630..cd24ae4263f585b901c85c27ce5522fc778e02b1 100644 (file)
@@ -728,14 +728,14 @@ AC_CONFIG_FILES([tests/cli/test_packet_seq_num], [chmod +x tests/cli/test_packet
 AC_CONFIG_FILES([tests/cli/test_trace_copy], [chmod +x tests/cli/test_trace_copy])
 AC_CONFIG_FILES([tests/cli/test_trace_read], [chmod +x tests/cli/test_trace_read])
 AC_CONFIG_FILES([tests/cli/test_trimmer], [chmod +x tests/cli/test_trimmer])
-AC_CONFIG_FILES([tests/lib/test_bin_info_complete], [chmod +x tests/lib/test_bin_info_complete])
 AC_CONFIG_FILES([tests/lib/test_ctf_writer_complete], [chmod +x tests/lib/test_ctf_writer_complete])
-AC_CONFIG_FILES([tests/lib/test_dwarf_complete], [chmod +x tests/lib/test_dwarf_complete])
 AC_CONFIG_FILES([tests/lib/test_plugin_complete], [chmod +x tests/lib/test_plugin_complete])
 AC_CONFIG_FILES([tests/lib/writer/bt_python_helper.py])
 AC_CONFIG_FILES([tests/lib/writer/test_ctf_writer_empty_packet.py])
 AC_CONFIG_FILES([tests/lib/writer/test_ctf_writer_no_packet_context.py])
 AC_CONFIG_FILES([tests/plugins/test-utils-muxer-complete], [chmod +x tests/plugins/test-utils-muxer-complete])
+AC_CONFIG_FILES([tests/plugins/test_dwarf_complete], [chmod +x tests/plugins/test_dwarf_complete])
+AC_CONFIG_FILES([tests/plugins/test_bin_info_complete], [chmod +x tests/plugins/test_bin_info_complete])
 
 AS_IF([test "x$enable_python" = xyes],
   [AC_CONFIG_FILES([tests/bindings/python/bt2/testall.sh], [chmod +x tests/bindings/python/bt2/testall.sh])]
index 511b8f373bffbee3a38ca388e88fef04cdb0b11b..2bcc630d6fc0f3479ba2218aa59897dcbc2eb4df 100644 (file)
@@ -51,24 +51,6 @@ test_bt_notification_iterator_SOURCES = test_bt_notification_iterator.c
 
 check_SCRIPTS = test_ctf_writer_complete
 
-#FIXME
-#if ENABLE_DEBUG_INFO
-#test_dwarf_LDFLAGS = -static
-#test_dwarf_LDADD = $(LIBTAP) \
-#      $(top_builddir)/lib/libbabeltrace.la \
-#      $(top_builddir)/lib/libdebug-info.la
-#test_dwarf_SOURCES = test_dwarf.c
-
-#test_bin_info_LDFLAGS = -static
-#test_bin_info_LDADD = $(LIBTAP) \
-#      $(top_builddir)/lib/libbabeltrace.la \
-#      $(top_builddir)/lib/libdebug-info.la
-#test_bin_info_SOURCES = test_bin_info.c
-
-#noinst_PROGRAMS += test_dwarf test_bin_info
-#check_SCRIPTS += test_dwarf_complete test_bin_info_complete
-#endif
-
 LOG_DRIVER_FLAGS='--merge'
 LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/config/tap-driver.sh
 
@@ -83,11 +65,6 @@ TESTS = test_bitfield \
        test_cc_prio_map \
        test_bt_notification_iterator
 
-if ENABLE_DEBUG_INFO
-TESTS += test_dwarf_complete \
-       test_bin_info_complete
-endif
-
 if ENABLE_PYTHON_BINDINGS
 TESTS +=
        writer/test_ctf_writer_no_packet_context.py \
diff --git a/tests/lib/test_bin_info.c b/tests/lib/test_bin_info.c
deleted file mode 100644 (file)
index fd9e4f1..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * test_bin_info.c
- *
- * Babeltrace SO info tests
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <babeltrace/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 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 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)
-{
-       int ret;
-       char path[PATH_MAX];
-       char *func_name = NULL;
-       struct bin_info *bin = NULL;
-       struct source_location *src_loc = NULL;
-       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
-       };
-
-       diag("bin-info tests - separate DWARF via build ID");
-
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_BUILD_ID);
-
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true);
-       ok(bin != NULL, "bin_info_create successful");
-
-       /* Test setting build_id */
-       ret = bin_info_set_build_id(bin, build_id, BUILD_ID_LEN);
-       ok(ret == 0, "bin_info_set_build_id successful");
-
-       /* Test function name lookup (with DWARF) */
-       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name);
-       ok(ret == 0, "bin_info_lookup_function_name successful");
-       if (func_name) {
-               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
-                       "bin_info_lookup_function_name - correct func_name value");
-               free(func_name);
-       } else {
-               skip(1, "bin_info_lookup_function_name - func_name is NULL");
-       }
-
-       /* Test source location lookup */
-       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc);
-       ok(ret == 0, "bin_info_lookup_source_location successful");
-       if (src_loc) {
-               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
-                       "bin_info_lookup_source_location - correct line_no");
-               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
-                       "bin_info_lookup_source_location - correct filename");
-               source_location_destroy(src_loc);
-       } else {
-               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
-       }
-
-       bin_info_destroy(bin);
-}
-
-static
-void test_bin_info_debug_link(const char *data_dir)
-{
-       int ret;
-       char path[PATH_MAX];
-       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;
-
-       diag("bin-info tests - separate DWARF via debug link");
-
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_DEBUG_LINK);
-
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true);
-       ok(bin != NULL, "bin_info_create successful");
-
-       /* Test setting debug link */
-       ret = bin_info_set_debug_link(bin, dbg_filename, crc);
-       ok(ret == 0, "bin_info_set_debug_link successful");
-
-       /* Test function name lookup (with DWARF) */
-       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_DBG_LINK,
-                                       &func_name);
-       ok(ret == 0, "bin_info_lookup_function_name successful");
-       if (func_name) {
-               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
-                       "bin_info_lookup_function_name - correct func_name value");
-               free(func_name);
-       } else {
-               skip(1, "bin_info_lookup_function_name - func_name is NULL");
-       }
-
-       /* Test source location lookup */
-       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_DBG_LINK,
-                                       &src_loc);
-       ok(ret == 0, "bin_info_lookup_source_location successful");
-       if (src_loc) {
-               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
-                       "bin_info_lookup_source_location - correct line_no");
-               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
-                       "bin_info_lookup_source_location - correct filename");
-               source_location_destroy(src_loc);
-       } else {
-               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
-       }
-
-       bin_info_destroy(bin);
-}
-
-static
-void test_bin_info_elf(const char *data_dir)
-{
-       int ret;
-       char path[PATH_MAX];
-       char *func_name = NULL;
-       struct bin_info *bin = NULL;
-       struct source_location *src_loc = NULL;
-
-       diag("bin-info tests - ELF only");
-
-       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_ELF);
-
-       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true);
-       ok(bin != NULL, "bin_info_create successful");
-
-       /* Test function name lookup (with ELF) */
-       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_ELF, &func_name);
-       ok(ret == 0, "bin_info_lookup_function_name successful");
-       if (func_name) {
-               ok(strcmp(func_name, FUNC_FOO_NAME_ELF) == 0,
-                       "bin_info_lookup_function_name - correct func_name value");
-               free(func_name);
-               func_name = NULL;
-       } else {
-               skip(1, "bin_info_lookup_function_name - func_name is NULL");
-       }
-
-       /* Test function name lookup - erroneous address */
-       ret = bin_info_lookup_function_name(bin, 0, &func_name);
-       ok(ret == -1 && func_name == NULL,
-               "bin_info_lookup_function_name - fail on addr not found");
-
-       /* Test source location location - should fail on ELF only file  */
-       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_ELF, &src_loc);
-       ok(ret == -1, "bin_info_lookup_source_location - fail on ELF only file");
-
-       source_location_destroy(src_loc);
-       bin_info_destroy(bin);
-}
-
-static
-void test_bin_info(const char *data_dir)
-{
-       int ret;
-       char path[PATH_MAX];
-       char *func_name = NULL;
-       struct bin_info *bin = NULL;
-       struct source_location *src_loc = NULL;
-
-       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);
-       ok(bin != NULL, "bin_info_create successful");
-
-       /* Test bin_info_has_address */
-       ret = bin_info_has_address(bin, 0);
-       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, FUNC_FOO_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");
-
-       /* Test function name lookup (with DWARF) */
-       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name);
-       ok(ret == 0, "bin_info_lookup_function_name successful");
-       if (func_name) {
-               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
-                       "bin_info_lookup_function_name - correct func_name value");
-               free(func_name);
-               func_name = NULL;
-       } else {
-               skip(1, "bin_info_lookup_function_name - func_name is NULL");
-       }
-
-       /* Test function name lookup - erroneous address */
-       ret = bin_info_lookup_function_name(bin, 0, &func_name);
-       ok(ret == -1 && func_name == NULL,
-               "bin_info_lookup_function_name - fail on addr not found");
-
-       /* Test source location lookup */
-       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc);
-       ok(ret == 0, "bin_info_lookup_source_location successful");
-       if (src_loc) {
-               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
-                       "bin_info_lookup_source_location - correct line_no");
-               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
-                       "bin_info_lookup_source_location - correct filename");
-               source_location_destroy(src_loc);
-               src_loc = NULL;
-       } else {
-               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
-       }
-
-       /* Test source location lookup - inlined function */
-       ret = bin_info_lookup_source_location(bin, FUNC_FOO_TP_ADDR, &src_loc);
-       ok(ret == 0,
-               "bin_info_lookup_source_location (inlined func) successful");
-       if (src_loc) {
-               ok(src_loc->line_no == FUNC_FOO_TP_LINE_NO,
-                       "bin_info_lookup_source_location (inlined func) - correct line_no");
-               ok(strcmp(src_loc->filename, FUNC_FOO_TP_FILENAME) == 0,
-                       "bin_info_lookup_source_location (inlined func) - correct filename");
-               source_location_destroy(src_loc);
-               src_loc = NULL;
-       } else {
-               skip(2, "bin_info_lookup_source_location (inlined func) - src_loc is NULL");
-       }
-
-       /* Test source location lookup - erroneous address */
-       ret = bin_info_lookup_source_location(bin, 0, &src_loc);
-       ok(ret == -1 && src_loc == NULL,
-               "bin_info_lookup_source_location - fail on addr not found");
-
-       bin_info_destroy(bin);
-}
-
-int main(int argc, char **argv)
-{
-       int ret;
-
-       plan_tests(NR_TESTS);
-
-       if (argc != 2) {
-               return EXIT_FAILURE;
-       } else {
-               opt_debug_info_dir = argv[1];
-       }
-
-       ret = bin_info_init();
-       ok(ret == 0, "bin_info_init successful");
-
-       test_bin_info(opt_debug_info_dir);
-       test_bin_info_elf(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/lib/test_bin_info_complete.in b/tests/lib/test_bin_info_complete.in
deleted file mode 100755 (executable)
index 3ca7ca2..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2015 - Antoine Busque <abusque@efficios.com>
-#
-# 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.
-#
-
-DEBUG_INFO_DATA="@abs_top_srcdir@/tests/debug-info-data"
-
-"@abs_top_builddir@/tests/lib/test_bin_info" "$DEBUG_INFO_DATA"
diff --git a/tests/lib/test_dwarf.c b/tests/lib/test_dwarf.c
deleted file mode 100644 (file)
index 90c1441..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * test_dwarf.c
- *
- * Babeltrace bt_dwarf (DWARF utilities) tests
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
- *
- * 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 <fcntl.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <babeltrace/dwarf.h>
-#include "tap/tap.h"
-
-#define NR_TESTS 15
-
-static
-void test_bt_dwarf(const char *data_dir)
-{
-       int fd, ret, tag;
-       char path[PATH_MAX];
-       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);
-
-       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);
-}
-
-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_dwarf(data_dir);
-
-       return EXIT_SUCCESS;
-}
diff --git a/tests/lib/test_dwarf_complete.in b/tests/lib/test_dwarf_complete.in
deleted file mode 100755 (executable)
index a3f026d..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2015 - Antoine Busque <abusque@efficios.com>
-#
-# 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.
-#
-
-DEBUG_INFO_DATA="@abs_top_srcdir@/tests/debug-info-data"
-
-"@abs_top_builddir@/tests/lib/test_dwarf" "$DEBUG_INFO_DATA"
index 867ddd9659abbfc38756e5256bddfe79e21a49c8..e34e66a6e1ac3693c455314d75f844191b3ced43 100644 (file)
@@ -1,4 +1,4 @@
-AM_CPPFLAGS += -I$(top_srcdir)/tests/utils
+AM_CPPFLAGS += -I$(top_srcdir)/tests/utils -I$(top_srcdir)/plugins
 
 LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la
 COMMON_TEST_LDADD = $(LIBTAP) \
@@ -18,3 +18,20 @@ LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/config/tap-driver.sh
 LOG_DRIVER_FLAGS='--merge'
 
 TESTS = test-utils-muxer-complete
+
+if ENABLE_DEBUG_INFO
+test_dwarf_LDFLAGS = -static
+test_dwarf_LDADD = $(LIBTAP) \
+       $(top_builddir)/plugins/lttng-utils/babeltrace-plugin-lttng-utils.la
+test_dwarf_SOURCES = test_dwarf.c
+
+test_bin_info_LDFLAGS = -static
+test_bin_info_LDADD = $(LIBTAP) \
+       $(top_builddir)/plugins/lttng-utils/babeltrace-plugin-lttng-utils.la
+test_bin_info_SOURCES = test_bin_info.c
+
+noinst_PROGRAMS += test_dwarf test_bin_info
+check_SCRIPTS += test_dwarf_complete test_bin_info_complete
+TESTS += test_dwarf_complete \
+       test_bin_info_complete
+endif
diff --git a/tests/plugins/test_bin_info.c b/tests/plugins/test_bin_info.c
new file mode 100644 (file)
index 0000000..f95cf0d
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+ * test_bin_info.c
+ *
+ * Babeltrace SO info tests
+ *
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <lttng-utils/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 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 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)
+{
+       int ret;
+       char path[PATH_MAX];
+       char *func_name = NULL;
+       struct bin_info *bin = NULL;
+       struct source_location *src_loc = NULL;
+       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
+       };
+
+       diag("bin-info tests - separate DWARF via build ID");
+
+       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_BUILD_ID);
+
+       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       ok(bin != NULL, "bin_info_create successful");
+
+       /* Test setting build_id */
+       ret = bin_info_set_build_id(bin, build_id, BUILD_ID_LEN);
+       ok(ret == 0, "bin_info_set_build_id successful");
+
+       /* Test function name lookup (with DWARF) */
+       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name);
+       ok(ret == 0, "bin_info_lookup_function_name successful");
+       if (func_name) {
+               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
+                       "bin_info_lookup_function_name - correct func_name value");
+               free(func_name);
+       } else {
+               skip(1, "bin_info_lookup_function_name - func_name is NULL");
+       }
+
+       /* Test source location lookup */
+       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc);
+       ok(ret == 0, "bin_info_lookup_source_location successful");
+       if (src_loc) {
+               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
+                       "bin_info_lookup_source_location - correct line_no");
+               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
+                       "bin_info_lookup_source_location - correct filename");
+               source_location_destroy(src_loc);
+       } else {
+               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
+       }
+
+       bin_info_destroy(bin);
+}
+
+static
+void test_bin_info_debug_link(const char *data_dir)
+{
+       int ret;
+       char path[PATH_MAX];
+       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;
+
+       diag("bin-info tests - separate DWARF via debug link");
+
+       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_DEBUG_LINK);
+
+       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       ok(bin != NULL, "bin_info_create successful");
+
+       /* Test setting debug link */
+       ret = bin_info_set_debug_link(bin, dbg_filename, crc);
+       ok(ret == 0, "bin_info_set_debug_link successful");
+
+       /* Test function name lookup (with DWARF) */
+       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_DBG_LINK,
+                                       &func_name);
+       ok(ret == 0, "bin_info_lookup_function_name successful");
+       if (func_name) {
+               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
+                       "bin_info_lookup_function_name - correct func_name value");
+               free(func_name);
+       } else {
+               skip(1, "bin_info_lookup_function_name - func_name is NULL");
+       }
+
+       /* Test source location lookup */
+       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_DBG_LINK,
+                                       &src_loc);
+       ok(ret == 0, "bin_info_lookup_source_location successful");
+       if (src_loc) {
+               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
+                       "bin_info_lookup_source_location - correct line_no");
+               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
+                       "bin_info_lookup_source_location - correct filename");
+               source_location_destroy(src_loc);
+       } else {
+               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
+       }
+
+       bin_info_destroy(bin);
+}
+
+static
+void test_bin_info_elf(const char *data_dir)
+{
+       int ret;
+       char path[PATH_MAX];
+       char *func_name = NULL;
+       struct bin_info *bin = NULL;
+       struct source_location *src_loc = NULL;
+
+       diag("bin-info tests - ELF only");
+
+       snprintf(path, PATH_MAX, "%s/%s", data_dir, SO_NAME_ELF);
+
+       bin = bin_info_create(path, SO_LOW_ADDR, SO_MEMSZ, true, data_dir, NULL);
+       ok(bin != NULL, "bin_info_create successful");
+
+       /* Test function name lookup (with ELF) */
+       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR_ELF, &func_name);
+       ok(ret == 0, "bin_info_lookup_function_name successful");
+       if (func_name) {
+               ok(strcmp(func_name, FUNC_FOO_NAME_ELF) == 0,
+                       "bin_info_lookup_function_name - correct func_name value");
+               free(func_name);
+               func_name = NULL;
+       } else {
+               skip(1, "bin_info_lookup_function_name - func_name is NULL");
+       }
+
+       /* Test function name lookup - erroneous address */
+       ret = bin_info_lookup_function_name(bin, 0, &func_name);
+       ok(ret == -1 && func_name == NULL,
+               "bin_info_lookup_function_name - fail on addr not found");
+
+       /* Test source location location - should fail on ELF only file  */
+       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR_ELF, &src_loc);
+       ok(ret == -1, "bin_info_lookup_source_location - fail on ELF only file");
+
+       source_location_destroy(src_loc);
+       bin_info_destroy(bin);
+}
+
+static
+void test_bin_info(const char *data_dir)
+{
+       int ret;
+       char path[PATH_MAX];
+       char *func_name = NULL;
+       struct bin_info *bin = NULL;
+       struct source_location *src_loc = NULL;
+
+       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);
+       ok(bin != NULL, "bin_info_create successful");
+
+       /* Test bin_info_has_address */
+       ret = bin_info_has_address(bin, 0);
+       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, FUNC_FOO_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");
+
+       /* Test function name lookup (with DWARF) */
+       ret = bin_info_lookup_function_name(bin, FUNC_FOO_ADDR, &func_name);
+       ok(ret == 0, "bin_info_lookup_function_name successful");
+       if (func_name) {
+               ok(strcmp(func_name, FUNC_FOO_NAME) == 0,
+                       "bin_info_lookup_function_name - correct func_name value");
+               free(func_name);
+               func_name = NULL;
+       } else {
+               skip(1, "bin_info_lookup_function_name - func_name is NULL");
+       }
+
+       /* Test function name lookup - erroneous address */
+       ret = bin_info_lookup_function_name(bin, 0, &func_name);
+       ok(ret == -1 && func_name == NULL,
+               "bin_info_lookup_function_name - fail on addr not found");
+
+       /* Test source location lookup */
+       ret = bin_info_lookup_source_location(bin, FUNC_FOO_ADDR, &src_loc);
+       ok(ret == 0, "bin_info_lookup_source_location successful");
+       if (src_loc) {
+               ok(src_loc->line_no == FUNC_FOO_LINE_NO,
+                       "bin_info_lookup_source_location - correct line_no");
+               ok(strcmp(src_loc->filename, FUNC_FOO_FILENAME) == 0,
+                       "bin_info_lookup_source_location - correct filename");
+               source_location_destroy(src_loc);
+               src_loc = NULL;
+       } else {
+               skip(2, "bin_info_lookup_source_location - src_loc is NULL");
+       }
+
+       /* Test source location lookup - inlined function */
+       ret = bin_info_lookup_source_location(bin, FUNC_FOO_TP_ADDR, &src_loc);
+       ok(ret == 0,
+               "bin_info_lookup_source_location (inlined func) successful");
+       if (src_loc) {
+               ok(src_loc->line_no == FUNC_FOO_TP_LINE_NO,
+                       "bin_info_lookup_source_location (inlined func) - correct line_no");
+               ok(strcmp(src_loc->filename, FUNC_FOO_TP_FILENAME) == 0,
+                       "bin_info_lookup_source_location (inlined func) - correct filename");
+               source_location_destroy(src_loc);
+               src_loc = NULL;
+       } else {
+               skip(2, "bin_info_lookup_source_location (inlined func) - src_loc is NULL");
+       }
+
+       /* Test source location lookup - erroneous address */
+       ret = bin_info_lookup_source_location(bin, 0, &src_loc);
+       ok(ret == -1 && src_loc == NULL,
+               "bin_info_lookup_source_location - fail on addr not found");
+
+       bin_info_destroy(bin);
+}
+
+int main(int argc, char **argv)
+{
+       int ret;
+
+       plan_tests(NR_TESTS);
+
+       if (argc != 2) {
+               return EXIT_FAILURE;
+       } else {
+               opt_debug_info_dir = argv[1];
+       }
+
+       ret = bin_info_init();
+       ok(ret == 0, "bin_info_init successful");
+
+       test_bin_info(opt_debug_info_dir);
+       test_bin_info_elf(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_complete.in b/tests/plugins/test_bin_info_complete.in
new file mode 100755 (executable)
index 0000000..3ca7ca2
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 - Antoine Busque <abusque@efficios.com>
+#
+# 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.
+#
+
+DEBUG_INFO_DATA="@abs_top_srcdir@/tests/debug-info-data"
+
+"@abs_top_builddir@/tests/lib/test_bin_info" "$DEBUG_INFO_DATA"
diff --git a/tests/plugins/test_dwarf.c b/tests/plugins/test_dwarf.c
new file mode 100644 (file)
index 0000000..8bae3d0
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * test_dwarf.c
+ *
+ * Babeltrace bt_dwarf (DWARF utilities) tests
+ *
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
+ *
+ * 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 <fcntl.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <lttng-utils/dwarf.h>
+#include "tap/tap.h"
+
+#define NR_TESTS 15
+
+static
+void test_bt_dwarf(const char *data_dir)
+{
+       int fd, ret, tag;
+       char path[PATH_MAX];
+       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);
+
+       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);
+}
+
+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_dwarf(data_dir);
+
+       return EXIT_SUCCESS;
+}
diff --git a/tests/plugins/test_dwarf_complete.in b/tests/plugins/test_dwarf_complete.in
new file mode 100755 (executable)
index 0000000..a3f026d
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (C) 2015 - Antoine Busque <abusque@efficios.com>
+#
+# 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.
+#
+
+DEBUG_INFO_DATA="@abs_top_srcdir@/tests/debug-info-data"
+
+"@abs_top_builddir@/tests/lib/test_dwarf" "$DEBUG_INFO_DATA"
This page took 0.036891 seconds and 4 git commands to generate.