Search in sources :

Example 11 with Wmm

use of com.dat3m.dartagnan.wmm.Wmm in project Dat3M by hernanponcedeleon.

the class PropertyEncoder method encodeDataRaces.

public BooleanFormula encodeDataRaces(SolverContext ctx) {
    final String hb = "hb";
    checkState(memoryModel.getAxioms().stream().anyMatch(ax -> ax.isAcyclicity() && ax.getRelation().getName().equals(hb)), "The provided WMM needs an 'acyclic(hb)' axiom to encode data races.");
    logger.info("Encoding data-races");
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    IntegerFormulaManager imgr = ctx.getFormulaManager().getIntegerFormulaManager();
    BooleanFormula enc = bmgr.makeFalse();
    for (Thread t1 : program.getThreads()) {
        for (Thread t2 : program.getThreads()) {
            if (t1.getId() == t2.getId()) {
                continue;
            }
            for (Event e1 : t1.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.WRITE), FilterBasic.get(Tag.INIT)))) {
                MemEvent w = (MemEvent) e1;
                for (Event e2 : t2.getCache().getEvents(FilterMinus.get(FilterBasic.get(Tag.MEMORY), FilterBasic.get(Tag.INIT)))) {
                    MemEvent m = (MemEvent) e2;
                    if (w.hasFilter(Tag.RMW) && m.hasFilter(Tag.RMW)) {
                        continue;
                    }
                    if (w.canRace() && m.canRace() && alias.mayAlias(w, m)) {
                        BooleanFormula conflict = bmgr.and(m.exec(), w.exec(), edge(hb, m, w, ctx), generalEqual(w.getMemAddressExpr(), m.getMemAddressExpr(), ctx), imgr.equal(intVar(hb, w, ctx), imgr.add(intVar(hb, m, ctx), imgr.makeNumber(BigInteger.ONE))));
                        enc = bmgr.or(enc, conflict);
                    }
                }
            }
        }
    }
    // We use the SMT variable to extract from the model if the property was violated
    enc = bmgr.equivalence(RACES.getSMTVariable(ctx), enc);
    return bmgr.and(RACES.getSMTVariable(ctx), enc);
}
Also used : Options(org.sosy_lab.common.configuration.Options) Property(com.dat3m.dartagnan.configuration.Property) Utils.intVar(com.dat3m.dartagnan.wmm.utils.Utils.intVar) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Utils.edge(com.dat3m.dartagnan.wmm.utils.Utils.edge) HashMap(java.util.HashMap) Thread(com.dat3m.dartagnan.program.Thread) ArrayList(java.util.ArrayList) Wmm(com.dat3m.dartagnan.wmm.Wmm) Map(java.util.Map) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) EnumSet(java.util.EnumSet) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) RelCo(com.dat3m.dartagnan.wmm.relation.base.memory.RelCo) Configuration(org.sosy_lab.common.configuration.Configuration) Collectors(java.util.stream.Collectors) Label(com.dat3m.dartagnan.program.event.core.Label) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) Tag(com.dat3m.dartagnan.program.event.Tag) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Context(com.dat3m.dartagnan.verification.Context) RelationNameRepository(com.dat3m.dartagnan.wmm.relation.RelationNameRepository) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) Load(com.dat3m.dartagnan.program.event.core.Load) LogManager(org.apache.logging.log4j.LogManager) FilterMinus(com.dat3m.dartagnan.program.filter.FilterMinus) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Thread(com.dat3m.dartagnan.program.Thread)

Example 12 with Wmm

use of com.dat3m.dartagnan.wmm.Wmm in project Dat3M by hernanponcedeleon.

the class Dat3M method runTest.

