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)
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);
144 if (!multijob && !feof(fp))
148 printf("test %d:\n", multijob++);
151 int selflags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL|SELECTION_GLOB|SELECTION_FLAT;
153 selflags |= SELECTION_FILELIST;
155 selection_make(pool, &job, list, selflags);
157 printf("No match\n");
163 selection_solvables(pool, &job, &q);
164 for (i = 0; i < q.count; i++)
165 printf(" - %s\n", testcase_solvid2str(pool, q.elements[i]));
169 else if (result || writeresult)
171 char *myresult, *resultdiff;
172 struct reportsolutiondata reportsolutiondata;
173 memset(&reportsolutiondata, 0, sizeof(reportsolutiondata));
176 solv->solution_callback = reportsolutioncb;
177 solv->solution_callback_data = &reportsolutiondata;
179 solver_solve(solv, &job);
180 solv->solution_callback = 0;
181 solv->solution_callback_data = 0;
183 resultflags = TESTCASE_RESULT_TRANSACTION | TESTCASE_RESULT_PROBLEMS;
184 myresult = testcase_solverresult(solv, resultflags);
185 if (rescallback && reportsolutiondata.result)
187 reportsolutiondata.result = solv_dupjoin(reportsolutiondata.result, myresult, 0);
189 myresult = reportsolutiondata.result;
202 for (i = 0; resultflags2str[i].str; i++)
203 if ((resultflags & resultflags2str[i].flag) != 0)
205 printf(p, resultflags2str[i].str);
208 printf(" <inline>\n");
212 const char *p2 = strchr(p, '\n');
213 p2 = p2 ? p2 + 1 : p + strlen(p);
214 printf("#>%.*s", (int)(p2 - p), p);
219 printf("%s", myresult);
224 resultdiff = testcase_resultdiff(result, myresult);
227 printf("Results differ:\n%s", resultdiff);
229 solv_free(resultdiff);
237 int pcnt = solver_solve(solv, &job);
239 testcase_write(solv, writetestcase, resultflags, 0, 0);
240 if (pcnt && solq.count)
243 for (i = 0; i < solq.count; i += 2)
245 if (solq.elements[i] > 0 && solq.elements[i] <= pcnt)
246 if (solq.elements[i + 1] > 0 && solq.elements[i + 1] <= solver_solution_count(solv, solq.elements[i]))
248 printf("problem %d: taking solution %d\n", solq.elements[i], solq.elements[i + 1]);
249 solver_take_solution(solv, solq.elements[i], solq.elements[i + 1], &job);
254 pcnt = solver_solve(solv, &job);
258 int problem, solution, scnt;
259 printf("Found %d problems:\n", pcnt);
260 for (problem = 1; problem <= pcnt; problem++)
262 printf("Problem %d:\n", problem);
264 solver_printprobleminfo(solv, problem);
270 solver_findallproblemrules(solv, problem, &pq);
271 for (j = 0; j < pq.count; j++)
272 solver_printproblemruleinfo(solv, pq.elements[j]);
277 scnt = solver_solution_count(solv, problem);
278 for (solution = 1; solution <= scnt; solution++)
280 printf("Solution %d:\n", solution);
281 solver_printsolution(solv, problem, solution);
288 Transaction *trans = solver_create_transaction(solv);
289 printf("Transaction summary:\n\n");
290 transaction_print(trans);
291 transaction_free(trans);