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;
96 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
97 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
98 case SOLVER_RULE_JOB_UNSUPPORTED:
100 case SOLVER_RULE_RPM:
101 printf(" some dependency problem\n");
103 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
104 printf(" nothing provides requested %s\n", pool_dep2str(pool, dep));
106 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
107 printf(" package %s is not installable\n", pool_solvid2str(pool, source));
109 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
110 printf(" nothing provides %s needed by %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, source));
113 Reldep *rd = GETRELDEP(pool, dep);
114 if (!ISRELDEP(rd->name))
117 FOR_PROVIDES(rp, rpp, rd->name)
118 printf(" (we have %s)\n", pool_solvid2str(pool, rp));
122 case SOLVER_RULE_RPM_SAME_NAME:
123 printf(" cannot install both %s and %s\n", pool_solvid2str(pool, source), pool_solvid2str(pool, target));
125 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
126 printf(" package %s conflicts with %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
128 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
129 printf(" package %s obsoletes %s provided by %s\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep), pool_solvid2str(pool, target));
131 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
132 printf(" package %s requires %s, but none of the providers can be installed\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
134 case SOLVER_RULE_RPM_SELF_CONFLICT:
135 printf(" package %s conflicts with %s provided by itself\n", pool_solvid2str(pool, source), pool_dep2str(pool, dep));
146 toinst(Solver *solv, Repo *repo, Repo *instrepo)
148 Pool *pool = solv->pool;
154 solver_get_decisionqueue(solv, &q);
155 for (k = 0; k < q.count; k++)
158 if (p < 0 || p == SYSTEMSOLVABLE)
161 /* printf(" toinstall %s\n", pool_solvid2str(pool, p));*/
163 pool->solvables[p].repo = instrepo;
169 dump_instrepo(Repo *instrepo, Pool *pool)
174 printf("instrepo..\n");
175 FOR_REPO_SOLVABLES(instrepo, p, s)
176 printf(" %s\n", pool_solvable2str(pool, s));
181 frominst(Solver *solv, Repo *repo, Repo *instrepo)
183 Pool *pool = solv->pool;
186 for (k = 1; k < pool->nsolvables; k++)
187 if (pool->solvables[k].repo == instrepo)
188 pool->solvables[k].repo = repo;
195 printf("%s: <arch> <patchnameprefix> [--install-available] [repos] [--updaterepos] [repos]...\n"
196 "\t --install-available: installation repository is available during update\n"
197 "\t repos: repository ending in\n"
198 "\t\tpackages, packages.gz, primary.xml.gz, updateinfo.xml.gz or .solv\n",
208 int install_available;
213 #define SHOW_PATCH(c) if (!(c)->shown++) printf("%s:\n", pool_solvable2str(pool, s));
214 #define PERF_DEBUGGING 0
219 test_all_old_patches_included(context_t *c, Id pid)
223 Solvable *s = pool->solvables + pid;
224 /* Test 1: are all old patches included */
225 FOR_PROVIDES(p, pp, s->name)
227 Solvable *s2 = pool->solvables + p;
232 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) <= 0)
234 conp2 = s2->repo->idarraydata + s2->conflicts;
235 while ((con2 = *conp2++) != 0)
240 rd2 = GETRELDEP(pool, con2);
241 conp = s->repo->idarraydata + s->conflicts;
242 while ((con = *conp++) != 0)
246 rd = GETRELDEP(pool, con);
247 if (rd->name == rd2->name)
253 printf(" %s contained %s\n", pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name));
257 if (pool_evrcmp(pool, rd->evr, rd2->evr, EVRCMP_COMPARE) < 0)
260 printf(" %s required newer version %s-%s of %s-%s\n",
261 pool_solvable2str(pool, s2), pool_dep2str(pool, rd2->name), pool_dep2str(pool, rd2->evr),
262 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr));
271 test_all_packages_installable(context_t *c, Id pid)
277 unsigned int now, solver_runs;
279 Solvable *s = pool->solvables + pid;
283 now = solv_timems(0);
286 conp = s->repo->idarraydata + s->conflicts;
287 while ((con = *conp++) != 0)
289 FOR_PROVIDES(p, pp, con)
292 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
295 /* also set up some minimal system */
296 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
297 queue_push(&job, pool_str2id(pool, "rpm", 1));
298 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
299 queue_push(&job, pool_str2id(pool, "aaa_base", 1));
301 solv = solver_create(pool);
302 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
304 if (solver_solve(solv, &job))
307 printf("error installing original package\n");
308 showproblems(solv, s, 0, 0);
310 toinst(solv, c->repo, c->instrepo);
314 dump_instrepo(instrepo, pool);
317 if (!c->install_available)
320 for (i = 1; i < c->updatestart; i++)
322 if (pool->solvables[i].repo != c->repo || i == pid)
324 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
328 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
329 queue_push(&job, pid);
330 solv = solver_create(pool);
331 /* solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1); */
333 if (solver_solve(solv, &job))
336 showproblems(solv, s, 0, 0);
338 frominst(solv, c->repo, c->instrepo);
344 printf(" test_all_packages_installable took %d ms in %d runs\n", solv_timems(now), solver_runs);
348 test_can_upgrade_all_packages(context_t *c, Id pid)
357 unsigned int now, solver_runs;
358 Solvable *s = pool->solvables + pid;
362 queue_init(&badguys);
364 now = solv_timems(0);
367 /* Test 3: can we upgrade all packages? */
368 for (p = 1; p < pool->nsolvables; p++)
370 Solvable *s = pool->solvables + p;
373 if (strchr(pool_id2str(pool, s->name), ':'))
374 continue; /* only packages, please */
375 if (!pool_installable(pool, s))
377 queue_push(&cand, p);
381 solv = solver_create(pool);
383 for (i = 0; i < badguys.count; i++)
385 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE|SOLVER_WEAK);
386 queue_push(&job, badguys.elements[i]);
388 conp = s->repo->idarraydata + s->conflicts;
389 while ((con = *conp++) != 0)
391 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES|SOLVER_WEAK);
392 queue_push(&job, con);
394 for (i = 0; i < cand.count; i++)
396 p = cand.elements[i];
397 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK);
401 solver_solve(solv, &job);
403 solver_printdecisions(solv);
405 /* put packages into installed repo and prune them from cand */
406 toinst(solv, c->repo, c->instrepo);
407 for (i = 0; i < cand.count; i++)
409 p = cand.elements[i];
410 if (p > 0 && solver_get_decisionlevel(solv, p) > 0)
411 cand.elements[i] = -p; /* drop candidate */
415 /* now the interesting part: test patch */
417 if (!c->install_available)
419 for (i = 1; i < c->updatestart; i++)
421 if (pool->solvables[i].repo != c->repo || i == pid)
423 queue_push(&job, SOLVER_ERASE|SOLVER_SOLVABLE);
427 queue_push(&job, SOLVER_INSTALL|SOLVER_SOLVABLE);
428 queue_push(&job, pid);
429 solv = solver_create(pool);
430 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
432 if (solver_solve(solv, &job))
435 showproblems(solv, s, &cand, &badguys);
437 frominst(solv, c->repo, c->instrepo);
439 /* now drop all negative elements from cand */
440 for (i = j = 0; i < cand.count; i++)
442 if (cand.elements[i] < 0)
444 cand.elements[j++] = cand.elements[i];
447 break; /* no progress */
451 printf(" test_can_upgrade_all_packages took %d ms in %d runs\n", solv_timems(now), solver_runs);
455 test_no_ga_package_fulfills_dependency(context_t *c, Id pid)
458 Solvable *s = pool->solvables + pid;
460 /* Test 4: no GA package fulfills patch dependency */
461 conp = s->repo->idarraydata + s->conflicts;
462 while ((con = *conp++) != 0)
469 rd = GETRELDEP(pool, con);
470 FOR_PROVIDES(rp, rpp, rd->name)
472 Solvable *s2 = pool_id2solvable(pool, rp);
473 if (rp < c->updatestart
474 && pool_evrcmp(pool, rd->evr, s2->evr, EVRCMP_COMPARE) < 0
475 && pool_match_nevr_rel(pool, s2, rd->name)
479 printf(" conflict %s < %s satisfied by non-updated package %s\n",
480 pool_dep2str(pool, rd->name), pool_dep2str(pool, rd->evr), pool_solvable2str(pool, s2));
488 main(int argc, char **argv)
490 char *arch, *mypatch;
498 static const char* langs[] = {"en"};
500 c.install_available = 0;
508 pool = pool_create();
509 pool_setarch(pool, arch);
510 pool_set_languages(pool, langs, 1);
513 pool_setdebuglevel(pool, 2);
518 c.repo = repo_create(pool, 0);
519 c.instrepo = repo_create(pool, 0);
520 for (i = 3; i < argc; i++)
522 if (!strcmp(argv[i], "--updaterepos"))
524 c.updatestart = pool->nsolvables;
528 if (!strcmp(argv[i], "--install-available"))
530 c.install_available = 1;
535 if (!strcmp(argv[i], "-"))
537 else if ((fp = solv_xfopen(argv[i], 0)) == 0)
546 #ifdef ENABLE_SUSEREPO
547 else if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
549 r = repo_add_susetags(c.repo, fp, 0, 0, 0);
551 else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
553 r = repo_add_susetags(c.repo, fp, 0, 0, 0);
557 else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
559 r = repo_add_rpmmd(c.repo, fp, 0, 0);
561 else if (l >= 17 && !strcmp(argv[i] + l - 17, "updateinfo.xml.gz"))
563 r = repo_add_updateinfoxml(c.repo, fp, 0);
567 r = repo_add_solv(c.repo, fp, 0);
570 fprintf(stderr, "could not add repo %s: %s\n", argv[i], pool_errstr(pool));
577 pool_addfileprovides(pool);
579 /* bad hack ahead: clone repo */
580 c.instrepo->idarraydata = c.repo->idarraydata;
581 c.instrepo->idarraysize = c.repo->idarraysize;
582 c.instrepo->start = c.repo->start;
583 c.instrepo->end = c.repo->end;
584 c.instrepo->nsolvables = c.repo->nsolvables; /* sic! */
585 pool_set_installed(pool, c.instrepo);
586 pool_createwhatprovides(pool);
588 for (pid = 1; pid < pool->nsolvables; pid++)
592 s = pool->solvables + pid;
595 if (!pool_installable(pool, s))
597 pname = pool_id2str(pool, s->name);
598 if (strncmp(pname, "patch:", 6) != 0)
603 if (strncmp(mypatch, pname + 6, strlen(pname + 6)) != 0)
605 if (strcmp(mypatch, pname + 6) != 0)
607 l = strlen(pname + 6);
608 if (mypatch[l] != '-')
610 if (strcmp(mypatch + l + 1, pool_id2str(pool, s->evr)) != 0)
616 FOR_PROVIDES(p, pp, s->name)
618 Solvable *s2 = pool->solvables + p;
619 if (pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE) < 0)
623 /* printf("found a newer one for %s\n", pname+6); */
624 continue; /* found a newer one */
632 printf("testing patch %s-%s\n", pname + 6, pool_id2str(pool, s->evr));
635 test_all_old_patches_included(&c, pid);
636 test_all_packages_installable(&c, pid);
637 test_can_upgrade_all_packages(&c, pid);
638 test_no_ga_package_fulfills_dependency(&c, pid);