Add a testcase for PR binutils/14567
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 6 Nov 2012 23:45:43 +0000 (23:45 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 6 Nov 2012 23:45:43 +0000 (23:45 +0000)
binutils/

PR binutils/14567
* Makefile.am (BFDTEST2_PROG): New.
(bfdtest2_DEPENDENCIES): Likewise.
(TEST_PROGS): Add $(BFDTEST2_PROG).
* Makefile.in: Regenerated.
* bfdtest2.c: New file.

binutils/testsuite/

PR binutils/14567
* binutils-all/ar.exp (bfdtest1): Removed.
(long_filenames): Take bfdtests.
(thin_archive): Likewise.
(thin_archive_with_nested): Likewise.
(bfdtests): New.
Pass $bfdtests to long_filenames, thin_archive and
thin_archive_with_nested.

binutils/ChangeLog
binutils/Makefile.am
binutils/Makefile.in
binutils/bfdtest2.c [new file with mode: 0644]
binutils/testsuite/ChangeLog
binutils/testsuite/binutils-all/ar.exp

index 387b34b44b99886cced4632a12cd71708e37a76b..84ea185c4f80bc62439395de4e3600cd2ba65bed 100644 (file)
@@ -1,3 +1,12 @@
+2012-11-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/14567
+       * Makefile.am (BFDTEST2_PROG): New.
+       (bfdtest2_DEPENDENCIES): Likewise.
+       (TEST_PROGS): Add $(BFDTEST2_PROG).
+       * Makefile.in: Regenerated.
+       * bfdtest2.c: New file.
+
 2012-11-05  Stephane Carrez  <Stephane.Carrez@gmail.com>
 
        * MAINTAINERS: Update my email address.
index f16de990876bf6b216ce36739280f9112838b285..be6e832500f24108bc95e4f096cdfaafae3d5ff5 100644 (file)
@@ -67,8 +67,9 @@ EXTRA_SCRIPTS = embedspu
 
 ## Test programs.
 BFDTEST1_PROG = bfdtest1
+BFDTEST2_PROG = bfdtest2
 
-TEST_PROGS = $(BFDTEST1_PROG)
+TEST_PROGS = $(BFDTEST1_PROG) $(BFDTEST2_PROG)
 
 ## We need a special rule to install the programs which are built with
 ## -new, and to rename cxxfilt to c++filt.
@@ -200,6 +201,7 @@ readelf_DEPENDENCIES =   $(LIBINTL_DEP) $(LIBIBERTY)
 elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 dllwrap_DEPENDENCIES =   $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
+bfdtest2_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 
 LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
 
index 59b10aa5759e4467f8146b117fb4fec597c56503..95e0b5bf279d744489f53d8dd855823a51ea14f8 100644 (file)
@@ -41,7 +41,7 @@ bin_PROGRAMS = $(am__EXEEXT_6) $(am__EXEEXT_7) $(am__EXEEXT_8) \
        @BUILD_NLMCONV@ @BUILD_SRCONV@ @BUILD_DLLTOOL@ @BUILD_WINDRES@ \
        @BUILD_WINDMC@ $(am__EXEEXT_12) $(am__EXEEXT_13) \
        $(am__EXEEXT_14) @BUILD_DLLWRAP@
-noinst_PROGRAMS = $(am__EXEEXT_18) $(am__EXEEXT_20) @BUILD_MISC@
+noinst_PROGRAMS = $(am__EXEEXT_18) $(am__EXEEXT_21) @BUILD_MISC@
 EXTRA_PROGRAMS = $(am__EXEEXT_1) srconv$(EXEEXT) sysdump$(EXEEXT) \
        coffdump$(EXEEXT) $(am__EXEEXT_2) $(am__EXEEXT_3) \
        $(am__EXEEXT_4) $(am__EXEEXT_5)
@@ -102,7 +102,8 @@ am__EXEEXT_16 = strip-new$(EXEEXT)
 am__EXEEXT_17 = cxxfilt$(EXEEXT)
 am__EXEEXT_18 = $(am__EXEEXT_15) $(am__EXEEXT_16) $(am__EXEEXT_17)
 am__EXEEXT_19 = bfdtest1$(EXEEXT)
-am__EXEEXT_20 = $(am__EXEEXT_19)
+am__EXEEXT_20 = bfdtest2$(EXEEXT)
+am__EXEEXT_21 = $(am__EXEEXT_19) $(am__EXEEXT_20)
 PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
 am__objects_1 = bucomm.$(OBJEXT) version.$(OBJEXT) filemode.$(OBJEXT)
 am_addr2line_OBJECTS = addr2line.$(OBJEXT) $(am__objects_1)
@@ -116,6 +117,9 @@ ar_OBJECTS = $(am_ar_OBJECTS)
 bfdtest1_SOURCES = bfdtest1.c
 bfdtest1_OBJECTS = bfdtest1.$(OBJEXT)
 bfdtest1_LDADD = $(LDADD)
+bfdtest2_SOURCES = bfdtest2.c
+bfdtest2_OBJECTS = bfdtest2.$(OBJEXT)
+bfdtest2_LDADD = $(LDADD)
 am_coffdump_OBJECTS = coffdump.$(OBJEXT) coffgrok.$(OBJEXT) \
        $(am__objects_1)
 coffdump_OBJECTS = $(am_coffdump_OBJECTS)
@@ -226,7 +230,7 @@ YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS)
 LTYACCCOMPILE = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(YACC) $(YFLAGS) $(AM_YFLAGS)
 SOURCES = $(addr2line_SOURCES) $(ar_SOURCES) $(EXTRA_ar_SOURCES) \
