static library for testsuite runs

Phil Edwards phil@jaj.com
Fri May 24 13:09:00 GMT 2002


This patch creates a library, libv3test.a, in the testsuite directory for
linking against while creating executables.  It moves the implementation
code from testsuite_hooks.h out into a .cc file and then bases the library
on that file.  The only pseudo-new functionality is that a useful class
from one of the test files is pulled out and added to the hooks.

Future possibilities include building special files into the library for
particular targets that need it.  Or whatever.


This does not use libtool.  Should it?  I have no particular desire to
take the two most opaque GNU projects (dejagnu and libtool) and figure
out from first principles how to tie them together.

Also, this should be tested on a platform which uses multilibs.  I have
not been able to build on sparc since before I developed the patch, and
I have no other multilib-using platform available.


As I mentioned on the list before 3.1, I've been using this for a while now.
My initial motivation was bringing the testsuite results for concept-checking
into line with those without concept-checking.  (C-c adds two regressions.
This fixes one problem in passing; one remains.)


2002-05-24  Phil Edwards  <pme@gcc.gnu.org>

	* Makefile.am (noinst_LIBRARIES):  New target.  Pull in CXX/INCLUDES.
	* testsuite_hooks.h (gnu_copy_tracker):  Move from list_modifiers.cc
	and rename from 'T'.  Move code bodies...
	* testsuite_hooks.cc:  ...to here.  New file.
	* 23_containers/list_modifiers.cc:  Move 'T' class out.
	* lib/libstdc++-v3-dg.exp (libstdc++-v3_target_compile):  Add
	libv3test.a to link options.


Index: Makefile.am
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/testsuite/Makefile.am,v
retrieving revision 1.4
diff -u -3 -p -r1.4 Makefile.am
--- Makefile.am	14 May 2001 01:15:35 -0000	1.4
+++ Makefile.am	6 May 2002 20:52:13 -0000
@@ -1,6 +1,6 @@
 ## Makefile for the testsuite subdirectory of the GNU C++ Standard library.
 ##
-## Copyright (C) 2001 Free Software Foundation, Inc.
+## Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 ##
 ## This file is part of the libstdc++ version 3 distribution.
 ## Process this file with automake to produce Makefile.in.
@@ -34,4 +34,13 @@ RUNTEST = `if [ -f @glibcpp_srcdir@/../d
 	    else echo runtest; fi`
 
 RUNTESTFLAGS =
+
+CXX = @glibcpp_CXX@ @GLIBCPP_INCLUDES@
+# Use common includes from acinclude.m4/GLIBCPP_EXPORT_INCLUDES
+INCLUDES = @TOPLEVEL_INCLUDES@
+
+noinst_LIBRARIES = libv3test.a
+
+libv3test_a_SOURCES = testsuite_hooks.cc
+
 
Index: testsuite_hooks.h
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/testsuite/testsuite_hooks.h,v
retrieving revision 1.6
diff -u -3 -p -r1.6 testsuite_hooks.h
--- testsuite_hooks.h	15 May 2002 15:57:05 -0000	1.6
+++ testsuite_hooks.h	16 May 2002 19:36:44 -0000
@@ -46,6 +46,10 @@
 //   which starts at zero, increments on instance construction, and decrements
 //   on instance destruction.  "assert_count(n)" can be called to VERIFY()
 //   that the count equals N.
+//
+// 4)  gnu_copy_tracker, from Stephen M. Webb <stephen@bregmasoft.com>.
+//   A class with nontrivial ctor/dtor that provides the ability to track the
+//   number of copy ctors and dtors, and will throw on demand during copy.
 
 #ifndef _GLIBCPP_TESTSUITE_HOOKS_H
 #define _GLIBCPP_TESTSUITE_HOOKS_H
@@ -61,64 +65,28 @@
 
 // Defined in GLIBCPP_CONFIGURE_TESTSUITE.
 #ifndef _GLIBCPP_MEM_LIMITS
-
 // Don't do memory limits.
-void
+extern void
 __set_testsuite_memlimit(float x = 0)
 { }
 
 #else
 
 // Do memory limits.
-#include <sys/resource.h>
-#include <unistd.h>
-
 #ifndef MEMLIMIT_MB
 #define MEMLIMIT_MB 16.0
 #endif
 
