Skip to content

Commit

Permalink
Split several sync utility tests to improve parallelization. Windows:
Browse files Browse the repository at this point in the history
* Spin and Shm based utilities will be tested independently.
* Includes some refactoring to avoid copy-pasting some code in several similar synchronization primitive tests.
  • Loading branch information
igaztanaga committed Jan 12, 2024
1 parent b01a6bc commit 48e201a
Show file tree
Hide file tree
Showing 31 changed files with 788 additions and 355 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions test/condition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,10 @@
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include "condition_test_template.hpp"

#if defined(BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/condition.hpp>
#include <boost/interprocess/sync/windows/mutex.hpp>
#include <boost/interprocess/sync/spin/condition.hpp>
#include <boost/interprocess/sync/spin/mutex.hpp>
#endif

using namespace boost::interprocess;

int main ()
{
#if defined(BOOST_INTERPROCESS_WINDOWS)
if(!test::do_test_condition<ipcdetail::winapi_condition, ipcdetail::winapi_mutex>())
return 1;
if(!test::do_test_condition<ipcdetail::spin_condition, ipcdetail::spin_mutex>())
return 1;
#endif
if(!test::do_test_condition<interprocess_condition, interprocess_mutex>())
return 1;

Expand Down
12 changes: 0 additions & 12 deletions test/mutex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include "mutex_test_template.hpp"

#if defined(BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/mutex.hpp>
#include <boost/interprocess/sync/spin/mutex.hpp>
#endif

int main ()
{
using namespace boost::interprocess;

#if defined(BOOST_INTERPROCESS_WINDOWS)
test::test_all_lock<ipcdetail::winapi_mutex>();
test::test_all_mutex<ipcdetail::winapi_mutex>();
test::test_all_lock<ipcdetail::spin_mutex>();
test::test_all_mutex<ipcdetail::spin_mutex>();
#endif

test::test_all_lock<interprocess_mutex>();
test::test_all_mutex<interprocess_mutex>();
return 0;
Expand Down
3 changes: 1 addition & 2 deletions test/mutex_test_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ void test_mutex_lock()
boost::interprocess::ipcdetail::thread_launch(tm2, thread_adapter<M>(&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);
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 1 addition & 20 deletions test/named_condition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,11 @@

#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/detail/locks.hpp>
#include "condition_test_template.hpp"
#include "named_creation_template.hpp"
#include "named_condition_test_helpers.hpp"
#include <string>
#include <sstream>
#include "get_process_id_name.hpp"

#if defined(BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/named_condition.hpp>
#include <boost/interprocess/sync/windows/named_mutex.hpp>
#endif

using namespace boost::interprocess;

int main()
{
int ret;
#if defined(BOOST_INTERPROCESS_WINDOWS)
ret = test::test_named_condition<ipcdetail::winapi_named_condition, ipcdetail::winapi_named_mutex>();
if (ret)
return ret;
#endif
ret = test::test_named_condition<named_condition, named_mutex>();

return ret;
return test::test_named_condition<named_condition, named_mutex>();
}
6 changes: 6 additions & 0 deletions test/named_condition_test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#define BOOST_INTERPROCESS_TEST_NAMED_CONDITION_HELPERS_HEADER

#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/sync/cv_status.hpp>
#include <boost/interprocess/detail/interprocess_tester.hpp>
#include <boost/interprocess/sync/detail/locks.hpp>
#include "condition_test_template.hpp"
#include "named_creation_template.hpp"
#include "get_process_id_name.hpp"

namespace boost { namespace interprocess { namespace test {

Expand Down
41 changes: 2 additions & 39 deletions test/named_mutex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,11 @@
//////////////////////////////////////////////////////////////////////////////

#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include "mutex_test_template.hpp"
#include "named_creation_template.hpp"
#include <boost/interprocess/detail/interprocess_tester.hpp>
#include <exception>

#if defined(BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/named_mutex.hpp>
#endif
#include "named_mutex_test_helpers.hpp"

using namespace boost::interprocess;

template<class NamedMutex>
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<NamedMutex> >();
#if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_named_creation< test::named_sync_creation_test_wrapper_w<NamedMutex> >();
#endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_all_lock< test::named_sync_wrapper<NamedMutex> >();
test::test_all_mutex<test::named_sync_wrapper<NamedMutex> >();
}
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<ipcdetail::winapi_named_mutex>();
if (ret)
return ret;
#endif
ret = test_named_mutex<named_mutex>();

return ret;
return test::test_named_mutex<named_mutex>();
}
73 changes: 73 additions & 0 deletions test/named_mutex_test_helpers.hpp
Original file line number Diff line number Diff line change
@@ -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 <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>

#include "mutex_test_template.hpp"
#include "named_creation_template.hpp"
#include "get_process_id_name.hpp"
#include <exception>

namespace boost { namespace interprocess { namespace test {

template<class NamedMutex>
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<NamedMutex> >();
#if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_named_creation< test::named_sync_creation_test_wrapper_w<NamedMutex> >();
#endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_all_lock< test::named_sync_wrapper<NamedMutex> >();
test::test_all_mutex<test::named_sync_wrapper<NamedMutex> >();
}
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<class NamedRecursiveMutex>
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<NamedRecursiveMutex> >();
#if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_named_creation< test::named_sync_creation_test_wrapper_w<NamedRecursiveMutex> >();
#endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_all_lock< test::named_sync_wrapper<NamedRecursiveMutex> >();
test::test_all_mutex<test::named_sync_wrapper<NamedRecursiveMutex> >();
test::test_all_recursive_lock<test::named_sync_wrapper<NamedRecursiveMutex> >();
}
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 <boost/interprocess/detail/config_end.hpp>

#endif //BOOST_INTERPROCESS_TEST_NAMED_MUTEX_HELPERS_HEADER
43 changes: 2 additions & 41 deletions test/named_recursive_mutex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,11 @@
//////////////////////////////////////////////////////////////////////////////

#include <boost/interprocess/sync/named_recursive_mutex.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include "mutex_test_template.hpp"
#include "named_creation_template.hpp"
#include "get_process_id_name.hpp"
#include <exception>

#if defined(BOOST_INTERPROCESS_WINDOWS)
#include <boost/interprocess/sync/windows/named_recursive_mutex.hpp>
#endif
#include "named_mutex_test_helpers.hpp"

using namespace boost::interprocess;


template<class NamedRecursiveMutex>
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<NamedRecursiveMutex> >();
#if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_named_creation< test::named_sync_creation_test_wrapper_w<NamedRecursiveMutex> >();
#endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES)
test::test_all_lock< test::named_sync_wrapper<NamedRecursiveMutex> >();
test::test_all_mutex<test::named_sync_wrapper<NamedRecursiveMutex> >();
test::test_all_recursive_lock<test::named_sync_wrapper<NamedRecursiveMutex> >();
}
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<ipcdetail::winapi_named_recursive_mutex>();
if (ret)
return ret;
#endif
ret = test_named_recursive_mutex<named_recursive_mutex>();

return ret;
return test::test_named_recursive_mutex<named_recursive_mutex>();
}
Loading

0 comments on commit 48e201a

Please sign in to comment.