From 0f6f54793bb92d2bbdd68d5cf524574f026984ab Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 8 May 2009 12:51:19 +0200 Subject: [PATCH] improve TestSetup testcase loading --- devel/devel.ma/DumpSolv.cc | 176 ++++++++++++++++++++++++++++++++++----------- tests/lib/TestSetup.h | 77 +++++++++++++++++++- 2 files changed, 210 insertions(+), 43 deletions(-) diff --git a/devel/devel.ma/DumpSolv.cc b/devel/devel.ma/DumpSolv.cc index 0972d99..a5ba541 100644 --- a/devel/devel.ma/DumpSolv.cc +++ b/devel/devel.ma/DumpSolv.cc @@ -1,10 +1,12 @@ #include "Tools.h" + #include #include #include #include "zypp/pool/GetResolvablesToInsDel.h" /////////////////////////////////////////////////////////////////// +#if 0 #include "zypp/parser/xml/ParseDef.h" #include "zypp/parser/xml/ParseDefConsume.h" #include "zypp/parser/xml/Reader.h" @@ -190,13 +192,20 @@ namespace zypp }; }; } +#endif /////////////////////////////////////////////////////////////////// static std::string appname( __FILE__ ); -void message( const std::string & msg_r ) +#define OUT USR +#define HEADL SEC << "===> " + +inline std::ostream & errmessage( const std::string & msg_r = std::string() ) { - cerr << "*** " << msg_r << endl; + cerr << "*** "; + if ( ! msg_r.empty() ) + cerr << msg_r << endl; + return cerr; } int usage( const std::string & msg_r = std::string(), int exit_r = 100 ) @@ -204,7 +213,7 @@ int usage( const std::string & msg_r = std::string(), int exit_r = 100 ) if ( ! msg_r.empty() ) { cerr << endl; - message( msg_r ); + errmessage( msg_r ); cerr << endl; } cerr << "Usage: " << appname << " TESTCASE" << endl; @@ -261,6 +270,117 @@ bool solve() /////////////////////////////////////////////////////////////////// +struct ArgList +{ + typedef std::vector::const_iterator const_iterator; + + ArgList() + {} + + ArgList( const std::string & line_r ) + { str::splitEscaped( line_r, std::back_inserter(_argv) ); } + + const_iterator begin() const { const_iterator ret =_argv.begin(); for ( unsigned i = _carg; i; --i ) ++ret; return ret; } + const_iterator end() const { return _argv.end(); } + + void clear() { _argv.clear(); _carg = 0; } + bool empty() const { return _argv.size() == _carg; } + unsigned size() const { return _argv.size() - _carg; } + + std::string & operator[]( int idx ) { return _argv[_carg+idx]; } + const std::string & operator[]( int idx ) const { return _argv[_carg+idx]; } + + std::string at( int idx ) const { return _carg+idx < _argv.size() ? _argv[_carg+idx] : std::string(); } + + unsigned carg() const { return _carg; } + void poparg( int cnt = 1 ) { _carg = arange( _carg + cnt ); } + + public: + std::vector & get() { return _argv; } + const std::vector & get() const { return _argv; } + private: + unsigned arange( int idx ) const { return idx < 0 ? 0 : std::min( unsigned(idx), _argv.size() ); } + private: + DefaultIntegral _carg; + std::vector _argv; +}; + +std::ostream & operator<<( std::ostream & str, const ArgList & obj ) +{ + for_( it, 0, obj.get().size() ) + { + str << ( it == obj.carg() ? " | " : " " ) << obj.get()[it]; + } + return str; +} + +/////////////////////////////////////////////////////////////////// +#define DELGATE(N,F) if ( argv.at(0) == #N ) { argv.poparg(); F( argv ); return; } +/////////////////////////////////////////////////////////////////// + +void listReposCmd( ArgList & argv ) +{ + errmessage() << "Not inplemented: " << argv << endl; +} + +void listIdent( IdString ident ) +{ + HEADL << "list " << ident << endl; + + ui::Selectable::Ptr sel( ui::Selectable::get( ident ) ); + OUT << dump(sel) << endl; + + sat::WhatProvides qp( (Capability( ident.id() )) ); + OUT << "Provided by " << qp << endl; + + +} + + +void listCmd( ArgList & argv ) +{ + DELGATE( repos, listReposCmd ); + + for_( it, argv.begin(), argv.end() ) + { + listIdent( IdString(*it) ); + } +} + +/////////////////////////////////////////////////////////////////// + +bool gocmd( ArgList & argv ) +{ + switch ( argv[0][0] ) + { +#define DOCMD(n) if ( argv[0] == #n ) { argv.poparg(); n##Cmd( argv ); return true; } + case 'e': + if ( argv[0] == "exit" ) { return false; } + break; + + case 'l': + DOCMD( list ); + break; +#undef DOCMD + } + // no command fall back to list + listCmd( argv ); + return true; +} + +void goprompt() +{ + std::cin.tie( &std::cout ); + ArgList argv; + do { + argv.clear(); + std::cout << "Hallo : "; + str::splitEscaped( iostr::getline( std::cin ), std::back_inserter(argv.get()) ); + } while ( argv.empty() || gocmd( argv ) ); +} + +/////////////////////////////////////////////////////////////////// + /****************************************************************** ** ** FUNCTION NAME : main @@ -272,52 +392,28 @@ int main( int argc, char * argv[] ) appname = Pathname::basename( argv[0] ); --argc; ++argv; - /////////////////////////////////////////////////////////////////// - Pathname mtest( "/suse/ma/BUGS/472099/zypper.solverTestCase" ); - Arch march( Arch_i686 ); + if ( !argc ) + return usage(); - while ( argc ) - { - --argc; - ++argv; - } + Pathname mtest( *argv ); + --argc; + ++argv; - if ( mtest.empty() ) + if ( ! PathInfo( mtest / "solver-test.xml" ).isFile() ) { - return usage( "Missing Testcase", 102 ); + return usage( "No testcase at " + mtest.asString() ); } /////////////////////////////////////////////////////////////////// + TestSetup test; + test.loadTestcaseRepos( mtest ); // <<< repos +#define GOCMD(c) { ArgList argv( #c ); gocmd( argv ); } + GOCMD( libsndfile ); + GOCMD( libsndfile1 ); - //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() ); - - { - //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_begin(pool), - make_filter_end(pool) ) << endl; + goprompt(); INT << "===[END]============================================" << endl << endl; zypp::base::LogControl::TmpLineWriter shutUp; diff --git a/tests/lib/TestSetup.h b/tests/lib/TestSetup.h index 1200972..2839db4 100644 --- a/tests/lib/TestSetup.h +++ b/tests/lib/TestSetup.h @@ -9,6 +9,8 @@ using boost::unit_test::test_case; #include "zypp/base/LogControl.h" #include "zypp/base/LogTools.h" +#include "zypp/base/InputStream.h" +#include "zypp/base/IOStream.h" #include "zypp/base/Flags.h" #include "zypp/ZYppFactory.h" #include "zypp/ZYpp.h" @@ -31,6 +33,18 @@ using namespace zypp; #define LABELED(V) #V << ":\t" << V +inline std::string getXmlNodeVal( const std::string & line_r, const std::string & node_r ) +{ + std::string::size_type pos = line_r.find( node_r + "=\"" ); + if ( pos != std::string::npos ) + { + pos += node_r.size() + 2; + std::string::size_type epos = line_r.find( "\"", pos ); + return line_r.substr( pos, epos-pos ); + } + return std::string(); +} + enum TestSetupOptionBits { TSO_CLEANROOT = (1 << 0) @@ -158,6 +172,14 @@ class TestSetup void loadRepo( const char * loc_r, const std::string & alias_r = std::string() ) { loadRepo( std::string( loc_r ? loc_r : "" ), alias_r ); } + private: + // repo data from solver-test.xml + struct RepoD { + DefaultIntegral priority; + std::string alias; + Url url; + }; + public: /** Directly load a helix repo from some testcase. * An empty alias is guessed. @@ -173,11 +195,50 @@ class TestSetup // Load repos included in a solver testcase. void loadTestcaseRepos( const Pathname & path_r ) { - if ( ! filesystem::PathInfo( path_r ).isDir() ) + filesystem::PathInfo pi( path_r / "solver-test.xml" ); + if ( ! pi.isFile() ) { - ERR << "No dir " << filesystem::PathInfo( path_r ) << endl; + ERR << "No testcase in " << filesystem::PathInfo( path_r ) << endl; return; } + // dumb parse + InputStream infile( pi.path() ); + Arch sysarch( Arch_empty ); + Url guessedUrl; + typedef std::map RepoI; + RepoI repoi; + for( iostr::EachLine in( infile ); in; in.next() ) + { + if ( str::hasPrefix( *in, "\t( getXmlNodeVal( *in, "priority" ) ); + repod.url = guessedUrl; + guessedUrl = Url(); + } + else if ( str::hasPrefix( *in, "\t- url " ) ) + { + std::string::size_type pos = in->find( ": " ); + if ( pos != std::string::npos ) + { + guessedUrl = Url( in->substr( pos+2 ) ); + } + } + else if ( str::hasPrefix( *in, "\t