@@ -35,6 +35,10 @@ static PGconn **conns = NULL;
3535static const char * * backend_pids = NULL ;
3636static int nconns = 0 ;
3737
38+ /* In dry run only output permutations to be run by the tester. */
39+ static int dry_run = false;
40+
41+ static void run_testspec (TestSpec * testspec );
3842static void run_all_permutations (TestSpec * testspec );
3943static void run_all_permutations_recurse (TestSpec * testspec ,int nsteps ,
4044Step * * steps );
@@ -69,20 +73,46 @@ main(int argc, char **argv)
6973int i ;
7074PGresult * res ;
7175PQExpBufferData wait_query ;
76+ int opt ;
77+
78+ while ((opt = getopt (argc ,argv ,"n" ))!= -1 )
79+ {
80+ switch (opt )
81+ {
82+ case 'n' :
83+ dry_run = true;
84+ break ;
85+ default :
86+ fprintf (stderr ,"Usage: isolationtester [-n] [CONNINFO]\n" );
87+ return EXIT_FAILURE ;
88+ }
89+ }
7290
7391/*
74- * If the user supplies a parameter on the command line, use it as the
75- * conninfo string; otherwise default to setting dbname=postgres and using
76- * environment variables or defaults for all other connection parameters.
92+ * If the user supplies a non-option parameter on the command line, use it
93+ * as the conninfo string; otherwise default to setting dbname=postgres and
94+ * using environment variables or defaults for all other connection
95+ * parameters.
7796 */
78- if (argc > 1 )
79- conninfo = argv [1 ];
97+ if (argc > optind )
98+ conninfo = argv [optind ];
8099else
81100conninfo = "dbname = postgres" ;
82101
83102/* Read the test spec from stdin */
84103spec_yyparse ();
85104testspec = & parseresult ;
105+
106+ /*
107+ * In dry-run mode, just print the permutations that would be run, and
108+ * exit.
109+ */
110+ if (dry_run )
111+ {
112+ run_testspec (testspec );
113+ return 0 ;
114+ }
115+
86116printf ("Parsed test spec with %d sessions\n" ,testspec -> nsessions );
87117
88118/*
@@ -240,10 +270,7 @@ main(int argc, char **argv)
240270 * Run the permutations specified in the spec, or all if none were
241271 * explicitly specified.
242272 */
243- if (testspec -> permutations )
244- run_named_permutations (testspec );
245- else
246- run_all_permutations (testspec );
273+ run_testspec (testspec );
247274
248275/* Clean up and exit */
249276for (i = 0 ;i < nconns ;i ++ )
@@ -253,6 +280,19 @@ main(int argc, char **argv)
253280
254281static int * piles ;
255282
283+ /*
284+ * Run the permutations specified in the spec, or all if none were
285+ * explicitly specified.
286+ */
287+ static void
288+ run_testspec (TestSpec * testspec )
289+ {
290+ if (testspec -> permutations )
291+ run_named_permutations (testspec );
292+ else
293+ run_all_permutations (testspec );
294+ }
295+
256296/*
257297 * Run all permutations of the steps and sessions.
258298 */
@@ -437,6 +477,19 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
437477int i ;
438478Step * waiting = NULL ;
439479
480+ /*
481+ * In dry run mode, just display the permutation in the same format used by
482+ * spec files, and return.
483+ */
484+ if (dry_run )
485+ {
486+ printf ("permutation" );
487+ for (i = 0 ;i < nsteps ;i ++ )
488+ printf (" \"%s\"" ,steps [i ]-> name );
489+ printf ("\n" );
490+ return ;
491+ }
492+
440493printf ("\nstarting permutation:" );
441494for (i = 0 ;i < nsteps ;i ++ )
442495printf (" %s" ,steps [i ]-> name );
@@ -649,7 +702,7 @@ try_complete_step(Step *step, int flags)
649702}
650703/* Detail may contain xid values, so just show primary. */
651704step -> errormsg = malloc (5 +
652- strlen (PQresultErrorField (res ,PG_DIAG_SEVERITY ))+
705+ strlen (PQresultErrorField (res ,PG_DIAG_SEVERITY ))+
653706strlen (PQresultErrorField (res ,
654707PG_DIAG_MESSAGE_PRIMARY )));
655708sprintf (step -> errormsg ,"%s: %s" ,