forked from boostorg/regex
Added additional thread safety tests.
[SVN r34775]
This commit is contained in:
@ -61,6 +61,14 @@ test-suite regex
|
||||
: # requirements
|
||||
: regex_regress_dll ]
|
||||
|
||||
[ run regress/$(R_SOURCE) ../build//boost_regex
|
||||
../../thread/build//boost_thread
|
||||
: # command line
|
||||
: # input files
|
||||
: # requirements
|
||||
<define>TEST_THREADS
|
||||
: regex_regress_threaded ]
|
||||
|
||||
[ regex-test posix_api_check : c_compiler_checks/posix_api_check.c ]
|
||||
|
||||
[ compile c_compiler_checks/wide_posix_api_check.c
|
||||
@ -124,3 +132,5 @@ test-suite regex
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -21,6 +21,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#ifdef TEST_THREADS
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#endif
|
||||
//
|
||||
// class test info,
|
||||
// store information about the test we are about to conduct:
|
||||
@ -45,10 +50,29 @@ private:
|
||||
bool need_to_print;
|
||||
std::string expression_type_name;
|
||||
};
|
||||
#ifdef TEST_THREADS
|
||||
static data_type& do_get_data()
|
||||
{
|
||||
static boost::thread_specific_ptr<data_type> pd;
|
||||
if(pd.get() == 0)
|
||||
pd.reset(new data_type());
|
||||
return *(pd.get());
|
||||
}
|
||||
static void init_data()
|
||||
{
|
||||
do_get_data();
|
||||
}
|
||||
#endif
|
||||
static data_type& data()
|
||||
{
|
||||
#ifdef TEST_THREADS
|
||||
static boost::once_flag f = BOOST_ONCE_INIT;
|
||||
boost::call_once(&init_data, f);
|
||||
return do_get_data();
|
||||
#else
|
||||
static data_type d;
|
||||
return d;
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
test_info_base(){};
|
||||
|
@ -20,9 +20,20 @@
|
||||
#include "test_locale.hpp"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef TEST_THREADS
|
||||
#include <list>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
int* get_array_data();
|
||||
|
||||
#endif
|
||||
|
||||
int error_count = 0;
|
||||
|
||||
int cpp_main(int /*argc*/, char * /*argv*/[])
|
||||
void run_tests()
|
||||
{
|
||||
basic_tests();
|
||||
test_simple_repeats();
|
||||
@ -47,14 +58,51 @@ int cpp_main(int /*argc*/, char * /*argv*/[])
|
||||
test_conditionals();
|
||||
test_options();
|
||||
test_options2();
|
||||
#ifndef TEST_THREADS
|
||||
test_en_locale();
|
||||
#endif
|
||||
test_emacs();
|
||||
test_operators();
|
||||
test_overloads();
|
||||
test_unicode();
|
||||
}
|
||||
|
||||
int cpp_main(int /*argc*/, char * /*argv*/[])
|
||||
{
|
||||
#ifdef TEST_THREADS
|
||||
get_array_data(); // initialises data.
|
||||
|
||||
std::list<boost::shared_ptr<boost::thread> > threads;
|
||||
for(int i = 0; i < 10; ++i)
|
||||
{
|
||||
threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(&run_tests)));
|
||||
}
|
||||
std::list<boost::shared_ptr<boost::thread> >::const_iterator a(threads.begin()), b(threads.end());
|
||||
while(a != b)
|
||||
{
|
||||
(*a)->join();
|
||||
++a;
|
||||
}
|
||||
#else
|
||||
run_tests();
|
||||
#endif
|
||||
return error_count;
|
||||
}
|
||||
|
||||
#ifdef TEST_THREADS
|
||||
|
||||
int* get_array_data()
|
||||
{
|
||||
static boost::thread_specific_ptr<boost::array<int, 200> > tp;
|
||||
|
||||
if(tp.get() == 0)
|
||||
tp.reset(new boost::array<int, 200>);
|
||||
|
||||
return tp.get()->data();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const int* make_array(int first, ...)
|
||||
{
|
||||
//
|
||||
@ -63,7 +111,11 @@ const int* make_array(int first, ...)
|
||||
// our testing macros (ideally we would use an array literal
|
||||
// but these can't apparently be used as macro arguments).
|
||||
//
|
||||
#ifdef TEST_THREADS
|
||||
int* data = get_array_data();
|
||||
#else
|
||||
static int data[200];
|
||||
#endif
|
||||
va_list ap;
|
||||
va_start(ap, first);
|
||||
//
|
||||
|
Reference in New Issue
Block a user