-       bfdtest1.c $(coffdump_SOURCES) $(cxxfilt_SOURCES) \
+       bfdtest1.c bfdtest2.c $(coffdump_SOURCES) $(cxxfilt_SOURCES) \
        $(dlltool_SOURCES) $(dllwrap_SOURCES) $(elfedit_SOURCES) \
        $(nlmconv_SOURCES) $(nm_new_SOURCES) $(objcopy_SOURCES) \
        $(objdump_SOURCES) $(EXTRA_objdump_SOURCES) $(ranlib_SOURCES) \
@@ -449,7 +453,8 @@ SRCONV_PROG = srconv$(EXEEXT) sysdump$(EXEEXT) coffdump$(EXEEXT)
 bin_SCRIPTS = @BUILD_INSTALL_MISC@
 EXTRA_SCRIPTS = embedspu
 BFDTEST1_PROG = bfdtest1
-TEST_PROGS = $(BFDTEST1_PROG)
+BFDTEST2_PROG = bfdtest2
+TEST_PROGS = $(BFDTEST1_PROG) $(BFDTEST2_PROG)
 RENAMED_PROGS = $(NM_PROG) $(STRIP_PROG) $(DEMANGLER_PROG)
 
 # Stuff that goes in tooldir/ if appropriate.
@@ -545,6 +550,7 @@ readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
+bfdtest2_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
 size_SOURCES = size.c $(BULIBS)
 objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
@@ -721,6 +727,9 @@ ar$(EXEEXT): $(ar_OBJECTS) $(ar_DEPENDENCIES)
 bfdtest1$(EXEEXT): $(bfdtest1_OBJECTS) $(bfdtest1_DEPENDENCIES) 
        @rm -f bfdtest1$(EXEEXT)
        $(LINK) $(bfdtest1_OBJECTS) $(bfdtest1_LDADD) $(LIBS)
+bfdtest2$(EXEEXT): $(bfdtest2_OBJECTS) $(bfdtest2_DEPENDENCIES) 
+       @rm -f bfdtest2$(EXEEXT)
+       $(LINK) $(bfdtest2_OBJECTS) $(bfdtest2_LDADD) $(LIBS)
 coffdump$(EXEEXT): $(coffdump_OBJECTS) $(coffdump_DEPENDENCIES) 
        @rm -f coffdump$(EXEEXT)
        $(LINK) $(coffdump_OBJECTS) $(coffdump_LDADD) $(LIBS)
