Search in sources :

Example 1 with AssertTrue

use of com.dat3m.dartagnan.asserts.AssertTrue in project Dat3M by hernanponcedeleon.

the class RefinementSolver method run.

// TODO: We do not yet use Witness information. The problem is that WitnessGraph.encode() generates
// constraints on hb, which is not encoded in Refinement.
public static Result run(SolverContext ctx, ProverEnvironment prover, RefinementTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
    task.preprocessProgram();
    if (task.getProgram().getAss() instanceof AssertTrue) {
        logger.info("Verification finished: assertion trivially holds");
        return PASS;
    }
    task.performStaticProgramAnalyses();
    task.performStaticWmmAnalyses();
    task.initializeEncoders(ctx);
    ProgramEncoder programEncoder = task.getProgramEncoder();
    PropertyEncoder propertyEncoder = task.getPropertyEncoder();
    WmmEncoder baselineEncoder = task.getBaselineWmmEncoder();
    SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
    Program program = task.getProgram();
    WMMSolver solver = new WMMSolver(task);
    Refiner refiner = new Refiner(task);
    CAATSolver.Status status = INCONSISTENT;
    logger.info("Starting encoding using " + ctx.getVersion());
    prover.addConstraint(programEncoder.encodeFullProgram(ctx));
    prover.addConstraint(baselineEncoder.encodeFullMemoryModel(ctx));
    prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
    prover.push();
    prover.addConstraint(propertyEncoder.encodeSpecification(task.getProperty(), ctx));
    // ------ Just for statistics ------
    List<DNF<CoreLiteral>> foundCoreReasons = new ArrayList<>();
    List<WMMSolver.Statistics> statList = new ArrayList<>();
    int iterationCount = 0;
    long lastTime = System.currentTimeMillis();
    long curTime;
    long totalNativeSolvingTime = 0;
    long totalCaatTime = 0;
    // ---------------------------------
    logger.info("Refinement procedure started.");
    while (!prover.isUnsat()) {
        if (iterationCount == 0 && logger.isDebugEnabled()) {
            String smtStatistics = "\n ===== SMT Statistics (after first iteration) ===== \n";
            for (String key : prover.getStatistics().keySet()) {
                smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
            }
            logger.debug(smtStatistics);
        }
        iterationCount++;
        curTime = System.currentTimeMillis();
        totalNativeSolvingTime += (curTime - lastTime);
        logger.debug("Solver iteration: \n" + " ===== Iteration: {} =====\n" + "Solving time(ms): {}", iterationCount, curTime - lastTime);
        curTime = System.currentTimeMillis();
        WMMSolver.Result solverResult;
        try (Model model = prover.getModel()) {
            solverResult = solver.check(model, ctx);
        } catch (SolverException e) {
            logger.error(e);
            throw e;
        }
        WMMSolver.Statistics stats = solverResult.getStatistics();
        statList.add(stats);
        logger.debug("Refinement iteration:\n{}", stats);
        status = solverResult.getStatus();
        if (status == INCONSISTENT) {
            DNF<CoreLiteral> reasons = solverResult.getCoreReasons();
            foundCoreReasons.add(reasons);
            prover.addConstraint(refiner.refine(reasons, ctx));
            if (REFINEMENT_GENERATE_GRAPHVIZ_DEBUG_FILES) {
                generateGraphvizFiles(task, solver.getExecution(), iterationCount, reasons);
            }
            if (logger.isTraceEnabled()) {
                // Some statistics
                StringBuilder message = new StringBuilder().append("Found inconsistency reasons:");
                for (Conjunction<CoreLiteral> cube : reasons.getCubes()) {
                    message.append("\n").append(cube);
                }
                logger.trace(message);
            }
        } else {
            // No violations found, we can't refine
            break;
        }
        totalCaatTime += (System.currentTimeMillis() - curTime);
        lastTime = System.currentTimeMillis();
    }
    iterationCount++;
    curTime = System.currentTimeMillis();
    totalNativeSolvingTime += (curTime - lastTime);
    logger.debug("Final solver iteration:\n" + " ===== Final Iteration: {} =====\n" + "Native Solving/Proof time(ms): {}", iterationCount, curTime - lastTime);
    if (logger.isInfoEnabled()) {
        String message;
        switch(status) {
            case INCONCLUSIVE:
                message = "CAAT Solver was inconclusive (bug?).";
                break;
            case CONSISTENT:
                message = "Violation verified.";
                break;
            case INCONSISTENT:
                message = "Bounded safety proven.";
                break;
            default:
                throw new IllegalStateException("Unknown result type returned by CAAT Solver.");
        }
        logger.info(message);
    }
    if (status == INCONCLUSIVE) {
        // CAATSolver got no result (should not be able to happen), so we cannot proceed further.
        return UNKNOWN;
    }
    Result veriResult;
    long boundCheckTime = 0;
    if (prover.isUnsat()) {
        // ------- CHECK BOUNDS -------
        lastTime = System.currentTimeMillis();
        prover.pop();
        // Add bound check
        prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
        // Add back the constraints found during Refinement (TODO: We might need to perform a second refinement)
        for (DNF<CoreLiteral> reason : foundCoreReasons) {
            prover.addConstraint(refiner.refine(reason, ctx));
        }
        veriResult = !prover.isUnsat() ? UNKNOWN : PASS;
        boundCheckTime = System.currentTimeMillis() - lastTime;
    } else {
        veriResult = FAIL;
    }
    if (logger.isInfoEnabled()) {
        logger.info(generateSummary(statList, iterationCount, totalNativeSolvingTime, totalCaatTime, boundCheckTime));
    }
    if (logger.isDebugEnabled()) {
        String smtStatistics = "\n ===== SMT Statistics (after final iteration) ===== \n";
        for (String key : prover.getStatistics().keySet()) {
            smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
        }
        logger.debug(smtStatistics);
    }
    veriResult = program.getAss().getInvert() ? veriResult.invert() : veriResult;
    logger.info("Verification finished with result " + veriResult);
    return veriResult;
}
Also used : PropertyEncoder(com.dat3m.dartagnan.encoding.PropertyEncoder) CAATSolver(com.dat3m.dartagnan.solver.caat.CAATSolver) ProgramEncoder(com.dat3m.dartagnan.encoding.ProgramEncoder) WmmEncoder(com.dat3m.dartagnan.encoding.WmmEncoder) WMMSolver(com.dat3m.dartagnan.solver.caat4wmm.WMMSolver) ArrayList(java.util.ArrayList) Result(com.dat3m.dartagnan.utils.Result) SymmetryEncoder(com.dat3m.dartagnan.encoding.SymmetryEncoder) Refiner(com.dat3m.dartagnan.solver.caat4wmm.Refiner) Program(com.dat3m.dartagnan.program.Program) AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) Model(org.sosy_lab.java_smt.api.Model) ExecutionModel(com.dat3m.dartagnan.verification.model.ExecutionModel) SolverException(org.sosy_lab.java_smt.api.SolverException) DNF(com.dat3m.dartagnan.utils.logic.DNF)

