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 #include "repo_susetags.h"
24 #include "repo_updateinfoxml.h"
25 #include "repo_rpmmd.h"
27 #include "solverdebug.h"
29 #include "solv_xfopen.h"
32 showproblems(Solver *solv, Solvable *s, Queue *cand, Queue *badguys)
34 Pool *pool = solv->pool;
42 printf("can't install %s:\n", pool_solvable2str(pool, s));
43 while ((problem = solver_next_problem(solv, problem)) != 0)
45 solver_findallproblemrules(solv, problem, &rids);
46 for (jj = 0; jj < rids.count; jj++)
48 Id probr = rids.elements[jj];
52 solver_allruleinfos(solv, probr, &rinfo);
53 for (k = 0; k < rinfo.count; k += 4)
55 Id dep, source, target;
56 source = rinfo.elements[k + 1];
57 target = rinfo.elements[k + 2];
58 dep = rinfo.elements[k + 3];
59 switch (rinfo.elements[k])
61 case SOLVER_RULE_DISTUPGRADE:
63 case SOLVER_RULE_INFARCH:
64 printf(" %s has inferior architecture\n", pool_solvid2str(pool, source));
66 case SOLVER_RULE_UPDATE:
67 printf(" update rule for %s\n", pool_solvid2str(pool, source));
69 queue_pushunique(badguys, source);
72 /* only drop update problem packages from cand so that we see all problems of this patch */
73 for (l = 0; l < cand->count; l++)
74 if (cand->elements[l] == source || cand->elements[l] == -source)
80 for (l = 0; l < cand->count; l++)
81 if (cand->elements[l] < 0)
82 cand->elements[l] = -cand->elements[l];
85 for (l = 0; l < cand->count; l++)
86 if (cand->elements[l] == source)
88 cand->elements[l] = -source;
94 printf(" some dependency problem\n");
96 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
97 printf(" nothing provides requested %s\n", pool_dep2str(pool, dep));
99 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
100 printf(" package %s is not installable\n", pool_solvid2str(pool, source));
102 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
103 printf(" nothing provides %s needed by %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, source));
106 Reldep *rd = GETRELDEP(pool, dep);
107 if (!ISRELDEP(rd->name))
110 FOR_PROVIDES(rp, rpp, rd->name)
111 printf(" (we have %s)\n", pool_solvid2str(pool, rp));
115 case SOLVER_RULE_RPM_SAME_NAME:
116 printf(" cannot install both %s and %s\n", pool_solvid2str(pool, source), pool_solvid2str(pool, target));
118 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
119 printf(" package %s conflicts with %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
121 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
122 printf(" package %s obsoletes %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
124 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
125 printf(" package %s requires %s, but none of the providers can be installed\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
127 case SOLVER_RULE_RPM_SELF_CONFLICT:
128 printf(" package %s conflicts with %s provided by itself\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
139 toinst(Solver *solv, Repo *repo, Repo *instrepo)
141 Pool *pool = solv->pool;
147 solver_get_decisionqueue(solv, &q);
148 for (k = 0; k < q.count; k++)
151 if (p < 0 || p == SYSTEMSOLVABLE)
154 /* printf(" toinstall %s\n", pool_solvid2str(pool, p));*/
156 pool->solvables[p].repo = instrepo;
162 dump_instrepo(Repo *instrepo, Pool *pool)
167 printf("instrepo..\n");
168 FOR_REPO_SOLVABLES(instrepo, p, s)
169 printf(" %s\n", pool_solvable2str(pool, s));
174 frominst(Solver *solv, Repo *repo, Repo *instrepo)
176 Pool *pool = solv->pool;
179 for (k = 1; k < pool->nsolvables; k++)
180 if (pool->solvables[k].repo == instrepo)
181 pool->solvables[k].repo = repo;
188 printf("%s: <arch> <patchnameprefix> [--install-available] [repos] [--updaterepos] [repos]...\n"
189 "\t --install-available: installation repository is available during update\n"
190 "\t repos: repository ending in\n"
191 "\t\tpackages, packages.gz, primary.xml.gz, updateinfo.xml.gz or .solv\n",
201 int install_available;
206 #define SHOW_PATCH(c) if (!(c)->shown++) printf("%s:\n", pool_solvable2str(pool, s));
207 #define PERF_DEBUGGING 0
212 test_all_old_patches_included(context_t *c, Id pid)
216 Solvable *s = pool->solvables + pid;
217 /* Test 1: are all old patches included */
218 FOR_PROVIDES(p, pp, s->name)
220 Solvable *s2 = pool->solvables + p;
225 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) <= 0)
227 conp2 = s2->repo->idarraydata + s2->conflicts;
228 while ((con2 = *conp2++) != 0)
233 rd2 = GETRELDEP(pool, con2);
234 conp = s->repo->idarraydata + s->conflicts;
235 while ((con = *conp++) != 0)
239 rd = GETRELDEP(pool, con);
240 if (rd->name == rd2->name)
246 printf(" %s contained %s\n", pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name));
250 if (pool_evrcmp(pool, rd->evr, rd2->evr, EVRCMP_COMPARE) < 0)
253 printf(" %s required newer version %s-%s of %s-%s\n",
254 pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name), pool_dep2str(pool, rd2->evr),
255 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr));
264 test_all_packages_installable(context_t *c, Id pid)
270 unsigned int now, solver_runs;
272 Solvable *s = pool->solvables + pid;
276 now = solv_timems(0);
279 conp = s->repo->idarraydata + s->conflicts;
280 while ((con = *conp++) != 0)
282 FOR_PROVIDES(p, pp, con)
285 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
288 /* also set up some minimal system */
289 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
290 queue_push(&job, pool_str2id(pool, "rpm", 1));
291 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
292 queue_push(&job, pool_str2id(pool, "aaa_base", 1));
294 solv = solver_create(pool);
295 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
297 if (solver_solve(solv, &job))
300 printf("error installing original package\n");
301 showproblems(solv, s, 0, 0);
303 toinst(solv, c->repo, c->instrepo);
307 dump_instrepo(instrepo, pool);
310 if (!c->install_available)
313 for (i = 1; i < c->updatestart; i++)
315 if (pool->solvables[i].repo != c->repo || i == pid)
317 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
321 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
322 queue_push(&job, pid);
323 solv = solver_create(pool);
324 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
326 if (solver_solve(solv, &job))
329 showproblems(solv, s, 0, 0);
331 frominst(solv, c->repo, c->instrepo);
337 printf(" test_all_packages_installable took %d ms in %d runs\n", solv_timems(now), solver_runs);
341 test_can_upgrade_all_packages(context_t *c, Id pid)
350 unsigned int now, solver_runs;
351 Solvable *s = pool->solvables + pid;
355 queue_init(&badguys);
357 now = solv_timems(0);
360 /* Test 3: can we upgrade all packages? */
361 for (p = 1; p < pool->nsolvables; p++)
363 Solvable *s = pool->solvables + p;
366 if (strchr(pool_id2str(pool, s->name), ':'))
367 continue; /* only packages, please */
368 if (!pool_installable(pool, s))
370 queue_push(&cand, p);
374 solv = solver_create(pool);
376 for (i = 0; i < badguys.count; i++)
378 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE|SOLVER_WEAK);
379 queue_push(&job, badguys.elements[i]);
381 conp = s->repo->idarraydata + s->conflicts;
382 while ((con = *conp++) != 0)
384 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
385 queue_push(&job, con);
387 for (i = 0; i < cand.count; i++)
389 p = cand.elements[i];
390 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
394 solver_solve(solv, &job);
396 solver_printdecisions(solv);
398 /* put packages into installed repo and prune them from cand */
399 toinst(solv, c->repo, c->instrepo);
400 for (i = 0; i < cand.count; i++)
402 p = cand.elements[i];
403 if (p > 0 && solver_get_decisionlevel(solv, p) > 0)
404 cand.elements[i] = -p; /* drop candidate */
408 /* now the interesting part: test patch */
410 if (!c->install_available)
412 for (i = 1; i < c->updatestart; i++)
414 if (pool->solvables[i].repo != c->repo || i == pid)
416 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
420 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
421 queue_push(&job, pid);
422 solv = solver_create(pool);
423 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
425 if (solver_solve(solv, &job))
428 showproblems(solv, s, &cand, &badguys);
430 frominst(solv, c->repo, c->instrepo);
432 /* now drop all negative elements from cand */
433 for (i = j = 0; i < cand.count; i++)
435 if (cand.elements[i] < 0)
437 cand.elements[j++] = cand.elements[i];
440 break; /* no progress */
444 printf(" test_can_upgrade_all_packages took %d ms in %d runs\n", solv_timems(now), solver_runs);
448 test_no_ga_package_fulfills_dependency(context_t *c, Id pid)
451 Solvable *s = pool->solvables + pid;
453 /* Test 4: no GA package fulfills patch dependency */
454 conp = s->repo->idarraydata + s->conflicts;
455 while ((con = *conp++) != 0)
462 rd = GETRELDEP(pool, con);
463 FOR_PROVIDES(rp, rpp, rd->name)
465 Solvable *s2 = pool_id2solvable(pool, rp);
466 if (rp < c->updatestart
467 && pool_evrcmp(pool, rd->evr, s2->evr, EVRCMP_COMPARE) < 0
468 && pool_match_nevr_rel(pool, s2, rd->name)
472 printf(" conflict %s < %s satisfied by non-updated package %s\n",
473 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr), pool_solvable2str(pool, s2));
481 main(int argc, char **argv)
483 char *arch, *mypatch;
492 c.install_available = 0;
500 pool = pool_create();
501 pool_setarch(pool, arch);
502 static const char* langs[] = {"en"};
503 pool_set_languages(pool, langs, 1);
506 pool_setdebuglevel(pool, 2);
511 c.repo = repo_create(pool, 0);
512 c.instrepo = repo_create(pool, 0);
513 for (i = 3; i < argc; i++)
515 if (!strcmp(argv[i], "--updaterepos"))
517 c.updatestart = pool->nsolvables;
521 if (!strcmp(argv[i], "--install-available"))
523 c.install_available = 1;
528 if (!strcmp(argv[i], "-"))
530 else if ((fp = solv_xfopen(argv[i], 0)) == 0)
535 if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
537 repo_add_susetags(c.repo, fp, 0, 0, 0);
539 else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
541 repo_add_susetags(c.repo, fp, 0, 0, 0);
543 else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
545 repo_add_rpmmd(c.repo, fp, 0, 0);
547 else if (l >= 17 && !strcmp(argv[i] + l - 17, "updateinfo.xml.gz"))
549 repo_add_updateinfoxml(c.repo, fp, 0);
551 else if (repo_add_solv(c.repo, fp))
553 fprintf(stderr, "could not add repo %s\n", argv[i]);
560 pool_addfileprovides(pool);
562 /* bad hack ahead: clone repo */
563 c.instrepo->idarraydata = c.repo->idarraydata;
564 c.instrepo->idarraysize = c.repo->idarraysize;
565 c.instrepo->start = c.repo->start;
566 c.instrepo->end = c.repo->end;
567 c.instrepo->nsolvables = c.repo->nsolvables; /* sic! */
568 pool_set_installed(pool, c.instrepo);
569 pool_createwhatprovides(pool);
571 for (pid = 1; pid < pool->nsolvables; pid++)
574 Solvable *s = pool->solvables + pid;
577 if (!pool_installable(pool, s))
579 pname = pool_id2str(pool, s->name);
580 if (strncmp(pname, "patch:", 6) != 0)
585 if (strncmp(mypatch, pname + 6, strlen(pname + 6)) != 0)
587 if (strcmp(mypatch, pname + 6) != 0)
589 l = strlen(pname + 6);
590 if (mypatch[l] != '-')
592 if (strcmp(mypatch + l + 1, pool_id2str(pool, s->evr)) != 0)
598 FOR_PROVIDES(p, pp, s->name)
600 Solvable *s2 = pool->solvables + p;
601 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) < 0)
605 /* printf("found a newer one for %s\n", pname+6); */
606 continue; /* found a newer one */
614 printf("testing patch %s-%s\n", pname + 6, pool_id2str(pool, s->evr));
617 test_all_old_patches_included(&c, pid);
618 test_all_packages_installable(&c, pid);
619 test_can_upgrade_all_packages(&c, pid);
620 test_no_ga_package_fulfills_dependency(&c, pid);