private void runTest() {
    UiOptions options = optionsPane.getOptions();
    testResult = null;
    try {
        Editor programEditor = editorsPane.getEditor(EditorCode.PROGRAM);
        Program program = new ProgramParser().parse(programEditor.getEditorPane().getText(), programEditor.getLoadedFormat());
        try {
            Wmm targetModel = new ParserCat().parse(editorsPane.getEditor(EditorCode.TARGET_MM).getEditorPane().getText());
            testResult = new ReachabilityResult(program, targetModel, options);
        } catch (Exception e) {
            String msg = e.getMessage() == null ? "Memory model cannot be parsed" : e.getMessage();
            showError(msg, "Target memory model error");
        }
    } catch (Exception e) {
        String msg = e.getMessage() == null ? "Program cannot be parsed" : e.getMessage();
        Throwable cause = e.getCause();
        if (cause instanceof InputMismatchException) {
            Token token = ((InputMismatchException) cause).getOffendingToken();
            msg = "Problem with \"" + token.getText() + "\" at line " + token.getLine();
        }
        showError(msg, "Program error");
    }
}
Also used : ReachabilityResult(com.dat3m.ui.result.ReachabilityResult) Program(com.dat3m.dartagnan.program.Program) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) Wmm(com.dat3m.dartagnan.wmm.Wmm) UiOptions(com.dat3m.ui.utils.UiOptions) Token(org.antlr.v4.runtime.Token) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) Editor(com.dat3m.ui.editor.Editor) InputMismatchException(org.antlr.v4.runtime.InputMismatchException) InputMismatchException(org.antlr.v4.runtime.InputMismatchException)

Example 13 with Wmm

use of com.dat3m.dartagnan.wmm.Wmm in project Dat3M by hernanponcedeleon.

the class BranchTest method data.

@Parameterized.Parameters(name = "{index}: {0}")
public static Iterable<Object[]> data() throws IOException {
    ImmutableMap<String, Result> expected = readExpectedResults();
    Wmm linuxWmm = new ParserCat().parse(new File(ResourceHelper.CAT_RESOURCE_PATH + "cat/linux-kernel.cat"));
    Wmm aarch64Wmm = new ParserCat().parse(new File(ResourceHelper.CAT_RESOURCE_PATH + "cat/aarch64.cat"));
    List<Object[]> data;
    try (Stream<Path> fileStream = Files.walk(Paths.get(ResourceHelper.TEST_RESOURCE_PATH + "branch/C/"))) {
        data = fileStream.filter(Files::isRegularFile).filter(f -> (f.toString().endsWith("litmus"))).map(f -> new Object[] { f.toString(), expected.get(f.getFileName().toString()), linuxWmm }).collect(Collectors.toList());
    }
    try (Stream<Path> fileStream = Files.walk(Paths.get(ResourceHelper.TEST_RESOURCE_PATH + "branch/AARCH64/"))) {
        data.addAll(fileStream.filter(Files::isRegularFile).filter(f -> (f.toString().endsWith("litmus"))).map(f -> new Object[] { f.toString(), expected.get(f.getFileName().toString()), aarch64Wmm }).collect(Collectors.toList()));
    }
    return data;
}
Also used : Path(java.nio.file.Path) Property(com.dat3m.dartagnan.configuration.Property) RunWith(org.junit.runner.RunWith) ProverOptions(org.sosy_lab.java_smt.api.SolverContext.ProverOptions) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) TestHelper(com.dat3m.dartagnan.utils.TestHelper) 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) ResourceHelper(com.dat3m.dartagnan.utils.ResourceHelper) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) EnumSet(java.util.EnumSet) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) TwoSolvers(com.dat3m.dartagnan.verification.solving.TwoSolvers) PASS(com.dat3m.dartagnan.utils.Result.PASS) List(java.util.List) Stream(java.util.stream.Stream) Arch(com.dat3m.dartagnan.configuration.Arch) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FAIL(com.dat3m.dartagnan.utils.Result.FAIL) Assert.assertEquals(org.junit.Assert.assertEquals) Wmm(com.dat3m.dartagnan.wmm.Wmm) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) Files(java.nio.file.Files) File(java.io.File) Result(com.dat3m.dartagnan.utils.Result)