Example 2 with AssertTrue

use of com.dat3m.dartagnan.asserts.AssertTrue in project Dat3M by hernanponcedeleon.

the class LoopUnrolling method updateAssertions.

private void updateAssertions(Program program) {
    if (program.getAss() != null) {
        // but I was under the impression that assFilter was used for Litmus tests.
        return;
    }
    List<Event> assertions = new ArrayList<>();
    for (Thread t : program.getThreads()) {
        assertions.addAll(t.getCache().getEvents(FilterBasic.get(Tag.ASSERTION)));
    }
    AbstractAssert ass = new AssertTrue();
    if (!assertions.isEmpty()) {
        ass = new AssertInline((Local) assertions.get(0));
        for (int i = 1; i < assertions.size(); i++) {
            ass = new AssertCompositeOr(ass, new AssertInline((Local) assertions.get(i)));
        }
    }
    program.setAss(ass);
    logger.info("Updated assertions after unrolling.");
}
Also used : AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) ArrayList(java.util.ArrayList) Event(com.dat3m.dartagnan.program.event.core.Event) Local(com.dat3m.dartagnan.program.event.core.Local) AbstractAssert(com.dat3m.dartagnan.asserts.AbstractAssert) AssertCompositeOr(com.dat3m.dartagnan.asserts.AssertCompositeOr) Thread(com.dat3m.dartagnan.program.Thread) AssertInline(com.dat3m.dartagnan.asserts.AssertInline)

