Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67747 - sandbox/guild/pool/libs/pool/test
From: chankwanting_at_[hidden]
Date: 2011-01-07 00:21:58


Author: ktchan
Date: 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
New Revision: 67747
URL: http://svn.boost.org/trac/boost/changeset/67747

Log:
Change from simple use of std::rand() to use Boost.Random and specify a reasonable range so we don't run out of memory. Other general tidy up.
Text files modified:
   sandbox/guild/pool/libs/pool/test/Jamfile.v2 | 4 ++--
   sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp | 40 +++++++++++++++++++++++++---------------
   sandbox/guild/pool/libs/pool/test/test_msvc_mem_leak_detect.cpp | 9 +++++----
   sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp | 5 +++++
   sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp | 14 +++++++++++---
   5 files changed, 48 insertions(+), 24 deletions(-)

Modified: sandbox/guild/pool/libs/pool/test/Jamfile.v2
==============================================================================
--- sandbox/guild/pool/libs/pool/test/Jamfile.v2 (original)
+++ sandbox/guild/pool/libs/pool/test/Jamfile.v2 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
@@ -14,9 +14,9 @@
 
 test-suite pool :
     [ run test_gcd_lcm.cpp ]
- [ run test_simple_seg_storage.cpp ]
+ [ run test_simple_seg_storage.cpp ]
     [ run test_pool_alloc.cpp ]
     [ run pool_msvc_compiler_bug_test.cpp ]
     [ run test_msvc_mem_leak_detect.cpp ]
- [ run test_bug_3349.cpp ]
+ [ run test_bug_3349.cpp ]
     ;

Modified: sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_gcd_lcm.cpp 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
@@ -7,18 +7,26 @@
 
 #include <boost/pool/detail/gcd_lcm.hpp>
 #include <boost/pool/detail/ct_gcd_lcm.hpp>
+#include <boost/cstdint.hpp>
 #include <boost/limits.hpp>
 #include <boost/math/common_factor.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int.hpp>
+#include <boost/random/variate_generator.hpp>
 
 #include <boost/detail/lightweight_test.hpp>
 
 #include <climits>
-#include <cstdlib>
 #include <ctime>
 
