Hi,
I've tried to check these functions in just one test, since they are very
similar. Thus, I've written the `elf-flag.c' file, which tests them so they
are all 100% covered. Tested on x86_64-redhat-linux. OK?
Marek
2011-05-07 Marek Polacek <mpolacek(a)redhat.com>
* elf-flag.c: New file.
* Makefile.am (TESTS, noinst_PROGRAMS): Add it.
(elf_flag_LDADD): New variable.
Signed-off-by: Marek Polacek <mpolacek(a)redhat.com>
---
tests/Makefile.am | 5 +-
tests/elf-flag.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+), 2 deletions(-)
create mode 100644 tests/elf-flag.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 35f55e3..cd4ebca 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,12 +58,12 @@ 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-flag
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
- update1 update2 update3 update4 \
+ update1 update2 update3 update4 elf-flag \
run-show-die-info.sh run-get-files.sh run-get-lines.sh \
run-get-pubnames.sh run-get-aranges.sh run-allfcts.sh \
run-show-abbrev.sh run-line2addr.sh hash \
@@ -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_flag_LDADD = $(libelf) $(libmudflap)
if GCOV
check: check-am coverage
diff --git a/tests/elf-flag.c b/tests/elf-flag.c
new file mode 100644
index 0000000..c208238
--- /dev/null
+++ b/tests/elf-flag.c
@@ -0,0 +1,108 @@
+/* Check elf_flag{data,ehdr,elf,phdr} functions.
+ 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>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include "libelfP.h"
+
+int
+main (int argc __attribute__ ((unused)), char *argv[])
+{
+ bool result = false;
+
+ /* Open ourselves. */
+ 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);
+
+ /* Create an ELF descriptor. */
+ Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
+ return 1;
+ }
+
+/* Lazy bastard, eh? */
+#define TEST_FLAG(type) \
+ result |= elf_flag##type (NULL, ELF_C_SET, ELF_F_DIRTY); \
+ result |= elf_flag##type (elf, ELF_C_SET, ELF_F_DIRTY) == 0; \
+ result |= elf_flag##type (elf, ELF_C_CLR, ELF_F_DIRTY); \
+ result |= elf_flag##type (elf, ELF_C_EMPTY, ELF_F_DIRTY); \
+ elf->kind = ELF_K_COFF; \
+ result |= elf_flag##type (elf, ELF_C_SET, ELF_F_DIRTY); \
+ elf->kind = ELF_K_ELF;
+
+ /* Test the elf_flagelf. */
+ TEST_FLAG (elf);
+
+ /* Test the elf_flagehdr. */
+ TEST_FLAG (ehdr);
+
+ /* Test the elf_flagphdr. */
+ TEST_FLAG (phdr);
+
+ /* Test the elf_flagdata. */
+ Elf_Scn *scn = NULL;
+ scn = elf_nextscn (elf, scn);
+ if (scn == NULL)
+ return 1;
+
+ Elf_Data *data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ return 1;
+
+ /* Try with NULL parameter. */
+ result |= elf_flagdata (NULL, ELF_C_SET, ELF_F_DIRTY);
+
+ /* Try to set a flag. */
+ result |= elf_flagdata (data, ELF_C_SET, ELF_F_DIRTY) == 0;
+
+ /* Try to clear a flag. */
+ result |= elf_flagdata (data, ELF_C_CLR, ELF_F_DIRTY) == 0;
+
+ /* Try an insane command. */
+ result |= elf_flagdata (data, ELF_C_EMPTY, ELF_F_DIRTY);
+
+ /* Set a kind that is not the ELF_K_ELF. */
+ scn->elf->kind = ELF_K_COFF;
+ result |= elf_flagdata (data, ELF_C_SET, ELF_F_DIRTY);
+
+ return result;
+}
--
1.7.3.4