Example 3 with AssertTrue

use of com.dat3m.dartagnan.asserts.AssertTrue in project Dat3M by hernanponcedeleon.

the class VerificationTask method updateAssertions.

private void updateAssertions(Program program) {
    List<Event> assertions = program.getCache().getEvents(FilterBasic.get(ASSERTION));
    AbstractAssert ass = new AssertTrue();
    if (!assertions.isEmpty()) {
        ass = new AssertInline((Local) assertions.get(0));
        for (int i = 1; i < assertions.size(); i++) {
            ass = new AssertCompositeOr(ass, new AssertInline((Local) assertions.get(i)));
        }
    }
    program.setAss(ass);
}
Also used : AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) Event(com.dat3m.dartagnan.program.event.core.Event) Local(com.dat3m.dartagnan.program.event.core.Local) AbstractAssert(com.dat3m.dartagnan.asserts.AbstractAssert) AssertCompositeOr(com.dat3m.dartagnan.asserts.AssertCompositeOr) AssertInline(com.dat3m.dartagnan.asserts.AssertInline)

Example 4 with AssertTrue

use of com.dat3m.dartagnan.asserts.AssertTrue in project Dat3M by hernanponcedeleon.

the class AssumeSolver method run.

public static Result run(SolverContext ctx, ProverEnvironment prover, VerificationTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
    Result res = Result.UNKNOWN;
    task.preprocessProgram();
    if (task.getProgram().getAss() instanceof AssertTrue) {
        logger.info("Verification finished: assertion trivially holds");
        return PASS;
    }
    task.performStaticProgramAnalyses();
    task.performStaticWmmAnalyses();
    task.initializeEncoders(ctx);
    ProgramEncoder programEncoder = task.getProgramEncoder();
    PropertyEncoder propertyEncoder = task.getPropertyEncoder();
    WmmEncoder wmmEncoder = task.getWmmEncoder();
    SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
    logger.info("Starting encoding using " + ctx.getVersion());
    prover.addConstraint(programEncoder.encodeFullProgram(ctx));
    prover.addConstraint(wmmEncoder.encodeFullMemoryModel(ctx));
    // For validation this contains information.
    // For verification graph.encode() just returns ctx.mkTrue()
    prover.addConstraint(task.getWitness().encode(task.getProgram(), ctx));
    prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula assumptionLiteral = bmgr.makeVariable("DAT3M_spec_assumption");
    BooleanFormula assumedSpec = bmgr.implication(assumptionLiteral, propertyEncoder.encodeSpecification(task.getProperty(), ctx));
    prover.addConstraint(assumedSpec);
    logger.info("Starting first solver.check()");
    if (prover.isUnsatWithAssumptions(singletonList(assumptionLiteral))) {
        prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
        logger.info("Starting second solver.check()");
        res = prover.isUnsat() ? PASS : Result.UNKNOWN;
    } else {
        res = FAIL;
    }
    if (logger.isDebugEnabled()) {
        String smtStatistics = "\n ===== SMT Statistics ===== \n";
        for (String key : prover.getStatistics().keySet()) {
            smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
        }
        logger.debug(smtStatistics);
    }
    res = task.getProgram().getAss().getInvert() ? res.invert() : res;
    logger.info("Verification finished with result " + res);
    return res;
}
Also used : PropertyEncoder(com.dat3m.dartagnan.encoding.PropertyEncoder) AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) ProgramEncoder(com.dat3m.dartagnan.encoding.ProgramEncoder) WmmEncoder(com.dat3m.dartagnan.encoding.WmmEncoder) SymmetryEncoder(com.dat3m.dartagnan.encoding.SymmetryEncoder) Result(com.dat3m.dartagnan.utils.Result)

