Search in sources :

Example 6 with Z3Exception

use of com.microsoft.z3.Z3Exception in project batfish by batfish.

the class NodFirstUnsatJob method call.

@Override
public NodFirstUnsatResult<KeyT, ResultT> call() {
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
        ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
        NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
        Fixedpoint fix = mkFixedpoint(program, false);
        KeyT key = _query.getKey();
        for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
            BoolExpr query = program.getQueries().get(queryNum);
            Status status = fix.query(query);
            switch(status) {
                case SATISFIABLE:
                    break;
                case UNKNOWN:
                    return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
                case UNSATISFIABLE:
                    return new NodFirstUnsatResult<>(key, queryNum, _query.getResultsByQueryIndex().get(queryNum), _logger.getHistory(), startTime);
                default:
                    return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
            }
        }
        return new NodFirstUnsatResult<>(key, null, null, _logger.getHistory(), startTime);
    } catch (Z3Exception e) {
        return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) Fixedpoint(com.microsoft.z3.Fixedpoint) Fixedpoint(com.microsoft.z3.Fixedpoint) Z3Exception(com.microsoft.z3.Z3Exception)

Example 7 with Z3Exception

use of com.microsoft.z3.Z3Exception in project batfish by batfish.

the class NodSatJob method call.

@Override
public NodSatResult<KeyT> call() {
    Map<KeyT, Boolean> results = new LinkedHashMap<>();
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
        ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
        NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
        Fixedpoint fix = mkFixedpoint(program, false);
        for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
            BoolExpr query = program.getQueries().get(queryNum);
            KeyT key = _query.getKeys().get(queryNum);
            Status status = fix.query(query);
            switch(status) {
                case SATISFIABLE:
                    results.put(key, true);
                    break;
                case UNKNOWN:
                    return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
                case UNSATISFIABLE:
                    results.put(key, false);
                    break;
                default:
                    return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
            }
        }
        return new NodSatResult<>(results, _logger.getHistory(), startTime);
    } catch (Z3Exception e) {
        return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) Fixedpoint(com.microsoft.z3.Fixedpoint) LinkedHashMap(java.util.LinkedHashMap) Fixedpoint(com.microsoft.z3.Fixedpoint) Z3Exception(com.microsoft.z3.Z3Exception)

Example 8 with Z3Exception

use of com.microsoft.z3.Z3Exception in project batfish by batfish.

the class AbstractNodJob method call.

