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 id = testcase_str2dep_simple(pool, &s);
387 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1);
392 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1);
394 else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t'))
397 id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1);
404 testcase_str2dep(Pool *pool, const char *s)
406 return testcase_str2dep_complex(pool, &s);
410 testcase_repoid2str(Pool *pool, Id repoid)
412 Repo *repo = pool_id2repo(pool, repoid);
415 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
417 for (rp = r; *rp; rp++)
418 if (*rp == ' ' || *rp == '\t')
425 sprintf(buf, "#%d", repoid);
426 return pool_tmpjoin(pool, buf, 0, 0);
431 testcase_solvid2str(Pool *pool, Id p)
433 Solvable *s = pool->solvables + p;
434 const char *n, *e, *a;
437 if (p == SYSTEMSOLVABLE)
439 n = pool_id2str(pool, s->name);
440 e = pool_id2str(pool, s->evr);
441 a = pool_id2str(pool, s->arch);
442 str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
443 sprintf(str, "%s-%s.%s", n, e, a);
445 return pool_tmpappend(pool, str, "@", 0);
449 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
451 if (str2[l] == ' ' || str2[l] == '\t')
455 sprintf(buf, "@#%d", s->repo->repoid);
456 return pool_tmpappend(pool, str, buf, 0);
460 testcase_str2repo(Pool *pool, const char *str)
464 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
468 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
469 repoid = repoid * 10 + (str[j] - '0');
470 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
471 repo = pool_id2repo(pool, repoid);
475 FOR_REPOS(repoid, repo)
480 l = strlen(repo->name);
481 for (i = 0; i < l; i++)
483 int c = repo->name[i];
484 if (c == ' ' || c == '\t')
489 if (i == l && !str[l])
492 if (repoid >= pool->nrepos)
499 testcase_str2solvid(Pool *pool, const char *str)
501 int i, l = strlen(str);
508 if (*str == '@' && !strcmp(str, "@SYSTEM"))
509 return SYSTEMSOLVABLE;
511 for (i = l - 1; i >= 0; i--)
512 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
517 /* now find the arch (if present) */
519 for (i = repostart - 1; i > 0; i--)
522 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
527 /* now find the name */
528 for (i = repostart - 1; i > 0; i--)
532 Id nid, evrid, p, pp;
533 nid = pool_strn2id(pool, str, i, 0);
536 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
539 FOR_PROVIDES(p, pp, nid)
541 Solvable *s = pool->solvables + p;
542 if (s->name != nid || s->evr != evrid)
544 if (repo && s->repo != repo)
546 if (arch && s->arch != arch)
556 testcase_job2str(Pool *pool, Id how, Id what)
563 Id select = how & SOLVER_SELECTMASK;
565 for (i = 0; job2str[i].str; i++)
566 if ((how & SOLVER_JOBMASK) == job2str[i].job)
568 jobstr = job2str[i].str ? job2str[i].str : "unknown";
569 if (select == SOLVER_SOLVABLE)
572 pkgstr = testcase_solvid2str(pool, what);
574 else if (select == SOLVER_SOLVABLE_NAME)
577 pkgstr = pool_dep2str(pool, what);
579 else if (select == SOLVER_SOLVABLE_PROVIDES)
581 selstr = " provides ";
582 pkgstr = pool_dep2str(pool, what);
584 else if (select == SOLVER_SOLVABLE_ONE_OF)
589 while ((p = pool->whatprovidesdata[what++]) != 0)
591 const char *s = testcase_solvid2str(pool, p);
594 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
595 pool_freetmpspace(pool, s);
603 else if (select == SOLVER_SOLVABLE_REPO)
605 Repo *repo = pool_id2repo(pool, what);
610 sprintf(buf, "#%d", repo->repoid);
611 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
614 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
616 else if (select == SOLVER_SOLVABLE_ALL)
623 selstr = " unknown ";
626 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
628 ret = pool_tmpappend(pool, ret, " ", 0);
629 for (i = 0; jobflags2str[i].str; i++)
630 if ((how & jobflags2str[i].flag) != 0)
631 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
637 ret = pool_tmpappend(pool, ret, "]", 0);
643 str2selflags(Pool *pool, char *s) /* modifies the string! */
648 char *se = strchr(s, ',');
651 for (i = 0; selflags2str[i].str; i++)
652 if (!strcmp(s, selflags2str[i].str))
654 selflags |= selflags2str[i].flag;
657 if (!selflags2str[i].str)
658 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection flag '%s'\n", s);
665 str2jobflags(Pool *pool, char *s) /* modifies the string */
670 char *se = strchr(s, ',');
673 for (i = 0; jobflags2str[i].str; i++)
674 if (!strcmp(s, jobflags2str[i].str))
676 jobflags |= jobflags2str[i].flag;
679 if (!jobflags2str[i].str)
680 pool_debug(pool, SOLV_ERROR, "str2job: unknown job flag '%s'\n", s);
687 testcase_str2job(Pool *pool, const char *str, Id *whatp)
697 /* so we can patch it */
698 s = pool_tmpjoin(pool, str, 0, 0);
699 /* split it in pieces */
702 while (*s == ' ' || *s == '\t')
706 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
707 pieces[npieces++] = s;
708 while (*s && *s != ' ' && *s != '\t')
715 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
720 for (i = 0; job2str[i].str; i++)
721 if (!strcmp(pieces[0], job2str[i].str))
725 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
729 job = job2str[i].job;
733 char *flags = pieces[npieces - 1];
734 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
738 flags[strlen(flags) - 1] = 0;
739 job |= str2jobflags(pool, flags);
742 if (!strcmp(pieces[1], "pkg"))
746 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
750 job |= SOLVER_SOLVABLE;
751 what = testcase_str2solvid(pool, pieces[2]);
754 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
759 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
761 /* join em again for dep2str... */
763 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
767 if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
769 char *spe = strchr(pieces[2], '(');
770 int l = strlen(pieces[2]);
771 if (spe && pieces[2][l - 1] == ')')
773 /* special namespace provides */
774 if (strcmp(spe, "(<NULL>)") != 0)
776 pieces[2][l - 1] = 0;
777 what = testcase_str2dep(pool, spe + 1);
778 pieces[2][l - 1] = ')';
780 what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
784 what = testcase_str2dep(pool, pieces[2]);
785 if (pieces[1][0] == 'n')
786 job |= SOLVER_SOLVABLE_NAME;
788 job |= SOLVER_SOLVABLE_PROVIDES;
790 else if (!strcmp(pieces[1], "oneof"))
793 job |= SOLVER_SOLVABLE_ONE_OF;
795 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
797 for (i = 2; i < npieces; i++)
799 Id p = testcase_str2solvid(pool, pieces[i]);
802 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
810 what = pool_queuetowhatprovides(pool, &q);
813 else if (!strcmp(pieces[1], "repo"))
818 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
822 repo = testcase_str2repo(pool, pieces[2]);
825 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
829 job |= SOLVER_SOLVABLE_REPO;
832 else if (!strcmp(pieces[1], "all"))
834 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
836 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
840 job |= SOLVER_SOLVABLE_ALL;
845 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
855 addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue)
862 for (i = 0; job2str[i].str; i++)
863 if (!strcmp(pieces[0], job2str[i].str))
867 pool_debug(pool, SOLV_ERROR, "selstr2job: unknown job '%s'\n", pieces[0]);
870 job = job2str[i].job;
873 char *flags = pieces[npieces - 1];
874 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
878 flags[strlen(flags) - 1] = 0;
879 job |= str2jobflags(pool, flags);
884 pool_debug(pool, SOLV_ERROR, "selstr2job: no selection flags\n");
887 selflags = str2selflags(pool, pieces[3]);
889 r = selection_make(pool, &sel, pieces[2], selflags);
890 for (i = 0; i < sel.count; i += 2)
891 queue_push2(jobqueue, job | sel.elements[i], sel.elements[i + 1]);
897 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
899 Pool *pool = repo->pool;
906 dp = repo->idarraydata + off;
908 while ((id = *dp++) != 0)
910 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
913 fprintf(fp, "-%s\n", tag);
918 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
923 idstr = pool_dep2str(pool, id);
926 Reldep *rd = GETRELDEP(pool, id);
927 if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
929 if (!strncmp(idstr, "namespace:", 10))
932 if (key == SOLVABLE_SUPPLEMENTS)
934 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
936 if (!strncmp(idstr, "namespace:", 10))
939 else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
941 if (!strncmp(idstr, "namespace:", 10))
944 else if (rd->flags == REL_AND)
946 /* either packageand chain or modalias */
948 if (ISRELDEP(rd->evr))
950 Reldep *mrd = GETRELDEP(pool, rd->evr);
951 if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
953 idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
954 idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
956 else if (mrd->flags >= 8)
961 /* must be and chain */
962 idstr = pool_dep2str(pool, rd->evr);
968 rd = GETRELDEP(pool, id);
969 if (rd->flags != REL_AND)
971 idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
973 idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
974 idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
977 else if (rd->flags >= 8)
983 fprintf(fp, "+%s\n", tag);
986 fprintf(fp, "%s\n", idstr);
988 if (key == SOLVABLE_PROVIDES)
990 /* add the filelist */
992 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
993 while (dataiterator_step(&di))
995 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
998 Id id = pool_str2id(pool, s, 0);
1001 for (dp = prvdp; *dp; dp++)
1005 continue; /* already included */
1010 fprintf(fp, "+%s", tag);
1013 fprintf(fp, "%s\n", s);
1017 fprintf(fp, "-%s\n", tag);
1021 testcase_write_testtags(Repo *repo, FILE *fp)
1023 Pool *pool = repo->pool;
1029 const char *release;
1033 fprintf(fp, "=Ver: 2.0\n");
1034 FOR_REPO_SOLVABLES(repo, p, s)
1036 name = pool_id2str(pool, s->name);
1037 evr = pool_id2str(pool, s->evr);
1038 arch = pool_id2str(pool, s->arch);
1039 release = strrchr(evr, '-');
1041 release = evr + strlen(evr);
1042 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
1043 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
1045 fprintf(fp, "=Sum: %s\n", tmp);
1046 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
1047 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
1048 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
1049 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
1050 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
1051 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
1052 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
1053 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
1055 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
1056 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
1058 fprintf(fp, "=Tim: %u\n", ti);
1063 static inline Offset
1064 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
1066 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
1067 return repo_addid_dep(repo, olddeps, id, marker);
1071 finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
1077 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1079 char *p = strrchr(filelist + l, '/');
1083 did = repodata_str2dir(data, filelist + l, 1);
1086 did = repodata_str2dir(data, "/", 1);
1087 repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
1090 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
1091 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
1092 s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
1093 s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
1096 /* stripped down version of susetags parser used for testcases */
1098 testcase_add_testtags(Repo *repo, FILE *fp, int flags)
1100 Pool *pool = repo->pool;
1113 data = repo_add_repodata(repo, flags);
1118 line = solv_malloc(aline);
1122 if (linep - line + 16 > aline)
1124 aline = linep - line;
1125 line = solv_realloc(line, aline + 512);
1126 linep = line + aline;
1129 if (!fgets(linep, aline - (linep - line), fp))
1131 linep += strlen(linep);
1132 if (linep == line || linep[-1] != '\n')
1135 linep = line + intag;
1138 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
1145 else if (line[0] == '+' && line[1] && line[1] != ':')
1147 char *tagend = strchr(line, ':');
1152 intag = tagend + 2 - line;
1153 linep = line + intag;
1156 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
1158 tag = line[1] << 16 | line[2] << 8 | line[3];
1161 case 'P' << 16 | 'k' << 8 | 'g':
1163 finish_solvable(pool, data, s, filelist, nfilelist);
1165 if (split(line + 5, sp, 5) != 4)
1167 s = pool_id2solvable(pool, repo_add_solvable(repo));
1168 s->name = pool_str2id(pool, sp[0], 1);
1169 /* join back version and release */
1170 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
1172 s->evr = makeevr(pool, sp[1]);
1173 s->arch = pool_str2id(pool, sp[3], 1);
1175 case 'S' << 16 | 'u' << 8 | 'm':
1176 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
1178 case 'V' << 16 | 'n' << 8 | 'd':
1179 s->vendor = pool_str2id(pool, line + 6, 1);
1181 case 'T' << 16 | 'i' << 8 | 'm':
1184 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
1186 case 'R' << 16 | 'e' << 8 | 'q':
1187 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
1189 case 'P' << 16 | 'r' << 8 | 'q':
1190 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
1192 case 'P' << 16 | 'r' << 8 | 'v':
1195 int l = strlen(line + 6) + 1;
1196 if (nfilelist + l > afilelist)
1198 afilelist = nfilelist + l + 512;
1199 filelist = solv_realloc(filelist, afilelist);
1201 memcpy(filelist + nfilelist, line + 6, l);
1208 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1209 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1212 s->provides = adddep(repo, s->provides, line + 6, 0);
1214 case 'O' << 16 | 'b' << 8 | 's':
1215 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1217 case 'C' << 16 | 'o' << 8 | 'n':
1218 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1220 case 'R' << 16 | 'e' << 8 | 'c':
1221 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1223 case 'S' << 16 | 'u' << 8 | 'p':
1224 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1226 case 'S' << 16 | 'u' << 8 | 'g':
1227 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1229 case 'E' << 16 | 'n' << 8 | 'h':
1230 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1237 finish_solvable(pool, data, s, filelist, nfilelist);
1239 solv_free(filelist);
1240 repodata_free_dircache(data);
1241 if (!(flags & REPO_NO_INTERNALIZE))
1242 repodata_internalize(data);
1247 testcase_getpoolflags(Pool *pool)
1249 const char *str = 0;
1251 for (i = 0; poolflags2str[i].str; i++)
1253 v = pool_get_flag(pool, poolflags2str[i].flag);
1254 if (v == poolflags2str[i].def)
1256 str = pool_tmpappend(pool, str, v ? " " : " !", poolflags2str[i].str);
1258 return str ? str + 1 : "";
1262 testcase_setpoolflags(Pool *pool, const char *str)
1264 const char *p = str, *s;
1268 while (*p == ' ' || *p == '\t' || *p == ',')
1279 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1281 for (i = 0; poolflags2str[i].str; i++)
1282 if (!strncmp(poolflags2str[i].str, s, p - s) && poolflags2str[i].str[p - s] == 0)
1284 if (!poolflags2str[i].str)
1286 pool_debug(pool, SOLV_ERROR, "setpoolflags: unknown flag '%.*s'\n", (int)(p - s), s);
1289 pool_set_flag(pool, poolflags2str[i].flag, v);
1295 testcase_resetpoolflags(Pool *pool)
1298 for (i = 0; poolflags2str[i].str; i++)
1299 pool_set_flag(pool, poolflags2str[i].flag, poolflags2str[i].def);
1303 testcase_getsolverflags(Solver *solv)
1305 Pool *pool = solv->pool;
1306 const char *str = 0;
1308 for (i = 0; solverflags2str[i].str; i++)
1310 v = solver_get_flag(solv, solverflags2str[i].flag);
1311 if (v == solverflags2str[i].def)
1313 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1315 return str ? str + 1 : "";
1319 testcase_setsolverflags(Solver *solv, const char *str)
1321 const char *p = str, *s;
1325 while (*p == ' ' || *p == '\t' || *p == ',')
1336 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1338 for (i = 0; solverflags2str[i].str; i++)
1339 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1341 if (!solverflags2str[i].str)
1343 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", (int)(p - s), s);
1346 solver_set_flag(solv, solverflags2str[i].flag, v);
1352 testcase_resetsolverflags(Solver *solv)
1355 for (i = 0; solverflags2str[i].str; i++)
1356 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1360 testcase_ruleid(Solver *solv, Id rid)
1366 const unsigned char *md5;
1372 solver_ruleliterals(solv, rid, &q);
1373 for (i = 0; i < q.count; i++)
1375 Id p = q.elements[i];
1376 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1378 s = pool_tmpjoin(solv->pool, "!", s, 0);
1379 strqueue_push(&sq, s);
1382 strqueue_sort_u(&sq);
1383 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1384 for (i = 0; i < sq.nstr; i++)
1385 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1386 md5 = solv_chksum_get(chk, &md5l);
1387 s = pool_bin2hex(solv->pool, md5, md5l);
1388 chk = solv_chksum_free(chk, 0);
1394 testcase_problemid(Solver *solv, Id problem)
1399 const unsigned char *md5;
1403 /* we build a hash of all rules that define the problem */
1406 solver_findallproblemrules(solv, problem, &q);
1407 for (i = 0; i < q.count; i++)
1408 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1410 strqueue_sort_u(&sq);
1411 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1412 for (i = 0; i < sq.nstr; i++)
1413 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1414 md5 = solv_chksum_get(chk, &md5l);
1415 s = pool_bin2hex(solv->pool, md5, 4);
1416 chk = solv_chksum_free(chk, 0);
1422 testcase_solutionid(Solver *solv, Id problem, Id solution)
1426 const unsigned char *md5;
1430 intid = solver_solutionelement_internalid(solv, problem, solution);
1431 /* internal stuff! handle with care! */
1435 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1440 s = testcase_ruleid(solv, intid);
1442 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1443 solv_chksum_add(chk, s, strlen(s) + 1);
1444 md5 = solv_chksum_get(chk, &md5l);
1445 s = pool_bin2hex(solv->pool, md5, 4);
1446 chk = solv_chksum_free(chk, 0);
1450 static struct class2str {
1454 { SOLVER_TRANSACTION_ERASE, "erase" },
1455 { SOLVER_TRANSACTION_INSTALL, "install" },
1456 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1457 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1458 { SOLVER_TRANSACTION_CHANGED, "change" },
1459 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1460 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1461 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1462 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1467 testcase_solverresult(Solver *solv, int resultflags)
1469 Pool *pool = solv->pool;
1477 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1479 Transaction *trans = solver_create_transaction(solv);
1483 for (i = 0; class2str[i].str; i++)
1486 transaction_classify_pkgs(trans, SOLVER_TRANSACTION_KEEP_PSEUDO, class2str[i].class, 0, 0, &q);
1487 for (j = 0; j < q.count; j++)
1491 if (pool->installed && pool->solvables[p].repo == pool->installed)
1492 op = transaction_obs_pkg(trans, p);
1493 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1495 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1496 strqueue_push(&sq, s);
1500 transaction_free(trans);
1502 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1504 char *probprefix, *solprefix;
1505 int problem, solution, element;
1508 pcnt = solver_problem_count(solv);
1509 for (problem = 1; problem <= pcnt; problem++)
1511 Id rid, from, to, dep;
1512 SolverRuleinfo rinfo;
1513 rid = solver_findproblemrule(solv, problem);
1514 s = testcase_problemid(solv, problem);
1515 probprefix = solv_dupjoin("problem ", s, 0);
1516 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1517 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1518 strqueue_push(&sq, s);
1519 scnt = solver_solution_count(solv, problem);
1520 for (solution = 1; solution <= scnt; solution++)
1522 s = testcase_solutionid(solv, problem, solution);
1523 solprefix = solv_dupjoin(probprefix, " solution ", s);
1525 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1527 if (p == SOLVER_SOLUTION_JOB)
1528 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1529 else if (p > 0 && op == 0)
1530 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1531 else if (p > 0 && op > 0)
1533 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1534 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1536 else if (p < 0 && op > 0)
1537 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1539 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1540 strqueue_push(&sq, s);
1542 solv_free(solprefix);
1544 solv_free(probprefix);
1548 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1553 solver_get_orphaned(solv, &q);
1554 for (i = 0; i < q.count; i++)
1556 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1557 strqueue_push(&sq, s);
1562 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1568 solver_get_recommendations(solv, &qr, &qs, 0);
1569 for (i = 0; i < qr.count; i++)
1571 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1572 strqueue_push(&sq, s);
1574 for (i = 0; i < qs.count; i++)
1576 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1577 strqueue_push(&sq, s);
1583 if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0)
1588 solver_get_unneeded(solv, &q, 0);
1589 for (i = 0; i < q.count; i++)
1591 s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0);
1592 strqueue_push(&sq, s);
1598 result = strqueue_join(&sq);
1605 testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasename, const char *resultname)
1607 Pool *pool = solv->pool;
1618 testcasename = "testcase.t";
1620 resultname = "solver.result";
1622 if (mkdir(dir, 0777) && errno != EEXIST)
1624 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
1628 FOR_REPOS(repoid, repo)
1630 const char *name = testcase_repoid2str(pool, repoid);
1632 if (repo->subpriority)
1633 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
1635 sprintf(priobuf, "%d", repo->priority);
1636 out = pool_tmpjoin(pool, name, ".repo", ".gz");
1637 cmd = pool_tmpjoin(pool, "repo ", name, " ");
1638 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
1639 cmd = pool_tmpappend(pool, cmd, "testtags ", out);
1640 strqueue_push(&sq, cmd);
1641 out = pool_tmpjoin(pool, dir, "/", out);
1642 if (!(fp = solv_xfopen(out, "w")))
1644 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1648 testcase_write_testtags(repo, fp);
1651 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1656 /* hmm, this is not optimal... we currently search for the lowest score */
1658 arch = pool->solvables[SYSTEMSOLVABLE].arch;
1659 for (i = 0; i < pool->lastarch; i++)
1661 if (pool->id2arch[i] == 1 && !lowscore)
1663 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
1666 lowscore = pool->id2arch[i];
1669 cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
1670 for (i = 0; disttype2str[i].str != 0; i++)
1671 if (pool->disttype == disttype2str[i].type)
1673 pool_tmpappend(pool, cmd, " ", disttype2str[i].str ? disttype2str[i].str : "unknown");
1674 if (pool->installed)
1675 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
1676 strqueue_push(&sq, cmd);
1677 s = testcase_getpoolflags(solv->pool);
1680 cmd = pool_tmpjoin(pool, "poolflags ", s, 0);
1681 strqueue_push(&sq, cmd);
1684 if (pool->vendorclasses)
1687 for (i = 0; pool->vendorclasses[i]; i++)
1689 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
1690 if (!pool->vendorclasses[i + 1])
1692 strqueue_push(&sq, cmd);
1699 s = testcase_getsolverflags(solv);
1702 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
1703 strqueue_push(&sq, cmd);
1706 /* now dump all the ns callback values we know */
1707 if (pool->nscallback)
1711 for (rid = 1; rid < pool->nrels; rid++)
1713 Reldep *rd = pool->rels + rid;
1714 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1716 /* evaluate all namespace ids, skip empty results */
1717 d = pool_whatprovides(pool, MAKERELDEP(rid));
1718 if (!d || !pool->whatprovidesdata[d])
1720 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
1721 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
1722 for (; pool->whatprovidesdata[d]; d++)
1723 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
1724 strqueue_push(&sq, cmd);
1728 for (i = 0; i < solv->job.count; i += 2)
1730 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
1731 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
1732 strqueue_push(&sq, cmd);
1739 for (i = 0; resultflags2str[i].str; i++)
1740 if ((resultflags & resultflags2str[i].flag) != 0)
1741 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
1742 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", 0);
1743 cmd = pool_tmpappend(pool, cmd, " ", resultname);
1744 strqueue_push(&sq, cmd);
1745 result = testcase_solverresult(solv, resultflags);
1746 if (!strcmp(resultname, "<inline>"))
1750 strqueue_init(&rsq);
1751 strqueue_split(&rsq, result);
1752 for (i = 0; i < rsq.nstr; i++)
1754 cmd = pool_tmpjoin(pool, "#>", rsq.str[i], 0);
1755 strqueue_push(&sq, cmd);
1757 strqueue_free(&rsq);
1761 out = pool_tmpjoin(pool, dir, "/", resultname);
1762 if (!(fp = fopen(out, "w")))
1764 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1769 if (result && *result && fwrite(result, strlen(result), 1, fp) != 1)
1771 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1779 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1787 cmd = strqueue_join(&sq);
1788 out = pool_tmpjoin(pool, dir, "/", testcasename);
1789 if (!(fp = fopen(out, "w")))
1791 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1795 if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
1797 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1804 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1814 read_inline_file(FILE *fp, char **bufp, char **bufpp, int *buflp)
1816 char *result = solv_malloc(1024);
1823 if (rp - result + 256 >= resultl)
1825 resultl = rp - result;
1826 result = solv_realloc(result, resultl + 1024);
1827 rp = result + resultl;
1830 if (!fgets(rp, resultl - (rp - result), fp))
1833 if (rl && (rp == result || rp[-1] == '\n'))
1835 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
1837 memmove(rp, rp + 2, rl - 2);
1842 while (rl + 16 > *buflp)
1844 *bufp = solv_realloc(*bufp, *buflp + 512);
1847 memmove(*bufp, rp, rl);
1848 if ((*bufp)[rl - 1] == '\n')
1854 (*bufpp) = *bufp + rl;
1871 char *result = solv_malloc(1024);
1878 if (rp - result + 256 >= resultl)
1880 resultl = rp - result;
1881 result = solv_realloc(result, resultl + 1024);
1882 rp = result + resultl;
1885 rl = fread(rp, 1, resultl - (rp - result), fp);
1897 str2resultflags(Pool *pool, char *s) /* modifies the string! */
1899 int i, resultflags = 0;
1902 char *se = strchr(s, ',');
1905 for (i = 0; resultflags2str[i].str; i++)
1906 if (!strcmp(s, resultflags2str[i].str))
1908 resultflags |= resultflags2str[i].flag;
1911 if (!resultflags2str[i].str)
1912 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
1919 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
1924 char *testcasedir, *s;
1930 int poolflagsreset = 0;
1932 if (!fp && !(fp = fopen(testcase, "r")))
1934 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
1937 testcasedir = solv_strdup(testcase);
1938 if ((s = strrchr(testcasedir, '/')) != 0)
1943 buf = solv_malloc(bufl);
1948 if (bufp - buf + 16 > bufl)
1951 buf = solv_realloc(buf, bufl + 512);
1955 if (!fgets(bufp, bufl - (bufp - buf), fp))
1959 if (!l || buf[l - 1] != '\n')
1966 while (*s && (*s == ' ' || *s == '\t'))
1968 if (!*s || *s == '#')
1971 /* split it in pieces */
1974 while (*s == ' ' || *s == '\t')
1978 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1979 pieces[npieces++] = s;
1980 while (*s && *s != ' ' && *s != '\t')
1985 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1986 pieces[npieces] = 0;
1987 if (!strcmp(pieces[0], "repo") && npieces >= 4)
1989 Repo *repo = repo_create(pool, pieces[1]);
1995 if (!poolflagsreset)
1998 testcase_resetpoolflags(pool); /* hmm */
2000 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
2003 prio = atoi(pieces[2]);
2005 repo->priority = prio;
2006 repo->subpriority = subprio;
2007 if (strcmp(pieces[3], "empty") != 0)
2009 const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0); /* gets overwritten in <inline> case */
2010 if (!strcmp(pieces[4], "<inline>"))
2012 char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
2014 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
2018 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
2019 rfp = solv_xfopen(rdata, "r");
2023 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2025 else if (!strcmp(repotype, "testtags"))
2027 testcase_add_testtags(repo, rfp, 0);
2030 else if (!strcmp(repotype, "solv"))
2032 repo_add_solv(repo, rfp, 0);
2036 else if (!strcmp(repotype, "helix"))
2038 extern int repo_add_helix(Repo *repo, FILE *fp, int flags);
2039 repo_add_helix(repo, rfp, 0);
2046 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
2050 else if (!strcmp(pieces[0], "system") && npieces >= 3)
2054 /* must set the disttype before the arch */
2055 for (i = 0; disttype2str[i].str != 0; i++)
2056 if (!strcmp(disttype2str[i].str, pieces[2]))
2058 if (!disttype2str[i].str)
2059 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown disttype '%s'\n", pieces[2]);
2060 else if (pool->disttype != disttype2str[i].type)
2062 #ifdef MULTI_SEMANTICS
2063 pool_setdisttype(pool, disttype2str[i].type);
2065 pool_debug(pool, SOLV_ERROR, "testcase_read: system: cannot change disttype to '%s'\n", pieces[2]);
2068 if (strcmp(pieces[1], "unset") == 0)
2069 pool_setarch(pool, 0);
2070 else if (pieces[1][0] == ':')
2071 pool_setarchpolicy(pool, pieces[1] + 1);
2073 pool_setarch(pool, pieces[1]);
2076 Repo *repo = testcase_str2repo(pool, pieces[3]);
2078 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
2080 pool_set_installed(pool, repo);
2083 else if (!strcmp(pieces[0], "job") && npieces > 1)
2089 pool_addfileprovides(pool);
2090 pool_createwhatprovides(pool);
2093 if (npieces >= 3 && !strcmp(pieces[2], "selection"))
2095 addselectionjob(pool, pieces + 1, npieces - 1, job);
2099 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
2102 how = testcase_str2job(pool, pieces[1], &what);
2103 if (how >= 0 && job)
2104 queue_push2(job, how, what);
2106 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
2108 pool_addvendorclass(pool, (const char **)(pieces + 1));
2110 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
2112 int i = strlen(pieces[1]);
2113 s = strchr(pieces[1], '(');
2114 if (!s && pieces[1][i - 1] != ')')
2116 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
2124 pieces[1][i - 1] = 0;
2125 name = pool_str2id(pool, pieces[1], 1);
2126 evr = pool_str2id(pool, s + 1, 1);
2128 pieces[1][i - 1] = ')';
2129 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
2130 for (i = 2; i < npieces; i++)
2131 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
2132 /* now do the callback */
2135 pool_addfileprovides(pool);
2136 pool_createwhatprovides(pool);
2139 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
2143 else if (!strcmp(pieces[0], "poolflags"))
2146 if (!poolflagsreset)
2149 testcase_resetpoolflags(pool); /* hmm */
2151 for (i = 1; i < npieces; i++)
2152 testcase_setpoolflags(pool, pieces[i]);
2154 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
2159 solv = solver_create(pool);
2160 testcase_resetsolverflags(solv);
2162 for (i = 1; i < npieces; i++)
2163 testcase_setsolverflags(solv, pieces[i]);
2165 else if (!strcmp(pieces[0], "result") && npieces > 2)
2168 int resultflags = str2resultflags(pool, pieces[1]);
2169 const char *rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
2170 if (!strcmp(pieces[2], "<inline>"))
2171 result = read_inline_file(fp, &buf, &bufp, &bufl);
2174 FILE *rfp = fopen(rdata, "r");
2176 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
2179 result = read_file(rfp);
2188 *resultflagsp = resultflags;
2190 else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
2196 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
2199 buf = solv_free(buf);
2200 pieces = solv_free(pieces);
2201 solv_free(testcasedir);
2204 pool_addfileprovides(pool);
2205 pool_createwhatprovides(pool);
2209 solv = solver_create(pool);
2210 testcase_resetsolverflags(solv);
2218 testcase_resultdiff(char *result1, char *result2)
2220 Strqueue sq1, sq2, osq;
2222 strqueue_init(&sq1);
2223 strqueue_init(&sq2);
2224 strqueue_init(&osq);
2225 strqueue_split(&sq1, result1);
2226 strqueue_split(&sq2, result2);
2227 strqueue_sort(&sq1);
2228 strqueue_sort(&sq2);
2229 strqueue_diff(&sq1, &sq2, &osq);
2230 r = osq.nstr ? strqueue_join(&osq) : 0;
2231 strqueue_free(&sq1);
2232 strqueue_free(&sq2);
2233 strqueue_free(&osq);