public void simple() { p = LoadProgramFrom(@" const g:int; axiom g > 0; procedure main() { return; } ", "test.bpl"); // Always return UNKNOWN so trying to prove the axiom fails so the initial state fails to be prepared var solver = new Solver.SimpleSolver(new Solver.DummySolver(Solver.Result.UNKNOWN)); e = GetExecutor(p, new DFSStateScheduler(), solver); // Global DDE must be disabled otherwise the axiom will be removed e.UseGlobalDDE = false; int stateTerminationCounter = 0; e.StateTerminated += delegate(object sender, Executor.ExecutionStateEventArgs eventArgs) { ++stateTerminationCounter; Assert.IsInstanceOf <TerminatedAtUnsatisfiableAxiom>(eventArgs.State.TerminationType); var terminationType = eventArgs.State.TerminationType as TerminatedAtUnsatisfiableAxiom; Assert.IsTrue(terminationType.ExitLocation.IsAxiom); }; bool hitException = false; try { e.Run(GetMain(p)); } catch (InitialStateTerminated) { hitException = true; Assert.AreEqual(Executor.ExecutorTerminationType.INITIAL_STATE_TERMINATED, e.TerminationType); } Assert.IsTrue(hitException); Assert.AreEqual(1, stateTerminationCounter); }
public void branchFeasibilityTrivialQueryExpr(bool trueBranch, Solver.Result expectedTrueBranch, Solver.Result expectedFalseBranch) { var builder = GetBuilder(); var solver = new Solver.SimpleSolver(GetSolverImpl()); var xVar = GetVar("x"); var constraint0Expr = builder.Lt(xVar.Expr, builder.ConstantInt(0)); var constraint0 = new Constraint(constraint0Expr); var cm = GetConstraintManager(); cm.AddConstraint(constraint0); var result = solver.CheckBranchSatisfiability(cm, new Constraint(builder.ConstantBool(trueBranch)), builder); Assert.AreEqual(expectedTrueBranch, result.TrueBranch); Assert.AreEqual(expectedFalseBranch, result.FalseBranch); }
public void branchFeasibilityNonTrivialOnlyFalseBranch() { var builder = GetBuilder(); var solver = new Solver.SimpleSolver(GetSolverImpl()); var xVar = GetVar("x"); var constraint0Expr = builder.Lt(xVar.Expr, builder.ConstantInt(0)); var constraint0 = new Constraint(constraint0Expr); var cm = GetConstraintManager(); cm.AddConstraint(constraint0); var queryExpr = builder.Gt(xVar.Expr, builder.ConstantInt(1)); var result = solver.CheckBranchSatisfiability(cm, new Constraint(queryExpr), builder); Assert.AreEqual(Solver.Result.UNSAT, result.TrueBranch); Assert.AreEqual(Solver.Result.SAT, result.FalseBranch); }
public static Solver.ISolver BuildSolverChain(CmdLineOpts options) { Solver.ISolverImpl solverImpl = null; // Try to guess the location of executable. This is just for convenience if (options.pathToSolver.Length == 0 && options.solver != CmdLineOpts.Solver.DUMMY) { Console.WriteLine("Path to SMT solver not specified. Guessing location"); // Look in the directory of the currently running executable for other solvers var pathToSolver = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), options.solver.ToString().ToLower()); if (File.Exists(pathToSolver)) { Console.WriteLine("Found \"{0}\"", pathToSolver); options.pathToSolver = pathToSolver; } else { // Try with ".exe" appended pathToSolver = pathToSolver + ".exe"; if (File.Exists(pathToSolver)) { Console.WriteLine("Found \"{0}\"", pathToSolver); options.pathToSolver = pathToSolver; } else { Console.Error.WriteLine("Could not find \"{0}\" (also without .exe)", pathToSolver); ExitWith(ExitCode.SOLVER_NOT_FOUND); } } } // HACK: THIS IS GROSS! REMOVE THIS ASAP AND FIND A CLEAN WAY OF DOING THIS!!!!!!!!!!!! var logicToUse = options.ForceQFAUFBV ? SMTLIBQueryPrinter.Logic.QF_AUFBV : SMTLIBQueryPrinter.Logic.DO_NOT_SET; switch (options.solver) { case CmdLineOpts.Solver.CVC4: solverImpl = new Solver.CVC4SMTLIBSolver(options.UseNamedAttributes > 0, options.pathToSolver, options.PersistentSolver > 0, options.emitTriggers > 0, logicToUse); break; case CmdLineOpts.Solver.Z3: solverImpl = new Solver.Z3SMTLIBSolver(options.UseNamedAttributes > 0, options.pathToSolver, options.PersistentSolver > 0, options.emitTriggers > 0, logicToUse); break; case CmdLineOpts.Solver.DUMMY: solverImpl = new Solver.DummySolver(Symbooglix.Solver.Result.UNKNOWN); break; default: throw new NotSupportedException("Unhandled solver type"); } if (options.queryLogPath.Length > 0) { // FIXME: How are we going to ensure this file gets closed properly? StreamWriter QueryLogFile = new StreamWriter(options.queryLogPath, /*append=*/ options.appendLoggedQueries > 0); solverImpl = new Solver.SMTLIBQueryLoggingSolverImpl(solverImpl, QueryLogFile, /*useNamedAttributeBindings=*/ true, options.humanReadable > 0); } if (options.CachingSolver >= 0) { solverImpl = new Solver.SimpleSolverCache(solverImpl, options.CachingSolver); } if (options.ConstraintIndepenceSolver > 0) { solverImpl = new Solver.ConstraintIndependenceSolver(solverImpl); } // Only support this for now. Solver.ISolver solver = new Solver.SimpleSolver(solverImpl); solver.SetTimeout(options.solverTimeout); return(solver); }