@Override
public final NodJobResult call() {
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        SmtInput smtInput = computeSmtInput(startTime, ctx);
        Map<OriginateVrf, Map<String, Long>> originateVrfConstraints = getOriginateVrfConstraints(ctx, smtInput);
        Set<Flow> flows = getFlows(originateVrfConstraints);
        return new NodJobResult(startTime, _logger.getHistory(), flows);
    } catch (Z3Exception e) {
        return new NodJobResult(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) BatfishException(org.batfish.common.BatfishException) OriginateVrf(org.batfish.z3.state.OriginateVrf) Z3Exception(com.microsoft.z3.Z3Exception) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Flow(org.batfish.datamodel.Flow)

Example 9 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class Dartagnan method main.

public static void main(String[] args) throws Z3Exception, IOException {
    List<String> MCMs = Arrays.asList("sc", "tso", "pso", "rmo", "alpha", "power", "arm");
    Options options = new Options();
    Option targetOpt = new Option("t", "target", true, "target MCM");
    targetOpt.setRequired(true);
    options.addOption(targetOpt);
    Option inputOpt = new Option("i", "input", true, "input file path");
    inputOpt.setRequired(true);
    options.addOption(inputOpt);
    options.addOption(Option.builder("unroll").hasArg().desc("Unrolling steps").build());
    options.addOption(Option.builder("draw").hasArg().desc("If a buf is found, it outputs a graph \\path_to_file.dot").build());
    options.addOption(Option.builder("rels").hasArgs().desc("Relations to be drawn in the graph").build());
    CommandLineParser parserCmd = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;
    try {
        cmd = parserCmd.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("DARTAGNAN", options);
        System.exit(1);
        return;
    }
    String target = cmd.getOptionValue("target");
    if (!MCMs.stream().anyMatch(mcms -> mcms.trim().equals(target))) {
        System.out.println("Unrecognized target");
        System.exit(0);
        return;
    }
    String inputFilePath = cmd.getOptionValue("input");
    if (!inputFilePath.endsWith("pts") && !inputFilePath.endsWith("litmus")) {
        System.out.println("Unrecognized program format");
        System.exit(0);
        return;
    }
    File file = new File(inputFilePath);
    String program = FileUtils.readFileToString(file, "UTF-8");
    ANTLRInputStream input = new ANTLRInputStream(program);
    Program p = new Program(inputFilePath);
    if (inputFilePath.endsWith("litmus")) {
        LitmusLexer lexer = new LitmusLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        LitmusParser parser = new LitmusParser(tokens);
        p = parser.program(inputFilePath).p;
    }
    if (inputFilePath.endsWith("pts")) {
        PorthosLexer lexer = new PorthosLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        PorthosParser parser = new PorthosParser(tokens);
        p = parser.program(inputFilePath).p;
    }
    String[] rels = new String[100];
    if (cmd.hasOption("rels")) {
        rels = cmd.getOptionValues("rels");
    }
    int steps = 1;
    if (cmd.hasOption("unroll")) {
        steps = Integer.parseInt(cmd.getOptionValue("unroll"));
    }
    p.initialize(steps);
    p.compile(target, false, true);
    Context ctx = new Context();
    Solver s = ctx.mkSolver();
    s.add(p.encodeDF(ctx));
    s.add(p.getAss().encode(ctx));
    s.add(p.encodeCF(ctx));
    s.add(p.encodeDF_RF(ctx));
    s.add(Domain.encode(p, ctx));
    s.add(p.encodeMM(ctx, target));
    s.add(p.encodeConsistent(ctx, target));
    ctx.setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB_FULL);
    if (s.check() == Status.SATISFIABLE) {
        System.out.println("The state is reachable");
        // System.out.println("       0");
        if (cmd.hasOption("draw")) {
            String outputPath = cmd.getOptionValue("draw");
            Utils.drawGraph(p, ctx, s.getModel(), outputPath, rels);
        }
    } else {
        System.out.println("The state is not reachable");
    // System.out.println("       1");
    }
    return;
}
Also used : Arrays(java.util.Arrays) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) Solver(com.microsoft.z3.Solver) org.apache.commons.cli(org.apache.commons.cli) Context(com.microsoft.z3.Context) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Utils(dartagnan.utils.Utils) File(java.io.File) Z3_ast_print_mode(com.microsoft.z3.enumerations.Z3_ast_print_mode) LitmusParser(dartagnan.LitmusParser) List(java.util.List) Domain(dartagnan.wmm.Domain) PorthosLexer(dartagnan.PorthosLexer) PorthosParser(dartagnan.PorthosParser) Status(com.microsoft.z3.Status) Z3Exception(com.microsoft.z3.Z3Exception) Program(dartagnan.program.Program) LitmusLexer(dartagnan.LitmusLexer) Context(com.microsoft.z3.Context) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Solver(com.microsoft.z3.Solver) Program(dartagnan.program.Program) LitmusLexer(dartagnan.LitmusLexer) LitmusParser(dartagnan.LitmusParser) PorthosParser(dartagnan.PorthosParser) PorthosLexer(dartagnan.PorthosLexer) File(java.io.File) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 10 with Z3Exception

use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.

the class ARM method encode.

