From 2f4bde27e0e6bbeb559d7720173ee6558b82eb95 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 29 Jul 2006 16:02:56 +0000 Subject: [PATCH] Added additional thread safety tests. [SVN r34775] --- test/Jamfile.v2 | 10 ++++++++ test/regress/info.hpp | 24 +++++++++++++++++++ test/regress/main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 0be2fb40..6feb981e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 + 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 ; + + diff --git a/test/regress/info.hpp b/test/regress/info.hpp index 0371442b..2b276693 100644 --- a/test/regress/info.hpp +++ b/test/regress/info.hpp @@ -21,6 +21,11 @@ #include #include #include + +#ifdef TEST_THREADS +#include +#include +#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 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(){}; diff --git a/test/regress/main.cpp b/test/regress/main.cpp index 9111b660..bab6e08f 100644 --- a/test/regress/main.cpp +++ b/test/regress/main.cpp @@ -20,9 +20,20 @@ #include "test_locale.hpp" #include +#ifdef TEST_THREADS +#include +#include +#include +#include +#include + +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 > threads; + for(int i = 0; i < 10; ++i) + { + threads.push_back(boost::shared_ptr(new boost::thread(&run_tests))); + } + std::list >::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 > tp; + + if(tp.get() == 0) + tp.reset(new boost::array); + + 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); //