forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainOptions.java
More file actions
346 lines (251 loc) · 12.8 KB
/
MainOptions.java
File metadata and controls
346 lines (251 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package sqlancer;
import java.util.Objects;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import sqlancer.Randomly.StringGenerationStrategy;
@Parameters(separators = "=", commandDescription = "Options applicable to all DBMS")
public class MainOptions {
public static final int NO_SET_PORT = -1;
public static final int NO_REDUCE_LIMIT = -1;
public static final MainOptions DEFAULT_OPTIONS = new MainOptions();
@Parameter(names = { "--help", "-h" }, description = "Lists all supported options and commands", help = true)
private boolean help; // NOPMD
@Parameter(names = {
"--num-threads" }, description = "How many threads should run concurrently to test separate databases")
private int nrConcurrentThreads = 16; // NOPMD
@Parameter(names = {
"--random-seed" }, description = "A seed value != -1 that can be set to make the query and database generation deterministic")
private long randomSeed = -1; // NOPMD
@Parameter(names = { "--num-tries" }, description = "Specifies after how many found errors to stop testing")
private int totalNumberTries = 100; // NOPMD
@Parameter(names = { "--max-num-inserts" }, description = "Specifies how many INSERT statements should be issued")
private int maxNumberInserts = 30; // NOPMD
@Parameter(names = {
"--max-expression-depth" }, description = "Specifies the maximum depth of randomly-generated expressions")
private int maxExpressionDepth = 3; // NOPMD
@Parameter(names = {
"--num-queries" }, description = "Specifies the number of queries to be issued to a database before creating a new database")
private int nrQueries = 100000; // NOPMD
@Parameter(names = {
"--num-statement-kind-retries" }, description = "Specifies the number of times a specific statement kind (e.g., INSERT) should be retried when the DBMS indicates that it failed")
private int nrStatementRetryCount = 1000; // NOPMD
@Parameter(names = "--log-each-select", description = "Logs every statement issued", arity = 1)
private boolean logEachSelect = true; // NOPMD
@Parameter(names = "--log-execution-time", description = "Logs the execution time of each statement (requires --log-each-select to be enabled)", arity = 1)
private boolean logExecutionTime = true; // NOPMD
@Parameter(names = "--print-failed", description = "Logs failed insert, create and other statements without results", arity = 1)
private boolean loggerPrintFailed = true; // NOPMD
@Parameter(names = "--qpg-enable", description = "Enable the experimental feature Query Plan Guidance (QPG)", arity = 1)
private boolean enableQPG;
@Parameter(names = "--qpg-log-query-plan", description = "Logs the query plans of each query (requires --qpg-enable)", arity = 1)
private boolean logQueryPlan;
@Parameter(names = "--qpg-max-interval", description = "The maximum number of iterations to mutate tables if no new query plans (requires --qpg-enable)")
private static int qpgMaxInterval = 1000;
@Parameter(names = "--qpg-reward-weight", description = "The weight (0-1) of last reward when updating weighted average reward. A higher value denotes average reward is more affected by the last reward (requires --qpg-enable)")
private static double qpgk = 0.25;
@Parameter(names = "--qpg-selection-probability", description = "The probability (0-1) of the random selection of mutators. A higher value (>0.5) favors exploration over exploitation. (requires --qpg-enable)")
private static double qpgProbability = 0.7;
@Parameter(names = "--username", description = "The user name used to log into the DBMS")
private String userName = "sqlancer"; // NOPMD
@Parameter(names = "--password", description = "The password used to log into the DBMS")
private String password = "sqlancer"; // NOPMD
@Parameter(names = "--host", description = "The host used to log into the DBMS")
private String host = null; // NOPMD
@Parameter(names = "--port", description = "The port used to log into the DBMS")
private int port = MainOptions.NO_SET_PORT; // NOPMD
@Parameter(names = "--print-progress-information", description = "Whether to print progress information such as the number of databases generated or queries issued", arity = 1)
private boolean printProgressInformation = true; // NOPMD
@Parameter(names = "--print-progress-summary", description = "Whether to print an execution summary when exiting SQLancer", arity = 1)
private boolean printProgressSummary; // NOPMD
@Parameter(names = "--timeout-seconds", description = "The timeout in seconds")
private int timeoutSeconds = -1; // NOPMD
@Parameter(names = "--max-generated-databases", description = "The maximum number of databases that are generated by each thread")
private int maxGeneratedDatabases = -1; // NOPMD
@Parameter(names = "--exit-code-error", description = "The exit code that should be returned when an error is encountered (or a bug is found)")
private int errorExitCode = -1; // NOPMD
@Parameter(names = "--print-statements", description = "Print all statements to stdout, before they are sent to the DBMS (not yet implemented for all oracles)", arity = 1)
private boolean printStatements; // NOPMD
@Parameter(names = "--print-succeeding-statements", description = "Print statements that are successfully processed by the DBMS to stdout (not yet implemented for all oracles)", arity = 1)
private boolean printSucceedingStatements; // NOPMD
@Parameter(names = "--test-only-nonempty-tables", description = "Test only databases each of whose tables contain at least a single row", arity = 1)
private boolean testOnlyWithMoreThanZeroRows; // NOPMD
@Parameter(names = "--pqs-test-aggregates", description = "Partially test aggregate functions when all tables contain only a single row.", arity = 1)
private boolean testAggregateFunctions; // NOPMD
@Parameter(names = "--random-string-generation", description = "Select the random-string eneration approach")
private StringGenerationStrategy randomStringGenerationStrategy = StringGenerationStrategy.SOPHISTICATED; // NOPMD
@Parameter(names = "--string-constant-max-length", description = "Specify the maximum-length of generated string constants")
private int maxStringConstantLength = 10; // NOPMD
@Parameter(names = "--use-constant-caching", description = "Specifies whether constants should be cached and re-used with a certain probability", arity = 1)
private boolean useConstantCaching = true; // NOPMD
@Parameter(names = "--use-connection-test", description = "Test whether the DBMS is accessible before trying to connect using multiple threads", arity = 1)
private boolean useConnectionTest = true; // NOPMD
@Parameter(names = "--constant-cache-size", description = "Specifies the size of the constant cache. This option only takes effect when constant caching is enabled")
private int constantCacheSize = 100; // NOPMD
@Parameter(names = "--database-prefix", description = "The prefix used for each database created")
private String databasePrefix = "database"; // NOPMD
@Parameter(names = "--serialize-reproduce-state", description = "Serialize the state to reproduce")
private boolean serializeReproduceState = false; // NOPMD
@Parameter(names = "--use-reducer", description = "EXPERIMENTAL Attempt to reduce queries using a simple reducer")
private boolean useReducer = false; // NOPMD
@Parameter(names = "--reduce-ast", description = "EXPERIMENTAL perform AST reduction after statement reduction")
private boolean reduceAST = false; // NOPMD
@Parameter(names = "--statement-reducer-max-steps", description = "EXPERIMENTAL Maximum steps the statement reducer will do")
private long maxStatementReduceSteps = NO_REDUCE_LIMIT; // NOPMD
@Parameter(names = "--statement-reducer-max-time", description = "EXPERIMENTAL Maximum time duration (secs) the AST-based reducer will do")
private long maxASTReduceTime = NO_REDUCE_LIMIT; // NOPMD
@Parameter(names = "--ast-reducer-max-steps", description = "EXPERIMENTAL Maximum steps the AST-based reducer will do")
private long maxASTReduceSteps = NO_REDUCE_LIMIT; // NOPMD
@Parameter(names = "--ast-reducer-max-time", description = "EXPERIMENTAL Maximum time duration (secs) the statement reducer will do")
private long maxStatementReduceTime = NO_REDUCE_LIMIT; // NOPMD
@Parameter(names = "--validate-result-size-only", description = "Should validate result size only and skip comparing content of the result set ", arity = 1)
private boolean validateResultSizeOnly = false; // NOPMD
@Parameter(names = "--canonicalize-sql-strings", description = "Should canonicalize query string (add ';' at the end", arity = 1)
private boolean canonicalizeSqlString = true; // NOPMD
public int getMaxExpressionDepth() {
return maxExpressionDepth;
}
public int getTotalNumberTries() {
return totalNumberTries;
}
public int getNumberConcurrentThreads() {
return nrConcurrentThreads;
}
public boolean logEachSelect() {
return logEachSelect;
}
public boolean printAllStatements() {
if (printSucceedingStatements && printStatements) {
throw new AssertionError();
}
return printStatements;
}
public boolean printSucceedingStatements() {
if (printStatements && printSucceedingStatements) {
throw new AssertionError();
}
return printSucceedingStatements;
}
public boolean logExecutionTime() {
if (!logEachSelect) {
throw new AssertionError();
}
return logExecutionTime;
}
public boolean loggerPrintFailed() {
return loggerPrintFailed;
}
public boolean logQueryPlan() {
return logQueryPlan;
}
public boolean enableQPG() {
return enableQPG;
}
public int getQPGMaxMutationInterval() {
return qpgMaxInterval;
}
public double getQPGk() {
return qpgk;
}
public double getQPGProbability() {
return qpgProbability;
}
public int getNrQueries() {
return nrQueries;
}
public int getMaxNumberInserts() {
return maxNumberInserts;
}
public int getNrStatementRetryCount() {
return nrStatementRetryCount;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getHost() {
return host;
}
public int getPort() {
return port;
}
public boolean printProgressInformation() {
return printProgressInformation;
}
public boolean printProgressSummary() {
return printProgressSummary;
}
public int getTimeoutSeconds() {
return timeoutSeconds;
}
public int getMaxGeneratedDatabases() {
return maxGeneratedDatabases;
}
public int getErrorExitCode() {
return errorExitCode;
}
public long getRandomSeed() {
return randomSeed;
}
public boolean testAggregateFunctionsPQS() {
return testAggregateFunctions;
}
public boolean testOnlyWithMoreThanZeroRows() {
return testOnlyWithMoreThanZeroRows;
}
public StringGenerationStrategy getRandomStringGenerationStrategy() {
return randomStringGenerationStrategy;
}
public int getMaxStringConstantLength() {
return maxStringConstantLength;
}
public boolean useConstantCaching() {
return useConstantCaching;
}
public int getConstantCacheSize() {
return constantCacheSize;
}
public boolean isHelp() {
return help;
}
public boolean isDefaultPassword() {
return Objects.equals(password, DEFAULT_OPTIONS.password);
}
public boolean isDefaultUsername() {
return Objects.equals(userName, DEFAULT_OPTIONS.userName);
}
public String getDatabasePrefix() {
return databasePrefix;
}
public boolean performConnectionTest() {
return useConnectionTest;
}
public boolean serializeReproduceState() {
return serializeReproduceState;
}
public boolean useReducer() {
return useReducer;
}
public boolean reduceAST() {
return reduceAST;
}
public long getMaxStatementReduceSteps() {
return maxStatementReduceSteps;
}
public long getMaxStatementReduceTime() {
return maxStatementReduceTime;
}
public long getMaxASTReduceSteps() {
return maxASTReduceSteps;
}
public long getMaxASTReduceTime() {
return maxASTReduceTime;
}
public boolean validateResultSizeOnly() {
return validateResultSizeOnly;
}
public boolean canonicalizeSqlString() {
return canonicalizeSqlString;
}
}