// -*- C++ -*-
-// Utility subroutines for the C++ library testsuite.
+// Utility subroutines for the C++ library testsuite.
//
-// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
-// Free Software Foundation, Inc.
+// Copyright (C) 2002-2024 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)
+// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
//
-// 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>
#include <list>
#include <string>
#include <stdexcept>
-#include <cstddef>
#include <clocale>
#include <cstdlib>
#include <locale>
namespace __gnu_test
{
#ifdef _GLIBCXX_RES_LIMITS
- void
+ void
set_memory_limits(float size)
{
struct rlimit r;
setrlimit(RLIMIT_VMEM, &r);
#endif
- // Virtual memory.
- // On x86_64-linux, the default is -z max-page-size=0x200000
- // which means up to 2MB of address space are accounted for
- // PROT_NONE mappings between text and data segments of
- // each shared library. There are 4 shared libs involved
- // in addition to the dynamic linker. Use at least 16MB address space
- // limit.
+ // Virtual memory. On x86_64-linux, the default is -z
+ // max-page-size=0x200000 which means up to 2MB of address space
+ // are accounted for PROT_NONE mappings between text and data
+ // segments of each shared library. There are 4 shared libs
+ // involved in addition to the dynamic linker, maybe 5 if libgomp
+ // is being used as well. Use at least 20MB address space limit.
#if defined(__x86_64__) && defined(__linux__)
- if (limit < 16777216)
- limit = 16777216;
+ if (limit < 20971520)
+ limit = 20971520;
#endif
+
// On HP-UX 11.23, a trivial C++ program that sets RLIMIT_AS to
// anything less than 128MB cannot "malloc" even 1K of memory.
// Therefore, we skip RLIMIT_AS on HP-UX.
#else
void
set_memory_limits(float) { }
-#endif
+#endif
#ifdef _GLIBCXX_RES_LIMITS
- void
+ void
set_file_limit(unsigned long size)
{
#if _GLIBCXX_HAVE_LIMIT_FSIZE
#else
void
set_file_limit(unsigned long) { }
-#endif
+#endif
- void
+ void
verify_demangle(const char* mangled, const char* wanted)
{
int status = 0;
- const char* s = abi::__cxa_demangle(mangled, 0, 0, &status);
- if (!s)
+ const char* s = 0;
+ char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
+ if (demangled)
+ s = demangled;
+ else
{
switch (status)
{
std::string w(wanted);
if (w != s)
std::__throw_runtime_error(s);
+ free(demangled);
}
- void
+ void
run_tests_wrapped_locale(const char* name, const func_callback& l)
{
using namespace std;
- bool test = true;
-
- // Set the global locale.
+
+ // Set the global locale.
locale loc_name = locale(name);
locale orig = locale::global(loc_name);
const char* res = setlocale(LC_ALL, name);
- if (res != NULL)
+ if (res)
{
string preLC_ALL = res;
const func_callback::test_type* tests = l.tests();
for (int i = 0; i < l.size(); ++i)
(*tests[i])();
- string postLC_ALL= setlocale(LC_ALL, NULL);
+ string postLC_ALL= setlocale(LC_ALL, 0);
VERIFY( preLC_ALL == postLC_ALL );
}
else
__throw_runtime_error(s.c_str());
}
}
-
- void
+
+ void
run_tests_wrapped_env(const char* name, const char* env,
const func_callback& l)
{
using namespace std;
- bool test = true;
-
-#ifdef _GLIBCXX_HAVE_SETENV
- // Set the global locale.
+
+#ifdef _GLIBCXX_HAVE_SETENV
+ // Set the global locale.
locale loc_name = locale(name);
locale orig = locale::global(loc_name);
- // Set environment variable env to value in name.
+ // Set environment variable env to value in name.
const char* oldENV = getenv(env);
if (!setenv(env, name, 1))
{
#endif
}
- counter::size_type counter::count = 0;
+ object_counter::size_type object_counter::count = 0;
unsigned int copy_constructor::count_ = 0;
unsigned int copy_constructor::throw_on_ = 0;
unsigned int assignment_operator::count_ = 0;
#ifdef _GLIBCXX_SYSV_SEM
// This union is not declared in system headers. Instead, it must
// be defined by user programs.
- union semun
+ union semun
{
int val;
struct semid_ds *buf;
};
#endif
- semaphore::semaphore()
+ semaphore::semaphore()
{
#ifdef _GLIBCXX_SYSV_SEM
- // Remeber the PID for the process that created the semaphore set
+ // Remember the PID for the process that created the semaphore set
// so that only one process will destroy the set.
pid_ = getpid();
#ifndef SEM_R
#define SEM_R 0400
#endif
-
+
#ifndef SEM_A
#define SEM_A 0200
#endif
#endif
}
- semaphore::~semaphore()
+ semaphore::~semaphore()
{
#ifdef _GLIBCXX_SYSV_SEM
union semun val;
- // Destroy the semaphore set only in the process that created it.
+ val.val = 0; // Avoid uninitialized variable warning.
+ // Destroy the semaphore set only in the process that created it.
if (pid_ == getpid())
semctl(sem_set_, 0, IPC_RMID, val);
#endif
}
void
- semaphore::signal()
+ semaphore::signal()
{
#ifdef _GLIBCXX_SYSV_SEM
- struct sembuf op[1] =
+ struct sembuf op[1] =
{
{ 0, 1, 0 }
};
}
void
- semaphore::wait()
+ semaphore::wait()
{
#ifdef _GLIBCXX_SYSV_SEM
- struct sembuf op[1] =
+ struct sembuf op[1] =
{
{ 0, -1, SEM_UNDO }
};
if (semop(sem_set_, op, 1) == -1)
std::__throw_runtime_error("could not wait for semaphore");
-#endif
+#endif
}
// For use in 22_locale/time_get and time_put.
tmp.tm_isdst = isdst;
return tmp;
}
-}; // namespace __gnu_test
+} // namespace __gnu_test