public static BoolExpr encode(Program program, Context ctx) throws Z3Exception {
    Set<Event> events = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    Set<Event> eventsL = program.getEvents().stream().filter(e -> e instanceof MemEvent || e instanceof Local).collect(Collectors.toSet());
    BoolExpr enc = satUnion("co", "fr", events, ctx);
    enc = ctx.mkAnd(enc, satUnion("com", "(co+fr)", "rf", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("poloc", "com", events, ctx));
    enc = ctx.mkAnd(enc, satTransFixPoint("idd", eventsL, ctx));
    enc = ctx.mkAnd(enc, satIntersection("data", "idd^+", "RW", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("addr", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "addr", "data", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satComp("coe", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("rdw", "poloc", "(fre;rfe)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("detour", "poloc", "(coe;rfe)", events, ctx));
    // Base case for program order
    enc = ctx.mkAnd(enc, satUnion("dp", "rdw", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ii0", "(dp+rdw)", "rfi", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("ic0", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ci0", "ctrlisb", "detour", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "ctrl", events, ctx));
    enc = ctx.mkAnd(enc, satComp("addr", "po", events, ctx));
    enc = ctx.mkAnd(enc, satARMPPO(events, ctx));
    enc = ctx.mkAnd(enc, satUnion("cc0", "(dp+ctrl)", "(addr;po)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RR", "ii", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RW", "ic", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("po-arm", "(RR&ii)", "(RW&ic)", events, ctx));
    // Happens before
    enc = ctx.mkAnd(enc, satUnion("po-arm", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("hb-arm", "(po-arm+rfe)", "ish", events, ctx));
    // Prop-base
    enc = ctx.mkAnd(enc, satComp("rfe", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ish", "(rfe;ish)", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("hb-arm", events, ctx));
    enc = ctx.mkAnd(enc, satComp("prop-base", "(ish+(rfe;ish))", "(hb-arm)*", events, ctx));
    // Propagation for ARM
    enc = ctx.mkAnd(enc, satTransRef("com", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(com)*", "(prop-base)*", events, ctx));
    enc = ctx.mkAnd(enc, satComp("((com)*;(prop-base)*)", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(((com)*;(prop-base)*);ish)", "(hb-arm)*", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("WW", "prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("prop", "(WW&prop-base)", "((((com)*;(prop-base)*);ish);(hb-arm)*)", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "prop", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(fre;prop)", "(hb-arm)*", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("co", "prop", events, ctx));
    return enc;
}
Also used : EncodingsCAT.satTransFixPoint(dartagnan.wmm.EncodingsCAT.satTransFixPoint) EncodingsCAT.satCycle(dartagnan.wmm.EncodingsCAT.satCycle) EncodingsCAT.satTransRef(dartagnan.wmm.EncodingsCAT.satTransRef) Event(dartagnan.program.Event) Context(com.microsoft.z3.Context) Set(java.util.Set) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Utils.intCount(dartagnan.utils.Utils.intCount) EncodingsCAT.satEmpty(dartagnan.wmm.EncodingsCAT.satEmpty) EncodingsCAT.satUnion(dartagnan.wmm.EncodingsCAT.satUnion) EncodingsCAT.satComp(dartagnan.wmm.EncodingsCAT.satComp) EncodingsCAT.satIrref(dartagnan.wmm.EncodingsCAT.satIrref) EncodingsCAT.satCycleDef(dartagnan.wmm.EncodingsCAT.satCycleDef) EncodingsCAT.satAcyclic(dartagnan.wmm.EncodingsCAT.satAcyclic) Local(dartagnan.program.Local) MemEvent(dartagnan.program.MemEvent) BoolExpr(com.microsoft.z3.BoolExpr) Z3Exception(com.microsoft.z3.Z3Exception) Program(dartagnan.program.Program) Utils.edge(dartagnan.utils.Utils.edge) EncodingsCAT.satIntersection(dartagnan.wmm.EncodingsCAT.satIntersection) BoolExpr(com.microsoft.z3.BoolExpr) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Local(dartagnan.program.Local)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)9 Context (com.microsoft.z3.Context)9 Z3Exception (com.microsoft.z3.Z3Exception)9 Event (dartagnan.program.Event)9 MemEvent (dartagnan.program.MemEvent)9 Program (dartagnan.program.Program)9 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 Local (dartagnan.program.Local)7 Utils.edge (dartagnan.utils.Utils.edge)6 Utils (dartagnan.utils.Utils)5 Status (com.microsoft.z3.Status)4 Init (dartagnan.program.Init)4 com.microsoft.z3 (com.microsoft.z3)3 Load (dartagnan.program.Load)3 Location (dartagnan.program.Location)3 Register (dartagnan.program.Register)3 Store (dartagnan.program.Store)3 Utils.intCount (dartagnan.utils.Utils.intCount)3 EncodingsCAT.satAcyclic (dartagnan.wmm.EncodingsCAT.satAcyclic)3