refactor testcase_str2dep
[platform/upstream/libsolv.git] / ext / testcase.c
index 7081f9d..a1c8ee6 100644 (file)
 #include "poolarch.h"
 #include "poolvendor.h"
 #include "repo.h"
-#include "repo_susetags.h"
 #include "repo_solv.h"
 #include "solver.h"
 #include "solverdebug.h"
 #include "chksum.h"
 #include "testcase.h"
+#include "selection.h"
 #include "solv_xfopen.h"
 
 #define DISABLE_JOIN2
@@ -38,7 +38,8 @@ static struct job2str {
   { SOLVER_ERASE,         "erase" },
   { SOLVER_UPDATE,        "update" },
   { SOLVER_WEAKENDEPS,    "weakendeps" },
-  { SOLVER_NOOBSOLETES,   "noobsoletes" },
+  { SOLVER_MULTIVERSION,  "multiversion" },
+  { SOLVER_MULTIVERSION,  "noobsoletes" },     /* old name */
   { SOLVER_LOCK,          "lock" },
   { SOLVER_DISTUPGRADE,   "distupgrade" },
   { SOLVER_VERIFY,        "verify" },
@@ -54,6 +55,9 @@ static struct jobflags2str {
   { SOLVER_WEAK,      "weak" },
   { SOLVER_ESSENTIAL, "essential" },
   { SOLVER_CLEANDEPS, "cleandeps" },
+  { SOLVER_ORUPDATE,  "orupdate" },
+  { SOLVER_FORCEBEST, "forcebest" },
+  { SOLVER_TARGETED,  "targeted" },
   { SOLVER_SETEV,     "setev" },
   { SOLVER_SETEVR,    "setevr" },
   { SOLVER_SETARCH,   "setarch" },
@@ -81,6 +85,7 @@ static struct solverflags2str {
   int def;
 } solverflags2str[] = {
   { SOLVER_FLAG_ALLOW_DOWNGRADE,            "allowdowngrade", 0 },
+  { SOLVER_FLAG_ALLOW_NAMECHANGE,           "allownamechange", 1 },
   { SOLVER_FLAG_ALLOW_ARCHCHANGE,           "allowarchchange", 0 },
   { SOLVER_FLAG_ALLOW_VENDORCHANGE,         "allowvendorchange", 0 },
   { SOLVER_FLAG_ALLOW_UNINSTALL,            "allowuninstall", 0 },
@@ -89,6 +94,9 @@ static struct solverflags2str {
   { SOLVER_FLAG_IGNORE_RECOMMENDED,         "ignorerecommended", 0 },
   { SOLVER_FLAG_ADD_ALREADY_RECOMMENDED,    "addalreadyrecommended", 0 },
   { SOLVER_FLAG_NO_INFARCHCHECK,            "noinfarchcheck", 0 },
+  { SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES,    "keepexplicitobsoletes", 0 },
+  { SOLVER_FLAG_BEST_OBEY_POLICY,           "bestobeypolicy", 0 },
+  { SOLVER_FLAG_NO_AUTOTARGET,              "noautotarget", 0 },
   { 0, 0, 0 }
 };
 
@@ -102,11 +110,44 @@ static struct poolflags2str {
   { POOL_FLAG_OBSOLETEUSESPROVIDES,         "obsoleteusesprovides", 0 },
   { POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES, "implicitobsoleteusesprovides", 0 },
   { POOL_FLAG_OBSOLETEUSESCOLORS,           "obsoleteusescolors", 0 },
+  { POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS,   "implicitobsoleteusescolors", 0 },
   { POOL_FLAG_NOINSTALLEDOBSOLETES,         "noinstalledobsoletes", 0 },
   { POOL_FLAG_HAVEDISTEPOCH,                "havedistepoch", 0 },
+  { POOL_FLAG_NOOBSOLETESMULTIVERSION,      "noobsoletesmultiversion", 0 },
+  { POOL_FLAG_ADDFILEPROVIDESFILTERED,      "addfileprovidesfiltered", 0 },
   { 0, 0, 0 }
 };
 
+static struct disttype2str {
+  Id type;
+  const char *str;
+} disttype2str[] = {
+  { DISTTYPE_RPM,  "rpm" },
+  { DISTTYPE_DEB,  "deb" },
+  { DISTTYPE_ARCH, "arch" },
+  { DISTTYPE_HAIKU, "haiku" },
+  { 0, 0 }
+};
+
+static struct selflags2str {
+  Id flag;
+  const char *str;
+} selflags2str[] = {
+  { SELECTION_NAME, "name" },
+  { SELECTION_PROVIDES, "provides" },
+  { SELECTION_FILELIST, "filelist" },
+  { SELECTION_CANON, "canon" },
+  { SELECTION_DOTARCH, "dotarch" },
+  { SELECTION_REL, "rel" },
+  { SELECTION_INSTALLED_ONLY, "installedonly" },
+  { SELECTION_GLOB, "glob" },
+  { SELECTION_FLAT, "flat" },
+  { SELECTION_NOCASE, "nocase" },
+  { SELECTION_SOURCE_ONLY, "sourceonly" },
+  { SELECTION_WITH_SOURCE, "withsource" },
+  { 0, 0 }
+};
+
 
 typedef struct strqueue {
   char **str;
@@ -246,21 +287,14 @@ pool_isknownarch(Pool *pool, Id id)
   return 1;
 }
 
-Id
-testcase_str2dep(Pool *pool, char *s)
+static Id
+testcase_str2dep_simple(Pool *pool, const char **sp)
 {
-  char *n, *a;
-  Id id;
+  const char *s = *sp;
+  const 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;
-    }
   while (*s == ' ' || *s == '\t')
     s++;
   n = s;
@@ -270,9 +304,9 @@ testcase_str2dep(Pool *pool, char *s)
        {
          while (*s && *s != ')')
            s++;
+         continue;
        }
-      else
-        s++;
+      s++;
     }
   if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')')
     {
@@ -285,32 +319,91 @@ testcase_str2dep(Pool *pool, char *s)
       else
         id = pool_strn2id(pool, n, s - n, 1);
     }
+  else if (s - n > 4 && s[-4] == ':' && !strncmp(s - 4, ":any", 4))
+    {
+      id = pool_strn2id(pool, n, s - n - 4, 1);
+      id = pool_rel2id(pool, id, ARCH_ANY, REL_MULTIARCH, 1);
+    }
   else
     id = pool_strn2id(pool, n, s - n, 1);
   if (!*s)
-    return id;
+    {
+      *sp = 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;
+       flags |= REL_LT;
       else if (*s == '=')
-        flags |= REL_EQ;
+       flags |= REL_EQ;
       else if (*s == '>')
-        flags |= REL_GT;
+       flags |= REL_GT;
       else
-        break;
+       break;
     }
   if (!flags)
-    return id;
+    {
+      *sp = s;
+      return id;
+    }
   while (*s == ' ' || *s == '\t')
     s++;
   n = s;
   while (*s && *s != ' ' && *s != '\t')
     s++;
-  return pool_rel2id(pool, id, pool_strn2id(pool, n, s - n, 1), flags, 1);
+  evr = pool_strn2id(pool, n, s - n, 1);
+  if (*s == ' ' && !strcmp(s, " compat >= "))
+    {
+      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);
+    }
+  *sp = s;
+  return pool_rel2id(pool, id, evr, flags, 1);
+}
+
+static Id
+testcase_str2dep_complex(Pool *pool, const char **sp)
+{
+  const char *s = *sp;
+  Id id;
+  id = testcase_str2dep_simple(pool, &s);
+  if (*s == '|')
+    {
+      s++;
+      id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1);
+    }
+  else if (*s == '&')
+    {
+      s++;
+      id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1);
+    }
+  else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t'))
+    {
+      s += 2;
+      id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1);
+    }
+  *sp = s;
+  return id;
+}
+
+Id
+testcase_str2dep(Pool *pool, const char *s)
+{
+  return testcase_str2dep_complex(pool, &s);
 }
 
 const char *
