-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Here's an attempt to cover elf_clone. I've tried to memcmp elf and cloned
elf, but this way it didn't work so I've used just manual comparison of
values. Tested on x86_64. Ok?
Signed-off-by: Marek Polacek <mpolacek(a)redhat.com>
- ---
tests/ChangeLog | 7 ++++
tests/Makefile.am | 7 ++--
tests/elf-clone.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
tests/run-elf-clone.sh | 30 +++++++++++++++++++
4 files changed, 115 insertions(+), 3 deletions(-)
create mode 100644 tests/elf-clone.c
create mode 100755 tests/run-elf-clone.sh
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 674fe96..3c51b13 100644
- --- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-31 Marek Polacek <mpolacek(a)redhat.com>
+
+ * elf-clone.c: New file.
+ * run-elf-clone.sh: Use it.
+ * Makefile.am (TESTS, EXTRA_DIST, noinst_PROGRAMS): Add files.
+ (elf_clone_LDADD): New variable.
+
2011-03-28 Marek Polacek <mpolacek(a)redhat.com>
* alldts.c: New file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 35f55e3..83d6b25 100644
- --- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames
sectiondump \
dwfl-addr-sect dwfl-bug-report early-offscn \
dwfl-bug-getmodules dwarf-getmacros addrcfi \
test-flag-nobits dwarf-getstring rerequest_tag \
- - alldts
+ alldts elf-clone
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -80,7 +80,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-readelf-test4.sh run-readelf-twofiles.sh \
run-native-test.sh run-bug1-test.sh \
dwfl-bug-addr-overflow run-addrname-test.sh \
- - dwfl-bug-fd-leak dwfl-bug-report \
+ dwfl-bug-fd-leak dwfl-bug-report run-elf-clone.sh \
run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
run-disasm-x86.sh run-disasm-x86-64.sh \
run-early-offscn.sh run-dwarf-getmacros.sh \
@@ -119,7 +119,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-addrname-test.sh run-dwfl-bug-offline-rel.sh \
run-dwfl-addr-sect.sh run-early-offscn.sh \
run-dwarf-getmacros.sh run-test-flag-nobits.sh \
- - run-dwarf-getstring.sh run-alldts.sh \
+ run-dwarf-getstring.sh run-alldts.sh run-elf-clone.sh \
testfile15.bz2 testfile15.debug.bz2 \
testfile16.bz2 testfile16.debug.bz2 \
testfile17.bz2 testfile17.debug.bz2 \
@@ -255,6 +255,7 @@ addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
test_flag_nobits_LDADD = $(libelf) $(libmudflap)
rerequest_tag_LDADD = $(libdw) $(libmudflap)
alldts_LDADD = $(libebl) $(libelf) $(libmudflap)
+elf_clone_LDADD = $(libelf) $(libmudflap)
if GCOV
check: check-am coverage
diff --git a/tests/elf-clone.c b/tests/elf-clone.c
new file mode 100644
index 0000000..a5d9b4b
- --- /dev/null
+++ b/tests/elf-clone.c
@@ -0,0 +1,74 @@
+/* Test for elf_clone.
+ Copyright (C) 2011 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+ Written by Marek Polacek <mpolacek(a)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>. */
+
+#include <elf.h>
+#include <fcntl.h>
+#include <libelf.h>
+#include <libelfP.h>
+#include <stdio.h>
+
+
+int
+main (int argc __attribute__ ((unused)), char *argv[])
+{
+ /* Open ourselves for reading. */
+ int fd = open64 (argv[0], O_RDONLY);
+ if (fd == -1)
+ {
+ printf ("cannot open `%s': %m\n", argv[0]);
+ return 1;
+ }
+
+ /* Tell the library which version are we expecting. */
+ elf_version (EV_CURRENT);
+
+ /* Get an ELF descriptor. */
+ struct Elf *elf = elf_begin (fd, ELF_C_RDWR, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ return 1;
+ }
+
+ /* This should return NULL. */
+ Elf *newelf = elf_clone (NULL, ELF_C_EMPTY);
+ if (newelf != NULL)
+ return 1;
+
+ /* Clone our descriptor. */
+ newelf = elf_clone (elf, ELF_C_EMPTY);
+
+ return !(elf->fildes == newelf->fildes
+ && elf->map_address == newelf->map_address
+ && elf->kind == newelf->kind
+ && elf->parent == newelf->parent
+ && elf->class == newelf->class
+ && elf->cmd == newelf->cmd
+ && elf->start_offset == newelf->start_offset
+ && elf->maximum_size == newelf->maximum_size
+ && newelf->ref_count == 1
+ && newelf->flags == ELF_F_DIRTY);
+}
diff --git a/tests/run-elf-clone.sh b/tests/run-elf-clone.sh
new file mode 100755
index 0000000..b2ac8e3
- --- /dev/null
+++ b/tests/run-elf-clone.sh
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2011 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
+
+testrun ./elf-clone
+
+exit 0
- --
1.7.3.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iF4EAREIAAYFAk2UyOMACgkQt3gKtVPE8IKNzAEAhFRChFRXxTwdz+YzIo0WeVev
hnWD3rlcUkjDfEQMz/sA/3Q4di0qKYuJa9UdoeTJ/VkyI+7x4ode1mKL+oFY2ZJr
=LeGe
-----END PGP SIGNATURE-----