9 #include "solverdebug.h"
12 static struct resultflags2str {
15 } resultflags2str[] = {
16 { TESTCASE_RESULT_TRANSACTION, "transaction" },
17 { TESTCASE_RESULT_PROBLEMS, "problems" },
18 { TESTCASE_RESULT_ORPHANED, "orphaned" },
19 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
20 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
21 { TESTCASE_RESULT_ALTERNATIVES, "alternatives" },
22 { TESTCASE_RESULT_RULES, "rules" },
23 { TESTCASE_RESULT_GENID, "genid" },
24 { TESTCASE_RESULT_REASON, "reason" },
25 { TESTCASE_RESULT_CLEANDEPS, "cleandeps" },
26 { TESTCASE_RESULT_JOBS, "jobs" },
33 fprintf(ex ? stderr : stdout, "Usage: testsolv <testcase>\n");
37 struct reportsolutiondata {
43 reportsolutioncb(Solver *solv, void *cbdata)
45 struct reportsolutiondata *sd = cbdata;
49 res = testcase_solverresult(solv, TESTCASE_RESULT_TRANSACTION);
54 sprintf(prefix, "callback%d:", sd->count);
55 while ((p2 = strchr(p, '\n')) != 0)
59 sd->result = solv_dupappend(sd->result, prefix, p);
69 main(int argc, char **argv)
74 Solver *solv, *reusesolv = 0;
79 char *writetestcase = 0;
85 int list_with_deps = 0;
90 while ((c = getopt(argc, argv, "vmrhL:l:s:T:")) >= 0)
115 if ((p = strchr(optarg, ':')))
116 queue_push2(&solq, atoi(optarg), atoi(p + 1));
118 queue_push2(&solq, 1, atoi(optarg));
121 writetestcase = optarg;
130 for (; optind < argc; optind++)
132 pool = pool_create();
133 pool_setdebuglevel(pool, debuglevel);
134 /* report all errors */
135 pool_setdebugmask(pool, pool->debugmask | SOLV_ERROR);
137 fp = fopen(argv[optind], "r");
140 perror(argv[optind]);
148 solv = testcase_read(pool, fp, argv[optind], &job, &result, &resultflags);
152 exit(resultflags == 77 ? 77 : 1);
160 if (!multijob && !feof(fp))
164 printf("test %d:\n", multijob++);
168 int selflags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL|SELECTION_GLOB|SELECTION_FLAT;
170 selflags |= SELECTION_FILELIST;
173 p = testcase_str2solvid(pool, list);
175 queue_push2(&job, SOLVER_SOLVABLE, p);
177 selection_make(pool, &job, list, selflags);
179 printf("No match\n");
185 selection_solvables(pool, &job, &q);
186 for (i = 0; i < q.count; i++)
188 printf(" - %s\n", testcase_solvid2str(pool, q.elements[i]));
194 SOLVABLE_PROVIDES, SOLVABLE_REQUIRES, SOLVABLE_CONFLICTS, SOLVABLE_OBSOLETES,
195 SOLVABLE_RECOMMENDS, SOLVABLE_SUGGESTS, SOLVABLE_SUPPLEMENTS, SOLVABLE_ENHANCES,
196 SOLVABLE_PREREQ_IGNOREINST,
199 vendor = pool_lookup_str(pool, q.elements[i], SOLVABLE_VENDOR);
201 printf(" %s: %s\n", pool_id2str(pool, SOLVABLE_VENDOR), vendor);
202 for (j = 0; deps[j]; j++)
206 pool_lookup_idarray(pool, q.elements[i], deps[j], &dq);
208 printf(" %s:\n", pool_id2str(pool, deps[j]));
209 for (k = 0; k < dq.count; k++)
210 printf(" %s\n", pool_dep2str(pool, dq.elements[k]));
218 else if (result || writeresult)
220 char *myresult, *resultdiff;
221 struct reportsolutiondata reportsolutiondata;
222 memset(&reportsolutiondata, 0, sizeof(reportsolutiondata));
225 solv->solution_callback = reportsolutioncb;
226 solv->solution_callback_data = &reportsolutiondata;
228 solver_solve(solv, &job);
229 solv->solution_callback = 0;
230 solv->solution_callback_data = 0;
231 if ((resultflags & ~TESTCASE_RESULT_REUSE_SOLVER) == 0)
232 resultflags |= TESTCASE_RESULT_TRANSACTION | TESTCASE_RESULT_PROBLEMS;
233 myresult = testcase_solverresult(solv, resultflags);
234 if (rescallback && reportsolutiondata.result)
236 reportsolutiondata.result = solv_dupjoin(reportsolutiondata.result, myresult, 0);
238 myresult = reportsolutiondata.result;
251 for (i = 0; resultflags2str[i].str; i++)
252 if ((resultflags & resultflags2str[i].flag) != 0)
254 printf(p, resultflags2str[i].str);
257 printf(" <inline>\n");
261 const char *p2 = strchr(p, '\n');
262 p2 = p2 ? p2 + 1 : p + strlen(p);
263 printf("#>%.*s", (int)(p2 - p), p);
268 printf("%s", myresult);
273 resultdiff = testcase_resultdiff(result, myresult);
276 printf("Results differ:\n%s", resultdiff);
278 solv_free(resultdiff);
286 int pcnt = solver_solve(solv, &job);
288 testcase_write(solv, writetestcase, resultflags, 0, 0);
289 if (pcnt && solq.count)
292 for (i = 0; i < solq.count; i += 2)
294 if (solq.elements[i] > 0 && solq.elements[i] <= pcnt)
295 if (solq.elements[i + 1] > 0 && solq.elements[i + 1] <= solver_solution_count(solv, solq.elements[i]))
297 printf("problem %d: taking solution %d\n", solq.elements[i], solq.elements[i + 1]);
298 solver_take_solution(solv, solq.elements[i], solq.elements[i + 1], &job);
303 pcnt = solver_solve(solv, &job);
307 int problem, solution, scnt;
308 printf("Found %d problems:\n", pcnt);
309 for (problem = 1; problem <= pcnt; problem++)
311 printf("Problem %d:\n", problem);
313 solver_printprobleminfo(solv, problem);
319 solver_findallproblemrules(solv, problem, &pq);
320 for (j = 0; j < pq.count; j++)
321 solver_printproblemruleinfo(solv, pq.elements[j]);
326 scnt = solver_solution_count(solv, problem);
327 for (solution = 1; solution <= scnt; solution++)
329 printf("Solution %d:\n", solution);
330 solver_printsolution(solv, problem, solution);
337 Transaction *trans = solver_create_transaction(solv);
338 printf("Transaction summary:\n\n");
339 transaction_print(trans);
340 transaction_free(trans);
344 if ((resultflags & TESTCASE_RESULT_REUSE_SOLVER) != 0 && !feof(fp))
350 solver_free(reusesolv);