]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
add support for id generation to testcase.c
authorMichael Schroeder <mls@suse.de>
Mon, 23 Mar 2015 11:45:59 +0000 (12:45 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 23 Mar 2015 11:45:59 +0000 (12:45 +0100)
This will be used to unit test testcase_dep2str and testcase_str2dep.

ext/repo_deb.c
ext/testcase.c
ext/testcase.h
tools/testsolv.c

index 05d731b3d00cc76b17c07c2d16ff33c1c89f8b88..26c73b0feac774c9c4f96ec0c8d0b401cb2a5f31 100644 (file)
@@ -655,7 +655,9 @@ pool_deb_get_autoinstalled(Pool *pool, FILE *fp, Queue *q, int flags)
          l = 0;
          if (name && autoinstalled > 0)
            {
-             if ((flags & GET_USERINSTALLED_NAMES) != 0)
+             if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
+               queue_push2(q, name, arch);
+             else if ((flags & GET_USERINSTALLED_NAMES) != 0)
                queue_push(q, name);
              else
                {
index 8da4ca66efdd3cff24e62423b07db06c01fc5fb8..4f6fc6d79c5573dbb6eed6b1dbed0b57aaa0111b 100644 (file)
@@ -79,6 +79,7 @@ static struct resultflags2str {
   { TESTCASE_RESULT_UNNEEDED,          "unneeded" },
   { TESTCASE_RESULT_ALTERNATIVES,      "alternatives" },
   { TESTCASE_RESULT_RULES,             "rules" },
+  { TESTCASE_RESULT_GENID,             "genid" },
   { 0, 0 }
 };
 
@@ -1678,6 +1679,33 @@ static struct class2str {
   { 0, 0 }
 };
 
+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)
 {
@@ -1950,7 +1978,24 @@ testcase_solverresult(Solver *solv, int resultflags)
        }
       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);
+       }
+    }
   strqueue_sort(&sq);
   result = strqueue_join(&sq);
   strqueue_free(&sq);
@@ -2298,6 +2343,8 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
   int closefp = !fp;
   int poolflagsreset = 0;
   int missing_features = 0;
+  Id *genid = 0;
+  int ngenid = 0;
 
   if (!fp && !(fp = fopen(testcase, "r")))
     {
@@ -2605,11 +2652,58 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
          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, 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
        {
          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]);
+  genid = solv_free(genid);
   buf = solv_free(buf);
   pieces = solv_free(pieces);
   solv_free(testcasedir);
index d85153af36e2ebd6cf03ba6e1a3fe298374ada0f..78f78b02b187b04b72ef4410329b4993f1bbef7c 100644 (file)
@@ -16,6 +16,7 @@
 #define TESTCASE_RESULT_UNNEEDED       (1 << 4)
 #define TESTCASE_RESULT_ALTERNATIVES   (1 << 5)
 #define TESTCASE_RESULT_RULES          (1 << 6)
+#define TESTCASE_RESULT_GENID          (1 << 7)
 
 extern Id testcase_str2dep(Pool *pool, const char *s);
 extern const char *testcase_dep2str(Pool *pool, Id id);
index 12829220f4946b14bb8871f49f6b88a0d838fd96..428688f42fe00ca0cf849c3ade75e7f6096efe16 100644 (file)
@@ -18,6 +18,9 @@ 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" },
   { 0, 0 }
 };