@@ -338,12 +431,16 @@ const char *
 testcase_solvid2str(Pool *pool, Id p)
 {
   Solvable *s = pool->solvables + p;
-  const char *str;
-  char buf[20];
+  const char *n, *e, *a;
+  char *str, buf[20];
 
   if (p == SYSTEMSOLVABLE)
     return "@SYSTEM";
-  str = pool_solvid2str(pool, 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);
   if (!s->repo)
     return pool_tmpappend(pool, str, "@", 0);
   if (s->repo->name)
@@ -542,6 +639,50 @@ testcase_job2str(Pool *pool, Id how, Id what)
   return ret;
 }
 
+static int
+str2selflags(Pool *pool, char *s)      /* modifies the string! */
+{
+  int i, selflags = 0;
+  while (s)
+    {
+      char *se = strchr(s, ',');
+      if (se)
+       *se++ = 0;
+      for (i = 0; selflags2str[i].str; i++)
+       if (!strcmp(s, selflags2str[i].str))
+         {
+           selflags |= selflags2str[i].flag;
+           break;
+         }
+      if (!selflags2str[i].str)
+       pool_debug(pool, SOLV_ERROR, "str2job: unknown selection flag '%s'\n", s);
+      s = se;
+    }
+  return selflags;
+}
+
+static int
+str2jobflags(Pool *pool, char *s)      /* modifies the string */
+{
+  int i, jobflags = 0;
+  while (s)
+    {
+      char *se = strchr(s, ',');
+      if (se)
+       *se++ = 0;
+      for (i = 0; jobflags2str[i].str; i++)
+       if (!strcmp(s, jobflags2str[i].str))
+         {
+           jobflags |= jobflags2str[i].flag;
+           break;
+         }
+      if (!jobflags2str[i].str)
+       pool_debug(pool, SOLV_ERROR, "str2job: unknown job flag '%s'\n", s);
+      s = se;
+    }
+  return jobflags;
+}
+
 Id
 testcase_str2job(Pool *pool, const char *str, Id *whatp)
 {
@@ -572,7 +713,8 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
   if (npieces < 3)
     {
       pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
-      return 0;
+      solv_free(pieces);
+      return -1;
     }
 
   for (i = 0; job2str[i].str; i++)
@@ -581,34 +723,20 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
   if (!job2str[i].str)
     {
       pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
-      return 0;
+      solv_free(pieces);
+      return -1;
     }
   job = job2str[i].job;
+  what = 0;
   if (npieces > 3)
     {
       char *flags = pieces[npieces - 1];
-      char *nf;
       if (*flags == '[' && flags[strlen(flags) - 1] == ']')
        {
          npieces--;
          flags++;
-         flags[strlen(flags) - 1] = ',';
-         while (*flags)
-           {
-             for (nf = flags; *nf != ','; nf++)
-               ;
-             *nf++ = 0;
-             for (i = 0; jobflags2str[i].str; i++)
-               if (!strcmp(flags, jobflags2str[i].str))
-                 break;
-             if (!jobflags2str[i].str)
-               {
-                 pool_debug(pool, SOLV_ERROR, "str2job: unknown jobflags in '%s'\n", str);
-                 return 0;
-               }
-             job |= jobflags2str[i].flag;
-             flags = nf;
-           }
+         flags[strlen(flags) - 1] = 0;
+         job |= str2jobflags(pool, flags);
        }
     }
   if (!strcmp(pieces[1], "pkg"))
@@ -616,14 +744,16 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
       if (npieces != 3)
        {
          pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
-         return 0;
+         solv_free(pieces);
+         return -1;
        }
       job |= SOLVER_SOLVABLE;
       what = testcase_str2solvid(pool, pieces[2]);
       if (!what)
        {
          pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
-         return 0;
+         solv_free(pieces);
+         return -1;
        }
     }
   else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
