5 * Copyright (c) 2009, Novell Inc.
7 * This program is licensed under the BSD license, read LICENSE.BSD
8 * for further information
22 #include "repo_solv.h"
23 #ifdef ENABLE_SUSEREPO
24 #include "repo_susetags.h"
27 #include "repo_updateinfoxml.h"
28 #include "repo_rpmmd.h"
31 #include "solverdebug.h"
33 #include "solv_xfopen.h"
36 showproblems(Solver *solv, Solvable *s, Queue *cand, Queue *badguys)
38 Pool *pool = solv->pool;
46 printf("can't install %s:\n", pool_solvable2str(pool, s));
47 while ((problem = solver_next_problem(solv, problem)) != 0)
49 solver_findallproblemrules(solv, problem, &rids);
50 for (jj = 0; jj < rids.count; jj++)
52 Id probr = rids.elements[jj];
56 solver_allruleinfos(solv, probr, &rinfo);
57 for (k = 0; k < rinfo.count; k += 4)
59 Id dep, source, target;
60 source = rinfo.elements[k + 1];
61 target = rinfo.elements[k + 2];
62 dep = rinfo.elements[k + 3];
63 switch (rinfo.elements[k])
65 case SOLVER_RULE_DISTUPGRADE:
67 case SOLVER_RULE_INFARCH:
68 printf(" %s has inferior architecture\n", pool_solvid2str(pool, source));
70 case SOLVER_RULE_UPDATE:
71 printf(" update rule for %s\n", pool_solvid2str(pool, source));
73 queue_pushunique(badguys, source);
76 /* only drop update problem packages from cand so that we see all problems of this patch */
77 for (l = 0; l < cand->count; l++)
78 if (cand->elements[l] == source || cand->elements[l] == -source)
84 for (l = 0; l < cand->count; l++)
85 if (cand->elements[l] < 0)
86 cand->elements[l] = -cand->elements[l];
89 for (l = 0; l < cand->count; l++)
90 if (cand->elements[l] == source)
92 cand->elements[l] = -source;
98 printf(" some dependency problem\n");
100 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
101 printf(" nothing provides requested %s\n", pool_dep2str(pool, dep));
103 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
104 printf(" package %s is not installable\n", pool_solvid2str(pool, source));
106 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
107 printf(" nothing provides %s needed by %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, source));
110 Reldep *rd = GETRELDEP(pool, dep);
111 if (!ISRELDEP(rd->name))
114 FOR_PROVIDES(rp, rpp, rd->name)
115 printf(" (we have %s)\n", pool_solvid2str(pool, rp));
119 case SOLVER_RULE_RPM_SAME_NAME:
120 printf(" cannot install both %s and %s\n", pool_solvid2str(pool, source), pool_solvid2str(pool, target));
122 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
123 printf(" package %s conflicts with %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
125 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
126 printf(" package %s obsoletes %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
128 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
129 printf(" package %s requires %s, but none of the providers can be installed\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
131 case SOLVER_RULE_RPM_SELF_CONFLICT:
132 printf(" package %s conflicts with %s provided by itself\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
143 toinst(Solver *solv, Repo *repo, Repo *instrepo)
145 Pool *pool = solv->pool;
151 solver_get_decisionqueue(solv, &q);
152 for (k = 0; k < q.count; k++)
155 if (p < 0 || p == SYSTEMSOLVABLE)
158 /* printf(" toinstall %s\n", pool_solvid2str(pool, p));*/
160 pool->solvables[p].repo = instrepo;
166 dump_instrepo(Repo *instrepo, Pool *pool)
171 printf("instrepo..\n");
172 FOR_REPO_SOLVABLES(instrepo, p, s)
173 printf(" %s\n", pool_solvable2str(pool, s));
178 frominst(Solver *solv, Repo *repo, Repo *instrepo)
180 Pool *pool = solv->pool;
183 for (k = 1; k < pool->nsolvables; k++)
184 if (pool->solvables[k].repo == instrepo)
185 pool->solvables[k].repo = repo;
192 printf("%s: <arch> <patchnameprefix> [--install-available] [repos] [--updaterepos] [repos]...\n"
193 "\t --install-available: installation repository is available during update\n"
194 "\t repos: repository ending in\n"
195 "\t\tpackages, packages.gz, primary.xml.gz, updateinfo.xml.gz or .solv\n",
205 int install_available;
210 #define SHOW_PATCH(c) if (!(c)->shown++) printf("%s:\n", pool_solvable2str(pool, s));
211 #define PERF_DEBUGGING 0
216 test_all_old_patches_included(context_t *c, Id pid)
220 Solvable *s = pool->solvables + pid;
221 /* Test 1: are all old patches included */
222 FOR_PROVIDES(p, pp, s->name)
224 Solvable *s2 = pool->solvables + p;
229 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) <= 0)
231 conp2 = s2->repo->idarraydata + s2->conflicts;
232 while ((con2 = *conp2++) != 0)
237 rd2 = GETRELDEP(pool, con2);
238 conp = s->repo->idarraydata + s->conflicts;
239 while ((con = *conp++) != 0)
243 rd = GETRELDEP(pool, con);
244 if (rd->name == rd2->name)
250 printf(" %s contained %s\n", pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name));
254 if (pool_evrcmp(pool, rd->evr, rd2->evr, EVRCMP_COMPARE) < 0)
257 printf(" %s required newer version %s-%s of %s-%s\n",
258 pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name), pool_dep2str(pool, rd2->evr),
259 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr));
268 test_all_packages_installable(context_t *c, Id pid)
274 unsigned int now, solver_runs;
276 Solvable *s = pool->solvables + pid;
280 now = solv_timems(0);
283 conp = s->repo->idarraydata + s->conflicts;
284 while ((con = *conp++) != 0)
286 FOR_PROVIDES(p, pp, con)
289 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
292 /* also set up some minimal system */
293 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
294 queue_push(&job, pool_str2id(pool, "rpm", 1));
295 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
296 queue_push(&job, pool_str2id(pool, "aaa_base", 1));
298 solv = solver_create(pool);
299 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
301 if (solver_solve(solv, &job))
304 printf("error installing original package\n");
305 showproblems(solv, s, 0, 0);
307 toinst(solv, c->repo, c->instrepo);
311 dump_instrepo(instrepo, pool);
314 if (!c->install_available)
317 for (i = 1; i < c->updatestart; i++)
319 if (pool->solvables[i].repo != c->repo || i == pid)
321 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
325 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
326 queue_push(&job, pid);
327 solv = solver_create(pool);
328 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
330 if (solver_solve(solv, &job))
333 showproblems(solv, s, 0, 0);
335 frominst(solv, c->repo, c->instrepo);
341 printf(" test_all_packages_installable took %d ms in %d runs\n", solv_timems(now), solver_runs);
345 test_can_upgrade_all_packages(context_t *c, Id pid)
354 unsigned int now, solver_runs;
355 Solvable *s = pool->solvables + pid;
359 queue_init(&badguys);
361 now = solv_timems(0);
364 /* Test 3: can we upgrade all packages? */
365 for (p = 1; p < pool->nsolvables; p++)
367 Solvable *s = pool->solvables + p;
370 if (strchr(pool_id2str(pool, s->name), ':'))
371 continue; /* only packages, please */
372 if (!pool_installable(pool, s))
374 queue_push(&cand, p);
378 solv = solver_create(pool);
380 for (i = 0; i < badguys.count; i++)
382 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE|SOLVER_WEAK);
383 queue_push(&job, badguys.elements[i]);
385 conp = s->repo->idarraydata + s->conflicts;
386 while ((con = *conp++) != 0)
388 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
389 queue_push(&job, con);
391 for (i = 0; i < cand.count; i++)
393 p = cand.elements[i];
394 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
398 solver_solve(solv, &job);
400 solver_printdecisions(solv);
402 /* put packages into installed repo and prune them from cand */
403 toinst(solv, c->repo, c->instrepo);
404 for (i = 0; i < cand.count; i++)
406 p = cand.elements[i];
407 if (p > 0 && solver_get_decisionlevel(solv, p) > 0)
408 cand.elements[i] = -p; /* drop candidate */
412 /* now the interesting part: test patch */
414 if (!c->install_available)
416 for (i = 1; i < c->updatestart; i++)
418 if (pool->solvables[i].repo != c->repo || i == pid)
420 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
424 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
425 queue_push(&job, pid);
426 solv = solver_create(pool);
427 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
429 if (solver_solve(solv, &job))
432 showproblems(solv, s, &cand, &badguys);
434 frominst(solv, c->repo, c->instrepo);
436 /* now drop all negative elements from cand */
437 for (i = j = 0; i < cand.count; i++)
439 if (cand.elements[i] < 0)
441 cand.elements[j++] = cand.elements[i];
444 break; /* no progress */
448 printf(" test_can_upgrade_all_packages took %d ms in %d runs\n", solv_timems(now), solver_runs);
452 test_no_ga_package_fulfills_dependency(context_t *c, Id pid)
455 Solvable *s = pool->solvables + pid;
457 /* Test 4: no GA package fulfills patch dependency */
458 conp = s->repo->idarraydata + s->conflicts;
459 while ((con = *conp++) != 0)
466 rd = GETRELDEP(pool, con);
467 FOR_PROVIDES(rp, rpp, rd->name)
469 Solvable *s2 = pool_id2solvable(pool, rp);
470 if (rp < c->updatestart
471 && pool_evrcmp(pool, rd->evr, s2->evr, EVRCMP_COMPARE) < 0
472 && pool_match_nevr_rel(pool, s2, rd->name)
476 printf(" conflict %s < %s satisfied by non-updated package %s\n",
477 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr), pool_solvable2str(pool, s2));
485 main(int argc, char **argv)
487 char *arch, *mypatch;
495 static const char* langs[] = {"en"};
497 c.install_available = 0;
505 pool = pool_create();
506 pool_setarch(pool, arch);
507 pool_set_languages(pool, langs, 1);
510 pool_setdebuglevel(pool, 2);
515 c.repo = repo_create(pool, 0);
516 c.instrepo = repo_create(pool, 0);
517 for (i = 3; i < argc; i++)
519 if (!strcmp(argv[i], "--updaterepos"))
521 c.updatestart = pool->nsolvables;
525 if (!strcmp(argv[i], "--install-available"))
527 c.install_available = 1;
532 if (!strcmp(argv[i], "-"))
534 else if ((fp = solv_xfopen(argv[i], 0)) == 0)
542 #ifdef ENABLE_SUSEREPO
543 else if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
545 repo_add_susetags(c.repo, fp, 0, 0, 0);
547 else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
549 repo_add_susetags(c.repo, fp, 0, 0, 0);
553 else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
555 repo_add_rpmmd(c.repo, fp, 0, 0);
557 else if (l >= 17 && !strcmp(argv[i] + l - 17, "updateinfo.xml.gz"))
559 repo_add_updateinfoxml(c.repo, fp, 0);
562 else if (repo_add_solv(c.repo, fp))
564 fprintf(stderr, "could not add repo %s\n", argv[i]);
571 pool_addfileprovides(pool);
573 /* bad hack ahead: clone repo */
574 c.instrepo->idarraydata = c.repo->idarraydata;
575 c.instrepo->idarraysize = c.repo->idarraysize;
576 c.instrepo->start = c.repo->start;
577 c.instrepo->end = c.repo->end;
578 c.instrepo->nsolvables = c.repo->nsolvables; /* sic! */
579 pool_set_installed(pool, c.instrepo);
580 pool_createwhatprovides(pool);
582 for (pid = 1; pid < pool->nsolvables; pid++)
586 s = pool->solvables + pid;
589 if (!pool_installable(pool, s))
591 pname = pool_id2str(pool, s->name);
592 if (strncmp(pname, "patch:", 6) != 0)
597 if (strncmp(mypatch, pname + 6, strlen(pname + 6)) != 0)
599 if (strcmp(mypatch, pname + 6) != 0)
601 l = strlen(pname + 6);
602 if (mypatch[l] != '-')
604 if (strcmp(mypatch + l + 1, pool_id2str(pool, s->evr)) != 0)
610 FOR_PROVIDES(p, pp, s->name)
612 Solvable *s2 = pool->solvables + p;
613 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) < 0)
617 /* printf("found a newer one for %s\n", pname+6); */
618 continue; /* found a newer one */
626 printf("testing patch %s-%s\n", pname + 6, pool_id2str(pool, s->evr));
629 test_all_old_patches_included(&c, pid);
630 test_all_packages_installable(&c, pid);
631 test_can_upgrade_all_packages(&c, pid);
632 test_no_ga_package_fulfills_dependency(&c, pid);