Skip to content

Integrate C-Reduce for Automatic Test Case Reduction #1241

@jinhuix

Description

@jinhuix

Problem Statement

Currently, SQLancer users must manually capture database states and write interestingness scripts when using C-Reduce for test case minimization. This process is error-prone and limits automation capabilities.

Implementation Plan

  1. Add CLI option (MainOptions.java):
@Parameter(names = "--use-creduce", description = "EXPERIMENTAL Attempt to reduce queries using c-reduce")
private boolean useCReduce = false; // NOPMD
  1. Modify Exception Handling (Main.java):

Inside executeMain(...): extend the existing catch (Throwable reduce) block.

try {
    ...
} catch (Throwable reduce) {
    reduce.printStackTrace();
    executor.getStateToReproduce().exception = reduce.getMessage();
    executor.getLogger().logFileWriter = null;
    executor.getLogger().logException(reduce, executor.getStateToReproduce());
    
    if (options.useCreduce()) {
        Reducer<G> reducer = new CReducer<>(provider);
        creducer.reduce(/* state, reduce, ... */);
    }
    return false;
}
  1. CReducer.reduce(...) should:
    • Generate databasex.sql: Dump all statements from state.getStatements(), and append the failing statement (from reduce.detailMessage)
    • Generate databasex.sh (interestingness script): Extract the error substring from reduce.cause.detailMessage (e.g., from [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed) grab database disk image is malformed), then can generate a script like: sqlite3 databasex.sql 2>&1 | grep -zq "database disk image is malformed".
    • Invoke C-reduce by ProcessBuilder, like: Process p = new ProcessBuilder("creduce", "databasex.sh", "databasex.sql").start();.

Questions

  • Is this design sensible? Any obvious pitfalls?
  • How to handle missing or mismatched SQLite versions? The interestingness script may fail.
  • This approach only works for SQLite. How can we generalize it to support other DBMSs?

@mrigger @KabilanMA Could you review this design before implementation? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions