2 #include <zypp/ResObjects.h>
4 #include "zypp/pool/GetResolvablesToInsDel.h"
6 Pathname mroot( "/tmp/Bb" );
7 TestSetup test( mroot, Arch_ppc64 );
9 bool checkCaps( Capabilities caps_r );
13 typedef std::tr1::unordered_map<sat::Solvable,TriBool> CacheType;
14 typedef std::vector<sat::Solvable> AnalyzeStack;
21 * Test whether there is a runable provider for each requirement.
23 bool isRunable( const PoolItem & pi ) const
24 { return isRunable( pi.satSolvable() ); }
26 bool isRunable( sat::Solvable solv_r ) const
28 tribool & cent( get( solv_r ) );
29 if ( indeterminate( cent ) )
30 return (cent = analyze( solv_r ));
35 * Test whether there is a runable provider for each pre-requirement.
37 bool isInstallable( const PoolItem & pi ) const
38 { return isInstallable( pi.satSolvable() ); }
40 bool isInstallable( sat::Solvable solv_r ) const
42 tribool & cent( get( solv_r ) );
44 return true; // if runable then also installable.
45 return checkCaps( solv_r.prerequires() );
48 /** Clear the cache. */
58 * Determine whether this solvable is runable.
60 bool analyze( sat::Solvable solv_r ) const
62 if ( ! push( solv_r ) )
64 if ( _stack.back() != solv_r )
65 SEC << _ltag << "??Already on stack: " << solv_r << " " << _stack << endl;
66 // else it's a self requirement
67 return true; // assume runnable?
70 INT << _ltag << "->" << solv_r << " " << _stack << endl;
71 bool ret = checkCaps( solv_r.requires() );
74 ERR << " Not runable: " << solv_r << endl;
76 INT << _ltag << "<-" << solv_r << " " << _stack << endl;
78 if ( ! pop( solv_r ) )
80 INT << "Stack corrupted! Expect " << solv_r << " " << _stack << endl;
86 * For each capability find a runable provider.
88 bool checkCaps( Capabilities caps_r ) const
90 for_( it, caps_r.begin(), caps_r.end() )
92 if ( ! findRunableProvider( *it ) )
99 * Find a runable provider of a capability on system.
101 * A runable package is already installed and all of
102 * its requirements are met by runable packages.
104 bool findRunableProvider( Capability cap_r ) const
106 _MIL("findRunableProvider") << _ltag << " " << cap_r << endl;
107 sat::WhatProvides prv( cap_r );
108 for_( pit, prv.begin(), prv.end() )
112 _DBG("findRunableProvider") << _ltag << " by system" << endl;
113 return true; // noSolvable provides: i.e. system provides
117 if ( pi.status().onSystem() )
119 if ( isRunable( pi ) )
121 _DBG("findRunableProvider") << _ltag << " " << pi << endl;
126 _WAR("findRunableProvider") << _ltag << " " << pi << endl;
130 ERR << _ltag << " NO on system provider for " << cap_r << endl;
135 /** Push a new solvable to the AnalyzeStack, or return false is already on stack. */
136 bool push( sat::Solvable solv_r ) const
138 if ( find( _stack.begin(), _stack.end(), solv_r ) == _stack.end() )
140 _stack.push_back( solv_r );
141 _ltag = str::form( "[%04u]", _stack.size() );
148 /** Pop solvable from AnalyzeStack (expecting it to be \c solv_r). */
149 bool pop( sat::Solvable solv_r ) const
151 if ( _stack.back() == solv_r )
154 _ltag = str::form( "[%04u]", _stack.size() );
161 /** Return cache entry, initializing new entries with \ref indeterminate.*/
162 tribool & get( sat::Solvable solv_r ) const
164 CacheType::iterator it( _cache.find( solv_r ) );
165 if ( it == _cache.end() )
166 return (_cache[solv_r] = indeterminate);
167 return _cache[solv_r];
170 mutable CacheType _cache;
171 mutable AnalyzeStack _stack;
172 mutable std::string _ltag;
177 //==================================================
183 zypp::base::LogControl::TmpLineWriter shutUp;
185 rres = getZYpp()->resolver()->doUpgrade( u );
189 ERR << "upgrade " << rres << endl;
190 getZYpp()->resolver()->problems();
193 MIL << "upgrade " << rres << endl;
199 static unsigned run = 0;
200 USR << "Solve " << run++ << endl;
203 //zypp::base::LogControl::TmpLineWriter shutUp;
204 rres = getZYpp()->resolver()->resolvePool();
208 ERR << "resolve " << rres << endl;
209 getZYpp()->resolver()->problems();
219 ResPool pool( test.pool() );
220 for_( it, make_filter_begin<resfilter::ByTransact>(pool),
221 make_filter_end<resfilter::ByTransact>(pool) )
223 if ( it->status().transacts() &&
224 it->status().isBySolver() )
226 WAR << "MISSING " << *it << endl;
234 test.poolProxy().saveState();
237 inline void restore()
239 test.poolProxy().restoreState();
242 /******************************************************************
244 ** FUNCTION NAME : main
245 ** FUNCTION TYPE : int
247 int main( int argc, char * argv[] )
249 INT << "===[START]==========================================" << endl;
251 Pathname mroot( "/tmp/Bb" );
252 TestSetup test( mroot, Arch_ppc64 );
254 ResPool pool( test.pool() );
255 sat::Pool satpool( test.satpool() );
258 zypp::base::LogControl::TmpLineWriter shutUp;
260 test.loadTestcaseRepos( "/suse/ma/BUGS/439802/bug439802/YaST2/solverTestcase" );
265 PoolItem p = getPi<Package>( "bash", Edition("3.1-24.14"), Arch("ppc64") );
266 p.status().setTransact( true, ResStatus::USER );
271 zypp::base::LogControl::TmpLineWriter shutUp;
272 getPi<Product>( "SUSE_SLES", Edition("11"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
273 getPi<Package>( "sles-release", Edition("11-54.3"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
276 vdumpPoolStats( USR << "Transacting:"<< endl,
277 make_filter_begin<resfilter::ByTransact>(pool),
278 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
280 pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
282 vdumpPoolStats( USR << "Transacting:"<< endl,
283 make_filter_begin<resfilter::ByTransact>(pool),
284 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
287 for_( it, collect._toDelete.begin(), collect._toDelete.end() )
289 it->status().setTransact( true, ResStatus::USER );
291 // vdumpPoolStats( SEC << "Transacting:"<< endl,
292 // make_filter_begin<resfilter::ByTransact>(pool),
293 // make_filter_end<resfilter::ByTransact>(pool) ) << endl;
295 (rcache.isInstallable( *it ) ? MIL : ERR) << *it << " deletable?" << endl;
300 for_( it, collect._toInstall.begin(), collect._toInstall.end() )
302 it->status().setTransact( true, ResStatus::USER );
304 // vdumpPoolStats( SEC << "Transacting:"<< endl,
305 // make_filter_begin<resfilter::ByTransact>(pool),
306 // make_filter_end<resfilter::ByTransact>(pool) ) << endl;
307 (rcache.isInstallable( *it ) ? MIL : ERR) << *it << " installable?" << endl;
313 //getPi<>( "", "", Edition(""), Arch("") );
314 getPi<Product>( "SUSE_SLES", Edition("11"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
315 getPi<Package>( "sles-release", Edition("11-54.3"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
317 ResPool pool( test.pool() );
318 vdumpPoolStats( USR << "Transacting:"<< endl,
319 make_filter_begin<resfilter::ByTransact>(pool),
320 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
322 vdumpPoolStats( USR << "Transacting:"<< endl,
323 make_filter_begin<resfilter::ByTransact>(pool),
324 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
326 pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
327 MIL << "GetResolvablesToInsDel:" << endl << collect << endl;
331 // Collect until the 1st package from an unwanted media occurs.
332 // Further collection could violate install order.
333 bool hitUnwantedMedia = false;
334 typedef pool::GetResolvablesToInsDel::PoolItemList PoolItemList;
335 PoolItemList::iterator fst=collect._toInstall.end();
336 for ( PoolItemList::iterator it = collect._toInstall.begin(); it != collect._toInstall.end(); ++it)
338 ResObject::constPtr res( it->resolvable() );
340 if ( hitUnwantedMedia
341 || ( res->mediaNr() && res->mediaNr() != 1 ) )
343 if ( !hitUnwantedMedia )
345 hitUnwantedMedia = true;
348 dumpRange( WAR << "toInstall1: " << endl,
349 collect._toInstall.begin(), fst ) << endl;
350 dumpRange( WAR << "toInstall2: " << endl,
351 fst, collect._toInstall.end() ) << endl;
352 dumpRange( ERR << "toDelete: " << endl,
353 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
357 dumpRange( WAR << "toInstall: " << endl,
358 collect._toInstall.begin(), collect._toInstall.end() ) << endl;
359 dumpRange( ERR << "toDelete: " << endl,
360 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
362 INT << "===[END]============================================" << endl << endl;
370 INT << "===[END]============================================" << endl << endl;
371 zypp::base::LogControl::TmpLineWriter shutUp;