mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Implement a dry-run mode for isolationtester
This mode prints out the permutations that would be run by the given spec file, in the same format used by the permutation lines in spec files. This helps in building new spec files. Author: Alexander Shulgin, with some tweaks by me
This commit is contained in:
@ -35,6 +35,10 @@ static PGconn **conns = NULL;
|
|||||||
static const char **backend_pids = NULL;
|
static const char **backend_pids = NULL;
|
||||||
static int nconns = 0;
|
static int nconns = 0;
|
||||||
|
|
||||||
|
/* In dry run only output permutations to be run by the tester. */
|
||||||
|
static int dry_run = false;
|
||||||
|
|
||||||
|
static void run_testspec(TestSpec *testspec);
|
||||||
static void run_all_permutations(TestSpec * testspec);
|
static void run_all_permutations(TestSpec * testspec);
|
||||||
static void run_all_permutations_recurse(TestSpec * testspec, int nsteps,
|
static void run_all_permutations_recurse(TestSpec * testspec, int nsteps,
|
||||||
Step ** steps);
|
Step ** steps);
|
||||||
@ -69,20 +73,46 @@ main(int argc, char **argv)
|
|||||||
int i;
|
int i;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
PQExpBufferData wait_query;
|
PQExpBufferData wait_query;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n")) != -1)
|
||||||
|
{
|
||||||
|
switch (opt)
|
||||||
|
{
|
||||||
|
case 'n':
|
||||||
|
dry_run = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Usage: isolationtester [-n] [CONNINFO]\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the user supplies a parameter on the command line, use it as the
|
* If the user supplies a non-option parameter on the command line, use it
|
||||||
* conninfo string; otherwise default to setting dbname=postgres and using
|
* as the conninfo string; otherwise default to setting dbname=postgres and
|
||||||
* environment variables or defaults for all other connection parameters.
|
* using environment variables or defaults for all other connection
|
||||||
|
* parameters.
|
||||||
*/
|
*/
|
||||||
if (argc > 1)
|
if (argc > optind)
|
||||||
conninfo = argv[1];
|
conninfo = argv[optind];
|
||||||
else
|
else
|
||||||
conninfo = "dbname = postgres";
|
conninfo = "dbname = postgres";
|
||||||
|
|
||||||
/* Read the test spec from stdin */
|
/* Read the test spec from stdin */
|
||||||
spec_yyparse();
|
spec_yyparse();
|
||||||
testspec = &parseresult;
|
testspec = &parseresult;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In dry-run mode, just print the permutations that would be run, and
|
||||||
|
* exit.
|
||||||
|
*/
|
||||||
|
if (dry_run)
|
||||||
|
{
|
||||||
|
run_testspec(testspec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
printf("Parsed test spec with %d sessions\n", testspec->nsessions);
|
printf("Parsed test spec with %d sessions\n", testspec->nsessions);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -240,10 +270,7 @@ main(int argc, char **argv)
|
|||||||
* Run the permutations specified in the spec, or all if none were
|
* Run the permutations specified in the spec, or all if none were
|
||||||
* explicitly specified.
|
* explicitly specified.
|
||||||
*/
|
*/
|
||||||
if (testspec->permutations)
|
run_testspec(testspec);
|
||||||
run_named_permutations(testspec);
|
|
||||||
else
|
|
||||||
run_all_permutations(testspec);
|
|
||||||
|
|
||||||
/* Clean up and exit */
|
/* Clean up and exit */
|
||||||
for (i = 0; i < nconns; i++)
|
for (i = 0; i < nconns; i++)
|
||||||
@ -253,6 +280,19 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
static int *piles;
|
static int *piles;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run the permutations specified in the spec, or all if none were
|
||||||
|
* explicitly specified.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
run_testspec(TestSpec *testspec)
|
||||||
|
{
|
||||||
|
if (testspec->permutations)
|
||||||
|
run_named_permutations(testspec);
|
||||||
|
else
|
||||||
|
run_all_permutations(testspec);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run all permutations of the steps and sessions.
|
* Run all permutations of the steps and sessions.
|
||||||
*/
|
*/
|
||||||
@ -437,6 +477,19 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
|
|||||||
int i;
|
int i;
|
||||||
Step *waiting = NULL;
|
Step *waiting = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In dry run mode, just display the permutation in the same format used by
|
||||||
|
* spec files, and return.
|
||||||
|
*/
|
||||||
|
if (dry_run)
|
||||||
|
{
|
||||||
|
printf("permutation");
|
||||||
|
for (i = 0; i < nsteps; i++)
|
||||||
|
printf(" \"%s\"", steps[i]->name);
|
||||||
|
printf("\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
printf("\nstarting permutation:");
|
printf("\nstarting permutation:");
|
||||||
for (i = 0; i < nsteps; i++)
|
for (i = 0; i < nsteps; i++)
|
||||||
printf(" %s", steps[i]->name);
|
printf(" %s", steps[i]->name);
|
||||||
@ -649,7 +702,7 @@ try_complete_step(Step *step, int flags)
|
|||||||
}
|
}
|
||||||
/* Detail may contain xid values, so just show primary. */
|
/* Detail may contain xid values, so just show primary. */
|
||||||
step->errormsg = malloc(5 +
|
step->errormsg = malloc(5 +
|
||||||
strlen(PQresultErrorField(res, PG_DIAG_SEVERITY)) +
|
strlen(PQresultErrorField(res, PG_DIAG_SEVERITY)) +
|
||||||
strlen(PQresultErrorField(res,
|
strlen(PQresultErrorField(res,
|
||||||
PG_DIAG_MESSAGE_PRIMARY)));
|
PG_DIAG_MESSAGE_PRIMARY)));
|
||||||
sprintf(step->errormsg, "%s: %s",
|
sprintf(step->errormsg, "%s: %s",
|
||||||
|
Reference in New Issue
Block a user