X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=ext%2Ftestcase.c;h=77cc7194704e9ee20ecd0d749ada9cbb365cc47e;hb=c948f862b552adbe2cdee24096357b887dfbb088;hp=3d62437fb10c45699b546d5252c3db4a98a45698;hpb=09387351f51bd0a6c6434b12bc50f2e83590954d;p=platform%2Fupstream%2Flibsolv.git diff --git a/ext/testcase.c b/ext/testcase.c index 3d62437..77cc719 100644 --- a/ext/testcase.c +++ b/ext/testcase.c @@ -7,8 +7,6 @@ #include #include -#include -#include #include #include #include @@ -25,6 +23,9 @@ #include "testcase.h" #include "selection.h" #include "solv_xfopen.h" +#if ENABLE_TESTCASE_HELIXREPO +#include "ext/repo_helix.h" +#endif #define DISABLE_JOIN2 #include "tools_util.h" @@ -33,18 +34,21 @@ static struct job2str { Id job; const char *str; } job2str[] = { - { SOLVER_NOOP, "noop" }, - { SOLVER_INSTALL, "install" }, - { SOLVER_ERASE, "erase" }, - { SOLVER_UPDATE, "update" }, - { SOLVER_WEAKENDEPS, "weakendeps" }, - { SOLVER_MULTIVERSION, "multiversion" }, - { SOLVER_MULTIVERSION, "noobsoletes" }, /* old name */ - { SOLVER_LOCK, "lock" }, - { SOLVER_DISTUPGRADE, "distupgrade" }, - { SOLVER_VERIFY, "verify" }, - { SOLVER_DROP_ORPHANED, "droporphaned" }, - { SOLVER_USERINSTALLED, "userinstalled" }, + { SOLVER_NOOP, "noop" }, + { SOLVER_INSTALL, "install" }, + { SOLVER_ERASE, "erase" }, + { SOLVER_UPDATE, "update" }, + { SOLVER_WEAKENDEPS, "weakendeps" }, + { SOLVER_MULTIVERSION, "multiversion" }, + { SOLVER_MULTIVERSION, "noobsoletes" }, /* old name */ + { SOLVER_LOCK, "lock" }, + { SOLVER_DISTUPGRADE, "distupgrade" }, + { SOLVER_VERIFY, "verify" }, + { SOLVER_DROP_ORPHANED, "droporphaned" }, + { SOLVER_USERINSTALLED, "userinstalled" }, + { SOLVER_ALLOWUNINSTALL, "allowuninstall" }, + { SOLVER_FAVOR, "favor" }, + { SOLVER_DISFAVOR, "disfavor" }, { 0, 0 } }; @@ -58,6 +62,7 @@ static struct jobflags2str { { SOLVER_ORUPDATE, "orupdate" }, { SOLVER_FORCEBEST, "forcebest" }, { SOLVER_TARGETED, "targeted" }, + { SOLVER_NOTBYUSER, "notbyuser" }, { SOLVER_SETEV, "setev" }, { SOLVER_SETEVR, "setevr" }, { SOLVER_SETARCH, "setarch" }, @@ -76,6 +81,10 @@ static struct resultflags2str { { TESTCASE_RESULT_ORPHANED, "orphaned" }, { TESTCASE_RESULT_RECOMMENDED, "recommended" }, { TESTCASE_RESULT_UNNEEDED, "unneeded" }, + { TESTCASE_RESULT_ALTERNATIVES, "alternatives" }, + { TESTCASE_RESULT_RULES, "rules" }, + { TESTCASE_RESULT_GENID, "genid" }, + { TESTCASE_RESULT_REASON, "reason" }, { 0, 0 } }; @@ -97,6 +106,19 @@ static struct solverflags2str { { SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES, "keepexplicitobsoletes", 0 }, { SOLVER_FLAG_BEST_OBEY_POLICY, "bestobeypolicy", 0 }, { SOLVER_FLAG_NO_AUTOTARGET, "noautotarget", 0 }, + { SOLVER_FLAG_DUP_ALLOW_DOWNGRADE, "dupallowdowngrade", 1 }, + { SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE, "dupallowarchchange", 1 }, + { SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE, "dupallowvendorchange", 1 }, + { SOLVER_FLAG_DUP_ALLOW_NAMECHANGE, "dupallownamechange", 1 }, + { SOLVER_FLAG_KEEP_ORPHANS, "keeporphans", 0 }, + { SOLVER_FLAG_BREAK_ORPHANS, "breakorphans", 0 }, + { SOLVER_FLAG_FOCUS_INSTALLED, "focusinstalled", 0 }, + { SOLVER_FLAG_YUM_OBSOLETES, "yumobsoletes", 0 }, + { SOLVER_FLAG_NEED_UPDATEPROVIDE, "needupdateprovide", 0 }, + { SOLVER_FLAG_URPM_REORDER, "urpmreorder", 0 }, + { SOLVER_FLAG_FOCUS_BEST, "focusbest", 0 }, + { SOLVER_FLAG_STRONG_RECOMMENDS, "strongrecommends", 0 }, + { SOLVER_FLAG_INSTALL_ALSO_UPDATES, "installalsoupdates", 0 }, { 0, 0, 0 } }; @@ -115,6 +137,7 @@ static struct poolflags2str { { POOL_FLAG_HAVEDISTEPOCH, "havedistepoch", 0 }, { POOL_FLAG_NOOBSOLETESMULTIVERSION, "noobsoletesmultiversion", 0 }, { POOL_FLAG_ADDFILEPROVIDESFILTERED, "addfileprovidesfiltered", 0 }, + { POOL_FLAG_NOWHATPROVIDESAUX, "nowhatprovidesaux", 0 }, { 0, 0, 0 } }; @@ -125,6 +148,7 @@ static struct disttype2str { { DISTTYPE_RPM, "rpm" }, { DISTTYPE_DEB, "deb" }, { DISTTYPE_ARCH, "arch" }, + { DISTTYPE_HAIKU, "haiku" }, { 0, 0 } }; @@ -147,6 +171,18 @@ static struct selflags2str { { 0, 0 } }; +static const char *features[] = { +#ifdef ENABLE_LINKED_PKGS + "linked_packages", +#endif +#ifdef ENABLE_COMPLEX_DEPS + "complex_deps", +#endif +#if ENABLE_TESTCASE_HELIXREPO + "testcase_helixrepo", +#endif + 0 +}; typedef struct strqueue { char **str; @@ -274,101 +310,346 @@ strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq) strqueue_pushjoin(osq, "+", sq2->str[j++], 0); } -static inline int -pool_isknownarch(Pool *pool, Id id) + +static const char * +testcase_id2str(Pool *pool, Id id, int isname) { - if (!id || id == ID_EMPTY) - return 0; - if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH) - return 1; - if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id])) - return 0; - return 1; + const char *s = pool_id2str(pool, id); + const char *ss; + char *s2, *s2p; + int bad = 0, paren = 0, parenbad = 0; + + if (id == 0) + return ""; + if (id == 1) + return "\\00"; + if (strchr("[(<=>!", *s)) + bad++; + if (!strncmp(s, "namespace:", 10)) + bad++; + for (ss = s + bad; *ss; ss++) + { + if (*ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')') + bad++; + if (*ss == '(') + paren = paren == 0 ? 1 : -1; + else if (*ss == ')') + { + paren = paren == 1 ? 0 : -1; + if (!paren) + parenbad += 2; + } + } + if (isname && ss - s > 4 && !strcmp(ss - 4, ":any")) + bad++; + if (!paren && !(bad - parenbad)) + return s; + + /* we need escaping! */ + s2 = s2p = pool_alloctmpspace(pool, strlen(s) + bad * 2 + 1); + if (!strncmp(s, "namespace:", 10)) + { + strcpy(s2p, "namespace\\3a"); + s2p += 12; + s += 10; + } + ss = s; + for (; *ss; ss++) + { + *s2p++ = *ss; + if ((ss == s && strchr("[(<=>!", *s)) || *ss == ' ' || *ss == '\\' || *(unsigned char *)ss < 32 || *ss == '(' || *ss == ')') + { + s2p[-1] = '\\'; + solv_bin2hex((unsigned char *)ss, 1, s2p); + s2p += 2; + } + } + *s2p = 0; + if (isname && s2p - s2 > 4 && !strcmp(s2p - 4, ":any")) + strcpy(s2p - 4, "\\3aany"); + return s2; } -Id -testcase_str2dep(Pool *pool, char *s) +struct oplist { + Id flags; + const char *opname; +} oplist[] = { + { REL_EQ, "=" }, + { REL_GT | REL_LT | REL_EQ, "<=>" }, + { REL_LT | REL_EQ, "<=" }, + { REL_GT | REL_EQ, ">=" }, + { REL_GT, ">" }, + { REL_GT | REL_LT, "<>" }, + { REL_AND, "&" }, + { REL_OR , "|" }, + { REL_WITH , "+" }, + { REL_WITHOUT , "-" }, + { REL_NAMESPACE , "" }, + { REL_ARCH, "." }, + { REL_MULTIARCH, "" }, + { REL_FILECONFLICT, "" }, + { REL_COND, "" }, + { REL_COMPAT, "compat >=" }, + { REL_KIND, "" }, + { REL_ELSE, "" }, + { REL_ERROR, "" }, + { REL_UNLESS, "" }, + { REL_LT, "<" }, + { 0, 0 } +}; + +static char * +testcase_dep2str_complex(Pool *pool, char *s, Id id, int addparens) { - char *n, *a; - Id id, evr; - int flags; - - if ((n = strchr(s, '|')) != 0) - { - id = testcase_str2dep(pool, n + 1); - *n = 0; - id = pool_rel2id(pool, testcase_str2dep(pool, s), id, REL_OR, 1); - *n = '|'; - return id; + Reldep *rd; + const char *s2; + int needparens; + struct oplist *op; + + if (!ISRELDEP(id)) + { + s2 = testcase_id2str(pool, id, 1); + s = pool_tmpappend(pool, s, s2, 0); + pool_freetmpspace(pool, s2); + return s; } - while (*s == ' ' || *s == '\t') - s++; - n = s; - while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>') + rd = GETRELDEP(pool, id); + + /* check for special shortcuts */ + if (rd->flags == REL_NAMESPACE && !ISRELDEP(rd->name) && !strncmp(pool_id2str(pool, rd->name), "namespace:", 10)) + { + s = pool_tmpappend(pool, s, pool_id2str(pool, rd->name), "("); + s = testcase_dep2str_complex(pool, s, rd->evr, 0); + return pool_tmpappend(pool, s, ")", 0); + } + if (rd->flags == REL_MULTIARCH && !ISRELDEP(rd->name) && rd->evr == ARCH_ANY) + { + /* append special :any suffix */ + s2 = testcase_id2str(pool, rd->name, 1); + s = pool_tmpappend(pool, s, s2, ":any"); + pool_freetmpspace(pool, s2); + return s; + } + + needparens = 0; + if (ISRELDEP(rd->name)) + { + Reldep *rd2 = GETRELDEP(pool, rd->name); + needparens = 1; + if (rd->flags > 7 && rd->flags != REL_COMPAT && rd2->flags && rd2->flags <= 7) + needparens = 0; + } + + if (addparens) + s = pool_tmpappend(pool, s, "(", 0); + s = testcase_dep2str_complex(pool, s, rd->name, needparens); + + for (op = oplist; op->flags; op++) + if (rd->flags == op->flags) + break; + if (op->flags) + { + s = pool_tmpappend(pool, s, " ", op->opname); + s = pool_tmpappend(pool, s, " ", 0); + } + else { + char buf[64]; + sprintf(buf, " <%u> ", rd->flags); + s = pool_tmpappend(pool, s, buf, 0); + } + + needparens = 0; + if (ISRELDEP(rd->evr)) + { + Reldep *rd2 = GETRELDEP(pool, rd->evr); + needparens = 1; + if (rd->flags > 7 && rd2->flags && rd2->flags <= 7) + needparens = 0; + if (rd->flags == REL_AND && rd2->flags == REL_AND) + needparens = 0; /* chain */ + if (rd->flags == REL_OR && rd2->flags == REL_OR) + needparens = 0; /* chain */ + if (rd->flags > 0 && rd->flags < 8 && rd2->flags == REL_COMPAT) + needparens = 0; /* chain */ + } + if (!ISRELDEP(rd->evr)) + { + s2 = testcase_id2str(pool, rd->evr, 0); + s = pool_tmpappend(pool, s, s2, 0); + pool_freetmpspace(pool, s2); + } + else + s = (char *)testcase_dep2str_complex(pool, s, rd->evr, needparens); + if (addparens) + s = pool_tmpappend(pool, s, ")", 0); + return s; +} + +const char * +testcase_dep2str(Pool *pool, Id id) +{ + char *s; + if (!ISRELDEP(id)) + return testcase_id2str(pool, id, 1); + s = pool_alloctmpspace(pool, 1); + *s = 0; + return testcase_dep2str_complex(pool, s, id, 0); +} + + +/* Convert a simple string. Also handle the :any suffix */ +static Id +testcase_str2dep_simple(Pool *pool, const char **sp, int isname) +{ + int haveesc = 0; + int paren = 0; + int isany = 0; + Id id; + const char *s; + for (s = *sp; *s; s++) + { + if (*s == '\\') + haveesc++; + if (*s == ' ' || *(unsigned char *)s < 32) + break; if (*s == '(') - { - while (*s && *s != ')') - s++; - } + paren++; + if (*s == ')' && paren-- <= 0) + break; + } + if (isname && s - *sp > 4 && !strncmp(s - 4, ":any", 4)) + { + isany = 1; + s -= 4; + } + if (!haveesc) + { + if (s - *sp == 6 && !strncmp(*sp, "", 6)) + id = 0; else - s++; + id = pool_strn2id(pool, *sp, s - *sp, 1); } - if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')') + else if (s - *sp == 3 && !strncmp(*sp, "\\00", 3)) + id = 1; + else { - Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0); - if (pool_isknownarch(pool, archid)) + char buf[128], *bp, *bp2; + const char *sp2; + bp = s - *sp >= 128 ? solv_malloc(s - *sp + 1) : buf; + for (bp2 = bp, sp2 = *sp; sp2 < s;) { - id = pool_strn2id(pool, n, a - n, 1); - id = pool_rel2id(pool, id, archid, REL_ARCH, 1); + *bp2++ = *sp2++; + if (bp2[-1] == '\\') + solv_hex2bin(&sp2, (unsigned char *)bp2 - 1, 1); } - else - id = pool_strn2id(pool, n, s - n, 1); + *bp2 = 0; + id = pool_str2id(pool, bp, 1); + if (bp != buf) + solv_free(bp); } - else - id = pool_strn2id(pool, n, s - n, 1); - if (!*s) - return id; - while (*s == ' ' || *s == '\t') - s++; - flags = 0; - if (*s == '!' && s[1] == '=') /* support != as synonym for <> */ - { - flags = REL_LT | REL_GT; - s += 2; - } - for (;;s++) - { - if (*s == '<') - flags |= REL_LT; - else if (*s == '=') - flags |= REL_EQ; - else if (*s == '>') - flags |= REL_GT; - else - break; + if (isany) + { + id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1); + s += 4; } - if (!flags) - return id; + *sp = s; + return id; +} + + +static Id +testcase_str2dep_complex(Pool *pool, const char **sp, int relop) +{ + const char *s = *sp; + Id flags, id, id2, namespaceid = 0; + struct oplist *op; + while (*s == ' ' || *s == '\t') s++; - n = s; - while (*s && *s != ' ' && *s != '\t') - s++; - evr = pool_strn2id(pool, n, s - n, 1); - if (*s == ' ' && !strcmp(s, " compat >= ")) + if (!strncmp(s, "namespace:", 10)) + { + /* special namespace hack */ + const char *s2; + for (s2 = s + 10; *s2 && *s2 != '('; s2++) + ; + if (*s2 == '(') + { + namespaceid = pool_strn2id(pool, s, s2 - s, 1); + s = s2; + } + } + if (*s == '(') + { + s++; + id = testcase_str2dep_complex(pool, &s, 0); + if (!s || *s != ')') + { + *sp = 0; + return 0; + } + s++; + } + else + id = testcase_str2dep_simple(pool, &s, relop ? 0 : 1); + if (namespaceid) + id = pool_rel2id(pool, namespaceid, id, REL_NAMESPACE, 1); + + for (;;) { - s += 11; while (*s == ' ' || *s == '\t') s++; - n = s; - while (*s && *s != ' ' && *s != '\t') - s++; - evr = pool_rel2id(pool, evr, pool_strn2id(pool, n, s - n, 1), REL_COMPAT, 1); + if (!*s || *s == ')' || (relop && strncmp(s, "compat >= ", 10) != 0)) + { + *sp = s; + return id; + } + + /* we have an op! Find the end */ + flags = -1; + if (s[0] == '<' && (s[1] >= '0' && s[1] <= '9')) + { + const char *s2; + for (s2 = s + 1; *s2 >= '0' && *s2 <= '9'; s2++) + ; + if (*s2 == '>') + { + flags = strtoul(s + 1, 0, 10); + s = s2 + 1; + } + } + if (flags == -1) + { + for (op = oplist; op->flags; op++) + if (!strncmp(s, op->opname, strlen(op->opname))) + break; + if (!op->flags) + { + *sp = 0; + return 0; + } + flags = op->flags; + s += strlen(op->opname); + } + id2 = testcase_str2dep_complex(pool, &s, flags > 0 && flags < 8); + if (!s) + { + *sp = 0; + return 0; + } + id = pool_rel2id(pool, id, id2, flags, 1); } - return pool_rel2id(pool, id, evr, flags, 1); } +Id +testcase_str2dep(Pool *pool, const char *s) +{ + Id id = testcase_str2dep_complex(pool, &s, 0); + return s && !*s ? id : 0; +} + +/**********************************************************/ + const char * testcase_repoid2str(Pool *pool, Id repoid) { @@ -402,8 +683,8 @@ testcase_solvid2str(Pool *pool, Id p) n = pool_id2str(pool, s->name); e = pool_id2str(pool, s->evr); a = pool_id2str(pool, s->arch); - str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3); - sprintf(str, "%s-%s.%s", n, e, a); + str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3); + sprintf(str, "%s-%s.%s", n, e, a); if (!s->repo) return pool_tmpappend(pool, str, "@", 0); if (s->repo->name) @@ -499,6 +780,7 @@ testcase_str2solvid(Pool *pool, const char *str) evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0); if (!evrid) continue; + /* first check whatprovides */ FOR_PROVIDES(p, pp, nid) { Solvable *s = pool->solvables + p; @@ -510,6 +792,31 @@ testcase_str2solvid(Pool *pool, const char *str) continue; return p; } + /* maybe it's not installable and thus not in whatprovides. do a slow search */ + if (repo) + { + Solvable *s; + FOR_REPO_SOLVABLES(repo, p, s) + { + if (s->name != nid || s->evr != evrid) + continue; + if (arch && s->arch != arch) + continue; + return p; + } + } + else + { + FOR_POOL_SOLVABLES(p) + { + Solvable *s = pool->solvables + p; + if (s->name != nid || s->evr != evrid) + continue; + if (arch && s->arch != arch) + continue; + return p; + } + } } } return 0; @@ -537,12 +844,12 @@ testcase_job2str(Pool *pool, Id how, Id what) else if (select == SOLVER_SOLVABLE_NAME) { selstr = " name "; - pkgstr = pool_dep2str(pool, what); + pkgstr = testcase_dep2str(pool, what); } else if (select == SOLVER_SOLVABLE_PROVIDES) { selstr = " provides "; - pkgstr = pool_dep2str(pool, what); + pkgstr = testcase_dep2str(pool, what); } else if (select == SOLVER_SOLVABLE_ONE_OF) { @@ -814,7 +1121,7 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp) return job; } -int +static int addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue) { Id job; @@ -860,14 +1167,13 @@ static void writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off) { Pool *pool = repo->pool; - Id id, *dp, *prvdp; + Id id, *dp; int tagwritten = 0; const char *idstr; if (!off) return; dp = repo->idarraydata + off; - prvdp = 0; while ((id = *dp++) != 0) { if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER) @@ -879,68 +1185,8 @@ writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off continue; } if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER) - { - prvdp = dp; - continue; - } - idstr = pool_dep2str(pool, id); - if (ISRELDEP(id)) - { - Reldep *rd = GETRELDEP(pool, id); - if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - if (key == SOLVABLE_SUPPLEMENTS) - { - if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS) - { - if (!strncmp(idstr, "namespace:", 10)) - idstr += 10; - } - else if (rd->flags == REL_AND) - { - /* either packageand chain or modalias */ - idstr = 0; - if (ISRELDEP(rd->evr)) - { - Reldep *mrd = GETRELDEP(pool, rd->evr); - if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS) - { - idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":"); - idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")"); - } - else if (mrd->flags >= 8) - continue; - } - if (!idstr) - { - /* must be and chain */ - idstr = pool_dep2str(pool, rd->evr); - for (;;) - { - id = rd->name; - if (!ISRELDEP(id)) - break; - rd = GETRELDEP(pool, id); - if (rd->flags != REL_AND) - break; - idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr); - } - idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr); - idstr = pool_tmpjoin(pool, "packageand(", idstr, ")"); - } - } - else if (rd->flags >= 8) - continue; - } - } + continue; + idstr = testcase_dep2str(pool, id); if (!tagwritten) { fprintf(fp, "+%s\n", tag); @@ -948,36 +1194,31 @@ writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off } fprintf(fp, "%s\n", idstr); } - if (key == SOLVABLE_PROVIDES) + if (tagwritten) + fprintf(fp, "-%s\n", tag); +} + +static void +writefilelist(Repo *repo, FILE *fp, const char *tag, Solvable *s) +{ + Pool *pool = repo->pool; + int tagwritten = 0; + Dataiterator di; + + dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0); + while (dataiterator_step(&di)) { - /* add the filelist */ - Dataiterator di; - dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0); - while (dataiterator_step(&di)) + const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str); + if (!tagwritten) { - const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str); - if (prvdp) - { - Id id = pool_str2id(pool, s, 0); - if (id) - { - for (dp = prvdp; *dp; dp++) - if (*dp == id) - break; - if (*dp) - continue; /* already included */ - } - } - if (!tagwritten) - { - fprintf(fp, "+%s", tag); - tagwritten = 1; - } - fprintf(fp, "%s\n", s); + fprintf(fp, "+%s\n", tag); + tagwritten = 1; } + fprintf(fp, "%s\n", s); } if (tagwritten) fprintf(fp, "-%s\n", tag); + dataiterator_free(&di); } int @@ -992,8 +1233,10 @@ testcase_write_testtags(Repo *repo, FILE *fp) const char *release; const char *tmp; unsigned int ti; + Queue q; - fprintf(fp, "=Ver: 2.0\n"); + fprintf(fp, "=Ver: 3.0\n"); + queue_init(&q); FOR_REPO_SOLVABLES(repo, p, s) { name = pool_id2str(pool, s->name); @@ -1014,12 +1257,22 @@ testcase_write_testtags(Repo *repo, FILE *fp) writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements); writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests); writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances); + if (solvable_lookup_idarray(s, SOLVABLE_PREREQ_IGNOREINST, &q)) + { + int i; + fprintf(fp, "+Ipr:\n"); + for (i = 0; i < q.count; i++) + fprintf(fp, "%s\n", testcase_dep2str(pool, q.elements[i])); + fprintf(fp, "-Ipr:\n"); + } if (s->vendor) fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor)); ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0); if (ti) fprintf(fp, "=Tim: %u\n", ti); + writefilelist(repo, fp, "Fls:", s); } + queue_free(&q); return 0; } @@ -1031,29 +1284,26 @@ adddep(Repo *repo, Offset olddeps, char *str, Id marker) } static void -finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist) +finish_v2_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist) { if (nfilelist) { int l; - Id did; - for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) + Id did; + for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) { char *p = strrchr(filelist + l, '/'); - if (!p) + if (!p) continue; - *p++ = 0; + *p++ = 0; did = repodata_str2dir(data, filelist + l, 1); - p[-1] = '/'; + p[-1] = '/'; if (!did) did = repodata_str2dir(data, "/", 1); repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p); } } - if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) - s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); - s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0); - s->conflicts = repo_fix_conflicts(s->repo, s->conflicts); + repo_rewrite_suse_deps(s, 0); } /* stripped down version of susetags parser used for testcases */ @@ -1072,6 +1322,8 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) char *filelist = 0; int afilelist = 0; int nfilelist = 0; + int tagsversion = 0; + int addselfprovides = 1; /* for compat reasons */ data = repo_add_repodata(repo, flags); s = 0; @@ -1094,7 +1346,7 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) linep += strlen(linep); if (linep == line || linep[-1] != '\n') continue; - *--linep = 0; + linep[-1] = 0; linep = line + intag; if (intag) { @@ -1121,9 +1373,18 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) tag = line[1] << 16 | line[2] << 8 | line[3]; switch(tag) { + case 'V' << 16 | 'e' << 8 | 'r': + tagsversion = atoi(line + 6); + addselfprovides = tagsversion < 3 || strstr(line + 6, "addselfprovides") != 0; + break; case 'P' << 16 | 'k' << 8 | 'g': if (s) - finish_solvable(pool, data, s, filelist, nfilelist); + { + if (tagsversion == 2) + finish_v2_solvable(pool, data, s, filelist, nfilelist); + if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) + s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); + } nfilelist = 0; if (split(line + 5, sp, 5) != 4) break; @@ -1153,27 +1414,44 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER); break; case 'P' << 16 | 'r' << 8 | 'v': - if (line[6] == '/') + /* version 2 had the file list at the end of the provides */ + if (tagsversion == 2) { - int l = strlen(line + 6) + 1; - if (nfilelist + l > afilelist) + if (line[6] == '/') + { + int l = strlen(line + 6) + 1; + if (nfilelist + l > afilelist) + { + afilelist = nfilelist + l + 512; + filelist = solv_realloc(filelist, afilelist); + } + memcpy(filelist + nfilelist, line + 6, l); + nfilelist += l; + break; + } + if (nfilelist) { - afilelist = nfilelist + l + 512; - filelist = solv_realloc(filelist, afilelist); + int l; + for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) + s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0); + nfilelist = 0; } - memcpy(filelist + nfilelist, line + 6, l); - nfilelist += l; - break; - } - if (nfilelist) - { - int l; - for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1) - s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0); - nfilelist = 0; } s->provides = adddep(repo, s->provides, line + 6, 0); break; + case 'F' << 16 | 'l' << 8 | 's': + { + char *p = strrchr(line + 6, '/'); + Id did; + if (!p) + break; + *p++ = 0; + did = repodata_str2dir(data, line + 6, 1); + if (!did) + did = repodata_str2dir(data, "/", 1); + repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p); + break; + } case 'O' << 16 | 'b' << 8 | 's': s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0); break; @@ -1192,12 +1470,23 @@ testcase_add_testtags(Repo *repo, FILE *fp, int flags) case 'E' << 16 | 'n' << 8 | 'h': s->enhances = adddep(repo, s->enhances, line + 6, 0); break; + case 'I' << 16 | 'p' << 8 | 'r': + { + Id id = line[6] == '/' ? pool_str2id(pool, line + 6, 1) : testcase_str2dep(pool, line + 6); + repodata_add_idarray(data, s - pool->solvables, SOLVABLE_PREREQ_IGNOREINST, id); + break; + } default: break; } } if (s) - finish_solvable(pool, data, s, filelist, nfilelist); + { + if (tagsversion == 2) + finish_v2_solvable(pool, data, s, filelist, nfilelist); + if (addselfprovides && s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) + s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); + } solv_free(line); solv_free(filelist); repodata_free_dircache(data); @@ -1306,7 +1595,11 @@ testcase_setsolverflags(Solver *solv, const char *str) pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", (int)(p - s), s); return 0; } - solver_set_flag(solv, solverflags2str[i].flag, v); + if (solver_set_flag(solv, solverflags2str[i].flag, v) == -1) + { + pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unsupported flag '%s'\n", solverflags2str[i].str); + return 0; + } } return 1; } @@ -1325,7 +1618,7 @@ testcase_ruleid(Solver *solv, Id rid) Strqueue sq; Queue q; int i; - void *chk; + Chksum *chk; const unsigned char *md5; int md5l; const char *s; @@ -1358,7 +1651,7 @@ testcase_problemid(Solver *solv, Id problem) { Strqueue sq; Queue q; - void *chk; + Chksum *chk; const unsigned char *md5; int i, md5l; const char *s; @@ -1385,7 +1678,7 @@ static const char * testcase_solutionid(Solver *solv, Id problem, Id solution) { Id intid; - void *chk; + Chksum *chk; const unsigned char *md5; int md5l; const char *s; @@ -1410,6 +1703,33 @@ testcase_solutionid(Solver *solv, Id problem, Id solution) return s; } +static const char * +testcase_alternativeid(Solver *solv, int type, Id id, Id from) +{ + const char *s; + Pool *pool = solv->pool; + Chksum *chk; + const unsigned char *md5; + int md5l; + chk = solv_chksum_create(REPOKEY_TYPE_MD5); + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + s = testcase_solvid2str(pool, from); + solv_chksum_add(chk, s, strlen(s) + 1); + s = testcase_dep2str(pool, id); + solv_chksum_add(chk, s, strlen(s) + 1); + } + else if (type == SOLVER_ALTERNATIVE_TYPE_RULE) + { + s = testcase_ruleid(solv, id); + solv_chksum_add(chk, s, strlen(s) + 1); + } + md5 = solv_chksum_get(chk, &md5l); + s = pool_bin2hex(pool, md5, 4); + chk = solv_chksum_free(chk, 0); + return s; +} + static struct class2str { Id class; const char *str; @@ -1426,6 +1746,89 @@ static struct class2str { { 0, 0 } }; +static struct reason2str { + Id reason; + const char *str; +} reason2str[] = { + { SOLVER_REASON_UNRELATED, "unrelated" }, + { SOLVER_REASON_UNIT_RULE, "unit" }, + { SOLVER_REASON_KEEP_INSTALLED, "keep" }, + { SOLVER_REASON_RESOLVE_JOB, "job" }, + { SOLVER_REASON_UPDATE_INSTALLED, "update" }, + { SOLVER_REASON_CLEANDEPS_ERASE, "cleandeps" }, + { SOLVER_REASON_RESOLVE, "resolve" }, + { SOLVER_REASON_WEAKDEP, "weakdep" }, + { SOLVER_REASON_RESOLVE_ORPHAN, "orphan" }, + + { SOLVER_REASON_RECOMMENDED, "recommended" }, + { SOLVER_REASON_SUPPLEMENTED, "supplemented" }, + { 0, 0 } +}; + +static const char * +testcase_reason2str(Id reason) +{ + int i; + for (i = 0; reason2str[i].str; i++) + if (reason == reason2str[i].reason) + return reason2str[i].str; + return "?"; +} + +static struct rclass2str { + Id rclass; + const char *str; +} rclass2str[] = { + { SOLVER_RULE_PKG, "pkg" }, + { SOLVER_RULE_UPDATE, "update" }, + { SOLVER_RULE_FEATURE, "feature" }, + { SOLVER_RULE_JOB, "job" }, + { SOLVER_RULE_DISTUPGRADE, "distupgrade" }, + { SOLVER_RULE_INFARCH, "infarch" }, + { SOLVER_RULE_CHOICE, "choice" }, + { SOLVER_RULE_LEARNT, "learnt" }, + { SOLVER_RULE_BEST, "best" }, + { SOLVER_RULE_YUMOBS, "yumobs" }, + { 0, 0 } +}; + +static const char * +testcase_rclass2str(Id rclass) +{ + int i; + for (i = 0; rclass2str[i].str; i++) + if (rclass == rclass2str[i].rclass) + return rclass2str[i].str; + return "unknown"; +} + +static int +dump_genid(Pool *pool, Strqueue *sq, Id id, int cnt) +{ + struct oplist *op; + char cntbuf[20]; + const char *s; + + if (ISRELDEP(id)) + { + Reldep *rd = GETRELDEP(pool, id); + for (op = oplist; op->flags; op++) + if (rd->flags == op->flags) + break; + cnt = dump_genid(pool, sq, rd->name, cnt); + cnt = dump_genid(pool, sq, rd->evr, cnt); + sprintf(cntbuf, "genid %2d: genid ", cnt++); + s = pool_tmpjoin(pool, cntbuf, "op ", op->flags ? op->opname : "unknown"); + } + else + { + sprintf(cntbuf, "genid %2d: genid ", cnt++); + s = pool_tmpjoin(pool, cntbuf, id ? "lit " : "null", id ? pool_id2str(pool, id) : 0); + } + strqueue_push(sq, s); + return cnt; +} + char * testcase_solverresult(Solver *solv, int resultflags) { @@ -1545,18 +1948,179 @@ testcase_solverresult(Solver *solv, int resultflags) if ((resultflags & TESTCASE_RESULT_UNNEEDED) != 0) { - Queue q; + Queue q, qf; queue_init(&q); + queue_init(&qf); solver_get_unneeded(solv, &q, 0); - for (i = 0; i < q.count; i++) + solver_get_unneeded(solv, &qf, 1); + for (i = j = 0; i < q.count; i++) { - s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0); + /* we rely on qf containing a subset of q in the same order */ + if (j < qf.count && q.elements[i] == qf.elements[j]) + { + s = pool_tmpjoin(pool, "unneeded_filtered ", testcase_solvid2str(pool, q.elements[i]), 0); + j++; + } + else + s = pool_tmpjoin(pool, "unneeded ", testcase_solvid2str(pool, q.elements[i]), 0); strqueue_push(&sq, s); } queue_free(&q); + queue_free(&qf); + } + if ((resultflags & TESTCASE_RESULT_ALTERNATIVES) != 0) + { + char *altprefix; + Queue q, rq; + int cnt; + Id alternative; + queue_init(&q); + queue_init(&rq); + cnt = solver_alternatives_count(solv); + for (alternative = 1; alternative <= cnt; alternative++) + { + Id id, from, chosen; + char num[20]; + int type = solver_get_alternative(solv, alternative, &id, &from, &chosen, &q, 0); + altprefix = solv_dupjoin("alternative ", testcase_alternativeid(solv, type, id, from), " "); + strcpy(num, " 0 "); + if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS) + { + char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, from)); + s = pool_tmpappend(pool, s, " recommends ", testcase_dep2str(pool, id)); + strqueue_push(&sq, s); + } + else if (type == SOLVER_ALTERNATIVE_TYPE_RULE) + { + /* map choice rules back to pkg rules */ + if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE) + id = solver_rule2pkgrule(solv, id); + solver_allruleinfos(solv, id, &rq); + for (i = 0; i < rq.count; i += 4) + { + int rtype = rq.elements[i]; + if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB) + { + const char *js = testcase_job2str(pool, rq.elements[i + 2], rq.elements[i + 3]); + char *s = pool_tmpjoin(pool, altprefix, num, " job "); + s = pool_tmpappend(pool, s, js, 0); + strqueue_push(&sq, s); + } + else if (rtype == SOLVER_RULE_PKG_REQUIRES) + { + char *s = pool_tmpjoin(pool, altprefix, num, testcase_solvid2str(pool, rq.elements[i + 1])); + s = pool_tmpappend(pool, s, " requires ", testcase_dep2str(pool, rq.elements[i + 3])); + strqueue_push(&sq, s); + } + } + } + for (i = 0; i < q.count; i++) + { + Id p = q.elements[i]; + if (i >= 9) + num[0] = '0' + (i + 1) / 10; + num[1] = '0' + (i + 1) % 10; + if (-p == chosen) + s = pool_tmpjoin(pool, altprefix, num, "+ "); + else if (p < 0) + s = pool_tmpjoin(pool, altprefix, num, "- "); + else if (p >= 0) + s = pool_tmpjoin(pool, altprefix, num, " "); + s = pool_tmpappend(pool, s, testcase_solvid2str(pool, p < 0 ? -p : p), 0); + strqueue_push(&sq, s); + } + solv_free(altprefix); + } + queue_free(&q); + queue_free(&rq); } + if ((resultflags & TESTCASE_RESULT_RULES) != 0) + { + /* dump all rules */ + Id rid; + SolverRuleinfo rclass; + Queue q; + int i; + queue_init(&q); + for (rid = 1; (rclass = solver_ruleclass(solv, rid)) != SOLVER_RULE_UNKNOWN; rid++) + { + char *prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " "); + prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0); + solver_ruleliterals(solv, rid, &q); + if (rclass == SOLVER_RULE_FEATURE && q.count == 1 && q.elements[0] == -SYSTEMSOLVABLE) + continue; + for (i = 0; i < q.count; i++) + { + Id p = q.elements[i]; + const char *s; + if (p < 0) + s = pool_tmpjoin(pool, prefix, " -", testcase_solvid2str(pool, -p)); + else + s = pool_tmpjoin(pool, prefix, " ", testcase_solvid2str(pool, p)); + strqueue_push(&sq, s); + } + solv_free(prefix); + } + queue_free(&q); + } + if ((resultflags & TESTCASE_RESULT_GENID) != 0) + { + for (i = 0 ; i < solv->job.count; i += 2) + { + Id id, id2; + if (solv->job.elements[i] != (SOLVER_NOOP | SOLVER_SOLVABLE_PROVIDES)) + continue; + id = solv->job.elements[i + 1]; + s = testcase_dep2str(pool, id); + strqueue_push(&sq, pool_tmpjoin(pool, "genid dep ", s, 0)); + if ((id2 = testcase_str2dep(pool, s)) != id) + { + s = pool_tmpjoin(pool, "genid roundtrip error: ", testcase_dep2str(pool, id2), 0); + strqueue_push(&sq, s); + } + dump_genid(pool, &sq, id, 1); + } + } + if ((resultflags & TESTCASE_RESULT_REASON) != 0) + { + Queue whyq; + queue_init(&whyq); + FOR_POOL_SOLVABLES(p) + { + Id info, p2, id; + int reason = solver_describe_decision(solv, p, &info); + if (reason == SOLVER_REASON_UNRELATED) + continue; + if (reason == SOLVER_REASON_WEAKDEP) + { + solver_describe_weakdep_decision(solv, p, &whyq); + if (whyq.count) + { + for (i = 0; i < whyq.count; i += 3) + { + reason = whyq.elements[i]; + p2 = whyq.elements[i + 1]; + id = whyq.elements[i + 2]; + s = pool_tmpjoin(pool, "reason ", testcase_solvid2str(pool, p), 0); + s = pool_tmpappend(pool, s, " ", testcase_reason2str(reason)); + s = pool_tmpappend(pool, s, " ", testcase_dep2str(pool, id)); + if (p2) + s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, p2)); + strqueue_push(&sq, s); + } + continue; + } + } + s = pool_tmpjoin(pool, "reason ", testcase_solvid2str(pool, p), 0); + s = pool_tmpappend(pool, s, " ", testcase_reason2str(reason)); + if (info) + s = pool_tmpappend(pool, s, " ", testcase_ruleid(solv, info)); + strqueue_push(&sq, s); + } + queue_free(&whyq); + } strqueue_sort(&sq); result = strqueue_join(&sq); strqueue_free(&sq); @@ -1564,8 +2128,8 @@ testcase_solverresult(Solver *solv, int resultflags) } -int -testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasename, const char *resultname) +static int +testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname) { Pool *pool = solv->pool; Repo *repo; @@ -1597,6 +2161,9 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam else sprintf(priobuf, "%d", repo->priority); out = pool_tmpjoin(pool, name, ".repo", ".gz"); + for (i = 0; out[i]; i++) + if (out[i] == '/') + out[i] = '_'; cmd = pool_tmpjoin(pool, "repo ", name, " "); cmd = pool_tmpappend(pool, cmd, priobuf, " "); cmd = pool_tmpappend(pool, cmd, "testtags ", out); @@ -1659,6 +2226,18 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam } } + /* dump disabled packages (must come before the namespace/job lines) */ + if (pool->considered) + { + Id p; + FOR_POOL_SOLVABLES(p) + if (!MAPTST(pool->considered, p)) + { + cmd = pool_tmpjoin(pool, "disable pkg ", testcase_solvid2str(pool, p), 0); + strqueue_push(&sq, cmd); + } + } + s = testcase_getsolverflags(solv); if (*s) { @@ -1695,7 +2274,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam strqueue_push(&sq, cmd); } - if (resultflags) + if ((resultflags & ~TESTCASE_RESULT_REUSE_SOLVER) != 0) { char *result; cmd = 0; @@ -1734,6 +2313,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n"); solv_free(result); strqueue_free(&sq); + fclose(fp); return 0; } if (fclose(fp)) @@ -1758,6 +2338,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam { pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n"); strqueue_free(&sq); + fclose(fp); return 0; } if (fclose(fp)) @@ -1771,13 +2352,59 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam return 1; } +int +testcase_write(Solver *solv, const char *dir, int resultflags, const char *testcasename, const char *resultname) +{ + Pool *pool = solv->pool; + int i, r, repoid; + int mangle = 1; + const char **orignames; + + /* mangle repo names so that there are no conflicts */ + orignames = solv_calloc(pool->nrepos, sizeof(char *)); + for (repoid = 1; repoid < pool->nrepos; repoid++) + { + Repo *repo = pool_id2repo(pool, repoid); + char *buf = solv_malloc((repo->name ? strlen(repo->name) : 0) + 40); + char *mp; + orignames[repoid] = repo->name; + if (!repo->name || !repo->name[0]) + sprintf(buf, "#%d", repoid); + else + strcpy(buf, repo->name); + for (i = 0; buf[i]; i++) + if (buf[i] == ' ' || buf[i] == '\t' || buf[i] == '/') + buf[i] = '_'; + mp = buf + strlen(buf); + for (;;) + { + for (i = 1; i < repoid; i++) + if (!strcmp(buf, pool_id2repo(pool, i)->name)) + break; + if (i == repoid) + break; + sprintf(mp, "_%d", mangle++); + } + repo->name = buf; + } + r = testcase_write_mangled(solv, dir, resultflags, testcasename, resultname); + for (repoid = 1; repoid < pool->nrepos; repoid++) + { + Repo *repo = pool_id2repo(pool, repoid); + solv_free((void *)repo->name); + repo->name = orignames[repoid]; + } + solv_free(orignames); + return r; +} + static char * read_inline_file(FILE *fp, char **bufp, char **bufpp, int *buflp) { char *result = solv_malloc(1024); char *rp = result; int resultl = 1024; - + for (;;) { size_t rl; @@ -1832,7 +2459,7 @@ read_file(FILE *fp) char *result = solv_malloc(1024); char *rp = result; int resultl = 1024; - + for (;;) { size_t rl; @@ -1877,7 +2504,7 @@ str2resultflags(Pool *pool, char *s) /* modifies the string! */ } Solver * -testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp) +testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **resultp, int *resultflagsp) { Solver *solv; char *buf, *bufp; @@ -1889,7 +2516,15 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int prepared = 0; int closefp = !fp; int poolflagsreset = 0; - + int missing_features = 0; + Id *genid = 0; + int ngenid = 0; + Queue autoinstq; + + if (resultp) + *resultp = 0; + if (resultflagsp) + *resultflagsp = 0; if (!fp && !(fp = fopen(testcase, "r"))) { pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase); @@ -1904,6 +2539,7 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, buf = solv_malloc(bufl); bufp = buf; solv = 0; + queue_init(&autoinstq); for (;;) { if (bufp - buf + 16 > bufl) @@ -1993,7 +2629,7 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, repo_add_solv(repo, rfp, 0); fclose(rfp); } -#if 0 +#if ENABLE_TESTCASE_HELIXREPO else if (!strcmp(repotype, "helix")) { repo_add_helix(repo, rfp, 0); @@ -2010,20 +2646,38 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, else if (!strcmp(pieces[0], "system") && npieces >= 3) { int i; - prepared = 0; + /* must set the disttype before the arch */ - for (i = 0; disttype2str[i].str != 0; i++) - if (!strcmp(disttype2str[i].str, pieces[2])) - break; - if (!disttype2str[i].str) - pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown disttype '%s'\n", pieces[2]); - else if (pool->disttype != disttype2str[i].type) + prepared = 0; + if (strcmp(pieces[2], "*") != 0) { + char *dp = pieces[2]; + while (dp && *dp) + { + char *dpe = strchr(dp, ','); + if (dpe) + *dpe = 0; + for (i = 0; disttype2str[i].str != 0; i++) + if (!strcmp(disttype2str[i].str, dp)) + break; + if (dpe) + *dpe++ = ','; + if (disttype2str[i].str) + { #ifdef MULTI_SEMANTICS - pool_setdisttype(pool, disttype2str[i].type); -#else - pool_debug(pool, SOLV_ERROR, "testcase_read: system: cannot change disttype to '%s'\n", pieces[2]); + if (pool->disttype != disttype2str[i].type) + pool_setdisttype(pool, disttype2str[i].type); #endif + if (pool->disttype == disttype2str[i].type) + break; + } + dp = dpe; + } + if (!(dp && *dp)) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: system: could not change disttype to '%s'\n", pieces[2]); + missing_features = 1; + } } if (strcmp(pieces[1], "unset") == 0) pool_setarch(pool, 0); @@ -2044,7 +2698,7 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, { char *sp; Id how, what; - if (!prepared) + if (prepared <= 0) { pool_addfileprovides(pool); pool_createwhatprovides(pool); @@ -2090,7 +2744,7 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, for (i = 2; i < npieces; i++) queue_push(&q, testcase_str2solvid(pool, pieces[i])); /* now do the callback */ - if (!prepared) + if (prepared <= 0) { pool_addfileprovides(pool); pool_createwhatprovides(pool); @@ -2122,22 +2776,26 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, for (i = 1; i < npieces; i++) testcase_setsolverflags(solv, pieces[i]); } - else if (!strcmp(pieces[0], "result") && npieces > 2) + else if (!strcmp(pieces[0], "result") && npieces > 1) { char *result = 0; int resultflags = str2resultflags(pool, pieces[1]); - const char *rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0); - if (!strcmp(pieces[2], "")) - result = read_inline_file(fp, &buf, &bufp, &bufl); - else + const char *rdata; + if (npieces > 2) { - FILE *rfp = fopen(rdata, "r"); - if (!rfp) - pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata); + rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0); + if (!strcmp(pieces[2], "")) + result = read_inline_file(fp, &buf, &bufp, &bufl); else { - result = read_file(rfp); - fclose(rfp); + FILE *rfp = fopen(rdata, "r"); + if (!rfp) + pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata); + else + { + result = read_file(rfp); + fclose(rfp); + } } } if (resultp) @@ -2147,15 +2805,116 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, if (resultflagsp) *resultflagsp = resultflags; } - else if (!strcmp(pieces[0], "nextjob") && npieces == 1) + else if (!strcmp(pieces[0], "nextjob")) { + if (npieces == 2 && resultflagsp && !strcmp(pieces[1], "reusesolver")) + *resultflagsp |= TESTCASE_RESULT_REUSE_SOLVER; break; } + else if (!strcmp(pieces[0], "disable") && npieces == 3) + { + Id p; + if (strcmp(pieces[1], "pkg")) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: bad disable type '%s'\n", pieces[1]); + continue; + } + if (!prepared) + pool_createwhatprovides(pool); + prepared = -1; + if (!pool->considered) + { + pool->considered = solv_calloc(1, sizeof(Map)); + map_init(pool->considered, pool->nsolvables); + map_setall(pool->considered); + } + p = testcase_str2solvid(pool, pieces[2]); + if (p) + MAPCLR(pool->considered, p); + else + pool_debug(pool, SOLV_ERROR, "disable: unknown package '%s'\n", pieces[2]); + } + else if (!strcmp(pieces[0], "feature")) + { + int i, j; + for (i = 1; i < npieces; i++) + { + for (j = 0; features[j]; j++) + if (!strcmp(pieces[i], features[j])) + break; + if (!features[j]) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: missing feature '%s'\n", pieces[i]); + missing_features++; + } + } + if (missing_features) + break; + } + else if (!strcmp(pieces[0], "genid") && npieces > 1) + { + Id id; + /* rejoin */ + if (npieces > 2) + { + char *sp; + for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++) + if (*sp == 0) + *sp = ' '; + } + genid = solv_extend(genid, ngenid, 1, sizeof(*genid), 7); + if (!strcmp(pieces[1], "op") && npieces > 2) + { + struct oplist *op; + for (op = oplist; op->flags; op++) + if (!strncmp(pieces[2], op->opname, strlen(op->opname))) + break; + if (!op->flags) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: genid: unknown op '%s'\n", pieces[2]); + break; + } + if (ngenid < 2) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: genid: out of stack\n"); + break; + } + ngenid -= 2; + id = pool_rel2id(pool, genid[ngenid] , genid[ngenid + 1], op->flags, 1); + } + else if (!strcmp(pieces[1], "lit")) + id = pool_str2id(pool, npieces > 2 ? pieces[2] : "", 1); + else if (!strcmp(pieces[1], "null")) + id = 0; + else if (!strcmp(pieces[1], "dep")) + id = testcase_str2dep(pool, pieces[2]); + else + { + pool_debug(pool, SOLV_ERROR, "testcase_read: genid: unknown command '%s'\n", pieces[1]); + break; + } + genid[ngenid++] = id; + } + else if (!strcmp(pieces[0], "autoinst") && npieces > 2) + { + if (strcmp(pieces[1], "name")) + { + pool_debug(pool, SOLV_ERROR, "testcase_read: autoinst: illegal mode\n"); + break; + } + queue_push(&autoinstq, pool_str2id(pool, pieces[2], 1)); + } else { pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]); } } + while (job && ngenid > 0) + queue_push2(job, SOLVER_NOOP | SOLVER_SOLVABLE_PROVIDES, genid[--ngenid]); + if (autoinstq.count) + pool_add_userinstalled_jobs(pool, &autoinstq, job, GET_USERINSTALLED_NAMES | GET_USERINSTALLED_INVERTED); + queue_free(&autoinstq); + genid = solv_free(genid); buf = solv_free(buf); pieces = solv_free(pieces); solv_free(testcasedir); @@ -2171,11 +2930,18 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, } if (closefp) fclose(fp); + if (missing_features) + { + solver_free(solv); + solv = 0; + if (resultflagsp) + *resultflagsp = 77; /* hack for testsolv */ + } return solv; } char * -testcase_resultdiff(char *result1, char *result2) +testcase_resultdiff(const char *result1, const char *result2) { Strqueue sq1, sq2, osq; char *r;