2 * Copyright (c) 2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "poolvendor.h"
21 #include "repo_solv.h"
23 #include "solverdebug.h"
26 #include "selection.h"
27 #include "solv_xfopen.h"
30 #include "tools_util.h"
32 static struct job2str {
36 { SOLVER_NOOP, "noop" },
37 { SOLVER_INSTALL, "install" },
38 { SOLVER_ERASE, "erase" },
39 { SOLVER_UPDATE, "update" },
40 { SOLVER_WEAKENDEPS, "weakendeps" },
41 { SOLVER_MULTIVERSION, "multiversion" },
42 { SOLVER_MULTIVERSION, "noobsoletes" }, /* old name */
43 { SOLVER_LOCK, "lock" },
44 { SOLVER_DISTUPGRADE, "distupgrade" },
45 { SOLVER_VERIFY, "verify" },
46 { SOLVER_DROP_ORPHANED, "droporphaned" },
47 { SOLVER_USERINSTALLED, "userinstalled" },
48 { SOLVER_ALLOWUNINSTALL, "allowuninstall" },
49 { SOLVER_FAVOR, "favor" },
50 { SOLVER_DISFAVOR, "disfavor" },
54 static struct jobflags2str {
58 { SOLVER_WEAK, "weak" },
59 { SOLVER_ESSENTIAL, "essential" },
60 { SOLVER_CLEANDEPS, "cleandeps" },
61 { SOLVER_ORUPDATE, "orupdate" },
62 { SOLVER_FORCEBEST, "forcebest" },
63 { SOLVER_TARGETED, "targeted" },
64 { SOLVER_NOTBYUSER, "notbyuser" },
65 { SOLVER_SETEV, "setev" },
66 { SOLVER_SETEVR, "setevr" },
67 { SOLVER_SETARCH, "setarch" },
68 { SOLVER_SETVENDOR, "setvendor" },
69 { SOLVER_SETREPO, "setrepo" },
70 { SOLVER_NOAUTOSET, "noautoset" },
74 static struct resultflags2str {
77 } resultflags2str[] = {
78 { TESTCASE_RESULT_TRANSACTION, "transaction" },
79 { TESTCASE_RESULT_PROBLEMS, "problems" },
80 { TESTCASE_RESULT_ORPHANED, "orphaned" },
81 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
82 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
83 { TESTCASE_RESULT_ALTERNATIVES, "alternatives" },
84 { TESTCASE_RESULT_RULES, "rules" },
85 { TESTCASE_RESULT_GENID, "genid" },
86 { TESTCASE_RESULT_REASON, "reason" },
90 static struct solverflags2str {
94 } solverflags2str[] = {
95 { SOLVER_FLAG_ALLOW_DOWNGRADE, "allowdowngrade", 0 },
96 { SOLVER_FLAG_ALLOW_NAMECHANGE, "allownamechange", 1 },
97 { SOLVER_FLAG_ALLOW_ARCHCHANGE, "allowarchchange", 0 },
98 { SOLVER_FLAG_ALLOW_VENDORCHANGE, "allowvendorchange", 0 },
99 { SOLVER_FLAG_ALLOW_UNINSTALL, "allowuninstall", 0 },
100 { SOLVER_FLAG_NO_UPDATEPROVIDE, "noupdateprovide", 0 },
101 { SOLVER_FLAG_SPLITPROVIDES, "splitprovides", 0 },
102 { SOLVER_FLAG_IGNORE_RECOMMENDED, "ignorerecommended", 0 },
103 { SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, "addalreadyrecommended", 0 },
104 { SOLVER_FLAG_NO_INFARCHCHECK, "noinfarchcheck", 0 },
105 { SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES, "keepexplicitobsoletes", 0 },
106 { SOLVER_FLAG_BEST_OBEY_POLICY, "bestobeypolicy", 0 },
107 { SOLVER_FLAG_NO_AUTOTARGET, "noautotarget", 0 },
108 { SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, "dupallowdowngrade", 1 },
109 { SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, "dupallowarchchange", 1 },
110 { SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, "dupallowvendorchange", 1 },
111 { SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, "dupallownamechange", 1 },
112 { SOLVER_FLAG_KEEP_ORPHANS, "keeporphans", 0 },
113 { SOLVER_FLAG_BREAK_ORPHANS, "breakorphans", 0 },
114 { SOLVER_FLAG_FOCUS_INSTALLED, "focusinstalled", 0 },
115 { SOLVER_FLAG_YUM_OBSOLETES, "yumobsoletes", 0 },
116 { SOLVER_FLAG_NEED_UPDATEPROVIDE, "needupdateprovide", 0 },
117 { SOLVER_FLAG_URPM_REORDER, "urpmreorder", 0 },
118 { SOLVER_FLAG_FOCUS_BEST, "focusbest", 0 },
119 { SOLVER_FLAG_STRONG_RECOMMENDS, "strongrecommends", 0 },
120 { SOLVER_FLAG_INSTALL_ALSO_UPDATES, "installalsoupdates", 0 },
124 static struct poolflags2str {
128 } poolflags2str[] = {
129 { POOL_FLAG_PROMOTEEPOCH, "promoteepoch", 0 },
130 { POOL_FLAG_FORBIDSELFCONFLICTS, "forbidselfconflicts", 0 },
131 { POOL_FLAG_OBSOLETEUSESPROVIDES, "obsoleteusesprovides", 0 },
132 { POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES, "implicitobsoleteusesprovides", 0 },
133 { POOL_FLAG_OBSOLETEUSESCOLORS, "obsoleteusescolors", 0 },
134 { POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS, "implicitobsoleteusescolors", 0 },
135 { POOL_FLAG_NOINSTALLEDOBSOLETES, "noinstalledobsoletes", 0 },
136 { POOL_FLAG_HAVEDISTEPOCH, "havedistepoch", 0 },
137 { POOL_FLAG_NOOBSOLETESMULTIVERSION, "noobsoletesmultiversion", 0 },
138 { POOL_FLAG_ADDFILEPROVIDESFILTERED, "addfileprovidesfiltered", 0 },
139 { POOL_FLAG_NOWHATPROVIDESAUX, "nowhatprovidesaux", 0 },
143 static struct disttype2str {
147 { DISTTYPE_RPM, "rpm" },
148 { DISTTYPE_DEB, "deb" },
149 { DISTTYPE_ARCH, "arch" },
150 { DISTTYPE_HAIKU, "haiku" },
154 static struct selflags2str {
158 { SELECTION_NAME, "name" },
159 { SELECTION_PROVIDES, "provides" },
160 { SELECTION_FILELIST, "filelist" },
161 { SELECTION_CANON, "canon" },
162 { SELECTION_DOTARCH, "dotarch" },
163 { SELECTION_REL, "rel" },
164 { SELECTION_INSTALLED_ONLY, "installedonly" },
165 { SELECTION_GLOB, "glob" },
166 { SELECTION_FLAT, "flat" },
167 { SELECTION_NOCASE, "nocase" },
168 { SELECTION_SOURCE_ONLY, "sourceonly" },
169 { SELECTION_WITH_SOURCE, "withsource" },
173 static const char *features[] = {
174 #ifdef ENABLE_LINKED_PKGS
177 #ifdef ENABLE_COMPLEX_DEPS
183 typedef struct strqueue {
188 #define STRQUEUE_BLOCK 63
191 strqueue_init(Strqueue *q)
198 strqueue_free(Strqueue *q)
201 for (i = 0; i < q->nstr; i++)
202 solv_free(q->str[i]);
203 q->str = solv_free(q->str);
208 strqueue_push(Strqueue *q, const char *s)
210 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
211 q->str[q->nstr++] = solv_strdup(s);
215 strqueue_pushjoin(Strqueue *q, const char *s1, const char *s2, const char *s3)
217 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
218 q->str[q->nstr++] = solv_dupjoin(s1, s2, s3);
222 strqueue_sort_cmp(const void *ap, const void *bp, void *dp)
224 const char *a = *(const char **)ap;
225 const char *b = *(const char **)bp;
226 return strcmp(a ? a : "", b ? b : "");
230 strqueue_sort(Strqueue *q)
233 solv_sort(q->str, q->nstr, sizeof(*q->str), strqueue_sort_cmp, 0);
237 strqueue_sort_u(Strqueue *q)
241 for (i = j = 0; i < q->nstr; i++)
242 if (!j || strqueue_sort_cmp(q->str + i, q->str + j - 1, 0) != 0)
243 q->str[j++] = q->str[i];
248 strqueue_join(Strqueue *q)
252 for (i = 0; i < q->nstr; i++)
254 l += strlen(q->str[i]) + 1;
255 l++; /* trailing \0 */
258 for (i = 0; i < q->nstr; i++)
261 strcpy(rp, q->str[i]);
270 strqueue_split(Strqueue *q, const char *s)
275 while ((p = strchr(s, '\n')) != 0)
277 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
278 q->str[q->nstr] = solv_malloc(p - s + 1);
280 memcpy(q->str[q->nstr], s, p - s);
281 q->str[q->nstr][p - s] = 0;
290 strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
293 while (i < sq1->nstr && j < sq2->nstr)
295 int r = strqueue_sort_cmp(sq1->str + i, sq2->str + j, 0);
299 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
301 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
303 while (i < sq1->nstr)
304 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
305 while (j < sq2->nstr)
306 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
311 testcase_id2str(Pool *pool, Id id, int isname)
313 const char *s = pool_id2str(pool, id);
316 int bad = 0, paren = 0, parenbad = 0;
322 if (strchr("[(<=>!", *s))
324 if (!strncmp(s, "namespace:", 10))
326 for (ss = s + bad; *ss; ss++)
328 if (*ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')')
331 paren = paren == 0 ? 1 : -1;
334 paren = paren == 1 ? 0 : -1;
339 if (isname && ss - s > 4 && !strcmp(ss - 4, ":any"))
341 if (!paren && !(bad - parenbad))
344 /* we need escaping! */
345 s2 = s2p = pool_alloctmpspace(pool, strlen(s) + bad * 2 + 1);
346 if (!strncmp(s, "namespace:", 10))
348 strcpy(s2p, "namespace\\3a");
356 if ((ss == s && strchr("[(<=>!", *s)) || *ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')')
359 solv_bin2hex((unsigned char *)ss, 1, s2p);
364 if (isname && s2p - s2 > 4 && !strcmp(s2p - 4, ":any"))
365 strcpy(s2p - 4, "\\3aany");
374 { REL_GT | REL_LT | REL_EQ, "<=>" },
375 { REL_LT | REL_EQ, "<=" },
376 { REL_GT | REL_EQ, ">=" },
378 { REL_GT | REL_LT, "<>" },
382 { REL_NAMESPACE , "<NAMESPACE>" },
384 { REL_MULTIARCH, "<MULTIARCH>" },
385 { REL_FILECONFLICT, "<FILECONFLICT>" },
386 { REL_COND, "<IF>" },
387 { REL_COMPAT, "compat >=" },
388 { REL_KIND, "<KIND>" },
389 { REL_ELSE, "<ELSE>" },
395 testcase_dep2str_complex(Pool *pool, Id id, int addparens)
404 return testcase_id2str(pool, id, 1);
405 rd = GETRELDEP(pool, id);
407 /* check for special shortcuts */
408 if (rd->flags == REL_NAMESPACE && !ISRELDEP(rd->name) && !strncmp(pool_id2str(pool, rd->name), "namespace:", 10))
410 const char *ns = pool_id2str(pool, rd->name);
411 int nslen = strlen(ns);
412 /* special namespace formatting */
413 const char *evrs = testcase_dep2str_complex(pool, rd->evr, 0);
414 s = pool_tmpappend(pool, evrs, ns, "()");
415 memmove(s + nslen + 1, s, strlen(s) - nslen - 2);
416 memcpy(s, ns, nslen);
420 if (rd->flags == REL_MULTIARCH && !ISRELDEP(rd->name) && rd->evr == ARCH_ANY)
422 /* special :any suffix */
423 const char *ns = testcase_id2str(pool, rd->name, 1);
424 return pool_tmpappend(pool, ns, ":any", 0);
428 if (ISRELDEP(rd->name))
430 Reldep *rd2 = GETRELDEP(pool, rd->name);
432 if (rd->flags > 7 && rd->flags != REL_COMPAT && rd2->flags && rd2->flags <= 7)
435 s = (char *)testcase_dep2str_complex(pool, rd->name, needparens);
439 s = pool_tmpappend(pool, s, "(", 0);
440 memmove(s + 1, s, strlen(s + 1));
443 for (op = oplist; op->flags; op++)
444 if (rd->flags == op->flags)
448 s = pool_tmpappend(pool, s, " ", op->opname);
449 s = pool_tmpappend(pool, s, " ", 0);
454 sprintf(buf, " <%u> ", rd->flags);
455 s = pool_tmpappend(pool, s, buf, 0);
459 if (ISRELDEP(rd->evr))
461 Reldep *rd2 = GETRELDEP(pool, rd->evr);
463 if (rd->flags > 7 && rd2->flags && rd2->flags <= 7)
465 if (rd->flags == REL_AND && rd2->flags == REL_AND)
466 needparens = 0; /* chain */
467 if (rd->flags == REL_OR && rd2->flags == REL_OR)
468 needparens = 0; /* chain */
469 if (rd->flags > 0 && rd->flags < 8 && rd2->flags == REL_COMPAT)
470 needparens = 0; /* chain */
472 if (!ISRELDEP(rd->evr))
473 s2 = testcase_id2str(pool, rd->evr, 0);
475 s2 = testcase_dep2str_complex(pool, rd->evr, needparens);
477 s = pool_tmpappend(pool, s, s2, ")");
479 s = pool_tmpappend(pool, s, s2, 0);
480 pool_freetmpspace(pool, s2);
485 testcase_dep2str(Pool *pool, Id id)
487 return testcase_dep2str_complex(pool, id, 0);
491 /* Convert a simple string. Also handle the :any suffix */
493 testcase_str2dep_simple(Pool *pool, const char **sp, int isname)
500 for (s = *sp; *s; s++)
504 if (*s == ' ' || *(unsigned char *)s < 32)
508 if (*s == ')' && paren-- <= 0)
511 if (isname && s - *sp > 4 && !strncmp(s - 4, ":any", 4))
518 if (s - *sp == 6 && !strncmp(*sp, "<NULL>", 6))
521 id = pool_strn2id(pool, *sp, s - *sp, 1);
523 else if (s - *sp == 3 && !strncmp(*sp, "\\00", 3))
527 char buf[128], *bp, *bp2;
529 bp = s - *sp >= 128 ? solv_malloc(s - *sp + 1) : buf;
530 for (bp2 = bp, sp2 = *sp; sp2 < s;)
534 solv_hex2bin(&sp2, (unsigned char *)bp2 - 1, 1);
537 id = pool_str2id(pool, bp, 1);
543 id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1);
552 testcase_str2dep_complex(Pool *pool, const char **sp, int relop)
555 Id flags, id, id2, namespaceid = 0;
558 while (*s == ' ' || *s == '\t')
560 if (!strncmp(s, "namespace:", 10))
562 /* special namespace hack */
564 for (s2 = s + 10; *s2 && *s2 != '('; s2++)
568 namespaceid = pool_strn2id(pool, s, s2 - s, 1);
575 id = testcase_str2dep_complex(pool, &s, 0);
584 id = testcase_str2dep_simple(pool, &s, relop ? 0 : 1);
586 id = pool_rel2id(pool, namespaceid, id, REL_NAMESPACE, 1);
590 while (*s == ' ' || *s == '\t')
592 if (!*s || *s == ')' || (relop && strncmp(s, "compat >= ", 10) != 0))
598 /* we have an op! Find the end */
600 if (s[0] == '<' && (s[1] >= '0' && s[1] <= '9'))
603 for (s2 = s + 1; *s2 >= '0' && *s2 <= '9'; s2++)
607 flags = strtoul(s + 1, 0, 10);
613 for (op = oplist; op->flags; op++)
614 if (!strncmp(s, op->opname, strlen(op->opname)))
622 s += strlen(op->opname);
624 id2 = testcase_str2dep_complex(pool, &s, flags > 0 && flags < 8);
630 id = pool_rel2id(pool, id, id2, flags, 1);
635 testcase_str2dep(Pool *pool, const char *s)
637 Id id = testcase_str2dep_complex(pool, &s, 0);
638 return s && !*s ? id : 0;
641 /**********************************************************/
644 testcase_repoid2str(Pool *pool, Id repoid)
646 Repo *repo = pool_id2repo(pool, repoid);
649 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
651 for (rp = r; *rp; rp++)
652 if (*rp == ' ' || *rp == '\t')
659 sprintf(buf, "#%d", repoid);
660 return pool_tmpjoin(pool, buf, 0, 0);
665 testcase_solvid2str(Pool *pool, Id p)
667 Solvable *s = pool->solvables + p;
668 const char *n, *e, *a;
671 if (p == SYSTEMSOLVABLE)
673 n = pool_id2str(pool, s->name);
674 e = pool_id2str(pool, s->evr);
675 a = pool_id2str(pool, s->arch);
676 str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
677 sprintf(str, "%s-%s.%s", n, e, a);
679 return pool_tmpappend(pool, str, "@", 0);
683 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
685 if (str2[l] == ' ' || str2[l] == '\t')
689 sprintf(buf, "@#%d", s->repo->repoid);
690 return pool_tmpappend(pool, str, buf, 0);
694 testcase_str2repo(Pool *pool, const char *str)
698 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
702 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
703 repoid = repoid * 10 + (str[j] - '0');
704 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
705 repo = pool_id2repo(pool, repoid);
709 FOR_REPOS(repoid, repo)
714 l = strlen(repo->name);
715 for (i = 0; i < l; i++)
717 int c = repo->name[i];
718 if (c == ' ' || c == '\t')
723 if (i == l && !str[l])
726 if (repoid >= pool->nrepos)
733 testcase_str2solvid(Pool *pool, const char *str)
735 int i, l = strlen(str);
742 if (*str == '@' && !strcmp(str, "@SYSTEM"))
743 return SYSTEMSOLVABLE;
745 for (i = l - 1; i >= 0; i--)
746 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
751 /* now find the arch (if present) */
753 for (i = repostart - 1; i > 0; i--)
756 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
761 /* now find the name */
762 for (i = repostart - 1; i > 0; i--)
766 Id nid, evrid, p, pp;
767 nid = pool_strn2id(pool, str, i, 0);
770 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
773 /* first check whatprovides */
774 FOR_PROVIDES(p, pp, nid)
776 Solvable *s = pool->solvables + p;
777 if (s->name != nid || s->evr != evrid)
779 if (repo && s->repo != repo)
781 if (arch && s->arch != arch)
785 /* maybe it's not installable and thus not in whatprovides. do a slow search */
789 FOR_REPO_SOLVABLES(repo, p, s)
791 if (s->name != nid || s->evr != evrid)
793 if (arch && s->arch != arch)
800 FOR_POOL_SOLVABLES(p)
802 Solvable *s = pool->solvables + p;
803 if (s->name != nid || s->evr != evrid)
805 if (arch && s->arch != arch)
816 testcase_job2str(Pool *pool, Id how, Id what)
823 Id select = how & SOLVER_SELECTMASK;
825 for (i = 0; job2str[i].str; i++)
826 if ((how & SOLVER_JOBMASK) == job2str[i].job)
828 jobstr = job2str[i].str ? job2str[i].str : "unknown";
829 if (select == SOLVER_SOLVABLE)
832 pkgstr = testcase_solvid2str(pool, what);
834 else if (select == SOLVER_SOLVABLE_NAME)
837 pkgstr = testcase_dep2str(pool, what);
839 else if (select == SOLVER_SOLVABLE_PROVIDES)
841 selstr = " provides ";
842 pkgstr = testcase_dep2str(pool, what);
844 else if (select == SOLVER_SOLVABLE_ONE_OF)
849 while ((p = pool->whatprovidesdata[what++]) != 0)
851 const char *s = testcase_solvid2str(pool, p);
854 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
855 pool_freetmpspace(pool, s);
863 else if (select == SOLVER_SOLVABLE_REPO)
865 Repo *repo = pool_id2repo(pool, what);
870 sprintf(buf, "#%d", repo->repoid);
871 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
874 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
876 else if (select == SOLVER_SOLVABLE_ALL)
883 selstr = " unknown ";
886 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
888 ret = pool_tmpappend(pool, ret, " ", 0);
889 for (i = 0; jobflags2str[i].str; i++)
890 if ((how & jobflags2str[i].flag) != 0)
891 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
897 ret = pool_tmpappend(pool, ret, "]", 0);
903 str2selflags(Pool *pool, char *s) /* modifies the string! */
908 char *se = strchr(s, ',');
911 for (i = 0; selflags2str[i].str; i++)
912 if (!strcmp(s, selflags2str[i].str))
914 selflags |= selflags2str[i].flag;
917 if (!selflags2str[i].str)
918 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection flag '%s'\n", s);
925 str2jobflags(Pool *pool, char *s) /* modifies the string */
930 char *se = strchr(s, ',');
933 for (i = 0; jobflags2str[i].str; i++)
934 if (!strcmp(s, jobflags2str[i].str))
936 jobflags |= jobflags2str[i].flag;
939 if (!jobflags2str[i].str)
940 pool_debug(pool, SOLV_ERROR, "str2job: unknown job flag '%s'\n", s);
947 testcase_str2job(Pool *pool, const char *str, Id *whatp)
957 /* so we can patch it */
958 s = pool_tmpjoin(pool, str, 0, 0);
959 /* split it in pieces */
962 while (*s == ' ' || *s == '\t')
966 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
967 pieces[npieces++] = s;
968 while (*s && *s != ' ' && *s != '\t')
975 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
980 for (i = 0; job2str[i].str; i++)
981 if (!strcmp(pieces[0], job2str[i].str))
985 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
989 job = job2str[i].job;
993 char *flags = pieces[npieces - 1];
994 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
998 flags[strlen(flags) - 1] = 0;
999 job |= str2jobflags(pool, flags);
1002 if (!strcmp(pieces[1], "pkg"))
1006 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
1010 job |= SOLVER_SOLVABLE;
1011 what = testcase_str2solvid(pool, pieces[2]);
1014 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
1019 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
1021 /* join em again for dep2str... */
1023 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
1027 if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
1029 char *spe = strchr(pieces[2], '(');
1030 int l = strlen(pieces[2]);
1031 if (spe && pieces[2][l - 1] == ')')
1033 /* special namespace provides */
1034 if (strcmp(spe, "(<NULL>)") != 0)
1036 pieces[2][l - 1] = 0;
1037 what = testcase_str2dep(pool, spe + 1);
1038 pieces[2][l - 1] = ')';
1040 what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
1044 what = testcase_str2dep(pool, pieces[2]);
1045 if (pieces[1][0] == 'n')
1046 job |= SOLVER_SOLVABLE_NAME;
1048 job |= SOLVER_SOLVABLE_PROVIDES;
1050 else if (!strcmp(pieces[1], "oneof"))
1053 job |= SOLVER_SOLVABLE_ONE_OF;
1055 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
1057 for (i = 2; i < npieces; i++)
1059 Id p = testcase_str2solvid(pool, pieces[i]);
1062 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
1070 what = pool_queuetowhatprovides(pool, &q);
1073 else if (!strcmp(pieces[1], "repo"))
1078 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
1082 repo = testcase_str2repo(pool, pieces[2]);
1085 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
1089 job |= SOLVER_SOLVABLE_REPO;
1090 what = repo->repoid;
1092 else if (!strcmp(pieces[1], "all"))
1094 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
1096 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
1100 job |= SOLVER_SOLVABLE_ALL;
1105 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
1115 addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue)
1122 for (i = 0; job2str[i].str; i++)
1123 if (!strcmp(pieces[0], job2str[i].str))
1125 if (!job2str[i].str)
1127 pool_debug(pool, SOLV_ERROR, "selstr2job: unknown job '%s'\n", pieces[0]);
1130 job = job2str[i].job;
1133 char *flags = pieces[npieces - 1];
1134 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
1138 flags[strlen(flags) - 1] = 0;
1139 job |= str2jobflags(pool, flags);
1144 pool_debug(pool, SOLV_ERROR, "selstr2job: no selection flags\n");
1147 selflags = str2selflags(pool, pieces[3]);
1149 r = selection_make(pool, &sel, pieces[2], selflags);
1150 for (i = 0; i < sel.count; i += 2)
1151 queue_push2(jobqueue, job | sel.elements[i], sel.elements[i + 1]);
1157 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
1159 Pool *pool = repo->pool;
1166 dp = repo->idarraydata + off;
1167 while ((id = *dp++) != 0)
1169 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
1172 fprintf(fp, "-%s\n", tag);
1177 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
1179 idstr = testcase_dep2str(pool, id);
1182 fprintf(fp, "+%s\n", tag);
1185 fprintf(fp, "%s\n", idstr);
1188 fprintf(fp, "-%s\n", tag);
1192 writefilelist(Repo *repo, FILE *fp, const char *tag, Solvable *s)
1194 Pool *pool = repo->pool;
1198 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
1199 while (dataiterator_step(&di))
1201 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
1204 fprintf(fp, "+%s\n", tag);
1207 fprintf(fp, "%s\n", s);
1210 fprintf(fp, "-%s\n", tag);
1211 dataiterator_free(&di);
1215 testcase_write_testtags(Repo *repo, FILE *fp)
1217 Pool *pool = repo->pool;
1223 const char *release;
1228 fprintf(fp, "=Ver: 3.0\n");
1230 FOR_REPO_SOLVABLES(repo, p, s)
1232 name = pool_id2str(pool, s->name);
1233 evr = pool_id2str(pool, s->evr);
1234 arch = pool_id2str(pool, s->arch);
1235 release = strrchr(evr, '-');
1237 release = evr + strlen(evr);
1238 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
1239 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
1241 fprintf(fp, "=Sum: %s\n", tmp);
1242 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
1243 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
1244 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
1245 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
1246 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
1247 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
1248 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
1249 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
1250 if (solvable_lookup_idarray(s, SOLVABLE_PREREQ_IGNOREINST, &q))
1253 fprintf(fp, "+Ipr:\n");
1254 for (i = 0; i < q.count; i++)
1255 fprintf(fp, "%s\n", testcase_dep2str(pool, q.elements[i]));
1256 fprintf(fp, "-Ipr:\n");
1259 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
1260 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
1262 fprintf(fp, "=Tim: %u\n", ti);
1263 writefilelist(repo, fp, "Fls:", s);
1269 static inline Offset
1270 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
1272 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
1273 return repo_addid_dep(repo, olddeps, id, marker);
1277 finish_v2_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
1283 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1285 char *p = strrchr(filelist + l, '/');
1289 did = repodata_str2dir(data, filelist + l, 1);
1292 did = repodata_str2dir(data, "/", 1);
1293 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
1296 repo_rewrite_suse_deps(s, 0);
1299 /* stripped down version of susetags parser used for testcases */
1301 testcase_add_testtags(Repo *repo, FILE *fp, int flags)
1303 Pool *pool = repo->pool;
1315 int tagsversion = 0;
1316 int addselfprovides = 1; /* for compat reasons */
1318 data = repo_add_repodata(repo, flags);
1323 line = solv_malloc(aline);
1327 if (linep - line + 16 > aline)
1329 aline = linep - line;
1330 line = solv_realloc(line, aline + 512);
1331 linep = line + aline;
1334 if (!fgets(linep, aline - (linep - line), fp))
1336 linep += strlen(linep);
1337 if (linep == line || linep[-1] != '\n')
1340 linep = line + intag;
1343 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
1350 else if (line[0] == '+' && line[1] && line[1] != ':')
1352 char *tagend = strchr(line, ':');
1357 intag = tagend + 2 - line;
1358 linep = line + intag;
1361 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
1363 tag = line[1] << 16 | line[2] << 8 | line[3];
1366 case 'V' << 16 | 'e' << 8 | 'r':
1367 tagsversion = atoi(line + 6);
1368 addselfprovides = tagsversion < 3 || strstr(line + 6, "addselfprovides") != 0;
1370 case 'P' << 16 | 'k' << 8 | 'g':
1373 if (tagsversion == 2)
1374 finish_v2_solvable(pool, data, s, filelist, nfilelist);
1375 if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
1376 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
1379 if (split(line + 5, sp, 5) != 4)
1381 s = pool_id2solvable(pool, repo_add_solvable(repo));
1382 s->name = pool_str2id(pool, sp[0], 1);
1383 /* join back version and release */
1384 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
1386 s->evr = makeevr(pool, sp[1]);
1387 s->arch = pool_str2id(pool, sp[3], 1);
1389 case 'S' << 16 | 'u' << 8 | 'm':
1390 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
1392 case 'V' << 16 | 'n' << 8 | 'd':
1393 s->vendor = pool_str2id(pool, line + 6, 1);
1395 case 'T' << 16 | 'i' << 8 | 'm':
1398 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
1400 case 'R' << 16 | 'e' << 8 | 'q':
1401 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
1403 case 'P' << 16 | 'r' << 8 | 'q':
1404 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
1406 case 'P' << 16 | 'r' << 8 | 'v':
1407 /* version 2 had the file list at the end of the provides */
1408 if (tagsversion == 2)
1412 int l = strlen(line + 6) + 1;
1413 if (nfilelist + l > afilelist)
1415 afilelist = nfilelist + l + 512;
1416 filelist = solv_realloc(filelist, afilelist);
1418 memcpy(filelist + nfilelist, line + 6, l);
1425 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1426 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1430 s->provides = adddep(repo, s->provides, line + 6, 0);
1432 case 'F' << 16 | 'l' << 8 | 's':
1434 char *p = strrchr(line + 6, '/');
1439 did = repodata_str2dir(data, line + 6, 1);
1441 did = repodata_str2dir(data, "/", 1);
1442 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
1445 case 'O' << 16 | 'b' << 8 | 's':
1446 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1448 case 'C' << 16 | 'o' << 8 | 'n':
1449 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1451 case 'R' << 16 | 'e' << 8 | 'c':
1452 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1454 case 'S' << 16 | 'u' << 8 | 'p':
1455 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1457 case 'S' << 16 | 'u' << 8 | 'g':
1458 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1460 case 'E' << 16 | 'n' << 8 | 'h':
1461 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1463 case 'I' << 16 | 'p' << 8 | 'r':
1465 Id id = line[6] == '/' ? pool_str2id(pool, line + 6, 1) : testcase_str2dep(pool, line + 6);
1466 repodata_add_idarray(data, s - pool->solvables, SOLVABLE_PREREQ_IGNOREINST, id);
1475 if (tagsversion == 2)
1476 finish_v2_solvable(pool, data, s, filelist, nfilelist);
1477 if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
1478 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
1481 solv_free(filelist);
1482 repodata_free_dircache(data);
1483 if (!(flags & REPO_NO_INTERNALIZE))
1484 repodata_internalize(data);
1489 testcase_getpoolflags(Pool *pool)
1491 const char *str = 0;
1493 for (i = 0; poolflags2str[i].str; i++)
1495 v = pool_get_flag(pool, poolflags2str[i].flag);
1496 if (v == poolflags2str[i].def)
1498 str = pool_tmpappend(pool, str, v ? " " : " !", poolflags2str[i].str);
1500 return str ? str + 1 : "";
1504 testcase_setpoolflags(Pool *pool, const char *str)
1506 const char *p = str, *s;
1510 while (*p == ' ' || *p == '\t' || *p == ',')
1521 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1523 for (i = 0; poolflags2str[i].str; i++)
1524 if (!strncmp(poolflags2str[i].str, s, p - s) && poolflags2str[i].str[p - s] == 0)
1526 if (!poolflags2str[i].str)
1528 pool_debug(pool, SOLV_ERROR, "setpoolflags: unknown flag '%.*s'\n", (int)(p - s), s);
1531 pool_set_flag(pool, poolflags2str[i].flag, v);
1537 testcase_resetpoolflags(Pool *pool)
1540 for (i = 0; poolflags2str[i].str; i++)
1541 pool_set_flag(pool, poolflags2str[i].flag, poolflags2str[i].def);
1545 testcase_getsolverflags(Solver *solv)
1547 Pool *pool = solv->pool;
1548 const char *str = 0;
1550 for (i = 0; solverflags2str[i].str; i++)
1552 v = solver_get_flag(solv, solverflags2str[i].flag);
1553 if (v == solverflags2str[i].def)
1555 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1557 return str ? str + 1 : "";
1561 testcase_setsolverflags(Solver *solv, const char *str)
1563 const char *p = str, *s;
1567 while (*p == ' ' || *p == '\t' || *p == ',')
1578 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1580 for (i = 0; solverflags2str[i].str; i++)
1581 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1583 if (!solverflags2str[i].str)
1585 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", (int)(p - s), s);
1588 if (solver_set_flag(solv, solverflags2str[i].flag, v) == -1)
1590 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unsupported flag '%s'\n", solverflags2str[i].str);
1598 testcase_resetsolverflags(Solver *solv)
1601 for (i = 0; solverflags2str[i].str; i++)
1602 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1606 testcase_ruleid(Solver *solv, Id rid)
1612 const unsigned char *md5;
1618 solver_ruleliterals(solv, rid, &q);
1619 for (i = 0; i < q.count; i++)
1621 Id p = q.elements[i];
1622 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1624 s = pool_tmpjoin(solv->pool, "!", s, 0);
1625 strqueue_push(&sq, s);
1628 strqueue_sort_u(&sq);
1629 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1630 for (i = 0; i < sq.nstr; i++)
1631 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1632 md5 = solv_chksum_get(chk, &md5l);
1633 s = pool_bin2hex(solv->pool, md5, md5l);
1634 chk = solv_chksum_free(chk, 0);
1640 testcase_problemid(Solver *solv, Id problem)
1645 const unsigned char *md5;
1649 /* we build a hash of all rules that define the problem */
1652 solver_findallproblemrules(solv, problem, &q);
1653 for (i = 0; i < q.count; i++)
1654 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1656 strqueue_sort_u(&sq);
1657 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1658 for (i = 0; i < sq.nstr; i++)
1659 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1660 md5 = solv_chksum_get(chk, &md5l);
1661 s = pool_bin2hex(solv->pool, md5, 4);
1662 chk = solv_chksum_free(chk, 0);
1668 testcase_solutionid(Solver *solv, Id problem, Id solution)
1672 const unsigned char *md5;
1676 intid = solver_solutionelement_internalid(solv, problem, solution);
1677 /* internal stuff! handle with care! */
1681 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1686 s = testcase_ruleid(solv, intid);
1688 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1689 solv_chksum_add(chk, s, strlen(s) + 1);
1690 md5 = solv_chksum_get(chk, &md5l);
1691 s = pool_bin2hex(solv->pool, md5, 4);
1692 chk = solv_chksum_free(chk, 0);
1697 testcase_alternativeid(Solver *solv, int type, Id id, Id from)
1700 Pool *pool = solv->pool;
1702 const unsigned char *md5;
1704 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1705 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
1707 s = testcase_solvid2str(pool, from);
1708 solv_chksum_add(chk, s, strlen(s) + 1);
1709 s = testcase_dep2str(pool, id);
1710 solv_chksum_add(chk, s, strlen(s) + 1);
1712 else if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
1714 s = testcase_ruleid(solv, id);
1715 solv_chksum_add(chk, s, strlen(s) + 1);
1717 md5 = solv_chksum_get(chk, &md5l);
1718 s = pool_bin2hex(pool, md5, 4);
1719 chk = solv_chksum_free(chk, 0);
1723 static struct class2str {
1727 { SOLVER_TRANSACTION_ERASE, "erase" },
1728 { SOLVER_TRANSACTION_INSTALL, "install" },
1729 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1730 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1731 { SOLVER_TRANSACTION_CHANGED, "change" },
1732 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1733 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1734 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1735 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1739 static struct reason2str {
1743 { SOLVER_REASON_UNRELATED, "unrelated" },
1744 { SOLVER_REASON_UNIT_RULE, "unit" },
1745 { SOLVER_REASON_KEEP_INSTALLED, "keep" },
1746 { SOLVER_REASON_RESOLVE_JOB, "job" },
1747 { SOLVER_REASON_UPDATE_INSTALLED, "update" },
1748 { SOLVER_REASON_CLEANDEPS_ERASE, "cleandeps" },
1749 { SOLVER_REASON_RESOLVE, "resolve" },
1750 { SOLVER_REASON_WEAKDEP, "weakdep" },
1751 { SOLVER_REASON_RESOLVE_ORPHAN, "orphan" },
1753 { SOLVER_REASON_RECOMMENDED, "recommended" },
1754 { SOLVER_REASON_SUPPLEMENTED, "supplemented" },
1759 testcase_reason2str(Id reason)
1762 for (i = 0; reason2str[i].str; i++)
1763 if (reason == reason2str[i].reason)
1764 return reason2str[i].str;
1768 static struct rclass2str {
1772 { SOLVER_RULE_PKG, "pkg" },
1773 { SOLVER_RULE_UPDATE, "update" },
1774 { SOLVER_RULE_FEATURE, "feature" },
1775 { SOLVER_RULE_JOB, "job" },
1776 { SOLVER_RULE_DISTUPGRADE, "distupgrade" },
1777 { SOLVER_RULE_INFARCH, "infarch" },
1778 { SOLVER_RULE_CHOICE, "choice" },
1779 { SOLVER_RULE_LEARNT, "learnt" },
1780 { SOLVER_RULE_BEST, "best" },
1781 { SOLVER_RULE_YUMOBS, "yumobs" },
1786 testcase_rclass2str(Id rclass)
1789 for (i = 0; rclass2str[i].str; i++)
1790 if (rclass == rclass2str[i].rclass)
1791 return rclass2str[i].str;
1796 dump_genid(Pool *pool, Strqueue *sq, Id id, int cnt)
1804 Reldep *rd = GETRELDEP(pool, id);
1805 for (op = oplist; op->flags; op++)
1806 if (rd->flags == op->flags)
1808 cnt = dump_genid(pool, sq, rd->name, cnt);
1809 cnt = dump_genid(pool, sq, rd->evr, cnt);
1810 sprintf(cntbuf, "genid %2d: genid ", cnt++);
1811 s = pool_tmpjoin(pool, cntbuf, "op ", op->flags ? op->opname : "unknown");
1815 sprintf(cntbuf, "genid %2d: genid ", cnt++);
1816 s = pool_tmpjoin(pool, cntbuf, id ? "lit " : "null", id ? pool_id2str(pool, id) : 0);
1818 strqueue_push(sq, s);
1823 testcase_solverresult(Solver *solv, int resultflags)
1825 Pool *pool = solv->pool;
1833 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1835 Transaction *trans = solver_create_transaction(solv);
1839 for (i = 0; class2str[i].str; i++)
1842 transaction_classify_pkgs(trans, SOLVER_TRANSACTION_KEEP_PSEUDO, class2str[i].class, 0, 0, &q);
1843 for (j = 0; j < q.count; j++)
1847 if (pool->installed && pool->solvables[p].repo == pool->installed)
1848 op = transaction_obs_pkg(trans, p);
1849 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1851 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1852 strqueue_push(&sq, s);
1856 transaction_free(trans);
1858 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1860 char *probprefix, *solprefix;
1861 int problem, solution, element;
1864 pcnt = solver_problem_count(solv);
1865 for (problem = 1; problem <= pcnt; problem++)
1867 Id rid, from, to, dep;
1868 SolverRuleinfo rinfo;
1869 rid = solver_findproblemrule(solv, problem);
1870 s = testcase_problemid(solv, problem);
1871 probprefix = solv_dupjoin("problem ", s, 0);
1872 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1873 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1874 strqueue_push(&sq, s);
1875 scnt = solver_solution_count(solv, problem);
1876 for (solution = 1; solution <= scnt; solution++)
1878 s = testcase_solutionid(solv, problem, solution);
1879 solprefix = solv_dupjoin(probprefix, " solution ", s);
1881 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1883 if (p == SOLVER_SOLUTION_JOB)
1884 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1885 else if (p > 0 && op == 0)
1886 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1887 else if (p > 0 && op > 0)
1889 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1890 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1892 else if (p < 0 && op > 0)
1893 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1895 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1896 strqueue_push(&sq, s);
1898 solv_free(solprefix);
1900 solv_free(probprefix);
1904 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1909 solver_get_orphaned(solv, &q);
1910 for (i = 0; i < q.count; i++)
1912 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1913 strqueue_push(&sq, s);
1918 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1924 solver_get_recommendations(solv, &qr, &qs, 0);
1925 for (i = 0; i < qr.count; i++)
1927 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1928 strqueue_push(&sq, s);
1930 for (i = 0; i < qs.count; i++)
1932 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1933 strqueue_push(&sq, s);
1939 if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0)
1945 solver_get_unneeded(solv, &q, 0);
1946 solver_get_unneeded(solv, &qf, 1);
1947 for (i = j = 0; i < q.count; i++)
1949 /* we rely on qf containing a subset of q in the same order */
1950 if (j < qf.count && q.elements[i] == qf.elements[j])
1952 s = pool_tmpjoin(pool, "unneeded_filtered ", testcase_solvid2str(pool, q.elements[i]), 0);
1956 s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0);
1957 strqueue_push(&sq, s);
1962 if ((resultflags & TESTCASE_RESULT_ALTERNATIVES) != 0)
1970 cnt = solver_alternatives_count(solv);
1971 for (alternative = 1; alternative <= cnt; alternative++)
1973 Id id, from, chosen;
1975 int type = solver_get_alternative(solv, alternative, &id, &from, &chosen, &q, 0);
1976 altprefix = solv_dupjoin("alternative ", testcase_alternativeid(solv, type, id, from), " ");
1978 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
1980 char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, from));
1981 s = pool_tmpappend(pool, s, " recommends ", testcase_dep2str(pool, id));
1982 strqueue_push(&sq, s);
1984 else if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
1986 /* map choice rules back to pkg rules */
1987 if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
1988 id = solver_rule2pkgrule(solv, id);
1989 solver_allruleinfos(solv, id, &rq);
1990 for (i = 0; i < rq.count; i += 4)
1992 int rtype = rq.elements[i];
1993 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
1995 const char *js = testcase_job2str(pool, rq.elements[i + 2], rq.elements[i + 3]);
1996 char *s = pool_tmpjoin(pool, altprefix, num, " job ");
1997 s = pool_tmpappend(pool, s, js, 0);
1998 strqueue_push(&sq, s);
2000 else if (rtype == SOLVER_RULE_PKG_REQUIRES)
2002 char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, rq.elements[i + 1]));
2003 s = pool_tmpappend(pool, s, " requires ", testcase_dep2str(pool, rq.elements[i + 3]));
2004 strqueue_push(&sq, s);
2008 for (i = 0; i < q.count; i++)
2010 Id p = q.elements[i];
2012 num[0] = '0' + (i + 1) / 10;
2013 num[1] = '0' + (i + 1) % 10;
2015 s = pool_tmpjoin(pool, altprefix, num, "+ ");
2017 s = pool_tmpjoin(pool, altprefix, num, "- ");
2019 s = pool_tmpjoin(pool, altprefix, num, " ");
2020 s = pool_tmpappend(pool, s, testcase_solvid2str(pool, p < 0 ? -p : p), 0);
2021 strqueue_push(&sq, s);
2023 solv_free(altprefix);
2028 if ((resultflags & TESTCASE_RESULT_RULES) != 0)
2030 /* dump all rules */
2032 SolverRuleinfo rclass;
2037 for (rid = 1; (rclass = solver_ruleclass(solv, rid)) != SOLVER_RULE_UNKNOWN; rid++)
2039 char *prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " ");
2040 prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0);
2041 solver_ruleliterals(solv, rid, &q);
2042 if (rclass == SOLVER_RULE_FEATURE && q.count == 1 && q.elements[0] == -SYSTEMSOLVABLE)
2044 for (i = 0; i < q.count; i++)
2046 Id p = q.elements[i];
2049 s = pool_tmpjoin(pool, prefix, " -", testcase_solvid2str(pool, -p));
2051 s = pool_tmpjoin(pool, prefix, " ", testcase_solvid2str(pool, p));
2052 strqueue_push(&sq, s);
2058 if ((resultflags & TESTCASE_RESULT_GENID) != 0)
2060 for (i = 0 ; i < solv->job.count; i += 2)
2063 if (solv->job.elements[i] != (SOLVER_NOOP | SOLVER_SOLVABLE_PROVIDES))
2065 id = solv->job.elements[i + 1];
2066 s = testcase_dep2str(pool, id);
2067 strqueue_push(&sq, pool_tmpjoin(pool, "genid dep ", s, 0));
2068 if ((id2 = testcase_str2dep(pool, s)) != id)
2070 s = pool_tmpjoin(pool, "genid roundtrip error: ", testcase_dep2str(pool, id2), 0);
2071 strqueue_push(&sq, s);
2073 dump_genid(pool, &sq, id, 1);
2076 if ((resultflags & TESTCASE_RESULT_REASON) != 0)
2080 FOR_POOL_SOLVABLES(p)
2083 int reason = solver_describe_decision(solv, p, &info);
2084 if (reason == SOLVER_REASON_UNRELATED)
2086 if (reason == SOLVER_REASON_WEAKDEP)
2088 solver_describe_weakdep_decision(solv, p, &whyq);
2091 for (i = 0; i < whyq.count; i += 3)
2093 reason = whyq.elements[i];
2094 p2 = whyq.elements[i + 1];
2095 id = whyq.elements[i + 2];
2096 s = pool_tmpjoin(pool, "reason ", testcase_solvid2str(pool, p), 0);
2097 s = pool_tmpappend(pool, s, " ", testcase_reason2str(reason));
2098 s = pool_tmpappend(pool, s, " ", testcase_dep2str(pool, id));
2100 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, p2));
2101 strqueue_push(&sq, s);
2106 s = pool_tmpjoin(pool, "reason ", testcase_solvid2str(pool, p), 0);
2107 s = pool_tmpappend(pool, s, " ", testcase_reason2str(reason));
2109 s = pool_tmpappend(pool, s, " ", testcase_ruleid(solv, info));
2110 strqueue_push(&sq, s);
2115 result = strqueue_join(&sq);
2122 testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname)
2124 Pool *pool = solv->pool;
2135 testcasename = "testcase.t";
2137 resultname = "solver.result";
2139 if (mkdir(dir, 0777) && errno != EEXIST)
2141 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
2145 FOR_REPOS(repoid, repo)
2147 const char *name = testcase_repoid2str(pool, repoid);
2149 if (repo->subpriority)
2150 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
2152 sprintf(priobuf, "%d", repo->priority);
2153 out = pool_tmpjoin(pool, name, ".repo", ".gz");
2154 for (i = 0; out[i]; i++)
2157 cmd = pool_tmpjoin(pool, "repo ", name, " ");
2158 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
2159 cmd = pool_tmpappend(pool, cmd, "testtags ", out);
2160 strqueue_push(&sq, cmd);
2161 out = pool_tmpjoin(pool, dir, "/", out);
2162 if (!(fp = solv_xfopen(out, "w")))
2164 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
2168 testcase_write_testtags(repo, fp);
2171 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
2176 /* hmm, this is not optimal... we currently search for the lowest score */
2178 arch = pool->solvables[SYSTEMSOLVABLE].arch;
2179 for (i = 0; i < pool->lastarch; i++)
2181 if (pool->id2arch[i] == 1 && !lowscore)
2183 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
2186 lowscore = pool->id2arch[i];
2189 cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
2190 for (i = 0; disttype2str[i].str != 0; i++)
2191 if (pool->disttype == disttype2str[i].type)
2193 pool_tmpappend(pool, cmd, " ", disttype2str[i].str ? disttype2str[i].str : "unknown");
2194 if (pool->installed)
2195 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
2196 strqueue_push(&sq, cmd);
2197 s = testcase_getpoolflags(solv->pool);
2200 cmd = pool_tmpjoin(pool, "poolflags ", s, 0);
2201 strqueue_push(&sq, cmd);
2204 if (pool->vendorclasses)
2207 for (i = 0; pool->vendorclasses[i]; i++)
2209 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
2210 if (!pool->vendorclasses[i + 1])
2212 strqueue_push(&sq, cmd);
2219 /* dump disabled packages (must come before the namespace/job lines) */
2220 if (pool->considered)
2223 FOR_POOL_SOLVABLES(p)
2224 if (!MAPTST(pool->considered, p))
2226 cmd = pool_tmpjoin(pool, "disable pkg ", testcase_solvid2str(pool, p), 0);
2227 strqueue_push(&sq, cmd);
2231 s = testcase_getsolverflags(solv);
2234 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
2235 strqueue_push(&sq, cmd);
2238 /* now dump all the ns callback values we know */
2239 if (pool->nscallback)
2243 for (rid = 1; rid < pool->nrels; rid++)
2245 Reldep *rd = pool->rels + rid;
2246 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
2248 /* evaluate all namespace ids, skip empty results */
2249 d = pool_whatprovides(pool, MAKERELDEP(rid));
2250 if (!d || !pool->whatprovidesdata[d])
2252 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
2253 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
2254 for (; pool->whatprovidesdata[d]; d++)
2255 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
2256 strqueue_push(&sq, cmd);
2260 for (i = 0; i < solv->job.count; i += 2)
2262 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
2263 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
2264 strqueue_push(&sq, cmd);
2271 for (i = 0; resultflags2str[i].str; i++)
2272 if ((resultflags & resultflags2str[i].flag) != 0)
2273 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
2274 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", 0);
2275 cmd = pool_tmpappend(pool, cmd, " ", resultname);
2276 strqueue_push(&sq, cmd);
2277 result = testcase_solverresult(solv, resultflags);
2278 if (!strcmp(resultname, "<inline>"))
2282 strqueue_init(&rsq);
2283 strqueue_split(&rsq, result);
2284 for (i = 0; i < rsq.nstr; i++)
2286 cmd = pool_tmpjoin(pool, "#>", rsq.str[i], 0);
2287 strqueue_push(&sq, cmd);
2289 strqueue_free(&rsq);
2293 out = pool_tmpjoin(pool, dir, "/", resultname);
2294 if (!(fp = fopen(out, "w")))
2296 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
2301 if (result && *result && fwrite(result, strlen(result), 1, fp) != 1)
2303 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
2311 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
2319 cmd = strqueue_join(&sq);
2320 out = pool_tmpjoin(pool, dir, "/", testcasename);
2321 if (!(fp = fopen(out, "w")))
2323 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
2327 if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
2329 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
2336 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
2346 testcase_write(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname)
2348 Pool *pool = solv->pool;
2351 const char **orignames;
2353 /* mangle repo names so that there are no conflicts */
2354 orignames = solv_calloc(pool->nrepos, sizeof(char *));
2355 for (repoid = 1; repoid < pool->nrepos; repoid++)
2357 Repo *repo = pool_id2repo(pool, repoid);
2358 char *buf = solv_malloc((repo->name ? strlen(repo->name) : 0) + 40);
2360 orignames[repoid] = repo->name;
2361 if (!repo->name || !repo->name[0])
2362 sprintf(buf, "#%d", repoid);
2364 strcpy(buf, repo->name);
2365 for (i = 0; buf[i]; i++)
2366 if (buf[i] == ' ' || buf[i] == '\t' || buf[i] == '/')
2368 mp = buf + strlen(buf);
2371 for (i = 1; i < repoid; i++)
2372 if (!strcmp(buf, pool_id2repo(pool, i)->name))
2376 sprintf(mp, "_%d", mangle++);
2380 r = testcase_write_mangled(solv, dir, resultflags, testcasename, resultname);
2381 for (repoid = 1; repoid < pool->nrepos; repoid++)
2383 Repo *repo = pool_id2repo(pool, repoid);
2384 solv_free((void *)repo->name);
2385 repo->name = orignames[repoid];
2387 solv_free(orignames);
2392 read_inline_file(FILE *fp, char **bufp, char **bufpp, int *buflp)
2394 char *result = solv_malloc(1024);
2401 if (rp - result + 256 >= resultl)
2403 resultl = rp - result;
2404 result = solv_realloc(result, resultl + 1024);
2405 rp = result + resultl;
2408 if (!fgets(rp, resultl - (rp - result), fp))
2411 if (rl && (rp == result || rp[-1] == '\n'))
2413 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
2415 memmove(rp, rp + 2, rl - 2);
2420 while (rl + 16 > *buflp)
2422 *bufp = solv_realloc(*bufp, *buflp + 512);
2425 memmove(*bufp, rp, rl);
2426 if ((*bufp)[rl - 1] == '\n')
2432 (*bufpp) = *bufp + rl;
2449 char *result = solv_malloc(1024);
2456 if (rp - result + 256 >= resultl)
2458 resultl = rp - result;
2459 result = solv_realloc(result, resultl + 1024);
2460 rp = result + resultl;
2463 rl = fread(rp, 1, resultl - (rp - result), fp);
2475 str2resultflags(Pool *pool, char *s) /* modifies the string! */
2477 int i, resultflags = 0;
2480 char *se = strchr(s, ',');
2483 for (i = 0; resultflags2str[i].str; i++)
2484 if (!strcmp(s, resultflags2str[i].str))
2486 resultflags |= resultflags2str[i].flag;
2489 if (!resultflags2str[i].str)
2490 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
2497 testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **resultp, int *resultflagsp)
2502 char *testcasedir, *s;
2508 int poolflagsreset = 0;
2509 int missing_features = 0;
2514 if (!fp && !(fp = fopen(testcase, "r")))
2516 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
2519 testcasedir = solv_strdup(testcase);
2520 if ((s = strrchr(testcasedir, '/')) != 0)
2525 buf = solv_malloc(bufl);
2528 queue_init(&autoinstq);
2531 if (bufp - buf + 16 > bufl)
2534 buf = solv_realloc(buf, bufl + 512);
2538 if (!fgets(bufp, bufl - (bufp - buf), fp))
2542 if (!l || buf[l - 1] != '\n')
2549 while (*s && (*s == ' ' || *s == '\t'))
2551 if (!*s || *s == '#')
2554 /* split it in pieces */
2557 while (*s == ' ' || *s == '\t')
2561 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2562 pieces[npieces++] = s;
2563 while (*s && *s != ' ' && *s != '\t')
2568 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2569 pieces[npieces] = 0;
2570 if (!strcmp(pieces[0], "repo") && npieces >= 4)
2572 Repo *repo = repo_create(pool, pieces[1]);
2578 if (!poolflagsreset)
2581 testcase_resetpoolflags(pool); /* hmm */
2583 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
2586 prio = atoi(pieces[2]);
2588 repo->priority = prio;
2589 repo->subpriority = subprio;
2590 if (strcmp(pieces[3], "empty") != 0)
2592 const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0); /* gets overwritten in <inline> case */
2593 if (!strcmp(pieces[4], "<inline>"))
2595 char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
2597 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
2601 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
2602 rfp = solv_xfopen(rdata, "r");
2606 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2608 else if (!strcmp(repotype, "testtags"))
2610 testcase_add_testtags(repo, rfp, 0);
2613 else if (!strcmp(repotype, "solv"))
2615 repo_add_solv(repo, rfp, 0);
2619 else if (!strcmp(repotype, "helix"))
2621 extern int repo_add_helix(Repo *repo, FILE *fp, int flags);
2622 repo_add_helix(repo, rfp, 0);
2629 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
2633 else if (!strcmp(pieces[0], "system") && npieces >= 3)
2637 /* must set the disttype before the arch */
2639 if (strcmp(pieces[2], "*") != 0)
2641 char *dp = pieces[2];
2644 char *dpe = strchr(dp, ',');
2647 for (i = 0; disttype2str[i].str != 0; i++)
2648 if (!strcmp(disttype2str[i].str, dp))
2652 if (disttype2str[i].str)
2654 #ifdef MULTI_SEMANTICS
2655 if (pool->disttype != disttype2str[i].type)
2656 pool_setdisttype(pool, disttype2str[i].type);
2658 if (pool->disttype == disttype2str[i].type)
2665 pool_debug(pool, SOLV_ERROR, "testcase_read: system: could not change disttype to '%s'\n", pieces[2]);
2666 missing_features = 1;
2669 if (strcmp(pieces[1], "unset") == 0)
2670 pool_setarch(pool, 0);
2671 else if (pieces[1][0] == ':')
2672 pool_setarchpolicy(pool, pieces[1] + 1);
2674 pool_setarch(pool, pieces[1]);
2677 Repo *repo = testcase_str2repo(pool, pieces[3]);
2679 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
2681 pool_set_installed(pool, repo);
2684 else if (!strcmp(pieces[0], "job") && npieces > 1)
2690 pool_addfileprovides(pool);
2691 pool_createwhatprovides(pool);
2694 if (npieces >= 3 && !strcmp(pieces[2], "selection"))
2696 addselectionjob(pool, pieces + 1, npieces - 1, job);
2700 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
2703 how = testcase_str2job(pool, pieces[1], &what);
2704 if (how >= 0 && job)
2705 queue_push2(job, how, what);
2707 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
2709 pool_addvendorclass(pool, (const char **)(pieces + 1));
2711 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
2713 int i = strlen(pieces[1]);
2714 s = strchr(pieces[1], '(');
2715 if (!s && pieces[1][i - 1] != ')')
2717 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
2725 pieces[1][i - 1] = 0;
2726 name = pool_str2id(pool, pieces[1], 1);
2727 evr = pool_str2id(pool, s + 1, 1);
2729 pieces[1][i - 1] = ')';
2730 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
2731 for (i = 2; i < npieces; i++)
2732 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
2733 /* now do the callback */
2736 pool_addfileprovides(pool);
2737 pool_createwhatprovides(pool);
2740 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
2744 else if (!strcmp(pieces[0], "poolflags"))
2747 if (!poolflagsreset)
2750 testcase_resetpoolflags(pool); /* hmm */
2752 for (i = 1; i < npieces; i++)
2753 testcase_setpoolflags(pool, pieces[i]);
2755 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
2760 solv = solver_create(pool);
2761 testcase_resetsolverflags(solv);
2763 for (i = 1; i < npieces; i++)
2764 testcase_setsolverflags(solv, pieces[i]);
2766 else if (!strcmp(pieces[0], "result") && npieces > 1)
2769 int resultflags = str2resultflags(pool, pieces[1]);
2773 rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
2774 if (!strcmp(pieces[2], "<inline>"))
2775 result = read_inline_file(fp, &buf, &bufp, &bufl);
2778 FILE *rfp = fopen(rdata, "r");
2780 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2783 result = read_file(rfp);
2793 *resultflagsp = resultflags;
2795 else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
2799 else if (!strcmp(pieces[0], "disable") && npieces == 3)
2802 if (strcmp(pieces[1], "pkg"))
2804 pool_debug(pool, SOLV_ERROR, "testcase_read: bad disable type '%s'\n", pieces[1]);
2808 pool_createwhatprovides(pool);
2810 if (!pool->considered)
2812 pool->considered = solv_calloc(1, sizeof(Map));
2813 map_init(pool->considered, pool->nsolvables);
2814 map_setall(pool->considered);
2816 p = testcase_str2solvid(pool, pieces[2]);
2818 MAPCLR(pool->considered, p);
2820 pool_debug(pool, SOLV_ERROR, "disable: unknown package '%s'\n", pieces[2]);
2822 else if (!strcmp(pieces[0], "feature"))
2825 for (i = 1; i < npieces; i++)
2827 for (j = 0; features[j]; j++)
2828 if (!strcmp(pieces[i], features[j]))
2832 pool_debug(pool, SOLV_ERROR, "testcase_read: missing feature '%s'\n", pieces[i]);
2836 if (missing_features)
2839 else if (!strcmp(pieces[0], "genid") && npieces > 1)
2846 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
2850 genid = solv_extend(genid, ngenid, 1, sizeof(*genid), 7);
2851 if (!strcmp(pieces[1], "op") && npieces > 2)
2854 for (op = oplist; op->flags; op++)
2855 if (!strncmp(pieces[2], op->opname, strlen(op->opname)))
2859 pool_debug(pool, SOLV_ERROR, "testcase_read: genid: unknown op '%s'\n", pieces[2]);
2864 pool_debug(pool, SOLV_ERROR, "testcase_read: genid: out of stack\n");
2868 id = pool_rel2id(pool, genid[ngenid] , genid[ngenid + 1], op->flags, 1);
2870 else if (!strcmp(pieces[1], "lit"))
2871 id = pool_str2id(pool, npieces > 2 ? pieces[2] : "", 1);
2872 else if (!strcmp(pieces[1], "null"))
2874 else if (!strcmp(pieces[1], "dep"))
2875 id = testcase_str2dep(pool, pieces[2]);
2878 pool_debug(pool, SOLV_ERROR, "testcase_read: genid: unknown command '%s'\n", pieces[1]);
2881 genid[ngenid++] = id;
2883 else if (!strcmp(pieces[0], "autoinst") && npieces > 2)
2885 if (strcmp(pieces[1], "name"))
2887 pool_debug(pool, SOLV_ERROR, "testcase_read: autoinst: illegal mode\n");
2890 queue_push(&autoinstq, pool_str2id(pool, pieces[2], 1));
2894 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
2897 while (job && ngenid > 0)
2898 queue_push2(job, SOLVER_NOOP | SOLVER_SOLVABLE_PROVIDES, genid[--ngenid]);
2899 if (autoinstq.count)
2900 pool_add_userinstalled_jobs(pool, &autoinstq, job, GET_USERINSTALLED_NAMES | GET_USERINSTALLED_INVERTED);
2901 queue_free(&autoinstq);
2902 genid = solv_free(genid);
2903 buf = solv_free(buf);
2904 pieces = solv_free(pieces);
2905 solv_free(testcasedir);
2908 pool_addfileprovides(pool);
2909 pool_createwhatprovides(pool);
2913 solv = solver_create(pool);
2914 testcase_resetsolverflags(solv);
2918 if (missing_features)
2923 *resultflagsp = 77; /* hack for testsolv */
2929 testcase_resultdiff(const char *result1, const char *result2)
2931 Strqueue sq1, sq2, osq;
2933 strqueue_init(&sq1);
2934 strqueue_init(&sq2);
2935 strqueue_init(&osq);
2936 strqueue_split(&sq1, result1);
2937 strqueue_split(&sq2, result2);
2938 strqueue_sort(&sq1);
2939 strqueue_sort(&sq2);
2940 strqueue_diff(&sq1, &sq2, &osq);
2941 r = osq.nstr ? strqueue_join(&osq) : 0;
2942 strqueue_free(&sq1);
2943 strqueue_free(&sq2);
2944 strqueue_free(&osq);