@@ -633,7 +763,25 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
       for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
        if (*sp == 0)
          *sp = ' ';
-      what = testcase_str2dep(pool, pieces[2]);
+      what = 0;
+      if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
+       {
+         char *spe = strchr(pieces[2], '(');
+         int l = strlen(pieces[2]);
+         if (spe && pieces[2][l - 1] == ')')
+           {
+             /* special namespace provides */
+             if (strcmp(spe, "(<NULL>)") != 0)
+               {
+                 pieces[2][l - 1] = 0;
+                 what = testcase_str2dep(pool, spe + 1);
+                 pieces[2][l - 1] = ')';
+               }
+             what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
+           }
+       }
+      if (!what)
+        what = testcase_str2dep(pool, pieces[2]);
       if (pieces[1][0] == 'n')
        job |= SOLVER_SOLVABLE_NAME;
       else
@@ -653,7 +801,8 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
                {
                  pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
                  queue_free(&q);
-                 return 0;
+                 solv_free(pieces);
+                 return -1;
                }
              queue_push(&q, p);
            }
@@ -667,13 +816,15 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
       if (npieces != 3)
        {
          pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
-         return 0;
+         solv_free(pieces);
+         return -1;
        }
       repo = testcase_str2repo(pool, pieces[2]);
       if (!repo)
        {
          pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
-         return 0;
+         solv_free(pieces);
+         return -1;
        }
       job |= SOLVER_SOLVABLE_REPO;
       what = repo->repoid;
