From 591a70632c9f99f8c509a840514dea6bf28ce6a1 Mon Sep 17 00:00:00 2001 From: khizmax Date: Sun, 5 Apr 2015 12:49:51 +0300 Subject: [PATCH] Improved map unit test --- tests/data/test-debug.conf | 2 +- tests/unit/map2/map_delodd.h | 100 ++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/tests/data/test-debug.conf b/tests/data/test-debug.conf index c72ae739..c765db2b 100644 --- a/tests/data/test-debug.conf +++ b/tests/data/test-debug.conf @@ -188,7 +188,7 @@ Duration=7 PrintGCStateFlag=1 [Map_DelOdd] -MapSize=500000 +MapSize=50000 InsThreadCount=2 DelThreadCount=2 ExtractThreadCount=2 diff --git a/tests/unit/map2/map_delodd.h b/tests/unit/map2/map_delodd.h index 226098bd..661571a7 100644 --- a/tests/unit/map2/map_delodd.h +++ b/tests/unit/map2/map_delodd.h @@ -276,33 +276,35 @@ namespace map2 { m_nDeleteSuccess = m_nDeleteFailed = 0; - std::vector& arrData = getTest().m_arrData; - if ( m_nThreadNo & 1 ) { - for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { - for ( size_t i = 0; i < arrData.size(); ++i ) { - if ( arrData[i] & 1 ) { - if ( rMap.erase_with( arrData[i], key_less() )) - ++m_nDeleteSuccess; - else - ++m_nDeleteFailed; + for ( size_t pass = 0; pass < 2; pass++ ) { + std::vector& arrData = getTest().m_arrData; + if ( m_nThreadNo & 1 ) { + for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { + for ( size_t i = 0; i < arrData.size(); ++i ) { + if ( arrData[i] & 1 ) { + if ( rMap.erase_with( arrData[i], key_less() )) + ++m_nDeleteSuccess; + else + ++m_nDeleteFailed; + } } + if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) + break; } - if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) - break; } - } - else { - for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { - for ( size_t i = arrData.size() - 1; i > 0; --i ) { - if ( arrData[i] & 1 ) { - if ( rMap.erase_with( arrData[i], key_less() )) - ++m_nDeleteSuccess; - else - ++m_nDeleteFailed; + else { + for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { + for ( size_t i = arrData.size() - 1; i > 0; --i ) { + if ( arrData[i] & 1 ) { + if ( rMap.erase_with( arrData[i], key_less() )) + ++m_nDeleteSuccess; + else + ++m_nDeleteFailed; + } } + if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) + break; } - if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) - break; } } } @@ -349,37 +351,39 @@ namespace map2 { typename Map::guarded_ptr gp; - std::vector& arrData = getTest().m_arrData; - if ( m_nThreadNo & 1 ) { - for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { - for ( size_t i = 0; i < arrData.size(); ++i ) { - if ( arrData[i] & 1 ) { - gp = rMap.extract_with( arrData[i], key_less()); - if ( gp ) - ++m_nDeleteSuccess; - else - ++m_nDeleteFailed; - gp.release(); + for ( size_t pass = 0; pass < 2; ++pass ) { + std::vector& arrData = getTest().m_arrData; + if ( m_nThreadNo & 1 ) { + for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { + for ( size_t i = 0; i < arrData.size(); ++i ) { + if ( arrData[i] & 1 ) { + gp = rMap.extract_with( arrData[i], key_less()); + if ( gp ) + ++m_nDeleteSuccess; + else + ++m_nDeleteFailed; + gp.release(); + } } + if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) + break; } - if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) - break; } - } - else { - for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { - for ( size_t i = arrData.size() - 1; i > 0; --i ) { - if ( arrData[i] & 1 ) { - gp = rMap.extract_with( arrData[i], key_less()); - if ( gp ) - ++m_nDeleteSuccess; - else - ++m_nDeleteFailed; - gp.release(); + else { + for ( size_t k = 0; k < c_nInsThreadCount; ++k ) { + for ( size_t i = arrData.size() - 1; i > 0; --i ) { + if ( arrData[i] & 1 ) { + gp = rMap.extract_with( arrData[i], key_less()); + if ( gp ) + ++m_nDeleteSuccess; + else + ++m_nDeleteFailed; + gp.release(); + } } + if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) + break; } - if ( getTest().m_nInsThreadCount.load( atomics::memory_order_acquire ) == 0 ) - break; } } } -- 2.34.1