Thread: [complement-svn] SF.net SVN: complement: [1561] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-05-17 16:26:53
|
Revision: 1561 http://svn.sourceforge.net/complement/?rev=1561&view=rev Author: complement Date: 2007-05-17 09:26:50 -0700 (Thu, 17 May 2007) Log Message: ----------- just development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/Makefile.inc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/Makefile.inc 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/Makefile.inc 2007-05-17 16:26:50 UTC (rev 1561) @@ -1,4 +1,4 @@ # -*- makefile -*- Time-stamp: <06/10/10 15:22:33 ptr> PRGNAME = vtime -SRC_CC = vtime_main.cc +SRC_CC = vtime_main.cc vtime.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-17 16:26:50 UTC (rev 1561) @@ -2,15 +2,68 @@ #include "vtime.h" +#include <stdint.h> + namespace vt { -void Proc::mess( const stem::Event_base<>& ev ) +using namespace std; +using namespace xmt; +using namespace stem; + +void vtime::pack( std::ostream& s ) const { + __pack( s, static_cast<uint8_t>(vt.size()) ); + for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { + __pack( s, i->first ); + __pack( s, i->second ); + } } +void vtime::net_pack( std::ostream& s ) const +{ + __net_pack( s, static_cast<uint8_t>(vt.size()) ); + for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { + __net_pack( s, i->first ); + __net_pack( s, i->second ); + } +} + +void vtime::unpack( std::istream& s ) +{ + vt.clear(); + uint8_t n; + __unpack( s, n ); + while ( n-- > 0 ) { + vtime_proc_type v; + + __unpack( s, v.first ); + __unpack( s, v.second ); + + vt.push_back( v ); + } +} + +void vtime::net_unpack( std::istream& s ) +{ + vt.clear(); + uint8_t n; + __net_unpack( s, n ); + while ( n-- > 0 ) { + vtime_proc_type v; + + __net_unpack( s, v.first ); + __net_unpack( s, v.second ); + + vt.push_back( v ); + } +} + +void Proc::mess( const stem::Event_base<vtime>& ev ) +{ +} + DEFINE_RESPONSE_TABLE( Proc ) - EV_Event_base_T_( ST_NULL, MESS, mess, intr::httprq ) + EV_Event_base_T_( ST_NULL, MESS, mess, vtime ) END_RESPONSE_TABLE } // namespace vt - Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-17 16:26:50 UTC (rev 1561) @@ -3,12 +3,71 @@ #ifndef __vtime_h #define __vtime_h +#include <algorithm> +#include <list> + +#include <istream> +#include <ostream> +#include <stdexcept> + #include <stem/Event.h> #include <stem/EventHandler.h> namespace vt { -class Proc +typedef unsigned vtime_unit_type; +typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; +typedef std::list<vtime_proc_type> vtime_type; + +inline bool operator <( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second < r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + +inline bool operator <=( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second <= r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + +inline bool operator ==( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + if ( l.first == r.first ) { + return l.second == r.second; + } + + throw std::invalid_argument( "uncomparable" ); +} + + +struct vtime : + public stem::__pack_base +{ + void pack( std::ostream& s ) const; + void net_pack( std::ostream& s ) const; + void unpack( std::istream& s ); + void net_unpack( std::istream& s ); + + vtime() + { } + vtime( const vtime& _vt ) : + vt( _vt.vt.begin(), _vt.vt.end() ) + { } + + vtime& operator =( const vtime& _vt ) + { vt.clear(); } + + vtime_type vt; +}; + +class Proc : public stem::EventHandler { public: @@ -18,7 +77,7 @@ stem::EventHandler( id ) { } - void mess( const stem::Event_base<>& ); + void mess( const stem::Event_base<vtime>& ); private: DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-17 09:15:59 UTC (rev 1560) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-17 16:26:50 UTC (rev 1561) @@ -1,13 +1,27 @@ #include <iostream> +#include <mt/xmt.h> #include "vtime.h" using namespace std; +using namespace xmt; +using namespace vt; int main() { + Condition cnd; + + cnd.set(false); + cerr << "Hello, world!" << endl; + Proc m1( 100 ); + Proc m2( 101 ); + Proc r1( 102 ); + Proc r3( 103 ); + + cnd.wait(); + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-18 07:12:36
|
Revision: 1563 http://svn.sourceforge.net/complement/?rev=1563&view=rev Author: complement Date: 2007-05-18 00:12:34 -0700 (Fri, 18 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 07:12:09 UTC (rev 1562) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 07:12:34 UTC (rev 1563) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/07 15:53:23 ptr> +// -*- C++ -*- Time-stamp: <07/05/17 23:30:42 ptr> #include "vtime.h" @@ -58,6 +58,45 @@ } } +vtime_type operator -( const vtime_type& l, const vtime_type& r ) +{ + if ( r.empty() ) { + return l; + } + + vtime_type vt; + vtime_type::const_iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( i != l.end() && j != r.end() ) { + while ( i->first < j->first && i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + + while ( i->first == j->first && i != l.end() && j != r.end() ) { + if ( i->second < j->second ) { + throw range_error( "vtime different: right value grater then left" ); + } + vt.push_back( make_pair( i->first, i->second - j->second ) ); + ++i; + ++j; + } + } + + if ( i == l.end() && j != r.end() ) { + throw range_error( "vtime different: right value grater then left" ); + } + + while ( i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + + return vt; +} + + void Proc::mess( const stem::Event_base<vtime>& ev ) { } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 07:12:09 UTC (rev 1562) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 07:12:34 UTC (rev 1563) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/03/06 19:23:37 ptr> +// -*- C++ -*- Time-stamp: <07/05/18 00:26:00 ptr> #ifndef __vtime_h #define __vtime_h @@ -19,13 +19,18 @@ typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; typedef std::list<vtime_proc_type> vtime_type; +inline bool uorder( const vtime_proc_type& l, const vtime_proc_type& r ) +{ + return l.first < r.first; +} + inline bool operator <( const vtime_proc_type& l, const vtime_proc_type& r ) { if ( l.first == r.first ) { return l.second < r.second; } - throw std::invalid_argument( "uncomparable" ); + throw std::invalid_argument( "uncomparable vtime" ); } inline bool operator <=( const vtime_proc_type& l, const vtime_proc_type& r ) @@ -34,7 +39,7 @@ return l.second <= r.second; } - throw std::invalid_argument( "uncomparable" ); + throw std::invalid_argument( "uncomparable vtime" ); } inline bool operator ==( const vtime_proc_type& l, const vtime_proc_type& r ) @@ -43,10 +48,49 @@ return l.second == r.second; } - throw std::invalid_argument( "uncomparable" ); + throw std::invalid_argument( "uncomparable vtime" ); } +#if 0 +bool operator <=( const vtime_type& l, const vtime_type& r ) +{ + if ( l.size() == 0 ) { // 0 always less or equal of anything + return true; + } + + bool result = true; + vtime_type::const_iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( j->first < i->first && j != r.end() ) { + ++j; + } + + if ( j == r.end() ) { // note, that i != l.end() here! + return false; + } + + for ( ; i != l.end() && j != r.end(); ) { + if ( i->second > j->second ) { + } + + if ( i->first < j->first ) { + ++i; + } else if ( i->first == j->first ) { + if ( i->second > j->second ) { + return false; + } + } else { + ++j; + } + } +} +#endif + + +vtime_type operator -( const vtime_type& l, const vtime_type& r ); + struct vtime : public stem::__pack_base { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-18 15:34:09
|
Revision: 1565 http://svn.sourceforge.net/complement/?rev=1565&view=rev Author: complement Date: 2007-05-18 08:34:06 -0700 (Fri, 18 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 15:34:06 UTC (rev 1565) @@ -2,6 +2,7 @@ #include "vtime.h" +#include <iostream> #include <stdint.h> namespace vt { @@ -58,6 +59,72 @@ } } +void gvtime::pack( std::ostream& s ) const +{ + __pack( s, static_cast<uint8_t>(gvt.size()) ); + for ( gvtime_type::const_iterator i = gvt.begin(); i != gvt.end(); ++i ) { + __pack( s, i->first ); + i->second.pack( s ); + } +} + +void gvtime::net_pack( std::ostream& s ) const +{ + __net_pack( s, static_cast<uint8_t>(gvt.size()) ); + for ( gvtime_type::const_iterator i = gvt.begin(); i != gvt.end(); ++i ) { + __net_pack( s, i->first ); + i->second.net_pack( s ); + } +} + +void gvtime::unpack( std::istream& s ) +{ + gvt.clear(); + uint8_t n; + __unpack( s, n ); + while ( n-- > 0 ) { + gvt.push_back( vtime_group_type() ); + __unpack( s, gvt.back().first ); + gvt.back().second.unpack( s ); + } +} + +void gvtime::net_unpack( std::istream& s ) +{ + gvt.clear(); + uint8_t n; + __net_unpack( s, n ); + while ( n-- > 0 ) { + gvt.push_back( vtime_group_type() ); + __net_unpack( s, gvt.back().first ); + gvt.back().second.net_unpack( s ); + } +} + +void VTmess::pack( std::ostream& s ) const +{ + gvt.pack( s ); + __pack( s, mess ); +} + +void VTmess::net_pack( std::ostream& s ) const +{ + gvt.net_pack( s ); + __net_pack( s, mess ); +} + +void VTmess::unpack( std::istream& s ) +{ + gvt.unpack( s ); + __unpack( s, mess ); +} + +void VTmess::net_unpack( std::istream& s ) +{ + gvt.net_unpack( s ); + __net_unpack( s, mess ); +} + vtime_type operator -( const vtime_type& l, const vtime_type& r ) { if ( r.empty() ) { @@ -97,12 +164,13 @@ } -void Proc::mess( const stem::Event_base<vtime>& ev ) +void Proc::mess( const stem::Event_base<VTmess>& ev ) { + cout << ev.value().mess << endl; } DEFINE_RESPONSE_TABLE( Proc ) - EV_Event_base_T_( ST_NULL, MESS, mess, vtime ) + EV_Event_base_T_( ST_NULL, MESS, mess, VTmess ) END_RESPONSE_TABLE } // namespace vt Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 15:34:06 UTC (rev 1565) @@ -5,6 +5,8 @@ #include <algorithm> #include <list> +#include <vector> +#include <iterator> #include <istream> #include <ostream> @@ -16,6 +18,7 @@ namespace vt { typedef unsigned vtime_unit_type; +typedef uint32_t group_type; typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; typedef std::list<vtime_proc_type> vtime_type; @@ -106,11 +109,54 @@ { } vtime& operator =( const vtime& _vt ) - { vt.clear(); } + { vt.clear(); std::copy( _vt.vt.begin(), _vt.vt.end(), std::back_insert_iterator<vtime_type>(vt) ); } vtime_type vt; }; +typedef std::pair<group_type, vtime> vtime_group_type; +typedef std::list<vtime_group_type> gvtime_type; + +struct gvtime : + public stem::__pack_base +{ + void pack( std::ostream& s ) const; + void net_pack( std::ostream& s ) const; + void unpack( std::istream& s ); + void net_unpack( std::istream& s ); + + gvtime() + { } + gvtime( const gvtime& _gvt ) : + gvt( _gvt.gvt.begin(), _gvt.gvt.end() ) + { } + + gvtime& operator =( const gvtime& _gvt ) + { gvt.clear(); std::copy( _gvt.gvt.begin(), _gvt.gvt.end(), std::back_insert_iterator<gvtime_type>(gvt) ); } + + gvtime_type gvt; +}; + +struct VTmess : + public stem::__pack_base +{ + void pack( std::ostream& s ) const; + void net_pack( std::ostream& s ) const; + void unpack( std::istream& s ); + void net_unpack( std::istream& s ); + + VTmess() + { } + VTmess( const VTmess& _gvt ) : + gvt( _gvt.gvt ), + mess( _gvt.mess ) + { } + + gvtime gvt; + std::string mess; +}; + + class Proc : public stem::EventHandler { @@ -121,9 +167,18 @@ stem::EventHandler( id ) { } - void mess( const stem::Event_base<vtime>& ); + void mess( const stem::Event_base<VTmess>& ); private: + + enum vtgroup { + first_group, + second_group, + n_groups + }; + + std::vector<vtime> vt[n_groups]; + DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-18 07:19:24 UTC (rev 1564) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-18 15:34:06 UTC (rev 1565) @@ -20,6 +20,13 @@ Proc r1( 102 ); Proc r3( 103 ); + stem::Event_base<VTmess> mess( MESS ); + + mess.dest( 101 ); + mess.value().mess = "Hello!"; + + m1.Send( mess ); + cnd.wait(); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-21 13:50:03
|
Revision: 1567 http://svn.sourceforge.net/complement/?rev=1567&view=rev Author: complement Date: 2007-05-21 06:50:00 -0700 (Mon, 21 May 2007) Log Message: ----------- developement Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-18 15:35:04 UTC (rev 1566) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-21 13:50:00 UTC (rev 1567) @@ -125,6 +125,43 @@ __net_unpack( s, mess ); } +bool operator <=( const vtime_type& l, const vtime_type& r ) +{ + if ( r.empty() ) { + return l.empty(); + } + + if ( l.empty() ) { + return true; + } + + vtime_type::const_iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( i != l.end() && j != r.end() ) { + if ( i->first < j->first ) { // v <= 0 --- false + return false; + } + while ( i->first > j->first && j != r.end() ) { // 0 <= v --- true + ++j; + } + + while ( i != l.end() && j != r.end() && i->first == j->first ) { + if ( i->second > j->second ) { + return false; + } + ++i; + ++j; + } + } + + if ( i == l.end() ) { + return true; + } + + return false; +} + vtime_type operator -( const vtime_type& l, const vtime_type& r ) { if ( r.empty() ) { @@ -144,8 +181,9 @@ while ( i->first == j->first && i != l.end() && j != r.end() ) { if ( i->second < j->second ) { throw range_error( "vtime different: right value grater then left" ); + } else if ( i->second > j->second ) { + vt.push_back( make_pair( i->first, i->second - j->second ) ); } - vt.push_back( make_pair( i->first, i->second - j->second ) ); ++i; ++j; } @@ -157,18 +195,150 @@ while ( i != l.end() ) { vt.push_back( make_pair( i->first, i->second ) ); - ++i; + ++i; } return vt; } +vtime_type operator +( const vtime_type& l, const vtime_type& r ) +{ + if ( r.empty() ) { + return l; + } + if ( l.empty() ) { + return r; + } + + vtime_type vt; + vtime_type::const_iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( i != l.end() && j != r.end() ) { + while ( i->first < j->first && i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + + while ( i->first == j->first && i != l.end() && j != r.end() ) { + vt.push_back( make_pair( i->first, i->second + j->second ) ); + ++i; + ++j; + } + } + + while ( i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + while ( j != l.end() ) { + vt.push_back( make_pair( j->first, j->second ) ); + ++j; + } + + return vt; +} + +// template <> +vtime_type max( const vtime_type& l, const vtime_type& r ) +{ + if ( l.empty() ) { + return r; + } + + if ( r.empty() ) { + return l; + } + + // here l and r non-empty + + vtime_type vt; + vtime_type::const_iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( i != l.end() && j != r.end() ) { + while ( i->first < j->first && i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + + while ( i->first == j->first && i != l.end() && j != r.end() ) { + vt.push_back( make_pair( i->first, max( i->second, j->second ) ) ); + ++i; + ++j; + } + } + while ( i != l.end() ) { + vt.push_back( make_pair( i->first, i->second ) ); + ++i; + } + while ( j != l.end() ) { + vt.push_back( make_pair( j->first, j->second ) ); + ++j; + } + + return vt; +} + void Proc::mess( const stem::Event_base<VTmess>& ev ) { cout << ev.value().mess << endl; } +bool order_correct( const stem::Event_base<VTmess>& ev ) +{ + // assume here first_group + + gvtime_type::const_iterator gr = ev.value().gvt.begin(); + gvtime_type::const_iterator ge = ev.value().gvt.end(); + + for ( ; gr != ge; ++i ) { + if ( gr->first == first_group ) { + vtime_type vt_tmp = last_vt[first_group] + gr->second; + + vtime_type::const_iterator i = vt_tmp.begin(); + vtime_type::const_iterator j = vt[first_group].begin(); + + while ( i != vt_tmp.end() && j != vt[first_group].end() ) { + if ( i->first < j->first ) { + return false; // really protocol fail: group member was lost + } + + while ( i->first == j->first && i != vt_tmp.end() && j != vt[first_group].end() ) { + if ( i->first == self_id() ) { + if ( i->second != (j->second + 1) ) { + return false; + } + } else { + if ( i->second > j->second ) { + return false; + } + } + ++i; + ++j; + } + + if ( i != vt_tmp.end() ) { + return false; // really protocol fail: group member lost + } + + while ( j != vt[first_group].end() ) { + if ( j->first == self_id() && j->second != 1 ) { + return false; + } + ++j; + } + } + } else { + vtime_type vt_tmp = last_vt[second_group] + gr->second; + if ( !(vt_tmp <= vt[second_group] )) { + return false; + } + } + } +} + DEFINE_RESPONSE_TABLE( Proc ) EV_Event_base_T_( ST_NULL, MESS, mess, VTmess ) END_RESPONSE_TABLE Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-18 15:35:04 UTC (rev 1566) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-21 13:50:00 UTC (rev 1567) @@ -92,8 +92,13 @@ #endif +bool operator <=( const vtime_type& l, const vtime_type& r ); vtime_type operator -( const vtime_type& l, const vtime_type& r ); +vtime_type operator +( const vtime_type& l, const vtime_type& r ); +template <> +vtime_type max( const vtime_type& l, const vtime_type& r ); + struct vtime : public stem::__pack_base { @@ -171,13 +176,16 @@ private: + bool order_correct( const stem::Event_base<VTmess>& ); + enum vtgroup { first_group, second_group, n_groups }; - std::vector<vtime> vt[n_groups]; + std::vector<vtime_type> vt[n_groups]; + std::vector<vtime_type> last_vt[n_groups]; DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-22 15:05:07
|
Revision: 1568 http://svn.sourceforge.net/complement/?rev=1568&view=rev Author: complement Date: 2007-05-22 08:05:03 -0700 (Tue, 22 May 2007) Log Message: ----------- development; tests Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Added Paths: ----------- trunk/complement/explore/test/virtual_time/test/ trunk/complement/explore/test/virtual_time/test/Makefile trunk/complement/explore/test/virtual_time/test/Makefile.inc trunk/complement/explore/test/virtual_time/test/unit_test.cc Property changes on: trunk/complement/explore/test/virtual_time/test ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/test/virtual_time/test/Makefile =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile (rev 0) +++ trunk/complement/explore/test/virtual_time/test/Makefile 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,38 @@ +# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> + +SRCROOT := ../../.. +COMPILER_NAME := gcc +# ALL_TAGS := install-release-shared install-dbg-shared +# CoMT_DIR := ../../external/complement/explore + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +# DEFS += -DUNIT_TEST +INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} -I.. + +LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR} + +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_test_utf -lboost_fs +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_test_utfg -lboost_fsg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_test_utfstlg -lboost_fsstlg + +LDLIBS = ${PROJECT_LIBS} + +check: all-shared + ${OUTPUT_DIR}/${PRGNAME} || exit 1 + ${OUTPUT_DIR_DBG}/${PRGNAME} || exit 1 +ifndef WITHOUT_STLPORT + ${OUTPUT_DIR_STLDBG}/${PRGNAME} || exit 1; +endif + +check-release-shared: release-shared + ${OUTPUT_DIR}/${PRGNAME} || exit 1 + +check-dbg-shared: dbg-shared + ${OUTPUT_DIR_DBG}/${PRGNAME} || exit 1 + +ifndef WITHOUT_STLPORT +check-stldbg-shared: stldbg-shared + ${OUTPUT_DIR_STLDBG}/${PRGNAME} || exit 1 +endif Added: trunk/complement/explore/test/virtual_time/test/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile.inc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,8 @@ +# -*- Makefile -*- + +PRGNAME = ut_vtime + +SRC_CC = ../vtime.cc \ + unit_test.cc + + Added: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,244 @@ +// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> + +#include <boost/test/unit_test.hpp> + +#include <boost/lexical_cast.hpp> + +#include <string> +#include <iostream> + +#include <vtime.h> + +using namespace boost::unit_test_framework; +using namespace vt; +using namespace std; + +struct vtime_operations +{ + void vt_compare(); + void vt_add(); + void vt_diff(); + void vt_max(); +}; + +void vtime_operations::vt_compare() +{ + vtime_type vt1; + vtime_type vt2; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( vt1 == vt2 ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( vt2 <= vt1 ); + + vt2.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( !(vt1 == vt2) ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( !(vt2 <= vt1) ); + + vt1.clear(); + vt2.clear(); + + vt1.push_back( make_pair( 1, 1 ) ); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( !(vt1 == vt2) ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( !(vt2 <= vt1) ); + + vt1.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( !(vt1 <= vt2) ); + BOOST_CHECK( !(vt2 <= vt1) ); +} + +void vtime_operations::vt_add() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 + vt2; + + BOOST_CHECK( vt1 == vt3 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 + vt2; + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt4.clear(); + + vt2.push_back( make_pair( 3, 1 ) ); + + vt3 = vt1 + vt2; + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + vt4.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); +} + +void vtime_operations::vt_diff() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 - vt2; + + BOOST_CHECK( vt1 == vt3 ); + + vt2.push_back( make_pair( 1, 1 ) ); + + vt3 = vt1 - vt2; + + vt4.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt4.clear(); + + vt3 = vt1 - vt2; + + BOOST_CHECK( vt3 == vt4 ); + + vt2.clear(); + + vt2.push_back( make_pair( 3, 1 ) ); + + try { + vt3 = vt1 - vt2; + BOOST_CHECK( false ); + } + catch ( const std::range_error& err ) { + BOOST_CHECK( true ); + } + + vt2.clear(); + + vt2.push_back( make_pair( 2, 2 ) ); + + try { + vt3 = vt1 - vt2; + BOOST_CHECK( false ); + } + catch ( const std::range_error& err ) { + BOOST_CHECK( true ); + } +} + +void vtime_operations::vt_max() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 1, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 3, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 1 ) ); + vt4.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.clear(); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 2, 2 ) ); + + vt4.clear(); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.push_back( make_pair( 3, 4 ) ); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 3, 4 ) ); + + BOOST_CHECK( vt3 == vt4 ); +} + +struct vtime_test_suite : + public boost::unit_test_framework::test_suite +{ + vtime_test_suite(); +}; + +vtime_test_suite::vtime_test_suite() : + test_suite( "vtime test suite" ) +{ + boost::shared_ptr<vtime_operations> vt_op_instance( new vtime_operations() ); + + test_case *vt_compare_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_compare, vt_op_instance ); + test_case *vt_add_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_add, vt_op_instance ); + test_case *vt_diff_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_diff, vt_op_instance ); + test_case *vt_max_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_max, vt_op_instance ); + + // long_msg_tc->depends_on( init_tc ); + + add( vt_compare_tc ); + add( vt_add_tc ); + add( vt_diff_tc ); + add( vt_max_tc ); + // add( service_tc ); +} + +test_suite *init_unit_test_suite( int argc, char **argv ) +{ + test_suite *ts = BOOST_TEST_SUITE( "vtime test" ); + ts->add( new vtime_test_suite() ); + + return ts; +} Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-21 13:50:00 UTC (rev 1567) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-22 15:05:03 UTC (rev 1568) @@ -142,7 +142,7 @@ if ( i->first < j->first ) { // v <= 0 --- false return false; } - while ( i->first > j->first && j != r.end() ) { // 0 <= v --- true + while ( j != r.end() && i->first > j->first ) { // 0 <= v --- true ++j; } @@ -173,12 +173,12 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { + while ( i != l.end() && j != r.end() && i->first == j->first ) { if ( i->second < j->second ) { throw range_error( "vtime different: right value grater then left" ); } else if ( i->second > j->second ) { @@ -216,12 +216,12 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { + while ( i != l.end() && j != r.end() && i->first == j->first ) { vt.push_back( make_pair( i->first, i->second + j->second ) ); ++i; ++j; @@ -232,7 +232,7 @@ vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( j != l.end() ) { + while ( j != r.end() ) { vt.push_back( make_pair( j->first, j->second ) ); ++j; } @@ -258,13 +258,13 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { - vt.push_back( make_pair( i->first, max( i->second, j->second ) ) ); + while ( i != l.end() && j != r.end() && i->first == j->first ) { + vt.push_back( make_pair( i->first, std::max( i->second, j->second ) ) ); ++i; ++j; } @@ -273,7 +273,7 @@ vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( j != l.end() ) { + while ( j != r.end() ) { vt.push_back( make_pair( j->first, j->second ) ); ++j; } @@ -286,16 +286,16 @@ cout << ev.value().mess << endl; } -bool order_correct( const stem::Event_base<VTmess>& ev ) +bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { // assume here first_group - gvtime_type::const_iterator gr = ev.value().gvt.begin(); - gvtime_type::const_iterator ge = ev.value().gvt.end(); + gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); + gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); - for ( ; gr != ge; ++i ) { + for ( ; gr != ge; ++gr ) { if ( gr->first == first_group ) { - vtime_type vt_tmp = last_vt[first_group] + gr->second; + vtime_type vt_tmp = last_vt[first_group] + gr->second.vt; vtime_type::const_iterator i = vt_tmp.begin(); vtime_type::const_iterator j = vt[first_group].begin(); @@ -331,7 +331,7 @@ } } } else { - vtime_type vt_tmp = last_vt[second_group] + gr->second; + vtime_type vt_tmp = last_vt[second_group] + gr->second.vt; if ( !(vt_tmp <= vt[second_group] )) { return false; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-21 13:50:00 UTC (rev 1567) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-22 15:05:03 UTC (rev 1568) @@ -54,49 +54,10 @@ throw std::invalid_argument( "uncomparable vtime" ); } - -#if 0 -bool operator <=( const vtime_type& l, const vtime_type& r ) -{ - if ( l.size() == 0 ) { // 0 always less or equal of anything - return true; - } - - bool result = true; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( j->first < i->first && j != r.end() ) { - ++j; - } - - if ( j == r.end() ) { // note, that i != l.end() here! - return false; - } - - for ( ; i != l.end() && j != r.end(); ) { - if ( i->second > j->second ) { - } - - if ( i->first < j->first ) { - ++i; - } else if ( i->first == j->first ) { - if ( i->second > j->second ) { - return false; - } - } else { - ++j; - } - } -} -#endif - - bool operator <=( const vtime_type& l, const vtime_type& r ); vtime_type operator -( const vtime_type& l, const vtime_type& r ); vtime_type operator +( const vtime_type& l, const vtime_type& r ); -template <> vtime_type max( const vtime_type& l, const vtime_type& r ); struct vtime : @@ -184,8 +145,8 @@ n_groups }; - std::vector<vtime_type> vt[n_groups]; - std::vector<vtime_type> last_vt[n_groups]; + vtime_type vt[n_groups]; + vtime_type last_vt[n_groups]; DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-23 15:26:11
|
Revision: 1569 http://svn.sourceforge.net/complement/?rev=1569&view=rev Author: complement Date: 2007-05-23 08:26:04 -0700 (Wed, 23 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-22 15:05:03 UTC (rev 1568) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-23 15:26:04 UTC (rev 1569) @@ -104,24 +104,28 @@ void VTmess::pack( std::ostream& s ) const { gvt.pack( s ); + __pack( s, grp ); __pack( s, mess ); } void VTmess::net_pack( std::ostream& s ) const { gvt.net_pack( s ); + __net_pack( s, grp ); __net_pack( s, mess ); } void VTmess::unpack( std::istream& s ) { gvt.unpack( s ); + __unpack( s, grp ); __unpack( s, mess ); } void VTmess::net_unpack( std::istream& s ) { gvt.net_unpack( s ); + __net_unpack( s, grp ); __net_unpack( s, mess ); } @@ -226,6 +230,12 @@ ++i; ++j; } + if ( i != l.end() ) { + while ( j != r.end() && j->first < i->first ) { + vt.push_back( make_pair( j->first, j->second ) ); + ++j; + } + } } while ( i != l.end() ) { @@ -240,6 +250,46 @@ return vt; } +vtime_type& operator +=( vtime_type& l, const vtime_type& r ) +{ + if ( r.empty() ) { + return l; + } + + if ( l.empty() ) { + l = r; + return l; + } + + vtime_type::iterator i = l.begin(); + vtime_type::const_iterator j = r.begin(); + + while ( i != l.end() && j != r.end() ) { + while ( i != l.end() && i->first < j->first ) { + ++i; + } + + while ( i != l.end() && j != r.end() && i->first == j->first ) { + i->second += j->second; + ++i; + ++j; + } + + while ( i != l.end() && j != r.end() && j->first < i->first ) { + l.insert( i, make_pair( j->first, j->second ) ); + ++i; + ++j; + } + } + + while ( j != r.end() ) { + l.push_back( make_pair( j->first, j->second ) ); + ++j; + } + + return l; +} + // template <> vtime_type max( const vtime_type& l, const vtime_type& r ) { @@ -281,62 +331,78 @@ return vt; } +vtime& vtime::operator += ( const vtime_proc_type& t ) +{ + vtime_type::iterator i = vt.begin(); + + for ( ; i != vt.end(); ++i ) { + if ( i->first > t.first ) { + break; + } else if ( i->first == t.first ) { + i->second += t.second; + return *this; + } + } + vt.insert( i, t ); + return *this; +} + +gvtime& gvtime::operator +=( const vtime_group_type& t ) +{ + gvtime_type::iterator i = gvt.begin(); + + for ( ; i != gvt.end(); ++i ) { + if ( i->first > t.first ) { + break; + } else if ( i->first == t.first ) { + i->second += t.second; + return *this; + } + } + gvt.insert( i, t ); + return *this; +} + void Proc::mess( const stem::Event_base<VTmess>& ev ) { cout << ev.value().mess << endl; + + cout << ev.value().gvt.gvt << endl; + + cout << order_correct( ev ) << endl; } bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { - // assume here first_group - gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); - for ( ; gr != ge; ++gr ) { - if ( gr->first == first_group ) { - vtime_type vt_tmp = last_vt[first_group] + gr->second.vt; + bool fine = false; - vtime_type::const_iterator i = vt_tmp.begin(); - vtime_type::const_iterator j = vt[first_group].begin(); + group_type mgrp = ev.value().grp; - while ( i != vt_tmp.end() && j != vt[first_group].end() ) { - if ( i->first < j->first ) { - return false; // really protocol fail: group member was lost - } - - while ( i->first == j->first && i != vt_tmp.end() && j != vt[first_group].end() ) { - if ( i->first == self_id() ) { - if ( i->second != (j->second + 1) ) { - return false; - } - } else { - if ( i->second > j->second ) { - return false; - } - } - ++i; - ++j; - } + for ( ; gr != ge; ++gr ) { // over all groups + if ( gr->first == mgrp ) { + vtime_type vt_tmp = last_vt[ev.value().grp] + gr->second.vt; - if ( i != vt_tmp.end() ) { - return false; // really protocol fail: group member lost - } - - while ( j != vt[first_group].end() ) { - if ( j->first == self_id() && j->second != 1 ) { - return false; - } - ++j; - } + vtime_type::const_iterator i = vt_tmp.begin(); + if ( vt[mgrp].empty() ) { + vtime vt_null; + vt_null += make_pair( ev.src(), 1 ); + cerr << vt_tmp << vt_null.vt; + return vt_tmp == vt_null.vt; + } else { + vtime_type::const_iterator j = vt[mgrp].begin(); } } else { - vtime_type vt_tmp = last_vt[second_group] + gr->second.vt; - if ( !(vt_tmp <= vt[second_group] )) { + vtime_type vt_tmp = last_vt[mgrp] + gr->second.vt; + if ( !(vt_tmp <= vt[mgrp] )) { return false; } } } + + return fine; } DEFINE_RESPONSE_TABLE( Proc ) @@ -344,3 +410,36 @@ END_RESPONSE_TABLE } // namespace vt + +namespace std { + +ostream& operator <<( ostream& o, const vt::vtime_proc_type& v ) +{ + o << "(" << v.first << "," << v.second << ")\n"; +} + +ostream& operator <<( ostream& o, const vt::vtime_type& v ) +{ + o << "[\n"; + for ( vt::vtime_type::const_iterator i = v.begin(); i != v.end(); ++i ) { + o << *i; + } + o << "]\n"; +} + +ostream& operator <<( ostream& o, const vt::vtime_group_type& v ) +{ + o << v.first << ": " << v.second.vt; +} + +ostream& operator <<( ostream& o, const vt::gvtime_type& v ) +{ + o << "{\n"; + for ( vt::gvtime_type::const_iterator i = v.begin(); i != v.end(); ++i ) { + o << *i; + } + o << "}\n"; +} + +} // namespace std + Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-22 15:05:03 UTC (rev 1568) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-23 15:26:04 UTC (rev 1569) @@ -17,9 +17,10 @@ namespace vt { +typedef stem::addr_type oid_type; typedef unsigned vtime_unit_type; typedef uint32_t group_type; -typedef std::pair<stem::addr_type, vtime_unit_type> vtime_proc_type; +typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; typedef std::list<vtime_proc_type> vtime_type; inline bool uorder( const vtime_proc_type& l, const vtime_proc_type& r ) @@ -57,6 +58,7 @@ bool operator <=( const vtime_type& l, const vtime_type& r ); vtime_type operator -( const vtime_type& l, const vtime_type& r ); vtime_type operator +( const vtime_type& l, const vtime_type& r ); +vtime_type& operator +=( vtime_type& l, const vtime_type& r ); vtime_type max( const vtime_type& l, const vtime_type& r ); @@ -73,10 +75,41 @@ vtime( const vtime& _vt ) : vt( _vt.vt.begin(), _vt.vt.end() ) { } + vtime( const vtime_type& _vt ) : + vt( _vt.begin(), _vt.end() ) + { } vtime& operator =( const vtime& _vt ) - { vt.clear(); std::copy( _vt.vt.begin(), _vt.vt.end(), std::back_insert_iterator<vtime_type>(vt) ); } + { + vt.clear(); + std::copy( _vt.vt.begin(), _vt.vt.end(), std::back_insert_iterator<vtime_type>(vt) ); + } + bool operator ==( const vtime& r ) const + { return vt == r.vt; } + + bool operator <=( const vtime& r ) const + { return vt <= r.vt; } + + vtime operator -( const vtime& r ) const + { return vtime( vt - r.vt ); } + + vtime operator +( const vtime& r ) const + { return vtime( vt + r.vt ); } + + vtime& operator +=( const vtime_type& t ) + { + vt += t; + return *this; + } + vtime& operator +=( const vtime& t ) + { + vt += t.vt; + return *this; + } + + vtime& operator +=( const vtime_proc_type& ); + vtime_type vt; }; @@ -98,8 +131,13 @@ { } gvtime& operator =( const gvtime& _gvt ) - { gvt.clear(); std::copy( _gvt.gvt.begin(), _gvt.gvt.end(), std::back_insert_iterator<gvtime_type>(gvt) ); } + { + gvt.clear(); + std::copy( _gvt.gvt.begin(), _gvt.gvt.end(), std::back_insert_iterator<gvtime_type>(gvt) ); + } + gvtime& operator +=( const vtime_group_type& ); + gvtime_type gvt; }; @@ -119,6 +157,7 @@ { } gvtime gvt; + group_type grp; std::string mess; }; @@ -155,4 +194,13 @@ } // namespace vt +namespace std { + +ostream& operator <<( ostream&, const vt::vtime_proc_type& ); +ostream& operator <<( ostream&, const vt::vtime_type& ); +ostream& operator <<( ostream&, const vt::vtime_group_type& ); +ostream& operator <<( ostream&, const vt::gvtime_type& ); + +} // namespace std + #endif // __vtime_h Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-22 15:05:03 UTC (rev 1568) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-23 15:26:04 UTC (rev 1569) @@ -23,7 +23,15 @@ stem::Event_base<VTmess> mess( MESS ); mess.dest( 101 ); + + vtime_group_type gvt; + + gvt.first = 0; // group + gvt.second += make_pair( 101, 1 ); + mess.value().mess = "Hello!"; + mess.value().grp = 0; + mess.value().gvt += gvt; m1.Send( mess ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-24 17:15:46
|
Revision: 1571 http://svn.sourceforge.net/complement/?rev=1571&view=rev Author: complement Date: 2007-05-24 10:15:39 -0700 (Thu, 24 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-24 07:09:05 UTC (rev 1570) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-24 17:15:39 UTC (rev 1571) @@ -370,6 +370,14 @@ cout << ev.value().gvt.gvt << endl; cout << order_correct( ev ) << endl; + + if ( order_correct( ev ) ) { + gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); + gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); + for ( ; gr != ge; ++gr ) { // over all groups + vt[gr->first] = max( vt[gr->first], vt[gr->first] + gr->second.vt ); + } + } } bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-24 07:09:05 UTC (rev 1570) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-05-24 17:15:39 UTC (rev 1571) @@ -27,7 +27,7 @@ vtime_group_type gvt; gvt.first = 0; // group - gvt.second += make_pair( 101, 1 ); + gvt.second += make_pair( 100, 1 ); mess.value().mess = "Hello!"; mess.value().grp = 0; @@ -35,6 +35,11 @@ m1.Send( mess ); + mess.value().gvt += gvt; + + mess.value().mess = "How are you?"; + m1.Send( mess ); + cnd.wait(); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-28 17:45:59
|
Revision: 1572 http://svn.sourceforge.net/complement/?rev=1572&view=rev Author: complement Date: 2007-05-28 10:45:58 -0700 (Mon, 28 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-24 17:15:39 UTC (rev 1571) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-28 17:45:58 UTC (rev 1572) @@ -347,7 +347,7 @@ return *this; } -gvtime& gvtime::operator +=( const vtime_group_type& t ) +gvtime_type& operator +=( gvtime_type& gvt, const vtime_group_type& t ) { gvtime_type::iterator i = gvt.begin(); @@ -356,13 +356,41 @@ break; } else if ( i->first == t.first ) { i->second += t.second; - return *this; + return gvt; } } gvt.insert( i, t ); + return gvt; +} + +gvtime& gvtime::operator +=( const vtime_group_type& t ) +{ + gvt += t; return *this; } +vtime_unit_type comp( const gvtime_type& gvt, group_type g, oid_type p ) +{ + gvtime_type::const_iterator k = gvt.begin(); + for ( ; k != gvt.end(); ++k ) { + if ( k->first == g ) { + for ( vtime_type::const_iterator i = k->second.vt.begin(); i != k->second.vt.end(); ++i ) { + if ( i->first == p ) { + return i->second; // found (p_i, t) in g_k + } else if ( i->first > p ) { + return 0; // pair sorted, so no pair required (p_i, t) expected more + } + } + return 0; // no pair (p_i, * ) + } else if ( k->first > g ) { // groups sorted, so no required group expected more + return 0; + } + } + + return 0; +} + + void Proc::mess( const stem::Event_base<VTmess>& ev ) { cout << ev.value().mess << endl; @@ -375,7 +403,7 @@ gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); for ( ; gr != ge; ++gr ) { // over all groups - vt[gr->first] = max( vt[gr->first], vt[gr->first] + gr->second.vt ); + // vt[gr->first] = max( vt[gr->first], vt[gr->first] + gr->second.vt ); } } } @@ -391,8 +419,43 @@ for ( ; gr != ge; ++gr ) { // over all groups if ( gr->first == mgrp ) { - vtime_type vt_tmp = last_vt[ev.value().grp] + gr->second.vt; +#if 0 + comp( vt, mgrp, ev.src() ); + comp( vt, mgrp, ev.src() ); + for ( gvtime_type::const_iterator my_gi = vt.begin(); my_gi != vt.end(); ++my_gi ) { + if ( my_gi->first == mgrp ) { + vtime_type vt_tmp = my_gi->second.vt + gr->second.vt; + for (vtime_type::const_iterator i = vt_tmp.begin(); i != vt_tmp.end(); ++i ) { + if ( i->first == ev.src() ) { + vtime_type::const_iterator j = my_gi->second.vt.begin(); + for ( ; j != my_gi->second.vt.end(); ++j ) { + if ( i->first == j->first ) { + if ( i->second != j->second + 1) { + return false; + } + break; + } + } + if ( j == my_gi->second.vt.end() ) { + if ( i->second != 1 ) { + return false; + } + } + } else { + if ( ) { + } + } + } + vtime_type vt_null; + vt_null += make_pair( ev.src(), 1 ); + } + } + // vtime_group_type vt_tmp = vt + *gr; + // vtime_type vt_tmp = last_vt[ev.value().grp] + gr->second.vt; +#endif + +#if 0 vtime_type::const_iterator i = vt_tmp.begin(); if ( vt[mgrp].empty() ) { vtime vt_null; @@ -402,11 +465,14 @@ } else { vtime_type::const_iterator j = vt[mgrp].begin(); } +#endif } else { +#if 0 vtime_type vt_tmp = last_vt[mgrp] + gr->second.vt; if ( !(vt_tmp <= vt[mgrp] )) { return false; } +#endif } } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-24 17:15:39 UTC (rev 1571) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-28 17:45:58 UTC (rev 1572) @@ -116,6 +116,9 @@ typedef std::pair<group_type, vtime> vtime_group_type; typedef std::list<vtime_group_type> gvtime_type; +vtime_unit_type comp( const gvtime_type&, group_type, oid_type ); +gvtime_type& operator +=( gvtime_type&, const vtime_group_type& ); + struct gvtime : public stem::__pack_base { @@ -184,8 +187,10 @@ n_groups }; - vtime_type vt[n_groups]; - vtime_type last_vt[n_groups]; + // vtime_type vt[n_groups]; + gvtime_type vt; + // vtime_type last_vt[n_groups]; + // gvtime_type last_vt; DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-05-29 16:50:33
|
Revision: 1573 http://svn.sourceforge.net/complement/?rev=1573&view=rev Author: complement Date: 2007-05-29 09:50:29 -0700 (Tue, 29 May 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-28 17:45:58 UTC (rev 1572) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-29 16:50:29 UTC (rev 1573) @@ -331,7 +331,7 @@ return vt; } -vtime& vtime::operator += ( const vtime_proc_type& t ) +vtime& vtime::operator +=( const vtime_proc_type& t ) { vtime_type::iterator i = vt.begin(); @@ -419,60 +419,28 @@ for ( ; gr != ge; ++gr ) { // over all groups if ( gr->first == mgrp ) { -#if 0 - comp( vt, mgrp, ev.src() ); - comp( vt, mgrp, ev.src() ); - - for ( gvtime_type::const_iterator my_gi = vt.begin(); my_gi != vt.end(); ++my_gi ) { - if ( my_gi->first == mgrp ) { - vtime_type vt_tmp = my_gi->second.vt + gr->second.vt; - for (vtime_type::const_iterator i = vt_tmp.begin(); i != vt_tmp.end(); ++i ) { - if ( i->first == ev.src() ) { - vtime_type::const_iterator j = my_gi->second.vt.begin(); - for ( ; j != my_gi->second.vt.end(); ++j ) { - if ( i->first == j->first ) { - if ( i->second != j->second + 1) { - return false; - } - break; - } + if ( comp( lvt, mgrp, ev.src() ) + 1 != comp( ev.value().gvt.gvt, mgrp, ev.src() ) ) { + return false; + } + for ( gvtime_type::const_iterator i = lvt.begin(); i != lvt.end(); ++i ) { + if ( mgrp == i->first ) { + for ( vtime_type::const_iterator j = ) { + } + } + } + } else { + for ( gvtime_type::const_iterator i = lvt.begin(); i != lvt.end(); ++i ) { + if ( gr->first == i->first ) { + vtime vt_tmp = i->second + gr->second; + for ( gvtime_type::const_iterator j = vt.begin(); j != vt.end(); ++j ) { + if ( i->first == j->first ) { + if ( !(vt_tmp <= j->second) ) { + return false; } - if ( j == my_gi->second.vt.end() ) { - if ( i->second != 1 ) { - return false; - } - } - } else { - if ( ) { - } } } - vtime_type vt_null; - vt_null += make_pair( ev.src(), 1 ); } } - // vtime_group_type vt_tmp = vt + *gr; - // vtime_type vt_tmp = last_vt[ev.value().grp] + gr->second.vt; -#endif - -#if 0 - vtime_type::const_iterator i = vt_tmp.begin(); - if ( vt[mgrp].empty() ) { - vtime vt_null; - vt_null += make_pair( ev.src(), 1 ); - cerr << vt_tmp << vt_null.vt; - return vt_tmp == vt_null.vt; - } else { - vtime_type::const_iterator j = vt[mgrp].begin(); - } -#endif - } else { -#if 0 - vtime_type vt_tmp = last_vt[mgrp] + gr->second.vt; - if ( !(vt_tmp <= vt[mgrp] )) { - return false; - } -#endif } } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-28 17:45:58 UTC (rev 1572) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-29 16:50:29 UTC (rev 1573) @@ -6,6 +6,7 @@ #include <algorithm> #include <list> #include <vector> +#include <hash_map> #include <iterator> #include <istream> @@ -20,41 +21,11 @@ typedef stem::addr_type oid_type; typedef unsigned vtime_unit_type; typedef uint32_t group_type; -typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; -typedef std::list<vtime_proc_type> vtime_type; +typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; -inline bool uorder( const vtime_proc_type& l, const vtime_proc_type& r ) -{ - return l.first < r.first; -} +// typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; +// typedef std::list<vtime_proc_type> vtime_type; -inline bool operator <( const vtime_proc_type& l, const vtime_proc_type& r ) -{ - if ( l.first == r.first ) { - return l.second < r.second; - } - - throw std::invalid_argument( "uncomparable vtime" ); -} - -inline bool operator <=( const vtime_proc_type& l, const vtime_proc_type& r ) -{ - if ( l.first == r.first ) { - return l.second <= r.second; - } - - throw std::invalid_argument( "uncomparable vtime" ); -} - -inline bool operator ==( const vtime_proc_type& l, const vtime_proc_type& r ) -{ - if ( l.first == r.first ) { - return l.second == r.second; - } - - throw std::invalid_argument( "uncomparable vtime" ); -} - bool operator <=( const vtime_type& l, const vtime_type& r ); vtime_type operator -( const vtime_type& l, const vtime_type& r ); vtime_type operator +( const vtime_type& l, const vtime_type& r ); @@ -113,8 +84,9 @@ vtime_type vt; }; -typedef std::pair<group_type, vtime> vtime_group_type; -typedef std::list<vtime_group_type> gvtime_type; +// typedef std::pair<group_type, vtime> vtime_group_type; +// typedef std::list<vtime_group_type> gvtime_type; +typedef std::hash_map<group_type, vtime_type> gvtime_type; vtime_unit_type comp( const gvtime_type&, group_type, oid_type ); gvtime_type& operator +=( gvtime_type&, const vtime_group_type& ); @@ -188,6 +160,7 @@ }; // vtime_type vt[n_groups]; + gvtime_type lvt; gvtime_type vt; // vtime_type last_vt[n_groups]; // gvtime_type last_vt; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-06-01 16:58:48
|
Revision: 1579 http://svn.sourceforge.net/complement/?rev=1579&view=rev Author: complement Date: 2007-06-01 09:58:36 -0700 (Fri, 01 Jun 2007) Log Message: ----------- dev Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-31 18:37:14 UTC (rev 1578) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-01 16:58:36 UTC (rev 1579) @@ -207,143 +207,44 @@ vtime_type operator +( const vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l; - } + vtime_type tmp( l.begin(), l.end() ); - if ( l.empty() ) { - return r; + for ( i = r.begin(); i != r.end(); ++i ) { + tmp[i->first] += i->second; } - vtime_type vt; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - vt.push_back( make_pair( i->first, i->second + j->second ) ); - ++i; - ++j; - } - if ( i != l.end() ) { - while ( j != r.end() && j->first < i->first ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - } - } - - while ( i != l.end() ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - while ( j != r.end() ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - - return vt; + return tmp; } vtime_type& operator +=( vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l; + for ( i = r.begin(); i != r.end(); ++i ) { + l[i->first] += i->second; } - if ( l.empty() ) { - l = r; - return l; - } - - vtime_type::iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - ++i; - } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - i->second += j->second; - ++i; - ++j; - } - - while ( i != l.end() && j != r.end() && j->first < i->first ) { - l.insert( i, make_pair( j->first, j->second ) ); - ++i; - ++j; - } - } - - while ( j != r.end() ) { - l.push_back( make_pair( j->first, j->second ) ); - ++j; - } - return l; } // template <> vtime_type max( const vtime_type& l, const vtime_type& r ) { - if ( l.empty() ) { - return r; - } + vtime_type tmp( l.begin(), l.end() ); - if ( r.empty() ) { - return l; - } - - // here l and r non-empty - - vtime_type vt; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; + for ( i = r.begin(); i != r.end(); ++i ) { + pair<vtime_type::iterator,bool> p = tmp.insert(i->first); + if ( p->second == false ) { + *p->first = i->second; + } else { + *p->first = max( *p->first->second, i->second ); } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - vt.push_back( make_pair( i->first, std::max( i->second, j->second ) ) ); - ++i; - ++j; - } } - while ( i != l.end() ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - while ( j != r.end() ) { - vt.push_back( make_pair( j->first, j->second ) ); - ++j; - } - - return vt; + return tmp; } vtime& vtime::operator +=( const vtime_proc_type& t ) { - vtime_type::iterator i = vt.begin(); + vt[t.first] += t.second; - for ( ; i != vt.end(); ++i ) { - if ( i->first > t.first ) { - break; - } else if ( i->first == t.first ) { - i->second += t.second; - return *this; - } - } - vt.insert( i, t ); return *this; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-31 18:37:14 UTC (rev 1578) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-06-01 16:58:36 UTC (rev 1579) @@ -23,45 +23,6 @@ typedef uint32_t group_type; typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; -template <class _InputIter1, class _InputIter2, class _OutputIter, - class _Compare> -_OutputIter vt_union(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2, _InputIter2 __last2, - _OutputIter __result, _Equal __equal, _Aggregate __aggr ) -{ - - while ( __first1 != __last1 ) { - _InputIter1 __cur1 = __first1; - for ( ; __cur1 != __last1, ++__cur1 ) { - if ( __equal(*__cur1, *__first2) ) { - __aggr( __cur1, __first2, __result ); - ++__first2; - break; - } - ++__result; - } - if ( __cur1 == __last1 ) { - - } - } - - while (__first1 != __last1 && __first2 != __last2) { - if (__comp(*__first1, *__first2)) { - *__result = *__first1; - ++__first1; - } else if (__comp(*__first2, *__first1)) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - ++__first2; - } - ++__result; - } - return copy(__first2, __last2, copy(__first1, __last1, __result)); -} - // typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; // typedef std::list<vtime_proc_type> vtime_type; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-06-04 16:49:01
|
Revision: 1580 http://svn.sourceforge.net/complement/?rev=1580&view=rev Author: complement Date: 2007-06-04 09:49:00 -0700 (Mon, 04 Jun 2007) Log Message: ----------- dev Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-01 16:58:36 UTC (rev 1579) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-04 16:49:00 UTC (rev 1580) @@ -35,12 +35,13 @@ uint8_t n; __unpack( s, n ); while ( n-- > 0 ) { - vtime_proc_type v; + oid_type oid; + vtime_unit_type v; - __unpack( s, v.first ); - __unpack( s, v.second ); + __unpack( s, oid ); + __unpack( s, v ); - vt.push_back( v ); + vt[oid] = v; } } @@ -50,12 +51,13 @@ uint8_t n; __net_unpack( s, n ); while ( n-- > 0 ) { - vtime_proc_type v; + oid_type oid; + vtime_unit_type v; - __net_unpack( s, v.first ); - __net_unpack( s, v.second ); + __net_unpack( s, oid ); + __net_unpack( s, v ); - vt.push_back( v ); + vt[oid] = v; } } @@ -83,9 +85,9 @@ uint8_t n; __unpack( s, n ); while ( n-- > 0 ) { - gvt.push_back( vtime_group_type() ); - __unpack( s, gvt.back().first ); - gvt.back().second.unpack( s ); + group_type gid; + __unpack( s, gid ); + gvt[gid].unpack( s ); } } @@ -95,9 +97,9 @@ uint8_t n; __net_unpack( s, n ); while ( n-- > 0 ) { - gvt.push_back( vtime_group_type() ); - __net_unpack( s, gvt.back().first ); - gvt.back().second.net_unpack( s ); + group_type gid; + __net_unpack( s, gid ); + gvt[gid].net_unpack( s ); } } @@ -168,48 +170,31 @@ vtime_type operator -( const vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l; - } + vtime_type tmp( r.begin(), r.end() ); - vtime_type vt; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - while ( i != l.end() && i->first < j->first ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; + for ( vtime_type::iterator i = tmp.begin(); i != tmp.end(); ++i ) { + vtime_type::const_iterator p = l.find(i->first); + if ( p == l.end() || p->second < i->second ) { + throw range_error( "vtime different: right value grater then left" ); } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - if ( i->second < j->second ) { - throw range_error( "vtime different: right value grater then left" ); - } else if ( i->second > j->second ) { - vt.push_back( make_pair( i->first, i->second - j->second ) ); - } - ++i; - ++j; - } + i->second = p->second - i->second; } - if ( i == l.end() && j != r.end() ) { - throw range_error( "vtime different: right value grater then left" ); + for ( vtime_type::const_iterator i = l.begin(); i != l.end(); ++i ) { + vtime_type::iterator p = tmp.find(i->first); + if ( p == tmp.end() ) { + tmp[i->first] = i->second; + } } - while ( i != l.end() ) { - vt.push_back( make_pair( i->first, i->second ) ); - ++i; - } - - return vt; + return tmp; } vtime_type operator +( const vtime_type& l, const vtime_type& r ) { vtime_type tmp( l.begin(), l.end() ); - for ( i = r.begin(); i != r.end(); ++i ) { + for ( vtime_type::const_iterator i = r.begin(); i != r.end(); ++i ) { tmp[i->first] += i->second; } @@ -218,7 +203,7 @@ vtime_type& operator +=( vtime_type& l, const vtime_type& r ) { - for ( i = r.begin(); i != r.end(); ++i ) { + for ( vtime_type::const_iterator i = r.begin(); i != r.end(); ++i ) { l[i->first] += i->second; } @@ -230,43 +215,30 @@ { vtime_type tmp( l.begin(), l.end() ); - for ( i = r.begin(); i != r.end(); ++i ) { - pair<vtime_type::iterator,bool> p = tmp.insert(i->first); - if ( p->second == false ) { - *p->first = i->second; - } else { - *p->first = max( *p->first->second, i->second ); - } + for ( vtime_type::const_iterator i = r.begin(); i != r.end(); ++i ) { + tmp[i->first] = std::max( tmp[i->first], i->second ); } return tmp; } -vtime& vtime::operator +=( const vtime_proc_type& t ) +vtime& vtime::operator +=( const vtime_type::value_type& t ) { vt[t.first] += t.second; return *this; } -gvtime_type& operator +=( gvtime_type& gvt, const vtime_group_type& t ) +gvtime_type& operator +=( gvtime_type& gvt, gvtime_type::value_type& t ) { - gvtime_type::iterator i = gvt.begin(); + gvt[t.first] += t.second; - for ( ; i != gvt.end(); ++i ) { - if ( i->first > t.first ) { - break; - } else if ( i->first == t.first ) { - i->second += t.second; - return gvt; - } - } - gvt.insert( i, t ); return gvt; } -gvtime& gvtime::operator +=( const vtime_group_type& t ) +gvtime& gvtime::operator +=( const gvtime_type::value_type& t ) { - gvt += t; + gvt[t.first] += t.second; + return *this; } @@ -311,41 +283,7 @@ bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { - gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); - gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); - - bool fine = false; - - group_type mgrp = ev.value().grp; - - for ( ; gr != ge; ++gr ) { // over all groups - if ( gr->first == mgrp ) { - if ( comp( lvt, mgrp, ev.src() ) + 1 != comp( ev.value().gvt.gvt, mgrp, ev.src() ) ) { - return false; - } - for ( gvtime_type::const_iterator i = lvt.begin(); i != lvt.end(); ++i ) { - if ( mgrp == i->first ) { - for ( vtime_type::const_iterator j = ) { - } - } - } - } else { - for ( gvtime_type::const_iterator i = lvt.begin(); i != lvt.end(); ++i ) { - if ( gr->first == i->first ) { - vtime vt_tmp = i->second + gr->second; - for ( gvtime_type::const_iterator j = vt.begin(); j != vt.end(); ++j ) { - if ( i->first == j->first ) { - if ( !(vt_tmp <= j->second) ) { - return false; - } - } - } - } - } - } - } - - return fine; + return false; } DEFINE_RESPONSE_TABLE( Proc ) @@ -356,7 +294,7 @@ namespace std { -ostream& operator <<( ostream& o, const vt::vtime_proc_type& v ) +ostream& operator <<( ostream& o, const vt::vtime_type::value_type& v ) { return o << "(" << v.first << "," << v.second << ")\n"; } @@ -370,7 +308,7 @@ return o << "]\n"; } -ostream& operator <<( ostream& o, const vt::vtime_group_type& v ) +ostream& operator <<( ostream& o, const vt::gvtime_type::value_type& v ) { o << v.first << ": " << v.second.vt; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-06-01 16:58:36 UTC (rev 1579) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-06-04 16:49:00 UTC (rev 1580) @@ -51,13 +51,10 @@ { } vtime& operator =( const vtime& _vt ) - { - vt.clear(); - std::copy( _vt.vt.begin(), _vt.vt.end(), std::back_insert_iterator<vtime_type>(vt) ); - } + { vt = _vt.vt; } - bool operator ==( const vtime& r ) const - { return vt == r.vt; } + // bool operator ==( const vtime& r ) const + // { return vt == r.vt; } bool operator <=( const vtime& r ) const { return vt <= r.vt; } @@ -79,17 +76,20 @@ return *this; } - vtime& operator +=( const vtime_proc_type& ); + vtime& operator +=( const vtime_type::value_type& ); + + vtime_type::data_type& operator[]( const vtime_type::key_type k ) + { return vt[k]; } vtime_type vt; }; // typedef std::pair<group_type, vtime> vtime_group_type; // typedef std::list<vtime_group_type> gvtime_type; -typedef std::hash_map<group_type, vtime_type> gvtime_type; +typedef std::hash_map<group_type, vtime> gvtime_type; vtime_unit_type comp( const gvtime_type&, group_type, oid_type ); -gvtime_type& operator +=( gvtime_type&, const vtime_group_type& ); +gvtime_type& operator +=( gvtime_type&, const gvtime_type::value_type& ); struct gvtime : public stem::__pack_base @@ -106,12 +106,9 @@ { } gvtime& operator =( const gvtime& _gvt ) - { - gvt.clear(); - std::copy( _gvt.gvt.begin(), _gvt.gvt.end(), std::back_insert_iterator<gvtime_type>(gvt) ); - } + { gvt = _gvt.gvt; } - gvtime& operator +=( const vtime_group_type& ); + gvtime& operator +=( const gvtime_type::value_type& ); gvtime_type gvt; }; @@ -174,9 +171,9 @@ namespace std { -ostream& operator <<( ostream&, const vt::vtime_proc_type& ); +ostream& operator <<( ostream&, const vt::vtime_type::value_type& ); ostream& operator <<( ostream&, const vt::vtime_type& ); -ostream& operator <<( ostream&, const vt::vtime_group_type& ); +ostream& operator <<( ostream&, const vt::gvtime_type::value_type& ); ostream& operator <<( ostream&, const vt::gvtime_type& ); } // namespace std Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-01 16:58:36 UTC (rev 1579) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-04 16:49:00 UTC (rev 1580) @@ -24,18 +24,18 @@ mess.dest( 101 ); - vtime_group_type gvt; + // gvtime_type::value_type gvt; - gvt.first = 0; // group - gvt.second += make_pair( 100, 1 ); + // gvt.first = 0; // group + // gvt.second += make_pair( 100, 1 ); mess.value().mess = "Hello!"; mess.value().grp = 0; - mess.value().gvt += gvt; + mess.value().gvt.gvt[0][100] = 1; m1.Send( mess ); - mess.value().gvt += gvt; + mess.value().gvt.gvt[0][100] += 1; mess.value().mess = "How are you?"; m1.Send( mess ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-06-05 16:20:18
|
Revision: 1581 http://svn.sourceforge.net/complement/?rev=1581&view=rev Author: complement Date: 2007-06-05 09:20:15 -0700 (Tue, 05 Jun 2007) Log Message: ----------- dev Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-04 16:49:00 UTC (rev 1580) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-05 16:20:15 UTC (rev 1581) @@ -242,48 +242,49 @@ return *this; } -vtime_unit_type comp( const gvtime_type& gvt, group_type g, oid_type p ) +void Proc::mess( const stem::Event_base<VTmess>& ev ) { - gvtime_type::const_iterator k = gvt.begin(); - for ( ; k != gvt.end(); ++k ) { - if ( k->first == g ) { - for ( vtime_type::const_iterator i = k->second.vt.begin(); i != k->second.vt.end(); ++i ) { - if ( i->first == p ) { - return i->second; // found (p_i, t) in g_k - } else if ( i->first > p ) { - return 0; // pair sorted, so no pair required (p_i, t) expected more - } - } - return 0; // no pair (p_i, * ) - } else if ( k->first > g ) { // groups sorted, so no required group expected more - return 0; - } - } + cout << self_id() << " " << ev.value().mess << endl; - return 0; + cout << ev.value().gvt.gvt << endl; + + cout << order_correct( ev ) << endl; + + // if ( order_correct( ev ) ) { + // + // } } - -void Proc::mess( const stem::Event_base<VTmess>& ev ) +bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { - cout << ev.value().mess << endl; + // 1. - cout << ev.value().gvt.gvt << endl; + gvtime gvt( ev.value().gvt ); - cout << order_correct( ev ) << endl; + if ( vt.gvt[ev.value().grp][ev.src()] + 1 != gvt[ev.value().grp][ev.src()] ) { + return false; + } - if ( order_correct( ev ) ) { - gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); - gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); - for ( ; gr != ge; ++gr ) { // over all groups - // vt[gr->first] = max( vt[gr->first], vt[gr->first] + gr->second.vt ); + vtime xvt = lvt[ev.value().grp] + gvt[ev.value().grp]; + xvt[ev.src()] = 0; + + if ( !(xvt <= vt[ev.value().grp]) ) { + return false; + } + + // change: iteration through all groups of this object (not the same as below) + for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { + if ( *l != ev.value().grp ) { + xvt = lvt[*l] + gvt[*l]; + if ( !(xvt <= vt[*l]) ) { + return false; + } } } -} -bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) -{ - return false; + // lvt += gvt; + + return true; } DEFINE_RESPONSE_TABLE( Proc ) Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-06-04 16:49:00 UTC (rev 1580) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-06-05 16:20:15 UTC (rev 1581) @@ -88,7 +88,6 @@ // typedef std::list<vtime_group_type> gvtime_type; typedef std::hash_map<group_type, vtime> gvtime_type; -vtime_unit_type comp( const gvtime_type&, group_type, oid_type ); gvtime_type& operator +=( gvtime_type&, const gvtime_type::value_type& ); struct gvtime : @@ -110,6 +109,9 @@ gvtime& operator +=( const gvtime_type::value_type& ); + gvtime_type::data_type& operator[]( const gvtime_type::key_type k ) + { return gvt[k]; } + gvtime_type gvt; }; @@ -144,23 +146,21 @@ stem::EventHandler( id ) { } + void add_group( group_type g ) + { groups.push_back( g ); } + void mess( const stem::Event_base<VTmess>& ); + typedef std::list<group_type> groups_container_type; + private: - bool order_correct( const stem::Event_base<VTmess>& ); + bool order_correct( const stem::Event_base<VTmess>& ); - enum vtgroup { - first_group, - second_group, - n_groups - }; + gvtime lvt; + gvtime vt; + groups_container_type groups; - // vtime_type vt[n_groups]; - gvtime_type lvt; - gvtime_type vt; - // vtime_type last_vt[n_groups]; - // gvtime_type last_vt; DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-04 16:49:00 UTC (rev 1580) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-05 16:20:15 UTC (rev 1581) @@ -18,28 +18,35 @@ Proc m1( 100 ); Proc m2( 101 ); Proc r1( 102 ); - Proc r3( 103 ); + Proc r2( 103 ); + m1.add_group( 0 ); + m2.add_group( 0 ); + r1.add_group( 0 ); + + m1.add_group( 1 ); + m2.add_group( 1 ); + r2.add_group( 1 ); + stem::Event_base<VTmess> mess( MESS ); - mess.dest( 101 ); + mess.dest( m2.self_id() ); - // gvtime_type::value_type gvt; - - // gvt.first = 0; // group - // gvt.second += make_pair( 100, 1 ); - mess.value().mess = "Hello!"; mess.value().grp = 0; - mess.value().gvt.gvt[0][100] = 1; + mess.value().gvt.gvt[0][m1.self_id()] = 1; m1.Send( mess ); - mess.value().gvt.gvt[0][100] += 1; + mess.dest( r1.self_id() ); - mess.value().mess = "How are you?"; m1.Send( mess ); + // mess.value().gvt.gvt[0][m1.self_id()] += 1; + + // mess.value().mess = "How are you?"; + // m1.Send( mess ); + cnd.wait(); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-06-06 16:23:30
|
Revision: 1582 http://svn.sourceforge.net/complement/?rev=1582&view=rev Author: complement Date: 2007-06-06 09:23:28 -0700 (Wed, 06 Jun 2007) Log Message: ----------- oh, first working Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-05 16:20:15 UTC (rev 1581) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-06-06 16:23:28 UTC (rev 1582) @@ -133,39 +133,20 @@ bool operator <=( const vtime_type& l, const vtime_type& r ) { - if ( r.empty() ) { - return l.empty(); - } - if ( l.empty() ) { return true; } - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( i != l.end() && j != r.end() ) { - if ( i->first < j->first ) { // v <= 0 --- false - return false; - } - while ( j != r.end() && i->first > j->first ) { // 0 <= v --- true - ++j; - } - - while ( i != l.end() && j != r.end() && i->first == j->first ) { - if ( i->second > j->second ) { + for ( vtime_type::const_iterator i = l.begin(); i != l.end(); ++i ) { + if ( i->second > 0 ) { + vtime_type::const_iterator j = r.find( i->first ); + if ( j == r.end() || i->second > j->second ) { return false; } - ++i; - ++j; } } - if ( i == l.end() ) { - return true; - } - - return false; + return true; } vtime_type operator -( const vtime_type& l, const vtime_type& r ) @@ -173,11 +154,13 @@ vtime_type tmp( r.begin(), r.end() ); for ( vtime_type::iterator i = tmp.begin(); i != tmp.end(); ++i ) { - vtime_type::const_iterator p = l.find(i->first); - if ( p == l.end() || p->second < i->second ) { - throw range_error( "vtime different: right value grater then left" ); + if ( i->second > 0 ) { + vtime_type::const_iterator p = l.find(i->first); + if ( p == l.end() || p->second < i->second ) { + throw range_error( "vtime different: right value grater then left" ); + } + i->second = p->second - i->second; } - i->second = p->second - i->second; } for ( vtime_type::const_iterator i = l.begin(); i != l.end(); ++i ) { @@ -221,6 +204,17 @@ return tmp; } +// template <> +vtime max( const vtime& l, const vtime& r ) +{ + vtime tmp( l ); + + for ( vtime_type::const_iterator i = r.vt.begin(); i != r.vt.end(); ++i ) { + tmp[i->first] = std::max( tmp[i->first], i->second ); + } + return tmp; +} + vtime& vtime::operator +=( const vtime_type::value_type& t ) { vt[t.first] += t.second; @@ -235,6 +229,38 @@ return gvt; } +gvtime_type& operator +=( gvtime_type& l, const gvtime_type& r ) +{ + for ( gvtime_type::const_iterator g = r.begin(); g != r.end(); ++g ) { + l[g->first] += g->second; + } + + return l; +} + +gvtime_type operator -( const gvtime_type& l, const gvtime_type& r ) +{ + gvtime_type tmp( r ); + + for ( gvtime_type::iterator g = tmp.begin(); g != tmp.end(); ++g ) { + gvtime_type::const_iterator i = l.find( g->first ); + if ( i == l.end() ) { + throw range_error( "gvtime different: right value grater then left" ); + } + + g->second = i->second - g->second; + } + + for ( gvtime_type::const_iterator g = l.begin(); g != l.end(); ++g ) { + gvtime_type::const_iterator i = tmp.find(g->first); + if ( i == tmp.end() ) { + tmp[g->first] = g->second; + } + } + + return tmp; +} + gvtime& gvtime::operator +=( const gvtime_type::value_type& t ) { gvt[t.first] += t.second; @@ -242,51 +268,98 @@ return *this; } +gvtime& gvtime::operator +=( const gvtime& t ) +{ + for ( gvtime_type::const_iterator g = t.gvt.begin(); g != t.gvt.end(); ++g ) { + gvt[g->first] += g->second; + } + + return *this; +} + void Proc::mess( const stem::Event_base<VTmess>& ev ) { cout << self_id() << " " << ev.value().mess << endl; - cout << ev.value().gvt.gvt << endl; + // cout << ev.value().gvt.gvt << endl; - cout << order_correct( ev ) << endl; - - // if ( order_correct( ev ) ) { - // - // } + if ( order_correct( ev ) ) { + cout << "Order correct" << endl; + lvt[ev.src()] += ev.value().gvt.gvt; + lvt[ev.src()][ev.value().grp][ev.src()] = vt.gvt[ev.value().grp][ev.src()] + 1; + vt.gvt[ev.value().grp] = vt::max( vt.gvt[ev.value().grp], lvt[ev.src()][ev.value().grp] ); + cout << vt.gvt << endl; + } else { + cout << "Order not correct" << endl; + } } bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { - // 1. - gvtime gvt( ev.value().gvt ); if ( vt.gvt[ev.value().grp][ev.src()] + 1 != gvt[ev.value().grp][ev.src()] ) { + cerr << "1" << endl; + cerr << vt.gvt[ev.value().grp][ev.src()] << "\n" + << gvt[ev.value().grp][ev.src()] + << endl; return false; } - vtime xvt = lvt[ev.value().grp] + gvt[ev.value().grp]; + vtime xvt = lvt[ev.src()][ev.value().grp] + gvt[ev.value().grp]; xvt[ev.src()] = 0; if ( !(xvt <= vt[ev.value().grp]) ) { + cerr << "2" << endl; + cerr << xvt << "\n\n" + << vt[ev.value().grp] << endl; return false; } - // change: iteration through all groups of this object (not the same as below) for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { if ( *l != ev.value().grp ) { - xvt = lvt[*l] + gvt[*l]; + xvt = lvt[ev.src()][*l] + gvt[*l]; if ( !(xvt <= vt[*l]) ) { + cerr << "3" << endl; + cerr << "group " << *l << xvt << "\n\n" + << vt[*l] << endl; return false; } } } - // lvt += gvt; - return true; } +void Proc::SendVC( group_type g, const std::string& mess ) +{ + try { + stem::Event_base<VTmess> m( MESS ); + m.value().mess = mess; + m.value().grp = g; + + vtime_type& gr = vt[g].vt; + + gr[self_id()] += 1; + + for ( vtime_type::const_iterator p = gr.begin(); p != gr.end(); ++p ) { + if ( p->first != self_id() ) { + m.dest( p->first ); + + m.value().gvt.gvt = vt.gvt - lvt[p->first]; + m.value().gvt.gvt[g][self_id()] = gr[self_id()]; + + lvt[p->first] = vt.gvt; + + Send(m); + } + } + } + catch ( const range_error& err ) { + cerr << err.what() << endl; + } +} + DEFINE_RESPONSE_TABLE( Proc ) EV_Event_base_T_( ST_NULL, MESS, mess, VTmess ) END_RESPONSE_TABLE @@ -304,21 +377,24 @@ { o << "[\n"; for ( vt::vtime_type::const_iterator i = v.begin(); i != v.end(); ++i ) { - o << *i; + o << " " << *i; } - return o << "]\n"; + return o << " ]\n"; } +ostream& operator <<( ostream& o, const vt::vtime& v ) +{ return o << v.vt; } + ostream& operator <<( ostream& o, const vt::gvtime_type::value_type& v ) { - o << v.first << ": " << v.second.vt; + o << "group " << v.first << ": " << v.second.vt; } ostream& operator <<( ostream& o, const vt::gvtime_type& v ) { o << "{\n"; for ( vt::gvtime_type::const_iterator i = v.begin(); i != v.end(); ++i ) { - o << *i; + o << " " << *i; } return o << "}\n"; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-06-05 16:20:15 UTC (rev 1581) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-06-06 16:23:28 UTC (rev 1582) @@ -84,11 +84,16 @@ vtime_type vt; }; + +vtime max( const vtime& l, const vtime& r ); + // typedef std::pair<group_type, vtime> vtime_group_type; // typedef std::list<vtime_group_type> gvtime_type; typedef std::hash_map<group_type, vtime> gvtime_type; gvtime_type& operator +=( gvtime_type&, const gvtime_type::value_type& ); +gvtime_type& operator +=( gvtime_type&, const gvtime_type& ); +gvtime_type operator -( const gvtime_type& l, const gvtime_type& r ); struct gvtime : public stem::__pack_base @@ -108,6 +113,7 @@ { gvt = _gvt.gvt; } gvtime& operator +=( const gvtime_type::value_type& ); + gvtime& operator +=( const gvtime& ); gvtime_type::data_type& operator[]( const gvtime_type::key_type k ) { return gvt[k]; } @@ -149,6 +155,11 @@ void add_group( group_type g ) { groups.push_back( g ); } + void add_group_member( group_type g, oid_type p ) + { vt[g][p]; } + + void SendVC( group_type, const std::string& mess ); + void mess( const stem::Event_base<VTmess>& ); typedef std::list<group_type> groups_container_type; @@ -157,7 +168,9 @@ bool order_correct( const stem::Event_base<VTmess>& ); - gvtime lvt; + typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; + + delta_vtime_type lvt; gvtime vt; groups_container_type groups; @@ -173,6 +186,7 @@ ostream& operator <<( ostream&, const vt::vtime_type::value_type& ); ostream& operator <<( ostream&, const vt::vtime_type& ); +ostream& operator <<( ostream&, const vt::vtime& ); ostream& operator <<( ostream&, const vt::gvtime_type::value_type& ); ostream& operator <<( ostream&, const vt::gvtime_type& ); Modified: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-05 16:20:15 UTC (rev 1581) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-06-06 16:23:28 UTC (rev 1582) @@ -24,31 +24,33 @@ m2.add_group( 0 ); r1.add_group( 0 ); + m1.add_group_member( 0, m2.self_id() ); + m1.add_group_member( 0, r1.self_id() ); + + r1.add_group_member( 0, m1.self_id() ); + r1.add_group_member( 0, m2.self_id() ); + + m2.add_group_member( 0, m1.self_id() ); + m2.add_group_member( 0, r1.self_id() ); + m1.add_group( 1 ); m2.add_group( 1 ); r2.add_group( 1 ); - stem::Event_base<VTmess> mess( MESS ); - - mess.dest( m2.self_id() ); + m1.add_group_member( 1, m2.self_id() ); + m1.add_group_member( 1, r2.self_id() ); - mess.value().mess = "Hello!"; - mess.value().grp = 0; - mess.value().gvt.gvt[0][m1.self_id()] = 1; + r2.add_group_member( 1, m1.self_id() ); + r2.add_group_member( 1, m2.self_id() ); - m1.Send( mess ); + m2.add_group_member( 1, m1.self_id() ); + m2.add_group_member( 1, r2.self_id() ); - mess.dest( r1.self_id() ); + r1.SendVC( 0, "Hello!" ); - m1.Send( mess ); + m1.SendVC( 0, "How are you?" ); - // mess.value().gvt.gvt[0][m1.self_id()] += 1; - - // mess.value().mess = "How are you?"; - // m1.Send( mess ); - cnd.wait(); return 0; } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-04 10:40:55
|
Revision: 1598 http://svn.sourceforge.net/complement/?rev=1598&view=rev Author: complement Date: 2007-07-04 03:40:41 -0700 (Wed, 04 Jul 2007) Log Message: ----------- development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-03 09:56:08 UTC (rev 1597) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-04 10:40:41 UTC (rev 1598) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/05/24 10:24:22 ptr> +// -*- C++ -*- Time-stamp: <07/06/27 01:04:38 ptr> #include "vtime.h" @@ -105,6 +105,8 @@ void VTmess::pack( std::ostream& s ) const { + __pack( s, code ); + __pack( s, src ); gvt.pack( s ); __pack( s, grp ); __pack( s, mess ); @@ -112,6 +114,8 @@ void VTmess::net_pack( std::ostream& s ) const { + __net_pack( s, code ); + __net_pack( s, src ); gvt.net_pack( s ); __net_pack( s, grp ); __net_pack( s, mess ); @@ -119,6 +123,8 @@ void VTmess::unpack( std::istream& s ) { + __unpack( s, code ); + __unpack( s, src ); gvt.unpack( s ); __unpack( s, grp ); __unpack( s, mess ); @@ -126,6 +132,8 @@ void VTmess::net_unpack( std::istream& s ) { + __net_unpack( s, code ); + __net_unpack( s, src ); gvt.net_unpack( s ); __net_unpack( s, grp ); __net_unpack( s, mess ); @@ -277,6 +285,159 @@ return *this; } +bool vtime_obj_rec::deliver( const VTmess& m ) +{ + // cout << self_id() << " " << ev.value().mess << endl; + + // cout << ev.value().gvt.gvt << endl; + + if ( order_correct( m ) ) { + cout << "Order correct" << endl; + lvt[m.src] += m.gvt.gvt; + lvt[m.src][m.grp][m.src] = vt.gvt[m.grp][m.src] + 1; + vt.gvt[m.grp] = vt::max( vt.gvt[m.grp], lvt[m.src][m.grp] ); + cout << vt.gvt << endl; + return true; + } + + cout << "Order not correct" << endl; + return false; +} + +bool vtime_obj_rec::order_correct( const VTmess& m ) +{ + gvtime gvt( m.gvt ); + + if ( vt.gvt[m.grp][m.src] + 1 != gvt[m.grp][m.src] ) { + cerr << "1" << endl; + cerr << vt.gvt[m.grp][m.src] << "\n" + << gvt[m.grp][m.src] + << endl; + return false; + } + + vtime xvt = lvt[m.src][m.grp] + gvt[m.grp]; + xvt[m.src] = 0; + + if ( !(xvt <= vt[m.grp]) ) { + cerr << "2" << endl; + cerr << xvt << "\n\n" + << vt[m.grp] << endl; + return false; + } + + for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { + if ( *l != m.grp ) { + xvt = lvt[m.src][*l] + gvt[*l]; + if ( !(xvt <= vt[*l]) ) { + cerr << "3" << endl; + cerr << "group " << *l << xvt << "\n\n" + << vt[*l] << endl; + return false; + } + } + } + + return true; +} + +void VTDispatcher::VTDispatch( const VTmess& m ) +{ + gid_map_type::const_iterator g = grmap.find( m.grp ); + if ( g != grmap.end() ) { + for ( std::list<oid_type>::const_iterator o = g->second.begin(); o != g->second.end(); ++o ) { + vt_map_type::iterator i = vtmap.find( *o ); + if ( i != vtmap.end() ) { + if ( i->second.deliver( m ) ) { + stem::Event ev( m.code ); + ev.dest(i->first); + ev.value() = m.mess; + Send( ev ); + } + } + } + } +} + +DEFINE_RESPONSE_TABLE( VTDispatcher ) + EV_T_( ST_NULL, MESS, VTDispatch, VTmess ) +END_RESPONSE_TABLE + +char *Init_buf[128]; +VTDispatch *VTHandler::_vtdsp = 0; +static int *_rcount = 0; + +void VTHandler::Init::__at_fork_prepare() +{ +} + +void VTHandler::Init::__at_fork_child() +{ + if ( *_rcount != 0 ) { + VTHandler::_vtdsp->~VTDispatch(); + VTHandler::_vtdsp = new( VTHandler::_vtdsp ) VTDispatcher(); + } +} + +void VTHandler::Init::__at_fork_parent() +{ +} + +void VTHandler::Init::_guard( int direction ) +{ + static xmt::MutexRS _init_lock; + static int _count = 0; + + if ( direction ) { + if ( _count++ == 0 ) { +#ifdef _PTHREADS + _rcount = &_count; + pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); +#endif + VTHandler::_vtdsp = new VTDispatcher(); + } + } else { + --_count; + if ( _count == 0 ) { + delete VTHandler::_vtdsp; + VTHandler::_vtdsp = 0; + } + } +} + +VTHandler::Init::Init() +{ _guard( 1 ); } + +VTHandler::Init::~Init() +{ _guard( 0 ); } + +void VTHandler::VTSend( const stem::Event& ev ) +{ +} + +VTHandler::VTHandler() : + EventHandler() +{ + new( Init_buf ) Init(); +} + +VTHandler::VTHandler( const char *info ) : + EventHandler( info ) +{ + new( Init_buf ) Init(); +} + +VTHandler::VTHandler( stem::addr_type id, const char *info ) : + EventHandler( id, info ) +{ + new( Init_buf ) Init(); +} + +VTHandler::~VTHandler() +{ + ((Init *)Init_buf)->~Init(); +} + void Proc::mess( const stem::Event_base<VTmess>& ev ) { cout << self_id() << " " << ev.value().mess << endl; Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-03 09:56:08 UTC (rev 1597) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-04 10:40:41 UTC (rev 1598) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/05/18 00:26:00 ptr> +// -*- C++ -*- Time-stamp: <07/06/27 00:59:45 ptr> #ifndef __vtime_h #define __vtime_h @@ -129,19 +129,108 @@ void unpack( std::istream& s ); void net_unpack( std::istream& s ); - VTmess() - { } - VTmess( const VTmess& _gvt ) : - gvt( _gvt.gvt ), - mess( _gvt.mess ) - { } + VTmess() + { } + VTmess( const VTmess& _gvt ) : + gvt( _gvt.gvt ), + mess( _gvt.mess ) + { } - gvtime gvt; - group_type grp; - std::string mess; + stem::code_type code; + oid_type src; + gvtime gvt; + group_type grp; + std::string mess; }; +class vtime_obj_rec +{ + public: + typedef std::list<group_type> groups_container_type; + typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; + + void add_group( group_type g ) + { groups.push_back( g ); } + + void add_group_member( group_type g, oid_type p ) + { vt[g][p]; } + + bool deliver( const VTmess& ev ); + + stem::addr_type addr; // stem address of object + delta_vtime_type lvt; // last seen VT of neighbours + gvtime vt; // VT of object + groups_container_type groups; // member of groups + // delay pool should be here + + private: + bool order_correct( const VTmess& ); +}; + +class VTDispatcher : + public stem::EventHandler +{ + public: + VTDispatcher() + { } + + VTDispatcher( stem::addr_type id ) : + stem::EventHandler( id ) + { } + + void VTDispatch( const VTmess& ); + + void VTSend( const Event& e ); + + private: + typedef std::hash_map<oid_type, vtime_obj_rec> vt_map_type; + typedef std::hash_map<group_type, std::list<oid_type> > gid_map_type; + // oid_type map_gid( group_type ); + // gid_type -> (oid_type, oid_type, ...) + + // in our case we can use gid = hi bits | oid + + vt_map_type vtmap; + gid_map_type grmap; + + DECLARE_RESPONSE_TABLE( VTDispatcher, stem::EventHandler ); +}; + +class VTHandler : + public stem::EventHandler +{ + public: + class Init + { + public: + Init(); + ~Init(); + private: + static void _guard( int ); + static void __at_fork_prepare(); + static void __at_fork_child(); + static void __at_fork_parent(); + }; + + public: + VTHandler(); + explicit VTHandler( const char *info ); + explicit VTHandler( stem::addr_type id, const char *info = 0 ); + virtual ~VTHandler(); + + void VTSend( const Event& e ); + + template <class D> + void VTSend( const stem::Event_base<D>& e ) + { VTHandler::VTSend( stem::Event_convert<D>()( e ) ); } + + + private: + static class VTDispatcher *_vtdsp; +}; + + class Proc : public stem::EventHandler { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-20 06:10:56
|
Revision: 1633 http://svn.sourceforge.net/complement/?rev=1633&view=rev Author: complement Date: 2007-07-19 23:10:55 -0700 (Thu, 19 Jul 2007) Log Message: ----------- unit test based on exam; fix VTmess copy constructor; add operation >= Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/Makefile trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/Makefile =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile 2007-07-19 20:25:18 UTC (rev 1632) +++ trunk/complement/explore/test/virtual_time/test/Makefile 2007-07-20 06:10:55 UTC (rev 1633) @@ -10,12 +10,13 @@ # DEFS += -DUNIT_TEST INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} -I.. +DEFS += -D__FIT_EXAM -LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR} +LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR}:${STLPORT_LIB_DIR} -release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_test_utf -lboost_fs -dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_test_utfg -lboost_fsg -stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_test_utfstlg -lboost_fsstlg +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lexam -lboost_fs +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lexamg -lboost_fsg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lexamstlg -lboost_fsstlg LDLIBS = ${PROJECT_LIBS} Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-19 20:25:18 UTC (rev 1632) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-20 06:10:55 UTC (rev 1633) @@ -1,6 +1,6 @@ -// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> +// -*- C++ -*- Time-stamp: <07/07/20 09:26:15 ptr> -#include <boost/test/unit_test.hpp> +#include <exam/suite.h> #include <boost/lexical_cast.hpp> @@ -9,236 +9,461 @@ #include <vtime.h> -using namespace boost::unit_test_framework; using namespace vt; using namespace std; struct vtime_operations { - void vt_compare(); - void vt_add(); - void vt_diff(); - void vt_max(); + int EXAM_DECL(vt_compare); + int EXAM_DECL(vt_add); + int EXAM_DECL(vt_diff); + int EXAM_DECL(vt_max); + + int EXAM_DECL(gvt_add); + + int EXAM_DECL(VTMess_core); }; -void vtime_operations::vt_compare() +int EXAM_IMPL(vtime_operations::vt_compare) { vtime_type vt1; vtime_type vt2; - vt1.push_back( make_pair( 1, 1 ) ); - vt1.push_back( make_pair( 2, 1 ) ); + vt1[1] = 1; + vt1[2] = 1; - vt2.push_back( make_pair( 1, 1 ) ); - vt2.push_back( make_pair( 2, 1 ) ); + vt2[1] = 1; + vt2[2] = 1; - BOOST_CHECK( vt1 == vt2 ); - BOOST_CHECK( vt1 <= vt2 ); - BOOST_CHECK( vt2 <= vt1 ); + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( vt2 <= vt1 ); + EXAM_CHECK( vt1 >= vt2 ); + EXAM_CHECK( vt2 >= vt1 ); - vt2.push_back( make_pair( 3, 1 ) ); + vt2[3] = 1; - BOOST_CHECK( !(vt1 == vt2) ); - BOOST_CHECK( vt1 <= vt2 ); - BOOST_CHECK( !(vt2 <= vt1) ); + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( !(vt2 <= vt1) ); + EXAM_CHECK( vt2 >= vt1 ); vt1.clear(); vt2.clear(); - vt1.push_back( make_pair( 1, 1 ) ); + vt1[1] = 1; - vt2.push_back( make_pair( 1, 1 ) ); - vt2.push_back( make_pair( 3, 1 ) ); + vt2[1] = 1; + vt2[3] = 1; - BOOST_CHECK( !(vt1 == vt2) ); - BOOST_CHECK( vt1 <= vt2 ); - BOOST_CHECK( !(vt2 <= vt1) ); + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( !(vt2 <= vt1) ); - vt1.push_back( make_pair( 2, 1 ) ); + vt1[2] = 1; - BOOST_CHECK( !(vt1 <= vt2) ); - BOOST_CHECK( !(vt2 <= vt1) ); + EXAM_CHECK( !(vt1 <= vt2) ); + EXAM_CHECK( !(vt2 <= vt1) ); } -void vtime_operations::vt_add() +int EXAM_IMPL(vtime_operations::vt_add) { vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1.push_back( make_pair( 1, 1 ) ); - vt1.push_back( make_pair( 2, 1 ) ); + vt1[1] = 1; + vt1[2] = 1; vt3 = vt1 + vt2; - BOOST_CHECK( vt1 == vt3 ); + EXAM_CHECK( vt1 <= vt3 ); + EXAM_CHECK( vt3 <= vt1 ); - vt2.push_back( make_pair( 2, 1 ) ); + vt2[2] = 1; vt3 = vt1 + vt2; - vt4.push_back( make_pair( 1, 1 ) ); - vt4.push_back( make_pair( 2, 2 ) ); + vt4[1] = 1; + vt4[2] = 2; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); vt4.clear(); - vt2.push_back( make_pair( 3, 1 ) ); + vt2[3] = 1; vt3 = vt1 + vt2; - vt4.push_back( make_pair( 1, 1 ) ); - vt4.push_back( make_pair( 2, 2 ) ); - vt4.push_back( make_pair( 3, 1 ) ); + vt4[1] = 1; + vt4[2] = 2; + vt4[3] = 1; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + return EXAM_RESULT; } -void vtime_operations::vt_diff() +int EXAM_IMPL(vtime_operations::vt_diff) { vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1.push_back( make_pair( 1, 1 ) ); - vt1.push_back( make_pair( 2, 1 ) ); + vt1[1] = 1; + vt1[2] = 1; vt3 = vt1 - vt2; - BOOST_CHECK( vt1 == vt3 ); + EXAM_CHECK( vt1 <= vt3 ); + EXAM_CHECK( vt3 <= vt1 ); - vt2.push_back( make_pair( 1, 1 ) ); + vt2[1] = 1; vt3 = vt1 - vt2; - vt4.push_back( make_pair( 2, 1 ) ); + vt4[2] = 1; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); - vt2.push_back( make_pair( 2, 1 ) ); + vt2[2] = 1; vt4.clear(); vt3 = vt1 - vt2; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); vt2.clear(); - vt2.push_back( make_pair( 3, 1 ) ); + vt2[3] = 1; try { vt3 = vt1 - vt2; - BOOST_CHECK( false ); + EXAM_ERROR( "Virtual Times are incomparable" ); } catch ( const std::range_error& err ) { - BOOST_CHECK( true ); + EXAM_CHECK( true ); } vt2.clear(); - vt2.push_back( make_pair( 2, 2 ) ); + vt2[2] = 2; try { vt3 = vt1 - vt2; - BOOST_CHECK( false ); + EXAM_ERROR( "Virtual Times are incomparable" ); } catch ( const std::range_error& err ) { - BOOST_CHECK( true ); - } + EXAM_CHECK( true ); + } + + return EXAM_RESULT; } -void vtime_operations::vt_max() +int EXAM_IMPL(vtime_operations::vt_max) { vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1.push_back( make_pair( 1, 1 ) ); - vt1.push_back( make_pair( 2, 1 ) ); + vt1[1] = 1; + vt1[2] = 1; vt3 = vt::max( vt1, vt2 ); - BOOST_CHECK( vt3 == vt1 ); + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); - vt2.push_back( make_pair( 1, 1 ) ); + vt2[1] = 1; vt3 = vt::max( vt1, vt2 ); - BOOST_CHECK( vt3 == vt1 ); + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); - vt2.push_back( make_pair( 2, 1 ) ); + vt2[2] = 1; vt3 = vt::max( vt1, vt2 ); - BOOST_CHECK( vt3 == vt1 ); + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); - vt2.push_back( make_pair( 3, 1 ) ); + vt2[3] = 1; vt3 = vt::max( vt1, vt2 ); - vt4.push_back( make_pair( 1, 1 ) ); - vt4.push_back( make_pair( 2, 1 ) ); - vt4.push_back( make_pair( 3, 1 ) ); + vt4[1] = 1; + vt4[2] = 1; + vt4[3] = 1; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); vt2.clear(); - vt2.push_back( make_pair( 1, 1 ) ); - vt2.push_back( make_pair( 2, 2 ) ); + vt2[1] = 1; + vt2[2] = 2; vt4.clear(); vt3 = vt::max( vt1, vt2 ); - vt4.push_back( make_pair( 1, 1 ) ); - vt4.push_back( make_pair( 2, 2 ) ); + vt4[1] = 1; + vt4[2] = 2; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); - vt2.push_back( make_pair( 3, 4 ) ); + vt2[3] = 4; vt3 = vt::max( vt1, vt2 ); - vt4.push_back( make_pair( 3, 4 ) ); + vt4[3] = 4; - BOOST_CHECK( vt3 == vt4 ); + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + return EXAM_RESULT; } -struct vtime_test_suite : - public boost::unit_test_framework::test_suite +int EXAM_IMPL(vtime_operations::gvt_add) { - vtime_test_suite(); + { + gvtime_type gvt1; + gvtime_type gvt2; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + gvt2[0] = vt2; + + gvt1 += gvt2; + + EXAM_CHECK( gvt1[0][1] == 2 ); + EXAM_CHECK( gvt1[0][2] == 2 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 0 ); + EXAM_CHECK( gvt1[1][2] == 0 ); + } + { + gvtime_type gvt1; + gvtime_type gvt2; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + gvt2[1] = vt2; + + gvt1 += gvt2; + + EXAM_CHECK( gvt1[0][1] == 1 ); + EXAM_CHECK( gvt1[0][2] == 1 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 1 ); + EXAM_CHECK( gvt1[1][2] == 1 ); + } + { + gvtime_type gvt1; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + + gvt1 += make_pair( 1, vt2 ); + + EXAM_CHECK( gvt1[0][1] == 1 ); + EXAM_CHECK( gvt1[0][2] == 1 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 1 ); + EXAM_CHECK( gvt1[1][2] == 1 ); + } +} + +class VTM_handler : + public stem::EventHandler +{ + public: + VTM_handler(); + VTM_handler( stem::addr_type id ); + VTM_handler( stem::addr_type id, const char *info ); + ~VTM_handler(); + + void handlerE( const stem::Event_base<VTmess>& ); + void handlerV( const VTmess& ); + + void wait(); + + stem::code_type code; + oid_type src; + gvtime gvt; + group_type grp; + std::string mess; + + private: + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( VTM_handler, stem::EventHandler ); }; -vtime_test_suite::vtime_test_suite() : - test_suite( "vtime test suite" ) +#define VT_MESS 0x1201 + +VTM_handler::VTM_handler() : + EventHandler() { - boost::shared_ptr<vtime_operations> vt_op_instance( new vtime_operations() ); + cnd.set( false ); +} - test_case *vt_compare_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_compare, vt_op_instance ); - test_case *vt_add_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_add, vt_op_instance ); - test_case *vt_diff_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_diff, vt_op_instance ); - test_case *vt_max_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_max, vt_op_instance ); +VTM_handler::VTM_handler( stem::addr_type id ) : + EventHandler( id ) +{ + cnd.set( false ); +} - // long_msg_tc->depends_on( init_tc ); +VTM_handler::VTM_handler( stem::addr_type id, const char *info ) : + EventHandler( id, info ) +{ + cnd.set( false ); +} - add( vt_compare_tc ); - add( vt_add_tc ); - add( vt_diff_tc ); - add( vt_max_tc ); - // add( service_tc ); +VTM_handler::~VTM_handler() +{ + // cnd.wait(); } -test_suite *init_unit_test_suite( int argc, char **argv ) +void VTM_handler::handlerE( const stem::Event_base<VTmess>& ev ) { - test_suite *ts = BOOST_TEST_SUITE( "vtime test" ); - ts->add( new vtime_test_suite() ); + code = ev.value().code; + src = ev.value().src; + gvt = ev.value().gvt; + grp = ev.value().grp; + mess = ev.value().mess; - return ts; + PushState( 1 ); + cnd.set( true ); } + +void VTM_handler::handlerV( const VTmess& m ) +{ + code = m.code; + src = m.src; + gvt = m.gvt; + grp = m.grp; + mess = m.mess; + + PopState(); + cnd.set( true ); +} + +void VTM_handler::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +DEFINE_RESPONSE_TABLE( VTM_handler ) + EV_Event_base_T_( ST_NULL, VT_MESS, handlerE, VTmess ) + EV_T_( 1, VT_MESS, handlerV, VTmess ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::VTMess_core) +{ + VTM_handler h; + + stem::Event_base<VTmess> ev( VT_MESS ); + + ev.dest( h.self_id() ); + ev.value().code = 2; + ev.value().src = 3; + ev.value().gvt[0][0] = 1; + ev.value().gvt[0][1] = 2; + ev.value().gvt[1][0] = 3; + ev.value().gvt[1][1] = 4; + ev.value().grp = 7; + ev.value().mess = "data"; + + h.Send( ev ); + + h.wait(); + + EXAM_CHECK( h.code == 2 ); + EXAM_CHECK( h.src == 3 ); + EXAM_CHECK( h.gvt[0][0] == 1 ); + EXAM_CHECK( h.gvt[0][1] == 2 ); + EXAM_CHECK( h.gvt[1][0] == 3 ); + EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.mess == "data" ); + + ev.value().code = 3; + ev.value().mess = "more data"; + + h.Send( ev ); + + h.wait(); + + EXAM_CHECK( h.code == 3 ); + EXAM_CHECK( h.src == 3 ); + EXAM_CHECK( h.gvt[0][0] == 1 ); + EXAM_CHECK( h.gvt[0][1] == 2 ); + EXAM_CHECK( h.gvt[1][0] == 3 ); + EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.mess == "more data" ); + + return EXAM_RESULT; +} + + +int EXAM_DECL(vtime_test_suite); + +int EXAM_IMPL(vtime_test_suite) +{ + exam::test_suite::test_case_type tc[2]; + + exam::test_suite t( "virtual time operations" ); + + vtime_operations vt_oper; + + t.add( &vtime_operations::vt_max, vt_oper, "Max", + tc[1] = t.add( &vtime_operations::vt_add, vt_oper, "Additions", + tc[0] = t.add( &vtime_operations::vt_compare, vt_oper, "Compare" ) ) ); + t.add( &vtime_operations::vt_diff, vt_oper, "Differences", tc[0] ); + + t.add( &vtime_operations::VTMess_core, vt_oper, "VTmess core transfer", + t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); + + return t.girdle(); +} + +int main( int, char ** ) +{ + + return vtime_test_suite(0); +} Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-19 20:25:18 UTC (rev 1632) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-20 06:10:55 UTC (rev 1633) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/06/27 01:04:38 ptr> +// -*- C++ -*- Time-stamp: <07/07/19 23:11:01 ptr> #include "vtime.h" @@ -230,7 +230,7 @@ return *this; } -gvtime_type& operator +=( gvtime_type& gvt, gvtime_type::value_type& t ) +gvtime_type& operator +=( gvtime_type& gvt, const gvtime_type::value_type& t ) { gvt[t.first] += t.second; @@ -364,7 +364,7 @@ END_RESPONSE_TABLE char *Init_buf[128]; -VTDispatch *VTHandler::_vtdsp = 0; +VTDispatcher *VTHandler::_vtdsp = 0; static int *_rcount = 0; void VTHandler::Init::__at_fork_prepare() @@ -374,7 +374,7 @@ void VTHandler::Init::__at_fork_child() { if ( *_rcount != 0 ) { - VTHandler::_vtdsp->~VTDispatch(); + VTHandler::_vtdsp->~VTDispatcher(); VTHandler::_vtdsp = new( VTHandler::_vtdsp ) VTDispatcher(); } } @@ -385,7 +385,7 @@ void VTHandler::Init::_guard( int direction ) { - static xmt::MutexRS _init_lock; + static xmt::recursive_mutex _init_lock; static int _count = 0; if ( direction ) { Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-19 20:25:18 UTC (rev 1632) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-20 06:10:55 UTC (rev 1633) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/06/27 00:59:45 ptr> +// -*- C++ -*- Time-stamp: <07/07/20 09:29:00 ptr> #ifndef __vtime_h #define __vtime_h @@ -27,6 +27,8 @@ // typedef std::list<vtime_proc_type> vtime_type; bool operator <=( const vtime_type& l, const vtime_type& r ); +inline bool operator >=( const vtime_type& l, const vtime_type& r ) + { return r <= l; } vtime_type operator -( const vtime_type& l, const vtime_type& r ); vtime_type operator +( const vtime_type& l, const vtime_type& r ); vtime_type& operator +=( vtime_type& l, const vtime_type& r ); @@ -58,6 +60,8 @@ bool operator <=( const vtime& r ) const { return vt <= r.vt; } + bool operator >=( const vtime& r ) const + { return vt >= r.vt; } vtime operator -( const vtime& r ) const { return vtime( vt - r.vt ); } @@ -129,10 +133,18 @@ void unpack( std::istream& s ); void net_unpack( std::istream& s ); - VTmess() + VTmess() : + code(0), + src(0), + gvt(), + grp(0), + mess() { } VTmess( const VTmess& _gvt ) : + code( _gvt.code ), + src( _gvt.src ), gvt( _gvt.gvt ), + grp( _gvt.grp ), mess( _gvt.mess ) { } @@ -181,7 +193,7 @@ void VTDispatch( const VTmess& ); - void VTSend( const Event& e ); + void VTSend( const stem::Event& e ); private: typedef std::hash_map<oid_type, vtime_obj_rec> vt_map_type; @@ -219,7 +231,7 @@ explicit VTHandler( stem::addr_type id, const char *info = 0 ); virtual ~VTHandler(); - void VTSend( const Event& e ); + void VTSend( const stem::Event& e ); template <class D> void VTSend( const stem::Event_base<D>& e ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-24 07:49:07
|
Revision: 1638 http://svn.sourceforge.net/complement/?rev=1638&view=rev Author: complement Date: 2007-07-24 00:49:03 -0700 (Tue, 24 Jul 2007) Log Message: ----------- test for delivery VT message established; throw exception, if message has no chance to be delivered Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-23 12:17:18 UTC (rev 1637) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-24 07:49:03 UTC (rev 1638) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/20 09:26:15 ptr> +// -*- C++ -*- Time-stamp: <07/07/23 23:46:02 ptr> #include <exam/suite.h> @@ -22,6 +22,8 @@ int EXAM_DECL(gvt_add); int EXAM_DECL(VTMess_core); + + int EXAM_DECL(vt_object); }; int EXAM_IMPL(vtime_operations::vt_compare) @@ -303,6 +305,8 @@ EXAM_CHECK( gvt1[1][1] == 1 ); EXAM_CHECK( gvt1[1][2] == 1 ); } + + return EXAM_RESULT; } class VTM_handler : @@ -440,12 +444,94 @@ return EXAM_RESULT; } +int EXAM_IMPL(vtime_operations::vt_object) +{ + vtime_obj_rec ob; + const group_type gr0 = 0; + const group_type gr1 = 0; + const oid_type obj0 = 0; + const oid_type obj1 = 1; + const oid_type obj2 = 2; + + ob.add_group( gr0 ); + ob.add_group_member( gr0, obj0 ); + ob.add_group_member( gr0, obj1 ); + ob.add_group_member( gr0, obj2 ); + + // gvtime gvt; + // gvt[gr0][obj1] = 1; + + VTmess mess; + VTmess mess_bad; + + mess_bad.code = mess.code = 1; + mess_bad.src = mess.src = obj1; + mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] = 1; + mess_bad.grp = mess.grp = gr0; + mess_bad.mess = mess.mess = "data"; + + EXAM_CHECK( ob.deliver(mess) ); // ack + + ++mess.gvt[gr0][obj1]; + + EXAM_CHECK( ob.deliver(mess) ); // ack + + ++mess.gvt[gr0][obj1]; + + try { + EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: too old (out of order) + EXAM_ERROR( "exception expected" ); + } + catch ( const out_of_range& ) { + } + + mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] + 1; + + EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: too new (out of order) + + EXAM_CHECK( ob.deliver(mess) ); // ack + + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; + + // ---- + + VTmess mess2; + + mess2.code = 1; + mess2.src = obj2; + mess2.gvt[gr0][obj2] = 1; + mess2.grp = gr0; + mess2.mess = "data"; + + mess_bad.gvt[gr0][obj2] = 1; + + EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: obj0 don't seen mess from obj2, but obj1 seen mess from obj2 + + EXAM_CHECK( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 + + ++mess2.gvt[gr0][obj2]; + + EXAM_CHECK( ob.deliver(mess_bad) ); // ack: now obj0 and obj1 sync dependency from obj2 + + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; + mess.gvt[gr0][obj2] = 1; + + // ---- + + ob.add_group( gr0 ); + ob.add_group_member( gr1, obj0 ); + ob.add_group_member( gr1, obj1 ); + ob.add_group_member( gr1, obj2 ); + + return EXAM_RESULT; +} + int EXAM_DECL(vtime_test_suite); int EXAM_IMPL(vtime_test_suite) { - exam::test_suite::test_case_type tc[2]; + exam::test_suite::test_case_type tc[3]; exam::test_suite t( "virtual time operations" ); @@ -457,8 +543,10 @@ t.add( &vtime_operations::vt_diff, vt_oper, "Differences", tc[0] ); t.add( &vtime_operations::VTMess_core, vt_oper, "VTmess core transfer", - t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); + tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); + t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ); + return t.girdle(); } Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-23 12:17:18 UTC (rev 1637) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-24 07:49:03 UTC (rev 1638) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/19 23:11:01 ptr> +// -*- C++ -*- Time-stamp: <07/07/23 20:32:22 ptr> #include "vtime.h" @@ -212,6 +212,15 @@ return tmp; } +vtime_type& sup( vtime_type& l, const vtime_type& r ) +{ + for ( vtime_type::const_iterator i = r.begin(); i != r.end(); ++i ) { + l[i->first] = std::max( l[i->first], i->second ); + } + return l; +} + + // template <> vtime max( const vtime& l, const vtime& r ) { @@ -223,6 +232,14 @@ return tmp; } +vtime& sup( vtime& l, const vtime& r ) +{ + for ( vtime_type::const_iterator i = r.vt.begin(); i != r.vt.end(); ++i ) { + l[i->first] = std::max( l[i->first], i->second ); + } + return l; +} + vtime& vtime::operator +=( const vtime_type::value_type& t ) { vt[t.first] += t.second; @@ -292,27 +309,32 @@ // cout << ev.value().gvt.gvt << endl; if ( order_correct( m ) ) { - cout << "Order correct" << endl; lvt[m.src] += m.gvt.gvt; lvt[m.src][m.grp][m.src] = vt.gvt[m.grp][m.src] + 1; - vt.gvt[m.grp] = vt::max( vt.gvt[m.grp], lvt[m.src][m.grp] ); - cout << vt.gvt << endl; + sup( vt.gvt[m.grp], lvt[m.src][m.grp] ); + // cout << vt.gvt << endl; return true; } - cout << "Order not correct" << endl; return false; } bool vtime_obj_rec::order_correct( const VTmess& m ) { + if ( groups.find( m.grp ) == groups.end() ) { + throw domain_error( "VT object not member of group" ); + } + gvtime gvt( m.gvt ); if ( vt.gvt[m.grp][m.src] + 1 != gvt[m.grp][m.src] ) { - cerr << "1" << endl; - cerr << vt.gvt[m.grp][m.src] << "\n" - << gvt[m.grp][m.src] - << endl; + // cerr << "1" << endl; + // cerr << vt.gvt[m.grp][m.src] << "\n" + // << gvt[m.grp][m.src] + // << endl; + if ( vt.gvt[m.grp][m.src] + 1 > gvt[m.grp][m.src] ) { + throw out_of_range( "duplicate or wrong VT message" ); + } return false; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-23 12:17:18 UTC (rev 1637) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-24 07:49:03 UTC (rev 1638) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/20 09:29:00 ptr> +// -*- C++ -*- Time-stamp: <07/07/23 21:33:09 ptr> #ifndef __vtime_h #define __vtime_h @@ -7,6 +7,7 @@ #include <list> #include <vector> #include <hash_map> +#include <hash_set> #include <iterator> #include <istream> @@ -34,6 +35,7 @@ vtime_type& operator +=( vtime_type& l, const vtime_type& r ); vtime_type max( const vtime_type& l, const vtime_type& r ); +vtime_type& sup( vtime_type& l, const vtime_type& r ); struct vtime : public stem::__pack_base @@ -90,6 +92,7 @@ vtime max( const vtime& l, const vtime& r ); +vtime& sup( vtime& l, const vtime& r ); // typedef std::pair<group_type, vtime> vtime_group_type; // typedef std::list<vtime_group_type> gvtime_type; @@ -159,11 +162,11 @@ { public: - typedef std::list<group_type> groups_container_type; + typedef std::hash_set<group_type> groups_container_type; typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; void add_group( group_type g ) - { groups.push_back( g ); } + { groups.insert(g); } void add_group_member( group_type g, oid_type p ) { vt[g][p]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-25 06:55:40
|
Revision: 1639 http://complement.svn.sourceforge.net/complement/?rev=1639&view=rev Author: complement Date: 2007-07-24 23:55:38 -0700 (Tue, 24 Jul 2007) Log Message: ----------- more information checked within unit test; evolution of VTDispatch Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-24 07:49:03 UTC (rev 1638) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-25 06:55:38 UTC (rev 1639) @@ -449,15 +449,16 @@ vtime_obj_rec ob; const group_type gr0 = 0; - const group_type gr1 = 0; + const group_type gr1 = 1; + const group_type gr2 = 2; const oid_type obj0 = 0; const oid_type obj1 = 1; const oid_type obj2 = 2; ob.add_group( gr0 ); - ob.add_group_member( gr0, obj0 ); - ob.add_group_member( gr0, obj1 ); - ob.add_group_member( gr0, obj2 ); + // ob.add_group_member( gr0, obj0 ); + // ob.add_group_member( gr0, obj1 ); + // ob.add_group_member( gr0, obj2 ); // gvtime gvt; // gvt[gr0][obj1] = 1; @@ -471,12 +472,30 @@ mess_bad.grp = mess.grp = gr0; mess_bad.mess = mess.mess = "data"; - EXAM_CHECK( ob.deliver(mess) ); // ack + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + vtime chk; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + EXAM_REQUIRE( ob.deliver(mess) ); // ack + + chk[obj1] += 1; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + ++mess.gvt[gr0][obj1]; - EXAM_CHECK( ob.deliver(mess) ); // ack + EXAM_REQUIRE( ob.deliver(mess) ); // ack + chk[obj1] += 1; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + ++mess.gvt[gr0][obj1]; try { @@ -484,16 +503,25 @@ EXAM_ERROR( "exception expected" ); } catch ( const out_of_range& ) { + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); } mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] + 1; - EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: too new (out of order) + EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: too new (out of order) - EXAM_CHECK( ob.deliver(mess) ); // ack + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( ob.deliver(mess) ); // ack + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + // ---- VTmess mess2; @@ -508,22 +536,90 @@ EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: obj0 don't seen mess from obj2, but obj1 seen mess from obj2 - EXAM_CHECK( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 + + chk[obj2] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + ++mess2.gvt[gr0][obj2]; - EXAM_CHECK( ob.deliver(mess_bad) ); // ack: now obj0 and obj1 sync dependency from obj2 + EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now obj0 and obj1 sync dependency from obj2 + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; mess.gvt[gr0][obj2] = 1; + mess_bad.gvt[gr0][obj2] = 0; // ---- - ob.add_group( gr0 ); - ob.add_group_member( gr1, obj0 ); - ob.add_group_member( gr1, obj1 ); - ob.add_group_member( gr1, obj2 ); + ob.add_group( gr1 ); + // ob.add_group_member( gr1, obj0 ); + // ob.add_group_member( gr1, obj1 ); + // ob.add_group_member( gr1, obj2 ); + mess_bad.grp = gr2; + + vtime chk1; + + try { + EXAM_CHECK( ob.deliver(mess_bad) ); // nac: ob not member of group gr2 + EXAM_ERROR( "exception expected" ); + } + catch ( const domain_error& ) { + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr2]) && (chk1 >= ob.vt[gr2]) ); + } + + // ---- + + mess_bad.grp = gr0; + mess_bad.gvt[gr1][obj2] = 1; + + EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: obj1 recieve new event in group gr1 from obj2 + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + + // cerr << "===========\n"; + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + VTmess mess3; + + mess3.code = 1; + mess3.src = obj2; + mess3.gvt[gr1][obj2] = 1; + mess3.grp = gr1; + mess3.mess = "data"; + + EXAM_REQUIRE( ob.deliver(mess3) ); // ack: see event from obj2 in group gr1 + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + chk1[obj2] += 1; + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + + ++mess3.gvt[gr1][obj2]; + + // cerr << "===========\n"; + // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr0] << endl; + // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr1] << endl; + // cerr << "===========\n"; + + // cerr << "2 ==========\n"; + EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now we know about event in group gr1 + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + return EXAM_RESULT; } Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-24 07:49:03 UTC (rev 1638) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-25 06:55:38 UTC (rev 1639) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/23 20:32:22 ptr> +// -*- C++ -*- Time-stamp: <07/07/25 10:22:27 ptr> #include "vtime.h" @@ -319,6 +319,23 @@ return false; } +bool vtime_obj_rec::deliver_delayed( const VTmess& m ) +{ + // cout << self_id() << " " << ev.value().mess << endl; + + // cout << ev.value().gvt.gvt << endl; + + if ( order_correct_delayed( m ) ) { + lvt[m.src] += m.gvt.gvt; + lvt[m.src][m.grp][m.src] = vt.gvt[m.grp][m.src] + 1; + sup( vt.gvt[m.grp], lvt[m.src][m.grp] ); + // cout << vt.gvt << endl; + return true; + } + + return false; +} + bool vtime_obj_rec::order_correct( const VTmess& m ) { if ( groups.find( m.grp ) == groups.end() ) { @@ -327,62 +344,115 @@ gvtime gvt( m.gvt ); - if ( vt.gvt[m.grp][m.src] + 1 != gvt[m.grp][m.src] ) { + if ( (vt.gvt[m.grp][m.src] + 1) != gvt[m.grp][m.src] ) { // cerr << "1" << endl; // cerr << vt.gvt[m.grp][m.src] << "\n" // << gvt[m.grp][m.src] // << endl; - if ( vt.gvt[m.grp][m.src] + 1 > gvt[m.grp][m.src] ) { + if ( (vt.gvt[m.grp][m.src] + 1) > gvt[m.grp][m.src] ) { throw out_of_range( "duplicate or wrong VT message" ); } return false; } vtime xvt = lvt[m.src][m.grp] + gvt[m.grp]; - xvt[m.src] = 0; + xvt[m.src] = 0; // force exclude message originator, it checked above if ( !(xvt <= vt[m.grp]) ) { - cerr << "2" << endl; - cerr << xvt << "\n\n" - << vt[m.grp] << endl; + // cerr << "2" << endl; + // cerr << xvt << "\n\n" << vt[m.grp] << endl; return false; } + // check side casuality (via groups other then message's group) for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { - if ( *l != m.grp ) { - xvt = lvt[m.src][*l] + gvt[*l]; - if ( !(xvt <= vt[*l]) ) { - cerr << "3" << endl; - cerr << "group " << *l << xvt << "\n\n" - << vt[*l] << endl; - return false; - } + if ( (*l != m.grp) && !((lvt[m.src][*l] + gvt[*l]) <= vt[*l]) ) { + // cerr << "3" << endl; + // cerr << "group " << *l << xvt << "\n\n" << vt[*l] << endl; + return false; } } return true; } -void VTDispatcher::VTDispatch( const VTmess& m ) +bool vtime_obj_rec::order_correct_delayed( const VTmess& m ) { - gid_map_type::const_iterator g = grmap.find( m.grp ); - if ( g != grmap.end() ) { - for ( std::list<oid_type>::const_iterator o = g->second.begin(); o != g->second.end(); ++o ) { - vt_map_type::iterator i = vtmap.find( *o ); - if ( i != vtmap.end() ) { - if ( i->second.deliver( m ) ) { - stem::Event ev( m.code ); - ev.dest(i->first); - ev.value() = m.mess; - Send( ev ); - } + gvtime gvt( m.gvt ); + + if ( (vt.gvt[m.grp][m.src] + 1) != gvt[m.grp][m.src] ) { + return false; + } + + vtime xvt = lvt[m.src][m.grp] + gvt[m.grp]; + xvt[m.src] = 0; // force exclude message originator, it checked above + + if ( !(xvt <= vt[m.grp]) ) { + return false; + } + + // check side casuality (via groups other then message's group) + for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { + if ( (*l != m.grp) && !((lvt[m.src][*l] + gvt[*l]) <= vt[*l]) ) { + return false; + } + } + + return true; +} + +void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) +{ + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( m.value().grp ); + + for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { + vt_map_type::iterator i = vtmap.find( o->second ); + if ( i != vtmap.end() || i->first == m.src() ) { // not for nobody and not for self + continue; + } + try { + if ( i->second.deliver( m.value() ) ) { + stem::Event ev( m.value().code ); + ev.dest(i->first); + ev.src(m.src()); + ev.value() = m.value().mess; + Forward( ev ); + bool more; + do { + more = false; + for ( vtime_obj_rec::dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { + if ( i->second.deliver_delayed( j->second->value() ) ) { + stem::Event evd( j->second->value().code ); + evd.dest(i->first); + ev.src(m.src()); + evd.value() = j->second->value().mess; + Forward( evd ); + delete j->second; + i->second.dpool.erase( j++ ); + more = true; + } else { + ++j; + } + } + } while ( more ); + } else { + i->second.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp } } + catch ( const out_of_range& ) { + } + catch ( const domain_error& ) { + } } } +void VTDispatcher::VTSend( const stem::Event& e ) +{ +} + DEFINE_RESPONSE_TABLE( VTDispatcher ) - EV_T_( ST_NULL, MESS, VTDispatch, VTmess ) + // EV_T_( ST_NULL, MESS, VTDispatch, VTmess ) + EV_Event_base_T_( ST_NULL, MESS, VTDispatch, VTmess ) END_RESPONSE_TABLE char *Init_buf[128]; Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-24 07:49:03 UTC (rev 1638) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-25 06:55:38 UTC (rev 1639) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/23 21:33:09 ptr> +// -*- C++ -*- Time-stamp: <07/07/25 09:07:25 ptr> #ifndef __vtime_h #define __vtime_h @@ -168,19 +168,25 @@ void add_group( group_type g ) { groups.insert(g); } - void add_group_member( group_type g, oid_type p ) - { vt[g][p]; } + // void add_group_member( group_type g, oid_type p ) + // { vt[g][p]; } bool deliver( const VTmess& ev ); + bool deliver_delayed( const VTmess& ev ); stem::addr_type addr; // stem address of object delta_vtime_type lvt; // last seen VT of neighbours gvtime vt; // VT of object groups_container_type groups; // member of groups // delay pool should be here + typedef std::pair<int,stem::Event_base<VTmess>*> delay_item_t; + typedef std::list<delay_item_t> dpool_t; + dpool_t dpool; + private: bool order_correct( const VTmess& ); + bool order_correct_delayed( const VTmess& ); }; class VTDispatcher : @@ -194,13 +200,13 @@ stem::EventHandler( id ) { } - void VTDispatch( const VTmess& ); + void VTDispatch( const stem::Event_base<VTmess>& ); void VTSend( const stem::Event& e ); private: typedef std::hash_map<oid_type, vtime_obj_rec> vt_map_type; - typedef std::hash_map<group_type, std::list<oid_type> > gid_map_type; + typedef std::hash_multimap<group_type, oid_type> gid_map_type; // oid_type map_gid( group_type ); // gid_type -> (oid_type, oid_type, ...) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-25 17:43:06
|
Revision: 1640 http://complement.svn.sourceforge.net/complement/?rev=1640&view=rev Author: complement Date: 2007-07-25 10:42:59 -0700 (Wed, 25 Jul 2007) Log Message: ----------- VTDispatcher development Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-25 06:55:38 UTC (rev 1639) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-25 17:42:59 UTC (rev 1640) @@ -24,6 +24,8 @@ int EXAM_DECL(VTMess_core); int EXAM_DECL(vt_object); + + int EXAM_DECL(VTDispatch); }; int EXAM_IMPL(vtime_operations::vt_compare) @@ -623,6 +625,95 @@ return EXAM_RESULT; } + +class Dummy : + public stem::EventHandler +{ + public: + Dummy(); + Dummy( stem::addr_type id ); + Dummy( stem::addr_type id, const char *info ); + ~Dummy(); + + void handler( const stem::Event& ); + + void wait(); + std::string msg; + + private: + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( Dummy, stem::EventHandler ); +}; + +#define VT_MESS2 0x1202 + +Dummy::Dummy() : + EventHandler() +{ + cnd.set( false ); +} + +Dummy::Dummy( stem::addr_type id ) : + EventHandler( id ) +{ + cnd.set( false ); +} + +Dummy::Dummy( stem::addr_type id, const char *info ) : + EventHandler( id, info ) +{ + cnd.set( false ); +} + +Dummy::~Dummy() +{ + // cnd.wait(); +} + +void Dummy::handler( const stem::Event& ev ) +{ + msg = ev.value(); + + cnd.set( true ); +} + +void Dummy::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +DEFINE_RESPONSE_TABLE( Dummy ) + EV_EDS( ST_NULL, VT_MESS2, handler ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::VTDispatch) +{ + vt::VTDispatcher dsp; + Dummy dummy1; + Dummy dummy2; + + dsp.Subscribe( dummy1.self_id(), 1, 0 ); + dsp.Subscribe( dummy2.self_id(), 2, 0 ); + + stem::Event ev( VT_MESS2 ); + ev.src( dummy1.self_id() ); + + ev.value() = "hello"; + + dsp.VTSend( ev, 0 ); + + dummy2.wait(); + + EXAM_CHECK( dummy2.msg == "hello" ); + EXAM_CHECK( dummy1.msg == "" ); + + return EXAM_RESULT; +} + + int EXAM_DECL(vtime_test_suite); int EXAM_IMPL(vtime_test_suite) Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-25 06:55:38 UTC (rev 1639) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-25 17:42:59 UTC (rev 1640) @@ -403,17 +403,22 @@ void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) { - pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( m.value().grp ); + VTDispatch_( m, grmap.equal_range( m.value().grp ) ); +} +void VTDispatcher::VTDispatch_( const stem::Event_base<VTmess>& m, const std::pair<gid_map_type::const_iterator,gid_map_type::const_iterator>& range ) +{ for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { vt_map_type::iterator i = vtmap.find( o->second ); - if ( i != vtmap.end() || i->first == m.src() ) { // not for nobody and not for self + if ( i == vtmap.end() || i->second.addr == m.src() ) { // not for nobody and not for self continue; } try { + // check local or remote? i->second.addr + // if remote, forward it to foreign VTDispatcher? if ( i->second.deliver( m.value() ) ) { stem::Event ev( m.value().code ); - ev.dest(i->first); + ev.dest(i->second.addr); ev.src(m.src()); ev.value() = m.value().mess; Forward( ev ); @@ -423,7 +428,7 @@ for ( vtime_obj_rec::dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { if ( i->second.deliver_delayed( j->second->value() ) ) { stem::Event evd( j->second->value().code ); - evd.dest(i->first); + evd.dest(i->second.addr); ev.src(m.src()); evd.value() = j->second->value().mess; Forward( evd ); @@ -446,10 +451,40 @@ } } -void VTDispatcher::VTSend( const stem::Event& e ) +void VTDispatcher::VTSend( const stem::Event& e, group_type grp ) { + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + + for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { + vt_map_type::iterator i = vtmap.find( o->second ); + if ( i != vtmap.end() && i->second.addr == e.src() ) { // for self + stem::Event_base<VTmess> m( MESS ); + m.value().src = o->second; // oid + m.value().code = e.code(); + m.value().mess = e.value(); + m.value().grp = grp; + m.value().gvt.gvt = i->second.vt.gvt - i->second.svt[grp]; // delta + m.value().gvt[grp][o->second] = ++i->second.vt.gvt[grp][o->second]; // my counter + i->second.svt[grp] = i->second.vt.gvt; // store last send VT to group + // m.dest( ??? ); // local VT dispatcher? + m.src( e.src() ); + VTDispatch_( m, range ); + return; + } + } + + // Error: not group member? } +void VTDispatcher::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) +{ + vtime_obj_rec& r = vtmap[oid]; + r.addr = addr; + r.add_group( grp ); + + grmap.insert( make_pair(grp,oid) ); +} + DEFINE_RESPONSE_TABLE( VTDispatcher ) // EV_T_( ST_NULL, MESS, VTDispatch, VTmess ) EV_Event_base_T_( ST_NULL, MESS, VTDispatch, VTmess ) Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-25 06:55:38 UTC (rev 1639) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-25 17:42:59 UTC (rev 1640) @@ -164,6 +164,7 @@ typedef std::hash_set<group_type> groups_container_type; typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; + typedef std::hash_map<group_type, gvtime_type> snd_delta_vtime_t; void add_group( group_type g ) { groups.insert(g); } @@ -174,10 +175,15 @@ bool deliver( const VTmess& ev ); bool deliver_delayed( const VTmess& ev ); - stem::addr_type addr; // stem address of object - delta_vtime_type lvt; // last seen VT of neighbours - gvtime vt; // VT of object + stem::addr_type addr; // stem address of object + delta_vtime_type lvt; // last recieve VT from neighbours + snd_delta_vtime_t svt; // last send VT to neighbours + gvtime vt; // VT of object + + private: groups_container_type groups; // member of groups + + public: // delay pool should be here typedef std::pair<int,stem::Event_base<VTmess>*> delay_item_t; typedef std::list<delay_item_t> dpool_t; @@ -202,7 +208,8 @@ void VTDispatch( const stem::Event_base<VTmess>& ); - void VTSend( const stem::Event& e ); + void VTSend( const stem::Event& e, group_type ); + void Subscribe( stem::addr_type, oid_type, group_type ); private: typedef std::hash_map<oid_type, vtime_obj_rec> vt_map_type; @@ -211,6 +218,8 @@ // gid_type -> (oid_type, oid_type, ...) // in our case we can use gid = hi bits | oid + + void VTDispatch_( const stem::Event_base<VTmess>&, const std::pair<gid_map_type::const_iterator,gid_map_type::const_iterator>& ); vt_map_type vtmap; gid_map_type grmap; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-26 04:44:47
|
Revision: 1641 http://complement.svn.sourceforge.net/complement/?rev=1641&view=rev Author: complement Date: 2007-07-25 21:44:44 -0700 (Wed, 25 Jul 2007) Log Message: ----------- split unit tests; looks like VTDispatcher work; Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/Makefile.inc trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Added Paths: ----------- trunk/complement/explore/test/virtual_time/test/VTmess_core.cc trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc trunk/complement/explore/test/virtual_time/test/vt_object.cc trunk/complement/explore/test/virtual_time/test/vt_operations.cc trunk/complement/explore/test/virtual_time/test/vt_operations.h Modified: trunk/complement/explore/test/virtual_time/test/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-07-25 17:42:59 UTC (rev 1640) +++ trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-07-26 04:44:44 UTC (rev 1641) @@ -3,6 +3,10 @@ PRGNAME = ut_vtime SRC_CC = ../vtime.cc \ - unit_test.cc + unit_test.cc \ + vt_operations.cc \ + VTmess_core.cc \ + vt_object.cc \ + vt_dispatch.cc Added: trunk/complement/explore/test/virtual_time/test/VTmess_core.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/VTmess_core.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/VTmess_core.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -0,0 +1,144 @@ +// -*- C++ -*- Time-stamp: <07/07/25 22:06:40 ptr> + +#include "vt_operations.h" + +#include <iostream> +#include <vtime.h> + +using namespace vt; +using namespace std; + +class VTM_handler : + public stem::EventHandler +{ + public: + VTM_handler(); + VTM_handler( stem::addr_type id ); + VTM_handler( stem::addr_type id, const char *info ); + ~VTM_handler(); + + void handlerE( const stem::Event_base<VTmess>& ); + void handlerV( const VTmess& ); + + void wait(); + + stem::code_type code; + oid_type src; + gvtime gvt; + group_type grp; + std::string mess; + + private: + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( VTM_handler, stem::EventHandler ); +}; + +#define VT_MESS 0x1201 + +VTM_handler::VTM_handler() : + EventHandler() +{ + cnd.set( false ); +} + +VTM_handler::VTM_handler( stem::addr_type id ) : + EventHandler( id ) +{ + cnd.set( false ); +} + +VTM_handler::VTM_handler( stem::addr_type id, const char *info ) : + EventHandler( id, info ) +{ + cnd.set( false ); +} + +VTM_handler::~VTM_handler() +{ + // cnd.wait(); +} + +void VTM_handler::handlerE( const stem::Event_base<VTmess>& ev ) +{ + code = ev.value().code; + src = ev.value().src; + gvt = ev.value().gvt; + grp = ev.value().grp; + mess = ev.value().mess; + + PushState( 1 ); + cnd.set( true ); +} + +void VTM_handler::handlerV( const VTmess& m ) +{ + code = m.code; + src = m.src; + gvt = m.gvt; + grp = m.grp; + mess = m.mess; + + PopState(); + cnd.set( true ); +} + +void VTM_handler::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +DEFINE_RESPONSE_TABLE( VTM_handler ) + EV_Event_base_T_( ST_NULL, VT_MESS, handlerE, VTmess ) + EV_T_( 1, VT_MESS, handlerV, VTmess ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::VTMess_core) +{ + VTM_handler h; + + stem::Event_base<VTmess> ev( VT_MESS ); + + ev.dest( h.self_id() ); + ev.value().code = 2; + ev.value().src = 3; + ev.value().gvt[0][0] = 1; + ev.value().gvt[0][1] = 2; + ev.value().gvt[1][0] = 3; + ev.value().gvt[1][1] = 4; + ev.value().grp = 7; + ev.value().mess = "data"; + + h.Send( ev ); + + h.wait(); + + EXAM_CHECK( h.code == 2 ); + EXAM_CHECK( h.src == 3 ); + EXAM_CHECK( h.gvt[0][0] == 1 ); + EXAM_CHECK( h.gvt[0][1] == 2 ); + EXAM_CHECK( h.gvt[1][0] == 3 ); + EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.mess == "data" ); + + ev.value().code = 3; + ev.value().mess = "more data"; + + h.Send( ev ); + + h.wait(); + + EXAM_CHECK( h.code == 3 ); + EXAM_CHECK( h.src == 3 ); + EXAM_CHECK( h.gvt[0][0] == 1 ); + EXAM_CHECK( h.gvt[0][1] == 2 ); + EXAM_CHECK( h.gvt[1][0] == 3 ); + EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.grp == 7 ); + EXAM_CHECK( h.mess == "more data" ); + + return EXAM_RESULT; +} Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-25 17:42:59 UTC (rev 1640) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -1,719 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/07/23 23:46:02 ptr> +// -*- C++ -*- Time-stamp: <07/07/25 22:14:50 ptr> -#include <exam/suite.h> +#include "vt_operations.h" -#include <boost/lexical_cast.hpp> - -#include <string> -#include <iostream> - -#include <vtime.h> - -using namespace vt; -using namespace std; - -struct vtime_operations -{ - int EXAM_DECL(vt_compare); - int EXAM_DECL(vt_add); - int EXAM_DECL(vt_diff); - int EXAM_DECL(vt_max); - - int EXAM_DECL(gvt_add); - - int EXAM_DECL(VTMess_core); - - int EXAM_DECL(vt_object); - - int EXAM_DECL(VTDispatch); -}; - -int EXAM_IMPL(vtime_operations::vt_compare) -{ - vtime_type vt1; - vtime_type vt2; - - vt1[1] = 1; - vt1[2] = 1; - - vt2[1] = 1; - vt2[2] = 1; - - EXAM_CHECK( vt1 <= vt2 ); - EXAM_CHECK( vt2 <= vt1 ); - EXAM_CHECK( vt1 >= vt2 ); - EXAM_CHECK( vt2 >= vt1 ); - - vt2[3] = 1; - - EXAM_CHECK( vt1 <= vt2 ); - EXAM_CHECK( !(vt2 <= vt1) ); - EXAM_CHECK( vt2 >= vt1 ); - - vt1.clear(); - vt2.clear(); - - vt1[1] = 1; - - vt2[1] = 1; - vt2[3] = 1; - - EXAM_CHECK( vt1 <= vt2 ); - EXAM_CHECK( !(vt2 <= vt1) ); - - vt1[2] = 1; - - EXAM_CHECK( !(vt1 <= vt2) ); - EXAM_CHECK( !(vt2 <= vt1) ); -} - -int EXAM_IMPL(vtime_operations::vt_add) -{ - vtime_type vt1; - vtime_type vt2; - vtime_type vt3; - vtime_type vt4; - - vt1[1] = 1; - vt1[2] = 1; - - vt3 = vt1 + vt2; - - EXAM_CHECK( vt1 <= vt3 ); - EXAM_CHECK( vt3 <= vt1 ); - - vt2[2] = 1; - - vt3 = vt1 + vt2; - - vt4[1] = 1; - vt4[2] = 2; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - vt4.clear(); - - vt2[3] = 1; - - vt3 = vt1 + vt2; - - vt4[1] = 1; - vt4[2] = 2; - vt4[3] = 1; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(vtime_operations::vt_diff) -{ - vtime_type vt1; - vtime_type vt2; - vtime_type vt3; - vtime_type vt4; - - vt1[1] = 1; - vt1[2] = 1; - - vt3 = vt1 - vt2; - - EXAM_CHECK( vt1 <= vt3 ); - EXAM_CHECK( vt3 <= vt1 ); - - vt2[1] = 1; - - vt3 = vt1 - vt2; - - vt4[2] = 1; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - vt2[2] = 1; - - vt4.clear(); - - vt3 = vt1 - vt2; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - vt2.clear(); - - vt2[3] = 1; - - try { - vt3 = vt1 - vt2; - EXAM_ERROR( "Virtual Times are incomparable" ); - } - catch ( const std::range_error& err ) { - EXAM_CHECK( true ); - } - - vt2.clear(); - - vt2[2] = 2; - - try { - vt3 = vt1 - vt2; - EXAM_ERROR( "Virtual Times are incomparable" ); - } - catch ( const std::range_error& err ) { - EXAM_CHECK( true ); - } - - return EXAM_RESULT; -} - -int EXAM_IMPL(vtime_operations::vt_max) -{ - vtime_type vt1; - vtime_type vt2; - vtime_type vt3; - vtime_type vt4; - - vt1[1] = 1; - vt1[2] = 1; - - vt3 = vt::max( vt1, vt2 ); - - EXAM_CHECK( vt3 <= vt1 ); - EXAM_CHECK( vt1 <= vt3 ); - - vt2[1] = 1; - - vt3 = vt::max( vt1, vt2 ); - - EXAM_CHECK( vt3 <= vt1 ); - EXAM_CHECK( vt1 <= vt3 ); - - vt2[2] = 1; - - vt3 = vt::max( vt1, vt2 ); - - EXAM_CHECK( vt3 <= vt1 ); - EXAM_CHECK( vt1 <= vt3 ); - - vt2[3] = 1; - - vt3 = vt::max( vt1, vt2 ); - - vt4[1] = 1; - vt4[2] = 1; - vt4[3] = 1; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - vt2.clear(); - - vt2[1] = 1; - vt2[2] = 2; - - vt4.clear(); - - vt3 = vt::max( vt1, vt2 ); - - vt4[1] = 1; - vt4[2] = 2; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - vt2[3] = 4; - - vt3 = vt::max( vt1, vt2 ); - - vt4[3] = 4; - - EXAM_CHECK( vt3 <= vt4 ); - EXAM_CHECK( vt4 <= vt3 ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(vtime_operations::gvt_add) -{ - { - gvtime_type gvt1; - gvtime_type gvt2; - - vtime_type vt1; - vtime_type vt2; - - vt1[1] = 1; - vt1[2] = 1; - - vt2[1] = 1; - vt2[2] = 1; - - gvt1[0] = vt1; - gvt2[0] = vt2; - - gvt1 += gvt2; - - EXAM_CHECK( gvt1[0][1] == 2 ); - EXAM_CHECK( gvt1[0][2] == 2 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 0 ); - EXAM_CHECK( gvt1[1][2] == 0 ); - } - { - gvtime_type gvt1; - gvtime_type gvt2; - - vtime_type vt1; - vtime_type vt2; - - vt1[1] = 1; - vt1[2] = 1; - - vt2[1] = 1; - vt2[2] = 1; - - gvt1[0] = vt1; - gvt2[1] = vt2; - - gvt1 += gvt2; - - EXAM_CHECK( gvt1[0][1] == 1 ); - EXAM_CHECK( gvt1[0][2] == 1 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 1 ); - EXAM_CHECK( gvt1[1][2] == 1 ); - } - { - gvtime_type gvt1; - - vtime_type vt1; - vtime_type vt2; - - vt1[1] = 1; - vt1[2] = 1; - - vt2[1] = 1; - vt2[2] = 1; - - gvt1[0] = vt1; - - gvt1 += make_pair( 1, vt2 ); - - EXAM_CHECK( gvt1[0][1] == 1 ); - EXAM_CHECK( gvt1[0][2] == 1 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 1 ); - EXAM_CHECK( gvt1[1][2] == 1 ); - } - - return EXAM_RESULT; -} - -class VTM_handler : - public stem::EventHandler -{ - public: - VTM_handler(); - VTM_handler( stem::addr_type id ); - VTM_handler( stem::addr_type id, const char *info ); - ~VTM_handler(); - - void handlerE( const stem::Event_base<VTmess>& ); - void handlerV( const VTmess& ); - - void wait(); - - stem::code_type code; - oid_type src; - gvtime gvt; - group_type grp; - std::string mess; - - private: - xmt::condition cnd; - - DECLARE_RESPONSE_TABLE( VTM_handler, stem::EventHandler ); -}; - -#define VT_MESS 0x1201 - -VTM_handler::VTM_handler() : - EventHandler() -{ - cnd.set( false ); -} - -VTM_handler::VTM_handler( stem::addr_type id ) : - EventHandler( id ) -{ - cnd.set( false ); -} - -VTM_handler::VTM_handler( stem::addr_type id, const char *info ) : - EventHandler( id, info ) -{ - cnd.set( false ); -} - -VTM_handler::~VTM_handler() -{ - // cnd.wait(); -} - -void VTM_handler::handlerE( const stem::Event_base<VTmess>& ev ) -{ - code = ev.value().code; - src = ev.value().src; - gvt = ev.value().gvt; - grp = ev.value().grp; - mess = ev.value().mess; - - PushState( 1 ); - cnd.set( true ); -} - -void VTM_handler::handlerV( const VTmess& m ) -{ - code = m.code; - src = m.src; - gvt = m.gvt; - grp = m.grp; - mess = m.mess; - - PopState(); - cnd.set( true ); -} - -void VTM_handler::wait() -{ - cnd.try_wait(); - - cnd.set( false ); -} - -DEFINE_RESPONSE_TABLE( VTM_handler ) - EV_Event_base_T_( ST_NULL, VT_MESS, handlerE, VTmess ) - EV_T_( 1, VT_MESS, handlerV, VTmess ) -END_RESPONSE_TABLE - -int EXAM_IMPL(vtime_operations::VTMess_core) -{ - VTM_handler h; - - stem::Event_base<VTmess> ev( VT_MESS ); - - ev.dest( h.self_id() ); - ev.value().code = 2; - ev.value().src = 3; - ev.value().gvt[0][0] = 1; - ev.value().gvt[0][1] = 2; - ev.value().gvt[1][0] = 3; - ev.value().gvt[1][1] = 4; - ev.value().grp = 7; - ev.value().mess = "data"; - - h.Send( ev ); - - h.wait(); - - EXAM_CHECK( h.code == 2 ); - EXAM_CHECK( h.src == 3 ); - EXAM_CHECK( h.gvt[0][0] == 1 ); - EXAM_CHECK( h.gvt[0][1] == 2 ); - EXAM_CHECK( h.gvt[1][0] == 3 ); - EXAM_CHECK( h.gvt[1][1] == 4 ); - EXAM_CHECK( h.grp == 7 ); - EXAM_CHECK( h.mess == "data" ); - - ev.value().code = 3; - ev.value().mess = "more data"; - - h.Send( ev ); - - h.wait(); - - EXAM_CHECK( h.code == 3 ); - EXAM_CHECK( h.src == 3 ); - EXAM_CHECK( h.gvt[0][0] == 1 ); - EXAM_CHECK( h.gvt[0][1] == 2 ); - EXAM_CHECK( h.gvt[1][0] == 3 ); - EXAM_CHECK( h.gvt[1][1] == 4 ); - EXAM_CHECK( h.grp == 7 ); - EXAM_CHECK( h.mess == "more data" ); - - return EXAM_RESULT; -} - -int EXAM_IMPL(vtime_operations::vt_object) -{ - vtime_obj_rec ob; - - const group_type gr0 = 0; - const group_type gr1 = 1; - const group_type gr2 = 2; - const oid_type obj0 = 0; - const oid_type obj1 = 1; - const oid_type obj2 = 2; - - ob.add_group( gr0 ); - // ob.add_group_member( gr0, obj0 ); - // ob.add_group_member( gr0, obj1 ); - // ob.add_group_member( gr0, obj2 ); - - // gvtime gvt; - // gvt[gr0][obj1] = 1; - - VTmess mess; - VTmess mess_bad; - - mess_bad.code = mess.code = 1; - mess_bad.src = mess.src = obj1; - mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] = 1; - mess_bad.grp = mess.grp = gr0; - mess_bad.mess = mess.mess = "data"; - - // cerr << ob.vt[gr0] << endl; - // cerr << "===========\n"; - - vtime chk; - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - EXAM_REQUIRE( ob.deliver(mess) ); // ack - - chk[obj1] += 1; - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - // cerr << ob.vt[gr0] << endl; - // cerr << "===========\n"; - - ++mess.gvt[gr0][obj1]; - - EXAM_REQUIRE( ob.deliver(mess) ); // ack - - chk[obj1] += 1; - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - ++mess.gvt[gr0][obj1]; - - try { - EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: too old (out of order) - EXAM_ERROR( "exception expected" ); - } - catch ( const out_of_range& ) { - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - } - - mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] + 1; - - EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: too new (out of order) - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - EXAM_REQUIRE( ob.deliver(mess) ); // ack - - chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; - - // cerr << ob.vt[gr0] << endl; - // cerr << "===========\n"; - - // ---- - - VTmess mess2; - - mess2.code = 1; - mess2.src = obj2; - mess2.gvt[gr0][obj2] = 1; - mess2.grp = gr0; - mess2.mess = "data"; - - mess_bad.gvt[gr0][obj2] = 1; - - EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: obj0 don't seen mess from obj2, but obj1 seen mess from obj2 - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - EXAM_REQUIRE( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 - - chk[obj2] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - ++mess2.gvt[gr0][obj2]; - - EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now obj0 and obj1 sync dependency from obj2 - - // cerr << ob.vt[gr0] << endl; - // cerr << "===========\n"; - - chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - - mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; - mess.gvt[gr0][obj2] = 1; - mess_bad.gvt[gr0][obj2] = 0; - - // ---- - - ob.add_group( gr1 ); - // ob.add_group_member( gr1, obj0 ); - // ob.add_group_member( gr1, obj1 ); - // ob.add_group_member( gr1, obj2 ); - - mess_bad.grp = gr2; - - vtime chk1; - - try { - EXAM_CHECK( ob.deliver(mess_bad) ); // nac: ob not member of group gr2 - EXAM_ERROR( "exception expected" ); - } - catch ( const domain_error& ) { - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr2]) && (chk1 >= ob.vt[gr2]) ); - } - - // ---- - - mess_bad.grp = gr0; - mess_bad.gvt[gr1][obj2] = 1; - - EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: obj1 recieve new event in group gr1 from obj2 - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); - - // cerr << "===========\n"; - // cerr << ob.vt[gr0] << endl; - // cerr << "===========\n"; - - VTmess mess3; - - mess3.code = 1; - mess3.src = obj2; - mess3.gvt[gr1][obj2] = 1; - mess3.grp = gr1; - mess3.mess = "data"; - - EXAM_REQUIRE( ob.deliver(mess3) ); // ack: see event from obj2 in group gr1 - - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - chk1[obj2] += 1; - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); - - ++mess3.gvt[gr1][obj2]; - - // cerr << "===========\n"; - // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr0] << endl; - // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr1] << endl; - // cerr << "===========\n"; - - // cerr << "2 ==========\n"; - EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now we know about event in group gr1 - - chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); - - return EXAM_RESULT; -} - - -class Dummy : - public stem::EventHandler -{ - public: - Dummy(); - Dummy( stem::addr_type id ); - Dummy( stem::addr_type id, const char *info ); - ~Dummy(); - - void handler( const stem::Event& ); - - void wait(); - std::string msg; - - private: - xmt::condition cnd; - - DECLARE_RESPONSE_TABLE( Dummy, stem::EventHandler ); -}; - -#define VT_MESS2 0x1202 - -Dummy::Dummy() : - EventHandler() -{ - cnd.set( false ); -} - -Dummy::Dummy( stem::addr_type id ) : - EventHandler( id ) -{ - cnd.set( false ); -} - -Dummy::Dummy( stem::addr_type id, const char *info ) : - EventHandler( id, info ) -{ - cnd.set( false ); -} - -Dummy::~Dummy() -{ - // cnd.wait(); -} - -void Dummy::handler( const stem::Event& ev ) -{ - msg = ev.value(); - - cnd.set( true ); -} - -void Dummy::wait() -{ - cnd.try_wait(); - - cnd.set( false ); -} - -DEFINE_RESPONSE_TABLE( Dummy ) - EV_EDS( ST_NULL, VT_MESS2, handler ) -END_RESPONSE_TABLE - -int EXAM_IMPL(vtime_operations::VTDispatch) -{ - vt::VTDispatcher dsp; - Dummy dummy1; - Dummy dummy2; - - dsp.Subscribe( dummy1.self_id(), 1, 0 ); - dsp.Subscribe( dummy2.self_id(), 2, 0 ); - - stem::Event ev( VT_MESS2 ); - ev.src( dummy1.self_id() ); - - ev.value() = "hello"; - - dsp.VTSend( ev, 0 ); - - dummy2.wait(); - - EXAM_CHECK( dummy2.msg == "hello" ); - EXAM_CHECK( dummy1.msg == "" ); - - return EXAM_RESULT; -} - - int EXAM_DECL(vtime_test_suite); int EXAM_IMPL(vtime_test_suite) @@ -732,7 +20,8 @@ t.add( &vtime_operations::VTMess_core, vt_oper, "VTmess core transfer", tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); - t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ); + t.add( &vtime_operations::VTDispatch, vt_oper, "VTDispatch", + t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ) ); return t.girdle(); } Added: trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -0,0 +1,102 @@ +// -*- C++ -*- Time-stamp: <07/07/25 23:12:24 ptr> + +#include "vt_operations.h" + +// #include <boost/lexical_cast.hpp> + +#include <iostream> +#include <vtime.h> + +using namespace vt; +using namespace std; + +class Dummy : + public stem::EventHandler +{ + public: + Dummy(); + Dummy( stem::addr_type id ); + Dummy( stem::addr_type id, const char *info ); + ~Dummy(); + + void handler( const stem::Event& ); + + void wait(); + std::string msg; + + private: + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( Dummy, stem::EventHandler ); +}; + +#define VT_MESS2 0x1202 + +Dummy::Dummy() : + EventHandler() +{ + cnd.set( false ); +} + +Dummy::Dummy( stem::addr_type id ) : + EventHandler( id ) +{ + cnd.set( false ); +} + +Dummy::Dummy( stem::addr_type id, const char *info ) : + EventHandler( id, info ) +{ + cnd.set( false ); +} + +Dummy::~Dummy() +{ + // cnd.wait(); +} + +void Dummy::handler( const stem::Event& ev ) +{ + msg = ev.value(); + + cnd.set( true ); +} + +void Dummy::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +DEFINE_RESPONSE_TABLE( Dummy ) + EV_EDS( ST_NULL, VT_MESS2, handler ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::VTDispatch) +{ + vt::VTDispatcher dsp; + Dummy dummy1; + Dummy dummy2; + Dummy dummy3; + + dsp.Subscribe( dummy1.self_id(), 1, 0 ); + dsp.Subscribe( dummy2.self_id(), 2, 0 ); + dsp.Subscribe( dummy3.self_id(), 3, 0 ); + + stem::Event ev( VT_MESS2 ); + ev.src( dummy1.self_id() ); + + ev.value() = "hello"; + + dsp.VTSend( ev, 0 ); + + dummy2.wait(); + dummy3.wait(); + + EXAM_CHECK( dummy3.msg == "hello" ); + EXAM_CHECK( dummy2.msg == "hello" ); + EXAM_CHECK( dummy1.msg == "" ); + + return EXAM_RESULT; +} Added: trunk/complement/explore/test/virtual_time/test/vt_object.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_object.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_object.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -0,0 +1,190 @@ +// -*- C++ -*- Time-stamp: <07/07/25 22:09:32 ptr> + +#include "vt_operations.h" + +// #include <boost/lexical_cast.hpp> + +#include <iostream> +#include <vtime.h> + +using namespace vt; +using namespace std; + +int EXAM_IMPL(vtime_operations::vt_object) +{ + detail::vtime_obj_rec ob; + + const group_type gr0 = 0; + const group_type gr1 = 1; + const group_type gr2 = 2; + const oid_type obj0 = 0; + const oid_type obj1 = 1; + const oid_type obj2 = 2; + + ob.add_group( gr0 ); + // ob.add_group_member( gr0, obj0 ); + // ob.add_group_member( gr0, obj1 ); + // ob.add_group_member( gr0, obj2 ); + + // gvtime gvt; + // gvt[gr0][obj1] = 1; + + VTmess mess; + VTmess mess_bad; + + mess_bad.code = mess.code = 1; + mess_bad.src = mess.src = obj1; + mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] = 1; + mess_bad.grp = mess.grp = gr0; + mess_bad.mess = mess.mess = "data"; + + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + vtime chk; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + EXAM_REQUIRE( ob.deliver(mess) ); // ack + + chk[obj1] += 1; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + ++mess.gvt[gr0][obj1]; + + EXAM_REQUIRE( ob.deliver(mess) ); // ack + + chk[obj1] += 1; + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + ++mess.gvt[gr0][obj1]; + + try { + EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: too old (out of order) + EXAM_ERROR( "exception expected" ); + } + catch ( const out_of_range& ) { + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + } + + mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] + 1; + + EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: too new (out of order) + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + EXAM_REQUIRE( ob.deliver(mess) ); // ack + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; + + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + // ---- + + VTmess mess2; + + mess2.code = 1; + mess2.src = obj2; + mess2.gvt[gr0][obj2] = 1; + mess2.grp = gr0; + mess2.mess = "data"; + + mess_bad.gvt[gr0][obj2] = 1; + + EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: obj0 don't seen mess from obj2, but obj1 seen mess from obj2 + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + EXAM_REQUIRE( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 + + chk[obj2] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + ++mess2.gvt[gr0][obj2]; + + EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now obj0 and obj1 sync dependency from obj2 + + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + + mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; + mess.gvt[gr0][obj2] = 1; + mess_bad.gvt[gr0][obj2] = 0; + + // ---- + + ob.add_group( gr1 ); + // ob.add_group_member( gr1, obj0 ); + // ob.add_group_member( gr1, obj1 ); + // ob.add_group_member( gr1, obj2 ); + + mess_bad.grp = gr2; + + vtime chk1; + + try { + EXAM_CHECK( ob.deliver(mess_bad) ); // nac: ob not member of group gr2 + EXAM_ERROR( "exception expected" ); + } + catch ( const domain_error& ) { + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr2]) && (chk1 >= ob.vt[gr2]) ); + } + + // ---- + + mess_bad.grp = gr0; + mess_bad.gvt[gr1][obj2] = 1; + + EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: obj1 recieve new event in group gr1 from obj2 + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + + // cerr << "===========\n"; + // cerr << ob.vt[gr0] << endl; + // cerr << "===========\n"; + + VTmess mess3; + + mess3.code = 1; + mess3.src = obj2; + mess3.gvt[gr1][obj2] = 1; + mess3.grp = gr1; + mess3.mess = "data"; + + EXAM_REQUIRE( ob.deliver(mess3) ); // ack: see event from obj2 in group gr1 + + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + chk1[obj2] += 1; + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + + ++mess3.gvt[gr1][obj2]; + + // cerr << "===========\n"; + // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr0] << endl; + // cerr << /* ob.vt[gr0] */ mess_bad.gvt[gr1] << endl; + // cerr << "===========\n"; + + // cerr << "2 ==========\n"; + EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now we know about event in group gr1 + + chk[obj1] += 1; + EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + + return EXAM_RESULT; +} Added: trunk/complement/explore/test/virtual_time/test/vt_operations.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_operations.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_operations.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -0,0 +1,300 @@ +// -*- C++ -*- Time-stamp: <07/07/25 23:34:58 ptr> + +#include "vt_operations.h" + +// #include <boost/lexical_cast.hpp> + +#include <iostream> +#include <vtime.h> + +using namespace vt; +using namespace std; + +int EXAM_IMPL(vtime_operations::vt_compare) +{ + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( vt2 <= vt1 ); + EXAM_CHECK( vt1 >= vt2 ); + EXAM_CHECK( vt2 >= vt1 ); + + vt2[3] = 1; + + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( !(vt2 <= vt1) ); + EXAM_CHECK( vt2 >= vt1 ); + + vt1.clear(); + vt2.clear(); + + vt1[1] = 1; + + vt2[1] = 1; + vt2[3] = 1; + + EXAM_CHECK( vt1 <= vt2 ); + EXAM_CHECK( !(vt2 <= vt1) ); + + vt1[2] = 1; + + EXAM_CHECK( !(vt1 <= vt2) ); + EXAM_CHECK( !(vt2 <= vt1) ); +} + +int EXAM_IMPL(vtime_operations::vt_add) +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1[1] = 1; + vt1[2] = 1; + + vt3 = vt1 + vt2; + + EXAM_CHECK( vt1 <= vt3 ); + EXAM_CHECK( vt3 <= vt1 ); + + vt2[2] = 1; + + vt3 = vt1 + vt2; + + vt4[1] = 1; + vt4[2] = 2; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + vt4.clear(); + + vt2[3] = 1; + + vt3 = vt1 + vt2; + + vt4[1] = 1; + vt4[2] = 2; + vt4[3] = 1; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(vtime_operations::vt_diff) +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1[1] = 1; + vt1[2] = 1; + + vt3 = vt1 - vt2; + + EXAM_CHECK( vt1 <= vt3 ); + EXAM_CHECK( vt3 <= vt1 ); + + vt2[1] = 1; + + vt3 = vt1 - vt2; + + vt4[2] = 1; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + vt2[2] = 1; + + vt4.clear(); + + vt3 = vt1 - vt2; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + vt2.clear(); + + vt2[3] = 1; + + try { + vt3 = vt1 - vt2; + EXAM_ERROR( "Virtual Times are incomparable" ); + } + catch ( const std::range_error& err ) { + EXAM_CHECK( true ); + } + + vt2.clear(); + + vt2[2] = 2; + + try { + vt3 = vt1 - vt2; + EXAM_ERROR( "Virtual Times are incomparable" ); + } + catch ( const std::range_error& err ) { + EXAM_CHECK( true ); + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(vtime_operations::vt_max) +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1[1] = 1; + vt1[2] = 1; + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); + + vt2[1] = 1; + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); + + vt2[2] = 1; + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + EXAM_CHECK( vt3 <= vt1 ); + EXAM_CHECK( vt1 <= vt3 ); + + vt2[3] = 1; + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + vt4[1] = 1; + vt4[2] = 1; + vt4[3] = 1; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + vt2.clear(); + + vt2[1] = 1; + vt2[2] = 2; + + vt4.clear(); + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + vt4[1] = 1; + vt4[2] = 2; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + vt2[3] = 4; + + vt3 = vt1; + vt::sup( vt3, vt2 ); + + vt4[3] = 4; + + EXAM_CHECK( vt3 <= vt4 ); + EXAM_CHECK( vt4 <= vt3 ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(vtime_operations::gvt_add) +{ + { + gvtime_type gvt1; + gvtime_type gvt2; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + gvt2[0] = vt2; + + gvt1 += gvt2; + + EXAM_CHECK( gvt1[0][1] == 2 ); + EXAM_CHECK( gvt1[0][2] == 2 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 0 ); + EXAM_CHECK( gvt1[1][2] == 0 ); + } + { + gvtime_type gvt1; + gvtime_type gvt2; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + gvt2[1] = vt2; + + gvt1 += gvt2; + + EXAM_CHECK( gvt1[0][1] == 1 ); + EXAM_CHECK( gvt1[0][2] == 1 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 1 ); + EXAM_CHECK( gvt1[1][2] == 1 ); + } + { + gvtime_type gvt1; + + vtime_type vt1; + vtime_type vt2; + + vt1[1] = 1; + vt1[2] = 1; + + vt2[1] = 1; + vt2[2] = 1; + + gvt1[0] = vt1; + + gvt1 += make_pair( 1, vt2 ); + + EXAM_CHECK( gvt1[0][1] == 1 ); + EXAM_CHECK( gvt1[0][2] == 1 ); + EXAM_CHECK( gvt1[0][0] == 0 ); + EXAM_CHECK( gvt1[1][1] == 1 ); + EXAM_CHECK( gvt1[1][2] == 1 ); + } + + return EXAM_RESULT; +} Added: trunk/complement/explore/test/virtual_time/test/vt_operations.h =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_operations.h (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_operations.h 2007-07-26 04:44:44 UTC (rev 1641) @@ -0,0 +1,24 @@ +// -*- C++ -*- Time-stamp: <07/07/25 22:01:43 ptr> + +#ifndef __vt_operations_h +#define __vt_operations_h + +#include <exam/suite.h> + +struct vtime_operations +{ + int EXAM_DECL(vt_compare); + int EXAM_DECL(vt_add); + int EXAM_DECL(vt_diff); + int EXAM_DECL(vt_max); + + int EXAM_DECL(gvt_add); + + int EXAM_DECL(VTMess_core); + + int EXAM_DECL(vt_object); + + int EXAM_DECL(VTDispatch); +}; + +#endif // __vt_operations_h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-25 17:42:59 UTC (rev 1640) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 04:44:44 UTC (rev 1641) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/25 10:22:27 ptr> +// -*- C++ -*- Time-stamp: <07/07/25 23:38:25 ptr> #include "vtime.h" @@ -201,6 +201,7 @@ return l; } +#if 0 // template <> vtime_type max( const vtime_type& l, const vtime_type& r ) { @@ -211,6 +212,7 @@ } return tmp; } +#endif vtime_type& sup( vtime_type& l, const vtime_type& r ) { @@ -221,6 +223,7 @@ } +#if 0 // template <> vtime max( const vtime& l, const vtime& r ) { @@ -231,6 +234,7 @@ } return tmp; } +#endif vtime& sup( vtime& l, const vtime& r ) { @@ -302,12 +306,10 @@ return *this; } +namespace detail { + bool vtime_obj_rec::deliver( const VTmess& m ) { - // cout << self_id() << " " << ev.value().mess << endl; - - // cout << ev.value().gvt.gvt << endl; - if ( order_correct( m ) ) { lvt[m.src] += m.gvt.gvt; lvt[m.src][m.grp][m.src] = vt.gvt[m.grp][m.src] + 1; @@ -321,10 +323,6 @@ bool vtime_obj_rec::deliver_delayed( const VTmess& m ) { - // cout << self_id() << " " << ev.value().mess << endl; - - // cout << ev.value().gvt.gvt << endl; - if ( order_correct_delayed( m ) ) { lvt[m.src] += m.gvt.gvt; lvt[m.src][m.grp][m.src] = vt.gvt[m.grp][m.src] + 1; @@ -401,6 +399,8 @@ return true; } +} // namespace detail + void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) { VTDispatch_( m, grmap.equal_range( m.value().grp ) ); @@ -408,6 +408,8 @@ void VTDispatcher::VTDispatch_( const stem::Event_base<VTmess>& m, const std::pair<gid_map_type::const_iterator,gid_map_type::const_iterator>& range ) { + typedef detail::vtime_obj_rec::dpool_t dpool_t; + for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { vt_map_type::iterator i = vtmap.find( o->second ); if ( i == vtmap.end() || i->second.addr == m.src() ) { // not for nobody and not for self @@ -425,7 +427,7 @@ bool more; do { more = false; - for ( vtime_obj_rec::dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { + for ( dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { if ( i->second.deliver_delayed( j->second->value() ) ) { stem::Event evd( j->second->value().code ); evd.dest(i->second.addr); @@ -473,12 +475,12 @@ } } - // Error: not group member? + throw domain_error( "VT object not member of group" ); // Error: not group member } void VTDispatcher::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) { - vtime_obj_rec& r = vtmap[oid]; + detail::vtime_obj_rec& r = vtmap[oid]; r.addr = addr; r.add_group( grp ); @@ -486,7 +488,6 @@ } DEFINE_RESPONSE_TABLE( VTDispatcher ) - // EV_T_( ST_NULL, MESS, VTDispatch, VTmess ) EV_Event_base_T_( ST_NULL, MESS, VTDispatch, VTmess ) END_RESPONSE_TABLE @@ -565,93 +566,6 @@ ((Init *)Init_buf)->~Init(); } -void Proc::mess( const stem::Event_base<VTmess>& ev ) -{ - cout << self_id() << " " << ev.value().mess << endl; - - // cout << ev.value().gvt.gvt << endl; - - if ( order_correct( ev ) ) { - cout << "Order correct" << endl; - lvt[ev.src()] += ev.value().gvt.gvt; - lvt[ev.src()][ev.value().grp][ev.src()] = vt.gvt[ev.value().grp][ev.src()] + 1; - vt.gvt[ev.value().grp] = vt::max( vt.gvt[ev.value().grp], lvt[ev.src()][ev.value().grp] ); - cout << vt.gvt << endl; - } else { - cout << "Order not correct" << endl; - } -} - -bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) -{ - gvtime gvt( ev.value().gvt ); - - if ( vt.gvt[ev.value().grp][ev.src()] + 1 != gvt[ev.value().grp][ev.src()] ) { - cerr << "1" << endl; - cerr << vt.gvt[ev.value().grp][ev.src()] << "\n" - << gvt[ev.value().grp][ev.src()] - << endl; - return false; - } - - vtime xvt = lvt[ev.src()][ev.value().grp] + gvt[ev.value().grp]; - xvt[ev.src()] = 0; - - if ( !(xvt <= vt[ev.value().grp]) ) { - cerr << "2" << endl; - cerr << xvt << "\n\n" - << vt[ev.value().grp] << endl; - return false; - } - - for ( groups_container_type::const_iterator l = groups.begin(); l != groups.end(); ++l ) { - if ( *l != ev.value().grp ) { - xvt = lvt[ev.src()][*l] + gvt[*l]; - if ( !(xvt <= vt[*l]) ) { - cerr << "3" << endl; - cerr << "group " << *l << xvt << "\n\n" - << vt[*l] << endl; - return false; - } - } - } - - return true; -} - -void Proc::SendVC( group_type g, const std::string& mess ) -{ - try { - stem::Event_base<VTmess> m( MESS ); - m.value().mess = mess; - m.value().grp = g; - - vtime_type& gr = vt[g].vt; - - gr[self_id()] += 1; - - for ( vtime_type::const_iterator p = gr.begin(); p != gr.end(); ++p ) { - if ( p->first != self_id() ) { - m.dest( p->first ); - - m.value().gvt.gvt = vt.gvt - lvt[p->first]; - m.value().gvt.gvt[g][self_id()] = gr[self_id()]; - - lvt[p->first] = vt.gvt; - - Send(m); - } - } - } - catch ( const range_error& err ) { - cerr << err.what() << endl; - } -} - -DEFINE_RESPONSE_TABLE( Proc ) - EV_Event_base_T_( ST_NULL, MESS, mess, VTmess ) -END_RESPONSE_TABLE - } // namespace vt namespace std { Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-25 17:42:59 UTC (rev 1640) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 04:44:44 UTC (rev 1641) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/25 09:07:25 ptr> +// -*- C++ -*- Time-stamp: <07/07/25 23:30:52 ptr> #ifndef __vtime_h #define __vtime_h @@ -24,9 +24,6 @@ typedef uint32_t group_type; typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; -// typedef std::pair<oid_type, vtime_unit_type> vtime_proc_type; -// typedef std::list<vtime_proc_type> vtime_type; - bool operator <=( const vtime_type& l, const vtime_type& r ); inline bool operator >=( const vtime_type& l, const vtime_type& r ) { return r <= l; } @@ -34,7 +31,7 @@ vtime_type operator +( const vtime_type& l, const vtime_type& r ); vtime_type& operator +=( vtime_type& l, const vtime_type& r ); -vtime_type max( const vtime_type& l, const vtime_type& r ); +// vt::vtime_type max( const vt::vtime_type& l, const vt::vtime_type& r ); vtime_type& sup( vtime_type& l, const vtime_type& r ); struct vtime : @@ -91,7 +88,7 @@ }; -vtime max( const vtime& l, const vtime& r ); +// vtime max( const vtime& l, const vtime& r ); vtime& sup( vtime& l, const vtime& r ); // typedef std::pair<group_type, vtime> vtime_group_type; @@ -158,6 +155,8 @@ std::string mess; }; +namespace detail { + class vtime_obj_rec { public: @@ -195,6 +194,8 @@ bool order_correct_delayed( const VTmess& ); }; +} // namespace detail + class VTDispatcher : public stem::EventHandler { @@ -211,8 +212,9 @@ void VTSend( const stem::Event& e, group_type ); void Subscribe( stem::addr_type, oid_type, group_type ); - private: - typedef std::hash_map<oid_type, vtime_obj_rec> vt_map_type; + private: + + typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::hash_multimap<group_type, oid_type> gid_map_type; // oid_type map_gid( group_type ); // gid_type -> (oid_type, oid_type, ...) @@ -260,43 +262,6 @@ static class VTDispatcher *_vtdsp; }; - -class Proc : - public stem::EventHandler -{ - public: - Proc() - { } - Proc( stem::addr_type id ) : - stem::EventHandler( id ) - { } - - void add_group( group_type g ) - { groups.push_back( g ); } - - void add_group_member( group_type g, oid_type p ) - { vt[g][p]; } - - void SendVC( group_type, const std::string& mess ); - - void mess( const stem::Event_base<VTmess>& ); - - typedef std::list<group_type> groups_container_type; - - private: - - bool order_correct( const stem::Event_base<VTmess>& ); - - typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; - - delta_vtime_type lvt; - gvtime vt; - groups_container_type groups; - - - DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); -}; - #define MESS 0x300 } // namespace vt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-26 06:32:17
|
Revision: 1642 http://complement.svn.sourceforge.net/complement/?rev=1642&view=rev Author: complement Date: 2007-07-25 23:32:14 -0700 (Wed, 25 Jul 2007) Log Message: ----------- store VT stamp for sended events per-object, not per-group (to allow individual repeats, restore and gossip in the future) Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 04:44:44 UTC (rev 1641) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 06:32:14 UTC (rev 1642) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/25 23:38:25 ptr> +// -*- C++ -*- Time-stamp: <07/07/26 10:28:55 ptr> #include "vtime.h" @@ -403,48 +403,19 @@ void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) { - VTDispatch_( m, grmap.equal_range( m.value().grp ) ); -} + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( m.value().grp ); -void VTDispatcher::VTDispatch_( const stem::Event_base<VTmess>& m, const std::pair<gid_map_type::const_iterator,gid_map_type::const_iterator>& range ) -{ - typedef detail::vtime_obj_rec::dpool_t dpool_t; - - for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { - vt_map_type::iterator i = vtmap.find( o->second ); + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); if ( i == vtmap.end() || i->second.addr == m.src() ) { // not for nobody and not for self continue; } try { // check local or remote? i->second.addr // if remote, forward it to foreign VTDispatcher? - if ( i->second.deliver( m.value() ) ) { - stem::Event ev( m.value().code ); - ev.dest(i->second.addr); - ev.src(m.src()); - ev.value() = m.value().mess; - Forward( ev ); - bool more; - do { - more = false; - for ( dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { - if ( i->second.deliver_delayed( j->second->value() ) ) { - stem::Event evd( j->second->value().code ); - evd.dest(i->second.addr); - ev.src(m.src()); - evd.value() = j->second->value().mess; - Forward( evd ); - delete j->second; - i->second.dpool.erase( j++ ); - more = true; - } else { - ++j; - } - } - } while ( more ); - } else { - i->second.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp - } + // looks, like local source shouldn't be here? + check_and_send( i, m ); } catch ( const out_of_range& ) { } @@ -453,9 +424,43 @@ } } +void VTDispatcher::check_and_send( const vt_map_type::iterator& i, const stem::Event_base<VTmess>& m ) +{ + typedef detail::vtime_obj_rec::dpool_t dpool_t; + + if ( i->second.deliver( m.value() ) ) { + stem::Event ev( m.value().code ); + ev.dest(i->second.addr); + ev.src(m.src()); + ev.value() = m.value().mess; + Forward( ev ); + bool more; + do { + more = false; + for ( dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { + if ( i->second.deliver_delayed( j->second->value() ) ) { + stem::Event evd( j->second->value().code ); + evd.dest(i->second.addr); + ev.src(m.src()); + evd.value() = j->second->value().mess; + Forward( evd ); + delete j->second; + i->second.dpool.erase( j++ ); + more = true; + } else { + ++j; + } + } + } while ( more ); + } else { + i->second.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp + } +} + void VTDispatcher::VTSend( const stem::Event& e, group_type grp ) { - pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); + const pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( grp ); for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { vt_map_type::iterator i = vtmap.find( o->second ); @@ -465,12 +470,35 @@ m.value().code = e.code(); m.value().mess = e.value(); m.value().grp = grp; - m.value().gvt.gvt = i->second.vt.gvt - i->second.svt[grp]; // delta - m.value().gvt[grp][o->second] = ++i->second.vt.gvt[grp][o->second]; // my counter - i->second.svt[grp] = i->second.vt.gvt; // store last send VT to group // m.dest( ??? ); // local VT dispatcher? m.src( e.src() ); - VTDispatch_( m, range ); + + // This is like VTDispatch, but VT stamp in every message different, + // in accordance with individual knowlage about object's VT. + + ++i->second.vt.gvt[grp][o->second]; // my counter + + for ( gid_map_type::const_iterator g = range.first; g != range.second; ++g ) { + vt_map_type::iterator k = vtmap.find( g->second ); + if ( k == vtmap.end() || k->second.addr == m.src() ) { // not for nobody and not for self + continue; + } + try { + m.value().gvt.gvt = i->second.vt.gvt - i->second.svt[g->second]; // delta + m.value().gvt[grp][o->second] = i->second.vt.gvt[grp][o->second]; // my counter, as is, not delta + + // check local or remote? i->second.addr + // if remote, forward it to foreign VTDispatcher? + check_and_send( k, m ); + + i->second.svt[g->second] = i->second.vt.gvt; // store last send VT to obj + } + catch ( const out_of_range& ) { + } + catch ( const domain_error& ) { + } + } + return; } } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 04:44:44 UTC (rev 1641) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 06:32:14 UTC (rev 1642) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/25 23:30:52 ptr> +// -*- C++ -*- Time-stamp: <07/07/26 09:34:53 ptr> #ifndef __vtime_h #define __vtime_h @@ -163,7 +163,7 @@ typedef std::hash_set<group_type> groups_container_type; typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; - typedef std::hash_map<group_type, gvtime_type> snd_delta_vtime_t; + typedef std::hash_map<oid_type, gvtime_type> snd_delta_vtime_t; void add_group( group_type g ) { groups.insert(g); } @@ -221,7 +221,7 @@ // in our case we can use gid = hi bits | oid - void VTDispatch_( const stem::Event_base<VTmess>&, const std::pair<gid_map_type::const_iterator,gid_map_type::const_iterator>& ); + void check_and_send( const vt_map_type::iterator&, const stem::Event_base<VTmess>& ); vt_map_type vtmap; gid_map_type grmap; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-26 10:40:12
|
Revision: 1644 http://complement.svn.sourceforge.net/complement/?rev=1644&view=rev Author: complement Date: 2007-07-26 03:40:08 -0700 (Thu, 26 Jul 2007) Log Message: ----------- hide implementation details Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/vt_object.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/vt_object.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_object.cc 2007-07-26 06:34:02 UTC (rev 1643) +++ trunk/complement/explore/test/virtual_time/test/vt_object.cc 2007-07-26 10:40:08 UTC (rev 1644) @@ -43,13 +43,13 @@ vtime chk; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); EXAM_REQUIRE( ob.deliver(mess) ); // ack chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); // cerr << ob.vt[gr0] << endl; // cerr << "===========\n"; @@ -60,7 +60,7 @@ chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); ++mess.gvt[gr0][obj1]; @@ -69,19 +69,19 @@ EXAM_ERROR( "exception expected" ); } catch ( const out_of_range& ) { - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); } mess_bad.gvt[gr0][obj1] = mess.gvt[gr0][obj1] + 1; EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: too new (out of order) - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); EXAM_REQUIRE( ob.deliver(mess) ); // ack chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; @@ -102,12 +102,12 @@ EXAM_CHECK( !ob.deliver(mess_bad) ); // nac: obj0 don't seen mess from obj2, but obj1 seen mess from obj2 - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); EXAM_REQUIRE( ob.deliver(mess2) ); // ack: obj0 see first mess from obj2 chk[obj2] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); ++mess2.gvt[gr0][obj2]; @@ -117,7 +117,7 @@ // cerr << "===========\n"; chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); mess_bad.gvt[gr0][obj1] = ++mess.gvt[gr0][obj1]; mess.gvt[gr0][obj2] = 1; @@ -139,9 +139,9 @@ EXAM_ERROR( "exception expected" ); } catch ( const domain_error& ) { - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr2]) && (chk1 >= ob.vt[gr2]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob[gr1]) && (chk1 >= ob[gr1]) ); + EXAM_REQUIRE( (chk1 <= ob[gr2]) && (chk1 >= ob[gr2]) ); } // ---- @@ -151,8 +151,8 @@ EXAM_REQUIRE( !ob.deliver(mess_bad) ); // nac: obj1 recieve new event in group gr1 from obj2 - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob[gr1]) && (chk1 >= ob[gr1]) ); // cerr << "===========\n"; // cerr << ob.vt[gr0] << endl; @@ -168,9 +168,9 @@ EXAM_REQUIRE( ob.deliver(mess3) ); // ack: see event from obj2 in group gr1 - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); chk1[obj2] += 1; - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + EXAM_REQUIRE( (chk1 <= ob[gr1]) && (chk1 >= ob[gr1]) ); ++mess3.gvt[gr1][obj2]; @@ -183,8 +183,8 @@ EXAM_REQUIRE( ob.deliver(mess_bad) ); // ack: now we know about event in group gr1 chk[obj1] += 1; - EXAM_REQUIRE( (chk <= ob.vt[gr0]) && (chk >= ob.vt[gr0]) ); - EXAM_REQUIRE( (chk1 <= ob.vt[gr1]) && (chk1 >= ob.vt[gr1]) ); + EXAM_REQUIRE( (chk <= ob[gr0]) && (chk >= ob[gr0]) ); + EXAM_REQUIRE( (chk1 <= ob[gr1]) && (chk1 >= ob[gr1]) ); return EXAM_RESULT; } Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 06:34:02 UTC (rev 1643) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 10:40:08 UTC (rev 1644) @@ -399,6 +399,12 @@ return true; } +void vtime_obj_rec::delta( gvtime& vtstamp, oid_type from, oid_type to, group_type grp ) +{ + vtstamp.gvt = vt.gvt - svt[to]; // delta + vtstamp[grp][from] = vt.gvt[grp][from]; // my counter, as is, not delta +} + } // namespace detail void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) @@ -408,14 +414,14 @@ for ( ; range.first != range.second; ++range.first ) { vt_map_type::iterator i = vtmap.find( range.first->second ); - if ( i == vtmap.end() || i->second.addr == m.src() ) { // not for nobody and not for self + if ( i == vtmap.end() || i->second.stem_addr() == m.src() ) { // not for nobody and not for self continue; } try { // check local or remote? i->second.addr // if remote, forward it to foreign VTDispatcher? // looks, like local source shouldn't be here? - check_and_send( i, m ); + check_and_send( i->second, m ); } catch ( const out_of_range& ) { } @@ -424,28 +430,30 @@ } } -void VTDispatcher::check_and_send( const vt_map_type::iterator& i, const stem::Event_base<VTmess>& m ) +void VTDispatcher::check_and_send( detail::vtime_obj_rec& vt, const stem::Event_base<VTmess>& m ) { typedef detail::vtime_obj_rec::dpool_t dpool_t; - if ( i->second.deliver( m.value() ) ) { + // detail::vtime_obj_rec& vt = i->second; + + if ( vt.deliver( m.value() ) ) { stem::Event ev( m.value().code ); - ev.dest(i->second.addr); + ev.dest(vt.stem_addr()); ev.src(m.src()); ev.value() = m.value().mess; Forward( ev ); bool more; do { more = false; - for ( dpool_t::iterator j = i->second.dpool.begin(); j != i->second.dpool.end(); ) { - if ( i->second.deliver_delayed( j->second->value() ) ) { + for ( dpool_t::iterator j = vt.dpool.begin(); j != vt.dpool.end(); ) { + if ( vt.deliver_delayed( j->second->value() ) ) { stem::Event evd( j->second->value().code ); - evd.dest(i->second.addr); + evd.dest(vt.stem_addr()); ev.src(m.src()); evd.value() = j->second->value().mess; Forward( evd ); delete j->second; - i->second.dpool.erase( j++ ); + vt.dpool.erase( j++ ); more = true; } else { ++j; @@ -453,7 +461,7 @@ } } while ( more ); } else { - i->second.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp + vt.dpool.push_back( make_pair( 0, new Event_base<VTmess>(m) ) ); // 0 should be timestamp } } @@ -464,9 +472,11 @@ for ( gid_map_type::const_iterator o = range.first; o != range.second; ++o ) { vt_map_type::iterator i = vtmap.find( o->second ); - if ( i != vtmap.end() && i->second.addr == e.src() ) { // for self + if ( i != vtmap.end() && i->second.stem_addr() == e.src() ) { // for self + detail::vtime_obj_rec& vt = i->second; + const oid_type& from = o->second; stem::Event_base<VTmess> m( MESS ); - m.value().src = o->second; // oid + m.value().src = from; // oid m.value().code = e.code(); m.value().mess = e.value(); m.value().grp = grp; @@ -476,22 +486,21 @@ // This is like VTDispatch, but VT stamp in every message different, // in accordance with individual knowlage about object's VT. - ++i->second.vt.gvt[grp][o->second]; // my counter + vt.next( from, grp ); // my counter for ( gid_map_type::const_iterator g = range.first; g != range.second; ++g ) { vt_map_type::iterator k = vtmap.find( g->second ); - if ( k == vtmap.end() || k->second.addr == m.src() ) { // not for nobody and not for self + if ( k == vtmap.end() || k->second.stem_addr() == m.src() ) { // not for nobody and not for self continue; } try { - m.value().gvt.gvt = i->second.vt.gvt - i->second.svt[g->second]; // delta - m.value().gvt[grp][o->second] = i->second.vt.gvt[grp][o->second]; // my counter, as is, not delta + vt.delta( m.value().gvt, from, g->second, grp ); // check local or remote? i->second.addr // if remote, forward it to foreign VTDispatcher? - check_and_send( k, m ); + check_and_send( k->second, m ); - i->second.svt[g->second] = i->second.vt.gvt; // store last send VT to obj + vt.base_advance(g->second); // store last send VT to obj } catch ( const out_of_range& ) { } @@ -508,10 +517,7 @@ void VTDispatcher::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) { - detail::vtime_obj_rec& r = vtmap[oid]; - r.addr = addr; - r.add_group( grp ); - + vtmap[oid].add( addr, grp ); grmap.insert( make_pair(grp,oid) ); } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 06:34:02 UTC (rev 1643) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 10:40:08 UTC (rev 1644) @@ -82,9 +82,12 @@ vtime& operator +=( const vtime_type::value_type& ); vtime_type::data_type& operator[]( const vtime_type::key_type k ) - { return vt[k]; } + { return vt[k]; } + const vtime_type::data_type& operator[]( const vtime_type::key_type k ) const + { return vt[k]; } + - vtime_type vt; + mutable vtime_type vt; }; @@ -121,8 +124,10 @@ gvtime_type::data_type& operator[]( const gvtime_type::key_type k ) { return gvt[k]; } + const gvtime_type::data_type& operator[]( const gvtime_type::key_type k ) const + { return gvt[k]; } - gvtime_type gvt; + mutable gvtime_type gvt; }; struct VTmess : @@ -160,26 +165,37 @@ class vtime_obj_rec { public: - - typedef std::hash_set<group_type> groups_container_type; - typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; - typedef std::hash_map<oid_type, gvtime_type> snd_delta_vtime_t; - void add_group( group_type g ) { groups.insert(g); } + void add( stem::addr_type a, group_type g ) + { addr = a; groups.insert(g); } - // void add_group_member( group_type g, oid_type p ) - // { vt[g][p]; } + stem::addr_type stem_addr() const + { return addr; } bool deliver( const VTmess& ev ); bool deliver_delayed( const VTmess& ev ); + void next( oid_type from, group_type grp ) + { ++vt.gvt[grp][from]; /* increment my VT counter */ } + void delta( gvtime& vtstamp, oid_type from, oid_type to, group_type grp ); + void base_advance( oid_type to ) + { svt[to] = vt.gvt; /* store last sent VT to obj */ } +#ifdef __FIT_EXAM + const gvtime_type::data_type& operator[]( const gvtime_type::key_type k ) const + { return vt[k]; } +#endif + + private: + typedef std::hash_set<group_type> groups_container_type; + typedef std::hash_map<oid_type, gvtime_type> delta_vtime_type; + typedef std::hash_map<oid_type, gvtime_type> snd_delta_vtime_t; + stem::addr_type addr; // stem address of object delta_vtime_type lvt; // last recieve VT from neighbours snd_delta_vtime_t svt; // last send VT to neighbours gvtime vt; // VT of object - private: groups_container_type groups; // member of groups public: @@ -221,7 +237,7 @@ // in our case we can use gid = hi bits | oid - void check_and_send( const vt_map_type::iterator&, const stem::Event_base<VTmess>& ); + void check_and_send( detail::vtime_obj_rec&, const stem::Event_base<VTmess>& ); vt_map_type vtmap; gid_map_type grmap; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-27 04:05:11
|
Revision: 1645 http://complement.svn.sourceforge.net/complement/?rev=1645&view=rev Author: complement Date: 2007-07-26 21:04:28 -0700 (Thu, 26 Jul 2007) Log Message: ----------- add lock to VTSend in VTDispatcher Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-26 10:40:08 UTC (rev 1644) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-27 04:04:28 UTC (rev 1645) @@ -467,6 +467,10 @@ void VTDispatcher::VTSend( const stem::Event& e, group_type grp ) { + // This method not called from Dispatch, but work on the same level and in the same + // scope, so this lock (from stem::EventHandler) required here: + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + const pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = grmap.equal_range( grp ); @@ -535,10 +539,11 @@ void VTHandler::Init::__at_fork_child() { - if ( *_rcount != 0 ) { - VTHandler::_vtdsp->~VTDispatcher(); - VTHandler::_vtdsp = new( VTHandler::_vtdsp ) VTDispatcher(); - } + // VTDispatcher not start threads (at least yet), so following not required: + // if ( *_rcount != 0 ) { + // VTHandler::_vtdsp->~VTDispatcher(); + // VTHandler::_vtdsp = new( VTHandler::_vtdsp ) VTDispatcher(); + // } } void VTHandler::Init::__at_fork_parent() @@ -548,6 +553,8 @@ void VTHandler::Init::_guard( int direction ) { static xmt::recursive_mutex _init_lock; + + xmt::recursive_scoped_lock lk(_init_lock); static int _count = 0; if ( direction ) { @@ -556,7 +563,7 @@ _rcount = &_count; pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); #endif - VTHandler::_vtdsp = new VTDispatcher(); + VTHandler::_vtdsp = new VTDispatcher( 2, "vtd" ); } } else { --_count; @@ -575,12 +582,16 @@ void VTHandler::VTSend( const stem::Event& ev ) { + ev.src( self_id() ); + // _vtdsp->VTSend( ev, grp ); } VTHandler::VTHandler() : EventHandler() { new( Init_buf ) Init(); + + // _vtdsp->Subscribe( self_id(), ... , ... ); } VTHandler::VTHandler( const char *info ) : Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-26 10:40:08 UTC (rev 1644) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-27 04:04:28 UTC (rev 1645) @@ -219,24 +219,27 @@ VTDispatcher() { } + VTDispatcher( const char *info ) : + stem::EventHandler( info ) + { } + VTDispatcher( stem::addr_type id ) : stem::EventHandler( id ) { } + VTDispatcher( stem::addr_type id, const char *info ) : + stem::EventHandler( id, info ) + { } + void VTDispatch( const stem::Event_base<VTmess>& ); void VTSend( const stem::Event& e, group_type ); void Subscribe( stem::addr_type, oid_type, group_type ); private: - typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; typedef std::hash_multimap<group_type, oid_type> gid_map_type; - // oid_type map_gid( group_type ); - // gid_type -> (oid_type, oid_type, ...) - // in our case we can use gid = hi bits | oid - void check_and_send( detail::vtime_obj_rec&, const stem::Event_base<VTmess>& ); vt_map_type vtmap; @@ -248,7 +251,7 @@ class VTHandler : public stem::EventHandler { - public: + private: class Init { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-27 10:24:40
|
Revision: 1647 http://complement.svn.sourceforge.net/complement/?rev=1647&view=rev Author: complement Date: 2007-07-27 03:24:38 -0700 (Fri, 27 Jul 2007) Log Message: ----------- replace oid_type from POD to stem::gaddr_type Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/VTmess_core.cc trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc trunk/complement/explore/test/virtual_time/test/vt_object.cc trunk/complement/explore/test/virtual_time/test/vt_operations.cc trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Modified: trunk/complement/explore/test/virtual_time/test/VTmess_core.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/VTmess_core.cc 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/test/VTmess_core.cc 2007-07-27 10:24:38 UTC (rev 1647) @@ -97,17 +97,21 @@ int EXAM_IMPL(vtime_operations::VTMess_core) { + oid_type t0; t0.addr = 0; + oid_type t1; t1.addr = 1; + oid_type t3; t3.addr = 3; + VTM_handler h; stem::Event_base<VTmess> ev( VT_MESS ); ev.dest( h.self_id() ); ev.value().code = 2; - ev.value().src = 3; - ev.value().gvt[0][0] = 1; - ev.value().gvt[0][1] = 2; - ev.value().gvt[1][0] = 3; - ev.value().gvt[1][1] = 4; + ev.value().src = t3; + ev.value().gvt[0][t0] = 1; + ev.value().gvt[0][t1] = 2; + ev.value().gvt[1][t0] = 3; + ev.value().gvt[1][t1] = 4; ev.value().grp = 7; ev.value().mess = "data"; @@ -116,11 +120,11 @@ h.wait(); EXAM_CHECK( h.code == 2 ); - EXAM_CHECK( h.src == 3 ); - EXAM_CHECK( h.gvt[0][0] == 1 ); - EXAM_CHECK( h.gvt[0][1] == 2 ); - EXAM_CHECK( h.gvt[1][0] == 3 ); - EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.src == t3 ); + EXAM_CHECK( h.gvt[0][t0] == 1 ); + EXAM_CHECK( h.gvt[0][t1] == 2 ); + EXAM_CHECK( h.gvt[1][t0] == 3 ); + EXAM_CHECK( h.gvt[1][t1] == 4 ); EXAM_CHECK( h.grp == 7 ); EXAM_CHECK( h.mess == "data" ); @@ -132,11 +136,11 @@ h.wait(); EXAM_CHECK( h.code == 3 ); - EXAM_CHECK( h.src == 3 ); - EXAM_CHECK( h.gvt[0][0] == 1 ); - EXAM_CHECK( h.gvt[0][1] == 2 ); - EXAM_CHECK( h.gvt[1][0] == 3 ); - EXAM_CHECK( h.gvt[1][1] == 4 ); + EXAM_CHECK( h.src == t3 ); + EXAM_CHECK( h.gvt[0][t0] == 1 ); + EXAM_CHECK( h.gvt[0][t1] == 2 ); + EXAM_CHECK( h.gvt[1][t0] == 3 ); + EXAM_CHECK( h.gvt[1][t1] == 4 ); EXAM_CHECK( h.grp == 7 ); EXAM_CHECK( h.mess == "more data" ); Modified: trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/test/vt_dispatch.cc 2007-07-27 10:24:38 UTC (rev 1647) @@ -78,9 +78,11 @@ vt::VTDispatcher dsp; Dummy dummy1; Dummy dummy2; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; - dsp.Subscribe( dummy1.self_id(), 1, 0 ); - dsp.Subscribe( dummy2.self_id(), 2, 0 ); + dsp.Subscribe( dummy1.self_id(), t1, 0 ); + dsp.Subscribe( dummy2.self_id(), t2, 0 ); stem::Event ev( VT_MESS2 ); ev.src( dummy1.self_id() ); @@ -103,10 +105,13 @@ Dummy dummy1; Dummy dummy2; Dummy dummy3; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + oid_type t3; t3.addr = 3; - dsp.Subscribe( dummy1.self_id(), 1, 0 ); - dsp.Subscribe( dummy2.self_id(), 2, 0 ); - dsp.Subscribe( dummy3.self_id(), 3, 0 ); + dsp.Subscribe( dummy1.self_id(), t1, 0 ); + dsp.Subscribe( dummy2.self_id(), t2, 0 ); + dsp.Subscribe( dummy3.self_id(), t3, 0 ); stem::Event ev( VT_MESS2 ); ev.src( dummy1.self_id() ); Modified: trunk/complement/explore/test/virtual_time/test/vt_object.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_object.cc 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/test/vt_object.cc 2007-07-27 10:24:38 UTC (rev 1647) @@ -17,9 +17,9 @@ const group_type gr0 = 0; const group_type gr1 = 1; const group_type gr2 = 2; - const oid_type obj0 = 0; - const oid_type obj1 = 1; - const oid_type obj2 = 2; + oid_type obj0; obj0.addr = 0; + oid_type obj1; obj1.addr = 1; + oid_type obj2; obj2.addr = 2; ob.add_group( gr0 ); // ob.add_group_member( gr0, obj0 ); Modified: trunk/complement/explore/test/virtual_time/test/vt_operations.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_operations.cc 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/test/vt_operations.cc 2007-07-27 10:24:38 UTC (rev 1647) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/25 23:34:58 ptr> +// -*- C++ -*- Time-stamp: <07/07/27 10:42:55 ptr> #include "vt_operations.h" @@ -12,21 +12,26 @@ int EXAM_IMPL(vtime_operations::vt_compare) { + oid_type t0; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + oid_type t3; t3.addr = 3; + vtime_type vt1; vtime_type vt2; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; - vt2[1] = 1; - vt2[2] = 1; + vt2[t1] = 1; + vt2[t2] = 1; EXAM_CHECK( vt1 <= vt2 ); EXAM_CHECK( vt2 <= vt1 ); EXAM_CHECK( vt1 >= vt2 ); EXAM_CHECK( vt2 >= vt1 ); - vt2[3] = 1; + vt2[t3] = 1; EXAM_CHECK( vt1 <= vt2 ); EXAM_CHECK( !(vt2 <= vt1) ); @@ -35,15 +40,15 @@ vt1.clear(); vt2.clear(); - vt1[1] = 1; + vt1[t1] = 1; - vt2[1] = 1; - vt2[3] = 1; + vt2[t1] = 1; + vt2[t3] = 1; EXAM_CHECK( vt1 <= vt2 ); EXAM_CHECK( !(vt2 <= vt1) ); - vt1[2] = 1; + vt1[t2] = 1; EXAM_CHECK( !(vt1 <= vt2) ); EXAM_CHECK( !(vt2 <= vt1) ); @@ -51,38 +56,43 @@ int EXAM_IMPL(vtime_operations::vt_add) { + oid_type t0; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + oid_type t3; t3.addr = 3; + vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; vt3 = vt1 + vt2; EXAM_CHECK( vt1 <= vt3 ); EXAM_CHECK( vt3 <= vt1 ); - vt2[2] = 1; + vt2[t2] = 1; vt3 = vt1 + vt2; - vt4[1] = 1; - vt4[2] = 2; + vt4[t1] = 1; + vt4[t2] = 2; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); vt4.clear(); - vt2[3] = 1; + vt2[t3] = 1; vt3 = vt1 + vt2; - vt4[1] = 1; - vt4[2] = 2; - vt4[3] = 1; + vt4[t1] = 1; + vt4[t2] = 2; + vt4[t3] = 1; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); @@ -92,29 +102,34 @@ int EXAM_IMPL(vtime_operations::vt_diff) { + oid_type t0; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + oid_type t3; t3.addr = 3; + vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; vt3 = vt1 - vt2; EXAM_CHECK( vt1 <= vt3 ); EXAM_CHECK( vt3 <= vt1 ); - vt2[1] = 1; + vt2[t1] = 1; vt3 = vt1 - vt2; - vt4[2] = 1; + vt4[t2] = 1; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); - vt2[2] = 1; + vt2[t2] = 1; vt4.clear(); @@ -125,7 +140,7 @@ vt2.clear(); - vt2[3] = 1; + vt2[t3] = 1; try { vt3 = vt1 - vt2; @@ -137,7 +152,7 @@ vt2.clear(); - vt2[2] = 2; + vt2[t2] = 2; try { vt3 = vt1 - vt2; @@ -152,13 +167,18 @@ int EXAM_IMPL(vtime_operations::vt_max) { + oid_type t0; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + oid_type t3; t3.addr = 3; + vtime_type vt1; vtime_type vt2; vtime_type vt3; vtime_type vt4; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; vt3 = vt1; vt::sup( vt3, vt2 ); @@ -166,7 +186,7 @@ EXAM_CHECK( vt3 <= vt1 ); EXAM_CHECK( vt1 <= vt3 ); - vt2[1] = 1; + vt2[t1] = 1; vt3 = vt1; vt::sup( vt3, vt2 ); @@ -174,7 +194,7 @@ EXAM_CHECK( vt3 <= vt1 ); EXAM_CHECK( vt1 <= vt3 ); - vt2[2] = 1; + vt2[t2] = 1; vt3 = vt1; vt::sup( vt3, vt2 ); @@ -182,40 +202,40 @@ EXAM_CHECK( vt3 <= vt1 ); EXAM_CHECK( vt1 <= vt3 ); - vt2[3] = 1; + vt2[t3] = 1; vt3 = vt1; vt::sup( vt3, vt2 ); - vt4[1] = 1; - vt4[2] = 1; - vt4[3] = 1; + vt4[t1] = 1; + vt4[t2] = 1; + vt4[t3] = 1; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); vt2.clear(); - vt2[1] = 1; - vt2[2] = 2; + vt2[t1] = 1; + vt2[t2] = 2; vt4.clear(); vt3 = vt1; vt::sup( vt3, vt2 ); - vt4[1] = 1; - vt4[2] = 2; + vt4[t1] = 1; + vt4[t2] = 2; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); - vt2[3] = 4; + vt2[t3] = 4; vt3 = vt1; vt::sup( vt3, vt2 ); - vt4[3] = 4; + vt4[t3] = 4; EXAM_CHECK( vt3 <= vt4 ); EXAM_CHECK( vt4 <= vt3 ); @@ -225,6 +245,10 @@ int EXAM_IMPL(vtime_operations::gvt_add) { + oid_type t0; + oid_type t1; t1.addr = 1; + oid_type t2; t2.addr = 2; + { gvtime_type gvt1; gvtime_type gvt2; @@ -232,22 +256,22 @@ vtime_type vt1; vtime_type vt2; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; - vt2[1] = 1; - vt2[2] = 1; + vt2[t1] = 1; + vt2[t2] = 1; gvt1[0] = vt1; gvt2[0] = vt2; gvt1 += gvt2; - EXAM_CHECK( gvt1[0][1] == 2 ); - EXAM_CHECK( gvt1[0][2] == 2 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 0 ); - EXAM_CHECK( gvt1[1][2] == 0 ); + EXAM_CHECK( gvt1[0][t1] == 2 ); + EXAM_CHECK( gvt1[0][t2] == 2 ); + EXAM_CHECK( gvt1[0][t0] == 0 ); + EXAM_CHECK( gvt1[1][t1] == 0 ); + EXAM_CHECK( gvt1[1][t2] == 0 ); } { gvtime_type gvt1; @@ -256,22 +280,22 @@ vtime_type vt1; vtime_type vt2; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; - vt2[1] = 1; - vt2[2] = 1; + vt2[t1] = 1; + vt2[t2] = 1; gvt1[0] = vt1; gvt2[1] = vt2; gvt1 += gvt2; - EXAM_CHECK( gvt1[0][1] == 1 ); - EXAM_CHECK( gvt1[0][2] == 1 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 1 ); - EXAM_CHECK( gvt1[1][2] == 1 ); + EXAM_CHECK( gvt1[0][t1] == 1 ); + EXAM_CHECK( gvt1[0][t2] == 1 ); + EXAM_CHECK( gvt1[0][t0] == 0 ); + EXAM_CHECK( gvt1[1][t1] == 1 ); + EXAM_CHECK( gvt1[1][t2] == 1 ); } { gvtime_type gvt1; @@ -279,21 +303,21 @@ vtime_type vt1; vtime_type vt2; - vt1[1] = 1; - vt1[2] = 1; + vt1[t1] = 1; + vt1[t2] = 1; - vt2[1] = 1; - vt2[2] = 1; + vt2[t1] = 1; + vt2[t2] = 1; gvt1[0] = vt1; gvt1 += make_pair( 1, vt2 ); - EXAM_CHECK( gvt1[0][1] == 1 ); - EXAM_CHECK( gvt1[0][2] == 1 ); - EXAM_CHECK( gvt1[0][0] == 0 ); - EXAM_CHECK( gvt1[1][1] == 1 ); - EXAM_CHECK( gvt1[1][2] == 1 ); + EXAM_CHECK( gvt1[0][t1] == 1 ); + EXAM_CHECK( gvt1[0][t2] == 1 ); + EXAM_CHECK( gvt1[0][t0] == 0 ); + EXAM_CHECK( gvt1[1][t1] == 1 ); + EXAM_CHECK( gvt1[1][t2] == 1 ); } return EXAM_RESULT; Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-07-27 10:24:38 UTC (rev 1647) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/26 10:28:55 ptr> +// -*- C++ -*- Time-stamp: <07/07/27 09:49:24 ptr> #include "vtime.h" @@ -15,7 +15,7 @@ { __pack( s, static_cast<uint8_t>(vt.size()) ); for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { - __pack( s, i->first ); + i->first.pack( s ); // __pack( s, i->first ); __pack( s, i->second ); } } @@ -24,7 +24,7 @@ { __net_pack( s, static_cast<uint8_t>(vt.size()) ); for ( vtime_type::const_iterator i = vt.begin(); i != vt.end(); ++i ) { - __net_pack( s, i->first ); + i->first.net_pack( s ); // __net_pack( s, i->first ); __net_pack( s, i->second ); } } @@ -38,7 +38,7 @@ oid_type oid; vtime_unit_type v; - __unpack( s, oid ); + oid.unpack( s ); // __unpack( s, oid ); __unpack( s, v ); vt[oid] = v; @@ -54,7 +54,7 @@ oid_type oid; vtime_unit_type v; - __net_unpack( s, oid ); + oid.net_unpack( s ); // __net_unpack( s, oid ); __net_unpack( s, v ); vt[oid] = v; @@ -106,7 +106,7 @@ void VTmess::pack( std::ostream& s ) const { __pack( s, code ); - __pack( s, src ); + src.pack( s ); // __pack( s, src ); gvt.pack( s ); __pack( s, grp ); __pack( s, mess ); @@ -115,7 +115,7 @@ void VTmess::net_pack( std::ostream& s ) const { __net_pack( s, code ); - __net_pack( s, src ); + src.net_pack( s ); // __net_pack( s, src ); gvt.net_pack( s ); __net_pack( s, grp ); __net_pack( s, mess ); @@ -124,7 +124,7 @@ void VTmess::unpack( std::istream& s ) { __unpack( s, code ); - __unpack( s, src ); + src.unpack( s ); // __unpack( s, src ); gvt.unpack( s ); __unpack( s, grp ); __unpack( s, mess ); @@ -133,7 +133,7 @@ void VTmess::net_unpack( std::istream& s ) { __net_unpack( s, code ); - __net_unpack( s, src ); + src.net_unpack( s ); // __net_unpack( s, src ); gvt.net_unpack( s ); __net_unpack( s, grp ); __net_unpack( s, mess ); Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-07-27 10:10:55 UTC (rev 1646) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-07-27 10:24:38 UTC (rev 1647) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/26 09:34:53 ptr> +// -*- C++ -*- Time-stamp: <07/07/27 09:53:24 ptr> #ifndef __vtime_h #define __vtime_h @@ -19,8 +19,25 @@ namespace vt { -typedef stem::addr_type oid_type; -typedef unsigned vtime_unit_type; +// typedef stem::addr_type oid_type; +typedef stem::gaddr_type oid_type; + +} // namespace vt + +namespace std { + +template <> +struct hash<vt::oid_type> +{ + size_t operator()(const vt::oid_type& __x) const + { return __x.addr; } +}; + +} // namespace std + +namespace vt { + +typedef uint32_t vtime_unit_type; typedef uint32_t group_type; typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; @@ -81,9 +98,9 @@ vtime& operator +=( const vtime_type::value_type& ); - vtime_type::data_type& operator[]( const vtime_type::key_type k ) + vtime_type::data_type& operator[]( const vtime_type::key_type& k ) { return vt[k]; } - const vtime_type::data_type& operator[]( const vtime_type::key_type k ) const + const vtime_type::data_type& operator[]( const vtime_type::key_type& k ) const { return vt[k]; } @@ -140,7 +157,7 @@ VTmess() : code(0), - src(0), + src(), gvt(), grp(0), mess() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-07-27 10:58:21
|
Revision: 1648 http://complement.svn.sourceforge.net/complement/?rev=1648&view=rev Author: complement Date: 2007-07-27 03:58:07 -0700 (Fri, 27 Jul 2007) Log Message: ----------- libvts 0.1.0 Modified Paths: -------------- trunk/complement/explore/test/virtual_time/Makefile trunk/complement/explore/test/virtual_time/Makefile.inc Removed Paths: ------------- trunk/complement/explore/test/virtual_time/vtime_main.cc Modified: trunk/complement/explore/test/virtual_time/Makefile =================================================================== --- trunk/complement/explore/test/virtual_time/Makefile 2007-07-27 10:24:38 UTC (rev 1647) +++ trunk/complement/explore/test/virtual_time/Makefile 2007-07-27 10:58:07 UTC (rev 1648) @@ -6,7 +6,7 @@ include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak -INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) +INCLUDES += -I$(SRCROOT)/include LIBMT_DIR = ${CoMT_DIR}/lib/mt LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios @@ -15,8 +15,35 @@ LDSEARCH += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} release-shared : LDLIBS = -lxmt -lsockios -lstem +ifndef WITHOUT_STLPORT stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lstemstlg +endif dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg +check: all-shared + $(MAKE) -C test + (cd test; ${OUTPUT_DIR}/ut_vtime) || exit 1 + (cd test; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 +ifndef WITHOUT_STLPORT + (cd test; ${OUTPUT_DIR_STLDBG}/ut_vt) || exit 1 +endif + +check-release-shared: release-shared + $(MAKE) -C test release-shared + (cd test; ${OUTPUT_DIR}/ut_vtime) || exit 1 + +check-dbg-shared: dbg-shared + $(MAKE) -C test dbg-shared + (cd test; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 + +ifndef WITHOUT_STLPORT +check-stldbg-shared: stldbg-shared + $(MAKE) -C test stldbg-shared + (cd test; ${OUTPUT_DIR_STLDBG}/ut_vtime) || exit 1 +endif + +depend:: + $(MAKE) -C test depend + # dbg-shared: DEFS += -DDEBUG Modified: trunk/complement/explore/test/virtual_time/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/Makefile.inc 2007-07-27 10:24:38 UTC (rev 1647) +++ trunk/complement/explore/test/virtual_time/Makefile.inc 2007-07-27 10:58:07 UTC (rev 1648) @@ -1,4 +1,7 @@ # -*- makefile -*- Time-stamp: <06/10/10 15:22:33 ptr> -PRGNAME = vtime -SRC_CC = vtime_main.cc vtime.cc +LIBNAME = vts +MAJOR = 0 +MINOR = 1 +PATCH = 0 +SRC_CC = vtime.cc Deleted: trunk/complement/explore/test/virtual_time/vtime_main.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-07-27 10:24:38 UTC (rev 1647) +++ trunk/complement/explore/test/virtual_time/vtime_main.cc 2007-07-27 10:58:07 UTC (rev 1648) @@ -1,56 +0,0 @@ -#include <iostream> -#include <mt/xmt.h> - -#include "vtime.h" - -using namespace std; -using namespace xmt; -using namespace vt; - -int main() -{ - Condition cnd; - - cnd.set(false); - - cerr << "Hello, world!" << endl; - - Proc m1( 100 ); - Proc m2( 101 ); - Proc r1( 102 ); - Proc r2( 103 ); - - m1.add_group( 0 ); - m2.add_group( 0 ); - r1.add_group( 0 ); - - m1.add_group_member( 0, m2.self_id() ); - m1.add_group_member( 0, r1.self_id() ); - - r1.add_group_member( 0, m1.self_id() ); - r1.add_group_member( 0, m2.self_id() ); - - m2.add_group_member( 0, m1.self_id() ); - m2.add_group_member( 0, r1.self_id() ); - - m1.add_group( 1 ); - m2.add_group( 1 ); - r2.add_group( 1 ); - - m1.add_group_member( 1, m2.self_id() ); - m1.add_group_member( 1, r2.self_id() ); - - r2.add_group_member( 1, m1.self_id() ); - r2.add_group_member( 1, m2.self_id() ); - - m2.add_group_member( 1, m1.self_id() ); - m2.add_group_member( 1, r2.self_id() ); - - r1.SendVC( 0, "Hello!" ); - - m1.SendVC( 0, "How are you?" ); - - cnd.wait(); - - return 0; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2007-08-03 06:33:51
|
Revision: 1661 http://complement.svn.sourceforge.net/complement/?rev=1661&view=rev Author: complement Date: 2007-08-02 23:33:49 -0700 (Thu, 02 Aug 2007) Log Message: ----------- subscribe/unsubscribe operations for VTHandler Modified Paths: -------------- trunk/complement/explore/test/virtual_time/test/Makefile trunk/complement/explore/test/virtual_time/test/Makefile.inc trunk/complement/explore/test/virtual_time/test/unit_test.cc trunk/complement/explore/test/virtual_time/test/vt_operations.h trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Added Paths: ----------- trunk/complement/explore/test/virtual_time/test/vt_handler.cc Modified: trunk/complement/explore/test/virtual_time/test/Makefile =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/test/Makefile 2007-08-03 06:33:49 UTC (rev 1661) @@ -14,9 +14,9 @@ LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR}:${STLPORT_LIB_DIR} -release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lexam -lboost_fs -dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lexamg -lboost_fsg -stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lexamstlg -lboost_fsstlg +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lexam +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lexamg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lexamstlg LDLIBS = ${PROJECT_LIBS} Modified: trunk/complement/explore/test/virtual_time/test/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-08-03 06:33:49 UTC (rev 1661) @@ -7,6 +7,5 @@ vt_operations.cc \ VTmess_core.cc \ vt_object.cc \ - vt_dispatch.cc - - + vt_dispatch.cc \ + vt_handler.cc Modified: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-08-03 06:33:49 UTC (rev 1661) @@ -20,9 +20,12 @@ t.add( &vtime_operations::VTMess_core, vt_oper, "VTmess core transfer", tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); - t.add( &vtime_operations::VTDispatch2, vt_oper, "VTDispatch2", - t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", - t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ) ) ); + t.add( &vtime_operations::VTSubscription, vt_oper, "VTSubscription", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler2", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTHandler1", + t.add( &vtime_operations::VTDispatch2, vt_oper, "VTDispatch2", + t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", + t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] ) ) ) ) ) ); return t.girdle(); } Added: trunk/complement/explore/test/virtual_time/test/vt_handler.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_handler.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/vt_handler.cc 2007-08-03 06:33:49 UTC (rev 1661) @@ -0,0 +1,177 @@ +// -*- C++ -*- Time-stamp: <07/07/26 09:53:24 ptr> + +#include "vt_operations.h" + +// #include <boost/lexical_cast.hpp> + +#include <iostream> +#include <vtime.h> + +using namespace vt; +using namespace std; + +class VTDummy : + public vt::VTHandler +{ + public: + VTDummy(); + VTDummy( stem::addr_type id ); + VTDummy( stem::addr_type id, const char *info ); + ~VTDummy(); + + void handler( const stem::Event& ); + void VTNewMember( const stem::Event& ); + + void wait(); + std::string msg; + int count; + + private: + xmt::condition cnd; + + DECLARE_RESPONSE_TABLE( VTDummy, vt::VTHandler ); +}; + +#define VT_MESS3 0x1203 + +VTDummy::VTDummy() : + VTHandler(), + count(0) +{ + cnd.set( false ); +} + +VTDummy::VTDummy( stem::addr_type id ) : + VTHandler( id ), + count(0) +{ + cnd.set( false ); +} + +VTDummy::VTDummy( stem::addr_type id, const char *info ) : + VTHandler( id, info ), + count(0) +{ + cnd.set( false ); +} + +VTDummy::~VTDummy() +{ + // cnd.wait(); +} + +void VTDummy::handler( const stem::Event& ev ) +{ + msg = ev.value(); + + cnd.set( true ); +} + +void VTDummy::VTNewMember( const stem::Event& ev ) +{ + // cerr << "Hello" << endl; + ++count; +} + +void VTDummy::wait() +{ + cnd.try_wait(); + + cnd.set( false ); +} + +DEFINE_RESPONSE_TABLE( VTDummy ) + EV_EDS( ST_NULL, VT_MESS3, handler ) +END_RESPONSE_TABLE + +int EXAM_IMPL(vtime_operations::VTHandler1) +{ + VTDummy dummy1; + VTDummy dummy2; + + stem::Event ev( VT_MESS3 ); + ev.dest( 0 ); // group + ev.value() = "hello"; + + dummy1.VTSend( ev ); + + dummy2.wait(); + + EXAM_CHECK( dummy2.msg == "hello" ); + EXAM_CHECK( dummy1.msg == "" ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(vtime_operations::VTHandler2) +{ + VTDummy dummy1; + VTDummy dummy2; + VTDummy dummy3; + + stem::Event ev( VT_MESS3 ); + ev.dest( 0 ); // group + ev.value() = "hello"; + + dummy1.VTSend( ev ); + + dummy2.wait(); + dummy3.wait(); + + EXAM_CHECK( dummy3.count == 0 ); + EXAM_CHECK( dummy3.msg == "hello" ); + EXAM_CHECK( dummy2.count == 1 ); + EXAM_CHECK( dummy2.msg == "hello" ); + EXAM_CHECK( dummy1.count == 2 ); + EXAM_CHECK( dummy1.msg == "" ); + + ev.dest( 100 ); // not this group member + try { + dummy1.VTSend( ev ); + EXAM_ERROR( "exception expected" ); + } + catch ( std::domain_error& ) { + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(vtime_operations::VTSubscription) +{ + VTDummy dummy1; + VTDummy dummy2; + + stem::Event ev( VT_MESS3 ); + ev.dest( 0 ); // group + ev.value() = "hello"; + + dummy1.VTSend( ev ); + + dummy2.wait(); + EXAM_CHECK( dummy2.msg == "hello" ); + + { + VTDummy dummy3; + + ev.value() = "hi"; + dummy1.VTSend( ev ); + + dummy2.wait(); + // dummy3.wait(); + + // EXAM_CHECK( dummy3.msg == "hi" ); + EXAM_CHECK( dummy3.msg == "" ); // dummy3 don't see, due to VTS + EXAM_CHECK( dummy2.msg == "hi" ); + EXAM_CHECK( dummy1.msg == "" ); + } + + ev.value() = "yet more"; + dummy1.VTSend( ev ); + + dummy2.wait(); + EXAM_CHECK( dummy2.msg == "yet more" ); + EXAM_CHECK( dummy1.msg == "" ); + + return EXAM_RESULT; +} + Modified: trunk/complement/explore/test/virtual_time/test/vt_operations.h =================================================================== --- trunk/complement/explore/test/virtual_time/test/vt_operations.h 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/test/vt_operations.h 2007-08-03 06:33:49 UTC (rev 1661) @@ -20,6 +20,11 @@ int EXAM_DECL(VTDispatch1); int EXAM_DECL(VTDispatch2); + + int EXAM_DECL(VTHandler1); + int EXAM_DECL(VTHandler2); + + int EXAM_DECL(VTSubscription); }; #endif // __vt_operations_h Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-08-03 06:33:49 UTC (rev 1661) @@ -405,6 +405,65 @@ vtstamp[grp][from] = vt.gvt[grp][from]; // my counter, as is, not delta } +bool vtime_obj_rec::rm_group( group_type g ) +{ + // strike out group g from my groups list + groups_container_type::iterator i = groups.find( g ); + if ( i == groups.end() ) { + throw domain_error( "VT object not member of group" ); + } + groups.erase( i ); + + // remove my VT component for group g + gvtime_type::iterator j = vt.gvt.find( g ); + + if ( j != vt.gvt.end() ) { + vt.gvt.erase( j ); + } + + // remove sended VT components for group g + for ( snd_delta_vtime_t::iterator k = svt.begin(); k != svt.end(); ++k ) { + gvtime_type::iterator l = k->second.find( g ); + if ( l != k->second.end() ) { + k->second.erase( l ); + } + } + + // remove recieved VT components for group g + for ( delta_vtime_type::iterator k = lvt.begin(); k != lvt.end(); ++k ) { + gvtime_type::iterator l = k->second.find( g ); + if ( l != k->second.end() ) { + k->second.erase( l ); + } + } + + // remove messages for group g that wait in delay pool + for ( dpool_t::iterator p = dpool.begin(); p != dpool.end(); ) { + if ( p->second->value().grp == g ) { + dpool.erase( p++ ); + } else { + ++p; + } + } + + return groups.empty() ? true : false; +} + +void vtime_obj_rec::rm_member( oid_type oid ) +{ + delta_vtime_type::iterator i = lvt.find( oid ); + + if ( i != lvt.end() ) { + lvt.erase( i ); + } + + snd_delta_vtime_t::iterator j = svt.find( oid ); + + if ( j != lvt.end() ) { + svt.erase( j ); + } +} + } // namespace detail void VTDispatcher::VTDispatch( const stem::Event_base<VTmess>& m ) @@ -521,10 +580,50 @@ void VTDispatcher::Subscribe( stem::addr_type addr, oid_type oid, group_type grp ) { + // See comment on top of VTSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::const_iterator,gid_map_type::const_iterator> range = + grmap.equal_range( grp ); + + for ( ; range.first != range.second; ++range.first ) { + vt_map_type::iterator i = vtmap.find( range.first->second ); + if ( i != vtmap.end() ) { + stem::Event ev( VTS_NEW_MEMBER ); + ev.dest( i->second.stem_addr() ); + ev.src( addr ); + Forward( ev ); + } + } + vtmap[oid].add( addr, grp ); grmap.insert( make_pair(grp,oid) ); } +void VTDispatcher::Unsubscribe( oid_type oid, group_type grp ) +{ + // See comment on top of VTSend above + xmt::recursive_scoped_lock lk( this->_theHistory_lock ); + + pair<gid_map_type::iterator,gid_map_type::iterator> range = + grmap.equal_range( grp ); + + while ( range.first != range.second ) { + if ( range.first->second == oid ) { + grmap.erase( range.first++ ); + } else { + ++range.first; + } + } + + vt_map_type::iterator i = vtmap.find( oid ); + if ( i != vtmap.end() ) { + if ( i->second.rm_group( grp ) ) { // no groups more + vtmap.erase( i ); + } + } +} + DEFINE_RESPONSE_TABLE( VTDispatcher ) EV_Event_base_T_( ST_NULL, MESS, VTDispatch, VTmess ) END_RESPONSE_TABLE @@ -583,7 +682,7 @@ void VTHandler::VTSend( const stem::Event& ev ) { ev.src( self_id() ); - // _vtdsp->VTSend( ev, grp ); + _vtdsp->VTSend( ev, ev.dest() ); // throw domain_error, if not group member } VTHandler::VTHandler() : @@ -591,26 +690,40 @@ { new( Init_buf ) Init(); - // _vtdsp->Subscribe( self_id(), ... , ... ); + _vtdsp->Subscribe( self_id(), oid_type( self_id() ), /* grp */ 0 ); } VTHandler::VTHandler( const char *info ) : EventHandler( info ) { new( Init_buf ) Init(); + + _vtdsp->Subscribe( self_id(), oid_type( self_id() ), /* grp */ 0 ); } VTHandler::VTHandler( stem::addr_type id, const char *info ) : EventHandler( id, info ) { new( Init_buf ) Init(); + + _vtdsp->Subscribe( id, oid_type( id ), /* grp */ 0 ); } VTHandler::~VTHandler() { + _vtdsp->Unsubscribe( oid_type( self_id() ), /* grp */ 0 ); + ((Init *)Init_buf)->~Init(); } +void VTHandler::VTNewMember( const stem::Event& ) +{ +} + +DEFINE_RESPONSE_TABLE( VTHandler ) + EV_EDS( ST_NULL, VTS_NEW_MEMBER, VTNewMember ) +END_RESPONSE_TABLE + } // namespace vt namespace std { Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-08-03 06:31:38 UTC (rev 1660) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-08-03 06:33:49 UTC (rev 1661) @@ -38,7 +38,7 @@ namespace vt { typedef uint32_t vtime_unit_type; -typedef uint32_t group_type; +typedef stem::addr_type group_type; // required, used in VTSend typedef std::hash_map<oid_type, vtime_unit_type> vtime_type; bool operator <=( const vtime_type& l, const vtime_type& r ); @@ -186,6 +186,8 @@ { groups.insert(g); } void add( stem::addr_type a, group_type g ) { addr = a; groups.insert(g); } + bool rm_group( group_type ); + void rm_member( oid_type ); stem::addr_type stem_addr() const { return addr; } @@ -252,6 +254,7 @@ void VTSend( const stem::Event& e, group_type ); void Subscribe( stem::addr_type, oid_type, group_type ); + void Unsubscribe( oid_type, group_type ); private: typedef std::hash_map<oid_type, detail::vtime_obj_rec> vt_map_type; @@ -288,6 +291,7 @@ virtual ~VTHandler(); void VTSend( const stem::Event& e ); + virtual void VTNewMember( const stem::Event& e ); template <class D> void VTSend( const stem::Event_base<D>& e ) @@ -296,9 +300,12 @@ private: static class VTDispatcher *_vtdsp; + + DECLARE_RESPONSE_TABLE( VTHandler, stem::EventHandler ); }; #define MESS 0x300 +#define VTS_NEW_MEMBER 0x301 } // namespace vt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |