ref: refs/heads/master
commit ddf52485bfed212dc98dee08863c77bbf0c255e1
Author: Michael Andres
Date: Thu Feb 26 13:29:15 2009 +0100
backup
---
devel/devel.ma/CMakeLists.txt | 21 +--
devel/devel.ma/DumpSolv.cc | 327 +++++++++++++++++++++++++++++++++---
devel/devel.ma/Sat.cc | 125 +++++++++++---
devel/devel.ma/SigTrackableFail.cc | 133 +++++++++++++++
devel/devel.ma/ma_test | 2 +-
5 files changed, 546 insertions(+), 62 deletions(-)
diff --git a/devel/devel.ma/CMakeLists.txt b/devel/devel.ma/CMakeLists.txt
index 425f469..9413648 100644
--- a/devel/devel.ma/CMakeLists.txt
+++ b/devel/devel.ma/CMakeLists.txt
@@ -15,31 +15,26 @@ ELSE ( NOT QT_FOUND )
#)
ENDIF( NOT QT_FOUND )
+SET(THREAD_LIBRARY boost_thread-mt)
+
## ############################################################
-ADD_CUSTOM_TARGET( ma_test
+ADD_CUSTOM_TARGET( ma_test ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ma_test
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/ma_test ${CMAKE_CURRENT_BINARY_DIR}/ma_test
)
## ############################################################
-FOREACH( loop_var MaTest NewPool DumpSolv Iorder Xml Ex Main FakePool AOUT Parse Test Basic Sat TransList)
- ADD_EXECUTABLE( ${loop_var}
- ${loop_var}.cc
- )
- TARGET_LINK_LIBRARIES( ${loop_var}
- zypp
- )
-ENDFOREACH( loop_var )
-
-
-FOREACH( loop_var ToolScanRepos ToolProvideSignedDir)
+FILE( GLOB ALLCC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc" )
+STRING( REPLACE ".cc" ";" APLLPROG ${ALLCC} )
+FOREACH( loop_var ${APLLPROG} )
ADD_EXECUTABLE( ${loop_var}
${loop_var}.cc
)
TARGET_LINK_LIBRARIES( ${loop_var}
- zypp
+ boost_signals
+#zypp ${THREAD_LIBRARY}
)
ENDFOREACH( loop_var )
diff --git a/devel/devel.ma/DumpSolv.cc b/devel/devel.ma/DumpSolv.cc
index af76ac0..0972d99 100644
--- a/devel/devel.ma/DumpSolv.cc
+++ b/devel/devel.ma/DumpSolv.cc
@@ -1,38 +1,325 @@
-#include <iostream>
-#include
-#include
-#include
+#include "Tools.h"
+#include
+#include
+#include
+#include "zypp/pool/GetResolvablesToInsDel.h"
-using std::endl;
-using std::cout;
-using namespace zypp;
+///////////////////////////////////////////////////////////////////
+#include "zypp/parser/xml/ParseDef.h"
+#include "zypp/parser/xml/ParseDefConsume.h"
+#include "zypp/parser/xml/Reader.h"
+namespace zypp
+{
+ namespace xml
+ {
+ namespace parsedefassign
+ {
+ template <class _Type> struct Assigner;
+
+ /** Common interface to all Assigner. */
+ template <>
+ struct Assigner<void>
+ {
+ virtual ~Assigner()
+ {}
+ virtual void assign( const char * text_r )
+ {}
+ };
+
+ /** Assigner assigns text to types constructible from \c char*. */
+ template <class _Type>
+ struct Assigner : public Assigner<void>
+ {
+ Assigner(_Type & value_r )
+ : _value( &value_r )
+ {}
+
+ virtual void assign( const char * text_r )
+ { *_value = _Type( text_r ); }
+
+ private:
+ _Type * _value;
+ };
+
+ /** \name Assigner specialisation for numeric and boolean values.
+ * \relates Assigner
+ */
+ //@{
+ template <>
+ inline void Assigner<short>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<int>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<long>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<long long>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<unsigned short>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<unsigned>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<unsigned long>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<unsigned long long>::assign( const char * text_r ) { str::strtonum( text_r, *_value ); }
+ template <>
+ inline void Assigner<bool>::assign( const char * text_r ) { str::strToBoolNodefault( text_r, *_value ); }
+ //@}
+ }
+
+ struct ParseDefAssignConsumer : public ParseDefConsume
+ {
+ virtual void start( const Node & node_r )
+ {}
+
+ virtual void text( const Node & node_r )
+ {}
+ };
+
+ struct ParseDefAssign
+ {
+ template <class _Type>
+ ParseDefAssign( _Type & value_r )
+ {}
+
+ operator const shared_ptr<ParseDefAssignConsumer> &() const
+ { return _ptr; }
+
+ private:
+ shared_ptr<ParseDefAssignConsumer> _ptr;
+ };
+
+ }
+
+ /** Parse \c input_r and store data in \c data_r.
+ *
+ * \c _Data must be defaultconstructible and assignable.
+ *
+ * \c _Data::RootNode must be a \ref xml::ParseDef constructible
+ * from \c _Data&.
+ *
+ * \throws ParseDefException on parse errors.
+ *
+ * To parse a xml file like this:
+ * \code
+ * <test><setup>value</setup></test>
+ * \endcode
+ *
+ * You need something like this:
+ * \code
+ * struct XmlData
+ * {
+ * std::string value;
+
+ * public:
+ * // Convenience parsing to *this.
+ * void parse( const Pathname & path_r )
+ * { rnParse( path_r, *this ); }
+
+ * public:
+ * // Parser description
+ * struct RootNode : public xml::ParseDef, public xml::ParseDefConsume
+ * {
+ * RootNode( XmlData & data )
+ * : ParseDef( "test", MANDTAORY )
+ * {
+ * (*this)
+ * ("setup", MANDTAORY, xml::parseDefAssignText( data.value ) )
+ * ;
+ * }
+ * };
+ * };
+ *
+ * XmlData xmlData;
+ * xmlData.parse( "/tmp/mytest.xml" );
+ * \endcode
+ */
+ template<class _Data>
+ inline void rnParse( const InputStream & input_r, _Data & data_r )
+ {
+ typedef typename _Data::RootNode RootNode;
+ MIL << "+++ " << input_r << endl;
+ _Data pdata;
+ try
+ {
+ xml::Reader reader( input_r );
+ RootNode rootNode( pdata );
+ rootNode.take( reader );
+ }
+ catch ( const Exception & err )
+ {
+ // parse error
+ ERR << err << endl;
+ ERR << "--- " << input_r << endl;
+ ZYPP_RETHROW( err );
+ }
+ MIL << "--- " << input_r << endl;
+ data_r = pdata;
+ }
+
+ struct SolverTestXml
+ {
+ public:
+ struct Chanel
+ {
+ Chanel() : priority( RepoInfo::defaultPriority() ) {}
+ std::string file;
+ std::string alias;
+ unsigned priority;
+ };
+
+ Arch systemArch;
+ Locale systemLocale;
+ std::string systemFile;
+ std::list<Chanel> chanelList;
+
+ public:
+ /** Convenience parsing to \c this, appending \c "solver-test.xml" to directories. */
+ void parse( const Pathname & path_r )
+ { rnParse( (PathInfo(path_r).isDir() ? path_r/"solver-test.xml" : path_r ), *this ); }
+
+ public:
+ struct RootNode : public xml::ParseDef, public xml::ParseDefConsume
+ {
+ RootNode( SolverTestXml & data )
+ : ParseDef( "test", MANDTAORY, xml::parseDefAssignText( data.systemFile ) )
+ {
+ (*this)
+ ("setup", MANDTAORY, xml::parseDefAssign( data.systemArch ) )
+ ;
+ }
+ };
+ };
+}
+///////////////////////////////////////////////////////////////////
+
+static std::string appname( __FILE__ );
+
+void message( const std::string & msg_r )
+{
+ cerr << "*** " << msg_r << endl;
+}
+
+int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
+{
+ if ( ! msg_r.empty() )
+ {
+ cerr << endl;
+ message( msg_r );
+ cerr << endl;
+ }
+ cerr << "Usage: " << appname << " TESTCASE" << endl;
+ cerr << " Load and process testcase." << endl;
+ return exit_r;
+}
+
+///////////////////////////////////////////////////////////////////
+
+bool progressReceiver( const ProgressData & v )
+{
+ DBG << "...->" << v << endl;
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////
+
+bool upgrade()
+{
+ bool rres = false;
+ {
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ UpgradeStatistics u;
+ rres = getZYpp()->resolver()->doUpgrade( u );
+ }
+ if ( ! rres )
+ {
+ ERR << "upgrade " << rres << endl;
+ getZYpp()->resolver()->problems();
+ return false;
+ }
+ MIL << "upgrade " << rres << endl;
+ return true;
+}
+
+bool solve()
+{
+ static unsigned run = 0;
+ USR << "Solve " << run++ << endl;
+ bool rres = false;
+ {
+ zypp::base::LogControl::TmpLineWriter shutUp;
+ rres = getZYpp()->resolver()->resolvePool();
+ }
+ if ( ! rres )
+ {
+ ERR << "resolve " << rres << endl;
+ getZYpp()->resolver()->problems();
+ return false;
+ }
+
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////
/******************************************************************
**
** FUNCTION NAME : main
** FUNCTION TYPE : int
*/
-int main( int argc, const char * argv[] )
+int main( int argc, char * argv[] )
{
- --argc; ++argv; // skip arg 0
- sat::Pool satpool( sat::Pool::instance() );
+ INT << "===[START]==========================================" << endl;
+ appname = Pathname::basename( argv[0] );
+ --argc;
+ ++argv;
+
+ ///////////////////////////////////////////////////////////////////
- for ( ; argc; --argc, ++argv )
+ Pathname mtest( "/suse/ma/BUGS/472099/zypper.solverTestCase" );
+ Arch march( Arch_i686 );
+
+ while ( argc )
{
- cout << "Read: " << argv[0] << endl;
- satpool.addRepoSolv( argv[0] );
+ --argc;
+ ++argv;
}
- cout << "Done: " << satpool << endl;
+ if ( mtest.empty() )
+ {
+ return usage( "Missing Testcase", 102 );
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
+ //xml::ParseDef::_debug = true;
+ SolverTestXml solvertest;
+ solvertest.parse( mtest );
+ USR << solvertest.systemFile << endl;
+ USR << solvertest.systemArch << endl;
+
+ INT << "===[END]============================================" << endl << endl;
+ return 0;
+
+ TestSetup test( march );
+ ResPool pool( test.pool() );
+ sat::Pool satpool( test.satpool() );
- if ( true || getenv("VERBOSE") )
{
- for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
- {
- cout << dump(*it) << endl;
- }
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ test.loadTarget();
+ test.loadTestcaseRepos( mtest ); // <<< repos
}
+ test.poolProxy().saveState();
+ {
+ //zypp::base::LogControl::TmpLineWriter shutUp;
+ upgrade();
+ }
+ vdumpPoolStats( USR << "Transacting:"<< endl,
+ make_filter_beginresfilter::ByTransact(pool),
+ make_filter_endresfilter::ByTransact(pool) ) << endl;
+
+ INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::TmpLineWriter shutUp;
return 0;
}
-
diff --git a/devel/devel.ma/Sat.cc b/devel/devel.ma/Sat.cc
index 5a9dd30..1012ba0 100644
--- a/devel/devel.ma/Sat.cc
+++ b/devel/devel.ma/Sat.cc
@@ -1,12 +1,17 @@
-extern "C"
+#include <iostream>
+
+#include
+#include
+namespace boost
{
-#include
-#include
-#include
+ namespace detail
+ {
+ inline std::ostream & operator<<( std::ostream & str, const thread_data_base & obj )
+ { return str << &obj; }
+ }
}
-#include <cstdio>
-#include <iostream>
+#include "zypp/ByteCount.h"
#include "zypp/Pathname.h"
#include "zypp/base/Logger.h"
#include "zypp/base/LogControl.h"
@@ -14,36 +19,100 @@ extern "C"
using std::endl;
using namespace zypp;
-int main( int argc, char * argv[] )
+#undef MIL
+#define MIL MilSync( _BASEFILE, __FUNCTION__, __LINE__ )._str
+
+#ifdef _REENTRANT
+#warning _REENTRANT
+#else
+#warning NOT_REENTRANT
+#endif
+
+template <class Derived>
+struct ClassLevelLockable
{
- //zypp::base::LogControl::instance().logfile( "log.restrict" );
- INT << "===[START]==========================================" << endl;
+ typedef boost::recursive_mutex Lockable;
+
+ typedef boost::lock_guard<Lockable> Lock;
+ struct Lock
+ {
+ Lock( const Derived & obj )
+ {}
+ ~Lock
+ };
+
+ Lockable _mutex;
+};
+
+template <class Derived>
+struct ObjectLevelLockable
+{
+ typedef boost::recursive_mutex Lockable;
+ typedef boost::lock_guard<Lockable> Lock;
+
+};
- ::_Pool * _pool = ::pool_create();
- Pathname p;
+struct MilSync
+{
+ MilSync( const char * file_r, const char * func_r, const int line_r )
+ : _guard( _mutex )
+ , _str( zypp::base::logger::getStream( ZYPP_BASE_LOGGER_LOGGROUP, zypp::base::logger::E_MIL, file_r, func_r, line_r ) )
+ {}
+ typedef boost::recursive_mutex Lockable;
+ static Lockable _mutex;
+ boost::lock_guard<Lockable> _guard;
+ std::ostream & _str;
+};
+MilSync::Lockable MilSync::_mutex;
+
+struct ThreadExcl
+{
+ ThreadExcl()
+ {
+ MIL << "+TE" << boost::this_thread::get_id() << endl;
+ boost::this_thread::sleep( boost::posix_time::seconds(1) );
+ }
- p = "sl10.1-beta7-selections.solv";
- FILE * file = ::fopen( p.c_str(), "r" );
- ::pool_addrepo_solv( _pool, file, p.c_str() );
- ::fclose( file );
+ ~ThreadExcl()
+ {
+ MIL << "-TE" << boost::this_thread::get_id() << endl;
+ }
+};
- p = "1234567890.solv";
- file = ::fopen( p.c_str(), "r" );
- ::pool_addrepo_solv( _pool, file, p.c_str() );
- ::fclose( file );
+void t_exit()
+{
+ MIL << "---" << boost::this_thread::get_id() << endl;
+}
+
+void t_main()
+{
+ MIL << "+++" << boost::this_thread::get_id() << " " << boost::this_thread::interruption_enabled() << endl;
+ boost::this_thread::at_thread_exit( t_exit );
+ ThreadExcl a;
+ while( true )
+ boost::this_thread::sleep( boost::posix_time::seconds(1) );
+}
+
+int main( int argc, char * argv[] )
+{
+ //zypp::base::LogControl::instance().logfile( "log.restrict" );
+ INT << "===[START]==========================================" << endl;
- p = "sl10.1-beta7-packages.solv";
- file = ::fopen( p.c_str(), "r" );
- ::pool_addrepo_solv( _pool, file, p.c_str() );
- ::fclose( file );
+ MIL << "M+++" << boost::this_thread::get_id() << endl;
+ boost::thread_group mthreads;
- ::_Pool & pool( *_pool );
+ mthreads.create_thread( t_main );
+ mthreads.create_thread( t_main );
+ mthreads.create_thread( t_main );
+ mthreads.create_thread( t_main );
+ mthreads.create_thread( t_main );
- MIL << _pool->nrepos << endl;
- MIL << (void*)(*pool.repos) << " " << (*pool.repos)->name << endl;
- MIL << (void*)(*(pool.repos+1)) << " " << (*(pool.repos+1))->name << endl;
- MIL << (void*)(*(pool.repos+2)) << " " << (*(pool.repos+2))->name << endl;
+ MIL << "M???" << boost::this_thread::get_id() << endl;
+ //boost::this_thread::sleep( boost::posix_time::seconds(10) );
+ mthreads.interrupt_all();
+ mthreads.join_all();
+ MIL << "M---" << boost::this_thread::get_id() << endl;
///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
diff --git a/devel/devel.ma/SigTrackableFail.cc b/devel/devel.ma/SigTrackableFail.cc
new file mode 100644
index 0000000..1bb8b97
--- /dev/null
+++ b/devel/devel.ma/SigTrackableFail.cc
@@ -0,0 +1,133 @@
+#include <iostream>
+using std::endl;
+using std::cout;
+
+#include
+#include
+using boost::signal;
+using boost::signals::connection;
+using boost::signals::scoped_connection;
+using boost::signals::trackable;
+
+#define DBG std::cerr
+#define MIL std::cerr
+namespace boost
+{
+ template<class Tp>
+ std::ostream & operator<<( std::ostream & str, const signal<Tp> & obj )
+ {
+ return str << "Connected slots: " << obj.num_slots();
+ }
+
+ namespace signals
+ {
+ std::ostream & operator<<( std::ostream & str, const connection & obj )
+ {
+ return str << "Connection: "
+ << ( obj.connected() ? '*' : '_' )
+ << ( obj.blocked() ? 'B' : '_' )
+ ;
+ }
+ }
+}
+
+struct Sender
+{
+ void ping() const
+ {
+ static unsigned i = 0;
+ ++i;
+ MIL << "Sending " << i << " -> " << _sigA << endl;
+ _sigA( i );
+ _sigB();
+ }
+
+ typedef signal SigA;
+ typedef signal SigB;
+
+ SigA & siga() const { return _sigA; }
+ SigB & sigb() const { return _sigB; }
+
+ mutable SigA _sigA;
+ mutable SigB _sigB;
+};
+
+struct Receiver : public trackable
+{
+ Receiver() {_s=++s;}
+ Receiver( const Receiver & rhs ) : trackable( rhs ) {_s=++s;}
+ Receiver& operator=( const Receiver & rhs ) {
+ trackable::operator=( rhs );
+ return *this;
+ }
+ ~Receiver() {_s=-_s;}
+ static int s;
+ int _s;
+
+ void fpong()
+ {
+ dumpOn( DBG << "Receiver " << _s << " <- " << 13 << " (" ) << ")" << endl;
+ }
+
+ void operator()( unsigned i )
+ { pong( i ); }
+
+ void pong( unsigned i )
+ {
+ dumpOn( DBG << "Receiver " << _s << " <- " << i << " (" ) << ")" << endl;
+ }
+
+ std::ostream & dumpOn( std::ostream & str ) const
+ {
+ return str << "Receiver " << _s << " connected signals: " << _connected_signals().size();
+ }
+};
+
+std::ostream & operator<<( std::ostream & str, const Receiver & obj )
+{ return obj.dumpOn( str ); }
+
+int Receiver::s;
+
+/******************************************************************
+**
+** FUNCTION NAME : main
+** FUNCTION TYPE : int
+*/
+int main( int argc, const char * argv[] )
+{
+ --argc; ++argv; // skip arg 0
+
+ Sender sender;
+ sender.ping();
+
+ Receiver rec;
+ sender.siga().connect( boost::bind( &Receiver::pong, &rec, _1 ) );
+ sender.ping();
+
+ {
+ Receiver recw;
+ sender.siga().connect( boost::ref(recw) );
+ sender.ping();
+
+ Receiver recx;
+ MIL << recx << endl;
+ sender.siga().connect( boost::bind( &Receiver::pong, &recx, _1 ) );
+ sender.sigb().connect( boost::bind( &Receiver::fpong, &recx ) );
+ MIL << recx << endl;
+ sender.ping();
+
+ Receiver recy;
+ connection cy( sender.siga().connect( boost::bind( &Receiver::pong, &recy, _1 ) ) );
+ sender.ping();
+
+ Receiver recz;
+ scoped_connection cz( sender.siga().connect( boost::bind( &Receiver::pong, &recz, _1 ) ) );
+ sender.ping();
+
+ cy.disconnect();
+ }
+
+ sender.ping();
+ return 0;
+}
+
diff --git a/devel/devel.ma/ma_test b/devel/devel.ma/ma_test
index 680d02a..4baea41 100755
--- a/devel/devel.ma/ma_test
+++ b/devel/devel.ma/ma_test
@@ -5,7 +5,7 @@
PRG=Main
SUDO=
if [ "$1" = -su ]; then
- SUDO=sudo
+ SUDO="sudo -E"
shift
fi
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org