diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b15530a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/test/test_intermod_holder.cpp.wrk +/test/test_intermod_holder.hpp.wrk +/test/intermod_holder_dll.hpp +/test/test_intermod_holder_main.cpp.wrk diff --git a/test/condition_test.cpp b/test/condition_test.cpp index a0155ba..8622acc 100644 --- a/test/condition_test.cpp +++ b/test/condition_test.cpp @@ -13,23 +13,10 @@ #include #include "condition_test_template.hpp" -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#include -#include -#include -#endif - using namespace boost::interprocess; int main () { - #if defined(BOOST_INTERPROCESS_WINDOWS) - if(!test::do_test_condition()) - return 1; - if(!test::do_test_condition()) - return 1; - #endif if(!test::do_test_condition()) return 1; diff --git a/test/mutex_test.cpp b/test/mutex_test.cpp index 9829f25..f56135a 100644 --- a/test/mutex_test.cpp +++ b/test/mutex_test.cpp @@ -12,22 +12,10 @@ #include #include "mutex_test_template.hpp" -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#include -#endif - int main () { using namespace boost::interprocess; - #if defined(BOOST_INTERPROCESS_WINDOWS) - test::test_all_lock(); - test::test_all_mutex(); - test::test_all_lock(); - test::test_all_mutex(); - #endif - test::test_all_lock(); test::test_all_mutex(); return 0; diff --git a/test/mutex_test_template.hpp b/test/mutex_test_template.hpp index f0a6fbb..fccee83 100644 --- a/test/mutex_test_template.hpp +++ b/test/mutex_test_template.hpp @@ -270,9 +270,7 @@ void test_mutex_lock() boost::interprocess::ipcdetail::thread_launch(tm2, thread_adapter(&lock_and_sleep, &d2, mtx)); //Wait completion - boost::interprocess::ipcdetail::thread_join(tm1); - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); boost::interprocess::ipcdetail::thread_join(tm2); BOOST_INTERPROCESS_CHECK(d1.m_value == 1); @@ -347,6 +345,7 @@ void test_mutex_timed_lock() { for (int flag = 0; flag != (int)ETimedLockFlagsMax; ++flag) { + //int flag = 2; shared_val = 0; M mtx, m2; diff --git a/test/named_condition_test.cpp b/test/named_condition_test.cpp index ea4564e..427572f 100644 --- a/test/named_condition_test.cpp +++ b/test/named_condition_test.cpp @@ -10,30 +10,11 @@ #include #include -#include -#include "condition_test_template.hpp" -#include "named_creation_template.hpp" #include "named_condition_test_helpers.hpp" -#include -#include -#include "get_process_id_name.hpp" - -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#include -#endif using namespace boost::interprocess; int main() { - int ret; - #if defined(BOOST_INTERPROCESS_WINDOWS) - ret = test::test_named_condition(); - if (ret) - return ret; - #endif - ret = test::test_named_condition(); - - return ret; + return test::test_named_condition(); } diff --git a/test/named_condition_test_helpers.hpp b/test/named_condition_test_helpers.hpp index c9b81cd..33ebf92 100644 --- a/test/named_condition_test_helpers.hpp +++ b/test/named_condition_test_helpers.hpp @@ -12,6 +12,12 @@ #define BOOST_INTERPROCESS_TEST_NAMED_CONDITION_HELPERS_HEADER #include +#include +#include +#include +#include "condition_test_template.hpp" +#include "named_creation_template.hpp" +#include "get_process_id_name.hpp" namespace boost { namespace interprocess { namespace test { diff --git a/test/named_mutex_test.cpp b/test/named_mutex_test.cpp index 29f482a..542f6cd 100644 --- a/test/named_mutex_test.cpp +++ b/test/named_mutex_test.cpp @@ -9,48 +9,11 @@ ////////////////////////////////////////////////////////////////////////////// #include -#include -#include "mutex_test_template.hpp" -#include "named_creation_template.hpp" -#include -#include - -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#endif +#include "named_mutex_test_helpers.hpp" using namespace boost::interprocess; -template -int test_named_mutex() -{ - int ret = 0; - BOOST_TRY{ - NamedMutex::remove(test::get_process_id_name()); - test::test_named_creation< test::named_sync_creation_test_wrapper >(); - #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - test::test_named_creation< test::named_sync_creation_test_wrapper_w >(); - #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - test::test_all_lock< test::named_sync_wrapper >(); - test::test_all_mutex >(); - } - BOOST_CATCH(std::exception &ex){ - std::cout << ex.what() << std::endl; - ret = 1; - } BOOST_CATCH_END - NamedMutex::remove(test::get_process_id_name()); - return ret; -} - int main() { - int ret; - #if defined(BOOST_INTERPROCESS_WINDOWS) - ret = test_named_mutex(); - if (ret) - return ret; - #endif - ret = test_named_mutex(); - - return ret; + return test::test_named_mutex(); } diff --git a/test/named_mutex_test_helpers.hpp b/test/named_mutex_test_helpers.hpp new file mode 100644 index 0000000..1bd1730 --- /dev/null +++ b/test/named_mutex_test_helpers.hpp @@ -0,0 +1,73 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2024-2024. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTERPROCESS_TEST_NAMED_MUTEX_HELPERS_HEADER +#define BOOST_INTERPROCESS_TEST_NAMED_MUTEX_HELPERS_HEADER + +#include +#include + +#include "mutex_test_template.hpp" +#include "named_creation_template.hpp" +#include "get_process_id_name.hpp" +#include + +namespace boost { namespace interprocess { namespace test { + +template +int test_named_mutex() +{ + int ret = 0; + BOOST_TRY{ + NamedMutex::remove(test::get_process_id_name()); + test::test_named_creation< test::named_sync_creation_test_wrapper >(); + #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + test::test_named_creation< test::named_sync_creation_test_wrapper_w >(); + #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + test::test_all_lock< test::named_sync_wrapper >(); + test::test_all_mutex >(); + } + BOOST_CATCH(std::exception& ex) { + std::cout << ex.what() << std::endl; + ret = 1; + } BOOST_CATCH_END + NamedMutex::remove(test::get_process_id_name()); + return ret; +} + +template +int test_named_recursive_mutex() +{ + int ret = 0; + BOOST_TRY{ + NamedRecursiveMutex::remove(test::get_process_id_name()); + test::test_named_creation< test::named_sync_creation_test_wrapper >(); + #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + test::test_named_creation< test::named_sync_creation_test_wrapper_w >(); + #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + test::test_all_lock< test::named_sync_wrapper >(); + test::test_all_mutex >(); + test::test_all_recursive_lock >(); + } + BOOST_CATCH(std::exception& ex) { + std::cout << ex.what() << std::endl; + ret = 1; + } BOOST_CATCH_END + NamedRecursiveMutex::remove(test::get_process_id_name()); + return ret; +} + + + +}}} //namespace boost { namespace interprocess { namespace test { + +#include + +#endif //BOOST_INTERPROCESS_TEST_NAMED_MUTEX_HELPERS_HEADER diff --git a/test/named_recursive_mutex_test.cpp b/test/named_recursive_mutex_test.cpp index 6b857d6..7719c0f 100644 --- a/test/named_recursive_mutex_test.cpp +++ b/test/named_recursive_mutex_test.cpp @@ -9,50 +9,11 @@ ////////////////////////////////////////////////////////////////////////////// #include -#include -#include "mutex_test_template.hpp" -#include "named_creation_template.hpp" -#include "get_process_id_name.hpp" -#include - -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#endif +#include "named_mutex_test_helpers.hpp" using namespace boost::interprocess; - -template -int test_named_recursive_mutex() -{ - int ret = 0; - BOOST_TRY{ - NamedRecursiveMutex::remove(test::get_process_id_name()); - test::test_named_creation< test::named_sync_creation_test_wrapper >(); - #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - test::test_named_creation< test::named_sync_creation_test_wrapper_w >(); - #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - test::test_all_lock< test::named_sync_wrapper >(); - test::test_all_mutex >(); - test::test_all_recursive_lock >(); - } - BOOST_CATCH(std::exception &ex){ - std::cout << ex.what() << std::endl; - ret = 1; - } BOOST_CATCH_END - NamedRecursiveMutex::remove(test::get_process_id_name()); - return ret; -} - int main() { - int ret; - #if defined(BOOST_INTERPROCESS_WINDOWS) - ret = test_named_recursive_mutex(); - if (ret) - return ret; - #endif - ret = test_named_recursive_mutex(); - - return ret; + return test::test_named_recursive_mutex(); } diff --git a/test/named_semaphore_test.cpp b/test/named_semaphore_test.cpp index f0d2e49..e60eb8e 100644 --- a/test/named_semaphore_test.cpp +++ b/test/named_semaphore_test.cpp @@ -9,147 +9,11 @@ ////////////////////////////////////////////////////////////////////////////// #include -#include -#include -#include "named_creation_template.hpp" -#include "mutex_test_template.hpp" -#include "get_process_id_name.hpp" -#include - -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#endif - -#include +#include "named_semaphore_test_helpers.hpp" using namespace boost::interprocess; -static const std::size_t RecSemCount = 100; - -//This wrapper is necessary to plug this class -//in lock tests -template -class lock_test_wrapper - : public NamedSemaphore -{ - public: - - template - lock_test_wrapper(create_only_t, const CharT *name, unsigned int count = 1) - : NamedSemaphore(create_only, name, count) - {} - - template - lock_test_wrapper(open_only_t, const CharT *name) - : NamedSemaphore(open_only, name) - {} - - template - lock_test_wrapper(open_or_create_t, const CharT *name, unsigned int count = 1) - : NamedSemaphore(open_or_create, name, count) - {} - - ~lock_test_wrapper() - {} - - void lock() - { this->wait(); } - - bool try_lock() - { return this->try_wait(); } - - template - bool timed_lock(const TimePoint &pt) - { return this->timed_wait(pt); } - - template bool try_lock_until(const TimePoint &abs_time) - { return this->timed_lock(abs_time); } - - template bool try_lock_for(const Duration &dur) - { return this->timed_lock(boost::interprocess::ipcdetail::duration_to_ustime(dur)); } - - void unlock() - { this->post(); } -}; - -//This wrapper is necessary to plug this class -//in recursive tests -template -class recursive_test_wrapper - : public lock_test_wrapper -{ - public: - recursive_test_wrapper(create_only_t, const char *name) - : lock_test_wrapper(create_only, name, RecSemCount) - {} - - recursive_test_wrapper(open_only_t, const char *name) - : lock_test_wrapper(open_only, name) - {} - - recursive_test_wrapper(open_or_create_t, const char *name) - : lock_test_wrapper(open_or_create, name, RecSemCount) - {} -}; - -template -bool test_named_semaphore_specific() -{ - NamedSemaphore::remove(test::get_process_id_name()); - //Test persistance - { - NamedSemaphore sem(create_only, test::get_process_id_name(), 3); - } - { - NamedSemaphore sem(open_only, test::get_process_id_name()); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == false); - sem.post(); - } - { - NamedSemaphore sem(open_only, test::get_process_id_name()); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); - BOOST_INTERPROCESS_CHECK(sem.try_wait() == false); - } - - NamedSemaphore::remove(test::get_process_id_name()); - return true; -} - -template -int test_named_semaphore() -{ - int ret = 0; - BOOST_TRY{ - test::test_named_creation< test::named_sync_creation_test_wrapper > >(); - #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - test::test_named_creation< test::named_sync_creation_test_wrapper_w > >(); - #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) - - test::test_all_lock< test::named_sync_wrapper > >(); - test::test_all_mutex > >(); - test::test_all_recursive_lock > >(); - test_named_semaphore_specific(); - } - BOOST_CATCH(std::exception &ex){ - std::cout << ex.what() << std::endl; - ret = 1; - } BOOST_CATCH_END - NamedSemaphore::remove(test::get_process_id_name()); - return ret; -} - int main() { - int ret; - #if defined(BOOST_INTERPROCESS_WINDOWS) - ret = test_named_semaphore(); - if (ret) - return ret; - #endif - ret = test_named_semaphore(); - - return ret; + return test::test_named_semaphore(); } diff --git a/test/named_semaphore_test_helpers.hpp b/test/named_semaphore_test_helpers.hpp new file mode 100644 index 0000000..fdac630 --- /dev/null +++ b/test/named_semaphore_test_helpers.hpp @@ -0,0 +1,150 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2024-2024. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTERPROCESS_TEST_NAMED_SEMAPHORE_HELPERS_HEADER +#define BOOST_INTERPROCESS_TEST_NAMED_SEMAPHORE_HELPERS_HEADER + +#include +#include + +#include +#include +#include "named_creation_template.hpp" +#include "mutex_test_template.hpp" +#include "get_process_id_name.hpp" +#include +#include + +#include + +namespace boost { namespace interprocess { namespace test { + +static const std::size_t RecSemCount = 100; + +//This wrapper is necessary to plug this class +//in lock tests +template +class lock_test_wrapper + : public NamedSemaphore +{ + public: + + template + lock_test_wrapper(create_only_t, const CharT *name, unsigned int count = 1) + : NamedSemaphore(create_only, name, count) + {} + + template + lock_test_wrapper(open_only_t, const CharT *name) + : NamedSemaphore(open_only, name) + {} + + template + lock_test_wrapper(open_or_create_t, const CharT *name, unsigned int count = 1) + : NamedSemaphore(open_or_create, name, count) + {} + + ~lock_test_wrapper() + {} + + void lock() + { this->wait(); } + + bool try_lock() + { return this->try_wait(); } + + template + bool timed_lock(const TimePoint &pt) + { return this->timed_wait(pt); } + + template bool try_lock_until(const TimePoint &abs_time) + { return this->timed_lock(abs_time); } + + template bool try_lock_for(const Duration &dur) + { return this->timed_lock(boost::interprocess::ipcdetail::duration_to_ustime(dur)); } + + void unlock() + { this->post(); } +}; + +//This wrapper is necessary to plug this class +//in recursive tests +template +class recursive_test_wrapper + : public lock_test_wrapper +{ + public: + recursive_test_wrapper(create_only_t, const char *name) + : lock_test_wrapper(create_only, name, RecSemCount) + {} + + recursive_test_wrapper(open_only_t, const char *name) + : lock_test_wrapper(open_only, name) + {} + + recursive_test_wrapper(open_or_create_t, const char *name) + : lock_test_wrapper(open_or_create, name, RecSemCount) + {} +}; + +template +bool test_named_semaphore_specific() +{ + NamedSemaphore::remove(test::get_process_id_name()); + //Test persistance + { + NamedSemaphore sem(create_only, test::get_process_id_name(), 3); + } + { + NamedSemaphore sem(open_only, test::get_process_id_name()); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == false); + sem.post(); + } + { + NamedSemaphore sem(open_only, test::get_process_id_name()); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == true); + BOOST_INTERPROCESS_CHECK(sem.try_wait() == false); + } + + NamedSemaphore::remove(test::get_process_id_name()); + return true; +} + +template +int test_named_semaphore() +{ + int ret = 0; + BOOST_TRY{ + test::test_named_creation< test::named_sync_creation_test_wrapper > >(); + #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + test::test_named_creation< test::named_sync_creation_test_wrapper_w > >(); + #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) + + test::test_all_lock< test::named_sync_wrapper > >(); + test::test_all_mutex > >(); + test::test_all_recursive_lock > >(); + test_named_semaphore_specific(); + } + BOOST_CATCH(std::exception &ex){ + std::cout << ex.what() << std::endl; + ret = 1; + } BOOST_CATCH_END + NamedSemaphore::remove(test::get_process_id_name()); + return ret; +} + +}}} //namespace boost { namespace interprocess { namespace test { + +#include + +#endif //BOOST_INTERPROCESS_TEST_NAMED_SEMAPHORE_HELPERS_HEADER diff --git a/test/recursive_mutex_test.cpp b/test/recursive_mutex_test.cpp index c6b3376..d445212 100644 --- a/test/recursive_mutex_test.cpp +++ b/test/recursive_mutex_test.cpp @@ -9,10 +9,6 @@ ////////////////////////////////////////////////////////////////////////////// #include -#if defined(BOOST_INTERPROCESS_WINDOWS) -#include -#include -#endif #include #include #include "mutex_test_template.hpp" @@ -20,17 +16,6 @@ int main () { using namespace boost::interprocess; - #if defined(BOOST_INTERPROCESS_WINDOWS) - // - test::test_all_lock(); - test::test_all_mutex(); - test::test_all_recursive_lock(); - // - test::test_all_lock(); - test::test_all_mutex(); - test::test_all_recursive_lock(); - #endif - // test::test_all_lock(); test::test_all_mutex(); test::test_all_recursive_lock(); diff --git a/test/semaphore_test.cpp b/test/semaphore_test.cpp index 0c8ea97..eba347d 100644 --- a/test/semaphore_test.cpp +++ b/test/semaphore_test.cpp @@ -9,65 +9,10 @@ ////////////////////////////////////////////////////////////////////////////// #include -#include -#include "named_creation_template.hpp" -#include "mutex_test_template.hpp" +#include "semaphore_test_template.hpp" -static const std::size_t SemCount = 1; -static const std::size_t RecSemCount = 100; - -//This wrapper is necessary to plug this class -//in named creation tests and interprocess_mutex tests -class semaphore_test_wrapper - : public boost::interprocess::interprocess_semaphore -{ - public: - semaphore_test_wrapper() - : boost::interprocess::interprocess_semaphore(SemCount) - {} - - void lock() - { this->wait(); } - - bool try_lock() - { return this->try_wait(); } - - template - bool timed_lock(const TimePoint &pt) - { return this->timed_wait(pt); } - - template bool try_lock_until(const TimePoint &abs_time) - { return this->timed_lock(abs_time); } - - template bool try_lock_for(const Duration &dur) - { return this->timed_lock(boost::interprocess::ipcdetail::duration_to_ustime(dur)); } - - void unlock() - { this->post(); } - - protected: - semaphore_test_wrapper(std::size_t initial_count) - : boost::interprocess::interprocess_semaphore(unsigned(initial_count)) - {} -}; - -//This wrapper is necessary to plug this class -//in recursive tests -class recursive_semaphore_test_wrapper - : public semaphore_test_wrapper -{ - public: - recursive_semaphore_test_wrapper() - : semaphore_test_wrapper(RecSemCount) - {} -}; - -int main () +int main() { using namespace boost::interprocess; - - test::test_all_lock(); - test::test_all_recursive_lock(); - test::test_all_mutex(); - return 0; + return test::test_all_semaphore(); } diff --git a/test/semaphore_test_template.hpp b/test/semaphore_test_template.hpp new file mode 100644 index 0000000..2b6df3a --- /dev/null +++ b/test/semaphore_test_template.hpp @@ -0,0 +1,101 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2001-2003 +// William E. Kempf +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. William E. Kempf makes no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. + +#ifndef BOOST_INTERPROCESS_TEST_SEMAPHORE_TEST_TEMPLATE_HEADER +#define BOOST_INTERPROCESS_TEST_SEMAPHORE_TEST_TEMPLATE_HEADER + +#include +#include +#include "named_creation_template.hpp" +#include "mutex_test_template.hpp" + +namespace boost { namespace interprocess { namespace test { + +#include +#include "named_creation_template.hpp" +#include "mutex_test_template.hpp" + +static const std::size_t SemCount = 1; +static const std::size_t RecSemCount = 100; + +//This wrapper is necessary to plug this class +//in named creation tests and interprocess_mutex tests +template +class semaphore_test_wrapper + : public Semaphore +{ + public: + semaphore_test_wrapper() + : Semaphore(SemCount) + {} + + void lock() + { this->wait(); } + + bool try_lock() + { return this->try_wait(); } + + template + bool timed_lock(const TimePoint &pt) + { return this->timed_wait(pt); } + + template bool try_lock_until(const TimePoint &abs_time) + { return this->timed_lock(abs_time); } + + template bool try_lock_for(const Duration &dur) + { return this->timed_lock(boost::interprocess::ipcdetail::duration_to_ustime(dur)); } + + void unlock() + { this->post(); } + + protected: + semaphore_test_wrapper(std::size_t initial_count) + : Semaphore(unsigned(initial_count)) + {} +}; + +//This wrapper is necessary to plug this class +//in recursive tests +template +class recursive_semaphore_test_wrapper + : public semaphore_test_wrapper +{ + public: + recursive_semaphore_test_wrapper() + : semaphore_test_wrapper(RecSemCount) + {} +}; + +template +inline int test_all_semaphore() +{ + using namespace boost::interprocess; + + test::test_all_lock >(); + test::test_all_recursive_lock >(); + test::test_all_mutex >(); + return 0; +} + +}}} //namespace boost { namespace interprocess { namespace test { + +#include + +#endif //BOOST_INTERPROCESS_TEST_SEMAPHORE_TEST_TEMPLATE_HEADER diff --git a/test/sharable_mutex_test_template.hpp b/test/sharable_mutex_test_template.hpp index 2eadcba..5249eac 100644 --- a/test/sharable_mutex_test_template.hpp +++ b/test/sharable_mutex_test_template.hpp @@ -86,24 +86,27 @@ void test_plain_sharable_mutex() { shared_val = 0; SM mtx; - data s1(1); - data s2(2); data e1(1); data e2(2); + data s1(1); + data s2(2); // Writer one launches, holds the lock for 3*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tw1; boost::interprocess::ipcdetail::thread_launch(tw1, thread_adapter(plain_exclusive, &e1, mtx)); + //Give time to e1 to grab the mutex + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs/2)); + // Writer two launches, tries to grab the lock, "clearly" // after Writer one will already be holding it. - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); boost::interprocess::ipcdetail::OS_thread_t tw2; boost::interprocess::ipcdetail::thread_launch(tw2, thread_adapter(plain_exclusive, &e2, mtx)); - // Reader one launches, "clearly" after writer two, and "clearly" + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs/2)); + + // Readers launche, "clearly" after writer two, and "clearly" // while writer 1 still holds the lock - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); boost::interprocess::ipcdetail::OS_thread_t thr1; boost::interprocess::ipcdetail::thread_launch(thr1, thread_adapter(plain_shared,&s1, mtx)); boost::interprocess::ipcdetail::OS_thread_t thr2; @@ -136,7 +139,7 @@ void test_plain_sharable_mutex() boost::interprocess::ipcdetail::thread_launch(thr2, thread_adapter(plain_shared,&s2, mtx)); //Make sure they try to hold the sharable lock - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs/2u)); // We launch two writers, that should block until the readers end boost::interprocess::ipcdetail::OS_thread_t tw1; @@ -168,16 +171,16 @@ void test_try_sharable_mutex() data e2(3); // We start with some specialized tests for "try" behavior - shared_val = 0; // Writer one launches, holds the lock for 3*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tw1; boost::interprocess::ipcdetail::thread_launch(tw1, thread_adapter(try_exclusive,&e1,mtx)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs/2u)); + // Reader one launches, "clearly" after writer #1 holds the lock // and before it releases the lock. - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); boost::interprocess::ipcdetail::OS_thread_t thr1; boost::interprocess::ipcdetail::thread_launch(thr1, thread_adapter(try_shared,&s1,mtx)); @@ -238,9 +241,7 @@ void timed_shared(void *arg, SM &sm) } if (r){ - if(pdata->m_msecs){ - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(pdata->m_msecs)); - } + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(3 * BaseMs)); pdata->m_value = shared_val; } } @@ -251,10 +252,10 @@ void test_timed_sharable_mutex() for (int flag = 0; flag != (int)ETimedLockFlagsMax; ++flag) { SM mtx; - data s1(1,1*BaseMs, flag); - data s2(2,3*BaseMs, flag); - data e1(3,3*BaseMs, flag); - data e2(4,1*BaseMs, flag); + data e1(3, 3*BaseMs, flag); + data e2(4, 1*BaseMs, flag); + data s1(1, 1*BaseMs, flag); + data s2(2, 3*BaseMs, flag); // We begin with some specialized tests for "timed" behavior @@ -264,7 +265,7 @@ void test_timed_sharable_mutex() boost::interprocess::ipcdetail::OS_thread_t tw1; boost::interprocess::ipcdetail::thread_launch(tw1, thread_adapter(timed_exclusive,&e1,mtx)); - boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)/2); // Writer two will "clearly" try for the lock after the readers // have tried for it. Writer will wait up 1*BaseMs seconds for the lock. // This write will fail. @@ -288,9 +289,9 @@ void test_timed_sharable_mutex() boost::interprocess::ipcdetail::thread_join(tw1); BOOST_INTERPROCESS_CHECK(e1.m_value == 10); + BOOST_INTERPROCESS_CHECK(e2.m_value == -1); BOOST_INTERPROCESS_CHECK(s1.m_value == -1); BOOST_INTERPROCESS_CHECK(s2.m_value == 10); - BOOST_INTERPROCESS_CHECK(e2.m_value == -1); } } diff --git a/test/shm_named_condition_test.cpp b/test/shm_named_condition_test.cpp new file mode 100644 index 0000000..9d4e121 --- /dev/null +++ b/test/shm_named_condition_test.cpp @@ -0,0 +1,20 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include "named_condition_test_helpers.hpp" +#include +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_condition(); +} diff --git a/test/shm_named_mutex_test.cpp b/test/shm_named_mutex_test.cpp new file mode 100644 index 0000000..2277b1a --- /dev/null +++ b/test/shm_named_mutex_test.cpp @@ -0,0 +1,19 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include "named_mutex_test_helpers.hpp" +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_mutex(); +} diff --git a/test/shm_named_recursive_mutex_test.cpp b/test/shm_named_recursive_mutex_test.cpp new file mode 100644 index 0000000..418444e --- /dev/null +++ b/test/shm_named_recursive_mutex_test.cpp @@ -0,0 +1,19 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include "named_mutex_test_helpers.hpp" +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_recursive_mutex(); +} diff --git a/test/shm_named_semaphore_test.cpp b/test/shm_named_semaphore_test.cpp new file mode 100644 index 0000000..3a1b13c --- /dev/null +++ b/test/shm_named_semaphore_test.cpp @@ -0,0 +1,19 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include "named_semaphore_test_helpers.hpp" + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_semaphore(); +} diff --git a/test/spin_condition_test.cpp b/test/spin_condition_test.cpp new file mode 100644 index 0000000..0fa73fa --- /dev/null +++ b/test/spin_condition_test.cpp @@ -0,0 +1,25 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include "condition_test_template.hpp" + +#include +#include + +using namespace boost::interprocess; + +int main () +{ + if(!test::do_test_condition()) + return 1; + + return 0; +} diff --git a/test/spin_mutex_test.cpp b/test/spin_mutex_test.cpp new file mode 100644 index 0000000..8e27951 --- /dev/null +++ b/test/spin_mutex_test.cpp @@ -0,0 +1,23 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include "mutex_test_template.hpp" + +#include + +int main () +{ + using namespace boost::interprocess; + + test::test_all_lock(); + test::test_all_mutex(); + return 0; +} diff --git a/test/spin_recursive_mutex_test.cpp b/test/spin_recursive_mutex_test.cpp new file mode 100644 index 0000000..815fe32 --- /dev/null +++ b/test/spin_recursive_mutex_test.cpp @@ -0,0 +1,25 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include "mutex_test_template.hpp" + +int main () +{ + using namespace boost::interprocess; + // + test::test_all_lock(); + test::test_all_mutex(); + test::test_all_recursive_lock(); + + return 0; +} diff --git a/test/spin_semaphore_test.cpp b/test/spin_semaphore_test.cpp new file mode 100644 index 0000000..119e40b --- /dev/null +++ b/test/spin_semaphore_test.cpp @@ -0,0 +1,18 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include "semaphore_test_template.hpp" + +int main () +{ + using namespace boost::interprocess; + return test::test_all_semaphore(); +} diff --git a/test/winapi_condition_test.cpp b/test/winapi_condition_test.cpp new file mode 100644 index 0000000..26a9420 --- /dev/null +++ b/test/winapi_condition_test.cpp @@ -0,0 +1,32 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include "condition_test_template.hpp" + +#if defined(BOOST_INTERPROCESS_WINDOWS) +#include +#include + +using namespace boost::interprocess; + +int main () +{ + if(!test::do_test_condition()) + return 1; + return 0; +} + +#else +int main() +{ + return 0; +} +#endif \ No newline at end of file diff --git a/test/winapi_mutex_test.cpp b/test/winapi_mutex_test.cpp new file mode 100644 index 0000000..cda1967 --- /dev/null +++ b/test/winapi_mutex_test.cpp @@ -0,0 +1,32 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#if defined(BOOST_INTERPROCESS_WINDOWS) +#include +#include "mutex_test_template.hpp" + +int main () +{ + using namespace boost::interprocess; + + test::test_all_lock(); + test::test_all_mutex(); + return 0; +} +#else //BOOST_INTERPROCESS_WINDOWS + +int main() +{ + return 0; +} + +#endif //BOOST_INTERPROCESS_WINDOWS diff --git a/test/winapi_named_condition_test.cpp b/test/winapi_named_condition_test.cpp new file mode 100644 index 0000000..2820589 --- /dev/null +++ b/test/winapi_named_condition_test.cpp @@ -0,0 +1,33 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef BOOST_INTERPROCESS_WINDOWS +#include "named_condition_test_helpers.hpp" + +#include +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_condition(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/test/winapi_named_mutex_test.cpp b/test/winapi_named_mutex_test.cpp new file mode 100644 index 0000000..f0d3d82 --- /dev/null +++ b/test/winapi_named_mutex_test.cpp @@ -0,0 +1,32 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef BOOST_INTERPROCESS_WINDOWS + +#include "named_mutex_test_helpers.hpp" +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_mutex(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/test/winapi_named_recursive_mutex_test.cpp b/test/winapi_named_recursive_mutex_test.cpp new file mode 100644 index 0000000..4dc3fba --- /dev/null +++ b/test/winapi_named_recursive_mutex_test.cpp @@ -0,0 +1,32 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef BOOST_INTERPROCESS_WINDOWS + +#include "named_mutex_test_helpers.hpp" +#include + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_recursive_mutex(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/test/winapi_named_semaphore_test.cpp b/test/winapi_named_semaphore_test.cpp new file mode 100644 index 0000000..61c386f --- /dev/null +++ b/test/winapi_named_semaphore_test.cpp @@ -0,0 +1,31 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include + +#ifdef BOOST_INTERPROCESS_WINDOWS +#include +#include "named_semaphore_test_helpers.hpp" + +using namespace boost::interprocess; + +int main() +{ + return test::test_named_semaphore(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/test/winapi_recursive_mutex_test.cpp b/test/winapi_recursive_mutex_test.cpp new file mode 100644 index 0000000..175d3a0 --- /dev/null +++ b/test/winapi_recursive_mutex_test.cpp @@ -0,0 +1,33 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#if defined(BOOST_INTERPROCESS_WINDOWS) +#include +#include "mutex_test_template.hpp" + +int main () +{ + using namespace boost::interprocess; + // + test::test_all_lock(); + test::test_all_mutex(); + test::test_all_recursive_lock(); + + return 0; +} +#else + +int main() +{ + return 0; +} + +#endif diff --git a/test/winapi_semaphore_test.cpp b/test/winapi_semaphore_test.cpp new file mode 100644 index 0000000..51d3ce6 --- /dev/null +++ b/test/winapi_semaphore_test.cpp @@ -0,0 +1,28 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#ifdef BOOST_INTERPROCESS_WINDOWS +#include +#include "semaphore_test_template.hpp" + +int main() +{ + using namespace boost::interprocess; + return test::test_all_semaphore(); +} +#else + +int main() +{ + return 0; +} + +#endif