Example 14 with Wmm

use of com.dat3m.dartagnan.wmm.Wmm in project Dat3M by hernanponcedeleon.

the class RefinementTask method createDefaultWmm.

private Wmm createDefaultWmm() {
    Wmm baseline = new Wmm();
    RelationRepository repo = baseline.getRelationRepository();
    Relation rf = repo.getRelation(RF);
    if (baselines.contains(UNIPROC)) {
        // ---- acyclic(po-loc | rf) ----
        Relation poloc = repo.getRelation(POLOC);
        Relation co = repo.getRelation(CO);
        Relation fr = repo.getRelation(FR);
        Relation porf = new RelUnion(poloc, rf);
        repo.addRelation(porf);
        Relation porfco = new RelUnion(porf, co);
        repo.addRelation(porfco);
        Relation porfcofr = new RelUnion(porfco, fr);
        repo.addRelation(porfcofr);
        baseline.addAxiom(new Acyclic(porfcofr));
    }
    if (baselines.contains(NO_OOTA)) {
        // ---- acyclic (dep | rf) ----
        Relation data = repo.getRelation(DATA);
        Relation ctrl = repo.getRelation(CTRL);
        Relation addr = repo.getRelation(ADDR);
        Relation dep = new RelUnion(data, addr);
        repo.addRelation(dep);
        dep = new RelUnion(ctrl, dep);
        repo.addRelation(dep);
        Relation hb = new RelUnion(dep, rf);
        repo.addRelation(hb);
        baseline.addAxiom(new Acyclic(hb));
    }
    if (baselines.contains(ATOMIC_RMW)) {
        // ---- empty (rmw & fre;coe) ----
        Relation rmw = repo.getRelation(RMW);
        Relation coe = repo.getRelation(COE);
        Relation fre = repo.getRelation(FRE);
        Relation frecoe = new RelComposition(fre, coe);
        repo.addRelation(frecoe);
        Relation rmwANDfrecoe = new RelIntersection(rmw, frecoe);
        repo.addRelation(rmwANDfrecoe);
        baseline.addAxiom(new Empty(rmwANDfrecoe));
    }
    return baseline;
}
Also used : Relation(com.dat3m.dartagnan.wmm.relation.Relation) Empty(com.dat3m.dartagnan.wmm.axiom.Empty) RelUnion(com.dat3m.dartagnan.wmm.relation.binary.RelUnion) Wmm(com.dat3m.dartagnan.wmm.Wmm) Acyclic(com.dat3m.dartagnan.wmm.axiom.Acyclic) RelComposition(com.dat3m.dartagnan.wmm.relation.binary.RelComposition) RelIntersection(com.dat3m.dartagnan.wmm.relation.binary.RelIntersection) RelationRepository(com.dat3m.dartagnan.wmm.utils.RelationRepository)

Aggregations

Wmm (com.dat3m.dartagnan.wmm.Wmm)14 ParserCat (com.dat3m.dartagnan.parsers.cat.ParserCat)10 File (java.io.File)8 Program (com.dat3m.dartagnan.program.Program)6 Test (org.junit.Test)6 ProgramParser (com.dat3m.dartagnan.parsers.program.ProgramParser)4 VerificationTask (com.dat3m.dartagnan.verification.VerificationTask)4 SolverContext (org.sosy_lab.java_smt.api.SolverContext)4 Property (com.dat3m.dartagnan.configuration.Property)3 Result (com.dat3m.dartagnan.utils.Result)3 EnumSet (java.util.EnumSet)3 Configuration (org.sosy_lab.common.configuration.Configuration)3 Relation (com.dat3m.dartagnan.wmm.relation.Relation)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)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 ParserErrorListener (com.dat3m.dartagnan.exception.ParserErrorListener)1