- add testsolv tool
authorMichael Schroeder <mls@suse.de>
Tue, 21 Feb 2012 16:56:54 +0000 (17:56 +0100)
committerMichael Schroeder <mls@suse.de>
Tue, 21 Feb 2012 16:56:54 +0000 (17:56 +0100)
tools/CMakeLists.txt
tools/testsolv.c [new file with mode: 0644]

index 5afb5b2..79ef605 100644 (file)
@@ -10,7 +10,7 @@ IF (ENABLE_RPMDB)
 SET (SYSTEM_LIBRARIES ${RPMDB_LIBRARY} ${SYSTEM_LIBRARIES})
 ENDIF (ENABLE_RPMDB)
 
-SET (tools_list mergesolv dumpsolv installcheck)
+SET (tools_list mergesolv dumpsolv installcheck testsolv)
 
 IF (ENABLE_RPMDB)
 ADD_EXECUTABLE (rpmdb2solv rpmdb2solv.c)
@@ -74,6 +74,9 @@ TARGET_LINK_LIBRARIES (dumpsolv libsolv)
 ADD_EXECUTABLE (mergesolv mergesolv.c )
 TARGET_LINK_LIBRARIES (mergesolv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES})
 
+ADD_EXECUTABLE (testsolv testsolv.c)
+TARGET_LINK_LIBRARIES (testsolv libsolvext libsolv ${SYSTEM_LIBRARIES})
+
 INSTALL (TARGETS ${tools_list} DESTINATION ${BIN_INSTALL_DIR})
 
 INSTALL (PROGRAMS repo2solv.sh DESTINATION ${BIN_INSTALL_DIR})
diff --git a/tools/testsolv.c b/tools/testsolv.c
new file mode 100644 (file)
index 0000000..be99975
--- /dev/null
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "pool.h"
+#include "repo.h"
+#include "solver.h"
+#include "solverdebug.h"
+#include "testcase.h"
+
+static void
+usage(ex)
+{
+  fprintf(ex ? stderr : stdout, "Usage: testsolv <testcase>\n");
+  exit(ex);
+}
+
+int
+main(int argc, char **argv)
+{
+  Pool *pool;
+  Queue job;
+  Solver *solv;
+  char *result = 0;
+  int resultflags = 0;
+  int debuglevel = 0;
+  int c;
+  int ex = 0;
+
+  while ((c = getopt(argc, argv, "vh")) >= 0)
+    {
+      switch (c)
+      {
+        case 'v':
+          debuglevel++;
+          break;
+        case 'h':
+         usage(0);
+          break;
+        default:
+         usage(1);
+          break;
+      }
+    }
+  if (optind == argc)
+    usage(1);
+  for (; optind < argc; optind++)
+    {
+      pool = pool_create();
+      pool_setdebuglevel(pool, debuglevel);
+      queue_init(&job);
+      solv = testcase_read(pool, 0, argv[optind], &job, &result, &resultflags);
+      if (!solv)
+       {
+         pool_free(pool);
+         exit(1);
+       }
+
+      if (result)
+       {
+         char *myresult, *resultdiff;
+         solver_solve(solv, &job);
+         myresult = testcase_solverresult(solv, resultflags);
+         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
+       {
+         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);
+      pool_free(pool);
+    }
+  exit(ex);
+}