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" },
51 static struct jobflags2str {
55 { SOLVER_WEAK, "weak" },
56 { SOLVER_ESSENTIAL, "essential" },
57 { SOLVER_CLEANDEPS, "cleandeps" },
58 { SOLVER_ORUPDATE, "orupdate" },
59 { SOLVER_FORCEBEST, "forcebest" },
60 { SOLVER_TARGETED, "targeted" },
61 { SOLVER_NOTBYUSER, "notbyuser" },
62 { SOLVER_SETEV, "setev" },
63 { SOLVER_SETEVR, "setevr" },
64 { SOLVER_SETARCH, "setarch" },
65 { SOLVER_SETVENDOR, "setvendor" },
66 { SOLVER_SETREPO, "setrepo" },
67 { SOLVER_NOAUTOSET, "noautoset" },
71 static struct resultflags2str {
74 } resultflags2str[] = {
75 { TESTCASE_RESULT_TRANSACTION, "transaction" },
76 { TESTCASE_RESULT_PROBLEMS, "problems" },
77 { TESTCASE_RESULT_ORPHANED, "orphaned" },
78 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
79 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
83 static struct solverflags2str {
87 } solverflags2str[] = {
88 { SOLVER_FLAG_ALLOW_DOWNGRADE, "allowdowngrade", 0 },
89 { SOLVER_FLAG_ALLOW_NAMECHANGE, "allownamechange", 1 },
90 { SOLVER_FLAG_ALLOW_ARCHCHANGE, "allowarchchange", 0 },
91 { SOLVER_FLAG_ALLOW_VENDORCHANGE, "allowvendorchange", 0 },
92 { SOLVER_FLAG_ALLOW_UNINSTALL, "allowuninstall", 0 },
93 { SOLVER_FLAG_NO_UPDATEPROVIDE, "noupdateprovide", 0 },
94 { SOLVER_FLAG_SPLITPROVIDES, "splitprovides", 0 },
95 { SOLVER_FLAG_IGNORE_RECOMMENDED, "ignorerecommended", 0 },
96 { SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, "addalreadyrecommended", 0 },
97 { SOLVER_FLAG_NO_INFARCHCHECK, "noinfarchcheck", 0 },
98 { SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES, "keepexplicitobsoletes", 0 },
99 { SOLVER_FLAG_BEST_OBEY_POLICY, "bestobeypolicy", 0 },
100 { SOLVER_FLAG_NO_AUTOTARGET, "noautotarget", 0 },
101 { SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, "dupallowdowngrade", 1 },
102 { SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, "dupallowarchchange", 1 },
103 { SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, "dupallowvendorchange", 1 },
104 { SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, "dupallownamechange", 1 },
105 { SOLVER_FLAG_KEEP_ORPHANS, "keeporphans", 0 },
106 { SOLVER_FLAG_BREAK_ORPHANS, "breakorphans", 0 },
107 { SOLVER_FLAG_FOCUS_INSTALLED, "focusinstalled", 0 },
108 { SOLVER_FLAG_YUM_OBSOLETES, "yumobsoletes", 0 },
112 static struct poolflags2str {
116 } poolflags2str[] = {
117 { POOL_FLAG_PROMOTEEPOCH, "promoteepoch", 0 },
118 { POOL_FLAG_FORBIDSELFCONFLICTS, "forbidselfconflicts", 0 },
119 { POOL_FLAG_OBSOLETEUSESPROVIDES, "obsoleteusesprovides", 0 },
120 { POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES, "implicitobsoleteusesprovides", 0 },
121 { POOL_FLAG_OBSOLETEUSESCOLORS, "obsoleteusescolors", 0 },
122 { POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS, "implicitobsoleteusescolors", 0 },
123 { POOL_FLAG_NOINSTALLEDOBSOLETES, "noinstalledobsoletes", 0 },
124 { POOL_FLAG_HAVEDISTEPOCH, "havedistepoch", 0 },
125 { POOL_FLAG_NOOBSOLETESMULTIVERSION, "noobsoletesmultiversion", 0 },
126 { POOL_FLAG_ADDFILEPROVIDESFILTERED, "addfileprovidesfiltered", 0 },
130 static struct disttype2str {
134 { DISTTYPE_RPM, "rpm" },
135 { DISTTYPE_DEB, "deb" },
136 { DISTTYPE_ARCH, "arch" },
137 { DISTTYPE_HAIKU, "haiku" },
141 static struct selflags2str {
145 { SELECTION_NAME, "name" },
146 { SELECTION_PROVIDES, "provides" },
147 { SELECTION_FILELIST, "filelist" },
148 { SELECTION_CANON, "canon" },
149 { SELECTION_DOTARCH, "dotarch" },
150 { SELECTION_REL, "rel" },
151 { SELECTION_INSTALLED_ONLY, "installedonly" },
152 { SELECTION_GLOB, "glob" },
153 { SELECTION_FLAT, "flat" },
154 { SELECTION_NOCASE, "nocase" },
155 { SELECTION_SOURCE_ONLY, "sourceonly" },
156 { SELECTION_WITH_SOURCE, "withsource" },
161 typedef struct strqueue {
166 #define STRQUEUE_BLOCK 63
169 strqueue_init(Strqueue *q)
176 strqueue_free(Strqueue *q)
179 for (i = 0; i < q->nstr; i++)
180 solv_free(q->str[i]);
181 q->str = solv_free(q->str);
186 strqueue_push(Strqueue *q, const char *s)
188 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
189 q->str[q->nstr++] = solv_strdup(s);
193 strqueue_pushjoin(Strqueue *q, const char *s1, const char *s2, const char *s3)
195 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
196 q->str[q->nstr++] = solv_dupjoin(s1, s2, s3);
200 strqueue_sort_cmp(const void *ap, const void *bp, void *dp)
202 const char *a = *(const char **)ap;
203 const char *b = *(const char **)bp;
204 return strcmp(a ? a : "", b ? b : "");
208 strqueue_sort(Strqueue *q)
211 solv_sort(q->str, q->nstr, sizeof(*q->str), strqueue_sort_cmp, 0);
215 strqueue_sort_u(Strqueue *q)
219 for (i = j = 0; i < q->nstr; i++)
220 if (!j || strqueue_sort_cmp(q->str + i, q->str + j - 1, 0) != 0)
221 q->str[j++] = q->str[i];
226 strqueue_join(Strqueue *q)
230 for (i = 0; i < q->nstr; i++)
232 l += strlen(q->str[i]) + 1;
233 l++; /* trailing \0 */
236 for (i = 0; i < q->nstr; i++)
239 strcpy(rp, q->str[i]);
248 strqueue_split(Strqueue *q, const char *s)
253 while ((p = strchr(s, '\n')) != 0)
255 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
256 q->str[q->nstr] = solv_malloc(p - s + 1);
258 memcpy(q->str[q->nstr], s, p - s);
259 q->str[q->nstr][p - s] = 0;
268 strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
271 while (i < sq1->nstr && j < sq2->nstr)
273 int r = strqueue_sort_cmp(sq1->str + i, sq2->str + j, 0);
277 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
279 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
281 while (i < sq1->nstr)
282 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
283 while (j < sq2->nstr)
284 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
288 pool_isknownarch(Pool *pool, Id id)
290 if (!id || id == ID_EMPTY)
292 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
294 if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id]))
300 testcase_str2dep_simple(Pool *pool, const char **sp)
307 while (*s == ' ' || *s == '\t')
310 while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>')
314 while (*s && *s != ')')
320 if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')')
322 Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0);
323 if (pool_isknownarch(pool, archid))
325 id = pool_strn2id(pool, n, a - n, 1);
326 id = pool_rel2id(pool, id, archid, REL_ARCH, 1);
329 id = pool_strn2id(pool, n, s - n, 1);
331 else if (s - n > 4 && s[-4] == ':' && !strncmp(s - 4, ":any", 4))
333 id = pool_strn2id(pool, n, s - n - 4, 1);
334 id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1);
337 id = pool_strn2id(pool, n, s - n, 1);
343 while (*s == ' ' || *s == '\t')
346 if (*s == '!' && s[1] == '=') /* support != as synonym for <> */
348 flags = REL_LT | REL_GT;
367 while (*s == ' ' || *s == '\t')
370 while (*s && *s != ' ' && *s != '\t')
372 evr = pool_strn2id(pool, n, s - n, 1);
373 if (*s == ' ' && !strcmp(s, " compat >= "))
376 while (*s == ' ' || *s == '\t')
379 while (*s && *s != ' ' && *s != '\t')
381 evr = pool_rel2id(pool, evr, pool_strn2id(pool, n, s - n, 1), REL_COMPAT, 1);
384 return pool_rel2id(pool, id, evr, flags, 1);
388 testcase_str2dep_complex(Pool *pool, const char **sp)
392 #ifdef ENABLE_COMPLEX_DEPS
393 while (*s == ' ' || *s == '\t')
398 id = testcase_str2dep_complex(pool, &s);
401 while (*s == ' ' || *s == '\t')
406 id = testcase_str2dep_simple(pool, &s);
410 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1);
415 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1);
417 else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t'))
420 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1);
427 testcase_str2dep(Pool *pool, const char *s)
429 return testcase_str2dep_complex(pool, &s);
433 testcase_repoid2str(Pool *pool, Id repoid)
435 Repo *repo = pool_id2repo(pool, repoid);
438 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
440 for (rp = r; *rp; rp++)
441 if (*rp == ' ' || *rp == '\t')
448 sprintf(buf, "#%d", repoid);
449 return pool_tmpjoin(pool, buf, 0, 0);
454 testcase_solvid2str(Pool *pool, Id p)
456 Solvable *s = pool->solvables + p;
457 const char *n, *e, *a;
460 if (p == SYSTEMSOLVABLE)
462 n = pool_id2str(pool, s->name);
463 e = pool_id2str(pool, s->evr);
464 a = pool_id2str(pool, s->arch);
465 str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
466 sprintf(str, "%s-%s.%s", n, e, a);
468 return pool_tmpappend(pool, str, "@", 0);
472 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
474 if (str2[l] == ' ' || str2[l] == '\t')
478 sprintf(buf, "@#%d", s->repo->repoid);
479 return pool_tmpappend(pool, str, buf, 0);
483 testcase_str2repo(Pool *pool, const char *str)
487 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
491 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
492 repoid = repoid * 10 + (str[j] - '0');
493 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
494 repo = pool_id2repo(pool, repoid);
498 FOR_REPOS(repoid, repo)
503 l = strlen(repo->name);
504 for (i = 0; i < l; i++)
506 int c = repo->name[i];
507 if (c == ' ' || c == '\t')
512 if (i == l && !str[l])
515 if (repoid >= pool->nrepos)
522 testcase_str2solvid(Pool *pool, const char *str)
524 int i, l = strlen(str);
531 if (*str == '@' && !strcmp(str, "@SYSTEM"))
532 return SYSTEMSOLVABLE;
534 for (i = l - 1; i >= 0; i--)
535 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
540 /* now find the arch (if present) */
542 for (i = repostart - 1; i > 0; i--)
545 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
550 /* now find the name */
551 for (i = repostart - 1; i > 0; i--)
555 Id nid, evrid, p, pp;
556 nid = pool_strn2id(pool, str, i, 0);
559 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
562 FOR_PROVIDES(p, pp, nid)
564 Solvable *s = pool->solvables + p;
565 if (s->name != nid || s->evr != evrid)
567 if (repo && s->repo != repo)
569 if (arch && s->arch != arch)
579 testcase_job2str(Pool *pool, Id how, Id what)
586 Id select = how & SOLVER_SELECTMASK;
588 for (i = 0; job2str[i].str; i++)
589 if ((how & SOLVER_JOBMASK) == job2str[i].job)
591 jobstr = job2str[i].str ? job2str[i].str : "unknown";
592 if (select == SOLVER_SOLVABLE)
595 pkgstr = testcase_solvid2str(pool, what);
597 else if (select == SOLVER_SOLVABLE_NAME)
600 pkgstr = pool_dep2str(pool, what);
602 else if (select == SOLVER_SOLVABLE_PROVIDES)
604 selstr = " provides ";
605 pkgstr = pool_dep2str(pool, what);
607 else if (select == SOLVER_SOLVABLE_ONE_OF)
612 while ((p = pool->whatprovidesdata[what++]) != 0)
614 const char *s = testcase_solvid2str(pool, p);
617 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
618 pool_freetmpspace(pool, s);
626 else if (select == SOLVER_SOLVABLE_REPO)
628 Repo *repo = pool_id2repo(pool, what);
633 sprintf(buf, "#%d", repo->repoid);
634 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
637 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
639 else if (select == SOLVER_SOLVABLE_ALL)
646 selstr = " unknown ";
649 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
651 ret = pool_tmpappend(pool, ret, " ", 0);
652 for (i = 0; jobflags2str[i].str; i++)
653 if ((how & jobflags2str[i].flag) != 0)
654 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
660 ret = pool_tmpappend(pool, ret, "]", 0);
666 str2selflags(Pool *pool, char *s) /* modifies the string! */
671 char *se = strchr(s, ',');
674 for (i = 0; selflags2str[i].str; i++)
675 if (!strcmp(s, selflags2str[i].str))
677 selflags |= selflags2str[i].flag;
680 if (!selflags2str[i].str)
681 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection flag '%s'\n", s);
688 str2jobflags(Pool *pool, char *s) /* modifies the string */
693 char *se = strchr(s, ',');
696 for (i = 0; jobflags2str[i].str; i++)
697 if (!strcmp(s, jobflags2str[i].str))
699 jobflags |= jobflags2str[i].flag;
702 if (!jobflags2str[i].str)
703 pool_debug(pool, SOLV_ERROR, "str2job: unknown job flag '%s'\n", s);
710 testcase_str2job(Pool *pool, const char *str, Id *whatp)
720 /* so we can patch it */
721 s = pool_tmpjoin(pool, str, 0, 0);
722 /* split it in pieces */
725 while (*s == ' ' || *s == '\t')
729 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
730 pieces[npieces++] = s;
731 while (*s && *s != ' ' && *s != '\t')
738 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
743 for (i = 0; job2str[i].str; i++)
744 if (!strcmp(pieces[0], job2str[i].str))
748 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
752 job = job2str[i].job;
756 char *flags = pieces[npieces - 1];
757 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
761 flags[strlen(flags) - 1] = 0;
762 job |= str2jobflags(pool, flags);
765 if (!strcmp(pieces[1], "pkg"))
769 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
773 job |= SOLVER_SOLVABLE;
774 what = testcase_str2solvid(pool, pieces[2]);
777 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
782 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
784 /* join em again for dep2str... */
786 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
790 if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
792 char *spe = strchr(pieces[2], '(');
793 int l = strlen(pieces[2]);
794 if (spe && pieces[2][l - 1] == ')')
796 /* special namespace provides */
797 if (strcmp(spe, "(<NULL>)") != 0)
799 pieces[2][l - 1] = 0;
800 what = testcase_str2dep(pool, spe + 1);
801 pieces[2][l - 1] = ')';
803 what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
807 what = testcase_str2dep(pool, pieces[2]);
808 if (pieces[1][0] == 'n')
809 job |= SOLVER_SOLVABLE_NAME;
811 job |= SOLVER_SOLVABLE_PROVIDES;
813 else if (!strcmp(pieces[1], "oneof"))
816 job |= SOLVER_SOLVABLE_ONE_OF;
818 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
820 for (i = 2; i < npieces; i++)
822 Id p = testcase_str2solvid(pool, pieces[i]);
825 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
833 what = pool_queuetowhatprovides(pool, &q);
836 else if (!strcmp(pieces[1], "repo"))
841 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
845 repo = testcase_str2repo(pool, pieces[2]);
848 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
852 job |= SOLVER_SOLVABLE_REPO;
855 else if (!strcmp(pieces[1], "all"))
857 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
859 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
863 job |= SOLVER_SOLVABLE_ALL;
868 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
878 addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue)
885 for (i = 0; job2str[i].str; i++)
886 if (!strcmp(pieces[0], job2str[i].str))
890 pool_debug(pool, SOLV_ERROR, "selstr2job: unknown job '%s'\n", pieces[0]);
893 job = job2str[i].job;
896 char *flags = pieces[npieces - 1];
897 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
901 flags[strlen(flags) - 1] = 0;
902 job |= str2jobflags(pool, flags);
907 pool_debug(pool, SOLV_ERROR, "selstr2job: no selection flags\n");
910 selflags = str2selflags(pool, pieces[3]);
912 r = selection_make(pool, &sel, pieces[2], selflags);
913 for (i = 0; i < sel.count; i += 2)
914 queue_push2(jobqueue, job | sel.elements[i], sel.elements[i + 1]);
920 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
922 Pool *pool = repo->pool;
929 dp = repo->idarraydata + off;
931 while ((id = *dp++) != 0)
933 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
936 fprintf(fp, "-%s\n", tag);
941 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
946 idstr = pool_dep2str(pool, id);
949 Reldep *rd = GETRELDEP(pool, id);
950 if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
952 if (!strncmp(idstr, "namespace:", 10))
955 if (key == SOLVABLE_SUPPLEMENTS)
957 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
959 if (!strncmp(idstr, "namespace:", 10))
962 else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
964 if (!strncmp(idstr, "namespace:", 10))
967 else if (rd->flags == REL_AND)
969 /* either packageand chain or modalias */
971 if (ISRELDEP(rd->evr))
973 Reldep *mrd = GETRELDEP(pool, rd->evr);
974 if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
976 idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
977 idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
979 else if (mrd->flags >= 8)
984 /* must be and chain */
985 idstr = pool_dep2str(pool, rd->evr);
991 rd = GETRELDEP(pool, id);
992 if (rd->flags != REL_AND)
994 idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
996 idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
997 idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
1000 else if (rd->flags >= 8)
1006 fprintf(fp, "+%s\n", tag);
1009 fprintf(fp, "%s\n", idstr);
1011 if (key == SOLVABLE_PROVIDES)
1013 /* add the filelist */
1015 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
1016 while (dataiterator_step(&di))
1018 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
1021 Id id = pool_str2id(pool, s, 0);
1024 for (dp = prvdp; *dp; dp++)
1028 continue; /* already included */
1033 fprintf(fp, "+%s", tag);
1036 fprintf(fp, "%s\n", s);
1040 fprintf(fp, "-%s\n", tag);
1044 testcase_write_testtags(Repo *repo, FILE *fp)
1046 Pool *pool = repo->pool;
1052 const char *release;
1056 fprintf(fp, "=Ver: 2.0\n");
1057 FOR_REPO_SOLVABLES(repo, p, s)
1059 name = pool_id2str(pool, s->name);
1060 evr = pool_id2str(pool, s->evr);
1061 arch = pool_id2str(pool, s->arch);
1062 release = strrchr(evr, '-');
1064 release = evr + strlen(evr);
1065 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
1066 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
1068 fprintf(fp, "=Sum: %s\n", tmp);
1069 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
1070 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
1071 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
1072 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
1073 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
1074 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
1075 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
1076 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
1078 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
1079 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
1081 fprintf(fp, "=Tim: %u\n", ti);
1086 static inline Offset
1087 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
1089 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
1090 return repo_addid_dep(repo, olddeps, id, marker);
1094 finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
1100 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1102 char *p = strrchr(filelist + l, '/');
1106 did = repodata_str2dir(data, filelist + l, 1);
1109 did = repodata_str2dir(data, "/", 1);
1110 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
1113 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
1114 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
1115 s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
1116 s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
1119 /* stripped down version of susetags parser used for testcases */
1121 testcase_add_testtags(Repo *repo, FILE *fp, int flags)
1123 Pool *pool = repo->pool;
1136 data = repo_add_repodata(repo, flags);
1141 line = solv_malloc(aline);
1145 if (linep - line + 16 > aline)
1147 aline = linep - line;
1148 line = solv_realloc(line, aline + 512);
1149 linep = line + aline;
1152 if (!fgets(linep, aline - (linep - line), fp))
1154 linep += strlen(linep);
1155 if (linep == line || linep[-1] != '\n')
1158 linep = line + intag;
1161 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
1168 else if (line[0] == '+' && line[1] && line[1] != ':')
1170 char *tagend = strchr(line, ':');
1175 intag = tagend + 2 - line;
1176 linep = line + intag;
1179 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
1181 tag = line[1] << 16 | line[2] << 8 | line[3];
1184 case 'P' << 16 | 'k' << 8 | 'g':
1186 finish_solvable(pool, data, s, filelist, nfilelist);
1188 if (split(line + 5, sp, 5) != 4)
1190 s = pool_id2solvable(pool, repo_add_solvable(repo));
1191 s->name = pool_str2id(pool, sp[0], 1);
1192 /* join back version and release */
1193 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
1195 s->evr = makeevr(pool, sp[1]);
1196 s->arch = pool_str2id(pool, sp[3], 1);
1198 case 'S' << 16 | 'u' << 8 | 'm':
1199 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
1201 case 'V' << 16 | 'n' << 8 | 'd':
1202 s->vendor = pool_str2id(pool, line + 6, 1);
1204 case 'T' << 16 | 'i' << 8 | 'm':
1207 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
1209 case 'R' << 16 | 'e' << 8 | 'q':
1210 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
1212 case 'P' << 16 | 'r' << 8 | 'q':
1213 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
1215 case 'P' << 16 | 'r' << 8 | 'v':
1218 int l = strlen(line + 6) + 1;
1219 if (nfilelist + l > afilelist)
1221 afilelist = nfilelist + l + 512;
1222 filelist = solv_realloc(filelist, afilelist);
1224 memcpy(filelist + nfilelist, line + 6, l);
1231 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1232 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1235 s->provides = adddep(repo, s->provides, line + 6, 0);
1237 case 'O' << 16 | 'b' << 8 | 's':
1238 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1240 case 'C' << 16 | 'o' << 8 | 'n':
1241 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1243 case 'R' << 16 | 'e' << 8 | 'c':
1244 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1246 case 'S' << 16 | 'u' << 8 | 'p':
1247 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1249 case 'S' << 16 | 'u' << 8 | 'g':
1250 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1252 case 'E' << 16 | 'n' << 8 | 'h':
1253 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1260 finish_solvable(pool, data, s, filelist, nfilelist);
1262 solv_free(filelist);
1263 repodata_free_dircache(data);
1264 if (!(flags & REPO_NO_INTERNALIZE))
1265 repodata_internalize(data);
1270 testcase_getpoolflags(Pool *pool)
1272 const char *str = 0;
1274 for (i = 0; poolflags2str[i].str; i++)
1276 v = pool_get_flag(pool, poolflags2str[i].flag);
1277 if (v == poolflags2str[i].def)
1279 str = pool_tmpappend(pool, str, v ? " " : " !", poolflags2str[i].str);
1281 return str ? str + 1 : "";
1285 testcase_setpoolflags(Pool *pool, const char *str)
1287 const char *p = str, *s;
1291 while (*p == ' ' || *p == '\t' || *p == ',')
1302 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1304 for (i = 0; poolflags2str[i].str; i++)
1305 if (!strncmp(poolflags2str[i].str, s, p - s) && poolflags2str[i].str[p - s] == 0)
1307 if (!poolflags2str[i].str)
1309 pool_debug(pool, SOLV_ERROR, "setpoolflags: unknown flag '%.*s'\n", (int)(p - s), s);
1312 pool_set_flag(pool, poolflags2str[i].flag, v);
1318 testcase_resetpoolflags(Pool *pool)
1321 for (i = 0; poolflags2str[i].str; i++)
1322 pool_set_flag(pool, poolflags2str[i].flag, poolflags2str[i].def);
1326 testcase_getsolverflags(Solver *solv)
1328 Pool *pool = solv->pool;
1329 const char *str = 0;
1331 for (i = 0; solverflags2str[i].str; i++)
1333 v = solver_get_flag(solv, solverflags2str[i].flag);
1334 if (v == solverflags2str[i].def)
1336 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1338 return str ? str + 1 : "";
1342 testcase_setsolverflags(Solver *solv, const char *str)
1344 const char *p = str, *s;
1348 while (*p == ' ' || *p == '\t' || *p == ',')
1359 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1361 for (i = 0; solverflags2str[i].str; i++)
1362 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1364 if (!solverflags2str[i].str)
1366 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", (int)(p - s), s);
1369 solver_set_flag(solv, solverflags2str[i].flag, v);
1375 testcase_resetsolverflags(Solver *solv)
1378 for (i = 0; solverflags2str[i].str; i++)
1379 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1383 testcase_ruleid(Solver *solv, Id rid)
1389 const unsigned char *md5;
1395 solver_ruleliterals(solv, rid, &q);
1396 for (i = 0; i < q.count; i++)
1398 Id p = q.elements[i];
1399 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1401 s = pool_tmpjoin(solv->pool, "!", s, 0);
1402 strqueue_push(&sq, s);
1405 strqueue_sort_u(&sq);
1406 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1407 for (i = 0; i < sq.nstr; i++)
1408 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1409 md5 = solv_chksum_get(chk, &md5l);
1410 s = pool_bin2hex(solv->pool, md5, md5l);
1411 chk = solv_chksum_free(chk, 0);
1417 testcase_problemid(Solver *solv, Id problem)
1422 const unsigned char *md5;
1426 /* we build a hash of all rules that define the problem */
1429 solver_findallproblemrules(solv, problem, &q);
1430 for (i = 0; i < q.count; i++)
1431 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1433 strqueue_sort_u(&sq);
1434 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1435 for (i = 0; i < sq.nstr; i++)
1436 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1437 md5 = solv_chksum_get(chk, &md5l);
1438 s = pool_bin2hex(solv->pool, md5, 4);
1439 chk = solv_chksum_free(chk, 0);
1445 testcase_solutionid(Solver *solv, Id problem, Id solution)
1449 const unsigned char *md5;
1453 intid = solver_solutionelement_internalid(solv, problem, solution);
1454 /* internal stuff! handle with care! */
1458 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1463 s = testcase_ruleid(solv, intid);
1465 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1466 solv_chksum_add(chk, s, strlen(s) + 1);
1467 md5 = solv_chksum_get(chk, &md5l);
1468 s = pool_bin2hex(solv->pool, md5, 4);
1469 chk = solv_chksum_free(chk, 0);
1473 static struct class2str {
1477 { SOLVER_TRANSACTION_ERASE, "erase" },
1478 { SOLVER_TRANSACTION_INSTALL, "install" },
1479 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1480 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1481 { SOLVER_TRANSACTION_CHANGED, "change" },
1482 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1483 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1484 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1485 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1490 testcase_solverresult(Solver *solv, int resultflags)
1492 Pool *pool = solv->pool;
1500 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1502 Transaction *trans = solver_create_transaction(solv);
1506 for (i = 0; class2str[i].str; i++)
1509 transaction_classify_pkgs(trans, SOLVER_TRANSACTION_KEEP_PSEUDO, class2str[i].class, 0, 0, &q);
1510 for (j = 0; j < q.count; j++)
1514 if (pool->installed && pool->solvables[p].repo == pool->installed)
1515 op = transaction_obs_pkg(trans, p);
1516 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1518 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1519 strqueue_push(&sq, s);
1523 transaction_free(trans);
1525 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1527 char *probprefix, *solprefix;
1528 int problem, solution, element;
1531 pcnt = solver_problem_count(solv);
1532 for (problem = 1; problem <= pcnt; problem++)
1534 Id rid, from, to, dep;
1535 SolverRuleinfo rinfo;
1536 rid = solver_findproblemrule(solv, problem);
1537 s = testcase_problemid(solv, problem);
1538 probprefix = solv_dupjoin("problem ", s, 0);
1539 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1540 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1541 strqueue_push(&sq, s);
1542 scnt = solver_solution_count(solv, problem);
1543 for (solution = 1; solution <= scnt; solution++)
1545 s = testcase_solutionid(solv, problem, solution);
1546 solprefix = solv_dupjoin(probprefix, " solution ", s);
1548 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1550 if (p == SOLVER_SOLUTION_JOB)
1551 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1552 else if (p > 0 && op == 0)
1553 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1554 else if (p > 0 && op > 0)
1556 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1557 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1559 else if (p < 0 && op > 0)
1560 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1562 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1563 strqueue_push(&sq, s);
1565 solv_free(solprefix);
1567 solv_free(probprefix);
1571 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1576 solver_get_orphaned(solv, &q);
1577 for (i = 0; i < q.count; i++)
1579 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1580 strqueue_push(&sq, s);
1585 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1591 solver_get_recommendations(solv, &qr, &qs, 0);
1592 for (i = 0; i < qr.count; i++)
1594 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1595 strqueue_push(&sq, s);
1597 for (i = 0; i < qs.count; i++)
1599 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1600 strqueue_push(&sq, s);
1606 if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0)
1612 solver_get_unneeded(solv, &q, 0);
1613 solver_get_unneeded(solv, &qf, 1);
1614 for (i = j = 0; i < q.count; i++)
1616 /* we rely on qf containing a subset of q in the same order */
1617 if (j < qf.count && q.elements[i] == qf.elements[j])
1619 s = pool_tmpjoin(pool, "unneeded_filtered ", testcase_solvid2str(pool, q.elements[i]), 0);
1623 s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0);
1624 strqueue_push(&sq, s);
1631 result = strqueue_join(&sq);
1638 testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasename, const char *resultname)
1640 Pool *pool = solv->pool;
1651 testcasename = "testcase.t";
1653 resultname = "solver.result";
1655 if (mkdir(dir, 0777) && errno != EEXIST)
1657 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
1661 FOR_REPOS(repoid, repo)
1663 const char *name = testcase_repoid2str(pool, repoid);
1665 if (repo->subpriority)
1666 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
1668 sprintf(priobuf, "%d", repo->priority);
1669 out = pool_tmpjoin(pool, name, ".repo", ".gz");
1670 cmd = pool_tmpjoin(pool, "repo ", name, " ");
1671 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
1672 cmd = pool_tmpappend(pool, cmd, "testtags ", out);
1673 strqueue_push(&sq, cmd);
1674 out = pool_tmpjoin(pool, dir, "/", out);
1675 if (!(fp = solv_xfopen(out, "w")))
1677 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1681 testcase_write_testtags(repo, fp);
1684 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1689 /* hmm, this is not optimal... we currently search for the lowest score */
1691 arch = pool->solvables[SYSTEMSOLVABLE].arch;
1692 for (i = 0; i < pool->lastarch; i++)
1694 if (pool->id2arch[i] == 1 && !lowscore)
1696 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
1699 lowscore = pool->id2arch[i];
1702 cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
1703 for (i = 0; disttype2str[i].str != 0; i++)
1704 if (pool->disttype == disttype2str[i].type)
1706 pool_tmpappend(pool, cmd, " ", disttype2str[i].str ? disttype2str[i].str : "unknown");
1707 if (pool->installed)
1708 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
1709 strqueue_push(&sq, cmd);
1710 s = testcase_getpoolflags(solv->pool);
1713 cmd = pool_tmpjoin(pool, "poolflags ", s, 0);
1714 strqueue_push(&sq, cmd);
1717 if (pool->vendorclasses)
1720 for (i = 0; pool->vendorclasses[i]; i++)
1722 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
1723 if (!pool->vendorclasses[i + 1])
1725 strqueue_push(&sq, cmd);
1732 /* dump disabled packages (must come before the namespace/job lines) */
1733 if (pool->considered)
1736 FOR_POOL_SOLVABLES(p)
1737 if (!MAPTST(pool->considered, p))
1739 cmd = pool_tmpjoin(pool, "disable pkg ", testcase_solvid2str(pool, p), 0);
1740 strqueue_push(&sq, cmd);
1744 s = testcase_getsolverflags(solv);
1747 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
1748 strqueue_push(&sq, cmd);
1751 /* now dump all the ns callback values we know */
1752 if (pool->nscallback)
1756 for (rid = 1; rid < pool->nrels; rid++)
1758 Reldep *rd = pool->rels + rid;
1759 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1761 /* evaluate all namespace ids, skip empty results */
1762 d = pool_whatprovides(pool, MAKERELDEP(rid));
1763 if (!d || !pool->whatprovidesdata[d])
1765 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
1766 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
1767 for (; pool->whatprovidesdata[d]; d++)
1768 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
1769 strqueue_push(&sq, cmd);
1773 for (i = 0; i < solv->job.count; i += 2)
1775 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
1776 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
1777 strqueue_push(&sq, cmd);
1784 for (i = 0; resultflags2str[i].str; i++)
1785 if ((resultflags & resultflags2str[i].flag) != 0)
1786 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
1787 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", 0);
1788 cmd = pool_tmpappend(pool, cmd, " ", resultname);
1789 strqueue_push(&sq, cmd);
1790 result = testcase_solverresult(solv, resultflags);
1791 if (!strcmp(resultname, "<inline>"))
1795 strqueue_init(&rsq);
1796 strqueue_split(&rsq, result);
1797 for (i = 0; i < rsq.nstr; i++)
1799 cmd = pool_tmpjoin(pool, "#>", rsq.str[i], 0);
1800 strqueue_push(&sq, cmd);
1802 strqueue_free(&rsq);
1806 out = pool_tmpjoin(pool, dir, "/", resultname);
1807 if (!(fp = fopen(out, "w")))
1809 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1814 if (result && *result && fwrite(result, strlen(result), 1, fp) != 1)
1816 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1824 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1832 cmd = strqueue_join(&sq);
1833 out = pool_tmpjoin(pool, dir, "/", testcasename);
1834 if (!(fp = fopen(out, "w")))
1836 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1840 if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
1842 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1849 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1859 read_inline_file(FILE *fp, char **bufp, char **bufpp, int *buflp)
1861 char *result = solv_malloc(1024);
1868 if (rp - result + 256 >= resultl)
1870 resultl = rp - result;
1871 result = solv_realloc(result, resultl + 1024);
1872 rp = result + resultl;
1875 if (!fgets(rp, resultl - (rp - result), fp))
1878 if (rl && (rp == result || rp[-1] == '\n'))
1880 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
1882 memmove(rp, rp + 2, rl - 2);
1887 while (rl + 16 > *buflp)
1889 *bufp = solv_realloc(*bufp, *buflp + 512);
1892 memmove(*bufp, rp, rl);
1893 if ((*bufp)[rl - 1] == '\n')
1899 (*bufpp) = *bufp + rl;
1916 char *result = solv_malloc(1024);
1923 if (rp - result + 256 >= resultl)
1925 resultl = rp - result;
1926 result = solv_realloc(result, resultl + 1024);
1927 rp = result + resultl;
1930 rl = fread(rp, 1, resultl - (rp - result), fp);
1942 str2resultflags(Pool *pool, char *s) /* modifies the string! */
1944 int i, resultflags = 0;
1947 char *se = strchr(s, ',');
1950 for (i = 0; resultflags2str[i].str; i++)
1951 if (!strcmp(s, resultflags2str[i].str))
1953 resultflags |= resultflags2str[i].flag;
1956 if (!resultflags2str[i].str)
1957 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
1964 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
1969 char *testcasedir, *s;
1975 int poolflagsreset = 0;
1977 if (!fp && !(fp = fopen(testcase, "r")))
1979 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
1982 testcasedir = solv_strdup(testcase);
1983 if ((s = strrchr(testcasedir, '/')) != 0)
1988 buf = solv_malloc(bufl);
1993 if (bufp - buf + 16 > bufl)
1996 buf = solv_realloc(buf, bufl + 512);
2000 if (!fgets(bufp, bufl - (bufp - buf), fp))
2004 if (!l || buf[l - 1] != '\n')
2011 while (*s && (*s == ' ' || *s == '\t'))
2013 if (!*s || *s == '#')
2016 /* split it in pieces */
2019 while (*s == ' ' || *s == '\t')
2023 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2024 pieces[npieces++] = s;
2025 while (*s && *s != ' ' && *s != '\t')
2030 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2031 pieces[npieces] = 0;
2032 if (!strcmp(pieces[0], "repo") && npieces >= 4)
2034 Repo *repo = repo_create(pool, pieces[1]);
2040 if (!poolflagsreset)
2043 testcase_resetpoolflags(pool); /* hmm */
2045 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
2048 prio = atoi(pieces[2]);
2050 repo->priority = prio;
2051 repo->subpriority = subprio;
2052 if (strcmp(pieces[3], "empty") != 0)
2054 const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0); /* gets overwritten in <inline> case */
2055 if (!strcmp(pieces[4], "<inline>"))
2057 char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
2059 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
2063 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
2064 rfp = solv_xfopen(rdata, "r");
2068 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2070 else if (!strcmp(repotype, "testtags"))
2072 testcase_add_testtags(repo, rfp, 0);
2075 else if (!strcmp(repotype, "solv"))
2077 repo_add_solv(repo, rfp, 0);
2081 else if (!strcmp(repotype, "helix"))
2083 extern int repo_add_helix(Repo *repo, FILE *fp, int flags);
2084 repo_add_helix(repo, rfp, 0);
2091 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
2095 else if (!strcmp(pieces[0], "system") && npieces >= 3)
2099 /* must set the disttype before the arch */
2100 for (i = 0; disttype2str[i].str != 0; i++)
2101 if (!strcmp(disttype2str[i].str, pieces[2]))
2103 if (!disttype2str[i].str)
2104 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown disttype '%s'\n", pieces[2]);
2105 else if (pool->disttype != disttype2str[i].type)
2107 #ifdef MULTI_SEMANTICS
2108 pool_setdisttype(pool, disttype2str[i].type);
2110 pool_debug(pool, SOLV_ERROR, "testcase_read: system: cannot change disttype to '%s'\n", pieces[2]);
2113 if (strcmp(pieces[1], "unset") == 0)
2114 pool_setarch(pool, 0);
2115 else if (pieces[1][0] == ':')
2116 pool_setarchpolicy(pool, pieces[1] + 1);
2118 pool_setarch(pool, pieces[1]);
2121 Repo *repo = testcase_str2repo(pool, pieces[3]);
2123 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
2125 pool_set_installed(pool, repo);
2128 else if (!strcmp(pieces[0], "job") && npieces > 1)
2134 pool_addfileprovides(pool);
2135 pool_createwhatprovides(pool);
2138 if (npieces >= 3 && !strcmp(pieces[2], "selection"))
2140 addselectionjob(pool, pieces + 1, npieces - 1, job);
2144 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
2147 how = testcase_str2job(pool, pieces[1], &what);
2148 if (how >= 0 && job)
2149 queue_push2(job, how, what);
2151 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
2153 pool_addvendorclass(pool, (const char **)(pieces + 1));
2155 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
2157 int i = strlen(pieces[1]);
2158 s = strchr(pieces[1], '(');
2159 if (!s && pieces[1][i - 1] != ')')
2161 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
2169 pieces[1][i - 1] = 0;
2170 name = pool_str2id(pool, pieces[1], 1);
2171 evr = pool_str2id(pool, s + 1, 1);
2173 pieces[1][i - 1] = ')';
2174 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
2175 for (i = 2; i < npieces; i++)
2176 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
2177 /* now do the callback */
2180 pool_addfileprovides(pool);
2181 pool_createwhatprovides(pool);
2184 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
2188 else if (!strcmp(pieces[0], "poolflags"))
2191 if (!poolflagsreset)
2194 testcase_resetpoolflags(pool); /* hmm */
2196 for (i = 1; i < npieces; i++)
2197 testcase_setpoolflags(pool, pieces[i]);
2199 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
2204 solv = solver_create(pool);
2205 testcase_resetsolverflags(solv);
2207 for (i = 1; i < npieces; i++)
2208 testcase_setsolverflags(solv, pieces[i]);
2210 else if (!strcmp(pieces[0], "result") && npieces > 1)
2213 int resultflags = str2resultflags(pool, pieces[1]);
2217 rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
2218 if (!strcmp(pieces[2], "<inline>"))
2219 result = read_inline_file(fp, &buf, &bufp, &bufl);
2222 FILE *rfp = fopen(rdata, "r");
2224 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2227 result = read_file(rfp);
2237 *resultflagsp = resultflags;
2239 else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
2243 else if (!strcmp(pieces[0], "disable") && npieces == 3)
2246 if (strcmp(pieces[1], "pkg"))
2248 pool_debug(pool, SOLV_ERROR, "testcase_read: bad disable type '%s'\n", pieces[1]);
2252 pool_createwhatprovides(pool);
2254 if (!pool->considered)
2256 pool->considered = solv_calloc(1, sizeof(Map));
2257 map_init(pool->considered, pool->nsolvables);
2258 map_setall(pool->considered);
2260 p = testcase_str2solvid(pool, pieces[2]);
2262 MAPCLR(pool->considered, p);
2264 pool_debug(pool, SOLV_ERROR, "disable: unknown package '%s'\n", pieces[2]);
2268 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
2271 buf = solv_free(buf);
2272 pieces = solv_free(pieces);
2273 solv_free(testcasedir);
2276 pool_addfileprovides(pool);
2277 pool_createwhatprovides(pool);
2281 solv = solver_create(pool);
2282 testcase_resetsolverflags(solv);
2290 testcase_resultdiff(char *result1, char *result2)
2292 Strqueue sq1, sq2, osq;
2294 strqueue_init(&sq1);
2295 strqueue_init(&sq2);
2296 strqueue_init(&osq);
2297 strqueue_split(&sq1, result1);
2298 strqueue_split(&sq2, result2);
2299 strqueue_sort(&sq1);
2300 strqueue_sort(&sq2);
2301 strqueue_diff(&sq1, &sq2, &osq);
2302 r = osq.nstr ? strqueue_join(&osq) : 0;
2303 strqueue_free(&sq1);
2304 strqueue_free(&sq2);
2305 strqueue_free(&osq);