@@ -683,7 +834,8 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
       if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
        {
          pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
-         return 0;
+         solv_free(pieces);
+         return -1;
        }
       job |= SOLVER_SOLVABLE_ALL;
       what = 0;
@@ -691,12 +843,56 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
   else
     {
       pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
-      return 0;
+      solv_free(pieces);
+      return -1;
     }
   *whatp = what;
+  solv_free(pieces);
   return job;
 }
 
+int
+addselectionjob(Pool *pool, char **pieces, int npieces, Queue *jobqueue)
+{
+  Id job;
+  int i, r;
+  int selflags;
+  Queue sel;
+
+  for (i = 0; job2str[i].str; i++)
+    if (!strcmp(pieces[0], job2str[i].str))
+      break;
+  if (!job2str[i].str)
+    {
+      pool_debug(pool, SOLV_ERROR, "selstr2job: unknown job '%s'\n", pieces[0]);
+      return -1;
+    }
+  job = job2str[i].job;
+  if (npieces > 3)
+    {
+      char *flags = pieces[npieces - 1];
+      if (*flags == '[' && flags[strlen(flags) - 1] == ']')
+       {
+         npieces--;
+         flags++;
+         flags[strlen(flags) - 1] = 0;
+         job |= str2jobflags(pool, flags);
+       }
+    }
+  if (npieces < 4)
+    {
+      pool_debug(pool, SOLV_ERROR, "selstr2job: no selection flags\n");
+      return -1;
+    }
+  selflags = str2selflags(pool, pieces[3]);
+  queue_init(&sel);
+  r = selection_make(pool, &sel, pieces[2], selflags);
+  for (i = 0; i < sel.count; i += 2)
+    queue_push2(jobqueue, job | sel.elements[i], sel.elements[i + 1]);
+  queue_free(&sel);
+  return r;
+}
+
 static void
 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
 {
@@ -822,7 +1018,7 @@ writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off
 }
 
 int
-testcase_write_susetags(Repo *repo, FILE *fp)
+testcase_write_testtags(Repo *repo, FILE *fp)
 {
   Pool *pool = repo->pool;
   Solvable *s;
@@ -877,15 +1073,15 @@ finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfi
   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);
