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_SETEV, "setev" },
62 { SOLVER_SETEVR, "setevr" },
63 { SOLVER_SETARCH, "setarch" },
64 { SOLVER_SETVENDOR, "setvendor" },
65 { SOLVER_SETREPO, "setrepo" },
66 { SOLVER_NOAUTOSET, "noautoset" },
70 static struct resultflags2str {
73 } resultflags2str[] = {
74 { TESTCASE_RESULT_TRANSACTION, "transaction" },
75 { TESTCASE_RESULT_PROBLEMS, "problems" },
76 { TESTCASE_RESULT_ORPHANED, "orphaned" },
77 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
78 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
82 static struct solverflags2str {
86 } solverflags2str[] = {
87 { SOLVER_FLAG_ALLOW_DOWNGRADE, "allowdowngrade", 0 },
88 { SOLVER_FLAG_ALLOW_NAMECHANGE, "allownamechange", 1 },
89 { SOLVER_FLAG_ALLOW_ARCHCHANGE, "allowarchchange", 0 },
90 { SOLVER_FLAG_ALLOW_VENDORCHANGE, "allowvendorchange", 0 },
91 { SOLVER_FLAG_ALLOW_UNINSTALL, "allowuninstall", 0 },
92 { SOLVER_FLAG_NO_UPDATEPROVIDE, "noupdateprovide", 0 },
93 { SOLVER_FLAG_SPLITPROVIDES, "splitprovides", 0 },
94 { SOLVER_FLAG_IGNORE_RECOMMENDED, "ignorerecommended", 0 },
95 { SOLVER_FLAG_ADD_ALREADY_RECOMMENDED, "addalreadyrecommended", 0 },
96 { SOLVER_FLAG_NO_INFARCHCHECK, "noinfarchcheck", 0 },
97 { SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES, "keepexplicitobsoletes", 0 },
98 { SOLVER_FLAG_BEST_OBEY_POLICY, "bestobeypolicy", 0 },
99 { SOLVER_FLAG_NO_AUTOTARGET, "noautotarget", 0 },
103 static struct poolflags2str {
107 } poolflags2str[] = {
108 { POOL_FLAG_PROMOTEEPOCH, "promoteepoch", 0 },
109 { POOL_FLAG_FORBIDSELFCONFLICTS, "forbidselfconflicts", 0 },
110 { POOL_FLAG_OBSOLETEUSESPROVIDES, "obsoleteusesprovides", 0 },
111 { POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES, "implicitobsoleteusesprovides", 0 },
112 { POOL_FLAG_OBSOLETEUSESCOLORS, "obsoleteusescolors", 0 },
113 { POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS, "implicitobsoleteusescolors", 0 },
114 { POOL_FLAG_NOINSTALLEDOBSOLETES, "noinstalledobsoletes", 0 },
115 { POOL_FLAG_HAVEDISTEPOCH, "havedistepoch", 0 },
116 { POOL_FLAG_NOOBSOLETESMULTIVERSION, "noobsoletesmultiversion", 0 },
117 { POOL_FLAG_ADDFILEPROVIDESFILTERED, "addfileprovidesfiltered", 0 },
121 static struct disttype2str {
125 { DISTTYPE_RPM, "rpm" },
126 { DISTTYPE_DEB, "deb" },
127 { DISTTYPE_ARCH, "arch" },
128 { DISTTYPE_HAIKU, "haiku" },
132 static struct selflags2str {
136 { SELECTION_NAME, "name" },
137 { SELECTION_PROVIDES, "provides" },
138 { SELECTION_FILELIST, "filelist" },
139 { SELECTION_CANON, "canon" },
140 { SELECTION_DOTARCH, "dotarch" },
141 { SELECTION_REL, "rel" },
142 { SELECTION_INSTALLED_ONLY, "installedonly" },
143 { SELECTION_GLOB, "glob" },
144 { SELECTION_FLAT, "flat" },
145 { SELECTION_NOCASE, "nocase" },
146 { SELECTION_SOURCE_ONLY, "sourceonly" },
147 { SELECTION_WITH_SOURCE, "withsource" },
152 typedef struct strqueue {
157 #define STRQUEUE_BLOCK 63
160 strqueue_init(Strqueue *q)
167 strqueue_free(Strqueue *q)
170 for (i = 0; i < q->nstr; i++)
171 solv_free(q->str[i]);
172 q->str = solv_free(q->str);
177 strqueue_push(Strqueue *q, const char *s)
179 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
180 q->str[q->nstr++] = solv_strdup(s);
184 strqueue_pushjoin(Strqueue *q, const char *s1, const char *s2, const char *s3)
186 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
187 q->str[q->nstr++] = solv_dupjoin(s1, s2, s3);
191 strqueue_sort_cmp(const void *ap, const void *bp, void *dp)
193 const char *a = *(const char **)ap;
194 const char *b = *(const char **)bp;
195 return strcmp(a ? a : "", b ? b : "");
199 strqueue_sort(Strqueue *q)
202 solv_sort(q->str, q->nstr, sizeof(*q->str), strqueue_sort_cmp, 0);
206 strqueue_sort_u(Strqueue *q)
210 for (i = j = 0; i < q->nstr; i++)
211 if (!j || strqueue_sort_cmp(q->str + i, q->str + j - 1, 0) != 0)
212 q->str[j++] = q->str[i];
217 strqueue_join(Strqueue *q)
221 for (i = 0; i < q->nstr; i++)
223 l += strlen(q->str[i]) + 1;
224 l++; /* trailing \0 */
227 for (i = 0; i < q->nstr; i++)
230 strcpy(rp, q->str[i]);
239 strqueue_split(Strqueue *q, const char *s)
244 while ((p = strchr(s, '\n')) != 0)
246 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
247 q->str[q->nstr] = solv_malloc(p - s + 1);
249 memcpy(q->str[q->nstr], s, p - s);
250 q->str[q->nstr][p - s] = 0;
259 strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
262 while (i < sq1->nstr && j < sq2->nstr)
264 int r = strqueue_sort_cmp(sq1->str + i, sq2->str + j, 0);
268 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
270 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
272 while (i < sq1->nstr)
273 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
274 while (j < sq2->nstr)
275 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
279 pool_isknownarch(Pool *pool, Id id)
281 if (!id || id == ID_EMPTY)
283 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
285 if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id]))
291 testcase_str2dep_simple(Pool *pool, const char **sp)
298 while (*s == ' ' || *s == '\t')
301 while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>')
305 while (*s && *s != ')')
311 if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')')
313 Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0);
314 if (pool_isknownarch(pool, archid))
316 id = pool_strn2id(pool, n, a - n, 1);
317 id = pool_rel2id(pool, id, archid, REL_ARCH, 1);
320 id = pool_strn2id(pool, n, s - n, 1);
322 else if (s - n > 4 && s[-4] == ':' && !strncmp(s - 4, ":any", 4))
324 id = pool_strn2id(pool, n, s - n - 4, 1);
325 id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1);
328 id = pool_strn2id(pool, n, s - n, 1);
334 while (*s == ' ' || *s == '\t')
337 if (*s == '!' && s[1] == '=') /* support != as synonym for <> */
339 flags = REL_LT | REL_GT;
358 while (*s == ' ' || *s == '\t')
361 while (*s && *s != ' ' && *s != '\t')
363 evr = pool_strn2id(pool, n, s - n, 1);
364 if (*s == ' ' && !strcmp(s, " compat >= "))
367 while (*s == ' ' || *s == '\t')
370 while (*s && *s != ' ' && *s != '\t')
372 evr = pool_rel2id(pool, evr, pool_strn2id(pool, n, s - n, 1), REL_COMPAT, 1);
375 return pool_rel2id(pool, id, evr, flags, 1);
379 testcase_str2dep_complex(Pool *pool, const char **sp)
383 #ifdef ENABLE_COMPLEX_DEPS
384 while (*s == ' ' || *s == '\t')
389 id = testcase_str2dep_complex(pool, &s);
392 while (*s == ' ' || *s == '\t')
397 id = testcase_str2dep_simple(pool, &s);
401 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1);
406 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1);
408 else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t'))
411 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1);
418 testcase_str2dep(Pool *pool, const char *s)
420 return testcase_str2dep_complex(pool, &s);
424 testcase_repoid2str(Pool *pool, Id repoid)
426 Repo *repo = pool_id2repo(pool, repoid);
429 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
431 for (rp = r; *rp; rp++)
432 if (*rp == ' ' || *rp == '\t')
439 sprintf(buf, "#%d", repoid);
440 return pool_tmpjoin(pool, buf, 0, 0);
445 testcase_solvid2str(Pool *pool, Id p)
447 Solvable *s = pool->solvables + p;
448 const char *n, *e, *a;
451 if (p == SYSTEMSOLVABLE)
453 n = pool_id2str(pool, s->name);
454 e = pool_id2str(pool, s->evr);
455 a = pool_id2str(pool, s->arch);
456 str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
457 sprintf(str, "%s-%s.%s", n, e, a);
459 return pool_tmpappend(pool, str, "@", 0);
463 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
465 if (str2[l] == ' ' || str2[l] == '\t')
469 sprintf(buf, "@#%d", s->repo->repoid);
470 return pool_tmpappend(pool, str, buf, 0);
474 testcase_str2repo(Pool *pool, const char *str)
478 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
482 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
483 repoid = repoid * 10 + (str[j] - '0');
484 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
485 repo = pool_id2repo(pool, repoid);
489 FOR_REPOS(repoid, repo)
494 l = strlen(repo->name);
495 for (i = 0; i < l; i++)
497 int c = repo->name[i];
498 if (c == ' ' || c == '\t')
503 if (i == l && !str[l])
506 if (repoid >= pool->nrepos)
513 testcase_str2solvid(Pool *pool, const char *str)
515 int i, l = strlen(str);
522 if (*str == '@' && !strcmp(str, "@SYSTEM"))
523 return SYSTEMSOLVABLE;
525 for (i = l - 1; i >= 0; i--)
526 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
531 /* now find the arch (if present) */
533 for (i = repostart - 1; i > 0; i--)
536 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
541 /* now find the name */
542 for (i = repostart - 1; i > 0; i--)
546 Id nid, evrid, p, pp;
547 nid = pool_strn2id(pool, str, i, 0);
550 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
553 FOR_PROVIDES(p, pp, nid)
555 Solvable *s = pool->solvables + p;
556 if (s->name != nid || s->evr != evrid)
558 if (repo && s->repo != repo)
560 if (arch && s->arch != arch)
570 testcase_job2str(Pool *pool, Id how, Id what)
577 Id select = how & SOLVER_SELECTMASK;
579 for (i = 0; job2str[i].str; i++)
580 if ((how & SOLVER_JOBMASK) == job2str[i].job)
582 jobstr = job2str[i].str ? job2str[i].str : "unknown";
583 if (select == SOLVER_SOLVABLE)
586 pkgstr = testcase_solvid2str(pool, what);
588 else if (select == SOLVER_SOLVABLE_NAME)
591 pkgstr = pool_dep2str(pool, what);
593 else if (select == SOLVER_SOLVABLE_PROVIDES)
595 selstr = " provides ";
596 pkgstr = pool_dep2str(pool, what);
598 else if (select == SOLVER_SOLVABLE_ONE_OF)
603 while ((p = pool->whatprovidesdata[what++]) != 0)
605 const char *s = testcase_solvid2str(pool, p);
608 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
609 pool_freetmpspace(pool, s);
617 else if (select == SOLVER_SOLVABLE_REPO)
619 Repo *repo = pool_id2repo(pool, what);
624 sprintf(buf, "#%d", repo->repoid);
625 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
628 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
630 else if (select == SOLVER_SOLVABLE_ALL)
637 selstr = " unknown ";
640 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
642 ret = pool_tmpappend(pool, ret, " ", 0);
643 for (i = 0; jobflags2str[i].str; i++)
644 if ((how & jobflags2str[i].flag) != 0)
645 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
651 ret = pool_tmpappend(pool, ret, "]", 0);
657 str2selflags(Pool *pool, char *s) /* modifies the string! */
662 char *se = strchr(s, ',');
665 for (i = 0; selflags2str[i].str; i++)
666 if (!strcmp(s, selflags2str[i].str))
668 selflags |= selflags2str[i].flag;
671 if (!selflags2str[i].str)
672 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection flag '%s'\n", s);
679 str2jobflags(Pool *pool, char *s) /* modifies the string */
684 char *se = strchr(s, ',');
687 for (i = 0; jobflags2str[i].str; i++)
688 if (!strcmp(s, jobflags2str[i].str))
690 jobflags |= jobflags2str[i].flag;
693 if (!jobflags2str[i].str)
694 pool_debug(pool, SOLV_ERROR, "str2job: unknown job flag '%s'\n", s);
701 testcase_str2job(Pool *pool, const char *str, Id *whatp)
711 /* so we can patch it */
712 s = pool_tmpjoin(pool, str, 0, 0);
713 /* split it in pieces */
716 while (*s == ' ' || *s == '\t')
720 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
721 pieces[npieces++] = s;
722 while (*s && *s != ' ' && *s != '\t')
729 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
734 for (i = 0; job2str[i].str; i++)
735 if (!strcmp(pieces[0], job2str[i].str))
739 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
743 job = job2str[i].job;
747 char *flags = pieces[npieces - 1];
748 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
752 flags[strlen(flags) - 1] = 0;
753 job |= str2jobflags(pool, flags);
756 if (!strcmp(pieces[1], "pkg"))
760 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
764 job |= SOLVER_SOLVABLE;
765 what = testcase_str2solvid(pool, pieces[2]);
768 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
773 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
775 /* join em again for dep2str... */
777 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
781 if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
783 char *spe = strchr(pieces[2], '(');
784 int l = strlen(pieces[2]);
785 if (spe && pieces[2][l - 1] == ')')
787 /* special namespace provides */
788 if (strcmp(spe, "(<NULL>)") != 0)
790 pieces[2][l - 1] = 0;
791 what = testcase_str2dep(pool, spe + 1);
792 pieces[2][l - 1] = ')';
794 what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
798 what = testcase_str2dep(pool, pieces[2]);
799 if (pieces[1][0] == 'n')
800 job |= SOLVER_SOLVABLE_NAME;
802 job |= SOLVER_SOLVABLE_PROVIDES;
804 else if (!strcmp(pieces[1], "oneof"))
807 job |= SOLVER_SOLVABLE_ONE_OF;
809 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
811 for (i = 2; i < npieces; i++)
813 Id p = testcase_str2solvid(pool, pieces[i]);
816 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
824 what = pool_queuetowhatprovides(pool, &q);
827 else if (!strcmp(pieces[1], "repo"))
832 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
836 repo = testcase_str2repo(pool, pieces[2]);
839 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
843 job |= SOLVER_SOLVABLE_REPO;
846 else if (!strcmp(pieces[1], "all"))
848 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
850 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
854 job |= SOLVER_SOLVABLE_ALL;
859 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
869 addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue)
876 for (i = 0; job2str[i].str; i++)
877 if (!strcmp(pieces[0], job2str[i].str))
881 pool_debug(pool, SOLV_ERROR, "selstr2job: unknown job '%s'\n", pieces[0]);
884 job = job2str[i].job;
887 char *flags = pieces[npieces - 1];
888 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
892 flags[strlen(flags) - 1] = 0;
893 job |= str2jobflags(pool, flags);
898 pool_debug(pool, SOLV_ERROR, "selstr2job: no selection flags\n");
901 selflags = str2selflags(pool, pieces[3]);
903 r = selection_make(pool, &sel, pieces[2], selflags);
904 for (i = 0; i < sel.count; i += 2)
905 queue_push2(jobqueue, job | sel.elements[i], sel.elements[i + 1]);
911 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
913 Pool *pool = repo->pool;
920 dp = repo->idarraydata + off;
922 while ((id = *dp++) != 0)
924 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
927 fprintf(fp, "-%s\n", tag);
932 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
937 idstr = pool_dep2str(pool, id);
940 Reldep *rd = GETRELDEP(pool, id);
941 if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
943 if (!strncmp(idstr, "namespace:", 10))
946 if (key == SOLVABLE_SUPPLEMENTS)
948 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
950 if (!strncmp(idstr, "namespace:", 10))
953 else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
955 if (!strncmp(idstr, "namespace:", 10))
958 else if (rd->flags == REL_AND)
960 /* either packageand chain or modalias */
962 if (ISRELDEP(rd->evr))
964 Reldep *mrd = GETRELDEP(pool, rd->evr);
965 if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
967 idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
968 idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
970 else if (mrd->flags >= 8)
975 /* must be and chain */
976 idstr = pool_dep2str(pool, rd->evr);
982 rd = GETRELDEP(pool, id);
983 if (rd->flags != REL_AND)
985 idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
987 idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
988 idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
991 else if (rd->flags >= 8)
997 fprintf(fp, "+%s\n", tag);
1000 fprintf(fp, "%s\n", idstr);
1002 if (key == SOLVABLE_PROVIDES)
1004 /* add the filelist */
1006 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
1007 while (dataiterator_step(&di))
1009 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
1012 Id id = pool_str2id(pool, s, 0);
1015 for (dp = prvdp; *dp; dp++)
1019 continue; /* already included */
1024 fprintf(fp, "+%s", tag);
1027 fprintf(fp, "%s\n", s);
1031 fprintf(fp, "-%s\n", tag);
1035 testcase_write_testtags(Repo *repo, FILE *fp)
1037 Pool *pool = repo->pool;
1043 const char *release;
1047 fprintf(fp, "=Ver: 2.0\n");
1048 FOR_REPO_SOLVABLES(repo, p, s)
1050 name = pool_id2str(pool, s->name);
1051 evr = pool_id2str(pool, s->evr);
1052 arch = pool_id2str(pool, s->arch);
1053 release = strrchr(evr, '-');
1055 release = evr + strlen(evr);
1056 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
1057 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
1059 fprintf(fp, "=Sum: %s\n", tmp);
1060 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
1061 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
1062 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
1063 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
1064 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
1065 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
1066 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
1067 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
1069 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
1070 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
1072 fprintf(fp, "=Tim: %u\n", ti);
1077 static inline Offset
1078 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
1080 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
1081 return repo_addid_dep(repo, olddeps, id, marker);
1085 finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
1091 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1093 char *p = strrchr(filelist + l, '/');
1097 did = repodata_str2dir(data, filelist + l, 1);
1100 did = repodata_str2dir(data, "/", 1);
1101 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
1104 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
1105 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
1106 s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
1107 s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
1110 /* stripped down version of susetags parser used for testcases */
1112 testcase_add_testtags(Repo *repo, FILE *fp, int flags)
1114 Pool *pool = repo->pool;
1127 data = repo_add_repodata(repo, flags);
1132 line = solv_malloc(aline);
1136 if (linep - line + 16 > aline)
1138 aline = linep - line;
1139 line = solv_realloc(line, aline + 512);
1140 linep = line + aline;
1143 if (!fgets(linep, aline - (linep - line), fp))
1145 linep += strlen(linep);
1146 if (linep == line || linep[-1] != '\n')
1149 linep = line + intag;
1152 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
1159 else if (line[0] == '+' && line[1] && line[1] != ':')
1161 char *tagend = strchr(line, ':');
1166 intag = tagend + 2 - line;
1167 linep = line + intag;
1170 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
1172 tag = line[1] << 16 | line[2] << 8 | line[3];
1175 case 'P' << 16 | 'k' << 8 | 'g':
1177 finish_solvable(pool, data, s, filelist, nfilelist);
1179 if (split(line + 5, sp, 5) != 4)
1181 s = pool_id2solvable(pool, repo_add_solvable(repo));
1182 s->name = pool_str2id(pool, sp[0], 1);
1183 /* join back version and release */
1184 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
1186 s->evr = makeevr(pool, sp[1]);
1187 s->arch = pool_str2id(pool, sp[3], 1);
1189 case 'S' << 16 | 'u' << 8 | 'm':
1190 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
1192 case 'V' << 16 | 'n' << 8 | 'd':
1193 s->vendor = pool_str2id(pool, line + 6, 1);
1195 case 'T' << 16 | 'i' << 8 | 'm':
1198 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
1200 case 'R' << 16 | 'e' << 8 | 'q':
1201 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
1203 case 'P' << 16 | 'r' << 8 | 'q':
1204 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
1206 case 'P' << 16 | 'r' << 8 | 'v':
1209 int l = strlen(line + 6) + 1;
1210 if (nfilelist + l > afilelist)
1212 afilelist = nfilelist + l + 512;
1213 filelist = solv_realloc(filelist, afilelist);
1215 memcpy(filelist + nfilelist, line + 6, l);
1222 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1223 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1226 s->provides = adddep(repo, s->provides, line + 6, 0);
1228 case 'O' << 16 | 'b' << 8 | 's':
1229 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1231 case 'C' << 16 | 'o' << 8 | 'n':
1232 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1234 case 'R' << 16 | 'e' << 8 | 'c':
1235 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1237 case 'S' << 16 | 'u' << 8 | 'p':
1238 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1240 case 'S' << 16 | 'u' << 8 | 'g':
1241 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1243 case 'E' << 16 | 'n' << 8 | 'h':
1244 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1251 finish_solvable(pool, data, s, filelist, nfilelist);
1253 solv_free(filelist);
1254 repodata_free_dircache(data);
1255 if (!(flags & REPO_NO_INTERNALIZE))
1256 repodata_internalize(data);
1261 testcase_getpoolflags(Pool *pool)
1263 const char *str = 0;
1265 for (i = 0; poolflags2str[i].str; i++)
1267 v = pool_get_flag(pool, poolflags2str[i].flag);
1268 if (v == poolflags2str[i].def)
1270 str = pool_tmpappend(pool, str, v ? " " : " !", poolflags2str[i].str);
1272 return str ? str + 1 : "";
1276 testcase_setpoolflags(Pool *pool, const char *str)
1278 const char *p = str, *s;
1282 while (*p == ' ' || *p == '\t' || *p == ',')
1293 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1295 for (i = 0; poolflags2str[i].str; i++)
1296 if (!strncmp(poolflags2str[i].str, s, p - s) && poolflags2str[i].str[p - s] == 0)
1298 if (!poolflags2str[i].str)
1300 pool_debug(pool, SOLV_ERROR, "setpoolflags: unknown flag '%.*s'\n", (int)(p - s), s);
1303 pool_set_flag(pool, poolflags2str[i].flag, v);
1309 testcase_resetpoolflags(Pool *pool)
1312 for (i = 0; poolflags2str[i].str; i++)
1313 pool_set_flag(pool, poolflags2str[i].flag, poolflags2str[i].def);
1317 testcase_getsolverflags(Solver *solv)
1319 Pool *pool = solv->pool;
1320 const char *str = 0;
1322 for (i = 0; solverflags2str[i].str; i++)
1324 v = solver_get_flag(solv, solverflags2str[i].flag);
1325 if (v == solverflags2str[i].def)
1327 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1329 return str ? str + 1 : "";
1333 testcase_setsolverflags(Solver *solv, const char *str)
1335 const char *p = str, *s;
1339 while (*p == ' ' || *p == '\t' || *p == ',')
1350 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1352 for (i = 0; solverflags2str[i].str; i++)
1353 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1355 if (!solverflags2str[i].str)
1357 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", (int)(p - s), s);
1360 solver_set_flag(solv, solverflags2str[i].flag, v);
1366 testcase_resetsolverflags(Solver *solv)
1369 for (i = 0; solverflags2str[i].str; i++)
1370 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1374 testcase_ruleid(Solver *solv, Id rid)
1380 const unsigned char *md5;
1386 solver_ruleliterals(solv, rid, &q);
1387 for (i = 0; i < q.count; i++)
1389 Id p = q.elements[i];
1390 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1392 s = pool_tmpjoin(solv->pool, "!", s, 0);
1393 strqueue_push(&sq, s);
1396 strqueue_sort_u(&sq);
1397 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1398 for (i = 0; i < sq.nstr; i++)
1399 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1400 md5 = solv_chksum_get(chk, &md5l);
1401 s = pool_bin2hex(solv->pool, md5, md5l);
1402 chk = solv_chksum_free(chk, 0);
1408 testcase_problemid(Solver *solv, Id problem)
1413 const unsigned char *md5;
1417 /* we build a hash of all rules that define the problem */
1420 solver_findallproblemrules(solv, problem, &q);
1421 for (i = 0; i < q.count; i++)
1422 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1424 strqueue_sort_u(&sq);
1425 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1426 for (i = 0; i < sq.nstr; i++)
1427 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1428 md5 = solv_chksum_get(chk, &md5l);
1429 s = pool_bin2hex(solv->pool, md5, 4);
1430 chk = solv_chksum_free(chk, 0);
1436 testcase_solutionid(Solver *solv, Id problem, Id solution)
1440 const unsigned char *md5;
1444 intid = solver_solutionelement_internalid(solv, problem, solution);
1445 /* internal stuff! handle with care! */
1449 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1454 s = testcase_ruleid(solv, intid);
1456 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1457 solv_chksum_add(chk, s, strlen(s) + 1);
1458 md5 = solv_chksum_get(chk, &md5l);
1459 s = pool_bin2hex(solv->pool, md5, 4);
1460 chk = solv_chksum_free(chk, 0);
1464 static struct class2str {
1468 { SOLVER_TRANSACTION_ERASE, "erase" },
1469 { SOLVER_TRANSACTION_INSTALL, "install" },
1470 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1471 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1472 { SOLVER_TRANSACTION_CHANGED, "change" },
1473 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1474 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1475 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1476 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1481 testcase_solverresult(Solver *solv, int resultflags)
1483 Pool *pool = solv->pool;
1491 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1493 Transaction *trans = solver_create_transaction(solv);
1497 for (i = 0; class2str[i].str; i++)
1500 transaction_classify_pkgs(trans, SOLVER_TRANSACTION_KEEP_PSEUDO, class2str[i].class, 0, 0, &q);
1501 for (j = 0; j < q.count; j++)
1505 if (pool->installed && pool->solvables[p].repo == pool->installed)
1506 op = transaction_obs_pkg(trans, p);
1507 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1509 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1510 strqueue_push(&sq, s);
1514 transaction_free(trans);
1516 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1518 char *probprefix, *solprefix;
1519 int problem, solution, element;
1522 pcnt = solver_problem_count(solv);
1523 for (problem = 1; problem <= pcnt; problem++)
1525 Id rid, from, to, dep;
1526 SolverRuleinfo rinfo;
1527 rid = solver_findproblemrule(solv, problem);
1528 s = testcase_problemid(solv, problem);
1529 probprefix = solv_dupjoin("problem ", s, 0);
1530 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1531 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1532 strqueue_push(&sq, s);
1533 scnt = solver_solution_count(solv, problem);
1534 for (solution = 1; solution <= scnt; solution++)
1536 s = testcase_solutionid(solv, problem, solution);
1537 solprefix = solv_dupjoin(probprefix, " solution ", s);
1539 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1541 if (p == SOLVER_SOLUTION_JOB)
1542 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1543 else if (p > 0 && op == 0)
1544 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1545 else if (p > 0 && op > 0)
1547 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1548 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1550 else if (p < 0 && op > 0)
1551 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1553 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1554 strqueue_push(&sq, s);
1556 solv_free(solprefix);
1558 solv_free(probprefix);
1562 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1567 solver_get_orphaned(solv, &q);
1568 for (i = 0; i < q.count; i++)
1570 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1571 strqueue_push(&sq, s);
1576 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1582 solver_get_recommendations(solv, &qr, &qs, 0);
1583 for (i = 0; i < qr.count; i++)
1585 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1586 strqueue_push(&sq, s);
1588 for (i = 0; i < qs.count; i++)
1590 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1591 strqueue_push(&sq, s);
1597 if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0)
1603 solver_get_unneeded(solv, &q, 0);
1604 solver_get_unneeded(solv, &qf, 1);
1605 for (i = j = 0; i < q.count; i++)
1607 /* we rely on qf containing a subset of q in the same order */
1608 if (j < qf.count && q.elements[i] == qf.elements[j])
1610 s = pool_tmpjoin(pool, "unneeded_filtered ", testcase_solvid2str(pool, q.elements[i]), 0);
1614 s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0);
1615 strqueue_push(&sq, s);
1622 result = strqueue_join(&sq);
1629 testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasename, const char *resultname)
1631 Pool *pool = solv->pool;
1642 testcasename = "testcase.t";
1644 resultname = "solver.result";
1646 if (mkdir(dir, 0777) && errno != EEXIST)
1648 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
1652 FOR_REPOS(repoid, repo)
1654 const char *name = testcase_repoid2str(pool, repoid);
1656 if (repo->subpriority)
1657 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
1659 sprintf(priobuf, "%d", repo->priority);
1660 out = pool_tmpjoin(pool, name, ".repo", ".gz");
1661 cmd = pool_tmpjoin(pool, "repo ", name, " ");
1662 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
1663 cmd = pool_tmpappend(pool, cmd, "testtags ", out);
1664 strqueue_push(&sq, cmd);
1665 out = pool_tmpjoin(pool, dir, "/", out);
1666 if (!(fp = solv_xfopen(out, "w")))
1668 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1672 testcase_write_testtags(repo, fp);
1675 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1680 /* hmm, this is not optimal... we currently search for the lowest score */
1682 arch = pool->solvables[SYSTEMSOLVABLE].arch;
1683 for (i = 0; i < pool->lastarch; i++)
1685 if (pool->id2arch[i] == 1 && !lowscore)
1687 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
1690 lowscore = pool->id2arch[i];
1693 cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
1694 for (i = 0; disttype2str[i].str != 0; i++)
1695 if (pool->disttype == disttype2str[i].type)
1697 pool_tmpappend(pool, cmd, " ", disttype2str[i].str ? disttype2str[i].str : "unknown");
1698 if (pool->installed)
1699 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
1700 strqueue_push(&sq, cmd);
1701 s = testcase_getpoolflags(solv->pool);
1704 cmd = pool_tmpjoin(pool, "poolflags ", s, 0);
1705 strqueue_push(&sq, cmd);
1708 if (pool->vendorclasses)
1711 for (i = 0; pool->vendorclasses[i]; i++)
1713 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
1714 if (!pool->vendorclasses[i + 1])
1716 strqueue_push(&sq, cmd);
1723 s = testcase_getsolverflags(solv);
1726 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
1727 strqueue_push(&sq, cmd);
1730 /* now dump all the ns callback values we know */
1731 if (pool->nscallback)
1735 for (rid = 1; rid < pool->nrels; rid++)
1737 Reldep *rd = pool->rels + rid;
1738 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1740 /* evaluate all namespace ids, skip empty results */
1741 d = pool_whatprovides(pool, MAKERELDEP(rid));
1742 if (!d || !pool->whatprovidesdata[d])
1744 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
1745 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
1746 for (; pool->whatprovidesdata[d]; d++)
1747 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
1748 strqueue_push(&sq, cmd);
1752 for (i = 0; i < solv->job.count; i += 2)
1754 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
1755 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
1756 strqueue_push(&sq, cmd);
1763 for (i = 0; resultflags2str[i].str; i++)
1764 if ((resultflags & resultflags2str[i].flag) != 0)
1765 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
1766 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", 0);
1767 cmd = pool_tmpappend(pool, cmd, " ", resultname);
1768 strqueue_push(&sq, cmd);
1769 result = testcase_solverresult(solv, resultflags);
1770 if (!strcmp(resultname, "<inline>"))
1774 strqueue_init(&rsq);
1775 strqueue_split(&rsq, result);
1776 for (i = 0; i < rsq.nstr; i++)
1778 cmd = pool_tmpjoin(pool, "#>", rsq.str[i], 0);
1779 strqueue_push(&sq, cmd);
1781 strqueue_free(&rsq);
1785 out = pool_tmpjoin(pool, dir, "/", resultname);
1786 if (!(fp = fopen(out, "w")))
1788 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1793 if (result && *result && fwrite(result, strlen(result), 1, fp) != 1)
1795 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1803 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1811 cmd = strqueue_join(&sq);
1812 out = pool_tmpjoin(pool, dir, "/", testcasename);
1813 if (!(fp = fopen(out, "w")))
1815 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1819 if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
1821 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1828 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1838 read_inline_file(FILE *fp, char **bufp, char **bufpp, int *buflp)
1840 char *result = solv_malloc(1024);
1847 if (rp - result + 256 >= resultl)
1849 resultl = rp - result;
1850 result = solv_realloc(result, resultl + 1024);
1851 rp = result + resultl;
1854 if (!fgets(rp, resultl - (rp - result), fp))
1857 if (rl && (rp == result || rp[-1] == '\n'))
1859 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
1861 memmove(rp, rp + 2, rl - 2);
1866 while (rl + 16 > *buflp)
1868 *bufp = solv_realloc(*bufp, *buflp + 512);
1871 memmove(*bufp, rp, rl);
1872 if ((*bufp)[rl - 1] == '\n')
1878 (*bufpp) = *bufp + rl;
1895 char *result = solv_malloc(1024);
1902 if (rp - result + 256 >= resultl)
1904 resultl = rp - result;
1905 result = solv_realloc(result, resultl + 1024);
1906 rp = result + resultl;
1909 rl = fread(rp, 1, resultl - (rp - result), fp);
1921 str2resultflags(Pool *pool, char *s) /* modifies the string! */
1923 int i, resultflags = 0;
1926 char *se = strchr(s, ',');
1929 for (i = 0; resultflags2str[i].str; i++)
1930 if (!strcmp(s, resultflags2str[i].str))
1932 resultflags |= resultflags2str[i].flag;
1935 if (!resultflags2str[i].str)
1936 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
1943 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
1948 char *testcasedir, *s;
1954 int poolflagsreset = 0;
1956 if (!fp && !(fp = fopen(testcase, "r")))
1958 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
1961 testcasedir = solv_strdup(testcase);
1962 if ((s = strrchr(testcasedir, '/')) != 0)
1967 buf = solv_malloc(bufl);
1972 if (bufp - buf + 16 > bufl)
1975 buf = solv_realloc(buf, bufl + 512);
1979 if (!fgets(bufp, bufl - (bufp - buf), fp))
1983 if (!l || buf[l - 1] != '\n')
1990 while (*s && (*s == ' ' || *s == '\t'))
1992 if (!*s || *s == '#')
1995 /* split it in pieces */
1998 while (*s == ' ' || *s == '\t')
2002 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2003 pieces[npieces++] = s;
2004 while (*s && *s != ' ' && *s != '\t')
2009 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
2010 pieces[npieces] = 0;
2011 if (!strcmp(pieces[0], "repo") && npieces >= 4)
2013 Repo *repo = repo_create(pool, pieces[1]);
2019 if (!poolflagsreset)
2022 testcase_resetpoolflags(pool); /* hmm */
2024 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
2027 prio = atoi(pieces[2]);
2029 repo->priority = prio;
2030 repo->subpriority = subprio;
2031 if (strcmp(pieces[3], "empty") != 0)
2033 const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0); /* gets overwritten in <inline> case */
2034 if (!strcmp(pieces[4], "<inline>"))
2036 char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
2038 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
2042 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
2043 rfp = solv_xfopen(rdata, "r");
2047 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2049 else if (!strcmp(repotype, "testtags"))
2051 testcase_add_testtags(repo, rfp, 0);
2054 else if (!strcmp(repotype, "solv"))
2056 repo_add_solv(repo, rfp, 0);
2060 else if (!strcmp(repotype, "helix"))
2062 extern int repo_add_helix(Repo *repo, FILE *fp, int flags);
2063 repo_add_helix(repo, rfp, 0);
2070 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
2074 else if (!strcmp(pieces[0], "system") && npieces >= 3)
2078 /* must set the disttype before the arch */
2079 for (i = 0; disttype2str[i].str != 0; i++)
2080 if (!strcmp(disttype2str[i].str, pieces[2]))
2082 if (!disttype2str[i].str)
2083 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown disttype '%s'\n", pieces[2]);
2084 else if (pool->disttype != disttype2str[i].type)
2086 #ifdef MULTI_SEMANTICS
2087 pool_setdisttype(pool, disttype2str[i].type);
2089 pool_debug(pool, SOLV_ERROR, "testcase_read: system: cannot change disttype to '%s'\n", pieces[2]);
2092 if (strcmp(pieces[1], "unset") == 0)
2093 pool_setarch(pool, 0);
2094 else if (pieces[1][0] == ':')
2095 pool_setarchpolicy(pool, pieces[1] + 1);
2097 pool_setarch(pool, pieces[1]);
2100 Repo *repo = testcase_str2repo(pool, pieces[3]);
2102 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
2104 pool_set_installed(pool, repo);
2107 else if (!strcmp(pieces[0], "job") && npieces > 1)
2113 pool_addfileprovides(pool);
2114 pool_createwhatprovides(pool);
2117 if (npieces >= 3 && !strcmp(pieces[2], "selection"))
2119 addselectionjob(pool, pieces + 1, npieces - 1, job);
2123 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
2126 how = testcase_str2job(pool, pieces[1], &what);
2127 if (how >= 0 && job)
2128 queue_push2(job, how, what);
2130 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
2132 pool_addvendorclass(pool, (const char **)(pieces + 1));
2134 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
2136 int i = strlen(pieces[1]);
2137 s = strchr(pieces[1], '(');
2138 if (!s && pieces[1][i - 1] != ')')
2140 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
2148 pieces[1][i - 1] = 0;
2149 name = pool_str2id(pool, pieces[1], 1);
2150 evr = pool_str2id(pool, s + 1, 1);
2152 pieces[1][i - 1] = ')';
2153 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
2154 for (i = 2; i < npieces; i++)
2155 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
2156 /* now do the callback */
2159 pool_addfileprovides(pool);
2160 pool_createwhatprovides(pool);
2163 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
2167 else if (!strcmp(pieces[0], "poolflags"))
2170 if (!poolflagsreset)
2173 testcase_resetpoolflags(pool); /* hmm */
2175 for (i = 1; i < npieces; i++)
2176 testcase_setpoolflags(pool, pieces[i]);
2178 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
2183 solv = solver_create(pool);
2184 testcase_resetsolverflags(solv);
2186 for (i = 1; i < npieces; i++)
2187 testcase_setsolverflags(solv, pieces[i]);
2189 else if (!strcmp(pieces[0], "result") && npieces > 1)
2192 int resultflags = str2resultflags(pool, pieces[1]);
2196 rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
2197 if (!strcmp(pieces[2], "<inline>"))
2198 result = read_inline_file(fp, &buf, &bufp, &bufl);
2201 FILE *rfp = fopen(rdata, "r");
2203 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2206 result = read_file(rfp);
2216 *resultflagsp = resultflags;
2218 else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
2224 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
2227 buf = solv_free(buf);
2228 pieces = solv_free(pieces);
2229 solv_free(testcasedir);
2232 pool_addfileprovides(pool);
2233 pool_createwhatprovides(pool);
2237 solv = solver_create(pool);
2238 testcase_resetsolverflags(solv);
2246 testcase_resultdiff(char *result1, char *result2)
2248 Strqueue sq1, sq2, osq;
2250 strqueue_init(&sq1);
2251 strqueue_init(&sq2);
2252 strqueue_init(&osq);
2253 strqueue_split(&sq1, result1);
2254 strqueue_split(&sq2, result2);
2255 strqueue_sort(&sq1);
2256 strqueue_sort(&sq2);
2257 strqueue_diff(&sq1, &sq2, &osq);
2258 r = osq.nstr ? strqueue_join(&osq) : 0;
2259 strqueue_free(&sq1);
2260 strqueue_free(&sq2);
2261 strqueue_free(&osq);