@@ -35,6 +35,10 @@ static PGconn **conns = NULL;
35
35
static const char * * backend_pids = NULL ;
36
36
static int nconns = 0 ;
37
37
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 );
38
42
static void run_all_permutations (TestSpec * testspec );
39
43
static void run_all_permutations_recurse (TestSpec * testspec , int nsteps ,
40
44
Step * * steps );
@@ -69,20 +73,46 @@ main(int argc, char **argv)
69
73
int i ;
70
74
PGresult * res ;
71
75
PQExpBufferData 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
+ }
72
90
73
91
/*
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.
77
96
*/
78
- if (argc > 1 )
79
- conninfo = argv [1 ];
97
+ if (argc > optind )
98
+ conninfo = argv [optind ];
80
99
else
81
100
conninfo = "dbname = postgres" ;
82
101
83
102
/* Read the test spec from stdin */
84
103
spec_yyparse ();
85
104
testspec = & 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
+
86
116
printf ("Parsed test spec with %d sessions\n" , testspec -> nsessions );
87
117
88
118
/*
@@ -240,10 +270,7 @@ main(int argc, char **argv)
240
270
* Run the permutations specified in the spec, or all if none were
241
271
* explicitly specified.
242
272
*/
243
- if (testspec -> permutations )
244
- run_named_permutations (testspec );
245
- else
246
- run_all_permutations (testspec );
273
+ run_testspec (testspec );
247
274
248
275
/* Clean up and exit */
249
276
for (i = 0 ; i < nconns ; i ++ )
@@ -253,6 +280,19 @@ main(int argc, char **argv)
253
280
254
281
static int * piles ;
255
282
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
+
256
296
/*
257
297
* Run all permutations of the steps and sessions.
258
298
*/
@@ -437,6 +477,19 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
437
477
int i ;
438
478
Step * waiting = NULL ;
439
479
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
+
440
493
printf ("\nstarting permutation:" );
441
494
for (i = 0 ; i < nsteps ; i ++ )
442
495
printf (" %s" , steps [i ]-> name );
@@ -649,7 +702,7 @@ try_complete_step(Step *step, int flags)
649
702
}
650
703
/* Detail may contain xid values, so just show primary. */
651
704
step -> errormsg = malloc (5 +
652
- strlen (PQresultErrorField (res , PG_DIAG_SEVERITY )) +
705
+ strlen (PQresultErrorField (res , PG_DIAG_SEVERITY )) +
653
706
strlen (PQresultErrorField (res ,
654
707
PG_DIAG_MESSAGE_PRIMARY )));
655
708
sprintf (step -> errormsg , "%s: %s" ,
0 commit comments