@@ -899,7 +1095,7 @@ finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfi
 
 /* stripped down version of susetags parser used for testcases */
 int
-testcase_add_susetags(Repo *repo, FILE *fp, int flags)
+testcase_add_testtags(Repo *repo, FILE *fp, int flags)
 {
   Pool *pool = repo->pool;
   char *line, *linep;
@@ -935,7 +1131,7 @@ testcase_add_susetags(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)
        {
@@ -1166,7 +1362,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;
@@ -1199,7 +1395,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;
@@ -1226,7 +1422,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;
@@ -1440,7 +1636,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
       out = pool_tmpjoin(pool, name, ".repo", ".gz");
       cmd = pool_tmpjoin(pool, "repo ", name, " ");
       cmd = pool_tmpappend(pool, cmd, priobuf, " ");
-      cmd = pool_tmpappend(pool, cmd, "susetags ", out);
+      cmd = pool_tmpappend(pool, cmd, "testtags ", out);
       strqueue_push(&sq, cmd);
       out = pool_tmpjoin(pool, dir, "/", out);
       if (!(fp = solv_xfopen(out, "w")))
@@ -1449,7 +1645,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
          strqueue_free(&sq);
          return 0;
        }
-      testcase_write_susetags(repo, fp);
+      testcase_write_testtags(repo, fp);
       if (fclose(fp))
        {
          pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
@@ -1459,7 +1655,7 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
     }
   /* hmm, this is not optimal... we currently search for the lowest score */
   lowscore = 0;
-  arch = ARCH_NOARCH;
+  arch = pool->solvables[SYSTEMSOLVABLE].arch;
   for (i = 0; i < pool->lastarch; i++)
     {
       if (pool->id2arch[i] == 1 && !lowscore)
@@ -1470,7 +1666,11 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
          lowscore = pool->id2arch[i];
        }
     }
-  cmd = pool_tmpjoin(pool, "system ", pool_id2str(pool, arch), pool->disttype == DISTTYPE_DEB ? " deb" : " rpm");
+  cmd = pool_tmpjoin(pool, "system ", pool->lastarch ? pool_id2str(pool, arch) : "unset", 0);
+  for (i = 0; disttype2str[i].str != 0; i++)
+    if (pool->disttype == disttype2str[i].type)
+      break;
+  pool_tmpappend(pool, cmd, " ", disttype2str[i].str ? disttype2str[i].str : "unknown");
   if (pool->installed)
     cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
   strqueue_push(&sq, cmd);
@@ -1513,8 +1713,9 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
          Reldep *rd = pool->rels + rid;
          if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
            continue;
-         /* check if we evaluated it, also skip empty results */
-         if (!(d = pool->whatprovides_rel[rid]) || !pool->whatprovidesdata[d])
+         /* evaluate all namespace ids, skip empty results */
+         d = pool_whatprovides(pool, MAKERELDEP(rid));
+         if (!d || !pool->whatprovidesdata[d])
            continue;
          cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
          cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
@@ -1570,6 +1771,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))
@@ -1594,6 +1796,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))
@@ -1607,6 +1810,111 @@ testcase_write(Solver *solv, char *dir, int resultflags, const char *testcasenam
   return 1;
 }
 
