From b5d3813a51b1beeacf8f63dfce7b143ab997ed6b Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Tue, 21 Feb 2012 17:56:54 +0100 Subject: [PATCH] - add testsolv tool --- tools/CMakeLists.txt | 5 +- tools/testsolv.c | 108 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tools/testsolv.c diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5afb5b2c..79ef605d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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 index 00000000..be999752 --- /dev/null +++ b/tools/testsolv.c @@ -0,0 +1,108 @@ +#include +#include +#include + +#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 \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); +} -- 2.47.2