diff options
author | Michael Schroeder <mls@suse.de> | 2012-06-22 11:53:38 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2012-06-22 11:53:38 +0200 |
commit | a4e2caaeae654b8ba5142b53e0c3cb753c6fb4c4 (patch) | |
tree | 4144c4e0a97bd36ab604df02b39ce2f9cb644171 /tools | |
parent | d39a42bdbca382fe332b4114484d61ab5afafe24 (diff) | |
download | libsolv-a4e2caaeae654b8ba5142b53e0c3cb753c6fb4c4.tar.gz libsolv-a4e2caaeae654b8ba5142b53e0c3cb753c6fb4c4.tar.bz2 libsolv-a4e2caaeae654b8ba5142b53e0c3cb753c6fb4c4.zip |
- add ENABLE_BZIP2_COMPRESSION and ENABLE_CUDFREPO to support some cudf tests
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tools/cudftest.c | 153 |
2 files changed, 161 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 681ca55..9fca9c6 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -9,6 +9,9 @@ SET (SYSTEM_LIBRARIES ${EXPAT_LIBRARY} ${ZLIB_LIBRARY}) IF (ENABLE_LZMA_COMPRESSION) SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${LZMA_LIBRARY}) ENDIF (ENABLE_LZMA_COMPRESSION) +IF (ENABLE_BZIP2_COMPRESSION) +SET (SYSTEM_LIBRARIES ${SYSTEM_LIBRARIES} ${BZIP2_LIBRARIES}) +ENDIF (ENABLE_BZIP2_COMPRESSION) IF (ENABLE_RPMDB) SET (SYSTEM_LIBRARIES ${RPMDB_LIBRARY} ${SYSTEM_LIBRARIES}) ENDIF (ENABLE_RPMDB) @@ -82,6 +85,11 @@ TARGET_LINK_LIBRARIES (archrepo2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRA SET (tools_list ${tools_list} archpkgs2solv archrepo2solv) ENDIF (ENABLE_ARCHREPO) +IF (ENABLE_CUDFREPO) +ADD_EXECUTABLE (cudftest cudftest.c) +TARGET_LINK_LIBRARIES (cudftest libsolvext libsolv ${SYSTEM_LIBRARIES}) +ENDIF (ENABLE_CUDFREPO) + ADD_EXECUTABLE (installcheck installcheck.c) TARGET_LINK_LIBRARIES (installcheck libsolvext libsolv ${SYSTEM_LIBRARIES}) diff --git a/tools/cudftest.c b/tools/cudftest.c new file mode 100644 index 0000000..05dea10 --- /dev/null +++ b/tools/cudftest.c @@ -0,0 +1,153 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "pool.h" +#include "evr.h" +#include "solver.h" +#include "solverdebug.h" +#include "repo_cudf.h" +#include "repo_write.h" +#include "solv_xfopen.h" + +static void +dump_repo(Repo *repo, char *name) +{ + FILE *fp; + if ((fp = fopen(name, "w")) == 0) + { + perror(name); + exit(1); + } + repo_write(repo, fp); + fclose(fp); +} + +static int +sortfunc(const void *ap, const void *bp, void *dp) +{ + Pool *pool = dp; + Solvable *sa, *sb; + sa = pool->solvables + *(Id *)ap; + sb = pool->solvables + *(Id *)bp; + if (sa->name != sb->name) + { + int r = strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name)); + if (r) + return r; + } + if (sa->evr != sb->evr) + { + int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE); + if (r) + return r; + } + return *(Id *)ap - *(Id *)bp; +} + +int +main(int argc, char **argv) +{ + char *cudfin; + char *cudfout = 0; + Pool *pool; + Repo *installed, *repo; + FILE *fp, *ofp; + Solver *solv; + Transaction *trans; + Queue job; + Queue dq; + int i; + int debug = 0; + + while (argc > 1 && !strcmp(argv[1], "-d")) + { + debug++; + argc--; + argv++; + } + if (argc < 2) + { + fprintf(stderr, "Usage: cudftest <cudfin> [cudfout]"); + exit(1); + } + cudfin = argv[1]; + cudfout = argc > 2 ? argv[2] : 0; + + if ((fp = solv_xfopen(cudfin, 0)) == 0) + { + perror(cudfin); + exit(1); + } + pool = pool_create(); + if (debug > 1) + pool_setdebuglevel(pool, debug - 1); + installed = repo_create(pool, "installed"); + pool_set_installed(pool, installed); + repo = repo_create(pool, "repo"); + queue_init(&job); + repo_add_cudf(repo, installed, fp, &job, 0); + pool_createwhatprovides(pool); + + /* debug */ + if (debug) + { + dump_repo(installed, "cudf_installed.solv"); + dump_repo(repo, "cudf_repo.solv"); + } + + solv = solver_create(pool); + solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); + if (solver_solve(solv, &job) != 0) + { + int problem; + int 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"); + } + } + trans = solver_create_transaction(solv); + solver_free(solv); + + if (debug) + transaction_print(trans); + + queue_init(&dq); + transaction_installedresult(trans, &dq); + solv_sort(dq.elements, dq.count, sizeof(Id), sortfunc, pool); + + ofp = stdout; + if (cudfout && ((ofp = fopen(cudfout, "w")) == 0)) + { + perror(cudfout); + exit(1); + } + for (i = 0; i < dq.count; i++) + { + Solvable *s = pool_id2solvable(pool, dq.elements[i]); + fprintf(ofp, "package: %s\n", pool_id2str(pool, s->name)); + fprintf(ofp, "version: %s\n", pool_id2str(pool, s->evr)); + fprintf(ofp, "installed: true\n"); + if (s->repo == pool->installed) + fprintf(ofp, "was-installed: true\n"); + fprintf(ofp, "\n"); + } + queue_free(&dq); + transaction_free(trans); + queue_free(&job); + pool_free(pool); + if (ofp != stdout) + { + if (fclose(ofp)) + { + perror("fclose"); + exit(1); + } + } + exit(0); +} + |