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" },
30 fprintf(ex ? stderr : stdout, "Usage: testsolv <testcase>\n");
34 struct reportsolutiondata {
40 reportsolutioncb(Solver *solv, void *cbdata)
42 struct reportsolutiondata *sd = cbdata;
46 res = testcase_solverresult(solv, TESTCASE_RESULT_TRANSACTION);
51 sprintf(prefix, "callback%d:", sd->count);
52 while ((p2 = strchr(p, '\n')) != 0)
56 sd->result = solv_dupappend(sd->result, prefix, p);
66 main(int argc, char **argv)
71 Solver *solv, *reusesolv = 0;
76 char *writetestcase = 0;
86 while ((c = getopt(argc, argv, "vmrhl:s:T:")) >= 0)
106 if ((p = strchr(optarg, ':')))
107 queue_push2(&solq, atoi(optarg), atoi(p + 1));
109 queue_push2(&solq, 1, atoi(optarg));
112 writetestcase = optarg;
121 for (; optind < argc; optind++)
123 pool = pool_create();
124 pool_setdebuglevel(pool, debuglevel);
126 fp = fopen(argv[optind], "r");
129 perror(argv[optind]);
137 solv = testcase_read(pool, fp, argv[optind], &job, &result, &resultflags);
141 exit(resultflags == 77 ? 77 : 1);
149 if (!multijob && !feof(fp))
153 printf("test %d:\n", multijob++);
156 int selflags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL|SELECTION_GLOB|SELECTION_FLAT;
158 selflags |= SELECTION_FILELIST;
160 selection_make(pool, &job, list, selflags);
162 printf("No match\n");
168 selection_solvables(pool, &job, &q);
169 for (i = 0; i < q.count; i++)
170 printf(" - %s\n", testcase_solvid2str(pool, q.elements[i]));
174 else if (result || writeresult)
176 char *myresult, *resultdiff;
177 struct reportsolutiondata reportsolutiondata;
178 memset(&reportsolutiondata, 0, sizeof(reportsolutiondata));
181 solv->solution_callback = reportsolutioncb;
182 solv->solution_callback_data = &reportsolutiondata;
184 solver_solve(solv, &job);
185 solv->solution_callback = 0;
186 solv->solution_callback_data = 0;
187 if ((resultflags & ~TESTCASE_RESULT_REUSE_SOLVER) == 0)
188 resultflags |= TESTCASE_RESULT_TRANSACTION | TESTCASE_RESULT_PROBLEMS;
189 myresult = testcase_solverresult(solv, resultflags);
190 if (rescallback && reportsolutiondata.result)
192 reportsolutiondata.result = solv_dupjoin(reportsolutiondata.result, myresult, 0);
194 myresult = reportsolutiondata.result;
207 for (i = 0; resultflags2str[i].str; i++)
208 if ((resultflags & resultflags2str[i].flag) != 0)
210 printf(p, resultflags2str[i].str);
213 printf(" <inline>\n");
217 const char *p2 = strchr(p, '\n');
218 p2 = p2 ? p2 + 1 : p + strlen(p);
219 printf("#>%.*s", (int)(p2 - p), p);
224 printf("%s", myresult);
229 resultdiff = testcase_resultdiff(result, myresult);
232 printf("Results differ:\n%s", resultdiff);
234 solv_free(resultdiff);
242 int pcnt = solver_solve(solv, &job);
244 testcase_write(solv, writetestcase, resultflags, 0, 0);
245 if (pcnt && solq.count)
248 for (i = 0; i < solq.count; i += 2)
250 if (solq.elements[i] > 0 && solq.elements[i] <= pcnt)
251 if (solq.elements[i + 1] > 0 && solq.elements[i + 1] <= solver_solution_count(solv, solq.elements[i]))
253 printf("problem %d: taking solution %d\n", solq.elements[i], solq.elements[i + 1]);
254 solver_take_solution(solv, solq.elements[i], solq.elements[i + 1], &job);
259 pcnt = solver_solve(solv, &job);
263 int problem, solution, scnt;
264 printf("Found %d problems:\n", pcnt);
265 for (problem = 1; problem <= pcnt; problem++)
267 printf("Problem %d:\n", problem);
269 solver_printprobleminfo(solv, problem);
275 solver_findallproblemrules(solv, problem, &pq);
276 for (j = 0; j < pq.count; j++)
277 solver_printproblemruleinfo(solv, pq.elements[j]);
282 scnt = solver_solution_count(solv, problem);
283 for (solution = 1; solution <= scnt; solution++)
285 printf("Solution %d:\n", solution);
286 solver_printsolution(solv, problem, solution);
293 Transaction *trans = solver_create_transaction(solv);
294 printf("Transaction summary:\n\n");
295 transaction_print(trans);
296 transaction_free(trans);
300 if ((resultflags & TESTCASE_RESULT_REUSE_SOLVER) != 0 && !feof(fp))
306 solver_free(reusesolv);