+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;
+      if (rp - result + 256 >= resultl)
+       {
+         resultl = rp - result;
+         result = solv_realloc(result, resultl + 1024);
+         rp = result + resultl;
+         resultl += 1024;
+       }
+      if (!fgets(rp, resultl - (rp - result), fp))
+       *rp = 0;
+      rl = strlen(rp);
+      if (rl && (rp == result || rp[-1] == '\n'))
+       {
+         if (rl > 1 && rp[0] == '#' && rp[1] == '>')
+           {
+             memmove(rp, rp + 2, rl - 2);
+             rl -= 2;
+           }
+         else
+           {
+             while (rl + 16 > *buflp)
+               {
+                 *bufp = solv_realloc(*bufp, *buflp + 512);
+                 *buflp += 512;
+               }
+             memmove(*bufp, rp, rl);
+             if ((*bufp)[rl - 1] == '\n')
+               {
+                 ungetc('\n', fp);
+                 rl--;
+               }
+             (*bufp)[rl] = 0;
+             (*bufpp) = *bufp + rl;
+             rl = 0;
+           }
+       }
+      if (rl <= 0)
+       {
+         *rp = 0;
+         break;
+       }
+      rp += rl;
+    }
+  return result;
+}
+
+static char *
+read_file(FILE *fp)
+{
+  char *result = solv_malloc(1024);
+  char *rp = result;
+  int resultl = 1024;
+
+  for (;;)
+    {
+      size_t rl;
+      if (rp - result + 256 >= resultl)
+       {
+         resultl = rp - result;
+         result = solv_realloc(result, resultl + 1024);
+         rp = result + resultl;
+         resultl += 1024;
+       }
+      rl = fread(rp, 1, resultl - (rp - result), fp);
+      if (rl <= 0)
+       {
+         *rp = 0;
+         break;
+       }
+      rp += rl;
+    }
+  return result;
+}
+
+static int
+str2resultflags(Pool *pool, char *s)   /* modifies the string! */
+{
+  int i, resultflags = 0;
+  while (s)
+    {
+      char *se = strchr(s, ',');
+      if (se)
+       *se++ = 0;
+      for (i = 0; resultflags2str[i].str; i++)
+       if (!strcmp(s, resultflags2str[i].str))
+         {
+           resultflags |= resultflags2str[i].flag;
+           break;
+         }
+      if (!resultflags2str[i].str)
+       pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
+      s = se;
+    }
+  return resultflags;
+}
+
 Solver *
 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
 {
@@ -1698,21 +2006,40 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
           repo->subpriority = subprio;
          if (strcmp(pieces[3], "empty") != 0)
            {
-             rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
-             if ((rfp = solv_xfopen(rdata, "r")) == 0)
+             const char *repotype = pool_tmpjoin(pool, pieces[3], 0, 0);       /* gets overwritten in <inline> case */
+             if (!strcmp(pieces[4], "<inline>"))
+               {
+                 char *idata = read_inline_file(fp, &buf, &bufp, &bufl);
+                 rdata = "<inline>";
+                 rfp = solv_xfopen_buf(rdata, &idata, 0, "rf");
+               }
+             else
+               {
+                 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
+                 rfp = solv_xfopen(rdata, "r");
+               }
+             if (!rfp)
                {
                  pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
                }
-             else if (!strcmp(pieces[3], "susetags"))
+             else if (!strcmp(repotype, "testtags"))
                {
-                 testcase_add_susetags(repo, rfp, 0);
+                 testcase_add_testtags(repo, rfp, 0);
                  fclose(rfp);
                }
-             else if (!strcmp(pieces[3], "solv"))
+             else if (!strcmp(repotype, "solv"))
                {
                  repo_add_solv(repo, rfp, 0);
                  fclose(rfp);
                }
+#if 0
+             else if (!strcmp(repotype, "helix"))
+               {
+                 extern int repo_add_helix(Repo *repo, FILE *fp, int flags);
+                 repo_add_helix(repo, rfp, 0);
+                 fclose(rfp);
+               }
+#endif
              else
                {
                  fclose(rfp);
@@ -1722,8 +2049,28 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
        }
       else if (!strcmp(pieces[0], "system") && npieces >= 3)
        {
+         int i;
          prepared = 0;
-         pool_setarch(pool, pieces[1]);
+         /* 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)
+           {
+#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]);
+#endif
+           }
+         if (strcmp(pieces[1], "unset") == 0)
+           pool_setarch(pool, 0);
+         else if (pieces[1][0] == ':')
+           pool_setarchpolicy(pool, pieces[1] + 1);
+         else
+           pool_setarch(pool, pieces[1]);
          if (npieces > 3)
            {
              Repo *repo = testcase_str2repo(pool, pieces[3]);
@@ -1743,6 +2090,11 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
              pool_createwhatprovides(pool);
              prepared = 1;
            }
+         if (npieces >= 3 && !strcmp(pieces[2], "selection"))
+           {
+             addselectionjob(pool, pieces + 1, npieces - 1, job);
+             continue;
+           }
          /* rejoin */
          for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
            if (*sp == 0)
@@ -1812,103 +2164,28 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
         }
       else if (!strcmp(pieces[0], "result") && npieces > 2)
        {
-         FILE *rfp;
-         const char *rdata;
-         int resultflags = 0;
-          char *s = pieces[1];
-         int i;
-         while (s)
-           {
-             char *se = strchr(s, ',');
-             if (se)
-               *se++ = 0;
-             for (i = 0; resultflags2str[i].str; i++)
-               if (!strcmp(s, resultflags2str[i].str))
-                 {
-                   resultflags |= resultflags2str[i].flag;
-                   break;
-                 }
-             if (!resultflags2str[i].str)
-               pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
-             s = se;
-           }
-
-         rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
+         char *result = 0;
+         int resultflags = str2resultflags(pool, pieces[1]);
+         const char *rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
          if (!strcmp(pieces[2], "<inline>"))
-           rfp = fp;
-         else
-            rfp = fopen(rdata, "r");
-          if (!rfp)
-           {
-             pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
-           }
+           result = read_inline_file(fp, &buf, &bufp, &bufl);
          else
            {
-             /* slurp it in... */
-             char *result = solv_malloc(1024);
-             char *rp = result;
-             int resultl = 1024;
-             for (;;)
+              FILE *rfp = fopen(rdata, "r");
+             if (!rfp)
+               pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
+             else
                {
-                 size_t rl;
-                 if (rp - result + 256 >= resultl)
-                   {
-                     resultl = rp - result;
-                     result = solv_realloc(result, resultl + 1024);
-                     rp = result + resultl;
-                     resultl += 1024;
-                   }
-                 if (fp == rfp)
-                   {
-                     if (!fgets(rp, resultl - (rp - result), fp))
-                       rl = 0;
-                     else
-                       {
-                         rl = strlen(rp);
-                         if (rl && (rp == result || rp[-1] == '\n'))
-                           {
-                             if (rl > 1 && rp[0] == '#' && rp[1] == '>')
-                               {
-                                 memmove(rp, rp + 2, rl - 2);
-                                 rl -= 2;
-                               }
-                             else
-                               {
-                                 while (rl + 16 > bufl)
-                                   {
-                                     buf = solv_realloc(buf, bufl + 512);
-                                     bufl += 512;
-                                   }
-                                 memmove(buf, rp, rl);
-                                 if (buf[rl - 1] == '\n')
-                                   {
-                                     ungetc('\n', fp);
-                                     rl--;
-                                   }
-                                 bufp = buf + rl;
-                                 rl = 0;
-                               }
-                           }
-                       }
-                   }
-                 else
-                   rl = fread(rp, 1, resultl - (rp - result), rfp);
-                 if (rl <= 0)
-                   {
-                     *rp = 0;
-                     break;
-                   }
-                 rp += rl;
+                 result = read_file(rfp);
+                 fclose(rfp);
                }
-             if (rfp != fp)
-               fclose(rfp);
-             if (resultp)
-               *resultp = result;
-             else
-               solv_free(result);
-             if (resultflagsp)
-               *resultflagsp = resultflags;
            }
+         if (resultp)
+           *resultp = result;
+         else
+           solv_free(result);
+         if (resultflagsp)
+           *resultflagsp = resultflags;
        }
       else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
        {