Example 5 with AssertTrue

use of com.dat3m.dartagnan.asserts.AssertTrue in project Dat3M by hernanponcedeleon.

the class IncrementalSolver method run.

public static Result run(SolverContext ctx, ProverEnvironment prover, VerificationTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
    Result res = Result.UNKNOWN;
    task.preprocessProgram();
    if (task.getProgram().getAss() instanceof AssertTrue) {
        logger.info("Verification finished: assertion trivially holds");
        return PASS;
    }
    task.performStaticProgramAnalyses();
    task.performStaticWmmAnalyses();
    task.initializeEncoders(ctx);
    ProgramEncoder programEncoder = task.getProgramEncoder();
    PropertyEncoder propertyEncoder = task.getPropertyEncoder();
    WmmEncoder wmmEncoder = task.getWmmEncoder();
    SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
    logger.info("Starting encoding using " + ctx.getVersion());
    prover.addConstraint(programEncoder.encodeFullProgram(ctx));
    prover.addConstraint(wmmEncoder.encodeFullMemoryModel(ctx));
    // For validation this contains information.
    // For verification graph.encode() just returns ctx.mkTrue()
    prover.addConstraint(task.getWitness().encode(task.getProgram(), ctx));
    prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
    logger.info("Starting push()");
    prover.push();
    prover.addConstraint(propertyEncoder.encodeSpecification(task.getProperty(), ctx));
    logger.info("Starting first solver.check()");
    if (prover.isUnsat()) {
        prover.pop();
        prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
        logger.info("Starting second solver.check()");
        res = prover.isUnsat() ? PASS : Result.UNKNOWN;
    } else {
        res = FAIL;
    }
    if (logger.isDebugEnabled()) {
        String smtStatistics = "\n ===== SMT Statistics ===== \n";
        for (String key : prover.getStatistics().keySet()) {
            smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
        }
        logger.debug(smtStatistics);
    }
    res = task.getProgram().getAss().getInvert() ? res.invert() : res;
    logger.info("Verification finished with result " + res);
    return res;
}
Also used : PropertyEncoder(com.dat3m.dartagnan.encoding.PropertyEncoder) AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) ProgramEncoder(com.dat3m.dartagnan.encoding.ProgramEncoder) WmmEncoder(com.dat3m.dartagnan.encoding.WmmEncoder) SymmetryEncoder(com.dat3m.dartagnan.encoding.SymmetryEncoder) Result(com.dat3m.dartagnan.utils.Result)

Aggregations

AssertTrue (com.dat3m.dartagnan.asserts.AssertTrue)6 ProgramEncoder (com.dat3m.dartagnan.encoding.ProgramEncoder)4 PropertyEncoder (com.dat3m.dartagnan.encoding.PropertyEncoder)4 SymmetryEncoder (com.dat3m.dartagnan.encoding.SymmetryEncoder)4 WmmEncoder (com.dat3m.dartagnan.encoding.WmmEncoder)4 Result (com.dat3m.dartagnan.utils.Result)4 AbstractAssert (com.dat3m.dartagnan.asserts.AbstractAssert)2 AssertCompositeOr (com.dat3m.dartagnan.asserts.AssertCompositeOr)2 AssertInline (com.dat3m.dartagnan.asserts.AssertInline)2 Event (com.dat3m.dartagnan.program.event.core.Event)2 Local (com.dat3m.dartagnan.program.event.core.Local)2 ArrayList (java.util.ArrayList)2 Program (com.dat3m.dartagnan.program.Program)1 Thread (com.dat3m.dartagnan.program.Thread)1 CAATSolver (com.dat3m.dartagnan.solver.caat.CAATSolver)1 Refiner (com.dat3m.dartagnan.solver.caat4wmm.Refiner)1 WMMSolver (com.dat3m.dartagnan.solver.caat4wmm.WMMSolver)1 CoreLiteral (com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral)1 DNF (com.dat3m.dartagnan.utils.logic.DNF)1 ExecutionModel (com.dat3m.dartagnan.verification.model.ExecutionModel)1