Add constructor test.
authorIan Lance Taylor <iant@google.com>
Sun, 23 Sep 2007 03:18:42 +0000 (03:18 +0000)
committerIan Lance Taylor <iant@google.com>
Sun, 23 Sep 2007 03:18:42 +0000 (03:18 +0000)
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/constructor_test.cc [new file with mode: 0644]

index 55f387d1d03e2b0c73148cbec99522c5fdf49367..01661aaeec8b1ff74d1cdc8bd6fc2cf75490202a 100644 (file)
@@ -16,11 +16,17 @@ INCLUDES = -D_GNU_SOURCE \
 
 if GCC
 if NATIVE_LINKER
+
 NATIVE_TESTING = \
        basic_test \
        basic_pic_test \
        basic_static_test \
-       basic_static_pic_test
+       basic_static_pic_test \
+       constructor_test
+
+NATIVE_PROGS = \
+       constructor_test
+
 endif
 endif
 
@@ -31,7 +37,7 @@ libgoldtest_a_SOURCES = test.cc testmain.cc testfile.cc
 
 LDADD = libgoldtest.a ../libgold.a
 
-check_PROGRAMS = object_unittest
+check_PROGRAMS = object_unittest $(NATIVE_PROGS)
 
 object_unittest_SOURCES = object_unittest.cc
 
@@ -58,5 +64,9 @@ basic_pic_test: basic_pic_test.o gcctestdir/ld
 basic_static_pic_test: basic_pic_test.o gcctestdir/ld
        $(CXXLINK) -Bgcctestdir/ -static basic_pic_test.o
 
+constructor_test_SOURCES = constructor_test.cc
+constructor_test_DEPENDENCIES = gcctestdir/ld
+constructor_test_LDFLAGS = -Bgcctestdir/
+
 endif
 endif
index 78933e9b50636aa1fd02a5f90bef75907c23da87..5cdd95934a9784f88deb2f4c9cb94e0f163661fc 100644 (file)
@@ -42,7 +42,10 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
-check_PROGRAMS = object_unittest$(EXEEXT)
+check_PROGRAMS = object_unittest$(EXEEXT) $(am__EXEEXT_1)
+@GCC_FALSE@constructor_test_DEPENDENCIES = libgoldtest.a ../libgold.a
+@NATIVE_LINKER_FALSE@constructor_test_DEPENDENCIES = libgoldtest.a \
+@NATIVE_LINKER_FALSE@  ../libgold.a
 subdir = testsuite
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -64,6 +67,13 @@ libgoldtest_a_LIBADD =
 am_libgoldtest_a_OBJECTS = test.$(OBJEXT) testmain.$(OBJEXT) \
        testfile.$(OBJEXT)
 libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_1 =  \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test$(EXEEXT)
+am__constructor_test_SOURCES_DIST = constructor_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am_constructor_test_OBJECTS =  \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test.$(OBJEXT)
+constructor_test_OBJECTS = $(am_constructor_test_OBJECTS)
+constructor_test_LDADD = $(LDADD)
 am_object_unittest_OBJECTS = object_unittest.$(OBJEXT)
 object_unittest_OBJECTS = $(am_object_unittest_OBJECTS)
 object_unittest_LDADD = $(LDADD)
@@ -76,8 +86,11 @@ CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 CXXLD = $(CXX)
 CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
        -o $@
-SOURCES = $(libgoldtest_a_SOURCES) $(object_unittest_SOURCES)
-DIST_SOURCES = $(libgoldtest_a_SOURCES) $(object_unittest_SOURCES)
+SOURCES = $(libgoldtest_a_SOURCES) $(constructor_test_SOURCES) \
+       $(object_unittest_SOURCES)
+DIST_SOURCES = $(libgoldtest_a_SOURCES) \
+       $(am__constructor_test_SOURCES_DIST) \
+       $(object_unittest_SOURCES)
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -212,13 +225,20 @@ INCLUDES = -D_GNU_SOURCE \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_pic_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_test \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_pic_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_pic_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test
+
+@GCC_TRUE@@NATIVE_LINKER_TRUE@NATIVE_PROGS = \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test
 
 TESTS = object_unittest $(NATIVE_TESTING)
 check_LIBRARIES = libgoldtest.a
 libgoldtest_a_SOURCES = test.cc testmain.cc testfile.cc
 LDADD = libgoldtest.a ../libgold.a
 object_unittest_SOURCES = object_unittest.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_SOURCES = constructor_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_DEPENDENCIES = gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_LDFLAGS = -Bgcctestdir/
 all: all-am
 
 .SUFFIXES:
@@ -262,6 +282,9 @@ libgoldtest.a: $(libgoldtest_a_OBJECTS) $(libgoldtest_a_DEPENDENCIES)
 
 clean-checkPROGRAMS:
        -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS)
+constructor_test$(EXEEXT): $(constructor_test_OBJECTS) $(constructor_test_DEPENDENCIES) 
+       @rm -f constructor_test$(EXEEXT)
+       $(CXXLINK) $(constructor_test_LDFLAGS) $(constructor_test_OBJECTS) $(constructor_test_LDADD) $(LIBS)
 object_unittest$(EXEEXT): $(object_unittest_OBJECTS) $(object_unittest_DEPENDENCIES) 
        @rm -f object_unittest$(EXEEXT)
        $(CXXLINK) $(object_unittest_LDFLAGS) $(object_unittest_OBJECTS) $(object_unittest_LDADD) $(LIBS)
@@ -272,6 +295,7 @@ mostlyclean-compile:
 distclean-compile:
        -rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/constructor_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object_unittest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testfile.Po@am__quote@
diff --git a/gold/testsuite/constructor_test.cc b/gold/testsuite/constructor_test.cc
new file mode 100644 (file)
index 0000000..e659cc2
--- /dev/null
@@ -0,0 +1,90 @@
+// constructor_test.cc -- a test case for gold global constructors
+
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// 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; either version 3 of the License, or
+// (at your option) any later version.
+
+// 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.
+
+// This file just runs some global constructors and destructors.  The
+// last global destructor verifies that the state is as expected, and
+// we assume that it runs correctly itself.
+
+#include <cassert>
+#include <cstdlib>
+
+// These counters let us verify the state.
+
+int c1_count;
+int c2_count;
+int atexit_count;
+
+// This class verifies that there are no objects left when it is
+// destroyed.  Therefore, we can only have one instance of this
+// object.
+
+class c1
+{
+ public:
+  static int count;
+
+  c1()
+  { ++c1_count; }
+
+  ~c1()
+  {
+    --c1_count;
+    assert(c1_count == 0 && c2_count == 0 && atexit_count == 0);
+  }
+};
+
+c1 c1v;
+
+// A function called at atexit time.
+
+void
+atexit_function()
+{
+  --atexit_count;
+  assert(atexit_count == c2_count);
+}
+
+// A class which counts itself and also calls atexit.
+
+class c2
+{
+ public:
+  c2()
+  {
+    assert(atexit_count == c2_count);
+    ++c2_count;
+    atexit(atexit_function);
+    ++atexit_count;
+  }
+
+  ~c2()
+  { --c2_count; }
+};
+
+c2 c2v1;
+c2 c2v2;
+
+int
+main()
+{
+  return 0;
+}