@@ -842,6 +851,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arparse.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arsup.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bfdtest1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bfdtest2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bin2c.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/binemul.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bucomm.Po@am__quote@
diff --git a/binutils/bfdtest2.c b/binutils/bfdtest2.c
new file mode 100644 (file)
index 0000000..a0bdd7c
--- /dev/null
@@ -0,0 +1,106 @@
+/* A program to test BFD.\r
+   Copyright 2012 Free Software Foundation, Inc.\r
+\r
+   This file is part of the GNU Binutils.\r
+\r
+   This program is free software; you can redistribute it and/or modify\r
+   it under the terms of the GNU General Public License as published by\r
+   the Free Software Foundation; either version 3 of the License, or\r
+   (at your option) any later version.\r
+\r
+   This program is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with this program; if not, write to the Free Software\r
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,\r
+   MA 02110-1301, USA.  */\r
+\r
+#include "sysdep.h"\r
+#include "bfd.h"\r
+\r
+static void\r
+die (const char *s)\r
+{\r
+  printf ("oops: %s\n", s);\r
+  exit (1);\r
+}\r
+\r
+static void *\r
+iovec_open (struct bfd *nbfd ATTRIBUTE_UNUSED, void *open_closure)\r
+{\r
+  return open_closure;\r
+}\r
+\r
+static file_ptr iovec_read (struct bfd *nbfd ATTRIBUTE_UNUSED,\r
+                           void *stream, void *buf, file_ptr nbytes,\r
+                           file_ptr offset)\r
+{\r
+  FILE* file = (FILE*) stream;\r
+\r
+  if (fseek(file, offset, SEEK_SET) != 0)\r
+    die ("fseek error");\r
+\r
+  return fread (buf, 1, nbytes, file);\r
+}\r
+\r
+static int\r
+iovec_stat (struct bfd *abfd ATTRIBUTE_UNUSED, \r
+           void *stream, struct stat *sb)\r
+{\r
+  return fstat (fileno ((FILE*) stream), sb);\r
+}\r
+\r
+static bfd_boolean\r
+check_format_any (struct bfd *abfd, bfd_format format)\r
+{\r
+  char** targets = NULL;\r
+\r
+  if (bfd_check_format_matches (abfd, format, &targets))\r
+    return TRUE;\r
+\r
+  if (targets)\r
+    {\r
+      bfd_find_target (targets[0], abfd);\r
+\r
+      return bfd_check_format (abfd, format);\r
+    }\r
+\r
+  return FALSE;\r
+}\r
+\r
+int\r
+main (int argc, const char** argv)\r
+{\r
+  FILE* file;\r
+  bfd *abfd, *mbfd;\r
+\r
+  if (argc < 2)\r
+    die ("Usage: test archivefile");\r
+\r
+  file = fopen(argv[1], "rb");\r
+  if (!file)\r
+    die ("file not found");\r
+\r
+  abfd = bfd_openr_iovec (argv[1], 0, iovec_open, file,\r
+                         iovec_read, NULL, iovec_stat);\r
+  if (!abfd)\r
+    die ("error opening file");\r
+\r
+  if (!check_format_any (abfd, bfd_archive))\r
+    die ("not an archive");\r
+\r
+  mbfd = bfd_openr_next_archived_file (abfd, 0);\r
+  if (!mbfd)\r
+    die ("error opening archive member");\r
+\r
+  if (!bfd_close (mbfd))\r
+    die ("error closing archive member");\r
+\r
+  if (!bfd_close (abfd))\r
+    die ("error closing archive");\r
+\r
+  return 0;\r
+}\r
index 229b2844bf7795ff1c8138d7ce2004c973e7a19a..b6ddda63d5d44460199121ea6e86a82a9f1f3706 100644 (file)
@@ -1,3 +1,14 @@
+2012-11-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/14567
+       * binutils-all/ar.exp (bfdtest1): Removed.
+       (long_filenames): Take bfdtests.
+       (thin_archive): Likewise.
+       (thin_archive_with_nested): Likewise.
+       (bfdtests): New.
+       Pass $bfdtests to long_filenames, thin_archive and
+       thin_archive_with_nested.
+
 2012-10-29  Alan Modra  <amodra@gmail.com>
 
        * binutils-all/copy-3.d: Exclude all cygwin and mingw targets,