+boost::mt19937 gen;
+
 int main()
 {
- std::srand(static_cast<unsigned>(std::time(0)));
+ gen.seed(static_cast<boost::uint32_t>(std::time(0)));
+ boost::uniform_int<> dist(2, 32767);
+ boost::variate_generator<boost::mt19937&,
+ boost::uniform_int<> > die(gen, dist);
 
     {
         BOOST_TEST_EQ(boost::details::pool::gcd<int>(1, 1), 1);
@@ -26,8 +34,7 @@
     }
 
     {
- int r;
- while((r = std::rand()) < 2) {}
+ int r = die();
 
         BOOST_TEST_EQ(boost::details::pool::gcd<int>(1, r), 1);
         BOOST_TEST_EQ(boost::details::pool::gcd<int>(r, 1), 1);
@@ -51,8 +58,7 @@
     }
 
     {
- int r1, r2;
- while((r1 = std::rand()) < 2 || (r2 = std::rand()) < 2) {}
+ int r1 = die(), r2 = die();
         int m = (std::numeric_limits<int>::max)();
 
         BOOST_TEST_EQ(boost::details::pool::gcd<int>(r1, r2),
@@ -73,9 +79,8 @@
 
     {
         int m = (std::numeric_limits<int>::max)();
- int r1, r2;
- while((r1 = std::rand()) < 2) {}
- do { r2 = std::rand(); } while((m/r1) < r2);
+ int r2, r1 = die();
+ do { r2 = die(); } while((m/r1) < r2);
 
         BOOST_TEST_EQ(boost::details::pool::lcm<int>(r1, r2),
                       boost::details::pool::lcm<int>(r2, r1));
@@ -84,8 +89,10 @@
         BOOST_TEST_EQ(boost::details::pool::lcm<int>(r2, r1),
                       boost::math::lcm(r2, r1));
 
- BOOST_TEST_EQ(boost::details::pool::lcm<int>(46340, 46341), 2147441940);
- BOOST_TEST_EQ(boost::details::pool::lcm<int>(46341, 46340), 2147441940);
+ BOOST_TEST_EQ(boost::details::pool::lcm<boost::int32_t>(46340L, 46341L),
+ 2147441940L);
+ BOOST_TEST_EQ(boost::details::pool::lcm<boost::int32_t>(46341L, 46340L),
+ 2147441940L);
     }
 
     {
@@ -114,9 +121,12 @@
         r = boost::details::pool::ct_gcd<6916U, 3458U>::value;
         BOOST_TEST_EQ(r, 3458U);
 
- r = boost::details::pool::ct_lcm<46340U, 46341U>::value;
- BOOST_TEST_EQ(r, 2147441940U);
- r = boost::details::pool::ct_lcm<46341U, 46340U>::value;
- BOOST_TEST_EQ(r, 2147441940U);
+ if(sizeof(unsigned) >= 4)
+ {
+ r = boost::details::pool::ct_lcm<46340U, 46341U>::value;
+ BOOST_TEST_EQ(r, 2147441940U);
+ r = boost::details::pool::ct_lcm<46341U, 46340U>::value;
+ BOOST_TEST_EQ(r, 2147441940U);
+ }
     }
 }

Modified: sandbox/guild/pool/libs/pool/test/test_msvc_mem_leak_detect.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_msvc_mem_leak_detect.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_msvc_mem_leak_detect.cpp 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
@@ -28,16 +28,16 @@
 {
     {
         boost::pool<> p(sizeof(int));
- int * const t = (int*)(p.malloc)();
+ (p.malloc)();
     }
 
     {
         boost::object_pool<Foo> p;
- Foo * const t = (Foo*)(p.malloc)();
+ (p.malloc)();
     }
 
     {
- int * const t = (int*)(boost::singleton_pool<Foo, sizeof(int)>::malloc)();
+ (boost::singleton_pool<Foo, sizeof(int)>::malloc)();
     }
     boost::singleton_pool<Foo, sizeof(int)>::purge_memory();
 
@@ -45,5 +45,6 @@
         std::vector<int, boost::pool_allocator<int> > v;
         v.push_back(8);
     }
- boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();
+ boost::singleton_pool<boost::pool_allocator_tag,
+ sizeof(int)>::release_memory();
 }

Modified: sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
@@ -18,6 +18,9 @@
 #include <stdexcept>
 #include <vector>
 
+#include <cstdlib>
+#include <ctime>
+
 // Each "tester" object below checks into and out of the "cdtor_checker",
 // which will check for any problems related to the construction/destruction of
 // "tester" objects.
@@ -276,6 +279,8 @@
 
 int main()
 {
+ std::srand(static_cast<unsigned>(std::time(0)));
+
     test();
     test_alloc();
     test_mem_usage();

Modified: sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_simple_seg_storage.cpp 2011-01-07 00:21:51 EST (Fri, 07 Jan 2011)
@@ -11,6 +11,9 @@
 #include <boost/pool/simple_segregated_storage.hpp>
 #include <boost/assert.hpp>
 #include <boost/math/common_factor_ct.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int.hpp>
+#include <boost/random/variate_generator.hpp>
 
 #include <boost/detail/lightweight_test.hpp>
 
@@ -64,15 +67,20 @@
     return nchunk;
 }
 
+boost::mt19937 gen;
+
 int main()
 {
     std::srand(static_cast<unsigned>(std::time(0)));
+ gen.seed(static_cast<boost::uint32_t>(std::time(0)));
 
     /* Store::segregate(block, sz, partition_sz, end) */
     std::size_t partition_sz
         = boost::math::static_lcm<sizeof(void*), sizeof(int)>::value;
- std::size_t block_size;
- while((block_size = std::rand()) < partition_sz) {}
+ boost::uniform_int<> dist(partition_sz, 10000);
+ boost::variate_generator<boost::mt19937&,
+ boost::uniform_int<> > die(gen, dist);
+ std::size_t block_size = die();
     // Pre: npartition_sz >= sizeof(void*)
     // npartition_sz = sizeof(void*) * i, for some integer i
     // nsz >= npartition_sz
@@ -263,7 +271,7 @@
             tstore.add_ordered_block(pc + (7 * partition_sz),
                 5 * partition_sz, partition_sz);
 
- void* pvret = tstore.malloc_n(3, partition_sz);
+ tstore.malloc_n(3, partition_sz);
             // "Order-preserving"
             test_is_order(tstore);
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk