static void run_all_permutations_recurse(TestSpec * testspec, int nsteps, Step ** steps) { int i; int found = 0; for (i = 0; i < testspec->nsessions; i++) { /* If there's any more steps in this pile, pick it and recurse */ if (piles[i] < testspec->sessions[i]->nsteps) { steps[nsteps] = testspec->sessions[i]->steps[piles[i]]; piles[i]++; run_all_permutations_recurse(testspec, nsteps + 1, steps); piles[i]--; found = 1; } } /* If all the piles were empty, this permutation is completed. Run it */ if (!found) run_permutation(testspec, nsteps, steps); }
/* * Run permutations given in the test spec */ static void run_named_permutations(TestSpec * testspec) { int i, j; int n; int nallsteps; Step **allsteps; /* First create a lookup table of all steps */ nallsteps = 0; for (i = 0; i < testspec->nsessions; i++) nallsteps += testspec->sessions[i]->nsteps; allsteps = malloc(nallsteps * sizeof(Step *)); n = 0; for (i = 0; i < testspec->nsessions; i++) { for (j = 0; j < testspec->sessions[i]->nsteps; j++) allsteps[n++] = testspec->sessions[i]->steps[j]; } qsort(allsteps, nallsteps, sizeof(Step *), &step_qsort_cmp); for (i = 0; i < testspec->npermutations; i++) { Permutation *p = testspec->permutations[i]; Step **steps; steps = malloc(p->nsteps * sizeof(Step *)); /* Find all the named steps using the lookup table */ for (j = 0; j < p->nsteps; j++) { Step **this = (Step **) bsearch(p->stepnames[j], allsteps, nallsteps, sizeof(Step *), &step_bsearch_cmp); if (this == NULL) { fprintf(stderr, "undefined step \"%s\" specified in permutation\n", p->stepnames[j]); exit_nicely(); } steps[j] = *this; } /* And run them */ run_permutation(testspec, p->nsteps, steps); free(steps); } }
/* * Run permutations given in the test spec */ static void run_named_permutations(TestSpec *testspec) { int i, j; for (i = 0; i < testspec->npermutations; i++) { Permutation *p = testspec->permutations[i]; Step **steps; steps = malloc(p->nsteps * sizeof(Step *)); /* Find all the named steps using the lookup table */ for (j = 0; j < p->nsteps; j++) { Step **this = (Step **) bsearch(p->stepnames[j], testspec->allsteps, testspec->nallsteps, sizeof(Step *), &step_bsearch_cmp); if (this == NULL) { fprintf(stderr, "undefined step \"%s\" specified in permutation\n", p->stepnames[j]); exit_nicely(); } steps[j] = *this; } /* And run them */ run_permutation(testspec, p->nsteps, steps); free(steps); } }