-void
-__set_testsuite_memlimit(float __size = MEMLIMIT_MB)
-{
-    struct rlimit r;
-    rlim_t limit = (rlim_t)(__size * 1048576);
-
-    // Heap size, seems to be common.
-#if _GLIBCPP_HAVE_MEMLIMIT_DATA
-    getrlimit(RLIMIT_DATA, &r);
-    r.rlim_cur = limit;
-    setrlimit(RLIMIT_DATA, &r);
-#endif
-
-    // Resident set size.
-#if _GLIBCPP_HAVE_MEMLIMIT_RSS
-    getrlimit(RLIMIT_RSS, &r);
-    r.rlim_cur = limit;
-    setrlimit(RLIMIT_RSS, &r);
-#endif
-
-    // Mapped memory (brk + mmap).
-#if _GLIBCPP_HAVE_MEMLIMIT_VMEM
-    getrlimit(RLIMIT_VMEM, &r);
-    r.rlim_cur = limit;
-    setrlimit(RLIMIT_VMEM, &r);
-#endif
-
-    // Virtual memory.
-#if _GLIBCPP_HAVE_MEMLIMIT_AS
-    getrlimit(RLIMIT_AS, &r);
-    r.rlim_cur = limit;
-    setrlimit(RLIMIT_AS, &r);
-#endif
-}
+extern void
+__set_testsuite_memlimit(float __size = MEMLIMIT_MB);
 #endif
 
 
 struct gnu_counting_struct
 {
     // Specifically and glaringly-obviously marked 'signed' so that when
-    // count mistakenly goes negative, we can track the patterns of
-    // deletions easier.
+    // COUNT mistakenly goes negative, we can track the patterns of
+    // deletions more easily.
     typedef  signed int     size_type;
     static size_type   count;
     gnu_counting_struct() { ++count; }
@@ -128,7 +96,56 @@ struct gnu_counting_struct
 
 #define assert_count(n)   VERIFY(gnu_counting_struct::count == n)
 
-gnu_counting_struct::size_type  gnu_counting_struct::count = 0;
+
+class gnu_copy_tracker
+{
+  public:
+    // Cannot be explicit.  Conversion ctor used by list_modifiers.cc's
+    // test03(), "range fill at beginning".
+    gnu_copy_tracker (int anId, bool throwOnDemand = false)
+    : itsId(anId), willThrow(throwOnDemand)
+    {}
+
+    gnu_copy_tracker (const gnu_copy_tracker& rhs)
+    : itsId(rhs.id()), willThrow(rhs.willThrow)
+    {
+      ++itsCopyCount;
+      if (willThrow) throw "copy tracker exception";
+    }
+
+    gnu_copy_tracker& operator=(const gnu_copy_tracker& rhs)
+    {
+      itsId = rhs.id();
+      // willThrow must obviously already be false to get this far
+    }
+
+    ~gnu_copy_tracker() { ++itsDtorCount; }
+
+    int
+    id() const
+    { return itsId; }
+
+  private:
+          int   itsId;
+    const bool  willThrow;
+
+  public:
+    static void
+    reset()
+    { itsCopyCount = 0; itsDtorCount = 0; }
+
+    static int
+    copyCount() 
+    { return itsCopyCount; }
+
+    static int
+    dtorCount() 
+    { return itsDtorCount; }
+
+  private:
+    static int itsCopyCount;
+    static int itsDtorCount;
+};
 
 
 #endif // _GLIBCPP_TESTSUITE_HOOKS_H
Index: testsuite_hooks.cc
===================================================================
RCS file: testsuite_hooks.cc
diff -N testsuite_hooks.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite_hooks.cc	16 May 2002 19:36:47 -0000
@@ -0,0 +1,77 @@
+// Utility subroutines for the C++ library testsuite.
+//
+// Copyright (C) 2002 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
+// any later version.
+//
+// This library 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 library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+//
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCPP_MEM_LIMITS
+#include <sys/resource.h>
+#include <unistd.h>
+
+void
+__set_testsuite_memlimit(float __size)
+{
+    struct rlimit r;
+    rlim_t limit = (rlim_t)(__size * 1048576);
+
+    // Heap size, seems to be common.
+#if _GLIBCPP_HAVE_MEMLIMIT_DATA
+    getrlimit(RLIMIT_DATA, &r);
+    r.rlim_cur = limit;
+    setrlimit(RLIMIT_DATA, &r);
+#endif
+
+    // Resident set size.
+#if _GLIBCPP_HAVE_MEMLIMIT_RSS
+    getrlimit(RLIMIT_RSS, &r);
+    r.rlim_cur = limit;
+    setrlimit(RLIMIT_RSS, &r);
+#endif
+
+    // Mapped memory (brk + mmap).
+#if _GLIBCPP_HAVE_MEMLIMIT_VMEM
+    getrlimit(RLIMIT_VMEM, &r);
+    r.rlim_cur = limit;
+    setrlimit(RLIMIT_VMEM, &r);
+#endif
+
+    // Virtual memory.
+#if _GLIBCPP_HAVE_MEMLIMIT_AS
+    getrlimit(RLIMIT_AS, &r);
+    r.rlim_cur = limit;
+    setrlimit(RLIMIT_AS, &r);
+#endif
+}
+#endif /* _GLIBCPP_MEM_LIMITS */
+
+
+gnu_counting_struct::size_type  gnu_counting_struct::count = 0;
+
+int gnu_copy_tracker::itsCopyCount = 0;
+int gnu_copy_tracker::itsDtorCount = 0;
+
Index: 23_containers/list_modifiers.cc
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/testsuite/23_containers/list_modifiers.cc,v
retrieving revision 1.1
diff -u -3 -p -r1.1 list_modifiers.cc
--- 23_containers/list_modifiers.cc	22 Nov 2001 19:19:23 -0000	1.1
+++ 23_containers/list_modifiers.cc	8 May 2002 19:51:41 -0000
@@ -21,59 +21,9 @@
 #include <list>
 #include <testsuite_hooks.h>
 
-bool test = true;
-
-// Here's a class with nontrivial ctor/dtor that provides
-// the ability to track the number of copy ctors and dtors
-// and will throw on demand during copy.
-class T
-{
-public:
-  // default constructor
-  T(int anId, bool throwOnDemand = false)
-  : itsId(anId), willThrow(throwOnDemand)
-  { }
-
-  // copy constructor
-  T(const T& rhs)
-  : itsId(rhs.id()), willThrow(rhs.willThrow)
-  {
-    ++itsCopyCount;
-    if (willThrow) 
-      throw "exception";
-  }
-
-  ~T()
-  { ++itsDtorCount; }
+typedef gnu_copy_tracker  T;
 
-  int
-  id() const
-  { return itsId; }
-
-private:
-  const int  itsId;
-  const bool willThrow;
-
-public:
-  static void
-  reset()
-  { itsCopyCount = 0; itsDtorCount = 0; }
-
-  static int
-  copyCount() 
-  { return itsCopyCount; }
-
-  static int
-  dtorCount() 
-  { return itsDtorCount; }
-
-private:
-  static int itsCopyCount;
-  static int itsDtorCount;
-};
-
-int T::itsCopyCount = 0;
-int T::itsDtorCount = 0;
+bool test = true;
 
 
 // This test verifies the following.
@@ -314,7 +264,7 @@ test03()
   VERIFY(e == list0301.end());
 }
 
-main(int argc, char* argv[])
+int main()
 {
     test01();
     test02();
Index: lib/libstdc++-v3-dg.exp
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/testsuite/lib/libstdc++-v3-dg.exp,v
retrieving revision 1.16
diff -u -3 -p -r1.16 libstdc++-v3-dg.exp
--- lib/libstdc++-v3-dg.exp	9 May 2002 21:01:54 -0000	1.16
+++ lib/libstdc++-v3-dg.exp	10 May 2002 09:01:23 -0000
@@ -196,7 +196,12 @@ proc libstdc++-v3_target_compile { sourc
     set cxx_final [concat $cxx_final $cxxflags]
     set cxx_final [concat $cxx_final $includes]
 
-    lappend options "compiler=$cxx_final";
+    lappend options "compiler=$cxx_final"
+
+    # Picks up our local freshly-built testsuite library.  We could just
+    # name it directly, "./libv3test.a" but this is more portable.
+    lappend options "ldflags=-L."
+    lappend options "libs=-lv3test"
 
     return [target_compile $source $dest $type $options]
 }



More information about the Libstdc++ mailing list