Search in sources :

Example 1 with VerificationTask

use of com.dat3m.dartagnan.verification.VerificationTask in project Dat3M by hernanponcedeleon.

the class Dartagnan method main.

public static void main(String[] args) throws Exception {
    if (Arrays.asList(args).contains("--help")) {
        collectOptions();
        return;
    }
    CreateGitInfo();
    String[] argKeyword = Arrays.stream(args).filter(s -> s.startsWith("-")).toArray(String[]::new);
    // TODO: We don't parse configs yet
    Configuration config = Configuration.fromCmdLineArguments(argKeyword);
    Dartagnan o = new Dartagnan(config);
    if (Arrays.stream(args).noneMatch(a -> supportedFormats.stream().anyMatch(a::endsWith))) {
        throw new IllegalArgumentException("Input program not given or format not recognized");
    }
    // get() is guaranteed to success
    File fileProgram = new File(Arrays.stream(args).filter(a -> supportedFormats.stream().anyMatch(a::endsWith)).findFirst().get());
    logger.info("Program path: " + fileProgram);
    if (Arrays.stream(args).noneMatch(a -> a.endsWith(".cat"))) {
        throw new IllegalArgumentException("CAT model not given or format not recognized");
    }
    // get() is guaranteed to success
    File fileModel = new File(Arrays.stream(args).filter(a -> a.endsWith(".cat")).findFirst().get());
    logger.info("CAT file path: " + fileModel);
    Wmm mcm = new ParserCat().parse(fileModel);
    Program p = new ProgramParser().parse(fileProgram);
    EnumSet<Property> properties = o.getProperty();
    WitnessGraph witness = new WitnessGraph();
    if (o.runValidator()) {
        logger.info("Witness path: " + o.getWitnessPath());
        witness = new ParserWitness().parse(new File(o.getWitnessPath()));
    }
    VerificationTask task = VerificationTask.builder().withConfig(config).withWitness(witness).build(p, mcm, properties);
    ShutdownManager sdm = ShutdownManager.create();
    Thread t = new Thread(() -> {
        try {
            if (o.hasTimeout()) {
                // Converts timeout from secs to millisecs
                Thread.sleep(1000L * o.getTimeout());
                sdm.requestShutdown("Shutdown Request");
                logger.warn("Shutdown Request");
            }
        } catch (InterruptedException e) {
        // Verification ended, nothing to be done.
        }
    });
    try {
        t.start();
        Configuration solverConfig = Configuration.builder().setOption(PHANTOM_REFERENCES, valueOf(o.usePhantomReferences())).build();
        try (SolverContext ctx = SolverContextFactory.createSolverContext(solverConfig, BasicLogManager.create(solverConfig), sdm.getNotifier(), o.getSolver());
            ProverEnvironment prover = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
            Result result = UNKNOWN;
            if (properties.contains(RACES)) {
                if (properties.size() > 1) {
                    System.out.println("Data race detection cannot be combined with other properties");
                    System.exit(1);
                }
                result = DataRaceSolver.run(ctx, prover, task);
            } else {
                // Property is either LIVENESS and/or REACHABILITY
                switch(o.getMethod()) {
                    case TWO:
                        try (ProverEnvironment prover2 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
                            result = TwoSolvers.run(ctx, prover, prover2, task);
                        }
                        break;
                    case INCREMENTAL:
                        result = IncrementalSolver.run(ctx, prover, task);
                        break;
                    case ASSUME:
                        result = AssumeSolver.run(ctx, prover, task);
                        break;
                    case CAAT:
                        result = RefinementSolver.run(ctx, prover, RefinementTask.fromVerificationTaskWithDefaultBaselineWMM(task));
                        break;
                }
            }
            // Verification ended, we can interrupt the timeout Thread
            t.interrupt();
            if (result.equals(FAIL) && o.generateGraphviz()) {
                ExecutionModel m = new ExecutionModel(task);
                m.initialize(prover.getModel(), ctx);
                String name = task.getProgram().getName().substring(0, task.getProgram().getName().lastIndexOf('.'));
                generateGraphvizFile(m, 1, (x, y) -> true, System.getenv("DAT3M_HOME") + "/output/", name);
            }
            if (p.getFormat().equals(SourceLanguage.LITMUS)) {
                if (p.getAssFilter() != null) {
                    System.out.println("Filter " + (p.getAssFilter()));
                }
                System.out.println("Condition " + p.getAss().toStringWithType());
                System.out.println(result == FAIL ? "Ok" : "No");
            } else {
                if (result == FAIL) {
                    if (TRUE.equals(prover.getModel().evaluate(REACHABILITY.getSMTVariable(ctx)))) {
                        System.out.println("Safety violation found");
                    }
                    if (TRUE.equals(prover.getModel().evaluate(LIVENESS.getSMTVariable(ctx)))) {
                        System.out.println("Liveness violation found");
                    }
                }
                System.out.println(result);
            }
            try {
                WitnessBuilder w = new WitnessBuilder(task, ctx, prover, result);
                // and if we are not doing witness validation
                if (properties.contains(REACHABILITY) && w.canBeBuilt() && !o.runValidator()) {
                    w.build().write();
                }
            } catch (InvalidConfigurationException e) {
                logger.warn(e.getMessage());
            }
        }
    } catch (InterruptedException e) {
        logger.warn("Timeout elapsed. The SMT solver was stopped");
        System.out.println("TIMEOUT");
        System.exit(0);
    } catch (Exception e) {
        logger.error(e.getMessage());
        System.out.println("ERROR");
        System.exit(1);
    }
}
Also used : Options(org.sosy_lab.common.configuration.Options) Arrays(java.util.Arrays) Property(com.dat3m.dartagnan.configuration.Property) SolverContextFactory(org.sosy_lab.java_smt.SolverContextFactory) CreateGitInfo(com.dat3m.dartagnan.utils.GitInfo.CreateGitInfo) ProverOptions(org.sosy_lab.java_smt.api.SolverContext.ProverOptions) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) Wmm(com.dat3m.dartagnan.wmm.Wmm) Result(com.dat3m.dartagnan.utils.Result) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) SourceLanguage(com.dat3m.dartagnan.program.Program.SourceLanguage) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) RefinementTask(com.dat3m.dartagnan.verification.RefinementTask) WitnessGraph(com.dat3m.dartagnan.witness.WitnessGraph) EnumSet(java.util.EnumSet) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) ExecutionGraphVisualizer.generateGraphvizFile(com.dat3m.dartagnan.utils.visualization.ExecutionGraphVisualizer.generateGraphvizFile) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) BaseOptions(com.dat3m.dartagnan.utils.options.BaseOptions) ImmutableSet(com.google.common.collect.ImmutableSet) Configuration(org.sosy_lab.common.configuration.Configuration) OptionInfo.collectOptions(com.dat3m.dartagnan.configuration.OptionInfo.collectOptions) Set(java.util.Set) WitnessBuilder(com.dat3m.dartagnan.witness.WitnessBuilder) File(java.io.File) Logger(org.apache.logging.log4j.Logger) String.valueOf(java.lang.String.valueOf) PHANTOM_REFERENCES(com.dat3m.dartagnan.configuration.OptionNames.PHANTOM_REFERENCES) ShutdownManager(org.sosy_lab.common.ShutdownManager) com.dat3m.dartagnan.verification.solving(com.dat3m.dartagnan.verification.solving) ExecutionModel(com.dat3m.dartagnan.verification.model.ExecutionModel) LogManager(org.apache.logging.log4j.LogManager) TRUE(java.lang.Boolean.TRUE) ParserWitness(com.dat3m.dartagnan.parsers.witness.ParserWitness) BasicLogManager(org.sosy_lab.common.log.BasicLogManager) Configuration(org.sosy_lab.common.configuration.Configuration) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) ShutdownManager(org.sosy_lab.common.ShutdownManager) WitnessGraph(com.dat3m.dartagnan.witness.WitnessGraph) Result(com.dat3m.dartagnan.utils.Result) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Property(com.dat3m.dartagnan.configuration.Property) Program(com.dat3m.dartagnan.program.Program) ParserWitness(com.dat3m.dartagnan.parsers.witness.ParserWitness) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) SolverContext(org.sosy_lab.java_smt.api.SolverContext) ExecutionModel(com.dat3m.dartagnan.verification.model.ExecutionModel) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) Wmm(com.dat3m.dartagnan.wmm.Wmm) ExecutionGraphVisualizer.generateGraphvizFile(com.dat3m.dartagnan.utils.visualization.ExecutionGraphVisualizer.generateGraphvizFile) File(java.io.File) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) WitnessBuilder(com.dat3m.dartagnan.witness.WitnessBuilder)

