- support testcases with multiple solver jobs
authorMichael Schroeder <mls@suse.de>
Wed, 22 Feb 2012 12:26:30 +0000 (13:26 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 22 Feb 2012 12:26:30 +0000 (13:26 +0100)
ext/testcase.c
tools/testsolv.c

index 287c2a64b8f954b045e830d8186f8cba90a61aa7..480577593f3cee619c8abf69f34027d9d745c641 100644 (file)
@@ -1787,6 +1787,10 @@ testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp,
                *resultflagsp = resultflags;
            }
        }
+      else if (!strcmp(pieces[0], "nextjob") && npieces == 1)
+       {
+         break;
+       }
       else
        {
          pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
index be99975226d852ceaad4acc581090bb797cb8e5a..8221190406e95726f0b80de65f3103eb90d92453 100644 (file)
@@ -24,16 +24,22 @@ main(int argc, char **argv)
   char *result = 0;
   int resultflags = 0;
   int debuglevel = 0;
+  int writeresult = 0;
+  int multijob = 0;
   int c;
   int ex = 0;
+  FILE *fp;
 
-  while ((c = getopt(argc, argv, "vh")) >= 0)
+  while ((c = getopt(argc, argv, "vrh")) >= 0)
     {
       switch (c)
       {
         case 'v':
           debuglevel++;
           break;
+        case 'r':
+          writeresult++;
+          break;
         case 'h':
          usage(0);
           break;
@@ -48,60 +54,101 @@ main(int argc, char **argv)
     {
       pool = pool_create();
       pool_setdebuglevel(pool, debuglevel);
-      queue_init(&job);
-      solv = testcase_read(pool, 0, argv[optind], &job, &result, &resultflags);
-      if (!solv)
+
+      fp = fopen(argv[optind], "r");
+      if (!fp)
        {
-         pool_free(pool);
-         exit(1);
+         perror(argv[optind]);
+         exit(0);
        }
-
-      if (result)
+      while(!feof(fp))
        {
-         char *myresult, *resultdiff;
-         solver_solve(solv, &job);
-         myresult = testcase_solverresult(solv, resultflags);
-         resultdiff = testcase_resultdiff(result, myresult);
-         if (resultdiff)
+         queue_init(&job);
+         result = 0;
+         resultflags = 0;
+         solv = testcase_read(pool, fp, argv[optind], &job, &result, &resultflags);
+         if (!solv)
            {
-             printf("Results differ:\n%s", resultdiff);
-             ex = 1;
-             solv_free(resultdiff);
+             pool_free(pool);
+             exit(1);
            }
-         solv_free(result);
-         solv_free(myresult);
-       }
-      else
-       {
-         if (solver_solve(solv, &job))
+
+         if (!multijob && !feof(fp))
+           multijob = 1;
+
+         if (multijob)
+           printf("test %d:\n", multijob++);
+         if (result || writeresult)
            {
-             int problem, solution, pcnt, scnt;
-             pcnt = solver_problem_count(solv);
-             printf("Found %d problems:\n", pcnt);
-             for (problem = 1; problem <= pcnt; problem++)
+             char *myresult, *resultdiff;
+             solver_solve(solv, &job);
+             if (!resultflags)
+               resultflags = TESTCASE_RESULT_TRANSACTION | TESTCASE_RESULT_PROBLEMS;
+             myresult = testcase_solverresult(solv, resultflags);
+             if (writeresult)
                {
-                 printf("Problem %d:\n", problem);
-                 solver_printprobleminfo(solv, problem);
-                 printf("\n");
-                 scnt = solver_solution_count(solv, problem);
-                 for (solution = 1; solution <= scnt; solution++)
+                 if (*myresult)
                    {
-                     printf("Solution %d:\n", solution);
-                     solver_printsolution(solv, problem, solution);
-                     printf("\n");
+                     if (writeresult > 1)
+                       {
+                         char *p = myresult;
+                         while (*p)
+                           {
+                             char *p2 = strchr(p, '\n');
+                             p2 = p2 ? p2 + 1 : p + strlen(p);
+                             printf("#>%.*s", p2 - p, p);
+                             p = p2;
+                           }
+                       }
+                     else
+                       printf("%s", myresult);
                    }
                }
+             else
+               {
+                 resultdiff = testcase_resultdiff(result, myresult);
+                 if (resultdiff)
+                   {
+                     printf("Results differ:\n%s", resultdiff);
+                     ex = 1;
+                     solv_free(resultdiff);
+                   }
+               }
+             solv_free(result);
+             solv_free(myresult);
            }
          else
            {
-             Transaction *trans = solver_create_transaction(solv);
-             printf("Transaction summary:\n\n");
-             transaction_print(trans);
-             transaction_free(trans);
+             if (solver_solve(solv, &job))
+               {
+                 int problem, solution, pcnt, scnt;
+                 pcnt = solver_problem_count(solv);
+                 printf("Found %d problems:\n", pcnt);
+                 for (problem = 1; problem <= pcnt; problem++)
+                   {
+                     printf("Problem %d:\n", problem);
+                     solver_printprobleminfo(solv, problem);
+                     printf("\n");
+                     scnt = solver_solution_count(solv, problem);
+                     for (solution = 1; solution <= scnt; solution++)
+                       {
+                         printf("Solution %d:\n", solution);
+                         solver_printsolution(solv, problem, solution);
+                         printf("\n");
+                       }
+                   }
+               }
+             else
+               {
+                 Transaction *trans = solver_create_transaction(solv);
+                 printf("Transaction summary:\n\n");
+                 transaction_print(trans);
+                 transaction_free(trans);
+               }
            }
+         queue_free(&job);
+         solver_free(solv);
        }
-      queue_free(&job);
-      solver_free(solv);
       pool_free(pool);
     }
   exit(ex);