This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
new libdwfl/core-file test
- From: Marek Polacek <mpolacek at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Mon, 23 May 2011 22:58:01 +0200
- Subject: new libdwfl/core-file test
Hi!
Here is an attempt to test the libdw/core-file.c. First of all,
it was needed to create an ET_CORE file. I did it running the
following program (and increasing the ulimit -c):
mpolacek(a)pdp-11 ~/wtf $ cat zz.c
extern void abort (void) __attribute__ ((__noreturn__));
int
main (void)
{
abort ();
}
The resulting coredump is now the `testfile59.bz2.'
To achieve a better coverage I've used both ELF_C_READ{,_MMAP}.
Is it OK?
2011-05-23 Marek Polacek <mpolacek@redhat.com>
* dwfl-core-file.c: New test.
* run-dwfl-core-file.sh: Use it.
* testfile59.bz2: New test file.
* Makefile.am (EXTRA_DIST): Add testfile59.bz2.
(TESTS, EXTRA_DIST, noinst_PROGRAMS): Add new test.
(dwfl_core_file_LDADD): New variable.
--- elfutils/tests/dwfl-core-file.c.mp 2011-05-23 21:53:09.899212741 +0200
+++ elfutils/tests/dwfl-core-file.c 2011-05-23 21:27:00.472216488 +0200
@@ -0,0 +1,99 @@
+/* Test program for dwfl core file handling.
+ Copyright (C) 2011 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+ Written by Marek Polacek <mpolacek@redhat.com>, 2011.
+
+ Red Hat elfutils 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; version 2 of the License.
+
+ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include ELFUTILS_HEADER(dwfl)
+
+
+int
+main (int argc, char *argv[])
+{
+ static const Dwfl_Callbacks callbacks =
+ {
+ .find_elf = dwfl_build_id_find_elf,
+ .find_debuginfo = dwfl_standard_find_debuginfo,
+ };
+
+ if (argc != 2)
+ return 1;
+
+ /* Open the file. */
+ int fd = open64 (argv[1], O_RDONLY, 0666);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %m\n", argv[1]);
+ return 1;
+ }
+
+ /* Set the ELF version. */
+ elf_version (EV_CURRENT);
+
+ /* Create an ELF descriptor. */
+ Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ fail:
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ return 1;
+ }
+
+ /* Set up a session. */
+ Dwfl *dwfl = dwfl_begin (&callbacks);
+ if (dwfl == NULL)
+ {
+ printf ("dwfl_begin: %s", dwfl_errmsg (-1));
+ return 1;
+ }
+
+ /* Get the number of modules. */
+ int n = dwfl_core_file_report (dwfl, elf);
+ assert (n == 4);
+
+ elf_end (elf);
+
+ /* Now do the same, only mmap the ELF file, so the
+ elf->map_address is non-NULL. */
+ elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
+ if (elf == NULL)
+ goto fail;
+
+ n = dwfl_core_file_report (dwfl, elf);
+ assert (n == 4);
+
+ /* Free the resources. */
+ elf_end (elf);
+ close (fd);
+ dwfl_end (dwfl);
+
+ return 0;
+}
--- elfutils/tests/run-dwfl-core-file.sh.mp 2011-05-23 21:52:40.030218106 +0200
+++ elfutils/tests/run-dwfl-core-file.sh 2011-05-23 21:52:40.030218106 +0200
@@ -0,0 +1,32 @@
+#! /bin/sh
+# Copyright (C) 2007-2009 Red Hat, Inc.
+# This file is part of Red Hat elfutils.
+#
+# Red Hat elfutils 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; version 2 of the License.
+#
+# Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+#
+# Red Hat elfutils is an included package of the Open Invention Network.
+# An included package of the Open Invention Network is a package for which
+# Open Invention Network licensees cross-license their patents. No patent
+# license is granted, either expressly or impliedly, by designation as an
+# included package. Should you wish to participate in the Open Invention
+# Network licensing program, please visit www.openinventionnetwork.com
+# <http://www.openinventionnetwork.com>.
+
+. $srcdir/test-subr.sh
+
+testfiles testfile59
+
+./dwfl-core-file testfile59
+
+exit 0
--- elfutils/tests/Makefile.am.mp 2011-05-23 21:58:22.000000000 +0200
+++ elfutils/tests/Makefile.am 2011-05-23 22:40:08.762217155 +0200
@@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest ne
dwfl-addr-sect dwfl-bug-report early-offscn \
dwfl-bug-getmodules dwarf-getmacros addrcfi \
test-flag-nobits dwarf-getstring rerequest_tag \
- alldts
+ alldts dwfl-core-file
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -78,7 +78,7 @@ TESTS = run-arextract.sh run-arsymtest.s
run-find-prologues.sh run-allregs.sh \
run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \
run-readelf-test4.sh run-readelf-twofiles.sh \
- run-native-test.sh run-bug1-test.sh \
+ run-native-test.sh run-bug1-test.sh run-dwfl-core-file.sh \
dwfl-bug-addr-overflow run-addrname-test.sh \
dwfl-bug-fd-leak dwfl-bug-report \
run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
@@ -143,7 +143,7 @@ EXTRA_DIST = run-arextract.sh run-arsymt
testfile45.S.bz2 testfile45.expect.bz2 run-disasm-x86-64.sh \
testfile46.bz2 testfile47.bz2 testfile48.bz2 testfile48.debug.bz2 \
testfile49.bz2 testfile50.bz2 testfile51.bz2 \
- run-prelink-addr-test.sh \
+ run-prelink-addr-test.sh run-dwfl-core-file.sh \
testfile52-32.so.bz2 testfile52-32.so.debug.bz2 \
testfile52-32.prelink.so.bz2 testfile52-32.noshdrs.so.bz2 \
testfile52-64.so.bz2 testfile52-64.so.debug.bz2 \
@@ -158,7 +158,8 @@ EXTRA_DIST = run-arextract.sh run-arsymt
testfile55-32.bz2 testfile55-32.debug.bz2 \
testfile55-32.prelink.bz2 testfile55-64.bz2 \
testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \
- testfile56.bz2 testfile57.bz2 testfile58.bz2
+ testfile56.bz2 testfile57.bz2 testfile58.bz2 \
+ testfile59.bz2
installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
bindir=$(DESTDIR)$(bindir) \
@@ -255,6 +256,7 @@ addrcfi_LDADD = $(libdw) $(libebl) $(lib
test_flag_nobits_LDADD = $(libelf) $(libmudflap)
rerequest_tag_LDADD = $(libdw) $(libmudflap)
alldts_LDADD = $(libebl) $(libelf) $(libmudflap)
+dwfl_core_file_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
if GCOV
check: check-am coverage