2 // Utility subroutines for the C++ library testsuite.
4 // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #include <testsuite_hooks.h>
33 #ifdef _GLIBCXX_MEM_LIMITS
36 #include <sys/resource.h>
45 namespace __gnu_cxx_test
47 #ifdef _GLIBCXX_MEM_LIMITS
49 set_memory_limits(float size
)
52 // Cater to the absence of rlim_t.
53 __typeof__ (r
.rlim_cur
) limit
= (__typeof__ (r
.rlim_cur
))(size
* 1048576);
55 // Heap size, seems to be common.
56 #if _GLIBCXX_HAVE_MEMLIMIT_DATA
57 getrlimit(RLIMIT_DATA
, &r
);
59 setrlimit(RLIMIT_DATA
, &r
);
63 #if _GLIBCXX_HAVE_MEMLIMIT_RSS
64 getrlimit(RLIMIT_RSS
, &r
);
66 setrlimit(RLIMIT_RSS
, &r
);
69 // Mapped memory (brk + mmap).
70 #if _GLIBCXX_HAVE_MEMLIMIT_VMEM
71 getrlimit(RLIMIT_VMEM
, &r
);
73 setrlimit(RLIMIT_VMEM
, &r
);
77 #if _GLIBCXX_HAVE_MEMLIMIT_AS
78 getrlimit(RLIMIT_AS
, &r
);
80 setrlimit(RLIMIT_AS
, &r
);
86 set_memory_limits(float) { }
91 verify_demangle(const char* mangled
, const char* wanted
)
94 const char* s
= abi::__cxa_demangle(mangled
, 0, 0, &status
);
100 s
= "error code = 0: success";
103 s
= "error code = -1: memory allocation failure";
106 s
= "error code = -2: invalid mangled name";
109 s
= "error code = -3: invalid arguments";
112 s
= "error code unknown - who knows what happened";
116 std::string
w(wanted
);
118 throw std::runtime_error(s
);
122 // Useful exceptions.
123 class locale_data
: public std::runtime_error
127 locale_data(const std::string
& __arg
) : runtime_error(__arg
) { }
130 class environment_variable
: public std::runtime_error
134 environment_variable(const std::string
& __arg
) : runtime_error(__arg
) { }
137 class not_found
: public std::runtime_error
141 not_found(const std::string
& __arg
) : runtime_error(__arg
) { }
145 run_tests_wrapped_locale(const char* name
, const func_callback
& l
)
150 // Set the global locale.
151 locale loc_name
= try_named_locale(name
);
152 locale orig
= locale::global(loc_name
);
154 const char* res
= setlocale(LC_ALL
, name
);
157 string preLC_ALL
= res
;
158 for (func_callback::const_iterator i
= l
.begin(); i
!= l
.end(); ++i
)
160 string postLC_ALL
= setlocale(LC_ALL
, NULL
);
161 VERIFY( preLC_ALL
== postLC_ALL
);
164 throw environment_variable(string("LC_ALL for ") + string(name
));
168 run_tests_wrapped_env(const char* name
, const char* env
,
169 const func_callback
& l
)
174 #ifdef _GLIBCXX_HAVE_SETENV
175 // Set the global locale.
176 locale loc_name
= try_named_locale(name
);
177 locale orig
= locale::global(loc_name
);
179 // Set environment variable env to value in name.
180 const char* oldENV
= getenv(env
);
181 if (!setenv(env
, name
, 1))
183 for (func_callback::const_iterator i
= l
.begin(); i
!= l
.end(); ++i
)
185 setenv(env
, oldENV
? oldENV
: "", 1);
188 throw environment_variable(string(env
) + string(" to ") + string(name
));
193 try_named_locale(const char* name
)
197 return std::locale(name
);
199 catch (std::runtime_error
& ex
)
201 // Thrown by generic and gnu implemenation if named locale fails.
202 if (std::strstr(ex
.what(), "name not valid"))
209 counter::size_type
counter::count
= 0;
210 unsigned int copy_constructor::count_
= 0;
211 unsigned int copy_constructor::throw_on_
= 0;
212 unsigned int assignment_operator::count_
= 0;
213 unsigned int assignment_operator::throw_on_
= 0;
214 unsigned int destructor::_M_count
= 0;
215 int copy_tracker::next_id_
= 0;
216 }; // namespace __cxx_test