index 8b7629ecce134f1ae281105b4173370fd8b3ff90..6efc1598472586233223023a94b326e58b38d1df 100644 (file)
@@ -27,16 +27,14 @@ if ![is_remote host] {
     }
 }
 
-set bfdtest1 $base_dir/bfdtest1
-
 # send_user "Version [binutil_version $AR]"
 
 # Test long file name support
 
-proc long_filenames { } {
+proc long_filenames { bfdtests } {
     global AR
     global host_triplet
-    global bfdtest1
+    global base_dir
 
     set testname "ar long file names"
 
@@ -126,11 +124,13 @@ proc long_filenames { } {
        return
     }
 
-    set exec_output [binutils_run $bfdtest1 "$dest"]
-    if ![string match "" $exec_output] {
-       verbose -log $exec_output
-       fail "$testname (bfdtest1)"
-       return
+    foreach bfdtest $bfdtests {
+       set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
+       if ![string match "" $exec_output] {
+           verbose -log $exec_output
+           fail "$testname ($bfdtest)"
+           return
+       }
     }
 
     if [is_remote host] {
@@ -227,13 +227,13 @@ proc symbol_table { } {
 
 # Test building a thin archive.
 
-proc thin_archive { } {
+proc thin_archive { bfdtests } {
     global AR
     global AS
     global NM
     global srcdir
     global subdir
-    global bfdtest1
+    global base_dir
 
     set testname "ar thin archive"
 
@@ -259,11 +259,13 @@ proc thin_archive { } {
        return
     }
 
-    set exec_output [binutils_run $bfdtest1 "$archive"]
-    if ![string match "" $exec_output] {
-       verbose -log $exec_output
-       fail "$testname (bfdtest1)"
-       return
+    foreach bfdtest $bfdtests {
+       set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
+       if ![string match "" $exec_output] {
+           verbose -log $exec_output
+           fail "$testname ($bfdtest)"
+           return
+       }
     }
 
     set got [binutils_run $NM "--print-armap $archive"]
@@ -282,13 +284,13 @@ proc thin_archive { } {
 
 # Test building a thin archive with a nested archive.
 
-proc thin_archive_with_nested { } {
+proc thin_archive_with_nested { bfdtests } {
     global AR
     global AS
     global NM
     global srcdir
     global subdir
-    global bfdtest1
+    global base_dir
 
     set testname "ar thin archive with nested archive"
 
@@ -324,18 +326,20 @@ proc thin_archive_with_nested { } {
        return
     }
 
-    set exec_output [binutils_run $bfdtest1 "$archive"]
-    if ![string match "" $exec_output] {
-       verbose -log $exec_output
-       fail "$testname (bfdtest1)"
-       return
-    }
+    foreach bfdtest $bfdtests {
+       set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
+       if ![string match "" $exec_output] {
+           verbose -log $exec_output
+           fail "$testname ($bfdtest)"
+           return
+       }
 
-    set exec_output [binutils_run $bfdtest1 "$archive2"]
-    if ![string match "" $exec_output] {
-       verbose -log $exec_output
-       fail "$testname (bfdtest1)"
-       return
+       set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
+       if ![string match "" $exec_output] {
+           verbose -log $exec_output
+           fail "$testname ($bfdtest)"
+           return
+       }
     }
 
     set got [binutils_run $NM "--print-armap $archive"]
@@ -554,10 +558,12 @@ proc move_an_element { } {
 
 # Run the tests.
 
-long_filenames
+set bfdtests [list bfdtest1 bfdtest2]
+
+long_filenames $bfdtests
 symbol_table
-thin_archive
-thin_archive_with_nested
+thin_archive $bfdtests
+thin_archive_with_nested $bfdtests
 argument_parsing
 deterministic_archive
 delete_an_element
This page took 0.031404 seconds and 4 git commands to generate.