Example 2 with VerificationTask

use of com.dat3m.dartagnan.verification.VerificationTask in project Dat3M by hernanponcedeleon.

the class ArrayValidTest method test.

@Test
public void test() {
    try (SolverContext ctx = TestHelper.createContext();
        ProverEnvironment prover1 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS);
        ProverEnvironment prover2 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        Program program = new ProgramParser().parse(new File(path));
        VerificationTask task = VerificationTask.builder().withSolverTimeout(60).withTarget(Arch.LKMM).build(program, wmm, EnumSet.of(Property.getDefault()));
        assertEquals(TwoSolvers.run(ctx, prover1, prover2, task), FAIL);
    } catch (Exception e) {
        fail("Missing resource file");
    }
}
Also used : SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with VerificationTask

use of com.dat3m.dartagnan.verification.VerificationTask in project Dat3M by hernanponcedeleon.

the class ExceptionsTest method initializedBeforeCompileException.

@Test(expected = IllegalArgumentException.class)
public void initializedBeforeCompileException() throws Exception {
    ProgramBuilder pb = new ProgramBuilder(SourceLanguage.LITMUS);
    pb.initThread(0);
    Program p = pb.build();
    Wmm cat = new ParserCat().parse(new File(ResourceHelper.CAT_RESOURCE_PATH + "cat/tso.cat"));
    Configuration config = Configuration.defaultConfiguration();
    VerificationTask task = VerificationTask.builder().withConfig(config).build(p, cat, EnumSet.of(Property.getDefault()));
    // The program must be compiled before being able to construct an Encoder for it
    ProgramEncoder.fromConfig(task.getProgram(), Context.create(), config);
}
Also used : Program(com.dat3m.dartagnan.program.Program) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) Configuration(org.sosy_lab.common.configuration.Configuration) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) Wmm(com.dat3m.dartagnan.wmm.Wmm) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) File(java.io.File) Test(org.junit.Test)

