Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: java
jdk: oraclejdk11
script:
- cd target
- java -jar SQLancer-0.0.1-SNAPSHOT.jar --timeout-seconds 60 sqlite3
- java -jar SQLancer-0.0.1-SNAPSHOT.jar --timeout-seconds 60 duckdb

- mvn test
cache:
directories:
- target/lib
after_success:
- bash <(curl -s https://codecov.io/bash)
after_failure:
- cat target/pmd.xml
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,32 @@
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
Expand Down Expand Up @@ -169,6 +194,12 @@
<artifactId>duckdb_jdbc</artifactId>
<version>0.1.8</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<reporting>
Expand Down
34 changes: 18 additions & 16 deletions src/sqlancer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

public final class Main {

private static final int THREADS_SHUTDOWN_EXIT_CODE = -1;
public static final File LOG_DIRECTORY = new File("logs");
public static volatile AtomicLong nrQueries = new AtomicLong();
public static volatile AtomicLong nrDatabases = new AtomicLong();
Expand Down Expand Up @@ -270,6 +271,10 @@ public static void printArray(Object[] arr) {
}

public static void main(String[] args) {
System.exit(executeMain(args));
}

public static int executeMain(String[] args) throws AssertionError {
List<DatabaseProvider<?, ?>> providers = new ArrayList<>();
providers.add(new SQLite3Provider());
providers.add(new CockroachDBProvider());
Expand Down Expand Up @@ -300,15 +305,14 @@ public static void main(String[] args) {
jc.parse(args);
if (jc.getParsedCommand() == null) {
jc.usage();
System.exit(-1);
return THREADS_SHUTDOWN_EXIT_CODE;
}

if (options.printProgressInformation()) {
startProgressMonitor(options);
startProgressMonitor();
}

ExecutorService executor = Executors.newFixedThreadPool(options.getNumberConcurrentThreads());

for (int i = 0; i < options.getTotalNumberTries(); i++) {
final String databaseName = "database" + i;

Expand Down Expand Up @@ -388,18 +392,25 @@ private void runThread(final String databaseName) {
e.printStackTrace();
}
if (threadsShutdown == options.getTotalNumberTries()) {
System.exit(-1);
System.exit(THREADS_SHUTDOWN_EXIT_CODE);
}
}
}
}
});
}

if (options.getTimeoutSeconds() != -1) {
try {
executor.awaitTermination(options.getTimeoutSeconds(), TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return threadsShutdown == 0 ? 0 : THREADS_SHUTDOWN_EXIT_CODE;
}

private static void startProgressMonitor(MainOptions options) {
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
private static void startProgressMonitor() {
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {

private long timeMillis = System.currentTimeMillis();
Expand Down Expand Up @@ -432,15 +443,6 @@ public void run() {
lastNrDbs = currentNrDbs;
}
}, 5, 5, TimeUnit.SECONDS);
if (options.getTimeoutSeconds() != -1) {
scheduler.schedule(new Runnable() {

@Override
public void run() {
System.exit(0);
}
}, options.getTimeoutSeconds(), TimeUnit.SECONDS);
}
}

}
20 changes: 20 additions & 0 deletions test/sqlancer/TestMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sqlancer;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class TestMain {

@Test
public void testSQLite() {
// do not check the result, since we still find bugs in the SQLite3 version included in the JDBC driver
Main.executeMain(new String[] { "--timeout-seconds", "30", "sqlite3", "--oracle", "NoREC" });
}

@Test
public void testDuckDB() {
assertEquals(0, Main.executeMain(new String[] { "--timeout-seconds", "30", "duckdb", "--oracle", "NoREC" }));
}

}