From 3a18bed0727a06b38268da72856855dc1b88c615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 25 Aug 2007 19:07:32 +0000 Subject: [PATCH] #1211: Interprocess tests hang when run in parallel #1080 boost::interprocess win32 global file mapping issue [SVN r38950] --- test/check_equal_containers.hpp | 6 +++- test/data_test.cpp | 10 +++--- test/deque_test.cpp | 4 +-- test/dummy_test_allocator.hpp | 31 +++++++++--------- test/expand_bwd_test_allocator.hpp | 33 +++++++++----------- test/file_mapping_test.cpp | 14 ++++----- test/flat_tree_test.cpp | 5 +++ test/get_process_id_name.hpp | 50 ++++++++++++++++++++++++++++++ test/intrusive_ptr_test.cpp | 16 ---------- test/list_test.hpp | 4 +-- 10 files changed, 106 insertions(+), 67 deletions(-) create mode 100644 test/get_process_id_name.hpp diff --git a/test/check_equal_containers.hpp b/test/check_equal_containers.hpp index d939160..cda3a23 100644 --- a/test/check_equal_containers.hpp +++ b/test/check_equal_containers.hpp @@ -32,9 +32,13 @@ bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont) typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end()); typename MyStdCont::iterator itstd(stdcont->begin()); + if((typename MyShmCont::size_type)std::distance(itshm, itshmend) != shmcont->size()){ + return false; + } for(; itshm != itshmend; ++itshm, ++itstd){ value_type val(*itstd); - if(*itshm != val) + const value_type &v = *itshm; + if(v != val) return false; } return true; diff --git a/test/data_test.cpp b/test/data_test.cpp index 51caea4..59ab046 100644 --- a/test/data_test.cpp +++ b/test/data_test.cpp @@ -18,17 +18,17 @@ #include #include #include "print_container.hpp" -#include "get_compiler_name.hpp" +#include "get_process_id_name.hpp" using namespace boost::interprocess; int main () { const int memsize = 65536; - std::string compiler_name; - test::get_compiler_name(compiler_name); - const char *const shMemName = compiler_name.c_str(); - std::string filename (test::get_compiler_name()); + std::string process_name; + test::get_process_id_name(process_name); + const char *const shMemName = process_name.c_str(); + std::string filename (test::get_process_id_name()); filename += "_file"; try{ diff --git a/test/deque_test.cpp b/test/deque_test.cpp index bd7a348..c8a6b8d 100644 --- a/test/deque_test.cpp +++ b/test/deque_test.cpp @@ -29,7 +29,7 @@ #include #include #include -#include "get_compiler_name.hpp" +#include "get_process_id_name.hpp" //***************************************************************// // // @@ -96,7 +96,7 @@ bool do_test() typedef deque MyShmDeque; typedef std::deque MyStdDeque; const int Memsize = 65536; - const char *const shMemName = test::get_compiler_name(); + const char *const shMemName = test::get_process_id_name(); const int max = 100; try{ diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index 56dc781..2c7393f 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -30,9 +30,8 @@ #include #include -/*!\file - Describes an allocator to test expand capabilities -*/ +//!\file +//!Describes an allocator to test expand capabilities namespace boost { namespace interprocess { @@ -71,15 +70,15 @@ class dummy_test_allocator struct rebind { typedef dummy_test_allocator other; }; - /*!Default constructor. Never throws*/ + //!Default constructor. Never throws dummy_test_allocator() {} - /*!Constructor from other dummy_test_allocator. Never throws*/ + //!Constructor from other dummy_test_allocator. Never throws dummy_test_allocator(const dummy_test_allocator &other) {} - /*!Constructor from related dummy_test_allocator. Never throws*/ + //!Constructor from related dummy_test_allocator. Never throws template dummy_test_allocator(const dummy_test_allocator &other) {} @@ -118,31 +117,31 @@ class dummy_test_allocator size_type &, const pointer & = 0) { return std::pair(0, true); } - /*!Returns maximum the number of objects the previously allocated memory - pointed by p can hold.*/ + //!Returns maximum the number of objects the previously allocated memory + //!pointed by p can hold. size_type size(const pointer &) const { return 0; } - /*!Allocates just one object. Memory allocated with this function - must be deallocated only with deallocate_one(). - Throws boost::interprocess::bad_alloc if there is no enough memory*/ + //!Allocates just one object. Memory allocated with this function + //!must be deallocated only with deallocate_one(). + //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate_one() { return pointer(0); } - /*!Deallocates memory previously allocated with allocate_one(). - You should never use deallocate_one to deallocate memory allocated - with other functions different from allocate_one(). Never throws*/ + //!Deallocates memory previously allocated with allocate_one(). + //!You should never use deallocate_one to deallocate memory allocated + //!with other functions different from allocate_one(). Never throws void deallocate_one(const pointer &) {} }; -/*!Equality test for same type of dummy_test_allocator*/ +//!Equality test for same type of dummy_test_allocator template inline bool operator==(const dummy_test_allocator &alloc1, const dummy_test_allocator &alloc2) { return false; } -/*!Inequality test for same type of dummy_test_allocator*/ +//!Inequality test for same type of dummy_test_allocator template inline bool operator!=(const dummy_test_allocator &alloc1, const dummy_test_allocator &alloc2) diff --git a/test/expand_bwd_test_allocator.hpp b/test/expand_bwd_test_allocator.hpp index 1c3957b..41c1c84 100644 --- a/test/expand_bwd_test_allocator.hpp +++ b/test/expand_bwd_test_allocator.hpp @@ -30,14 +30,11 @@ #include #include -/*!\file - Describes an allocator to test expand capabilities -*/ +//!\file +//!Describes an allocator to test expand capabilities namespace boost { - namespace interprocess { - namespace test { //This allocator just allows two allocations. The first one will return @@ -73,17 +70,17 @@ class expand_bwd_test_allocator struct rebind { typedef expand_bwd_test_allocator other; }; - /*!Constructor from the segment manager. Never throws*/ + //!Constructor from the segment manager. Never throws expand_bwd_test_allocator(T *buffer, size_type size, difference_type offset) : mp_buffer(buffer), m_size(size) , m_offset(offset), m_allocations(0){ } - /*!Constructor from other expand_bwd_test_allocator. Never throws*/ + //!Constructor from other expand_bwd_test_allocator. Never throws expand_bwd_test_allocator(const expand_bwd_test_allocator &other) : mp_buffer(other.mp_buffer), m_size(other.m_size) , m_offset(other.m_offset), m_allocations(0){ } - /*!Constructor from related expand_bwd_test_allocator. Never throws*/ + //!Constructor from related expand_bwd_test_allocator. Never throws template expand_bwd_test_allocator(const expand_bwd_test_allocator &other) : mp_buffer(other.mp_buffer), m_size(other.m_size) @@ -153,20 +150,20 @@ class expand_bwd_test_allocator return std::pair(0, true); } - /*!Returns maximum the number of objects the previously allocated memory - pointed by p can hold.*/ + //!Returns maximum the number of objects the previously allocated memory + //!pointed by p can hold. size_type size(const pointer &p) const { (void)p; return m_size; } - /*!Allocates just one object. Memory allocated with this function - must be deallocated only with deallocate_one(). - Throws boost::interprocess::bad_alloc if there is no enough memory*/ + //!Allocates just one object. Memory allocated with this function + //!must be deallocated only with deallocate_one(). + //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate_one() { return this->allocate(1); } - /*!Deallocates memory previously allocated with allocate_one(). - You should never use deallocate_one to deallocate memory allocated - with other functions different from allocate_one(). Never throws*/ + //!Deallocates memory previously allocated with allocate_one(). + //!You should never use deallocate_one to deallocate memory allocated + //!with other functions different from allocate_one(). Never throws void deallocate_one(const pointer &p) { return this->deallocate(p, 1); } @@ -176,13 +173,13 @@ class expand_bwd_test_allocator char m_allocations; }; -/*!Equality test for same type of expand_bwd_test_allocator*/ +//!Equality test for same type of expand_bwd_test_allocator template inline bool operator==(const expand_bwd_test_allocator &alloc1, const expand_bwd_test_allocator &alloc2) { return false; } -/*!Inequality test for same type of expand_bwd_test_allocator*/ +//!Inequality test for same type of expand_bwd_test_allocator template inline bool operator!=(const expand_bwd_test_allocator &alloc1, const expand_bwd_test_allocator &alloc2) diff --git a/test/file_mapping_test.cpp b/test/file_mapping_test.cpp index c16c0ec..c0e8f13 100644 --- a/test/file_mapping_test.cpp +++ b/test/file_mapping_test.cpp @@ -16,7 +16,7 @@ #include #include #include -#include "get_compiler_name.hpp" +#include "get_process_id_name.hpp" using namespace boost::interprocess; @@ -26,14 +26,14 @@ int main () const std::size_t FileSize = 99999*2; { //Create file with given size - std::ofstream file(test::get_compiler_name(), std::ios::binary | std::ios::trunc); + std::ofstream file(test::get_process_id_name(), std::ios::binary | std::ios::trunc); file.seekp(static_cast(FileSize-1)); file.write("", 1); } { //Create a file mapping - file_mapping mapping(test::get_compiler_name(), read_write); + file_mapping mapping(test::get_process_id_name(), read_write); //Create two mapped regions, one half of the file each mapped_region region (mapping ,read_write @@ -66,7 +66,7 @@ int main () //See if the pattern is correct in the file { //Open the file - std::ifstream file(test::get_compiler_name(), std::ios::binary); + std::ifstream file(test::get_process_id_name(), std::ios::binary); //Create a memory buffer std::auto_ptr memory (new unsigned char [FileSize/2 +1]); @@ -103,7 +103,7 @@ int main () //Now check the pattern mapping a single read only mapped_region { //Create a file mapping - file_mapping mapping(test::get_compiler_name(), read_only); + file_mapping mapping(test::get_process_id_name(), read_only); //Create a single regions, mapping all the file mapped_region region (mapping @@ -122,11 +122,11 @@ int main () } } catch(std::exception &exc){ - std::remove(test::get_compiler_name()); + std::remove(test::get_process_id_name()); std::cout << "Unhandled exception: " << exc.what() << std::endl; throw; } - std::remove(test::get_compiler_name()); + std::remove(test::get_process_id_name()); return 0; } diff --git a/test/flat_tree_test.cpp b/test/flat_tree_test.cpp index e573f87..95acd84 100644 --- a/test/flat_tree_test.cpp +++ b/test/flat_tree_test.cpp @@ -120,6 +120,7 @@ int main() ,MyStdSet ,MyShmMultiSet ,MyStdMultiSet>()){ + std::cout << "Error in set_test" << std::endl; return 1; } if (0 != set_test()){ + std::cout << "Error in set_test" << std::endl; return 1; } @@ -135,6 +137,7 @@ int main() ,MyStdSet ,MyMoveCopyShmMultiSet ,MyStdMultiSet>()){ + std::cout << "Error in set_test" << std::endl; return 1; } @@ -143,6 +146,7 @@ int main() ,MyStdMap ,MyShmMultiMap ,MyStdMultiMap>()){ + std::cout << "Error in set_test" << std::endl; return 1; } @@ -159,6 +163,7 @@ int main() ,MyStdMap ,MyMoveCopyShmMultiMap ,MyStdMultiMap>()){ + std::cout << "Error in set_test" << std::endl; return 1; } diff --git a/test/get_process_id_name.hpp b/test/get_process_id_name.hpp new file mode 100644 index 0000000..26250f6 --- /dev/null +++ b/test/get_process_id_name.hpp @@ -0,0 +1,50 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2004-2007. 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_GET_PROCESS_ID_NAME_HPP +#define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP + +#include +#include +#include +#include +#include + +namespace boost{ +namespace interprocess{ +namespace test{ + +inline void get_process_id_name(std::string &str) +{ + std::stringstream sstr; + sstr << "process_" << boost::interprocess::detail::get_current_process_id(); + str = sstr.str(); +} + +inline const char *get_process_id_name() +{ + static std::string str; + get_process_id_name(str); + return str.c_str(); +} + +inline const char *add_to_process_id_name(const char *name) +{ + static std::string str; + get_process_id_name(str); + str += name; + return str.c_str(); +} + +} //namespace test{ +} //namespace interprocess{ +} //namespace boost{ + +#endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP diff --git a/test/intrusive_ptr_test.cpp b/test/intrusive_ptr_test.cpp index 2dafb3c..083b0ce 100644 --- a/test/intrusive_ptr_test.cpp +++ b/test/intrusive_ptr_test.cpp @@ -19,22 +19,6 @@ #include #include -#if defined(BOOST_MSVC) - -#pragma warning(disable: 4786) // identifier truncated in debug info -#pragma warning(disable: 4710) // function not inlined -#pragma warning(disable: 4711) // function selected for automatic inline expansion -#pragma warning(disable: 4514) // unreferenced inline removed -#pragma warning(disable: 4355) // 'this' : used in base member initializer list -#pragma warning(disable: 4511) // copy constructor could not be generated -#pragma warning(disable: 4512) // assignment operator could not be generated - -#if (BOOST_MSVC >= 1310) -#pragma warning(disable: 4675) // resolved overload found with Koenig lookup -#endif - -#endif - typedef boost::interprocess::offset_ptr VP; namespace N diff --git a/test/list_test.hpp b/test/list_test.hpp index 2d5712f..c557d1a 100644 --- a/test/list_test.hpp +++ b/test/list_test.hpp @@ -21,7 +21,7 @@ #include #include #include -#include "get_compiler_name.hpp" +#include "get_process_id_name.hpp" namespace boost{ namespace interprocess{ @@ -94,7 +94,7 @@ int list_test (bool copied_allocators_equal = true) typedef std::list MyStdList; typedef typename MyShmList::value_type IntType; const int memsize = 65536; - const char *const shMemName = test::get_compiler_name(); + const char *const shMemName = test::get_process_id_name(); const int max = 100; typedef push_data_function push_data_t;