Example 4 with VerificationTask

use of com.dat3m.dartagnan.verification.VerificationTask in project Dat3M by hernanponcedeleon.

the class BuildWitnessTest method BuildWriteEncode.

@Test
public void BuildWriteEncode() throws Exception {
    Configuration config = Configuration.builder().setOption(WITNESS_ORIGINAL_PROGRAM_PATH, ResourceHelper.TEST_RESOURCE_PATH + "witness/lazy01-for-witness.bpl").setOption(BOUND, "1").build();
    Program p = new ProgramParser().parse(new File(ResourceHelper.TEST_RESOURCE_PATH + "witness/lazy01-for-witness.bpl"));
    Wmm wmm = new ParserCat().parse(new File(ResourceHelper.CAT_RESOURCE_PATH + "cat/svcomp.cat"));
    VerificationTask task = VerificationTask.builder().withConfig(config).build(p, wmm, EnumSet.of(Property.getDefault()));
    try (SolverContext ctx = TestHelper.createContext();
        ProverEnvironment prover = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        Result res = IncrementalSolver.run(ctx, prover, task);
        WitnessBuilder witnessBuilder = new WitnessBuilder(task, ctx, prover, res);
        config.inject(witnessBuilder);
        WitnessGraph graph = witnessBuilder.build();
        File witnessFile = new File(System.getenv("DAT3M_HOME") + "/output/lazy01-for-witness.graphml");
        // The file should not exist
        assertFalse(witnessFile.exists());
        // Write to file
        graph.write();
        // The file should exist now
        assertTrue(witnessFile.exists());
        // Delete the file
        witnessFile.delete();
        // Create encoding
        BooleanFormula enc = graph.encode(p, ctx);
        BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
        // Check the formula is not trivial
        assertFalse(bmgr.isFalse(enc));
        assertFalse(bmgr.isTrue(enc));
    }
}
Also used : Program(com.dat3m.dartagnan.program.Program) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Configuration(org.sosy_lab.common.configuration.Configuration) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) Result(com.dat3m.dartagnan.utils.Result) SolverContext(org.sosy_lab.java_smt.api.SolverContext) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) Wmm(com.dat3m.dartagnan.wmm.Wmm) File(java.io.File) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 5 with VerificationTask

use of com.dat3m.dartagnan.verification.VerificationTask in project Dat3M by hernanponcedeleon.

the class BranchTest method test.

@Test
public void test() {
    try (SolverContext ctx = TestHelper.createContext();
        ProverEnvironment prover1 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS);
        ProverEnvironment prover2 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        Program program = new ProgramParser().parse(new File(path));
        VerificationTask task = VerificationTask.builder().withSolverTimeout(60).withTarget(Arch.LKMM).build(program, wmm, EnumSet.of(Property.getDefault()));
        assertEquals(expected, TwoSolvers.run(ctx, prover1, prover2, task));
    } catch (Exception e) {
        fail("Missing resource file");
    }
}
Also used : SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

VerificationTask (com.dat3m.dartagnan.verification.VerificationTask)6 Program (com.dat3m.dartagnan.program.Program)5 File (java.io.File)5 ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)5 SolverContext (org.sosy_lab.java_smt.api.SolverContext)5 ProgramParser (com.dat3m.dartagnan.parsers.program.ProgramParser)4 Test (org.junit.Test)4 Configuration (org.sosy_lab.common.configuration.Configuration)4 ParserCat (com.dat3m.dartagnan.parsers.cat.ParserCat)3 Result (com.dat3m.dartagnan.utils.Result)3 Wmm (com.dat3m.dartagnan.wmm.Wmm)3 IOException (java.io.IOException)2 ShutdownManager (org.sosy_lab.common.ShutdownManager)2 Arch (com.dat3m.dartagnan.configuration.Arch)1 OptionInfo.collectOptions (com.dat3m.dartagnan.configuration.OptionInfo.collectOptions)1 PHANTOM_REFERENCES (com.dat3m.dartagnan.configuration.OptionNames.PHANTOM_REFERENCES)1 Property (com.dat3m.dartagnan.configuration.Property)1 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)1 ParserWitness (com.dat3m.dartagnan.parsers.witness.ParserWitness)1 SourceLanguage (com.dat3m.dartagnan.program.Program.SourceLanguage)1