From b7ad28da58e432abb3cd6e8591a5cdc3dd0fa899 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 7 Aug 2023 13:20:16 +0200 Subject: [PATCH 001/278] First TestGeneration Version: - Adds Errorstates to each branch an annotates them with a TestGoal ID - Uses a BlockEncoding that breaks after Havoc NonDet - Long Trace Optimisation requiers some dependency changes - TraceCheck takes Value of the first representative and adds to a linkedList where the Index in the SSA corresponds to the index of the lsit - creates an ErrorAutomaton for every covered Testgoal along a Trace and saves the Result for each corresponding error State. - Writest All TestVectors in the same Folder - Writes MetaFile in WitnessPrinter --- .../implementation/base/CHandler.java | 282 +++++++++++++----- .../operations/IsEmptyHeuristic.java | 170 +++++++++-- .../singletracecheck/TraceCheck.java | 32 +- .../core/lib/models/annotation/Check.java | 38 ++- .../generator/rcfgbuilder/cfg/CfgBuilder.java | 41 ++- .../RcfgPreferenceInitializer.java | 2 +- .../traceabstraction/AbstractCegarLoop.java | 35 ++- .../traceabstraction/NwaCegarLoop.java | 75 ++++- .../ErrorGeneralizationEngine.java | 3 +- .../SimpleErrorAutomatonBuilder.java | 87 +++++- .../witnessprinter/WitnessPrinter.java | 23 +- 11 files changed, 649 insertions(+), 139 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 40b90da5ec1..0b04f4e3e85 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -221,7 +221,10 @@ import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.util.SFO; import de.uni_freiburg.informatik.ultimate.cdt.translation.interfaces.handler.INameHandler; import de.uni_freiburg.informatik.ultimate.cdt.translation.interfaces.handler.ITypeHandler; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Overapprox; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.model.acsl.ACSLNode; @@ -366,6 +369,8 @@ public class CHandler { private final boolean mIsInLibraryMode; + private int countTestGoals = 0; + /** * Constructor for CHandler in pre-run mode. * @@ -412,7 +417,8 @@ public CHandler(final ILogger logger, final ICACSL2BoogieBacktranslatorMapping b mSettings.useBitpreciseBitfields()); // the procedure manager has to be replaced between pre-run and main run - // the following fields form the transitive dependency hull on the procedure + // the following fields form the transitive dependency hull on the + // procedure // manager mProcedureManager = new ProcedureManager(mLogger, settings); @@ -481,33 +487,38 @@ public CHandler(final CHandler prerunCHandler, final ProcedureManager procedureM mGlobAcslExtractors = new ArrayList<>(); mDeclarations = new ArrayList<>(); - // reuse these parts of the old CHandler that have state that was created during + // reuse these parts of the old CHandler that have state that was + // created during // the prerun mVariablesOnHeap = prerunCHandler.mVariablesOnHeap; mFunctionToIndex = prerunCHandler.mFunctionToIndex; mBacktranslator = prerunCHandler.mBacktranslator; mLocationFactory = prerunCHandler.mLocationFactory; - // reuse these parts of the old CHandler that do not have state that was created + // reuse these parts of the old CHandler that do not have state that was + // created // during the prerun mLogger = prerunCHandler.mLogger; mSettings = prerunCHandler.mSettings; mReachableDeclarations = prerunCHandler.mReachableDeclarations; mReporter = prerunCHandler.mReporter; - // we need to replace the name handler and all instances that depend on it + // we need to replace the name handler and all instances that depend on + // it mNameHandler = nameHandler; mSymbolTable = symbolTable; mTypeSizes = typeSizes; - // we need to replace the static objects handler and all instances that depend + // we need to replace the static objects handler and all instances that + // depend // on it mStaticObjectsHandler = staticObjectsHandler; mTypeHandler = typeHandler; mExpressionTranslation = expressionTranslation; mTypeSizeComputer = typeSizeAndOffsetComputer; - // we need to replace the procedure manager and all instances that depend on it + // we need to replace the procedure manager and all instances that + // depend on it mProcedureManager = procedureManager; mAuxVarInfoBuilder = new AuxVarInfoBuilder(nameHandler, typeHandler, procedureManager); @@ -606,7 +617,8 @@ public CHandlerTranslationResult visit(final IDispatcher main, final List en : mFunctionToIndex.entrySet()) { final String funcId = SFO.FUNCTION_ADDRESS + en.getKey(); final VarList varList = new VarList(loc, new String[] { funcId }, mTypeHandler.constructPointerType(loc)); - // would unique make sense here?? -- would potentially add lots of axioms + // would unique make sense here?? -- would potentially add lots of + // axioms mDeclarations.add(new ConstDeclaration(loc, new Attribute[0], false, varList, null, false)); final Expression funcIdExpr = ExpressionFactory.constructIdentifierExpression(loc, @@ -661,7 +674,8 @@ public CHandlerTranslationResult visit(final IDispatcher main, final List in that case "isOnHeap" has not yet been determined, we set it to false + // --> in that case "isOnHeap" has not yet been determined, we set it to + // false final boolean isOnHeap = isOnHeap(node); final IASTPointerOperator[] pointerOps = node.getPointerOperators(); @@ -1169,7 +1193,8 @@ public Result visit(final IDispatcher main, final IASTDeclarator node) { sizeFactor = (RValue) converted.getLrValue(); } else if (am.getConstantExpression() == null && arrDecl.getArrayModifiers()[arrDecl.getArrayModifiers().length - 1] == am) { - // the innermost array modifier may be empty, if there is an initializer; like + // the innermost array modifier may be empty, if there is an + // initializer; like // int a[1][2][] = {...} final int intSizeFactor; if (arrDecl.getInitializer() != null) { @@ -1180,7 +1205,8 @@ public Result visit(final IDispatcher main, final IASTDeclarator node) { } else if (resType.getCType() instanceof CFunction) { // if we have an array of function pointers, // the initializer is stored in the parent node - // 2016-12-31 Matthias: I think this is only a workaround. + // 2016-12-31 Matthias: I think this is only a + // workaround. // What if we do not have an array of function pointers // but an arrray of pointers to function pointers? Then // we probably have to check the parent of the parent @@ -1190,15 +1216,18 @@ public Result visit(final IDispatcher main, final IASTDeclarator node) { } intSizeFactor = computeSizeOfInitializer((IASTEqualsInitializer) fundecl.getInitializer()); } else { - // we have an incomplete array type without an initializer -- + // we have an incomplete array type without an + // initializer -- // this may happen in a function parameter.. intSizeFactor = CArray.INCOMPLETE_ARRY_MAGIC_NUMBER; } - // Index type of the array. All C expressions that access the array are + // Index type of the array. All C expressions that access + // the array are // converted to this type. // In the past we wanted a type that is large enough for the // CArray.INCOMPLETE_ARRY_MAGIC_NUMBER. - // If we work with an unsigned type for pointer components we have to rethink + // If we work with an unsigned type for pointer components + // we have to rethink // the use of the magic number. final CPrimitive arrayIndexCtype = mTypeSizes.getSizeT(); final Expression sizeExpression = mTypeSizes.constructLiteralForIntegerType(loc, arrayIndexCtype, @@ -1325,7 +1354,8 @@ private boolean isOnHeap(final IASTDeclarator node) { final IBinding binding = node.getName().resolveBinding(); if (binding instanceof CVariable) { final IASTNode[] decls = ((CVariable) binding).getDeclarations(); - // check if any of the declarations of this var are on heap, because then, all + // check if any of the declarations of this var are on heap, because + // then, all // have to be on heap if (decls != null && decls.length > 0) { for (final IASTNode decl : decls) { @@ -1459,7 +1489,8 @@ public Result visit(final IDispatcher main, final IASTFunctionCallExpression nod public Result visit(final IDispatcher main, final IASTFunctionDefinition node) { if (!isReachable(node)) { - // Unreachable function declaration. Test for parent=TU skipped: Not necessary, + // Unreachable function declaration. Test for parent=TU skipped: Not + // necessary, // right? return new SkipResult(); } @@ -1508,9 +1539,11 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { if ("__PRETTY_FUNCTION__".equals(cId) || "__FUNCTION__".equals(cId)) { // TODO: Was only in SvComp14Handler, but seems useful anywhere final CType returnType = new CPointer(new CPrimitive(CPrimitives.CHAR)); - // final String tId = main.mNameHandler.getTempVarUID(SFO.AUXVAR.NONDET, + // final String tId = + // main.mNameHandler.getTempVarUID(SFO.AUXVAR.NONDET, // returnType); - // final VariableDeclaration tVarDecl = new VariableDeclaration(loc, new + // final VariableDeclaration tVarDecl = new VariableDeclaration(loc, + // new // Attribute[0], new VarList[] { // new VarList(loc, new String[] { tId }, // main.mTypeHandler.constructPointerType(loc)) }); @@ -1518,7 +1551,8 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { final RValue rvalue = new RValue(auxvar.getExp(), returnType); final ArrayList decls = new ArrayList<>(); decls.add(auxvar.getVarDec()); - // final Map auxVars = new LinkedHashMap<>(); + // final Map auxVars = new + // LinkedHashMap<>(); // auxVars.put(auxvar.getVarDec(), loc); return new ExpressionResult(new ArrayList(), rvalue, decls, Collections.singleton(auxvar)); } @@ -1532,8 +1566,10 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { } if ("__func__".equals(cId)) { final CType cType = new CPointer(new CPrimitive(CPrimitives.CHAR)); - // final String tId = mNameHandler.getTempVarUID(SFO.AUXVAR.NONDET, cType); - // final VariableDeclaration tVarDecl = new VariableDeclaration(loc, new + // final String tId = mNameHandler.getTempVarUID(SFO.AUXVAR.NONDET, + // cType); + // final VariableDeclaration tVarDecl = new VariableDeclaration(loc, + // new // Attribute[0], // new VarList[] { new VarList(loc, new String[] { tId }, // mTypeHandler.constructPointerType(loc)) }); @@ -1541,7 +1577,8 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { final RValue rvalue = new RValue(auxvar.getExp(), cType); final ArrayList decls = new ArrayList<>(); decls.add(auxvar.getVarDec()); - // final Map auxVars = new LinkedHashMap<>(); + // final Map auxVars = new + // LinkedHashMap<>(); // auxVars.put(auxvar.getVarDec(), loc); return new ExpressionResult(new ArrayList(), rvalue, decls, Collections.singleton(auxvar)); } @@ -1586,7 +1623,8 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { } return new ExpressionResult(new RValue(stv.getConstantValue(), cType)); } - // } else if (mFunctionHandler.getProcedures().keySet().contains(cId)) { + // } else if + // (mFunctionHandler.getProcedures().keySet().contains(cId)) { } else if (mProcedureManager.hasProcedure(cIdMp)) { // C11 6.3.2.1.4 says: A function designator is an expression that // has function type. @@ -1612,10 +1650,12 @@ public Result visit(final IDispatcher main, final IASTIdExpression node) { LRValue lrVal = null; if (useHeap) { - final IdentifierExpression idExp = // new IdentifierExpression(loc, bId); + final IdentifierExpression idExp = // new IdentifierExpression(loc, + // bId); ExpressionFactory.constructIdentifierExpression(loc, mTypeHandler.getBoogiePointerType(), bId, declarationInformation); - // convention: the ctype in the symbol table of something that we put on the + // convention: the ctype in the symbol table of something that we + // put on the // heap // is the same as it would be if we did not put it on heap lrVal = LRValueFactory.constructHeapLValue(mTypeHandler, idExp, cType, intFromPtr, null); @@ -1685,8 +1725,51 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { assert thenStmt != null; assert elseStmt != null; // TODO : handle if(pointer), if(pointer==NULL) and if(pointer==0) - final IfStatement ifStmt = new IfStatement(loc, cond.getValue(), - thenStmt.toArray(new Statement[thenStmt.size()]), elseStmt.toArray(new Statement[elseStmt.size()])); + // TODO Setting, Count error states for statistics, list all error + // states with identifier for later + // Annotation zur identifikation + // mLogger für statistik + final boolean testGeneration = true; + final IfStatement ifStmt; + if (testGeneration) { + + final ArrayList thenArray = new ArrayList(); + final ArrayList elseArray = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + // assertFalseThen.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", + // tg1); + countTestGoals += 1; + thenArray.add(assertFalseThen); + thenArray.addAll(thenStmt); + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + + final ILocation loc2 = mLocationFactory.createCLocation(node); + final Statement assertFalseElse = + new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); + + final TestGoalAnnotation tg2 = new TestGoalAnnotation(countTestGoals); + countTestGoals += 1; + // assertFalseElse.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", + // tg2); + tg2.annotate(assertFalseElse); + chk.annotate(assertFalseElse); + elseArray.add(assertFalseElse); + elseArray.addAll(elseStmt); + + ifStmt = new IfStatement(loc, cond.getValue(), thenArray.toArray(new Statement[thenArray.size()]), + elseArray.toArray(new Statement[elseArray.size()])); + + } else { + ifStmt = new IfStatement(loc, cond.getValue(), thenStmt.toArray(new Statement[thenStmt.size()]), + elseStmt.toArray(new Statement[elseStmt.size()])); + } + for (final Overapprox overapprItem : overappr) { overapprItem.annotate(ifStmt); } @@ -1695,7 +1778,8 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { } public Result visit(final IDispatcher main, final IASTTypeIdInitializerExpression node) { - // node represents a compound literal (something like "(int []) { 1, 2 }") + // node represents a compound literal (something like "(int []) { 1, 2 + // }") final ILocation loc = mLocationFactory.createCLocation(node); // translate type @@ -1784,7 +1868,8 @@ public Result visit(final IDispatcher main, final IASTTypeIdInitializerExpressio aux = mAuxVarInfoBuilder.constructAuxVarInfoForBlockScope(loc, pointerType, SFO.AUXVAR.COMPOUNDLITERAL, declInfo); builder.addDeclaration(aux.getVarDec()); - // do not add aux var to builder for havoccing here (havoccing is done after + // do not add aux var to builder for havoccing here (havoccing is + // done after // freeing at endScope } @@ -1797,10 +1882,12 @@ public Result visit(final IDispatcher main, final IASTTypeIdInitializerExpressio } else { final LocalLValueILocationPair llvp = new LocalLValueILocationPair(llv, loc); - // malloc auxvar; note that in contrast to on-heap variables, this malloc must + // malloc auxvar; note that in contrast to on-heap variables, + // this malloc must // only happen at the // beginning - // of the scope, not each time the declaration point of the variable/this + // of the scope, not each time the declaration point of the + // variable/this // compound literal is reached mMemoryHandler.addVariableToBeMalloced(llvp); // schedule aux to be freed at scope end @@ -1808,7 +1895,8 @@ public Result visit(final IDispatcher main, final IASTTypeIdInitializerExpressio } } - // write the contents of the compound literal to the memory location designated + // write the contents of the compound literal to the memory location + // designated // by aux final ExpressionResult initialization = mInitHandler.initialize(loc, aux.getLhs(), cType, ir, true, node); builder.addAllExceptLrValue(initialization); @@ -1933,7 +2021,8 @@ public Result visit(final IDispatcher main, final IASTLiteralExpression node) { */ private Result handleStringLiteralExpression(final ILocation loc, final IDispatcher main, final IASTLiteralExpression node) { - // Note: We can either use loc here or create a new ignore-loc s.t. the string + // Note: We can either use loc here or create a new ignore-loc s.t. the + // string // literal assignment will not be shown in the backtranslation final ILocation actualLoc = LocationFactory.createIgnoreCLocation(node); @@ -1959,7 +2048,8 @@ private Result handleStringLiteralExpression(final ILocation loc, final IDispatc } else { auxvar = mAuxVarInfoBuilder.constructGlobalAuxVarInfo(actualLoc, pointerType, SFO.AUXVAR.STRINGLITERAL); addressRValue = new RValue(auxvar.getExp(), arrayType); - // the declaration of the variable that corresponds to a string literal has to + // the declaration of the variable that corresponds to a string + // literal has to // be made global mStaticObjectsHandler.addGlobalVarDeclarationWithoutCDeclaration(auxvar.getVarDec()); ultimateAllocCall = mMemoryHandler.getUltimateMemAllocCall(sizeInBytesExpr, auxvar.getLhs(), actualLoc, @@ -1969,7 +2059,8 @@ private Result handleStringLiteralExpression(final ILocation loc, final IDispatc final List statements = new ArrayList<>(); statements.add(ultimateAllocCall); - // Overapproximate string literals of length STRING_OVERAPPROXIMATION_THRESHOLD + // Overapproximate string literals of length + // STRING_OVERAPPROXIMATION_THRESHOLD // or longer final boolean writeValues = stringLiteral.getByteValues().size() < mSettings.getStringOverapproximationThreshold(); @@ -2029,9 +2120,12 @@ public Result visit(final IDispatcher main, final IASTProblem node) { public Result visit(final IDispatcher main, final IASTProblemDeclaration node) { if (node.getRawSignature().equals("_Noreturn") || node.getRawSignature().equals("noreturn")) { - // Matthias 20230309: It seems like the parser does not support die _Noreturn - // function specifier. It considers this as a IASTProblemDeclaration that is a - // direct child of the translation unit. As a workaround, we skip this node. + // Matthias 20230309: It seems like the parser does not support die + // _Noreturn + // function specifier. It considers this as a IASTProblemDeclaration + // that is a + // direct child of the translation unit. As a workaround, we skip + // this node. return new SkipResult(); } else { final ILocation loc = mLocationFactory.createCLocation(node); @@ -2203,9 +2297,11 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { final Result switchParam = main.dispatch(node.getControllerExpression()); ExpressionResult expr = mExprResultTransformer.switchToRValue((ExpressionResult) switchParam, loc, node.getControllerExpression()); - // 6.8.4.2-1: "The controlling expression of a switch statement shall have + // 6.8.4.2-1: "The controlling expression of a switch statement shall + // have // integer type." - // note that this does not mean that it has "int" type, it may be long or char, + // note that this does not mean that it has "int" type, it may be long + // or char, // for instance assert expr.getLrValue().getCType().isIntegerType(); // 6.8.4.2-5: "The integer promotions are performed on the controlling @@ -2234,12 +2330,14 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { beginScope(); for (final IASTNode child : node.getBody().getChildren()) { if (isFirst && !(child instanceof IASTCaseStatement) && !(child instanceof IASTDefaultStatement)) { - // declarations in the beginning of a switch body (i.e. before the first + // declarations in the beginning of a switch body (i.e. before + // the first // case/default) are used, // statements are dropped // see example 6.8.4.2-7 - // we need to dispatch the child in order to fill the symbol table with + // we need to dispatch the child in order to fill the symbol + // table with // declarations accordingly // the result can only contain statements, which we drop. main.dispatch(child); @@ -2281,7 +2379,8 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { locC = mLocationFactory.createCLocation(child); if (child instanceof IASTCaseStatement) { - // 6.8.4.2-5: "The constant expression in each case label is converted to the + // 6.8.4.2-5: "The constant expression in each case label is + // converted to the // promoted type of the controlling expression" caseExpression = mExpressionTranslation.convertIntToInt(locC, caseExpression, (CPrimitive) expr.getLrValue().getCType()); @@ -2380,7 +2479,8 @@ public Result visit(final IDispatcher main, final IASTTranslationUnit node) { mDeclarations.addAll(acslResultBuilder.getDeclarations()); } - // NOTE: Hack for ACSL was removed; we should first process C and then ACSL. + // NOTE: Hack for ACSL was removed; we should first process C and then + // ACSL. for (final IASTNode child : node.getChildren()) { // Ignore included declarations which might cause problems if (!child.isPartOfTranslationUnitFile()) { @@ -2395,7 +2495,8 @@ public Result visit(final IDispatcher main, final IASTTranslationUnit node) { checkForACSL(main, acslResultBuilder, node, null, false); mDeclarations.addAll(acslResultBuilder.getDeclarations()); - // The declarations (which are needed for the caller) are handled as a member as + // The declarations (which are needed for the caller) are handled as a + // member as // they // do not consist of a Boogie node. // So as a workaround null is returned here @@ -2411,7 +2512,8 @@ public Result visit(final IDispatcher main, final IASTTypeIdExpression node) { final DeclaratorResult dr = (DeclaratorResult) main.dispatch(node.getTypeId().getAbstractDeclarator()); mCurrentDeclaredTypes.pop(); // TypesResult checked = checkForPointer(main, - // node.getTypeId().getAbstractDeclarator().getPointerOperators(), rt, false); + // node.getTypeId().getAbstractDeclarator().getPointerOperators(), + // rt, false); final var rVal = new RValue(mMemoryHandler.calculateSizeOf(loc, dr.getDeclaration().getType()), mTypeSizeComputer.getSizeT()); @@ -2579,7 +2681,7 @@ public RValue decayArrayLrValToPointer(final ILocation loc, final LRValue rightL if (rightLrVal instanceof HeapLValue) { /* * Can happen for example if we have an array in a struct and now are dealing with a pointer to that - * struct. (see for example examples/CToBoogieTranslation/regression/pointerArithOnArrays.c) + * struct. (see for example examples/CToBoogieTranslation/regression/pointerArithOnArrays .c) */ oldValue = ((HeapLValue) rightLrVal).getAddress(); } else { @@ -2689,7 +2791,8 @@ public ExpressionResult makeAssignment(final ILocation loc, final LRValue leftHa builder.addStatements(mMemoryHandler.getWriteCall(loc, hlv, rhsWithBitfieldTreatment, rightHandSideValueWithConversionsApplied.getCType(), false)); - // the value of an assignment statement expression is the right hand side of the + // the value of an assignment statement expression is the right hand + // side of the // assignment builder.setLrValue(rightHandSideValueWithConversionsApplied); for (final Overapprox oa : rhsConverted.getOverapprs()) { @@ -2738,12 +2841,15 @@ public ExpressionResult makeAssignment(final ILocation loc, final LRValue leftHa oa.annotate(stm); } } - // TODO: DD 2020-12-02: havocing neighbours should only happen if the field is + // TODO: DD 2020-12-02: havocing neighbours should only happen if the + // field is // really on the stack -- it // seems that this cannot happen anymore - // final ExpressionResultBuilder builderWithUnionFieldAndNeighboursUpdated = + // final ExpressionResultBuilder + // builderWithUnionFieldAndNeighboursUpdated = // assignOrHavocUnionNeighbours(loc, - // (RValue) rhsConverted.getLrValue(), rhsConverted.getNeighbourUnionFields(), + // (RValue) rhsConverted.getLrValue(), + // rhsConverted.getNeighbourUnionFields(), // rightHandSideValueWithConversionsApplied, builder, hook); // return builderWithUnionFieldAndNeighboursUpdated.build(); @@ -2764,9 +2870,11 @@ public ExpressionResult makeAssignment(final ILocation loc, final LRValue leftHa public void updateStmtsAndDeclsAtScopeEnd(final ExpressionResultBuilder exprResultBuilder, final IASTNode hook) { exprResultBuilder.resetStatements(mMemoryHandler.insertMallocs(exprResultBuilder.getStatements())); for (final SymbolTableValue stv : mSymbolTable.getInnermostCScopeValues(hook)) { - // there may be a null declaration in case of foo(void) -- therefore we need to + // there may be a null declaration in case of foo(void) -- therefore + // we need to // check the second conjunct - // (case where this is called from FunctionHandler.handleFunctionDefinition) + // (case where this is called from + // FunctionHandler.handleFunctionDefinition) if (!stv.isBoogieGlobalVar() && stv.getBoogieDecl() != null) { exprResultBuilder.addDeclaration(stv.getBoogieDecl()); } @@ -2792,7 +2900,8 @@ public void moveArrayAndStructIdsOnHeap(final ILocation loc, final CType underly for (final String id : bie.getIds()) { final String cid = mSymbolTable.getCIdForBoogieId(id); if (cid == null) { - // expression does not have a corresponding c identifier --> nothing to move on + // expression does not have a corresponding c identifier --> + // nothing to move on // heap continue; } @@ -2851,7 +2960,8 @@ private Result handleIASTDeclarator(final IDispatcher main, final ILocation loc, addBoogieIdsOfHeapVars(bId); } - // this is only to have a minimal symbolTableEntry (containing boogieID) for + // this is only to have a minimal symbolTableEntry (containing boogieID) + // for // translation of the initializer mSymbolTable.storeCSymbol(hook, cDec.getName(), new SymbolTableValue(bId, null, null, cDec, declarationInformation, hook, false)); @@ -2892,7 +3002,8 @@ private Result handleIASTDeclarator(final IDispatcher main, final ILocation loc, result = skipOrSideEffects(declResult); } else if (storageClass == CStorageClass.STATIC && !mProcedureManager.isGlobalScope()) { // we have a local static variable -> special treatment - // global static variables are treated like normal global variables.. + // global static variables are treated like normal global + // variables.. boogieDec = new VariableDeclaration(loc, new Attribute[0], new VarList[] { new VarList(loc, new String[] { bId }, translatedType) }); mStaticObjectsHandler.addGlobalVariableDeclaration((VariableDeclaration) boogieDec, cDec); @@ -2927,27 +3038,31 @@ private Result handleIASTDeclarator(final IDispatcher main, final ILocation loc, ExpressionFactory.constructVariableLHS(loc, boogieType, bId, declarationInformation); if (cDec.hasInitializer()) { - // must be a non-real initializer for variable length array size + // must be a non-real initializer for variable length array + // size // --> need to pass this on // TODO: double check this erb.addAllExceptLrValue(cDec.getInitializer().getRootExpressionResult()); } - // no initializer --> essentially needs to be havoced f.i. in each loop + // no initializer --> essentially needs to be havoced f.i. in + // each loop // iteration if (!onHeap) { erb.addStatement(new HavocStatement(loc, new VariableLHS[] { lhs })); } else { final LocalLValue llVal = new LocalLValue(lhs, cDec.getType(), null); // old solution: havoc via an auxvar, new solution (below): - // just malloc at the right place (much shorter for arrays and structs..) + // just malloc at the right place (much shorter for arrays + // and structs..) erb.addStatement(mMemoryHandler.getUltimateMemAllocCall(llVal, loc, MemoryArea.STACK)); mMemoryHandler.addVariableToBeFreed( new LocalLValueILocationPair(llVal, LocationFactory.createIgnoreLocation(loc))); } result = erb.build(); } else if (hasRealInitializer && !mProcedureManager.isGlobalScope() && !isInsideStructDeclaration) { - // in case of a local variable declaration with an initializer, the statements + // in case of a local variable declaration with an initializer, + // the statements // and delcs necessary for the initialization are the result final VariableLHS lhs = ExpressionFactory.constructVariableLHS(loc, boogieType, bId, declarationInformation); @@ -2968,8 +3083,10 @@ private Result handleIASTDeclarator(final IDispatcher main, final ILocation loc, throw new AssertionError("passing side-effects from DeclaratorResults is not yet implemented"); } - // in case of global variables, the result is the declaration, initialization is - // done in the postProcessor in case this simpleDeclaration is part of a struct + // in case of global variables, the result is the declaration, + // initialization is + // done in the postProcessor in case this simpleDeclaration is + // part of a struct // definition, we also need the Declarations as a result result = new DeclarationResult(cDec); } @@ -2979,7 +3096,8 @@ private Result handleIASTDeclarator(final IDispatcher main, final ILocation loc, } // reset the symbol table value with its final contents - // TODO: Unnamed struct fields have cDec.getName() == "" ; is this supposed to + // TODO: Unnamed struct fields have cDec.getName() == "" ; is this + // supposed to // happen? mSymbolTable.storeCSymbol(hook, cDec.getName(), new SymbolTableValue(bId, boogieDec, translatedType, cDec, declarationInformation, hook, false)); @@ -3096,7 +3214,8 @@ private static boolean isGlobal(final IASTDeclarator node) { return true; } if (node instanceof IASTFieldDeclarator) { - // fields in a struct are never global in this sense; the struct may be global + // fields in a struct are never global in this sense; the struct may + // be global return false; } IASTNode parent = node.getParent(); @@ -3216,11 +3335,14 @@ private void checkForACSL(final IDispatcher main, final ExpressionResultBuilder } else if (mAcsl.getSuccessorCNode() == null) { if (parent != null && compoundStatement && next == null) { - // ACSL at the end of a function or at the end of the last statement in a switch + // ACSL at the end of a function or at the end of the last + // statement in a switch // that is not terminated by a break - // TODO: the latter case needs fixing, the ACSL is inserted outside the + // TODO: the latter case needs fixing, the ACSL is inserted + // outside the // corresponding if-scope right now - // example: int s = 1; switch (s) { case 0: s++; //@ assert \false; } will yield + // example: int s = 1; switch (s) { case 0: s++; //@ assert + // \false; } will yield // a unsafe boogie program for (final ACSLNode acslNode : mAcsl.getAcsl()) { final int parentLineEnd = parent.getFileLocation().getEndingLineNumber(); @@ -3232,7 +3354,8 @@ private void checkForACSL(final IDispatcher main, final ExpressionResultBuilder final int parentLineStart = parent.getFileLocation().getStartingLineNumber(); final int acslLineEnd = acslNode.getEndingLineNumber(); if (parentLineEnd < acslLineEnd || parentLineStart > aclsLineStart) { - // TODO: DD: It seems strange that we may skip a single acslNode in this case + // TODO: DD: It seems strange that we may skip a single + // acslNode in this case continue; } @@ -3490,7 +3613,8 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res } if (node instanceof IASTForStatement) { - // add the loop label (continue statements become a jump to the loop label) + // add the loop label (continue statements become a jump to the loop + // label) bodyBlock.add(new Label(loc, loopLabel)); } diff --git a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java index 13292b88237..471f74b78ca 100644 --- a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java +++ b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java @@ -141,6 +141,7 @@ private IsEmptyHeuristic(final AutomataLibraryServices services, mIsGoalState = funIsGoalState; mIsForbiddenState = funIsForbiddenState; mHeuristic = heuristic; + assert startStates != null; assert mIsGoalState != null; assert mIsForbiddenState != null; @@ -201,14 +202,92 @@ private NestedRun getAcceptingRun(final Collection startSt if (mLogger.isDebugEnabled()) { mLogger.debug(String.format("Current: %s", current)); } - if (mIsGoalState.test(current.mTargetState)) { - if (mLogger.isDebugEnabled()) { - mLogger.debug(" Is target"); - printDebugStats(lowestCall, lowestOther, summaries); - } - return current.constructRun(); - } - + final boolean testcomp = true; + // if (mIsGoalState.test(current.mTargetState)) { + // if (testcomp) { + // if (current.mTargetState instanceof SPredicate) { + // if (((SPredicate) current.mTargetState).getProgramPoint().getPayload().getAnnotations() + // .containsKey(TestGoalAnnotation.class.getName())) { + // + // if (((TestGoalAnnotation) ((SPredicate) current.mTargetState).getProgramPoint().getPayload() + // .getAnnotations().get(TestGoalAnnotation.class + // .getName())).mId == ((TestCompHeuristic) heuristic).mHighestErrorStateID) { + // if (mLogger.isDebugEnabled()) { + // mLogger.debug(" Is target with testgoal Id: " + // + ((TestCompHeuristic) heuristic).mHighestErrorStateID); + // printDebugStats(lowestCall, lowestOther, summaries); + // } + // + // return current.constructRun(); + // } + // + // } + // } else if (current.mTargetState instanceof UnknownState) { + // if (((UnknownState) current.mTargetState).getProgramPoint().getPayload().getAnnotations() + // .containsKey(TestGoalAnnotation.class.getName())) { + // + // if (((TestGoalAnnotation) ((UnknownState) current.mTargetState).getProgramPoint() + // .getPayload().getAnnotations().get(TestGoalAnnotation.class + // .getName())).mId == ((TestCompHeuristic) heuristic).mHighestErrorStateID) { + // if (mLogger.isDebugEnabled()) { + // mLogger.debug(" Is target with testgoal Id: " + // + ((TestCompHeuristic) heuristic).mHighestErrorStateID); + // printDebugStats(lowestCall, lowestOther, summaries); + // } + // + // return current.constructRun(); + // } + // + // } + // } else { + // if (mIsGoalState.test(current.mTargetState)) { + // if (mLogger.isDebugEnabled()) { + // mLogger.debug(" Is target"); + // printDebugStats(lowestCall, lowestOther, summaries); + // } + // return current.constructRun(); + // } + // } + // + // } else { + // if (mIsGoalState.test(current.mTargetState)) { + // + // if (current.mTargetState instanceof SPredicate) { + // if (((SPredicate) current.mTargetState).getProgramPoint().getPayload().getAnnotations() + // .containsKey(TestGoalAnnotation.class.getName())) { + // + // if (((TestCompHeuristic) heuristic).mTestGoalTodoStack + // .contains(((TestGoalAnnotation) ((SPredicate) current.mTargetState) + // .getProgramPoint().getPayload().getAnnotations() + // .get(TestGoalAnnotation.class.getName())).mId)) { + // + // return current.constructRun(); + // } + // + // } + // } else if (current.mTargetState instanceof UnknownState) { + // if (((UnknownState) current.mTargetState).getProgramPoint().getPayload().getAnnotations() + // .containsKey(TestGoalAnnotation.class.getName())) { + // + // if (((TestCompHeuristic) heuristic).mTestGoalTodoStack + // .contains(((TestGoalAnnotation) ((UnknownState) current.mTargetState) + // .getProgramPoint().getPayload().getAnnotations() + // .get(TestGoalAnnotation.class.getName())).mId)) { + // + // return current.constructRun(); + // } + // + // } + // } + // + // // if (mLogger.isDebugEnabled()) { + // // mLogger.debug(" Is target"); + // // printDebugStats(lowestCall, lowestOther, summaries); + // // } + // // return current.constructRun(); + // } + // } + // } final List stragglingSummaries; if (current.mItemType == ItemType.RETURN) { stragglingSummaries = updateSummaries(summaries, usedSummaries, current); @@ -247,7 +326,8 @@ private NestedRun getAcceptingRun(final Collection startSt } if (lowestCostSoFar != null && costSoFar >= lowestCostSoFar) { - // we have already seen this successor but with a lower cost, so we should not explore with a + // we have already seen this successor but with a lower + // cost, so we should not explore with a // higher cost if (mLogger.isDebugEnabled()) { mLogger.debug(String.format(" Skip (cost %s, but have seen with cost %s)", costSoFar, @@ -257,9 +337,12 @@ private NestedRun getAcceptingRun(final Collection startSt } if (succ.mItemType == ItemType.CALL && !isCheapestAncestor(lowestCall, discoveredUniqueReturnStates, succ, costSoFar)) { - // if the succ is not yet in lowest, there can still be an item with a call stack that has the - // same ancestor as the current succ -- if this item is cheaper, we do not insert. - // TODO: isCheapestAncestor is rather expensive, but with a dedicated data structure it could be + // if the succ is not yet in lowest, there can still be an + // item with a call stack that has the + // same ancestor as the current succ -- if this item is + // cheaper, we do not insert. + // TODO: isCheapestAncestor is rather expensive, but with a + // dedicated data structure it could be // much cheaper, e.g., something similar to a suffix tree delayedCalls.computeIfAbsent(current.getHierPreState(), a -> new LinkedHashSet<>()).add(succ); continue; @@ -269,7 +352,8 @@ private NestedRun getAcceptingRun(final Collection startSt heuristic.getHeuristicValue(succ.mTargetState, succ.getHierPreState(), succ.mLetter); succ.setEstimatedCostToTarget(expectedCostToTarget); - // we changed the cost of this item, so we have to remove it if it is already in the queue, because + // we changed the cost of this item, so we have to remove it if + // it is already in the queue, because // its queue position will not be updated otherwise if (worklist.remove(succ)) { if (mLogger.isDebugEnabled()) { @@ -286,7 +370,9 @@ private NestedRun getAcceptingRun(final Collection startSt } } } - if (mLogger.isDebugEnabled()) { + if (mLogger.isDebugEnabled()) + + { printDebugStats(lowestCall, lowestOther, summaries); } return null; @@ -322,10 +408,13 @@ private List addCostAndSummaries(final List succs, final Map summary = summaries.get(callTrans); if (summary != null) { assert !summary.isEmpty(); - // there is a summary for this call and we are going to use it. - // we need to record that we used a summary in case we find more summaries later (straggling + // there is a summary for this call and we are going to use + // it. + // we need to record that we used a summary in case we find + // more summaries later (straggling // summaries) - // we save the cost of the current location in the successor item, so we may use it for straggling + // we save the cost of the current location in the successor + // item, so we may use it for straggling // summaries succ.setCostSoFar(currentCostSoFar + concreteCost); final Map> usedSummariesForCall = @@ -356,7 +445,8 @@ private List addCostAndSummaries(final List succs, private List updateSummaries(final Map> summaries, final Map>> usedSummaries, final Item returnItem) { - // the current item is a return (returnItem), so we can compute a new summary + // the current item is a return (returnItem), so we can compute a new + // summary final Item callItem = returnItem.findCorrespondingCallItem(); final CallTransition callTrans = new CallTransition(callItem); @@ -372,7 +462,8 @@ private List updateSummaries(final Map> usedSummariesForCall = usedSummaries.get(callTrans); if (usedSummariesForCall != null) { @@ -424,14 +515,16 @@ private boolean isCheapestAncestor(final Map lowest, final double lowestCostSoFar = entry.getValue(); if (item.mHierPreStates.size() >= succ.mHierPreStates.size()) { - // item cannot be prefix, is either longer, or, if it is the same length, has a different + // item cannot be prefix, is either longer, or, if it is the + // same length, has a different // hashcode (checked before) continue; } final int extension = discoveredUniqueReturnStates.getOrDefault(succ.getHierPreState(), Collections.emptySet()).size(); if (item.isHierStatesPrefixOf(succ, extension) && costSoFar >= lowestCostSoFar) { - // we have already seen this successor but with a lower cost, so we should not explore + // we have already seen this successor but with a lower cost, so + // we should not explore // with a higher cost if (mLogger.isDebugEnabled()) { mLogger.debug(String.format( @@ -488,7 +581,8 @@ private List getUnvaluatedSuccessors(final Item current, rtr.add(new Item(succ, null, symbol, current, ItemType.RETURN)); } if (old != rtr.size()) { - // we found a new state from which a hierPre call can take at least one return + // we found a new state from which a hierPre call can take at least + // one return discoveredUniqueReturnStates.computeIfAbsent(hierPre, a -> new HashSet<>()).add(current.mTargetState); final Set hierDelayedCalls = delayedCalls.remove(hierPre); @@ -649,7 +743,8 @@ private interface IWithBackPointer { private class SummaryItem implements IWithBackPointer { - // the actual cost of this summary, i.e., the cost of the subpath in this summary + // the actual cost of this summary, i.e., the cost of the subpath in + // this summary private final double mSummaryCost; private final NestedRun mSubrun; private final IWithBackPointer mBackPointer; @@ -730,7 +825,8 @@ public class Item implements Comparable, IWithBackPointer { private double mCostSoFar; // h-value, i.e., how expensive from here to target using this node private double mEstimatedCostToTargetFromHere; - // f-value, i.e. how expensive from start to target if we use this node, i.e. g+h + // f-value, i.e. how expensive from start to target if we use this node, + // i.e. g+h private double mEstimatedCostToTarget; /** @@ -840,10 +936,12 @@ public boolean isHierStatesPrefixOf(final Item other, int maxExtension) { } if (iter.hasNext()) { - // we have more items, but the other one does not, so we are not a prefix + // we have more items, but the other one does not, so we are not + // a prefix return false; } - // we are a prefix of other, but we are lenient for up to maxExtension: + // we are a prefix of other, but we are lenient for up to + // maxExtension: while (otherIter.hasNext() && maxExtension > 0) { maxExtension--; otherIter.next(); @@ -1084,7 +1182,7 @@ public LETTER getLetter() { } public enum AStarHeuristic { - ZERO, RANDOM_HALF, RANDOM_FULL, SMT_FEATURE_COMPARISON + ZERO, RANDOM_HALF, RANDOM_FULL, SMT_FEATURE_COMPARISON, TESTCOMP } /** @@ -1119,6 +1217,19 @@ public static IHeuristic getHeuristic(final AStar } } + public static IHeuristic getHeuristic(final AStarHeuristic astarHeuristic, + final ScoringMethod scoringMethod, final long seed, final Integer testGoalWithHighesID, + final List testGoalTodoStack) { + switch (astarHeuristic) { + + case TESTCOMP: + return IHeuristic.getTestCompHeuristic(testGoalWithHighesID, testGoalTodoStack); + default: + throw new UnsupportedOperationException("Unknown heuristic: " + astarHeuristic.toString()); + + } + } + public static IHeuristic getZeroHeuristic() { return new IHeuristic() { @Override @@ -1175,6 +1286,11 @@ public final double getConcreteCost(final LETTER e) { return new SmtFeatureHeuristic<>(scoringMethod); } + public static TestCompHeuristic + getTestCompHeuristic(final Integer testGoalWithHighesID, final List testGoalTodoStack) { + return new TestCompHeuristic<>(testGoalWithHighesID, testGoalTodoStack); + } + } /** diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index e1bf5ac2b34..ece6bf547e8 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -61,6 +61,7 @@ import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; +import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; import de.uni_freiburg.informatik.ultimate.logic.QuotedObject; import de.uni_freiburg.informatik.ultimate.logic.SMTLIBException; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; @@ -325,7 +326,8 @@ protected FeasibilityCheckResult checkTrace() { result = new FeasibilityCheckResult(isSafe, tcru, false); } catch (final SMTLIBException e) { if (!mServices.getProgressMonitorService().continueProcessing()) { - // there was a cancellation request, probably responsible for abnormal solver termination + // there was a cancellation request, probably responsible for + // abnormal solver termination result = new FeasibilityCheckResult(LBool.UNKNOWN, new TraceCheckReasonUnknown(Reason.ULTIMATE_TIMEOUT, null, ExceptionHandlingCategory.KNOWN_IGNORE), true); } else { @@ -368,8 +370,10 @@ private IcfgProgramExecution computeRcfgProgramExecutionAndDecodeBranches(fin case UNKNOWN: final Exception ex = tc.getTraceCheckReasonUnknown().getException(); if (ex instanceof ToolchainCanceledException || ex instanceof AutomataOperationCanceledException) { - // TODO: 20210701 DD: It might be useful to set a higher timeout for a TraceCheck here because the - // chance of getting a program execution if the previous TC was already successful is high. + // TODO: 20210701 DD: It might be useful to set a higher + // timeout for a TraceCheck here because the + // chance of getting a program execution if the previous TC + // was already successful is high. throw new ToolchainCanceledException((IRunningTaskStackProvider) ex, new RunningTaskInfo(getClass(), "computing program execution")); } @@ -419,18 +423,40 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild funGetValue = this::getValue; } + final TestVector testV = new TestVector(); + for (final var entry : nsb.getIndexedVarRepresentative().entrySet()) { final IProgramVar bv = entry.getKey(); final Map indexedRepresentatives = entry.getValue(); if (SmtUtils.isSortForWhichWeCanGetValues(bv.getTermVariable().getSort())) { + boolean firstRepresentatives = true; for (final var representative : indexedRepresentatives.entrySet()) { final Integer index = representative.getKey(); final Term indexedVar = representative.getValue(); final Term valueT = funGetValue.apply(indexedVar); + if (indexedVar instanceof ApplicationTerm) { + assert ((ApplicationTerm) indexedVar).getParameters().length == 0; + if (indexedVar.toStringDirect().contains("nondet") && firstRepresentatives) { + assert indexedRepresentatives.entrySet().size() == 2; + // TODO Not sure if save, but by far the best solution + testV.addValueAssignment(valueT, index); // Only if nondetINT!! + firstRepresentatives = false; + } + + } rpeb.addValueAtVarAssignmentPosition(bv, index, valueT); + } } } + + try { + TestExporter.getInstance().exportTests(testV, rpeb.mTrace.hashCode()); + } catch (final Exception e) { + // TODO TestGeneration Auto-generated catch block + e.printStackTrace(); + } + cleanupAndUnlockSolver(); return rpeb.getIcfgProgramExecution(); } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java index 5def7bb39e8..f97d62a05cb 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java @@ -101,8 +101,9 @@ public enum Spec { */ MALLOC_NONNEGATIVE, /** - * Pointer arithmetic that is not allowed by C. E.g. - computing the difference of two pointers that point to - * completely different arrays - comparing pointers that point to completely different arrays + * Pointer arithmetic that is not allowed by C. E.g. - computing the + * difference of two pointers that point to completely different arrays + * - comparing pointers that point to completely different arrays */ ILLEGAL_POINTER_ARITHMETIC, /** @@ -157,6 +158,8 @@ public enum Spec { */ CHC_SATISFIABILITY, + TEST_GOAL_ANNOTATION, + } private static final long serialVersionUID = -3753413284642976683L; @@ -170,10 +173,16 @@ public enum Spec { private final Function mNegMsgProvider; + private Integer testId; + public Check(final Check.Spec spec) { this(EnumSet.of(spec)); } + public Check(final Check.Spec spec, final Integer testId) { + this(EnumSet.of(spec)); + } + public Check(final Check.Spec spec, final Function funPositiveMessageProvider, final Function funNegativeMessageProvider) { this(EnumSet.of(spec), funPositiveMessageProvider, funNegativeMessageProvider); @@ -267,6 +276,7 @@ public static String getDefaultPositiveMessage(final Spec spec) { return "there are no data races"; case CHC_SATISFIABILITY: return "the set of constraint Horn clauses is satisfiable"; + default: return "a specification is correct but has no positive message: " + spec; } @@ -342,10 +352,27 @@ public IAnnotations merge(final IAnnotations other) { final EnumSet newSpec = EnumSet.copyOf(mSpec); newSpec.addAll(otherCheck.getSpec()); - // note: automatic merging looses all information about message providers and uses the default ones + // note: automatic merging looses all information about message + // providers and uses the default ones return new Check(newSpec); } + /** + * Adds this Check object to the annotations of a IElement. + * + * @param node + * the element + */ + public void annotate(final IElement node, final int countTestGoals) { + if (mSpec.equals(Spec.TEST_GOAL_ANNOTATION)) { + final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + node.getPayload().getAnnotations().put(KEY, tg1); + } else { + node.getPayload().getAnnotations().put(KEY, this); + } + + } + /** * Adds this Check object to the annotations of a IElement. * @@ -353,11 +380,14 @@ public IAnnotations merge(final IAnnotations other) { * the element */ public void annotate(final IElement node) { + node.getPayload().getAnnotations().put(KEY, this); + } /** - * Return the checked specification that is checked at this location or null. + * Return the checked specification that is checked at this location or + * null. */ public static Check getAnnotation(final IElement node) { return ModelUtils.getAnnotation(node, KEY, a -> (Check) a); diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java index db7e8324ae5..04b650c1c43 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java @@ -494,9 +494,8 @@ private BoogieIcfgLocation addErrorNode(final String procName, final BoogieASTNo } /** - * Check it this statement is a plain assume true statement, i.e. whether - * * it has an empty list of attributes or no attributes at all, and - * * it is not annotated with an LTLStepAnnotation. + * Check it this statement is a plain assume true statement, i.e. whether * it has an empty list of + * attributes or no attributes at all, and * it is not annotated with an LTLStepAnnotation. */ private static boolean isPlainAssumeTrueStatement(final Statement st) { if (st instanceof AssumeStatement) { @@ -1194,7 +1193,19 @@ private void processAssuAssiHavoStatement(final Statement st, final Origin origi switch (mCodeBlockSize) { case LoopFreeBlock: case SequenceOfStatements: - addStatementToStatementSequenceThatIsCurrentlyBuilt(st); + // addStatementToStatementSequenceThatIsCurrentlyBuilt(st); + // break; + // case SequenceOfStatementsWithTestComp: //TODO TestGeneration Setting + if (st instanceof HavocStatement) { + if (st.getPayload().toString().contains("__VERIFIER_nondet_")) { + // TODO better + endCurrentStatementSequence(st); + startNewStatementSequenceAndAddStatement(st, origin); + } + + } else { + addStatementToStatementSequenceThatIsCurrentlyBuilt(st); + } break; case OneNontrivialStatement: if (((StatementSequence) mCurrent).isTrivial() || StatementSequence.isAssumeTrueStatement(st)) { @@ -1567,18 +1578,18 @@ private void processAtomicStatement(final String procName, final AtomicStatement } /** - * Merge one LocNode into another. The oldLocNode will be merged into the - * newLocNode. The newLocNode gets connected to all incoming/outgoing - * transitions of the oldLocNode. The oldLocNode looses connections to all - * incoming/outgoing transitions. If the oldLocNode was representative for a - * Label the new location will from now on be the representative of this Label. + * Merge one LocNode into another. The oldLocNode will be merged into the newLocNode. The newLocNode gets + * connected to all incoming/outgoing transitions of the oldLocNode. The oldLocNode looses connections to all + * incoming/outgoing transitions. If the oldLocNode was representative for a Label the new location will from + * now on be the representative of this Label. * - * @param oldLocNode LocNode that gets merged into the newLocNode. Must - * not represent an error location. - * @param newLocNode LocNode that absorbes the oldLocNode. - * @param copyAllAnnotations If `true` then we copy all annotations from the old - * node to the new node, if `false` we copy all - * annotations by the {@link ILocation}. + * @param oldLocNode + * LocNode that gets merged into the newLocNode. Must not represent an error location. + * @param newLocNode + * LocNode that absorbes the oldLocNode. + * @param copyAllAnnotations + * If `true` then we copy all annotations from the old node to the new node, if `false` we copy all + * annotations by the {@link ILocation}. */ private void mergeLocNodes(final BoogieIcfgLocation oldLocNode, final BoogieIcfgLocation newLocNode, final boolean copyAllAnnotations) { diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java index c018b0c8862..6a5832fa51f 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java @@ -42,7 +42,7 @@ public class RcfgPreferenceInitializer extends UltimatePreferenceInitializer { public enum CodeBlockSize { - SingleStatement, OneNontrivialStatement, SequenceOfStatements, LoopFreeBlock + SingleStatement, OneNontrivialStatement, SequenceOfStatements, LoopFreeBlock, SequenceOfStatementsForTestComp } // some solver commands diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index cfac4d6a58e..70978bcaa0b 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -59,6 +59,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.TaskCanceledException.UserDefinedLimit; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainExceptionWrapper; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.lib.results.UnprovabilityReason; import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; @@ -79,6 +80,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.HoareAnnotation; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicateUnifier; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.ISLPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.PredicateFactory; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.taskidentifier.SubtaskFileIdentifier; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.taskidentifier.TaskIdentifier; @@ -449,11 +451,13 @@ private void iterate() throws AutomataLibraryException { mResultBuilder.addResult(currentErrorLoc, result, IcfgProgramExecution.create(mCounterexample.getWord().asList(), Collections.emptyMap()), e, null); + mLogger.warn("Local analysis aborted during iteration targeting %s because %s: %s", currentErrorLoc, result, e.printRunningTaskMessage()); final long remainingTime = mServices.getProgressMonitorService().remainingTime(); if (remainingTime == 0 || mResultBuilder.remainingErrorLocs() <= 0) { - // if we do not have anymore time or any more error locations, end + // if we do not have anymore time or any more error + // locations, end return; } mLogger.warn("Still %s and %s left, trying to recover", @@ -522,7 +526,33 @@ private IcfgLocation getErrorLocFromCounterexample() { private AutomatonType processFeasibilityCheckResult(final LBool isCounterexampleFeasible, final IProgramExecution programExecution, final IcfgLocation currentErrorLoc) { if (isCounterexampleFeasible == Script.LBool.SAT) { - mResultBuilder.addResultForProgramExecution(Result.UNSAFE, programExecution, null, null); + + // TODO TestGeneration Setting + final boolean testcomp = true; + if (testcomp) { + final List sequence = mCounterexample.getStateSequence(); + for (int i = 0; i < sequence.size(); i++) { + if (sequence.get(i) instanceof ISLPredicate) { + final ISLPredicate stmt = (ISLPredicate) sequence.get(i); + if (stmt.getProgramPoint().getPayload().getAnnotations() + .containsKey(TestGoalAnnotation.class.getName())) { + for (final IcfgLocation node : stmt.getProgramPoint().getOutgoingNodes()) { + if (sequence.get(i) instanceof ISLPredicate) { + if (node.getPayload().getAnnotations() + .containsKey(TestGoalAnnotation.class.getName())) { + mResultBuilder.addResult(node, Result.UNSAFE, null, null, null); + } + } + } + + } + + } + } + } else { + mResultBuilder.addResultForProgramExecution(Result.UNSAFE, programExecution, null, null); + } + if (mPref.stopAfterFirstViolation()) { mResultBuilder.addResultForAllRemaining(Result.UNKNOWN); } @@ -797,6 +827,7 @@ public CegarLoopResultBuilder addResultForProgramExecution(final Result result, final AtomicTraceElement lastElem = programExecution.getTraceElement(programExecution.getLength() - 1); final IcfgLocation loc = lastElem.getStep().getTarget(); return addResult(loc, result, programExecution, rtsp, reasonUnknown); + } public CegarLoopResultBuilder addResult(final IcfgLocation loc, final Result result, diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 8c1ea3d927e..e8affe3580f 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -63,6 +64,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.TaskCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.TaskCanceledException.UserDefinedLimit; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.lib.results.DangerInvariantResult; import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; @@ -132,6 +134,11 @@ public class NwaCegarLoop> extends BasicCegarLoop mTestGoalTodoStack = new ArrayList<>(); + private final List mTestGoalsInCurrentTrace = new ArrayList<>(); + private Integer mTestGoalWithHighesID = super.mErrorLocs.size() - 1; + public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton initialAbstraction, final IIcfg rootNode, final CfgSmtToolkit csToolkit, final PredicateFactory predicateFactory, final TAPreferences taPrefs, final Set errorLocs, @@ -152,15 +159,33 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton abstraction = mAbstraction; - + System.out.println(mTestGoalTodoStack); mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.EmptinessCheckTime); try { - if (mUseHeuristicEmptinessCheck) { + + if (!mTestGoalTodoStack.isEmpty() && mLongTraceOptimization) { // TODO + + mCounterexample = + new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, + IHeuristic.getHeuristic(AStarHeuristic.TESTCOMP, mScoringMethod, + mAStarRandomHeuristicSeed, mTestGoalWithHighesID, mTestGoalTodoStack)) + .getNestedRun(); + + assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; + } else if (mUseHeuristicEmptinessCheck) { mCounterexample = new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, IHeuristic.getHeuristic(mAStarHeuristic, mScoringMethod, mAStarRandomHeuristicSeed)) .getNestedRun(); @@ -178,6 +203,39 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException if (mCounterexample == null) { return true; } + // 1. Wir wollen, dass alle errorstates entlang dieses traces + // (irreführend) durch den automaten abgedeckt werden, + // sodass die trace abstraction diese nicht länger berücksichtigt + // (müssen dann alle als covered in die statistk) + + // Wir wollen, dass ein Error state gewählt wird mit hohem Index + // final SimpleErrorAutomatonBuilder eab = new + // SimpleErrorAutomatonBuilder(mServices, mPredicateFactory, null, + // mCsToolkit, mPredicateFactoryInterpolantAutomata, mAbstraction, + // null); + + final List a = mCounterexample.getStateSequence(); + String print = ""; + final boolean coeringError = false; + for (int i = 0; i < a.size(); i++) { + if (a.get(i) instanceof ISLPredicate) { + final ISLPredicate stmt = (ISLPredicate) a.get(i); + if (stmt.getProgramPoint().getPayload().getAnnotations() + .containsKey(TestGoalAnnotation.class.getName())) { + print = print + " " + ((TestGoalAnnotation) stmt.getProgramPoint().getPayload().getAnnotations() + .get(TestGoalAnnotation.class.getName())).mId; + // coeringError = true; + mTestGoalsInCurrentTrace.add(((TestGoalAnnotation) stmt.getProgramPoint().getPayload() + .getAnnotations().get(TestGoalAnnotation.class.getName())).mId); + } + + } + } + System.out.println(print); + // TODO error atuomaton + + // TODO loop wenn mProgramPoint hat payload mit annotation + // testgeneradings if (mPref.dumpAutomata()) { mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.DumpTime); @@ -278,7 +336,6 @@ protected void constructErrorAutomaton() throws AutomataOperationCanceledExcepti mRefinementResult.getPredicateUnifier(), mCsToolkit, mSimplificationTechnique, mXnfConversionTechnique, mIcfg.getCfgSmtToolkit().getSymbolTable(), mPredicateFactoryInterpolantAutomata, mAbstraction, mIteration); - mInterpolAutomaton = null; final NestedWordAutomaton resultBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); @@ -311,6 +368,8 @@ protected boolean refineAbstraction() throws AutomataLibraryException { enhanceMode = mErrorGeneralizationEngine.getEnhancementMode(); subtrahendBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); subtrahend = mErrorGeneralizationEngine.getResultAfterEnhancement(); + mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); + // mTestGoalTodoStack.clear(); } else { automatonType = AutomatonType.FLOYD_HOARE; useErrorAutomaton = false; @@ -318,9 +377,17 @@ protected boolean refineAbstraction() throws AutomataLibraryException { subtrahendBeforeEnhancement = mInterpolAutomaton; enhanceMode = mPref.interpolantAutomatonEnhancement(); subtrahend = enhanceInterpolantAutomaton(enhanceMode, predicateUnifier, htc, subtrahendBeforeEnhancement); + + if (!mTestGoalTodoStack.isEmpty()) { + mTestGoalTodoStack.remove(mTestGoalTodoStack.get(mTestGoalTodoStack.size() - 1)); + } + } + if (!mTestGoalTodoStack.isEmpty()) { + mTestGoalWithHighesID = mTestGoalTodoStack.get(mTestGoalTodoStack.size() - 1); } - // TODO: HTC and predicateunifier statistics are saved in the following method, but it seems better to save them + // TODO: HTC and predicateunifier statistics are saved in the following + // method, but it seems better to save them // at the end of the htc lifecycle instead of there computeAutomataDifference(minuend, subtrahend, subtrahendBeforeEnhancement, predicateUnifier, exploitSigmaStarConcatOfIa, htc, enhanceMode, useErrorAutomaton, automatonType); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java index ba1cecc199a..ba780af3b0b 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java @@ -195,7 +195,7 @@ public void constructErrorAutomaton(final IRun counterexample, final Predi switch (type) { case SIMPLE_ERROR_AUTOMATON: mErrorAutomatonBuilder = new SimpleErrorAutomatonBuilder<>(mServices, predicateFactory, - predicateUnifier, csToolkit, stateFactoryForAutomaton, abstraction, trace); + predicateUnifier, csToolkit, stateFactoryForAutomaton, abstraction, counterexample); break; case ERROR_AUTOMATON: mErrorAutomatonBuilder = new ErrorAutomatonBuilder<>(mServices, predicateFactory, predicateUnifier, @@ -210,6 +210,7 @@ public void constructErrorAutomaton(final IRun counterexample, final Predi default: throw new IllegalArgumentException("Unknown automaton type: " + type); } + } catch (final ToolchainCanceledException tce) { mErrorAutomatonStatisticsGenerator.stopErrorAutomatonConstructionTime(); mErrorAutomatonStatisticsGenerator.finishAutomatonInstance(); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java index a3b1a8c07c3..654e0029330 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java @@ -26,18 +26,25 @@ */ package de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.errorabstraction; +import java.util.Iterator; +import java.util.List; + import de.uni_freiburg.informatik.ultimate.automata.AutomataLibraryServices; +import de.uni_freiburg.informatik.ultimate.automata.IRun; import de.uni_freiburg.informatik.ultimate.automata.nestedword.INestedWordAutomaton; import de.uni_freiburg.informatik.ultimate.automata.nestedword.INwaOutgoingLetterAndTransitionProvider; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWordAutomataUtils; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWordAutomaton; import de.uni_freiburg.informatik.ultimate.automata.nestedword.VpAlphabet; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IIcfgTransition; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IcfgLocation; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicateUnifier; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.ISLPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.PredicateFactory; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.PredicateFactoryForInterpolantAutomata; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TAPreferences.InterpolantAutomatonEnhancement; @@ -56,10 +63,13 @@ public class SimpleErrorAutomatonBuilder> implement public SimpleErrorAutomatonBuilder(final IUltimateServiceProvider services, final PredicateFactory predicateFactory, final IPredicateUnifier predicateUnifier, final CfgSmtToolkit csToolkit, final PredicateFactoryForInterpolantAutomata predicateFactoryErrorAutomaton, - final INestedWordAutomaton abstraction, final NestedWord trace) { + final INestedWordAutomaton abstraction, final IRun counterexample) { + final NestedWord trace = (NestedWord) counterexample.getWord(); mTruePredicate = predicateUnifier.getTruePredicate(); mResult = constructStraightLineAutomaton(services, csToolkit, predicateFactory, predicateUnifier, predicateFactoryErrorAutomaton, NestedWordAutomataUtils.getVpAlphabet(abstraction), trace); + addCoveredTestGoalsToErrorAutomaton(trace, counterexample, abstraction); + } private NestedWordAutomaton constructStraightLineAutomaton(final IUltimateServiceProvider services, @@ -97,6 +107,81 @@ private NestedWordAutomaton constructStraightLineAutomaton(final return nwa; } + private void addCoveredTestGoalsToErrorAutomaton(final NestedWord trace, final IRun counterexample, + final INwaOutgoingLetterAndTransitionProvider abstraction) { + System.out.println("HELP2"); + + final List sequence = counterexample.getStateSequence(); + for (int i = 0; i < sequence.size(); i++) { + final IPredicate errorStatePredecessor = (IPredicate) sequence.get(i); + if (stateIsTestGoalButNoErrorLocation((ISLPredicate) errorStatePredecessor)) { + final Integer testGoalId = getTestGoalId((ISLPredicate) errorStatePredecessor); + for (final IPredicate errorState : ((INestedWordAutomaton) abstraction) + .getFinalStates()) { + if (errorStateIsTestGoalWithId((ISLPredicate) errorState, testGoalId)) { + mResult.addState(false, true, errorState); + + for (final Iterator it = mResult.getInitialStates().iterator(); it.hasNext();) { + final IPredicate f = it.next(); + + final L letter = ((L) trace.getSymbol(i).getSource().getOutgoingEdges().get(0).getLabel()); + mResult.addInternalTransition(f, letter, errorState); + break; + } + + } + + } + } + + } + + } + + /* + * caller has to ensure state is an errorState with testgoal annotation + */ + private boolean errorStateIsTestGoalWithId(final ISLPredicate state, final Integer testGoalId) { + if (((TestGoalAnnotation) state.getProgramPoint().getPayload().getAnnotations() + .get(TestGoalAnnotation.class.getName())).mId == testGoalId) { + return true; + + } + return false; + } + + private boolean stateIsTestGoalButNoErrorLocation(final ISLPredicate state) { + if (state.getProgramPoint().getSuccessors().isEmpty()) { + return false; + } + + if (state.getProgramPoint().getPayload().getAnnotations().containsKey(TestGoalAnnotation.class.getName())) { + for (final IcfgLocation node : state.getProgramPoint().getOutgoingNodes()) { + if (state instanceof ISLPredicate) { + if (node.getPayload().getAnnotations().containsKey(TestGoalAnnotation.class.getName())) { + return true; + + } + } + } + + } + + return false; + + } + + private int getTestGoalId(final ISLPredicate state) { + if (state.getProgramPoint().getPayload().getAnnotations().containsKey(TestGoalAnnotation.class.getName())) { + return ((TestGoalAnnotation) state.getProgramPoint().getPayload().getAnnotations() + .get(TestGoalAnnotation.class.getName())).mId; + + } else { + return -1; + } + + } + @Override public NestedWordAutomaton getResultBeforeEnhancement() { return mResult; diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java index 98f42e9214f..bd9c20fb24d 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java @@ -94,7 +94,8 @@ public void setInputDefinition(final ModelType graphType) { @Override public List getObservers() { if (mMatchingModel) { - // we should create this class somewere in cacsl s.t. we get the correct parameters -- perhaps translation + // we should create this class somewere in cacsl s.t. we get the + // correct parameters -- perhaps translation // service mRCFGCatcher = new RCFGCatcher(); return Collections.singletonList(mRCFGCatcher); @@ -127,6 +128,11 @@ public void finish() { .flatMap(a -> a.getValue().stream()).collect(Collectors.toList()); final WitnessManager cexVerifier = new WitnessManager(mLogger, mServices); + final boolean TestCompMetaFileTODO = true; + if (TestCompMetaFileTODO) { // TODO + mLogger.info("Generating MetaFile for TestComp Reults"); + generateMetaFile(cexVerifier, results); + } if (results.stream().anyMatch(a -> a instanceof CounterExampleResult)) { mLogger.info("Generating witness for reachability counterexample"); generateReachabilityCounterexampleWitness(cexVerifier, results); @@ -140,11 +146,24 @@ public void finish() { mLogger.info("No result that supports witness generation found"); } - } catch (IOException | InterruptedException e) { + } catch (final Exception e) { throw new RuntimeException(e); } } + // creates a MetaFile with the descriptions necessary for the TestComp + private void generateMetaFile(final WitnessManager cexVerifier, final List results) throws Exception { + final IBacktranslationService backtrans = mServices.getBacktranslationService(); + final BoogieIcfgContainer root = mRCFGCatcher.getModel(); + final String filename = ILocation.getAnnotation(root).getFileName(); + final BacktranslatedCFG origCfg = + new BacktranslatedCFG<>(filename, IcfgGraphProvider.getVirtualRoot(root), IcfgEdge.class); + + final TestCompMetaFilePrinter asd = + new TestCompMetaFilePrinter(backtrans.translateCFG(origCfg), mLogger, mServices); + + } + private void generateProofWitness(final WitnessManager cexVerifier, final List results) throws IOException, InterruptedException { final AllSpecificationsHoldResult result = From 1ec07da0829088ade294aefa7bd5b8904387cef7 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 7 Aug 2023 15:15:53 +0200 Subject: [PATCH 002/278] Bugfix and NullPointer Check --- .../singletracecheck/IcfgProgramExecutionBuilder.java | 2 +- .../errorabstraction/SimpleErrorAutomatonBuilder.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/IcfgProgramExecutionBuilder.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/IcfgProgramExecutionBuilder.java index 25f93da0061..61fae4088c3 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/IcfgProgramExecutionBuilder.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/IcfgProgramExecutionBuilder.java @@ -52,7 +52,7 @@ public class IcfgProgramExecutionBuilder { private final ModifiableGlobalsTable mModifiableGlobalVariableManager; - private final NestedWord mTrace; + public final NestedWord mTrace; private final Map> mVar2Pos2Value; private final RelevantVariables mRelevantVariables; private IcfgProgramExecution mIcfgProgramExecution; diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java index 654e0029330..a015d2d2948 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java @@ -109,8 +109,6 @@ private NestedWordAutomaton constructStraightLineAutomaton(final private void addCoveredTestGoalsToErrorAutomaton(final NestedWord trace, final IRun counterexample, final INwaOutgoingLetterAndTransitionProvider abstraction) { - System.out.println("HELP2"); - final List sequence = counterexample.getStateSequence(); for (int i = 0; i < sequence.size(); i++) { final IPredicate errorStatePredecessor = (IPredicate) sequence.get(i); @@ -139,9 +137,13 @@ private void addCoveredTestGoalsToErrorAutomaton(final NestedWord trace, fina } /* - * caller has to ensure state is an errorState with testgoal annotation + * can be Check ErrorLocation and not a TestGoal */ private boolean errorStateIsTestGoalWithId(final ISLPredicate state, final Integer testGoalId) { + if (((TestGoalAnnotation) state.getProgramPoint().getPayload().getAnnotations() + .get(TestGoalAnnotation.class.getName())) == null) { + return false; + } if (((TestGoalAnnotation) state.getProgramPoint().getPayload().getAnnotations() .get(TestGoalAnnotation.class.getName())).mId == testGoalId) { return true; From d76d0d2a155a045be51a0e800ee7b5193b5707e4 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 9 Sep 2023 21:39:25 +0200 Subject: [PATCH 003/278] Added Settings, export of statistics, test goals to loops --- releaseScripts/default/adds/Ultimate.py | 54 ++++- .../implementation/base/CHandler.java | 66 ++++-- .../base/TranslationSettings.java | 23 +- .../CACSLPreferenceInitializer.java | 18 +- .../operations/IsEmptyHeuristic.java | 88 +------- .../singletracecheck/TraceCheck.java | 27 ++- .../decider/SafetyCheckTestResultDecider.java | 79 +++++-- .../generator/rcfgbuilder/cfg/CfgBuilder.java | 7 +- .../RcfgPreferenceInitializer.java | 2 +- .../traceabstraction/AbstractCegarLoop.java | 39 +++- .../CegarLoopResultReporter.java | 4 + .../traceabstraction/NwaCegarLoop.java | 212 ++++++++++++++---- .../SimpleErrorAutomatonBuilder.java | 7 +- .../preferences/TAPreferences.java | 7 + ...TraceAbstractionPreferenceInitializer.java | 21 +- 15 files changed, 469 insertions(+), 185 deletions(-) diff --git a/releaseScripts/default/adds/Ultimate.py b/releaseScripts/default/adds/Ultimate.py index f233f24d472..5cb5e9c69af 100755 --- a/releaseScripts/default/adds/Ultimate.py +++ b/releaseScripts/default/adds/Ultimate.py @@ -60,6 +60,9 @@ class _PropParser: prop_regex = re.compile( "^\s*CHECK\s*\(\s*init\s*\((.*)\)\s*,\s*LTL\((.*)\)\s*\)\s*$", re.MULTILINE ) + prop_regex_testcomp = re.compile( + "^\s*COVER\s*\(\s*init\s*\((.*)\)\s*,\s*FQL\((.*)\)\s*\)\s*$", re.MULTILINE + ) funid_regex = re.compile("\s*(\S*)\s*\(.*\)") word_regex = re.compile("\b[^\W\d_]+\b") forbidden_words = [ @@ -86,6 +89,8 @@ def __init__(self, propfile): self.ltlformula = None self.mem_cleanup = False self.data_race = False + self.cover_error = False + self.cover_edges = False for match in self.prop_regex.finditer(self.content): init, formula = match.groups() @@ -120,6 +125,7 @@ def __init__(self, propfile): self.mem_cleanup = True elif formula == "G ! data-race": self.data_race = True + elif not check_string_contains( self.word_regex.findall(formula), self.forbidden_words ): @@ -134,6 +140,25 @@ def __init__(self, propfile): self.ltlformula = formula else: raise RuntimeError("The formula {0} is unknown".format(formula)) + for match in self.prop_regex_testcomp.finditer(self.content): + init, formula = match.groups() + + fun_match = self.funid_regex.match(init) + if not fun_match: + raise RuntimeError("No init specified in this check") + if self.init and self.init != fun_match.group(1): + raise RuntimeError( + "We do not support multiple and different init functions (have seen {0} and {1}".format( + self.init, fun_match.group(1) + ) + ) + self.init = fun_match.group(1) + if formula == "COVER EDGES(@CALL(reach_error))": + self.cover_error = True + elif formula == "COVER EDGES(@DECISIONEDGE)": + self.cover_edges = True + else: + raise RuntimeError("The formula {0} is unknown".format(formula)) def get_init_method(self): return self.init @@ -173,7 +198,13 @@ def get_ltl_formula(self): def is_data_race(self): return self.data_race + + def is_cover_error(self): + return self.cover_error + def is_cover_edges(self): + return self.cover_edges + class _AbortButPrint(Exception): def __init__(self, value): @@ -234,6 +265,7 @@ def get_java(): candidates = [ "java.exe", "C:\\Program Files\\Java\\jdk-11\\bin\\java.exe", + "C:\\Program Files\\Java\\jdk-11.0.17\\bin\\java.exe", "C:\\Program Files\\Eclipse Adoptium\\jdk-11*-hotspot\\bin\\java.exe", ] else: # Unix-like @@ -415,7 +447,11 @@ def run_ultimate(ultimate_call, prop, verbose=False): if blank_lines < 1: blank_lines += 1 else: - reading_error_path = False + reading_error_path = False + # elif prop.is_cover_error(): + # TODO result + # elif prop.is_cover_edges(): + # TODO else: if line.find(safety_string) != -1 or line.find(all_spec_string) != -1: result = "TRUE" @@ -510,6 +546,8 @@ def create_cli_settings(prop, validate_witness, architecture, c_file): "--traceabstraction.compute.hoare.annotation.of.negated.interpolant.automaton,.abstraction.and.cfg" ) ret.append("false") + + elif not validate_witness: # we are not in validation mode, so we should generate a witness and need # to pass some things to the witness printer @@ -528,8 +566,8 @@ def create_cli_settings(prop, validate_witness, architecture, c_file): ret.append(architecture) ret.append("--witnessprinter.graph.data.programhash") - sha = call_desperate(["sha256sum", c_file[0]]) - ret.append(sha.communicate()[0].split()[0].decode("utf-8", "ignore")) + #sha = call_desperate(["sha256sum", c_file[0]]) + #ret.append(sha.communicate()[0].split()[0].decode("utf-8", "ignore")) return ret @@ -854,6 +892,12 @@ def create_settings_search_string(prop, architecture): elif prop.is_data_race(): print("Checking for data races") settings_search_string = "DataRace" + elif prop.is_cover_error(): + print("Generating Tests to Cover Error") + settings_search_string = "CoverError" + elif prop.is_cover_edges(): + print("Generating Tests to Cover Branches") + settings_search_string = "CoverEdges" else: print("Checking for ERROR reachability") settings_search_string = "Reach" @@ -873,6 +917,10 @@ def get_toolchain_path(prop, witnessmode): search_string = "*MemDerefMemtrack.xml" elif prop.is_ltl(): search_string = "*LTL.xml" + elif prop.is_cover_error(): + search_string = "*CoverError.xml" + elif prop. is_cover_edges(): + search_string = "*CoverEdges.xml" else: search_string = "*Reach.xml" diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 0b04f4e3e85..7117b3edb5b 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -369,6 +369,9 @@ public class CHandler { private final boolean mIsInLibraryMode; + // Test Generation + private final boolean mTestGenerationErrorCoverage; + private final boolean mTestGenerationBranchCoverage; private int countTestGoals = 0; /** @@ -456,6 +459,8 @@ public CHandler(final ILogger logger, final ICACSL2BoogieBacktranslatorMapping b mMemoryHandler, mInitHandler, mFunctionHandler, this); mIsInLibraryMode = false; + mTestGenerationErrorCoverage = settings.isCoverError(); + mTestGenerationBranchCoverage = settings.isCoverBranches(); } /** @@ -554,7 +559,8 @@ public CHandler(final CHandler prerunCHandler, final ProcedureManager procedureM mFunctionToIndex, mTypeSizes, mSymbolTable, mStaticObjectsHandler, mSettings, procedureManager, mMemoryHandler, mInitHandler, mFunctionHandler, this); mIsInLibraryMode = !prerunCHandler.mProcedureManager.hasProcedure(mSettings.getEntryMethod()); - + mTestGenerationErrorCoverage = mSettings.isCoverError(); + mTestGenerationBranchCoverage = mSettings.isCoverBranches(); } /** @@ -1729,9 +1735,8 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { // states with identifier for later // Annotation zur identifikation // mLogger für statistik - final boolean testGeneration = true; final IfStatement ifStmt; - if (testGeneration) { + if (mTestGenerationBranchCoverage) { final ArrayList thenArray = new ArrayList(); final ArrayList elseArray = new ArrayList(); @@ -1761,7 +1766,6 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { chk.annotate(assertFalseElse); elseArray.add(assertFalseElse); elseArray.addAll(elseStmt); - ifStmt = new IfStatement(loc, cond.getValue(), thenArray.toArray(new Statement[thenArray.size()]), elseArray.toArray(new Statement[elseArray.size()])); @@ -3642,15 +3646,51 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res resultBuilder.addDeclarations(condResult.getDeclarations()); final RValue condRVal = (RValue) condResult.getLrValue(); IfStatement ifStmt; - { - final Expression cond = ExpressionFactory.constructUnaryExpression(loc, UnaryExpression.Operator.LOGICNEG, - condRVal.getValue()); - final ArrayList thenStmt = - new ArrayList<>(CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars())); - thenStmt.add(new BreakStatement(loc)); - final Statement[] elseStmt = - CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars()).toArray(new Statement[0]); - ifStmt = new IfStatement(loc, cond, thenStmt.toArray(new Statement[thenStmt.size()]), elseStmt); + final Expression cond = + ExpressionFactory.constructUnaryExpression(loc, UnaryExpression.Operator.LOGICNEG, condRVal.getValue()); + final ArrayList thenStmt = + new ArrayList<>(CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars())); + thenStmt.add(new BreakStatement(loc)); + final ArrayList elseStmt = + // CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars()).toArray(new Statement[0]); + new ArrayList<>(CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars())); + if (mTestGenerationBranchCoverage) { + + final ArrayList thenArray = new ArrayList(); + final ArrayList elseArray = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + // assertFalseThen.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", + // tg1); + countTestGoals += 1; + thenArray.add(assertFalseThen); + thenArray.addAll(thenStmt); + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + + final ILocation loc2 = mLocationFactory.createCLocation(node); + final Statement assertFalseElse = + new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); + + final TestGoalAnnotation tg2 = new TestGoalAnnotation(countTestGoals); + countTestGoals += 1; + // assertFalseElse.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", + // tg2); + tg2.annotate(assertFalseElse); + chk.annotate(assertFalseElse); + elseArray.add(assertFalseElse); + elseArray.addAll(elseStmt); + + ifStmt = new IfStatement(loc, cond, thenArray.toArray(new Statement[thenArray.size()]), + elseArray.toArray(new Statement[elseArray.size()])); + + } else { + ifStmt = new IfStatement(loc, cond, thenStmt.toArray(new Statement[thenStmt.size()]), + elseStmt.toArray(new Statement[elseStmt.size()])); } if (node instanceof IASTWhileStatement || node instanceof IASTForStatement) { diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/TranslationSettings.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/TranslationSettings.java index 869f3296d2f..beacb55718a 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/TranslationSettings.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/TranslationSettings.java @@ -79,6 +79,9 @@ public final class TranslationSettings { private final FloatingPointRoundingMode mInitialRoundingMode; private final boolean mAdaptMemoryModelResolutionOnPointerCasts; private final int mStringOverapproximationThreshold; + // Test Generation + private final boolean mTestGenerationErrorCoverage; + private final boolean mTestGenerationBranchCoverage; public TranslationSettings(final IPreferenceProvider ups) { mCheckSignedIntegerBounds = ups.getBoolean(CACSLPreferenceInitializer.LABEL_CHECK_SIGNED_INTEGER_BOUNDS); @@ -120,7 +123,6 @@ public TranslationSettings(final IPreferenceProvider ups) { ups.getBoolean(CACSLPreferenceInitializer.LABEL_OVERAPPROXIMATE_FLOATS); mUseConstantArrays = ups.getBoolean(CACSLPreferenceInitializer.LABEL_USE_CONSTANT_ARRAYS); mUseStoreChains = ups.getBoolean(CACSLPreferenceInitializer.LABEL_USE_STORE_CHAINS); - mEnableFesetround = ups.getBoolean(CACSLPreferenceInitializer.LABEL_FP_ROUNDING_MODE_ENABLE_FESETROUND); mInitialRoundingMode = ups.getEnum(CACSLPreferenceInitializer.LABEL_FP_ROUNDING_MODE_INITIAL, FloatingPointRoundingMode.class); @@ -128,6 +130,9 @@ public TranslationSettings(final IPreferenceProvider ups) { ups.getBoolean(CACSLPreferenceInitializer.LABEL_ADAPT_MEMORY_MODEL_ON_POINTER_CASTS); mStringOverapproximationThreshold = ups.getInt(CACSLPreferenceInitializer.LABEL_STRING_OVERAPPROXIMATION_THRESHOLD); + // Test Generation + mTestGenerationErrorCoverage = ups.getBoolean(CACSLPreferenceInitializer.LABEL_ERROR_COVERAGE); + mTestGenerationBranchCoverage = ups.getBoolean(CACSLPreferenceInitializer.LABEL_BRANCH_COVERAGE); } private TranslationSettings(final PointerCheckMode divisionByZeroOfIntegerTypes, @@ -144,7 +149,7 @@ private TranslationSettings(final PointerCheckMode divisionByZeroOfIntegerTypes, final boolean checkSignedIntegerBounds, final boolean checkDataRaces, final boolean useConstantArrays, final boolean useStoreChains, final boolean enableFesetround, final FloatingPointRoundingMode initialRoundingMode, final boolean adaptMemoryModelResolutionOnPointerCasts, - final int stringOverapproximationThreshold) { + final int stringOverapproximationThreshold, final boolean coverError, final boolean coverBranches) { super(); mDivisionByZeroOfIntegerTypes = divisionByZeroOfIntegerTypes; mDivisionByZeroOfFloatingTypes = divisionByZeroOfFloatingTypes; @@ -175,6 +180,8 @@ private TranslationSettings(final PointerCheckMode divisionByZeroOfIntegerTypes, mInitialRoundingMode = initialRoundingMode; mAdaptMemoryModelResolutionOnPointerCasts = adaptMemoryModelResolutionOnPointerCasts; mStringOverapproximationThreshold = stringOverapproximationThreshold; + mTestGenerationErrorCoverage = coverError; + mTestGenerationBranchCoverage = coverBranches; } public PointerIntegerConversion getPointerIntegerCastMode() { @@ -305,6 +312,15 @@ public int getStringOverapproximationThreshold() { return mStringOverapproximationThreshold; } + // TestGeneration + public boolean isCoverError() { + return mTestGenerationErrorCoverage; + } + + public boolean isCoverBranches() { + return mTestGenerationBranchCoverage; + } + public TranslationSettings setMemoryModelPreference(final MemoryModel memoryModel) { return new TranslationSettings(mDivisionByZeroOfIntegerTypes, mDivisionByZeroOfFloatingTypes, mBitvectorTranslation, mOverapproximateFloatingPointOperations, mBitpreciseBitfields, @@ -313,7 +329,8 @@ public TranslationSettings setMemoryModelPreference(final MemoryModel memoryMode memoryModel, mFpToIeeeBvExtension, mSmtBoolArraysWorkaround, mEntryMethod, mCheckErrorFunction, mCheckAssertions, mIsSvcompMemtrackCompatibilityMode, mCheckAllocationPurity, mCheckMemoryLeakInMain, mCheckSignedIntegerBounds, mCheckDataRaces, mUseConstantArrays, mUseStoreChains, mEnableFesetround, - mInitialRoundingMode, mAdaptMemoryModelResolutionOnPointerCasts, mStringOverapproximationThreshold); + mInitialRoundingMode, mAdaptMemoryModelResolutionOnPointerCasts, mStringOverapproximationThreshold, + mTestGenerationErrorCoverage, mTestGenerationBranchCoverage); } /** diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/plugins/generator/cacsl2boogietranslator/preferences/CACSLPreferenceInitializer.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/plugins/generator/cacsl2boogietranslator/preferences/CACSLPreferenceInitializer.java index a6083b9f4b8..dcf6f59daa7 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/plugins/generator/cacsl2boogietranslator/preferences/CACSLPreferenceInitializer.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/plugins/generator/cacsl2boogietranslator/preferences/CACSLPreferenceInitializer.java @@ -135,6 +135,14 @@ public class CACSLPreferenceInitializer extends UltimatePreferenceInitializer { + "bytes or more are overapproximated, i.e., Ultimate assumes that the string can contain arbitrary bytes."; private static final int DEFAULT_STRING_OVERAPPROXIMATION_THRESHOLD = 9; + // Test Generation ========================================================= + public static final String LABEL_BRANCH_COVERAGE = "Branch Coverage Property"; + private static final boolean DEF_BRANCH_COVERAGE = false; + private static final String DESC_BRANCH_COVERAGE = "TODO"; + public static final String LABEL_ERROR_COVERAGE = "Error Coverage Property"; + private static final boolean DEF_ERROR_COVERAGE = false; + private static final String DESC_ERROR_COVERAGE = "TODO"; + public enum PointerCheckMode { IGNORE, ASSUME, ASSERTandASSUME } @@ -316,7 +324,11 @@ protected UltimatePreferenceItem[] initDefaultPreferences() { DESC_ADAPT_MEMORY_MODEL_ON_POINTER_CASTS, PreferenceType.Boolean), new UltimatePreferenceItem<>(LABEL_STRING_OVERAPPROXIMATION_THRESHOLD, DEFAULT_STRING_OVERAPPROXIMATION_THRESHOLD, DESC_STRING_OVERAPPROXIMATION_THRESHOLD, - PreferenceType.Integer) }; - + PreferenceType.Integer), + // Test Generation + new UltimatePreferenceItem<>(LABEL_BRANCH_COVERAGE, DEF_BRANCH_COVERAGE, DESC_BRANCH_COVERAGE, + PreferenceType.Boolean), + new UltimatePreferenceItem<>(LABEL_ERROR_COVERAGE, DEF_ERROR_COVERAGE, DESC_ERROR_COVERAGE, + PreferenceType.Boolean) }; } -} +} \ No newline at end of file diff --git a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java index 471f74b78ca..2ca10309923 100644 --- a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java +++ b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java @@ -202,92 +202,6 @@ private NestedRun getAcceptingRun(final Collection startSt if (mLogger.isDebugEnabled()) { mLogger.debug(String.format("Current: %s", current)); } - final boolean testcomp = true; - // if (mIsGoalState.test(current.mTargetState)) { - // if (testcomp) { - // if (current.mTargetState instanceof SPredicate) { - // if (((SPredicate) current.mTargetState).getProgramPoint().getPayload().getAnnotations() - // .containsKey(TestGoalAnnotation.class.getName())) { - // - // if (((TestGoalAnnotation) ((SPredicate) current.mTargetState).getProgramPoint().getPayload() - // .getAnnotations().get(TestGoalAnnotation.class - // .getName())).mId == ((TestCompHeuristic) heuristic).mHighestErrorStateID) { - // if (mLogger.isDebugEnabled()) { - // mLogger.debug(" Is target with testgoal Id: " - // + ((TestCompHeuristic) heuristic).mHighestErrorStateID); - // printDebugStats(lowestCall, lowestOther, summaries); - // } - // - // return current.constructRun(); - // } - // - // } - // } else if (current.mTargetState instanceof UnknownState) { - // if (((UnknownState) current.mTargetState).getProgramPoint().getPayload().getAnnotations() - // .containsKey(TestGoalAnnotation.class.getName())) { - // - // if (((TestGoalAnnotation) ((UnknownState) current.mTargetState).getProgramPoint() - // .getPayload().getAnnotations().get(TestGoalAnnotation.class - // .getName())).mId == ((TestCompHeuristic) heuristic).mHighestErrorStateID) { - // if (mLogger.isDebugEnabled()) { - // mLogger.debug(" Is target with testgoal Id: " - // + ((TestCompHeuristic) heuristic).mHighestErrorStateID); - // printDebugStats(lowestCall, lowestOther, summaries); - // } - // - // return current.constructRun(); - // } - // - // } - // } else { - // if (mIsGoalState.test(current.mTargetState)) { - // if (mLogger.isDebugEnabled()) { - // mLogger.debug(" Is target"); - // printDebugStats(lowestCall, lowestOther, summaries); - // } - // return current.constructRun(); - // } - // } - // - // } else { - // if (mIsGoalState.test(current.mTargetState)) { - // - // if (current.mTargetState instanceof SPredicate) { - // if (((SPredicate) current.mTargetState).getProgramPoint().getPayload().getAnnotations() - // .containsKey(TestGoalAnnotation.class.getName())) { - // - // if (((TestCompHeuristic) heuristic).mTestGoalTodoStack - // .contains(((TestGoalAnnotation) ((SPredicate) current.mTargetState) - // .getProgramPoint().getPayload().getAnnotations() - // .get(TestGoalAnnotation.class.getName())).mId)) { - // - // return current.constructRun(); - // } - // - // } - // } else if (current.mTargetState instanceof UnknownState) { - // if (((UnknownState) current.mTargetState).getProgramPoint().getPayload().getAnnotations() - // .containsKey(TestGoalAnnotation.class.getName())) { - // - // if (((TestCompHeuristic) heuristic).mTestGoalTodoStack - // .contains(((TestGoalAnnotation) ((UnknownState) current.mTargetState) - // .getProgramPoint().getPayload().getAnnotations() - // .get(TestGoalAnnotation.class.getName())).mId)) { - // - // return current.constructRun(); - // } - // - // } - // } - // - // // if (mLogger.isDebugEnabled()) { - // // mLogger.debug(" Is target"); - // // printDebugStats(lowestCall, lowestOther, summaries); - // // } - // // return current.constructRun(); - // } - // } - // } final List stragglingSummaries; if (current.mItemType == ItemType.RETURN) { stragglingSummaries = updateSummaries(summaries, usedSummaries, current); @@ -974,7 +888,7 @@ public Item findCorrespondingCallItem() { if (mItemType != ItemType.RETURN) { return null; } - IWithBackPointer current = this.mBackPointer; + IWithBackPointer current = mBackPointer; final Deque> localStack = new ArrayDeque<>(); while (current != null) { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index ece6bf547e8..c5c25814452 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -27,6 +27,10 @@ */ package de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -148,6 +152,8 @@ public class TraceCheck implements ITraceCheck { protected final IIcfgSymbolTable mBoogie2SmtSymbolTable; protected final FeasibilityCheckResult mFeasibilityResult; + private final boolean mWriteEvaluationToFile = true; + /** * Check if trace fulfills specification given by precondition, postcondition and pending contexts. The * pendingContext maps the positions of pending returns to predicates which define possible variable valuations in @@ -451,7 +457,14 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } try { - TestExporter.getInstance().exportTests(testV, rpeb.mTrace.hashCode()); + final boolean mExportTestCase = true; // TODO Setting + if (mWriteEvaluationToFile) { + writeEvalRow(); + } + if (!testV.isEmpty() && mExportTestCase) { + TestExporter.getInstance().exportTests(testV, rpeb.mTrace.hashCode()); + } + } catch (final Exception e) { // TODO TestGeneration Auto-generated catch block e.printStackTrace(); @@ -461,6 +474,18 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild return rpeb.getIcfgProgramExecution(); } + private void writeEvalRow() { + try (FileWriter fw = + new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalTestCases.csv", true); + + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter out = new PrintWriter(bw)) { + out.append(String.format("%s, ", 1)); + } catch (final IOException e) { + throw new AssertionError(e); + } + } + protected AnnotateAndAssertCodeBlocks getAnnotateAndAsserterCodeBlocks(final NestedFormulas ssa) { return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger); } diff --git a/trunk/source/Library-UltimateTest/src/de/uni_freiburg/informatik/ultimate/test/decider/SafetyCheckTestResultDecider.java b/trunk/source/Library-UltimateTest/src/de/uni_freiburg/informatik/ultimate/test/decider/SafetyCheckTestResultDecider.java index 9b251b75513..f4cfec9a355 100644 --- a/trunk/source/Library-UltimateTest/src/de/uni_freiburg/informatik/ultimate/test/decider/SafetyCheckTestResultDecider.java +++ b/trunk/source/Library-UltimateTest/src/de/uni_freiburg/informatik/ultimate/test/decider/SafetyCheckTestResultDecider.java @@ -2,22 +2,22 @@ * Copyright (C) 2014-2015 Daniel Dietsch (dietsch@informatik.uni-freiburg.de) * Copyright (C) 2014-2015 Matthias Heizmann (heizmann@informatik.uni-freiburg.de) * Copyright (C) 2015 University of Freiburg - * + * * This file is part of the ULTIMATE UnitTest Library. - * + * * The ULTIMATE UnitTest Library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * The ULTIMATE UnitTest Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with the ULTIMATE UnitTest Library. If not, see . - * + * * Additional permission under GNU GPL version 3 section 7: * If you modify the ULTIMATE UnitTest Library, or any covered work, by linking * or combining it with Eclipse RCP (or a modified version of Eclipse RCP), @@ -38,31 +38,30 @@ import de.uni_freiburg.informatik.ultimate.test.util.TestUtil; /** - * Use keywords in filename and first line to decide correctness of safety - * checker results. - * + * Use keywords in filename and first line to decide correctness of safety checker results. + * * @author heizmann@informatik.uni-freiburg.de * @author Daniel Dietsch (dietsch@informatik.uni-freiburg.de) - * + * */ public class SafetyCheckTestResultDecider extends ThreeTierTestResultDecider { /** - * + * * @param ultimateRunDefinition - * + * * @param unknownIsJUnitSuccess - * if true the TestResult UNKNOWN is a success for JUnit, if - * false, the TestResult UNKNOWN is a failure for JUnit. + * if true the TestResult UNKNOWN is a success for JUnit, if false, the TestResult UNKNOWN is a failure + * for JUnit. */ - public SafetyCheckTestResultDecider(final UltimateRunDefinition ultimateRunDefinition, final boolean unknownIsJUnitSuccess) { + public SafetyCheckTestResultDecider(final UltimateRunDefinition ultimateRunDefinition, + final boolean unknownIsJUnitSuccess) { super(ultimateRunDefinition, unknownIsJUnitSuccess); } @Override public IExpectedResultFinder constructExpectedResultFinder() { - return new KeywordBasedExpectedResultFinder<>( - TestUtil.constructFilenameKeywordMap_AllSafetyChecker(), null, + return new KeywordBasedExpectedResultFinder<>(TestUtil.constructFilenameKeywordMap_AllSafetyChecker(), null, TestUtil.constructFirstlineKeywordMap_SafetyChecker()); } @@ -85,14 +84,23 @@ public class SafetyCheckerTestResultEvaluation implements ITestResultEvaluation< public void evaluateTestResult(final IExpectedResultFinder expectedResultFinder, final IOverallResultEvaluator overallResultDeterminer) { evaluateExpectedResult(expectedResultFinder); + final boolean testGeneration = true; switch (expectedResultFinder.getExpectedResultFinderStatus()) { case ERROR: // we will not evaluate overall result; return; case EXPECTED_RESULT_FOUND: + if (testGeneration) { + evaluateTestGenerationResult(overallResultDeterminer); + return; + } compareToOverallResult(expectedResultFinder.getExpectedResult(), overallResultDeterminer); return; case NO_EXPECTED_RESULT_FOUND: + if (testGeneration) { + evaluateTestGenerationResult(overallResultDeterminer); + return; + } evaluateOverallResultWithoutExpectedResult(overallResultDeterminer); return; default: @@ -109,9 +117,18 @@ private void evaluateOverallResultWithoutExpectedResult( mMessage += " UltimateResult: " + overallResultMsg; switch (overallResult) { case EXCEPTION_OR_ERROR: - case UNSUPPORTED_SYNTAX: - case NO_RESULT: + case UNSUPPORTED_SYNTAX: { mTestResult = TestResult.FAIL; + + break; + } + case NO_RESULT: + final boolean testGeneration = true; + if (testGeneration) { + mTestResult = TestResult.SUCCESS; + } else { + mTestResult = TestResult.FAIL; + } break; case SAFE: case UNSAFE: @@ -129,6 +146,32 @@ private void evaluateOverallResultWithoutExpectedResult( } } + private void evaluateTestGenerationResult( + final IOverallResultEvaluator overallResultDeterminer) { + final SafetyCheckerOverallResult overallResult = overallResultDeterminer.getOverallResult(); + mCategory = overallResult + " (Expected:UNKNOWN)"; + mMessage += " Ultimate TestGeneration"; + switch (overallResult) { + case EXCEPTION_OR_ERROR: + case UNSUPPORTED_SYNTAX: + mTestResult = TestResult.FAIL; + break; + + case UNSAFE_DEREF: + case UNSAFE_FREE: + case UNSAFE_MEMTRACK: + case UNSAFE_OVERAPPROXIMATED: + case UNKNOWN: + case SYNTAX_ERROR: + case TIMEOUT: + mTestResult = TestResult.UNKNOWN; + break; + default: + mTestResult = TestResult.SUCCESS; + break; + } + } + private void compareToOverallResult(final SafetyCheckerOverallResult expectedResult, final IOverallResultEvaluator overallResultDeterminer) { final SafetyCheckerOverallResult overallResult = overallResultDeterminer.getOverallResult(); diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java index 04b650c1c43..581190798ec 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java @@ -1193,16 +1193,15 @@ private void processAssuAssiHavoStatement(final Statement st, final Origin origi switch (mCodeBlockSize) { case LoopFreeBlock: case SequenceOfStatements: - // addStatementToStatementSequenceThatIsCurrentlyBuilt(st); - // break; - // case SequenceOfStatementsWithTestComp: //TODO TestGeneration Setting + addStatementToStatementSequenceThatIsCurrentlyBuilt(st); + break; + case SequenceOfStatementsBreakOnNondet: // TODO TestGeneration Setting if (st instanceof HavocStatement) { if (st.getPayload().toString().contains("__VERIFIER_nondet_")) { // TODO better endCurrentStatementSequence(st); startNewStatementSequenceAndAddStatement(st, origin); } - } else { addStatementToStatementSequenceThatIsCurrentlyBuilt(st); } diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java index 6a5832fa51f..824bd211eac 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java @@ -42,7 +42,7 @@ public class RcfgPreferenceInitializer extends UltimatePreferenceInitializer { public enum CodeBlockSize { - SingleStatement, OneNontrivialStatement, SequenceOfStatements, LoopFreeBlock, SequenceOfStatementsForTestComp + SingleStatement, OneNontrivialStatement, SequenceOfStatements, LoopFreeBlock, SequenceOfStatementsBreakOnNondet } // some solver commands diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index 70978bcaa0b..40e0fe83a45 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -117,6 +118,9 @@ public abstract class AbstractCegarLoop, A extends protected final XnfConversionTechnique mXnfConversionTechnique; protected final Class mTransitionClazz; + final Set mNotReachedLongTraceStates = new HashSet<>(); + private long TraceCeckTime = 0; + private long ExportedTestVectors = 0; /** * Interprocedural control flow graph. */ @@ -167,6 +171,9 @@ public abstract class AbstractCegarLoop, A extends */ protected NestedWordAutomaton mInterpolAutomaton; + protected final boolean mTestGeneration; + protected boolean mLongTraceOptimization; + // used for debugging only protected IAutomaton mArtifactAutomaton; @@ -227,6 +234,9 @@ protected AbstractCegarLoop(final IUltimateServiceProvider services, final Debug // TODO: TaskIdentifier should probably be provided by caller mTaskIdentifier = new SubtaskFileIdentifier(null, mIcfg.getIdentifier() + "_" + name); mResultBuilder = new CegarLoopResultBuilder(); + // Test-Generation Settings + mTestGeneration = mPref.getTestGeneration(); + mLongTraceOptimization = mPref.getLongTraceOpti(); // Skips Unsat Long Traces; } /** @@ -430,15 +440,24 @@ private void iterate() throws AutomataLibraryException { mDumper = new Dumper(mLogger, mPref, mName, mIteration); } try { + final long startTime = System.nanoTime(); final Pair> isCexResult = isCounterexampleFeasible(); - final AutomatonType automatonType = processFeasibilityCheckResult(isCexResult.getFirst(), - isCexResult.getSecond(), currentErrorLoc); - if (mPref.stopAfterFirstViolation() && automatonType != AutomatonType.INTERPOLANT) { - return; + final long estimatedTime = System.nanoTime() - startTime; + TraceCeckTime += estimatedTime; + System.out.println("TimeSpendinTraceCecking: " + TraceCeckTime); + if (isCexResult.getFirst() == Script.LBool.SAT) { + ExportedTestVectors += 1; + System.out.println("Exported tests: " + ExportedTestVectors); + } + if (isCexResult.getFirst() != Script.LBool.UNSAT || !mLongTraceOptimization) { + final AutomatonType automatonType = processFeasibilityCheckResult(isCexResult.getFirst(), + isCexResult.getSecond(), currentErrorLoc); + if (mPref.stopAfterFirstViolation() && automatonType != AutomatonType.INTERPOLANT) { + return; + } + constructRefinementAutomaton(automatonType); + refineAbstractionInternal(automatonType); } - constructRefinementAutomaton(automatonType); - refineAbstractionInternal(automatonType); - } catch (AutomataOperationCanceledException | ToolchainCanceledException e) { mServices = updateTimeBudget(currentErrorLoc, parentServices, iterationServices); updateBudget = false; @@ -484,6 +503,7 @@ private void iterate() throws AutomataLibraryException { } } mResultBuilder.addResultForAllRemaining(Result.USER_LIMIT_ITERATIONS); + } private void refineAbstractionInternal(final AutomatonType automatonType) @@ -527,9 +547,7 @@ private AutomatonType processFeasibilityCheckResult(final LBool isCounterexample final IProgramExecution programExecution, final IcfgLocation currentErrorLoc) { if (isCounterexampleFeasible == Script.LBool.SAT) { - // TODO TestGeneration Setting - final boolean testcomp = true; - if (testcomp) { + if (mTestGeneration) { final List sequence = mCounterexample.getStateSequence(); for (int i = 0; i < sequence.size(); i++) { if (sequence.get(i) instanceof ISLPredicate) { @@ -807,6 +825,7 @@ public static final Result convert(final TaskCanceledException.UserDefinedLimit } private final class CegarLoopResultBuilder { + // TODO result for test generation private final Map> mResults = new LinkedHashMap<>(); public CegarLoopResultBuilder addResultForAllRemaining(final Result result) { diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index bc591adb4c0..c4a75ea6dff 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -147,6 +147,10 @@ private void reportPositiveResult(final IcfgLocation errorLoc) { } private void reportCounterexampleResult(final IcfgLocation errorLoc, final IProgramExecution pe) { + final boolean testcomp = true; + if (testcomp) { + return; + } final List upreasons = UnprovabilityReason.getUnprovabilityReasons(pe); if (!upreasons.isEmpty()) { reportUnproveableResult(errorLoc, pe, upreasons); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index e8affe3580f..ab26b8a0b75 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -29,6 +29,13 @@ */ package de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -66,6 +73,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.lib.results.DangerInvariantResult; +import de.uni_freiburg.informatik.ultimate.core.model.models.annotation.IAnnotations; import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; @@ -134,10 +142,20 @@ public class NwaCegarLoop> extends BasicCegarLoop mTestGoalTodoStack = new ArrayList<>(); - private final List mTestGoalsInCurrentTrace = new ArrayList<>(); - private Integer mTestGoalWithHighesID = super.mErrorLocs.size() - 1; + // TestGeneration + private final ArrayList mTestGoalTodoStack = new ArrayList<>(); + private final Set mTestGoalWorkingSet = new HashSet<>(); + private final Set mTestGoalsInCurrentTrace = new HashSet<>(); + private Integer mCurrentTestGoalId; + private final boolean mNaiveLongTrace = false; + + // TestGeneration Statistiks + private final boolean mWriteEvaluationToFile = true; + private final long startTime = System.nanoTime(); + private int CegarLoopIterations = 1; + private double Covered = 0; + private double CoveredLongTrace = 0; + private long mLongTraceTime = 0; public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton initialAbstraction, final IIcfg rootNode, final CfgSmtToolkit csToolkit, final PredicateFactory predicateFactory, @@ -160,9 +178,23 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton longTraceRun(final INestedWordAutomaton abstraction, + final Set possibleEndPoints) throws AutomataOperationCanceledException { + return new IsEmpty<>(new AutomataLibraryServices(mServices), abstraction, abstraction.getInitialStates(), + Collections.emptySet(), possibleEndPoints).getNestedRun(); + } // TODO mCounterexample ist der Trace @@ -172,19 +204,44 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton abstraction = mAbstraction; - System.out.println(mTestGoalTodoStack); mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.EmptinessCheckTime); try { - if (!mTestGoalTodoStack.isEmpty() && mLongTraceOptimization) { // TODO + if (mLongTraceOptimization && !mTestGoalTodoStack.isEmpty()) { // TODO + // Wir fügen in jeder iteration einen neuen goalstate hinzu, immer den höchsten + // es ist uns egal wenn mehrere goal state drin sin - mCounterexample = - new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, - IHeuristic.getHeuristic(AStarHeuristic.TESTCOMP, mScoringMethod, - mAStarRandomHeuristicSeed, mTestGoalWithHighesID, mTestGoalTodoStack)) - .getNestedRun(); + final Set longTraceGoalStates = new HashSet<>(); + mTestGoalWorkingSet.add(mCurrentTestGoalId); + if (!mNaiveLongTrace) { + mCurrentTestGoalId -= 1; + } + for (final IPredicate testGoal : mAbstraction.getFinalStates()) { + final ISLPredicate testGoalISL = (ISLPredicate) testGoal; + final IAnnotations pLocAnno = testGoalISL.getProgramPoint().getPayload().getAnnotations() + .get(TestGoalAnnotation.class.getName()); + + if (pLocAnno instanceof TestGoalAnnotation) { + if (mTestGoalWorkingSet.contains(((TestGoalAnnotation) pLocAnno).mId)) { + longTraceGoalStates.add(testGoal); + } + } + } + mTestGoalWorkingSet.clear(); // If Skips Unsat Long Traces activated + + mCounterexample = longTraceRun(mAbstraction, longTraceGoalStates); + if (mCounterexample == null) { // mTestGoalTodoStack can be not Empty but mCounterexample can be null + // If more testgoals than iterations + if (mNaiveLongTrace) { + mCurrentTestGoalId -= 1; + } + mLongTraceTime = System.nanoTime() - startTime; + mLongTraceOptimization = false; + mCounterexample = + new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) + .getNestedRun(); - assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; + } } else if (mUseHeuristicEmptinessCheck) { mCounterexample = new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, IHeuristic.getHeuristic(mAStarHeuristic, mScoringMethod, mAStarRandomHeuristicSeed)) @@ -197,26 +254,30 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException .getNestedRun(); } } finally { + final long estimatedTime = System.nanoTime() - startTime; + if (mLongTraceOptimization) { + mLongTraceTime = System.nanoTime() - startTime; + } + if (mWriteEvaluationToFile) { + writeEvalRow(estimatedTime, mLongTraceTime); + } + CegarLoopIterations += 1; mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } - if (mCounterexample == null) { + final long estimatedTime = System.nanoTime() - startTime; + if (mLongTraceOptimization) { + mLongTraceTime = System.nanoTime() - startTime; + } + if (mWriteEvaluationToFile) { + writeEvalRow(estimatedTime, mLongTraceTime); + } return true; } - // 1. Wir wollen, dass alle errorstates entlang dieses traces - // (irreführend) durch den automaten abgedeckt werden, - // sodass die trace abstraction diese nicht länger berücksichtigt - // (müssen dann alle als covered in die statistk) - - // Wir wollen, dass ein Error state gewählt wird mit hohem Index - // final SimpleErrorAutomatonBuilder eab = new - // SimpleErrorAutomatonBuilder(mServices, mPredicateFactory, null, - // mCsToolkit, mPredicateFactoryInterpolantAutomata, mAbstraction, - // null); + // TODO auslagern: remove collect COvered Testgoals final List a = mCounterexample.getStateSequence(); String print = ""; - final boolean coeringError = false; for (int i = 0; i < a.size(); i++) { if (a.get(i) instanceof ISLPredicate) { final ISLPredicate stmt = (ISLPredicate) a.get(i); @@ -224,7 +285,6 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException .containsKey(TestGoalAnnotation.class.getName())) { print = print + " " + ((TestGoalAnnotation) stmt.getProgramPoint().getPayload().getAnnotations() .get(TestGoalAnnotation.class.getName())).mId; - // coeringError = true; mTestGoalsInCurrentTrace.add(((TestGoalAnnotation) stmt.getProgramPoint().getPayload() .getAnnotations().get(TestGoalAnnotation.class.getName())).mId); } @@ -232,10 +292,6 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException } } System.out.println(print); - // TODO error atuomaton - - // TODO loop wenn mProgramPoint hat payload mit annotation - // testgeneradings if (mPref.dumpAutomata()) { mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.DumpTime); @@ -265,6 +321,78 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException return false; } + private void writeEvalRowLongTrace() { + try (FileWriter fw = new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEval2.csv", true); + + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter out = new PrintWriter(bw)) { + out.println(String.format("%s", mLongTraceOptimization)); + } catch (final IOException e) { + throw new AssertionError(e); + } + } + + private void writeEvalTestCaseNewRow() { + final File fold = new File("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); + if (fold.exists() && !fold.isDirectory()) { + try (FileWriter fw = + new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalTestCases.csv", true); + + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter out = new PrintWriter(bw)) { + out.print("\n"); + } catch (final IOException e) { + throw new AssertionError(e); + } + } + } + + private void writeEvalRow(final long estimatedTime, final long longTraceTime) { + String asd = ""; + final File fold = new File("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); + if (fold.exists() && !fold.isDirectory()) { + asd = readEvalCoverage(); + fold.delete(); + } + + try (FileWriter fw = + new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv", true); + + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter out = new PrintWriter(bw)) { + fw.write(asd); + out.println( + String.format("Time: %s, Coverage: %s , LongTraceTime %s, CoverageLongTrace: %s, Iterations: %s", + estimatedTime / 1000, Covered / mErrorLocs.size(), longTraceTime / 1000, + CoveredLongTrace / mErrorLocs.size(), CegarLoopIterations)); + } catch (final IOException e) { + throw new AssertionError(e); + } + + } + + private String readEvalCoverage() { + final StringBuilder resultStringBuilder = new StringBuilder(); + String fileCOntentWithoutLastLine = ""; + try (final FileReader fr = + new FileReader("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); + final BufferedReader br = new BufferedReader(fr)) { + String line; + + while ((line = br.readLine()) != null) { + fileCOntentWithoutLastLine = resultStringBuilder.toString(); + resultStringBuilder.append(line).append("\n"); + + } + if (CegarLoopIterations == 1) { + return resultStringBuilder.toString(); + } + } catch (final IOException e) { + throw new AssertionError(e); + } + return fileCOntentWithoutLastLine; + } + private boolean checkIsEmptyHeuristic(final INwaOutgoingLetterAndTransitionProvider abstraction) throws AutomataOperationCanceledException { final NestedRun isEmptyHeuristicCex = (NestedRun) mCounterexample; @@ -368,8 +496,7 @@ protected boolean refineAbstraction() throws AutomataLibraryException { enhanceMode = mErrorGeneralizationEngine.getEnhancementMode(); subtrahendBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); subtrahend = mErrorGeneralizationEngine.getResultAfterEnhancement(); - mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); - // mTestGoalTodoStack.clear(); + testGenerationCoverage(); } else { automatonType = AutomatonType.FLOYD_HOARE; useErrorAutomaton = false; @@ -378,12 +505,6 @@ protected boolean refineAbstraction() throws AutomataLibraryException { enhanceMode = mPref.interpolantAutomatonEnhancement(); subtrahend = enhanceInterpolantAutomaton(enhanceMode, predicateUnifier, htc, subtrahendBeforeEnhancement); - if (!mTestGoalTodoStack.isEmpty()) { - mTestGoalTodoStack.remove(mTestGoalTodoStack.get(mTestGoalTodoStack.size() - 1)); - } - } - if (!mTestGoalTodoStack.isEmpty()) { - mTestGoalWithHighesID = mTestGoalTodoStack.get(mTestGoalTodoStack.size() - 1); } // TODO: HTC and predicateunifier statistics are saved in the following @@ -400,6 +521,19 @@ protected boolean refineAbstraction() throws AutomataLibraryException { return !stillAccepted; } + // TestGoal Coverage for Statistic and removing covered TestGoals form Stack + private void testGenerationCoverage() { + for (final Integer testgoal : mTestGoalsInCurrentTrace) { + if (mTestGoalTodoStack.contains(testgoal)) { + Covered += 1; + if (mLongTraceOptimization) { + CoveredLongTrace += 1; + } + } + } + mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); + } + private void computeAutomataDifference(final INestedWordAutomaton minuend, final INwaOutgoingLetterAndTransitionProvider subtrahend, final INwaOutgoingLetterAndTransitionProvider subtrahendBeforeEnhancement, diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java index a015d2d2948..6e4df763e22 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java @@ -42,6 +42,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IIcfgTransition; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IcfgLocation; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.BasicPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicateUnifier; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.ISLPredicate; @@ -117,13 +118,15 @@ private void addCoveredTestGoalsToErrorAutomaton(final NestedWord trace, fina for (final IPredicate errorState : ((INestedWordAutomaton) abstraction) .getFinalStates()) { if (errorStateIsTestGoalWithId((ISLPredicate) errorState, testGoalId)) { - mResult.addState(false, true, errorState); + final BasicPredicate errorStateAsBP = + new BasicPredicate(mResult.size(), null, errorState.getFormula(), null, null, null); + mResult.addState(false, true, errorStateAsBP); for (final Iterator it = mResult.getInitialStates().iterator(); it.hasNext();) { final IPredicate f = it.next(); final L letter = ((L) trace.getSymbol(i).getSource().getOutgoingEdges().get(0).getLabel()); - mResult.addInternalTransition(f, letter, errorState); + mResult.addInternalTransition(f, letter, errorStateAsBP); break; } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java index ca7a3cf6b92..c2d5bd9eef5 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java @@ -556,4 +556,11 @@ public McrInterpolantMethod getMcrInterpolantMethod() { return mMcrInterpolantMethod; } + public boolean getTestGeneration() { + return mPrefs.getBoolean(TraceAbstractionPreferenceInitializer.LABEL_TESTGENERATION); + } + + public boolean getLongTraceOpti() { + return mPrefs.getBoolean(TraceAbstractionPreferenceInitializer.LABEL_LONGTRACEOPTIMIZATION); + } } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java index 828e53d6404..d9b58bc1a89 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java @@ -495,6 +495,15 @@ public enum CoinflipMode { private static final String DESC_ASSERT_CODEBLOCKS_HEURISTIC_SCORE_THRESHOLD = "If Assert CodeBlocks is set to SMT_FEATURE_HEURISTIC and partitioning strategy is THRESHOLD, two partitions are created, one partition contains all terms >= threshold and one all terms < threshold"; + // Test Generation + // ======================================================================== + public static final String LABEL_TESTGENERATION = "Enable Test Generation"; + private static final boolean DEF_TESTGENERATION = false; + private static final String DESC_TESTGENERATION = "TODO"; + public static final String LABEL_LONGTRACEOPTIMIZATION = "Enable Test Long Trace Optimization"; + private static final boolean DEF_LONGTRACEOPTIMIZATION = false; + private static final String DESC_LONGTRACEOPTIMIZATION = "TODO"; + /** * Constructor. */ @@ -681,7 +690,7 @@ protected BaseUltimatePreferenceItem[] initDefaultPreferences() { new UltimatePreferenceItem<>(LABEL_DUMP_PATH_PROGRAM_IF_ANALYZED_TOO_OFTEN, 0, PreferenceType.Integer), new UltimatePreferenceItem<>(LABEL_DUMP_PATH_PROGRAM_STOP_MODE, PathProgramDumpStop.AFTER_FIRST_DUMP, PreferenceType.Combo, PathProgramDumpStop.values()), - getConcurrencySettings() }; + getConcurrencySettings(), getTestGenerationSettings() }; } public UltimatePreferenceItemContainer getConcurrencySettings() { @@ -708,6 +717,16 @@ public UltimatePreferenceItemContainer getConcurrencySettings() { getPORSettings(), getPetriLbeSettings()); } + public UltimatePreferenceItemContainer getTestGenerationSettings() { + return new UltimatePreferenceItemContainer("Test Generation", + new UltimatePreferenceItem<>(LABEL_TESTGENERATION, DEF_TESTGENERATION, DESC_TESTGENERATION, + PreferenceType.Boolean), + new UltimatePreferenceItem<>(LABEL_LONGTRACEOPTIMIZATION, DEF_LONGTRACEOPTIMIZATION, + DESC_LONGTRACEOPTIMIZATION, PreferenceType.Boolean) + + ); + } + public UltimatePreferenceItemContainer getPORSettings() { return new UltimatePreferenceItemContainer("Partial Order Reduction (GemCutter)", new UltimatePreferenceItem<>(LABEL_POR_ONESHOT, DEF_POR_ONESHOT, PreferenceType.Boolean), From 9f96eab4e1a2c707af1734ce2b78d20827bea1b0 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 11 Sep 2023 21:45:06 +0200 Subject: [PATCH 004/278] relative path for test export --- .../tracecheckerutils/singletracecheck/TraceCheck.java | 3 +-- .../plugins/generator/rcfgbuilder/cfg/CfgBuilder.java | 1 + .../plugins/generator/traceabstraction/NwaCegarLoop.java | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index c5c25814452..e29cece1bef 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -475,8 +475,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } private void writeEvalRow() { - try (FileWriter fw = - new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalTestCases.csv", true); + try (FileWriter fw = new FileWriter("TestGenerationEvalTestCases.csv", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java index 581190798ec..4d1a9c327ee 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/cfg/CfgBuilder.java @@ -279,6 +279,7 @@ public IIcfg createIcfg(final Unit unit) { case LoopFreeBlock: new LargeBlockEncoding(InternalLbeMode.ALL); break; + case SequenceOfStatementsBreakOnNondet: case SequenceOfStatements: // handled in ProcedureCfgBuilder case OneNontrivialStatement: case SingleStatement: diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index ab26b8a0b75..0d2098c8b3c 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -349,14 +349,13 @@ private void writeEvalTestCaseNewRow() { private void writeEvalRow(final long estimatedTime, final long longTraceTime) { String asd = ""; - final File fold = new File("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); + final File fold = new File("TestGenerationEvalCoverage.csv"); if (fold.exists() && !fold.isDirectory()) { asd = readEvalCoverage(); fold.delete(); } - try (FileWriter fw = - new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv", true); + try (FileWriter fw = new FileWriter("TestGenerationEvalCoverage.csv", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { @@ -374,8 +373,7 @@ private void writeEvalRow(final long estimatedTime, final long longTraceTime) { private String readEvalCoverage() { final StringBuilder resultStringBuilder = new StringBuilder(); String fileCOntentWithoutLastLine = ""; - try (final FileReader fr = - new FileReader("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); + try (final FileReader fr = new FileReader("TestGenerationEvalCoverage.csv"); final BufferedReader br = new BufferedReader(fr)) { String line; From ffa43952813c5078727abd75771274eb94e96d0f Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 11 Sep 2023 22:53:23 +0200 Subject: [PATCH 005/278] Added missing files --- .../operations/IsEmptyHeuristic.java | 9 - .../singletracecheck/TestExporter.java | 162 ++++++++++++ .../models/annotation/TestGoalAnnotation.java | 44 ++++ .../TestCompMetaFilePrinter.java | 245 ++++++++++++++++++ 4 files changed, 451 insertions(+), 9 deletions(-) create mode 100644 trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java create mode 100644 trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/TestGoalAnnotation.java create mode 100644 trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java diff --git a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java index 2ca10309923..605b832b58b 100644 --- a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java +++ b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmptyHeuristic.java @@ -1135,9 +1135,6 @@ public static IHeuristic getHeuristic(final AStar final ScoringMethod scoringMethod, final long seed, final Integer testGoalWithHighesID, final List testGoalTodoStack) { switch (astarHeuristic) { - - case TESTCOMP: - return IHeuristic.getTestCompHeuristic(testGoalWithHighesID, testGoalTodoStack); default: throw new UnsupportedOperationException("Unknown heuristic: " + astarHeuristic.toString()); @@ -1199,12 +1196,6 @@ public final double getConcreteCost(final LETTER e) { getSmtFeatureHeuristic(final ScoringMethod scoringMethod) { return new SmtFeatureHeuristic<>(scoringMethod); } - - public static TestCompHeuristic - getTestCompHeuristic(final Integer testGoalWithHighesID, final List testGoalTodoStack) { - return new TestCompHeuristic<>(testGoalWithHighesID, testGoalTodoStack); - } - } /** diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java new file mode 100644 index 00000000000..a35bedf5b26 --- /dev/null +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -0,0 +1,162 @@ +package de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedHashSet; +import java.util.LinkedList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.uni_freiburg.informatik.ultimate.logic.Term; + +public class TestExporter { + + private static final boolean WRITE_TESTCASES_TO_FILE = true; + LinkedHashSet tvSet = new LinkedHashSet<>(); + private static TestExporter instance = null; + private String mDirName = null; + private boolean foundMakefileAndDir = false; + private String pathToDir; + + /* + * Export Tests in: + * 1: one directory for all programs + * 2: one directory for each program + */ + public void exportTests(final TestVector testV, final int i) throws Exception { + if (!foundMakefileAndDir) { + findMakeFileAndDir(); + } + if (mDirName == null) { + // useDefaultFodler; + + try { + Files.createDirectories(Paths.get("testsuite")); + + final String name = "testcase" + i; + + final FileOutputStream output = new FileOutputStream("testsuite/" + name + ".xml"); + writeXml(createXML(testV), output); // TODO Setting + } catch (final IOException e) { + throw e; + } + } else { + try { + final String name = "testcase" + i; + Files.createDirectories(Paths.get(mDirName)); + final FileOutputStream output = new FileOutputStream(mDirName + "/" + name + ".xml"); + writeXml(createXML(testV), output); // TODO Setting + } catch (final IOException e) { + throw e; + } + } + + } + + public static TestExporter getInstance() { + if (instance == null) { + instance = new TestExporter(); + } + return instance; + } + + // TODO split exportation and creation of the testvectors. Means + private Document createXML(final TestVector tv) throws ParserConfigurationException { + + // instance of a DocumentBuilderFactory + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + // use factory to get an instance of document builder + final DocumentBuilder db = dbf.newDocumentBuilder(); + // create instance of DOM + final Document dom = db.newDocument(); + + // create the root element + final Element rootEle = dom.createElement("testcases"); + + // create data elements and place them under root + + for (final Term va : tv.values) { + if (va != null) { + final Element element = dom.createElement("input"); + element.appendChild(dom.createTextNode(va.toStringDirect())); + rootEle.appendChild(element); + } + } + + dom.appendChild(rootEle); + return dom; + } + + // write doc to output stream + private static void writeXml(final Document doc, final OutputStream output) throws TransformerException { + + final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + final Transformer transformer = transformerFactory.newTransformer(); + // pretty print XML + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + final DOMSource source = new DOMSource(doc); + final StreamResult result = new StreamResult(output); + + transformer.transform(source, result); + + } + + public void addTvToSet(final TestVector tv) { + tvSet.add(tv); + } + + /* + * Can be Used to create one Dir for each program + */ + public void findMakeFileAndDir() { + System.out.println("Test " + mDirName); + final File dir = new File("tests"); + final File[] files = dir.listFiles(); + final File lastModified = Arrays.stream(files).filter(File::isDirectory) + .max(Comparator.comparing(File::lastModified)).orElse(null); + System.out.println(lastModified); + mDirName = lastModified.toString(); + foundMakefileAndDir = true; + } + +} + +class TestVector { + + final LinkedList values = new LinkedList<>(); + + public void addValueAssignment(final Term value, final int position) { + addToLinkedList(values, position, value); + } + + private void addToLinkedList(final LinkedList testVector, final Integer index, final Term t) { + if (testVector.size() < index) { + for (int i = testVector.size(); i < index; i = i + 1) { + testVector.add(null); + } + } + testVector.add(index, t); + } + + public boolean isEmpty() { + return values.isEmpty(); + } +} diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/TestGoalAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/TestGoalAnnotation.java new file mode 100644 index 00000000000..0d1eb03bb46 --- /dev/null +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/TestGoalAnnotation.java @@ -0,0 +1,44 @@ +package de.uni_freiburg.informatik.ultimate.core.lib.models.annotation; + +import java.util.HashMap; +import java.util.Map; + +import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; +import de.uni_freiburg.informatik.ultimate.core.model.models.ModelUtils; + +/* + * Annotation for states that represent a test goal + */ +public class TestGoalAnnotation extends ModernAnnotations { + private static final long serialVersionUID = 1L; + private static final String KEY = TestGoalAnnotation.class.getName(); + private final Map mMap = new HashMap<>(); + public int mId; + + public TestGoalAnnotation(final int countTestGoals) { + mId = countTestGoals; + } + + @Override + public Map getAnnotationsAsMap() { + return mMap; + } + + @Override + public String toString() { + return mMap.toString(); + } + + public void setId(final int id) { + mId = id; + } + + public static TestGoalAnnotation getAnnotation(final IElement node) { + return ModelUtils.getAnnotation(node, KEY, a -> (TestGoalAnnotation) a); + } + + public void annotate(final IElement node) { + node.getPayload().getAnnotations().put(KEY, this); + + } +} diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java new file mode 100644 index 00000000000..dd946250246 --- /dev/null +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2016 Daniel Dietsch (dietsch@informatik.uni-freiburg.de) + * Copyright (C) 2016 University of Freiburg + * + * This file is part of the ULTIMATE WitnessPrinter plug-in. + * + * The ULTIMATE WitnessPrinter plug-in is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The ULTIMATE WitnessPrinter plug-in is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the ULTIMATE WitnessPrinter plug-in. If not, see . + * + * Additional permission under GNU GPL version 3 section 7: + * If you modify the ULTIMATE WitnessPrinter plug-in, or any covered work, by linking + * or combining it with Eclipse RCP (or a modified version of Eclipse RCP), + * containing parts covered by the terms of the Eclipse Public License, the + * licensors of the ULTIMATE WitnessPrinter plug-in grant you additional permission + * to convey the resulting work. + */ + +package de.uni_freiburg.informatik.ultimate.witnessprinter; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.DigestInputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider; +import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; +import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; +import de.uni_freiburg.informatik.ultimate.core.model.translation.IBacktranslatedCFG; +import de.uni_freiburg.informatik.ultimate.core.model.translation.IBacktranslationValueProvider; +import de.uni_freiburg.informatik.ultimate.util.CoreUtil; +import de.uni_freiburg.informatik.ultimate.witnessprinter.preferences.PreferenceInitializer; + +/** + * + * @author Max Barth max.barth95@gmx.de + * + */ +public class TestCompMetaFilePrinter extends BaseWitnessGenerator { + + private static final String[] ACSL_SUBSTRING = new String[] { "\\old", "\\result", "\\exists" }; + + private final ILogger mLogger; + private final IBacktranslationValueProvider mStringProvider; + private final IBacktranslatedCFG mTranslatedCFG; + private final boolean mIsACSLForbidden; + IUltimateServiceProvider mServices; + + @SuppressWarnings("unchecked") + public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, final ILogger logger, + final IUltimateServiceProvider services) throws Exception { + super(services); + mLogger = logger; + mStringProvider = (IBacktranslationValueProvider) translatedCFG.getBacktranslationValueProvider(); + mTranslatedCFG = translatedCFG; + mIsACSLForbidden = + PreferenceInitializer.getPreferences(services).getBoolean(PreferenceInitializer.LABEL_DO_NOT_USE_ACSL); + mServices = services; + final boolean mPrintEval = true; + if (mPrintEval) { + writeEvalRow(); + } + + try { + final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( + mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); + + Files.createDirectories(Paths.get("tests")); + Files.createDirectories(Paths.get("tests/testsuite_" + outputDir)); + final FileOutputStream output = new FileOutputStream("tests/testsuite_" + outputDir + "/metadata.xml"); + writeXml(createXML(), output); + } catch (final IOException | TransformerException | ParserConfigurationException e) { + throw e; + } + + } + + public Document createXML() throws ParserConfigurationException { + + final IPreferenceProvider ups = mServices.getPreferenceProvider(Activator.PLUGIN_ID); + // instance of a DocumentBuilderFactory + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + // use factory to get an instance of document builder + final DocumentBuilder db = dbf.newDocumentBuilder(); + // create instance of DOM + final Document dom = db.newDocument(); + final Element rootEle = dom.createElement("test-metadata"); + + // + final Element sourcecodelang = dom.createElement("sourcecodelang"); + sourcecodelang.appendChild(dom.createTextNode("C")); // TODO + rootEle.appendChild(sourcecodelang); + + // + final Element producer = dom.createElement("producer"); + producer.appendChild(dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_PRODUCER))); + rootEle.appendChild(producer); + + // + final Element specification = dom.createElement("specification"); + if (true) { // TODO + // ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_SPECIFICATION) + specification.appendChild(dom.createTextNode("CHECK( FQL(cover EDGES(@CONDITIONEDGE)) )")); + } else { + specification.appendChild(dom.createTextNode("CHECK( LTL(G ! call(__VERIFIER_error())) )")); + + specification.appendChild( + dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_SPECIFICATION))); + + } + + rootEle.appendChild(specification); + + // + final Element programfile = dom.createElement("programfile"); + programfile.appendChild(dom.createTextNode( + "./" + mTranslatedCFG.getFilename().substring(mTranslatedCFG.getFilename().lastIndexOf("\\") + 1))); + rootEle.appendChild(programfile); + + // + final Element programhash = dom.createElement("programhash"); + programhash.appendChild(dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_PROGRAMHASH))); + rootEle.appendChild(programhash); + + // + final Element entryfunction = dom.createElement("entryfunction"); + entryfunction.appendChild(dom.createTextNode("main")); // TODO + rootEle.appendChild(entryfunction); + + // + final Element architecture = dom.createElement("architecture"); + architecture + .appendChild(dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_ARCHITECTURE))); + rootEle.appendChild(architecture); + + // + final Element creationtime = dom.createElement("creationtime"); + creationtime.appendChild(dom.createTextNode(CoreUtil.getIsoUtcTimestamp())); + rootEle.appendChild(creationtime); + + // + // final Element inputtestsuitefile = + // dom.createElement("inputtestsuitefile"); + // inputtestsuitefile.appendChild(dom.createTextNode()); + // rootEle.appendChild(inputtestsuitefile); + + // + // final Element inputtestsuitehash = + // dom.createElement("inputtestsuitehash"); + // inputtestsuitehash.appendChild(dom.createTextNode()); + // rootEle.appendChild(inputtestsuitehash); + + dom.appendChild(rootEle); + return dom; + } + + // write doc to output stream + private static void writeXml(final Document doc, final OutputStream output) throws TransformerException { + + final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + final Transformer transformer = transformerFactory.newTransformer(); + // pretty print XML + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + final DOMSource source = new DOMSource(doc); + final StreamResult result = new StreamResult(output); + + transformer.transform(source, result); + + } + + @SuppressWarnings("resource") + public String calcSHA256(final String filepath) { + + try { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + final DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md); + while (dis.read() != -1) { + ; // empty loop to clear the data + } + md = dis.getMessageDigest(); + // bytes to hex + final StringBuilder result = new StringBuilder(); + for (final byte b : md.digest()) { + result.append(String.format("%02x", b)); + } + return result.toString(); + } catch (final IOException | NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ""; + + } + + private void writeEvalRow() { + try (FileWriter fw = new FileWriter("TestGenerationEval1.csv", true); + // create a File linked to the same file using the name of this one; + + final BufferedWriter bw = new BufferedWriter(fw); + final PrintWriter out = new PrintWriter(bw)) { + out.println( + "./" + mTranslatedCFG.getFilename().substring(mTranslatedCFG.getFilename().lastIndexOf("\\") + 1)); + } catch (final IOException e) { + throw new AssertionError(e); + } + } + + @Override + public String makeGraphMLString() { + // TODO Auto-generated method stub + return null; + } +} \ No newline at end of file From bc559fab16a8eeac29e3f9247508ae5d2f934c5e Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 14 Sep 2023 13:55:49 +0200 Subject: [PATCH 006/278] deactivated evaluation output --- .../singletracecheck/TraceCheck.java | 20 ------------------- .../traceabstraction/NwaCegarLoop.java | 7 ++----- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index e29cece1bef..e169be1ea85 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -27,10 +27,6 @@ */ package de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -152,8 +148,6 @@ public class TraceCheck implements ITraceCheck { protected final IIcfgSymbolTable mBoogie2SmtSymbolTable; protected final FeasibilityCheckResult mFeasibilityResult; - private final boolean mWriteEvaluationToFile = true; - /** * Check if trace fulfills specification given by precondition, postcondition and pending contexts. The * pendingContext maps the positions of pending returns to predicates which define possible variable valuations in @@ -458,9 +452,6 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild try { final boolean mExportTestCase = true; // TODO Setting - if (mWriteEvaluationToFile) { - writeEvalRow(); - } if (!testV.isEmpty() && mExportTestCase) { TestExporter.getInstance().exportTests(testV, rpeb.mTrace.hashCode()); } @@ -474,17 +465,6 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild return rpeb.getIcfgProgramExecution(); } - private void writeEvalRow() { - try (FileWriter fw = new FileWriter("TestGenerationEvalTestCases.csv", true); - - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter out = new PrintWriter(bw)) { - out.append(String.format("%s, ", 1)); - } catch (final IOException e) { - throw new AssertionError(e); - } - } - protected AnnotateAndAssertCodeBlocks getAnnotateAndAsserterCodeBlocks(final NestedFormulas ssa) { return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger); } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 0d2098c8b3c..f23e07e41c4 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -150,7 +150,7 @@ public class NwaCegarLoop> extends BasicCegarLoop a = mCounterexample.getStateSequence(); - String print = ""; + for (int i = 0; i < a.size(); i++) { if (a.get(i) instanceof ISLPredicate) { final ISLPredicate stmt = (ISLPredicate) a.get(i); if (stmt.getProgramPoint().getPayload().getAnnotations() .containsKey(TestGoalAnnotation.class.getName())) { - print = print + " " + ((TestGoalAnnotation) stmt.getProgramPoint().getPayload().getAnnotations() - .get(TestGoalAnnotation.class.getName())).mId; mTestGoalsInCurrentTrace.add(((TestGoalAnnotation) stmt.getProgramPoint().getPayload() .getAnnotations().get(TestGoalAnnotation.class.getName())).mId); } } } - System.out.println(print); if (mPref.dumpAutomata()) { mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.DumpTime); From 7dc30a48e9592a5460575c44eaa2e76df6b281cc Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 16 Sep 2023 18:33:55 +0200 Subject: [PATCH 007/278] Added Ultiamte Result --- releaseScripts/default/adds/Ultimate.py | 12 ++++++---- .../core/lib/models/annotation/Check.java | 13 ++++++----- .../core/lib/results/PositiveResult.java | 8 ++++++- .../traceabstraction/AbstractCegarLoop.java | 8 +++++-- .../CegarLoopResultReporter.java | 23 +++++++++++++++---- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/releaseScripts/default/adds/Ultimate.py b/releaseScripts/default/adds/Ultimate.py index 5cb5e9c69af..05f20e3ffde 100755 --- a/releaseScripts/default/adds/Ultimate.py +++ b/releaseScripts/default/adds/Ultimate.py @@ -39,6 +39,7 @@ witness_errorstring = "InvalidWitnessErrorResult" exception_errorstring = "ExceptionOrErrorResult" safety_string = "Ultimate proved your program to be correct" +testGen_string = "TestGeneration" all_spec_string = "AllSpecificationsHoldResult" unsafety_string = "Ultimate proved your program to be incorrect" mem_deref_false_string = "pointer dereference may fail" @@ -448,10 +449,13 @@ def run_ultimate(ultimate_call, prop, verbose=False): blank_lines += 1 else: reading_error_path = False - # elif prop.is_cover_error(): - # TODO result - # elif prop.is_cover_edges(): - # TODO + elif prop.is_cover_error(): + if line.find(testGen_string) != -1: + result = "DONE" + elif prop.is_cover_edges(): + print(line) + if line.find(testGen_string) != -1: + result = "DONE" else: if line.find(safety_string) != -1 or line.find(all_spec_string) != -1: result = "TRUE" diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java index f97d62a05cb..f675864b3b6 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/Check.java @@ -101,9 +101,8 @@ public enum Spec { */ MALLOC_NONNEGATIVE, /** - * Pointer arithmetic that is not allowed by C. E.g. - computing the - * difference of two pointers that point to completely different arrays - * - comparing pointers that point to completely different arrays + * Pointer arithmetic that is not allowed by C. E.g. - computing the difference of two pointers that point to + * completely different arrays - comparing pointers that point to completely different arrays */ ILLEGAL_POINTER_ARITHMETIC, /** @@ -276,7 +275,8 @@ public static String getDefaultPositiveMessage(final Spec spec) { return "there are no data races"; case CHC_SATISFIABILITY: return "the set of constraint Horn clauses is satisfiable"; - + case TEST_GOAL_ANNOTATION: + return "this test goal is not reachable"; default: return "a specification is correct but has no positive message: " + spec; } @@ -332,6 +332,8 @@ public static String getDefaultNegativeMessage(final Spec spec) { return "the program contains a data race"; case CHC_SATISFIABILITY: return "the set of constraint Horn clauses is unsatisfiable"; + case TEST_GOAL_ANNOTATION: + return "test goal reachable"; default: return "a specification may be violated but has no negative message: " + spec; } @@ -386,8 +388,7 @@ public void annotate(final IElement node) { } /** - * Return the checked specification that is checked at this location or - * null. + * Return the checked specification that is checked at this location or null. */ public static Check getAnnotation(final IElement node) { return ModelUtils.getAnnotation(node, KEY, a -> (Check) a); diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/PositiveResult.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/PositiveResult.java index 93b5be5e07b..e73a0eaa87f 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/PositiveResult.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/PositiveResult.java @@ -31,6 +31,7 @@ package de.uni_freiburg.informatik.ultimate.core.lib.results; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; import de.uni_freiburg.informatik.ultimate.core.model.services.IBacktranslationService; @@ -68,13 +69,18 @@ public String getShortDescription() { @Override public String getLongDescription() { + if (mCheckedSpecification.getSpec().equals(Spec.TEST_GOAL_ANNOTATION)) { + return "TestGeneration"; + } if (mCheckedSpecification == null) { return "some specification holds - ERROR (information lost during translation process)"; } final StringBuilder sb = new StringBuilder(); sb.append("For all program executions holds that "); sb.append(mCheckedSpecification.getPositiveMessage()); - sb.append(" at this location"); + if (!mCheckedSpecification.getSpec().equals(Spec.TEST_GOAL_ANNOTATION)) { + sb.append(" at this location"); + } return sb.toString(); } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index 40e0fe83a45..4a6afd6b9f2 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -558,7 +558,7 @@ private AutomatonType processFeasibilityCheckResult(final LBool isCounterexample if (sequence.get(i) instanceof ISLPredicate) { if (node.getPayload().getAnnotations() .containsKey(TestGoalAnnotation.class.getName())) { - mResultBuilder.addResult(node, Result.UNSAFE, null, null, null); + mResultBuilder.addResult(node, Result.TEST_GENERATION, null, null, null); } } } @@ -761,7 +761,11 @@ public enum Result { /** * The user-specified limit for the amount of analysis attempts per path program was hit */ - USER_LIMIT_PATH_PROGRAM(4); + USER_LIMIT_PATH_PROGRAM(4), + /** + * Test Generation Terminated + */ + TEST_GENERATION(0); private final int mHierarchy; diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index c4a75ea6dff..6666a41c542 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -38,6 +38,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.results.CounterExampleResult; import de.uni_freiburg.informatik.ultimate.core.lib.results.DataRaceFoundResult; import de.uni_freiburg.informatik.ultimate.core.lib.results.PositiveResult; +import de.uni_freiburg.informatik.ultimate.core.lib.results.TestGenerationResult; import de.uni_freiburg.informatik.ultimate.core.lib.results.TimeoutResultAtElement; import de.uni_freiburg.informatik.ultimate.core.lib.results.UnprovabilityReason; import de.uni_freiburg.informatik.ultimate.core.lib.results.UnprovableResult; @@ -56,6 +57,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.BoogieIcfgLocation; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.util.IcfgAngelicProgramExecution; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.AbstractCegarLoop.Result; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TAPreferences; /** * @@ -68,6 +70,8 @@ public final class CegarLoopResultReporter> { private final BiConsumer mReportFunction; private final String mPluginId; private final String mPluginName; + protected final TAPreferences mPref; + protected final boolean mTestGeneration; /** * Constructor s.t. the {@link CegarLoopResultReporter} reports all created results immediately to @@ -76,10 +80,13 @@ public final class CegarLoopResultReporter> { public CegarLoopResultReporter(final IUltimateServiceProvider services, final ILogger logger, final String pluginId, final String pluginName) { mServices = services; + mLogger = logger; mPluginId = pluginId; mPluginName = pluginName; mReportFunction = (errorLoc, result) -> this.reportResult(result); + mPref = new TAPreferences(mServices); + mTestGeneration = mPref.getTestGeneration(); } /** @@ -93,6 +100,8 @@ public CegarLoopResultReporter(final IUltimateServiceProvider services, final IL mPluginId = pluginId; mPluginName = pluginName; mReportFunction = reportFunction; + mPref = new TAPreferences(mServices); + mTestGeneration = mPref.getTestGeneration(); } public void reportCegarLoopResult(final CegarLoopResult clres) { @@ -117,6 +126,9 @@ public void reportCegarLoopResult(final CegarLoopResult clres) { final IProgramExecution pe = localResult.getProgramExecution(); reportUnproveableResult(errorLoc, pe, localResult.getUnprovabilityReasons()); break; + case TEST_GENERATION: + reportTestGenerationResult(errorLoc, localResult.getProgramExecution()); + break; default: throw new UnsupportedOperationException("Unknown result type " + localResult.getResult()); } @@ -146,11 +158,13 @@ private void reportPositiveResult(final IcfgLocation errorLoc) { mReportFunction.accept(errorLoc, pResult); } + private void reportTestGenerationResult(final IcfgLocation errorLoc, final IProgramExecution pe) { + final IResult cexResult = new TestGenerationResult(mPluginName); + mReportFunction.accept(errorLoc, cexResult); + } + private void reportCounterexampleResult(final IcfgLocation errorLoc, final IProgramExecution pe) { - final boolean testcomp = true; - if (testcomp) { - return; - } + final List upreasons = UnprovabilityReason.getUnprovabilityReasons(pe); if (!upreasons.isEmpty()) { reportUnproveableResult(errorLoc, pe, upreasons); @@ -168,6 +182,7 @@ private void reportCounterexampleResult(final IcfgLocation errorLoc, final IProg } else { cexResult = new CounterExampleResult<>(errorLoc, mPluginName, mServices.getBacktranslationService(), pe); } + mReportFunction.accept(errorLoc, cexResult); } From 76c917946911256ca1af2db3c2aa3572191129d4 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 16 Sep 2023 19:09:26 +0200 Subject: [PATCH 008/278] Missing files --- .../ultimate/boogie/ast/BoogieASTNode.java | 4 +++ .../lib/results/TestGenerationResult.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java diff --git a/trunk/source/Library-BoogieAST/src/de/uni_freiburg/informatik/ultimate/boogie/ast/BoogieASTNode.java b/trunk/source/Library-BoogieAST/src/de/uni_freiburg/informatik/ultimate/boogie/ast/BoogieASTNode.java index 129cf7b393d..64144c6666c 100644 --- a/trunk/source/Library-BoogieAST/src/de/uni_freiburg/informatik/ultimate/boogie/ast/BoogieASTNode.java +++ b/trunk/source/Library-BoogieAST/src/de/uni_freiburg/informatik/ultimate/boogie/ast/BoogieASTNode.java @@ -38,6 +38,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.models.BasePayloadContainer; import de.uni_freiburg.informatik.ultimate.core.lib.models.VisualizationNode; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.core.model.models.ISimpleAST; import de.uni_freiburg.informatik.ultimate.core.model.models.IWalkable; @@ -133,6 +134,9 @@ public void accept(final GeneratedBoogieAstVisitor visitor) { public static Check createDefaultCheck(final BoogieASTNode node) { if (node instanceof AssertStatement) { + if (node.getPayload().getAnnotations().containsKey(TestGoalAnnotation.class.getName())) { + return new Check(Check.Spec.TEST_GOAL_ANNOTATION); + } final NamedAttribute[] attrib = ((AssertStatement) node).getAttributes(); if (attrib != null && attrib.length > 0) { final String namedAttribStr = BoogiePrettyPrinter.print(attrib); diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java new file mode 100644 index 00000000000..e880a5e6a08 --- /dev/null +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java @@ -0,0 +1,27 @@ +package de.uni_freiburg.informatik.ultimate.core.lib.results; + +import de.uni_freiburg.informatik.ultimate.core.model.results.IResult; + +public class TestGenerationResult implements IResult { + + protected final String mPlugin; + + public TestGenerationResult(final String plugin) { + mPlugin = plugin; + } + + @Override + public final String getPlugin() { + return mPlugin; + } + + @Override + public String getShortDescription() { + return "TestGeneration"; + } + + @Override + public String getLongDescription() { + return "TestGeneration"; + } +} \ No newline at end of file From 419d7a7084df685ab4f4bc22ffcc51ddbb0f6ef2 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 19 Sep 2023 12:38:43 +0200 Subject: [PATCH 009/278] Changed Settings Activated Output --- releaseScripts/default/adds/Ultimate.py | 1 - .../singletracecheck/TestExporter.java | 4 +- .../singletracecheck/TraceCheck.java | 43 ++++- .../traceabstraction/AbstractCegarLoop.java | 23 +-- .../CegarLoopResultReporter.java | 3 +- .../traceabstraction/NwaCegarLoop.java | 162 +++++++++++------- .../TraceAbstractionStarter.java | 6 +- .../preferences/TAPreferences.java | 9 +- ...TraceAbstractionPreferenceInitializer.java | 42 +++-- .../TestCompMetaFilePrinter.java | 64 +------ .../witnessprinter/WitnessPrinter.java | 6 +- 11 files changed, 189 insertions(+), 174 deletions(-) diff --git a/releaseScripts/default/adds/Ultimate.py b/releaseScripts/default/adds/Ultimate.py index 05f20e3ffde..10966d99d99 100755 --- a/releaseScripts/default/adds/Ultimate.py +++ b/releaseScripts/default/adds/Ultimate.py @@ -453,7 +453,6 @@ def run_ultimate(ultimate_call, prop, verbose=False): if line.find(testGen_string) != -1: result = "DONE" elif prop.is_cover_edges(): - print(line) if line.find(testGen_string) != -1: result = "DONE" else: diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index a35bedf5b26..962d21b837f 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -40,7 +40,7 @@ public class TestExporter { * 1: one directory for all programs * 2: one directory for each program */ - public void exportTests(final TestVector testV, final int i) throws Exception { + public void exportTests(final TestVector testV, final int i, final boolean allInOneFile) throws Exception { if (!foundMakefileAndDir) { findMakeFileAndDir(); } @@ -127,12 +127,10 @@ public void addTvToSet(final TestVector tv) { * Can be Used to create one Dir for each program */ public void findMakeFileAndDir() { - System.out.println("Test " + mDirName); final File dir = new File("tests"); final File[] files = dir.listFiles(); final File lastModified = Arrays.stream(files).filter(File::isDirectory) .max(Comparator.comparing(File::lastModified)).orElse(null); - System.out.println(lastModified); mDirName = lastModified.toString(); foundMakefileAndDir = true; } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index e169be1ea85..f0d03b6c93e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -423,8 +423,37 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild funGetValue = this::getValue; } - final TestVector testV = new TestVector(); + final boolean mTestGeneration = true; + if (mTestGeneration) { + final TestVector testV = extractTestVector(nsb, funGetValue, rpeb); + final boolean mExportTests = true; + if (mExportTests) { + final boolean mExportAllInOneFile = true; + exportTest(testV, rpeb.mTrace.hashCode(), mExportAllInOneFile); + } + } else { + for (final var entry : nsb.getIndexedVarRepresentative().entrySet()) { + final IProgramVar bv = entry.getKey(); + final Map indexedRepresentatives = entry.getValue(); + if (SmtUtils.isSortForWhichWeCanGetValues(bv.getTermVariable().getSort())) { + for (final var representative : indexedRepresentatives.entrySet()) { + final Integer index = representative.getKey(); + final Term indexedVar = representative.getValue(); + final Term valueT = funGetValue.apply(indexedVar); + rpeb.addValueAtVarAssignmentPosition(bv, index, valueT); + } + } + } + } + cleanupAndUnlockSolver(); + return rpeb.getIcfgProgramExecution(); + } + + // does rpeb.addValueAtVarAssignmentPosition and creates a testVector at the same time + private TestVector extractTestVector(final NestedSsaBuilder nsb, final Function funGetValue, + final IcfgProgramExecutionBuilder rpeb) { + final TestVector testV = new TestVector(); for (final var entry : nsb.getIndexedVarRepresentative().entrySet()) { final IProgramVar bv = entry.getKey(); final Map indexedRepresentatives = entry.getValue(); @@ -449,20 +478,18 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } } } + return testV; + } + private void exportTest(final TestVector testV, final int identifier, final boolean allInOneFile) { try { - final boolean mExportTestCase = true; // TODO Setting - if (!testV.isEmpty() && mExportTestCase) { - TestExporter.getInstance().exportTests(testV, rpeb.mTrace.hashCode()); + if (!testV.isEmpty()) { + TestExporter.getInstance().exportTests(testV, identifier, allInOneFile); } - } catch (final Exception e) { // TODO TestGeneration Auto-generated catch block e.printStackTrace(); } - - cleanupAndUnlockSolver(); - return rpeb.getIcfgProgramExecution(); } protected AnnotateAndAssertCodeBlocks getAnnotateAndAsserterCodeBlocks(final NestedFormulas ssa) { diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index 4a6afd6b9f2..1818e6cebd5 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -97,6 +97,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TAPreferences.Artifact; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.FloydHoareAutomataReuse; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.HoareAnnotationPositions; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.TestGenerationMode; import de.uni_freiburg.informatik.ultimate.util.CoreUtil; import de.uni_freiburg.informatik.ultimate.util.ReflectionUtil; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; @@ -119,8 +120,8 @@ public abstract class AbstractCegarLoop, A extends protected final Class mTransitionClazz; final Set mNotReachedLongTraceStates = new HashSet<>(); - private long TraceCeckTime = 0; - private long ExportedTestVectors = 0; + private final long TraceCeckTime = 0; + private final long ExportedTestVectors = 0; /** * Interprocedural control flow graph. */ @@ -171,8 +172,7 @@ public abstract class AbstractCegarLoop, A extends */ protected NestedWordAutomaton mInterpolAutomaton; - protected final boolean mTestGeneration; - protected boolean mLongTraceOptimization; + protected TestGenerationMode mTestGeneration; // used for debugging only protected IAutomaton mArtifactAutomaton; @@ -236,7 +236,6 @@ protected AbstractCegarLoop(final IUltimateServiceProvider services, final Debug mResultBuilder = new CegarLoopResultBuilder(); // Test-Generation Settings mTestGeneration = mPref.getTestGeneration(); - mLongTraceOptimization = mPref.getLongTraceOpti(); // Skips Unsat Long Traces; } /** @@ -440,16 +439,10 @@ private void iterate() throws AutomataLibraryException { mDumper = new Dumper(mLogger, mPref, mName, mIteration); } try { - final long startTime = System.nanoTime(); final Pair> isCexResult = isCounterexampleFeasible(); - final long estimatedTime = System.nanoTime() - startTime; - TraceCeckTime += estimatedTime; - System.out.println("TimeSpendinTraceCecking: " + TraceCeckTime); - if (isCexResult.getFirst() == Script.LBool.SAT) { - ExportedTestVectors += 1; - System.out.println("Exported tests: " + ExportedTestVectors); - } - if (isCexResult.getFirst() != Script.LBool.UNSAT || !mLongTraceOptimization) { + if (isCexResult.getFirst() != Script.LBool.UNSAT + || !mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { + // TestGen, LongTrace ignores UNSAT traces final AutomatonType automatonType = processFeasibilityCheckResult(isCexResult.getFirst(), isCexResult.getSecond(), currentErrorLoc); if (mPref.stopAfterFirstViolation() && automatonType != AutomatonType.INTERPOLANT) { @@ -547,7 +540,7 @@ private AutomatonType processFeasibilityCheckResult(final LBool isCounterexample final IProgramExecution programExecution, final IcfgLocation currentErrorLoc) { if (isCounterexampleFeasible == Script.LBool.SAT) { - if (mTestGeneration) { + if (!mTestGeneration.equals(TestGenerationMode.None)) { final List sequence = mCounterexample.getStateSequence(); for (int i = 0; i < sequence.size(); i++) { if (sequence.get(i) instanceof ISLPredicate) { diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index 6666a41c542..e47b4907cba 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -58,6 +58,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.util.IcfgAngelicProgramExecution; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.AbstractCegarLoop.Result; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TAPreferences; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.TestGenerationMode; /** * @@ -71,7 +72,7 @@ public final class CegarLoopResultReporter> { private final String mPluginId; private final String mPluginName; protected final TAPreferences mPref; - protected final boolean mTestGeneration; + protected TestGenerationMode mTestGeneration; /** * Constructor s.t. the {@link CegarLoopResultReporter} reports all created results immediately to diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index f23e07e41c4..ea27d20f042 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -112,6 +112,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.CounterexampleSearchStrategy; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.Minimization; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.RelevanceAnalysisMode; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.TestGenerationMode; import de.uni_freiburg.informatik.ultimate.util.HistogramOfIterable; /** @@ -147,7 +148,6 @@ public class NwaCegarLoop> extends BasicCegarLoop mTestGoalWorkingSet = new HashSet<>(); private final Set mTestGoalsInCurrentTrace = new HashSet<>(); private Integer mCurrentTestGoalId; - private final boolean mNaiveLongTrace = false; // TestGeneration Statistiks private final boolean mWriteEvaluationToFile = false; // TODO add setting or remove in final version @@ -155,7 +155,8 @@ public class NwaCegarLoop> extends BasicCegarLoop initialAbstraction, final IIcfg rootNode, final CfgSmtToolkit csToolkit, final PredicateFactory predicateFactory, @@ -178,15 +179,15 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton longTraceRun(final INestedWordAutomaton abstraction = mAbstraction; mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.EmptinessCheckTime); - try { + if (!mTestGeneration.equals(TestGenerationMode.None)) { + nwaCegarWithTestGeneration(abstraction); + } else { + try { + if (mUseHeuristicEmptinessCheck) { + mCounterexample = new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, + IHeuristic.getHeuristic(mAStarHeuristic, mScoringMethod, mAStarRandomHeuristicSeed)) + .getNestedRun(); + + assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; + } else { + mCounterexample = + new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) + .getNestedRun(); + } + } finally { + mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); + } + } + if (mCounterexample == null) { + return true; + } + if (mPref.dumpAutomata()) { + mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.DumpTime); + mDumper.dumpNestedRun(mCounterexample); + mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.DumpTime); + } + mLogger.info("Found error trace"); + + if (mLogger.isDebugEnabled()) { + mLogger.debug(mCounterexample.getWord()); + } + final HistogramOfIterable traceHistogram = new HistogramOfIterable<>(mCounterexample.getWord()); + mCegarLoopBenchmark.reportTraceHistogramMaximum(traceHistogram.getMax()); + if (mLogger.isInfoEnabled()) { + mLogger.info("trace histogram " + traceHistogram.toString()); + } + if (traceHistogram.getMax() > DEBUG_DANGER_INVARIANTS_THRESHOLD) { + checkForDangerInvariantAndReport(); + } + + if (mPref.hasLimitTraceHistogram() && traceHistogram.getMax() > mPref.getLimitTraceHistogram()) { + final String taskDescription = + "bailout by trace histogram " + traceHistogram.toString() + " in iteration " + mIteration; + throw new TaskCanceledException(UserDefinedLimit.TRACE_HISTOGRAM, getClass(), taskDescription); + } + + return false; + } + + /* + * Different Heuristics and A* Goal Sets can be used in TestGeneration + */ + private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionProvider abstraction) + throws AutomataOperationCanceledException { - if (mLongTraceOptimization && !mTestGoalTodoStack.isEmpty()) { // TODO + try { + if (!mTestGeneration.equals(TestGenerationMode.Standard) && !mTestGoalTodoStack.isEmpty()) { // TODO // Wir fügen in jeder iteration einen neuen goalstate hinzu, immer den höchsten // es ist uns egal wenn mehrere goal state drin sin final Set longTraceGoalStates = new HashSet<>(); mTestGoalWorkingSet.add(mCurrentTestGoalId); - if (!mNaiveLongTrace) { + if (!mTestGeneration.equals(TestGenerationMode.NaiveMultiGoal)) { mCurrentTestGoalId -= 1; } for (final IPredicate testGoal : mAbstraction.getFinalStates()) { @@ -232,15 +284,14 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException mCounterexample = longTraceRun(mAbstraction, longTraceGoalStates); if (mCounterexample == null) { // mTestGoalTodoStack can be not Empty but mCounterexample can be null // If more testgoals than iterations - if (mNaiveLongTrace) { + if (mTestGeneration.equals(TestGenerationMode.NaiveMultiGoal)) { mCurrentTestGoalId -= 1; } mLongTraceTime = System.nanoTime() - startTime; - mLongTraceOptimization = false; + mTestGeneration = TestGenerationMode.Standard; mCounterexample = new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) .getNestedRun(); - } } else if (mUseHeuristicEmptinessCheck) { mCounterexample = new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, @@ -249,35 +300,39 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; } else { + mLogger.info("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); + mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mCounterexample = new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) .getNestedRun(); } } finally { - final long estimatedTime = System.nanoTime() - startTime; - if (mLongTraceOptimization) { - mLongTraceTime = System.nanoTime() - startTime; - } if (mWriteEvaluationToFile) { - writeEvalRow(estimatedTime, mLongTraceTime); + final long estimatedTime = System.nanoTime() - startTime; + if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { + mLongTraceTime = System.nanoTime() - startTime; + writeEvalRow(estimatedTime, mLongTraceTime); + } } - CegarLoopIterations += 1; mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } if (mCounterexample == null) { - final long estimatedTime = System.nanoTime() - startTime; - if (mLongTraceOptimization) { + mLogger.info("TestGen, CEGAR Iterations: " + CegarLoopIterations); + mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); + if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { mLongTraceTime = System.nanoTime() - startTime; + mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); + mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); } + mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); + final long estimatedTime = System.nanoTime() - startTime; if (mWriteEvaluationToFile) { writeEvalRow(estimatedTime, mLongTraceTime); } - return true; + return; } - // TODO auslagern: remove collect COvered Testgoals - final List a = mCounterexample.getStateSequence(); - for (int i = 0; i < a.size(); i++) { if (a.get(i) instanceof ISLPredicate) { final ISLPredicate stmt = (ISLPredicate) a.get(i); @@ -289,33 +344,7 @@ protected boolean isAbstractionEmpty() throws AutomataOperationCanceledException } } - - if (mPref.dumpAutomata()) { - mCegarLoopBenchmark.start(CegarLoopStatisticsDefinitions.DumpTime); - mDumper.dumpNestedRun(mCounterexample); - mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.DumpTime); - } - mLogger.info("Found error trace"); - - if (mLogger.isDebugEnabled()) { - mLogger.debug(mCounterexample.getWord()); - } - final HistogramOfIterable traceHistogram = new HistogramOfIterable<>(mCounterexample.getWord()); - mCegarLoopBenchmark.reportTraceHistogramMaximum(traceHistogram.getMax()); - if (mLogger.isInfoEnabled()) { - mLogger.info("trace histogram " + traceHistogram.toString()); - } - if (traceHistogram.getMax() > DEBUG_DANGER_INVARIANTS_THRESHOLD) { - checkForDangerInvariantAndReport(); - } - - if (mPref.hasLimitTraceHistogram() && traceHistogram.getMax() > mPref.getLimitTraceHistogram()) { - final String taskDescription = - "bailout by trace histogram " + traceHistogram.toString() + " in iteration " + mIteration; - throw new TaskCanceledException(UserDefinedLimit.TRACE_HISTOGRAM, getClass(), taskDescription); - } - - return false; + CegarLoopIterations += 1; } private void writeEvalRowLongTrace() { @@ -323,7 +352,7 @@ private void writeEvalRowLongTrace() { BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { - out.println(String.format("%s", mLongTraceOptimization)); + out.println(String.format("%s", mTestGeneration.equals(TestGenerationMode.SearchMultiGoal))); } catch (final IOException e) { throw new AssertionError(e); } @@ -344,7 +373,7 @@ private void writeEvalTestCaseNewRow() { } } - private void writeEvalRow(final long estimatedTime, final long longTraceTime) { + private void writeEvalRow(final long estimatedTime, final double mLongTraceTime2) { String asd = ""; final File fold = new File("TestGenerationEvalCoverage.csv"); if (fold.exists() && !fold.isDirectory()) { @@ -359,7 +388,7 @@ private void writeEvalRow(final long estimatedTime, final long longTraceTime) { fw.write(asd); out.println( String.format("Time: %s, Coverage: %s , LongTraceTime %s, CoverageLongTrace: %s, Iterations: %s", - estimatedTime / 1000, Covered / mErrorLocs.size(), longTraceTime / 1000, + estimatedTime / 1000, Covered / mErrorLocs.size(), mLongTraceTime2 / 1000, CoveredLongTrace / mErrorLocs.size(), CegarLoopIterations)); } catch (final IOException e) { throw new AssertionError(e); @@ -491,7 +520,9 @@ protected boolean refineAbstraction() throws AutomataLibraryException { enhanceMode = mErrorGeneralizationEngine.getEnhancementMode(); subtrahendBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); subtrahend = mErrorGeneralizationEngine.getResultAfterEnhancement(); - testGenerationCoverage(); + if (!mTestGeneration.equals(TestGenerationMode.None)) { + testGenerationCoverage(); + } } else { automatonType = AutomatonType.FLOYD_HOARE; useErrorAutomaton = false; @@ -518,10 +549,11 @@ protected boolean refineAbstraction() throws AutomataLibraryException { // TestGoal Coverage for Statistic and removing covered TestGoals form Stack private void testGenerationCoverage() { + mTestsExported += 1; for (final Integer testgoal : mTestGoalsInCurrentTrace) { if (mTestGoalTodoStack.contains(testgoal)) { Covered += 1; - if (mLongTraceOptimization) { + if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { CoveredLongTrace += 1; } } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/TraceAbstractionStarter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/TraceAbstractionStarter.java index cb6a52f88c4..8ad043e1d85 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/TraceAbstractionStarter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/TraceAbstractionStarter.java @@ -84,6 +84,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.FloydHoareAutomataReuse; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.OrderOfErrorLocations; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.TestGenerationMode; import de.uni_freiburg.informatik.ultimate.util.datastructures.DataStructureUtils; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; import de.uni_freiburg.informatik.ultimate.util.statistics.StatisticsData; @@ -126,6 +127,8 @@ public enum CegarRestartBehaviour { private final Map mResultsPerLocation; private final CegarLoopResultReporter mResultReporter; + protected TestGenerationMode mTestGeneration; + public TraceAbstractionStarter(final IUltimateServiceProvider services, final IIcfg icfg, final INwaOutgoingLetterAndTransitionProvider witnessAutomaton, final List> rawFloydHoareAutomataFromFile, @@ -140,7 +143,7 @@ public TraceAbstractionStarter(final IUltimateServiceProvider services, final II mIsConcurrent = IcfgUtils.isConcurrent(icfg); mResultReporter = new CegarLoopResultReporter<>(mServices, mLogger, Activator.PLUGIN_ID, Activator.PLUGIN_NAME, this::recordLocationResult); - + mTestGeneration = mPrefs.getTestGeneration(); if (mPrefs.computeHoareAnnotation() && mIsConcurrent) { mLogger.warn("Switching off computation of Hoare annotation because input is a concurrent program"); mComputeHoareAnnotation = false; @@ -177,6 +180,7 @@ private void runCegarLoops(final IIcfg icfg) { mLogger.info("Computing trace abstraction results"); // Report results that were buffered because they may be overridden or amended. + reportLocationResults(); reportBenchmarkResults(); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java index c2d5bd9eef5..f3471204a0e 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TAPreferences.java @@ -58,6 +58,7 @@ import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.Minimization; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.OrderOfErrorLocations; import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.RefinementStrategy; +import de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction.preferences.TraceAbstractionPreferenceInitializer.TestGenerationMode; import de.uni_freiburg.informatik.ultimate.util.ReflectionUtil.Reflected; public final class TAPreferences { @@ -556,11 +557,7 @@ public McrInterpolantMethod getMcrInterpolantMethod() { return mMcrInterpolantMethod; } - public boolean getTestGeneration() { - return mPrefs.getBoolean(TraceAbstractionPreferenceInitializer.LABEL_TESTGENERATION); - } - - public boolean getLongTraceOpti() { - return mPrefs.getBoolean(TraceAbstractionPreferenceInitializer.LABEL_LONGTRACEOPTIMIZATION); + public TestGenerationMode getTestGeneration() { + return mPrefs.getEnum(TraceAbstractionPreferenceInitializer.LABEL_TEST_GEN_MODE, TestGenerationMode.class); } } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java index d9b58bc1a89..740fdbdfa32 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java @@ -497,12 +497,10 @@ public enum CoinflipMode { // Test Generation // ======================================================================== - public static final String LABEL_TESTGENERATION = "Enable Test Generation"; - private static final boolean DEF_TESTGENERATION = false; - private static final String DESC_TESTGENERATION = "TODO"; - public static final String LABEL_LONGTRACEOPTIMIZATION = "Enable Test Long Trace Optimization"; - private static final boolean DEF_LONGTRACEOPTIMIZATION = false; - private static final String DESC_LONGTRACEOPTIMIZATION = "TODO"; + private static final TestGenerationMode DEF_TEST_GEN_MODE = TestGenerationMode.None; + public static final String LABEL_TEST_GEN_MODE = "Test Generation Mode"; + private static final String DESC_TEST_GEN_MODE = + "None deactivates Test Generation, Standart standart Test Generation for Model Checkers, Search-MultiGoal uses the A* to find Multi Goal test cases and ignores ifeasible traces during the search, Naive-MultiGoal starts the CEGAR with the last added Test Goal and adds a new Test Goal every iteration"; /** * Constructor. @@ -718,11 +716,8 @@ public UltimatePreferenceItemContainer getConcurrencySettings() { } public UltimatePreferenceItemContainer getTestGenerationSettings() { - return new UltimatePreferenceItemContainer("Test Generation", - new UltimatePreferenceItem<>(LABEL_TESTGENERATION, DEF_TESTGENERATION, DESC_TESTGENERATION, - PreferenceType.Boolean), - new UltimatePreferenceItem<>(LABEL_LONGTRACEOPTIMIZATION, DEF_LONGTRACEOPTIMIZATION, - DESC_LONGTRACEOPTIMIZATION, PreferenceType.Boolean) + return new UltimatePreferenceItemContainer("Test Generation", new UltimatePreferenceItem<>(LABEL_TEST_GEN_MODE, + DEF_TEST_GEN_MODE, DESC_TEST_GEN_MODE, PreferenceType.Combo, TestGenerationMode.values()) ); } @@ -1066,4 +1061,29 @@ public enum OrderOfErrorLocations { public enum PathProgramDumpStop { NEVER, AFTER_FIRST_DUMP, BEFORE_FIRST_DUPLICATE } + + /** + * Differnt modes of Test Generation + * + * @author Max Barth (Max.Barth@gmx.de) + */ + public enum TestGenerationMode { + /** + * No Test Generation. + */ + None, + /** + * Standart Test Generation for Model Checkers + */ + Standard, + /** + * Use the A* to search a trace that covers multiple test goals. Ignore the trace if it is UNSAT + */ + SearchMultiGoal, + /** + * Does NOT ignore the trace if it is UNSAT. + */ + NaiveMultiGoal + } + } diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index dd946250246..90c590fef4f 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -27,18 +27,11 @@ package de.uni_freiburg.informatik.ultimate.witnessprinter; -import java.io.BufferedWriter; -import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; -import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; -import java.security.DigestInputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -86,11 +79,10 @@ public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, f mIsACSLForbidden = PreferenceInitializer.getPreferences(services).getBoolean(PreferenceInitializer.LABEL_DO_NOT_USE_ACSL); mServices = services; - final boolean mPrintEval = true; - if (mPrintEval) { - writeEvalRow(); - } + } + + public void printMetaFile() throws Exception { try { final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); @@ -102,7 +94,6 @@ public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, f } catch (final IOException | TransformerException | ParserConfigurationException e) { throw e; } - } public Document createXML() throws ParserConfigurationException { @@ -129,16 +120,9 @@ public Document createXML() throws ParserConfigurationException { // final Element specification = dom.createElement("specification"); - if (true) { // TODO - // ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_SPECIFICATION) - specification.appendChild(dom.createTextNode("CHECK( FQL(cover EDGES(@CONDITIONEDGE)) )")); - } else { - specification.appendChild(dom.createTextNode("CHECK( LTL(G ! call(__VERIFIER_error())) )")); - specification.appendChild( - dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_SPECIFICATION))); - - } + specification + .appendChild(dom.createTextNode(ups.getString(PreferenceInitializer.LABEL_GRAPH_DATA_SPECIFICATION))); rootEle.appendChild(specification); @@ -199,44 +183,6 @@ private static void writeXml(final Document doc, final OutputStream output) thro } - @SuppressWarnings("resource") - public String calcSHA256(final String filepath) { - - try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - - final DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md); - while (dis.read() != -1) { - ; // empty loop to clear the data - } - md = dis.getMessageDigest(); - // bytes to hex - final StringBuilder result = new StringBuilder(); - for (final byte b : md.digest()) { - result.append(String.format("%02x", b)); - } - return result.toString(); - } catch (final IOException | NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ""; - - } - - private void writeEvalRow() { - try (FileWriter fw = new FileWriter("TestGenerationEval1.csv", true); - // create a File linked to the same file using the name of this one; - - final BufferedWriter bw = new BufferedWriter(fw); - final PrintWriter out = new PrintWriter(bw)) { - out.println( - "./" + mTranslatedCFG.getFilename().substring(mTranslatedCFG.getFilename().lastIndexOf("\\") + 1)); - } catch (final IOException e) { - throw new AssertionError(e); - } - } - @Override public String makeGraphMLString() { // TODO Auto-generated method stub diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java index bd9c20fb24d..3d78f9aff85 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/WitnessPrinter.java @@ -132,8 +132,7 @@ public void finish() { if (TestCompMetaFileTODO) { // TODO mLogger.info("Generating MetaFile for TestComp Reults"); generateMetaFile(cexVerifier, results); - } - if (results.stream().anyMatch(a -> a instanceof CounterExampleResult)) { + } else if (results.stream().anyMatch(a -> a instanceof CounterExampleResult)) { mLogger.info("Generating witness for reachability counterexample"); generateReachabilityCounterexampleWitness(cexVerifier, results); } else if (results.stream().anyMatch(a -> a instanceof LassoShapedNonTerminationArgument)) { @@ -159,8 +158,7 @@ private void generateMetaFile(final WitnessManager cexVerifier, final List origCfg = new BacktranslatedCFG<>(filename, IcfgGraphProvider.getVirtualRoot(root), IcfgEdge.class); - final TestCompMetaFilePrinter asd = - new TestCompMetaFilePrinter(backtrans.translateCFG(origCfg), mLogger, mServices); + new TestCompMetaFilePrinter<>(backtrans.translateCFG(origCfg), mLogger, mServices).printMetaFile(); } From 6b181867dd4f9865222e65c7a7399d1f2c4c52b3 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 19 Sep 2023 15:48:17 +0200 Subject: [PATCH 010/278] minor changes --- .../singletracecheck/TestExporter.java | 42 +++++++++---------- .../traceabstraction/NwaCegarLoop.java | 14 +++---- .../TestCompMetaFilePrinter.java | 23 +++++++--- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 962d21b837f..7ab65397e8b 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -2,7 +2,6 @@ import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Paths; @@ -41,33 +40,30 @@ public class TestExporter { * 2: one directory for each program */ public void exportTests(final TestVector testV, final int i, final boolean allInOneFile) throws Exception { - if (!foundMakefileAndDir) { - findMakeFileAndDir(); - } - if (mDirName == null) { - // useDefaultFodler; - - try { - Files.createDirectories(Paths.get("testsuite")); - - final String name = "testcase" + i; - final FileOutputStream output = new FileOutputStream("testsuite/" + name + ".xml"); - writeXml(createXML(testV), output); // TODO Setting - } catch (final IOException e) { - throw e; + final FileOutputStream output; + final String name = "testcase" + i; + final boolean noDirectories = false; + final boolean allInOneDirecotry = true; + if (noDirectories) { + output = new FileOutputStream(name + ".xml"); + } else if (allInOneDirecotry) { + Files.createDirectories(Paths.get(mDirName)); + output = new FileOutputStream("testsuites/" + name + ".xml"); + } else { // testsuites directory and subdirectory for every program that contains the tests + if (!foundMakefileAndDir) { + findMakeFileAndDir(); } - } else { - try { - final String name = "testcase" + i; + if (mDirName == null) { + Files.createDirectories(Paths.get("testsuites")); + + output = new FileOutputStream("testsuites/" + name + ".xml"); + } else { Files.createDirectories(Paths.get(mDirName)); - final FileOutputStream output = new FileOutputStream(mDirName + "/" + name + ".xml"); - writeXml(createXML(testV), output); // TODO Setting - } catch (final IOException e) { - throw e; + output = new FileOutputStream("testsuites/" + name + ".xml"); } } - + writeXml(createXML(testV), output); // TODO Setting } public static TestExporter getInstance() { diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index ea27d20f042..dda70452bb4 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -300,8 +300,8 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; } else { - mLogger.info("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); - mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mLogger.debug("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); + mLogger.debug("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); mCounterexample = new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) @@ -318,14 +318,14 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } if (mCounterexample == null) { - mLogger.info("TestGen, CEGAR Iterations: " + CegarLoopIterations); - mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); + mLogger.debug("TestGen, CEGAR Iterations: " + CegarLoopIterations); + mLogger.debug("TestGen, Coverage: " + Covered / mErrorLocs.size()); if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { mLongTraceTime = System.nanoTime() - startTime; - mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); - mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mLogger.debug("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); + mLogger.debug("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); } - mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); + mLogger.debug("TestGen, Amount of Tests Exported: " + mTestsExported); final long estimatedTime = System.nanoTime() - startTime; if (mWriteEvaluationToFile) { writeEvalRow(estimatedTime, mLongTraceTime); diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index 90c590fef4f..fb227afdac1 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -83,13 +83,24 @@ public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, f } public void printMetaFile() throws Exception { + final boolean noDirectories = false; + final boolean allInOneDirecotry = true; try { - final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( - mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); - - Files.createDirectories(Paths.get("tests")); - Files.createDirectories(Paths.get("tests/testsuite_" + outputDir)); - final FileOutputStream output = new FileOutputStream("tests/testsuite_" + outputDir + "/metadata.xml"); + final FileOutputStream output; + if (noDirectories) { + output = new FileOutputStream("metadata.xml"); + } else if (allInOneDirecotry) { + Files.createDirectories(Paths.get("testsuites")); + output = new FileOutputStream("testsuites/metadata.xml"); + // output = new FileOutputStream("metadata.xml"); + } else { + final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( + mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); + + Files.createDirectories(Paths.get("tests")); + Files.createDirectories(Paths.get("tests/testsuite_" + outputDir)); + output = new FileOutputStream("tests/testsuite_" + outputDir + "/metadata.xml"); + } writeXml(createXML(), output); } catch (final IOException | TransformerException | ParserConfigurationException e) { throw e; From 28581b8a2eebd55606a25905b71d6d4023a4aa76 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 19 Sep 2023 17:20:47 +0200 Subject: [PATCH 011/278] logger level --- .../generator/traceabstraction/NwaCegarLoop.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index dda70452bb4..42a649e715c 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -178,7 +178,7 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) @@ -318,14 +318,14 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } if (mCounterexample == null) { - mLogger.debug("TestGen, CEGAR Iterations: " + CegarLoopIterations); - mLogger.debug("TestGen, Coverage: " + Covered / mErrorLocs.size()); + mLogger.fatal("TestGen, CEGAR Iterations: " + CegarLoopIterations); + mLogger.fatal("TestGen, Coverage: " + Covered / mErrorLocs.size()); if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { mLongTraceTime = System.nanoTime() - startTime; - mLogger.debug("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); - mLogger.debug("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mLogger.fatal("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); + mLogger.fatal("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); } - mLogger.debug("TestGen, Amount of Tests Exported: " + mTestsExported); + mLogger.fatal("TestGen, Amount of Tests Exported: " + mTestsExported); final long estimatedTime = System.nanoTime() - startTime; if (mWriteEvaluationToFile) { writeEvalRow(estimatedTime, mLongTraceTime); From 37856a5c4e8de47b3fe4d519f38d0410f8cad561 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 19 Sep 2023 20:00:33 +0200 Subject: [PATCH 012/278] No export directory, bugfix ultimate.py --- releaseScripts/default/adds/Ultimate.py | 5 ++--- .../lib/tracecheckerutils/singletracecheck/TestExporter.java | 4 ++-- .../ultimate/witnessprinter/TestCompMetaFilePrinter.java | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/releaseScripts/default/adds/Ultimate.py b/releaseScripts/default/adds/Ultimate.py index 10966d99d99..a835f807a34 100755 --- a/releaseScripts/default/adds/Ultimate.py +++ b/releaseScripts/default/adds/Ultimate.py @@ -568,9 +568,8 @@ def create_cli_settings(prop, validate_witness, architecture, c_file): ret.append("--witnessprinter.graph.data.architecture") ret.append(architecture) ret.append("--witnessprinter.graph.data.programhash") - - #sha = call_desperate(["sha256sum", c_file[0]]) - #ret.append(sha.communicate()[0].split()[0].decode("utf-8", "ignore")) + sha = call_desperate(["sha256sum", c_file[0]]) + ret.append(sha.communicate()[0].split()[0].decode("utf-8", "ignore")) return ret diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 7ab65397e8b..3b3f56a2b41 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -43,8 +43,8 @@ public void exportTests(final TestVector testV, final int i, final boolean allIn final FileOutputStream output; final String name = "testcase" + i; - final boolean noDirectories = false; - final boolean allInOneDirecotry = true; + final boolean noDirectories = true; + final boolean allInOneDirecotry = false; if (noDirectories) { output = new FileOutputStream(name + ".xml"); } else if (allInOneDirecotry) { diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index fb227afdac1..dc6e428b327 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -83,8 +83,8 @@ public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, f } public void printMetaFile() throws Exception { - final boolean noDirectories = false; - final boolean allInOneDirecotry = true; + final boolean noDirectories = true; + final boolean allInOneDirecotry = false; try { final FileOutputStream output; if (noDirectories) { From 351c56db6e013ca8c84adcdb0035ebb4df526a74 Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 20 Sep 2023 16:25:47 +0200 Subject: [PATCH 013/278] changed ouput to one directory --- .../tracecheckerutils/singletracecheck/TestExporter.java | 8 ++++---- .../ultimate/witnessprinter/TestCompMetaFilePrinter.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 3b3f56a2b41..b60c84c89e4 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -43,13 +43,13 @@ public void exportTests(final TestVector testV, final int i, final boolean allIn final FileOutputStream output; final String name = "testcase" + i; - final boolean noDirectories = true; - final boolean allInOneDirecotry = false; + final boolean noDirectories = false; + final boolean allInOneDirecotry = true; if (noDirectories) { output = new FileOutputStream(name + ".xml"); } else if (allInOneDirecotry) { - Files.createDirectories(Paths.get(mDirName)); - output = new FileOutputStream("testsuites/" + name + ".xml"); + Files.createDirectories(Paths.get("test-suite")); + output = new FileOutputStream("test-suite/" + name + ".xml"); } else { // testsuites directory and subdirectory for every program that contains the tests if (!foundMakefileAndDir) { findMakeFileAndDir(); diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index dc6e428b327..03dc4bc7b6e 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -83,15 +83,15 @@ public TestCompMetaFilePrinter(final IBacktranslatedCFG translatedCFG, f } public void printMetaFile() throws Exception { - final boolean noDirectories = true; - final boolean allInOneDirecotry = false; + final boolean noDirectories = false; + final boolean allInOneDirecotry = true; try { final FileOutputStream output; if (noDirectories) { output = new FileOutputStream("metadata.xml"); } else if (allInOneDirecotry) { - Files.createDirectories(Paths.get("testsuites")); - output = new FileOutputStream("testsuites/metadata.xml"); + Files.createDirectories(Paths.get("test-suite")); + output = new FileOutputStream("test-suite/metadata.xml"); // output = new FileOutputStream("metadata.xml"); } else { final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( From bc9765a02944180ecdcabbd016c2bcffddd1b310 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 21 Sep 2023 11:22:45 +0200 Subject: [PATCH 014/278] changed log level, fixed naive multi goal maybe --- .../traceabstraction/NwaCegarLoop.java | 30 ++++++++++++------- .../TestCompMetaFilePrinter.java | 1 - 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 42a649e715c..ed47cfebeed 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -178,7 +178,7 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) .getNestedRun(); @@ -300,8 +303,8 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; } else { - mLogger.fatal("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); - mLogger.fatal("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mLogger.info("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); + mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); mCounterexample = new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) @@ -318,20 +321,21 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } if (mCounterexample == null) { - mLogger.fatal("TestGen, CEGAR Iterations: " + CegarLoopIterations); - mLogger.fatal("TestGen, Coverage: " + Covered / mErrorLocs.size()); + mLogger.info("TestGen, CEGAR Iterations: " + CegarLoopIterations); + mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { mLongTraceTime = System.nanoTime() - startTime; - mLogger.fatal("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); - mLogger.fatal("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); + mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); } - mLogger.fatal("TestGen, Amount of Tests Exported: " + mTestsExported); + mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); final long estimatedTime = System.nanoTime() - startTime; if (mWriteEvaluationToFile) { writeEvalRow(estimatedTime, mLongTraceTime); } return; } + mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); final List a = mCounterexample.getStateSequence(); for (int i = 0; i < a.size(); i++) { if (a.get(i) instanceof ISLPredicate) { @@ -555,9 +559,13 @@ private void testGenerationCoverage() { Covered += 1; if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { CoveredLongTrace += 1; + mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); + mLogger.info("TestGen, Coverage: " + CoveredLongTrace / mErrorLocs.size()); } } } + + mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); } diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index 03dc4bc7b6e..fd299e1e165 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -92,7 +92,6 @@ public void printMetaFile() throws Exception { } else if (allInOneDirecotry) { Files.createDirectories(Paths.get("test-suite")); output = new FileOutputStream("test-suite/metadata.xml"); - // output = new FileOutputStream("metadata.xml"); } else { final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); From 7464f1ad71e4f1a9f4880ceba70db09e38aa6644 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 23 Sep 2023 16:36:45 +0200 Subject: [PATCH 015/278] Bugfix Coverage WorkSet was not resetted --- .../plugins/generator/traceabstraction/NwaCegarLoop.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index ed47cfebeed..060589d841b 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -267,6 +267,7 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro mTestGoalWorkingSet.add(mCurrentTestGoalId); if (!mTestGeneration.equals(TestGenerationMode.NaiveMultiGoal)) { mCurrentTestGoalId -= 1; + assert mTestGoalWorkingSet.size() == 1; } for (final IPredicate testGoal : mAbstraction.getFinalStates()) { final ISLPredicate testGoalISL = (ISLPredicate) testGoal; @@ -337,6 +338,7 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro } mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); final List a = mCounterexample.getStateSequence(); + mTestGoalsInCurrentTrace.clear(); for (int i = 0; i < a.size(); i++) { if (a.get(i) instanceof ISLPredicate) { final ISLPredicate stmt = (ISLPredicate) a.get(i); @@ -345,7 +347,6 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro mTestGoalsInCurrentTrace.add(((TestGoalAnnotation) stmt.getProgramPoint().getPayload() .getAnnotations().get(TestGoalAnnotation.class.getName())).mId); } - } } CegarLoopIterations += 1; @@ -564,9 +565,9 @@ private void testGenerationCoverage() { } } } - mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); + } private void computeAutomataDifference(final INestedWordAutomaton minuend, From 284fa05a0e39e78002e86d1a4fe0a24d332b26eb Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 27 Sep 2023 17:54:22 +0200 Subject: [PATCH 016/278] added testgoals to switch statements added doxtype to xmls --- .../implementation/base/CHandler.java | 28 +++++++++++++++++++ .../singletracecheck/TestExporter.java | 10 ++++++- .../TestCompMetaFilePrinter.java | 8 ++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 7117b3edb5b..563ed4aae15 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -2405,6 +2405,20 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { resultBuilder.addOverapprox(res.getOverapprs()); for (final Statement s : res.getStatements()) { if (s instanceof BreakStatement) { + if (mTestGenerationBranchCoverage) { + final ArrayList ifBlockWithTestGoal = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + countTestGoals += 1; + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + ifBlockWithTestGoal.add(assertFalseThen); + ifBlockWithTestGoal.addAll(ifBlock); + ifBlock = ifBlockWithTestGoal; + } ifBlock.add(new GotoStatement(locC, new String[] { breakLabelName })); } else { ifBlock.add(s); @@ -2417,6 +2431,20 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { resultBuilder.addDeclarations(Arrays.asList(b.getLocalVars())); for (final Statement s : b.getBlock()) { if (s instanceof BreakStatement) { + if (mTestGenerationBranchCoverage) { + final ArrayList ifBlockWithTestGoal = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + countTestGoals += 1; + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + ifBlockWithTestGoal.add(assertFalseThen); + ifBlockWithTestGoal.addAll(ifBlock); + ifBlock = ifBlockWithTestGoal; + } ifBlock.add(new GotoStatement(locC, new String[] { breakLabelName })); } else { ifBlock.add(s); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index b60c84c89e4..dcb9ae8322c 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -20,7 +20,9 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import de.uni_freiburg.informatik.ultimate.logic.Term; @@ -85,7 +87,7 @@ private Document createXML(final TestVector tv) throws ParserConfigurationExcept final Document dom = db.newDocument(); // create the root element - final Element rootEle = dom.createElement("testcases"); + final Element rootEle = dom.createElement("testcase"); // create data elements and place them under root @@ -108,6 +110,12 @@ private static void writeXml(final Document doc, final OutputStream output) thro final Transformer transformer = transformerFactory.newTransformer(); // pretty print XML transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + final DOMImplementation domImpl = doc.getImplementation(); + final DocumentType doctype = + domImpl.createDocumentType("testcase", "+//IDN sosy-lab.org//DTD test-format testcase 1.1//EN", + "https://sosy-lab.org/test-format/testcase-1.1.dtd"); + transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId()); + transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId()); final DOMSource source = new DOMSource(doc); final StreamResult result = new StreamResult(output); diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index fd299e1e165..69ef83e59a8 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -43,7 +43,9 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider; @@ -186,6 +188,12 @@ private static void writeXml(final Document doc, final OutputStream output) thro final Transformer transformer = transformerFactory.newTransformer(); // pretty print XML transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + final DOMImplementation domImpl = doc.getImplementation(); + final DocumentType doctype = domImpl.createDocumentType("test-metadata", + "+//IDN sosy-lab.org//DTD test-format test-metadata 1.1//EN", + "https://sosy-lab.org/test-format/test-metadata-1.1.dtd"); + transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId()); + transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId()); final DOMSource source = new DOMSource(doc); final StreamResult result = new StreamResult(output); From 6b16b16e10b21d91da41f365653d6810a71b68d2 Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 29 Sep 2023 00:47:48 +0200 Subject: [PATCH 017/278] Addded Test Goals for Conditional and Switch Fixed TestCase Ouput for negative numbers from (- 1) to -1 --- .../base/CExpressionTranslator.java | 73 +++++++++++++- .../implementation/base/CHandler.java | 94 ++++++++++--------- .../singletracecheck/TestExporter.java | 2 + 3 files changed, 119 insertions(+), 50 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index 7502cf65f61..e3b006b8c29 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -54,6 +54,7 @@ import de.uni_freiburg.informatik.ultimate.boogie.ast.StructAccessExpression; import de.uni_freiburg.informatik.ultimate.boogie.ast.UnaryExpression; import de.uni_freiburg.informatik.ultimate.boogie.ast.VariableDeclaration; +import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.LocationFactory; import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.chandler.MemoryHandler; import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.chandler.StaticObjectsHandler; import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.base.chandler.TypeSizes; @@ -78,6 +79,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Overapprox; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.plugins.generator.cacsl2boogietranslator.preferences.CACSLPreferenceInitializer.PointerCheckMode; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; @@ -100,6 +102,10 @@ public class CExpressionTranslator { private final TypeSizes mTypeSizes; private final AuxVarInfoBuilder mAuxVarInfoBuilder; + private int mTestGoalCount; + private LocationFactory mLocationFactory; + private boolean mTestGenerationBranchCoverage = false; + public CExpressionTranslator(final TranslationSettings settings, final MemoryHandler memoryHandler, final ExpressionTranslation expressionTranslation, final ExpressionResultTransformer exprResultTransformer, final AuxVarInfoBuilder auxVarInfoBuilder, final TypeSizes typeSizes, @@ -795,7 +801,7 @@ public ExpressionResult handleConditionalOperator(final ILocation loc, final Exp resultCType = opPositive.getLrValue().getCType(); } return constructResultForConditionalOperator(loc, opCondition, opPositive, opNegative, resultCType, - secondArgIsVoid, thirdArgIsVoid); + secondArgIsVoid, thirdArgIsVoid, hook); } /** @@ -803,7 +809,7 @@ public ExpressionResult handleConditionalOperator(final ILocation loc, final Exp */ private ExpressionResult constructResultForConditionalOperator(final ILocation loc, final ExpressionResult opCondition, final ExpressionResult opPositive, final ExpressionResult opNegative, - final CType resultCType, final boolean secondArgIsVoid, final boolean thirdArgIsVoid) { + final CType resultCType, final boolean secondArgIsVoid, final boolean thirdArgIsVoid, final IASTNode hook) { final ExpressionResultBuilder resultBuilder = new ExpressionResultBuilder(); // TODO: a solution that checks if the void value is ever assigned would be nice, but unclear if necessary @@ -849,9 +855,17 @@ private ExpressionResult constructResultForConditionalOperator(final ILocation l final List elseStatements = new ArrayList<>(); assignAuxVar(loc, opPositive, resultBuilder, auxvar, ifStatements, secondArgIsVoid); assignAuxVar(loc, opNegative, resultBuilder, auxvar, elseStatements, thirdArgIsVoid); - final Statement rtrStatement = new IfStatement(loc, opCondition.getLrValue().getValue(), - ifStatements.toArray(new Statement[ifStatements.size()]), - elseStatements.toArray(new Statement[elseStatements.size()])); + final Statement rtrStatement; + if (mTestGenerationBranchCoverage) { + + rtrStatement = addTestGoalsToConditionalOperator(loc, opCondition, ifStatements, elseStatements, + secondArgIsVoid, thirdArgIsVoid, hook); + } else { + rtrStatement = new IfStatement(loc, opCondition.getLrValue().getValue(), + ifStatements.toArray(new Statement[ifStatements.size()]), + elseStatements.toArray(new Statement[elseStatements.size()])); + } + for (final Overapprox overapprItem : resultBuilder.getOverappr()) { overapprItem.annotate(rtrStatement); } @@ -1160,4 +1174,53 @@ private static void assignAuxVar(final ILocation loc, final ExpressionResult bra } + /* + * caller ensures we are in a test generation setting + * + * testGoalCount needs to be added in CHandler separately + */ + private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final ExpressionResult opCondition, + final List ifStatements, final List elseStatements, final boolean secondArgIsVoid, + final boolean thirdArgIsVoid, final IASTNode node) { + final ArrayList thenArray = new ArrayList(); + final ArrayList elseArray = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + if (!secondArgIsVoid) { + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + thenArray.add(assertFalseThen); + + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + } + thenArray.addAll(ifStatements); + if (!thirdArgIsVoid) { + final ILocation loc2 = mLocationFactory.createCLocation(node); + final Statement assertFalseElse = + new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); + + final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + tg2.annotate(assertFalseElse); + chk.annotate(assertFalseElse); + elseArray.add(assertFalseElse); + + } + elseArray.addAll(elseStatements); + return new IfStatement(loc, opCondition.getLrValue().getValue(), + thenArray.toArray(new Statement[thenArray.size()]), elseArray.toArray(new Statement[elseArray.size()])); + } + + public int getTestGoalCount() { + return mTestGoalCount; + } + + public void setTestGoalCountAndFactory(final int testGoalCount, final LocationFactory locationFactory) { + mTestGenerationBranchCoverage = true; + mLocationFactory = locationFactory; + mTestGoalCount = testGoalCount; + } } diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 563ed4aae15..d2b5ed41df8 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -372,7 +372,7 @@ public class CHandler { // Test Generation private final boolean mTestGenerationErrorCoverage; private final boolean mTestGenerationBranchCoverage; - private int countTestGoals = 0; + private int mTestGoalCount = 0; /** * Constructor for CHandler in pre-run mode. @@ -1143,7 +1143,16 @@ public Result visit(final IDispatcher main, final IASTConditionalExpression node opPositive = mExprResultTransformer.switchToRValue(opPositive, loc, node); ExpressionResult opNegative = (ExpressionResult) main.dispatch(node.getNegativeResultExpression()); opNegative = mExprResultTransformer.switchToRValue(opNegative, loc, node); - return mCExpressionTranslator.handleConditionalOperator(loc, opCondition, opPositive, opNegative, node); + if (mTestGenerationBranchCoverage) { + mCExpressionTranslator.setTestGoalCountAndFactory(mTestGoalCount, mLocationFactory); + final ExpressionResult result = + mCExpressionTranslator.handleConditionalOperator(loc, opCondition, opPositive, opNegative, node); + mTestGoalCount = mCExpressionTranslator.getTestGoalCount(); + return result; + } else { + return mCExpressionTranslator.handleConditionalOperator(loc, opCondition, opPositive, opNegative, node); + } + } public Result visit(final IDispatcher main, final IASTContinueStatement cs) { @@ -1737,18 +1746,15 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { // mLogger für statistik final IfStatement ifStmt; if (mTestGenerationBranchCoverage) { - - final ArrayList thenArray = new ArrayList(); - final ArrayList elseArray = new ArrayList(); + final ArrayList thenArray = new ArrayList(); + final ArrayList elseArray = new ArrayList(); final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); final ILocation loc1 = mLocationFactory.createCLocation(node); final Statement assertFalseThen = new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); - final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); - // assertFalseThen.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", - // tg1); - countTestGoals += 1; + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; thenArray.add(assertFalseThen); thenArray.addAll(thenStmt); tg1.annotate(assertFalseThen); @@ -1758,10 +1764,8 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { final Statement assertFalseElse = new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); - final TestGoalAnnotation tg2 = new TestGoalAnnotation(countTestGoals); - countTestGoals += 1; - // assertFalseElse.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", - // tg2); + final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; tg2.annotate(assertFalseElse); chk.annotate(assertFalseElse); elseArray.add(assertFalseElse); @@ -2359,6 +2363,20 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { if (child instanceof IASTCaseStatement || child instanceof IASTDefaultStatement) { ExpressionResult caseExpression = (ExpressionResult) main.dispatch(child); if (locC != null) { + if (mTestGenerationBranchCoverage) { + final ArrayList ifBlockWithTestGoal = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + ifBlockWithTestGoal.add(assertFalseThen); + ifBlockWithTestGoal.addAll(ifBlock); + ifBlock = ifBlockWithTestGoal; + } final IfStatement ifStmt = new IfStatement(locC, switchAuxvar.getExp(), ifBlock.toArray(new Statement[ifBlock.size()]), new Statement[0]); for (final Overapprox overapprItem : caseExpression.getOverapprs()) { @@ -2405,20 +2423,6 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { resultBuilder.addOverapprox(res.getOverapprs()); for (final Statement s : res.getStatements()) { if (s instanceof BreakStatement) { - if (mTestGenerationBranchCoverage) { - final ArrayList ifBlockWithTestGoal = new ArrayList(); - final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); - final ILocation loc1 = mLocationFactory.createCLocation(node); - final Statement assertFalseThen = - new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); - final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); - countTestGoals += 1; - tg1.annotate(assertFalseThen); - chk.annotate(assertFalseThen); - ifBlockWithTestGoal.add(assertFalseThen); - ifBlockWithTestGoal.addAll(ifBlock); - ifBlock = ifBlockWithTestGoal; - } ifBlock.add(new GotoStatement(locC, new String[] { breakLabelName })); } else { ifBlock.add(s); @@ -2431,20 +2435,6 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { resultBuilder.addDeclarations(Arrays.asList(b.getLocalVars())); for (final Statement s : b.getBlock()) { if (s instanceof BreakStatement) { - if (mTestGenerationBranchCoverage) { - final ArrayList ifBlockWithTestGoal = new ArrayList(); - final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); - final ILocation loc1 = mLocationFactory.createCLocation(node); - final Statement assertFalseThen = - new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); - final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); - countTestGoals += 1; - tg1.annotate(assertFalseThen); - chk.annotate(assertFalseThen); - ifBlockWithTestGoal.add(assertFalseThen); - ifBlockWithTestGoal.addAll(ifBlock); - ifBlock = ifBlockWithTestGoal; - } ifBlock.add(new GotoStatement(locC, new String[] { breakLabelName })); } else { ifBlock.add(s); @@ -2455,6 +2445,20 @@ public Result visit(final IDispatcher main, final IASTSwitchStatement node) { } if (locC != null) { assert cond != null; + if (mTestGenerationBranchCoverage) { + final ArrayList ifBlockWithTestGoal = new ArrayList(); + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + final ILocation loc1 = mLocationFactory.createCLocation(node); + final Statement assertFalseThen = + new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + ifBlockWithTestGoal.add(assertFalseThen); + ifBlockWithTestGoal.addAll(ifBlock); + ifBlock = ifBlockWithTestGoal; + } final IfStatement ifStmt = new IfStatement(locC, switchAuxvar.getExp(), ifBlock.toArray(new Statement[ifBlock.size()]), new Statement[0]); for (final Overapprox overapprItem : resultBuilder.getOverappr()) { @@ -3691,10 +3695,10 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res final ILocation loc1 = mLocationFactory.createCLocation(node); final Statement assertFalseThen = new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); - final TestGoalAnnotation tg1 = new TestGoalAnnotation(countTestGoals); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); // assertFalseThen.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", // tg1); - countTestGoals += 1; + mTestGoalCount += 1; thenArray.add(assertFalseThen); thenArray.addAll(thenStmt); tg1.annotate(assertFalseThen); @@ -3704,8 +3708,8 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res final Statement assertFalseElse = new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); - final TestGoalAnnotation tg2 = new TestGoalAnnotation(countTestGoals); - countTestGoals += 1; + final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; // assertFalseElse.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", // tg2); tg2.annotate(assertFalseElse); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index dcb9ae8322c..57a135c770e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -94,6 +94,8 @@ private Document createXML(final TestVector tv) throws ParserConfigurationExcept for (final Term va : tv.values) { if (va != null) { final Element element = dom.createElement("input"); + String inputValue = va.toStringDirect(); + inputValue = inputValue.replaceAll("[\\(\\)\\s]", ""); element.appendChild(dom.createTextNode(va.toStringDirect())); rootEle.appendChild(element); } From 485ac4d7410a652e3391d66e2a6211cf0f2684be Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 2 Oct 2023 01:17:37 +0200 Subject: [PATCH 018/278] Changed Output, Made sure Overaprox is represented in Result --- .../base/CExpressionTranslator.java | 10 +-- .../implementation/base/CHandler.java | 10 +-- .../singletracecheck/TestExporter.java | 81 +++++++++++++++++-- .../singletracecheck/TraceCheck.java | 4 +- .../traceabstraction/AbstractCegarLoop.java | 6 +- .../CegarLoopResultReporter.java | 6 ++ .../SimpleErrorAutomatonBuilder.java | 2 +- 7 files changed, 98 insertions(+), 21 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index e3b006b8c29..59a8de3517f 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -1185,10 +1185,9 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final final ArrayList thenArray = new ArrayList(); final ArrayList elseArray = new ArrayList(); final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); - if (!secondArgIsVoid) { - final ILocation loc1 = mLocationFactory.createCLocation(node); + if (!secondArgIsVoid) { // TODO do we need a test goal either way? final Statement assertFalseThen = - new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; thenArray.add(assertFalseThen); @@ -1197,10 +1196,9 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final chk.annotate(assertFalseThen); } thenArray.addAll(ifStatements); - if (!thirdArgIsVoid) { - final ILocation loc2 = mLocationFactory.createCLocation(node); + if (!thirdArgIsVoid) { // TODO do we need a test goal either way? final Statement assertFalseElse = - new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index d2b5ed41df8..843914358a3 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -1745,14 +1745,13 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { // Annotation zur identifikation // mLogger für statistik final IfStatement ifStmt; - if (mTestGenerationBranchCoverage) { + if (mTestGenerationBranchCoverage && !loc.toString().contains("C: if (0) ; else __assert_fail")) { final ArrayList thenArray = new ArrayList(); final ArrayList elseArray = new ArrayList(); final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); - final ILocation loc1 = mLocationFactory.createCLocation(node); final Statement assertFalseThen = - new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; thenArray.add(assertFalseThen); @@ -1760,16 +1759,15 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { tg1.annotate(assertFalseThen); chk.annotate(assertFalseThen); - final ILocation loc2 = mLocationFactory.createCLocation(node); final Statement assertFalseElse = - new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); - + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; tg2.annotate(assertFalseElse); chk.annotate(assertFalseElse); elseArray.add(assertFalseElse); elseArray.addAll(elseStmt); + ifStmt = new IfStatement(loc, cond.getValue(), thenArray.toArray(new Statement[thenArray.size()]), elseArray.toArray(new Statement[elseArray.size()])); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 57a135c770e..8ba8efeee94 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -9,6 +9,8 @@ import java.util.Comparator; import java.util.LinkedHashSet; import java.util.LinkedList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -25,6 +27,8 @@ import org.w3c.dom.DocumentType; import org.w3c.dom.Element; +import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; +import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; import de.uni_freiburg.informatik.ultimate.logic.Term; public class TestExporter { @@ -90,13 +94,59 @@ private Document createXML(final TestVector tv) throws ParserConfigurationExcept final Element rootEle = dom.createElement("testcase"); // create data elements and place them under root - + String valueString = null; for (final Term va : tv.values) { if (va != null) { + switch (va.getSort().getName()) { + case SmtSortUtils.FLOATINGPOINT_SORT: { + assert va instanceof ApplicationTerm; + final ApplicationTerm cva = (ApplicationTerm) va; + + String sign = cva.getParameters()[0].toStringDirect(); + sign = sign.replaceAll("[^01]", ""); + + String exponent = cva.getParameters()[1].toStringDirect(); + exponent = exponent.replaceAll("[^01]", ""); + + String significant = cva.getParameters()[2].toStringDirect(); + significant = significant.replaceAll("[^01]", ""); + + final String floatAsBitString = sign + exponent + significant; + final int intBits = (int) Long.parseLong(floatAsBitString, 2); + final float myFloat = Float.intBitsToFloat(intBits); + + valueString = myFloat + ""; + break; + } + case SmtSortUtils.BITVECTOR_SORT: { + final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(va.toStringDirect()); + valueString = m.group(); + break; + } + case SmtSortUtils.INT_SORT: { + valueString = va.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + break; + } + case SmtSortUtils.REAL_SORT: { + valueString = va.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + break; + } + // case SmtSortUtils.BOOL_SORT: { + // if (SmtUtils.isTrueLiteral(va)) { + // valueString = "1"; + // } else { + // valueString = "0"; + // } + // break; + // } + default: { + throw new AssertionError("Unexpected Sort For Test Output"); + } + } + final Element element = dom.createElement("input"); - String inputValue = va.toStringDirect(); - inputValue = inputValue.replaceAll("[\\(\\)\\s]", ""); - element.appendChild(dom.createTextNode(va.toStringDirect())); + + element.appendChild(dom.createTextNode(valueString)); rootEle.appendChild(element); } } @@ -146,9 +196,20 @@ public void findMakeFileAndDir() { class TestVector { final LinkedList values = new LinkedList<>(); + final LinkedList valuesWithNegativeIndices = new LinkedList<>(); + final LinkedList valuesWithPositiveIndices = new LinkedList<>(); + int countNonDets = 0; public void addValueAssignment(final Term value, final int position) { - addToLinkedList(values, position, value); + if (position < 0) { + throw new UnsupportedOperationException("Negative Position fo NonDet in SSA"); + // addNegativPositionToLinkedList(valuesWithNegativeIndices, position, value); + } else { + countNonDets += 1; + addToLinkedList(values, position, value); + // addToLinkedList(valuesWithPositiveIndices, position, value); + } + } private void addToLinkedList(final LinkedList testVector, final Integer index, final Term t) { @@ -160,7 +221,17 @@ private void addToLinkedList(final LinkedList testVector, final Integer in testVector.add(index, t); } + private void addNegativPositionToLinkedList(final LinkedList testVector, final Integer index, final Term t) { + assert index < 0; + testVector.add(t); + } + public boolean isEmpty() { return values.isEmpty(); } + + public void addValuesWithNegativeIndex() { + values.addAll(valuesWithNegativeIndices); + values.addAll(valuesWithPositiveIndices); + } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index f0d03b6c93e..4c2adfd2539 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -426,6 +426,8 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final boolean mTestGeneration = true; if (mTestGeneration) { final TestVector testV = extractTestVector(nsb, funGetValue, rpeb); + // testV.addValuesWithNegativeIndex(); + System.out.println("Amount Of NonDets in TestCase: " + testV.countNonDets); final boolean mExportTests = true; if (mExportTests) { final boolean mExportAllInOneFile = true; @@ -468,7 +470,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (indexedVar.toStringDirect().contains("nondet") && firstRepresentatives) { assert indexedRepresentatives.entrySet().size() == 2; // TODO Not sure if save, but by far the best solution - testV.addValueAssignment(valueT, index); // Only if nondetINT!! + testV.addValueAssignment(valueT, index); // Only if nondetINT!!} firstRepresentatives = false; } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index 1818e6cebd5..90ec9337303 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -551,7 +551,8 @@ private AutomatonType processFeasibilityCheckResult(final LBool isCounterexample if (sequence.get(i) instanceof ISLPredicate) { if (node.getPayload().getAnnotations() .containsKey(TestGoalAnnotation.class.getName())) { - mResultBuilder.addResult(node, Result.TEST_GENERATION, null, null, null); + mResultBuilder.addResult(node, Result.TEST_GENERATION, programExecution, null, + null); } } } @@ -755,10 +756,11 @@ public enum Result { * The user-specified limit for the amount of analysis attempts per path program was hit */ USER_LIMIT_PATH_PROGRAM(4), + /** * Test Generation Terminated */ - TEST_GENERATION(0); + TEST_GENERATION(4); private final int mHierarchy; diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index e47b4907cba..4713801bca3 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -128,6 +128,7 @@ public void reportCegarLoopResult(final CegarLoopResult clres) { reportUnproveableResult(errorLoc, pe, localResult.getUnprovabilityReasons()); break; case TEST_GENERATION: + reportTestGenerationResult(errorLoc, localResult.getProgramExecution()); break; default: @@ -160,6 +161,11 @@ private void reportPositiveResult(final IcfgLocation errorLoc) { } private void reportTestGenerationResult(final IcfgLocation errorLoc, final IProgramExecution pe) { + final List upreasons = UnprovabilityReason.getUnprovabilityReasons(pe); + if (!upreasons.isEmpty()) { + reportUnproveableResult(errorLoc, pe, upreasons); + return; + } final IResult cexResult = new TestGenerationResult(mPluginName); mReportFunction.accept(errorLoc, cexResult); } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java index 6e4df763e22..f50764a54fb 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java @@ -69,7 +69,7 @@ public SimpleErrorAutomatonBuilder(final IUltimateServiceProvider services, fina mTruePredicate = predicateUnifier.getTruePredicate(); mResult = constructStraightLineAutomaton(services, csToolkit, predicateFactory, predicateUnifier, predicateFactoryErrorAutomaton, NestedWordAutomataUtils.getVpAlphabet(abstraction), trace); - addCoveredTestGoalsToErrorAutomaton(trace, counterexample, abstraction); + addCoveredTestGoalsToErrorAutomaton(trace, counterexample, abstraction); // TODO double eroor locaiton? } From eb7d5379b78bb98570b7f14d6a16aa29a8e8c42f Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 4 Oct 2023 00:58:41 +0200 Subject: [PATCH 019/278] Fix TestVectors in range and added testgoals to conditional statement --- .../base/CExpressionTranslator.java | 44 ++- .../implementation/base/CHandler.java | 23 +- .../singletracecheck/TestExporter.java | 312 ++++++++++++++---- .../singletracecheck/TraceCheck.java | 13 +- 4 files changed, 309 insertions(+), 83 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index 59a8de3517f..0bda02924f7 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -825,11 +825,47 @@ private ExpressionResult constructResultForConditionalOperator(final ILocation l resultBuilder.addAllExceptLrValue(opCondition, opPositive, opNegative); if (resultCType.isVoidType()) { // result type is void the value is not assigned + // TODO do we have to do sth here for test generation? } else { - final Expression ite = - ExpressionFactory.constructIfThenElseExpression(loc, opCondition.getLrValue().getValue(), - opPositive.getLrValue().getValue(), opNegative.getLrValue().getValue()); - resultBuilder.setLrValue(new RValue(ite, resultCType)); + if (mTestGenerationBranchCoverage) { + // void reach_error() { ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail + // ("0", "knuth.c", 7, __extension__ __PRETTY_FUNCTION__); })); } + final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + + final Statement assertFalseThen = new AssertStatement(loc, opCondition.getLrValue().getValue()); + final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + + tg1.annotate(assertFalseThen); + chk.annotate(assertFalseThen); + resultBuilder.addStatement(assertFalseThen); + Expression negated = null; + if (opCondition.getLrValue().isBoogieBool()) { + // in Boogie already represented by bool, we only negate + negated = ExpressionFactory.constructUnaryExpression(loc, UnaryExpression.Operator.LOGICNEG, + opCondition.getLrValue().getValue()); + } else { + throw new IllegalArgumentException("TODO other than BoogieBool"); + } + final Statement assertFalseElse = new AssertStatement(loc, negated); + + final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); + mTestGoalCount += 1; + tg2.annotate(assertFalseElse); + chk.annotate(assertFalseElse); + resultBuilder.addStatement(assertFalseElse); + + final Expression ite = + ExpressionFactory.constructIfThenElseExpression(loc, opCondition.getLrValue().getValue(), + opPositive.getLrValue().getValue(), opNegative.getLrValue().getValue()); + resultBuilder.setLrValue(new RValue(ite, resultCType)); + } else { + + final Expression ite = + ExpressionFactory.constructIfThenElseExpression(loc, opCondition.getLrValue().getValue(), + opPositive.getLrValue().getValue(), opNegative.getLrValue().getValue()); + resultBuilder.setLrValue(new RValue(ite, resultCType)); + } } } else { // Second or third operand has side-effects, we have to translate to an diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 843914358a3..ee050a3a985 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -1689,7 +1689,7 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { final List overappr = new ArrayList<>(); // final Map emptyAuxVars = new // LinkedHashMap<>(); - + // Hier schon test goal id erhöhen?? ExpressionResult condResult = (ExpressionResult) main.dispatch(node.getConditionExpression()); condResult = mExprResultTransformer.transformSwitchRexIntToBool(condResult, loc, node); final RValue cond = (RValue) condResult.getLrValue(); @@ -1698,6 +1698,7 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { overappr.addAll(condResult.getOverapprs()); final List havocs = CTranslationUtil.createHavocsForAuxVars(condResult.getAuxVars()); + // hier recursion!!!s final Result thenResult = main.dispatch(node.getThenClause()); final List thenStmt = new ArrayList<>(); thenStmt.addAll(havocs); @@ -1754,10 +1755,10 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; - thenArray.add(assertFalseThen); - thenArray.addAll(thenStmt); tg1.annotate(assertFalseThen); chk.annotate(assertFalseThen); + thenArray.add(assertFalseThen); + thenArray.addAll(thenStmt); final Statement assertFalseElse = new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); @@ -3690,26 +3691,22 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res final ArrayList elseArray = new ArrayList(); final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); - final ILocation loc1 = mLocationFactory.createCLocation(node); final Statement assertFalseThen = - new AssertStatement(loc1, ExpressionFactory.createBooleanLiteral(loc1, false)); + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); - // assertFalseThen.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", - // tg1); + mTestGoalCount += 1; - thenArray.add(assertFalseThen); - thenArray.addAll(thenStmt); tg1.annotate(assertFalseThen); chk.annotate(assertFalseThen); + thenArray.add(assertFalseThen); + thenArray.addAll(thenStmt); - final ILocation loc2 = mLocationFactory.createCLocation(node); final Statement assertFalseElse = - new AssertStatement(loc2, ExpressionFactory.createBooleanLiteral(loc2, false)); + new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; - // assertFalseElse.getPayload().getAnnotations().put("TEST_GOAL_ANNOTATION", - // tg2); + tg2.annotate(assertFalseElse); chk.annotate(assertFalseElse); elseArray.add(assertFalseElse); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 8ba8efeee94..3f11cb0b6d6 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; @@ -47,7 +48,7 @@ public class TestExporter { */ public void exportTests(final TestVector testV, final int i, final boolean allInOneFile) throws Exception { - final FileOutputStream output; + FileOutputStream output; final String name = "testcase" + i; final boolean noDirectories = false; final boolean allInOneDirecotry = true; @@ -69,10 +70,14 @@ public void exportTests(final TestVector testV, final int i, final boolean allIn output = new FileOutputStream("testsuites/" + name + ".xml"); } } - writeXml(createXML(testV), output); // TODO Setting + writeXml(createXML(testV.values), output); + if (testV.need64Bit) { + output = new FileOutputStream("test-suite/" + name + "64bit" + ".xml"); + writeXml(createXML(testV.values64Bit), output); + } } - public static TestExporter getInstance() { + public static final TestExporter getInstance() { if (instance == null) { instance = new TestExporter(); } @@ -80,7 +85,7 @@ public static TestExporter getInstance() { } // TODO split exportation and creation of the testvectors. Means - private Document createXML(final TestVector tv) throws ParserConfigurationException { + final Document createXML(final LinkedList inputs) throws ParserConfigurationException { // instance of a DocumentBuilderFactory final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -94,58 +99,10 @@ private Document createXML(final TestVector tv) throws ParserConfigurationExcept final Element rootEle = dom.createElement("testcase"); // create data elements and place them under root - String valueString = null; - for (final Term va : tv.values) { - if (va != null) { - switch (va.getSort().getName()) { - case SmtSortUtils.FLOATINGPOINT_SORT: { - assert va instanceof ApplicationTerm; - final ApplicationTerm cva = (ApplicationTerm) va; - - String sign = cva.getParameters()[0].toStringDirect(); - sign = sign.replaceAll("[^01]", ""); - - String exponent = cva.getParameters()[1].toStringDirect(); - exponent = exponent.replaceAll("[^01]", ""); - - String significant = cva.getParameters()[2].toStringDirect(); - significant = significant.replaceAll("[^01]", ""); - - final String floatAsBitString = sign + exponent + significant; - final int intBits = (int) Long.parseLong(floatAsBitString, 2); - final float myFloat = Float.intBitsToFloat(intBits); - - valueString = myFloat + ""; - break; - } - case SmtSortUtils.BITVECTOR_SORT: { - final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(va.toStringDirect()); - valueString = m.group(); - break; - } - case SmtSortUtils.INT_SORT: { - valueString = va.toStringDirect().replaceAll("[\\(\\)\\s]", ""); - break; - } - case SmtSortUtils.REAL_SORT: { - valueString = va.toStringDirect().replaceAll("[\\(\\)\\s]", ""); - break; - } - // case SmtSortUtils.BOOL_SORT: { - // if (SmtUtils.isTrueLiteral(va)) { - // valueString = "1"; - // } else { - // valueString = "0"; - // } - // break; - // } - default: { - throw new AssertionError("Unexpected Sort For Test Output"); - } - } + for (final String valueString : inputs) { + if (valueString != null) { final Element element = dom.createElement("input"); - element.appendChild(dom.createTextNode(valueString)); rootEle.appendChild(element); } @@ -153,6 +110,7 @@ private Document createXML(final TestVector tv) throws ParserConfigurationExcept dom.appendChild(rootEle); return dom; + } // write doc to output stream @@ -195,30 +153,247 @@ public void findMakeFileAndDir() { class TestVector { - final LinkedList values = new LinkedList<>(); - final LinkedList valuesWithNegativeIndices = new LinkedList<>(); - final LinkedList valuesWithPositiveIndices = new LinkedList<>(); + final LinkedList values = new LinkedList<>(); + final LinkedList values64Bit = new LinkedList<>(); + final LinkedList valuesWithNegativeIndices = new LinkedList<>(); + final LinkedList valuesWithPositiveIndices = new LinkedList<>(); int countNonDets = 0; + boolean need64Bit = false; - public void addValueAssignment(final Term value, final int position) { + public void addValueAssignment(final Term value, final int position, final String type) { if (position < 0) { throw new UnsupportedOperationException("Negative Position fo NonDet in SSA"); // addNegativPositionToLinkedList(valuesWithNegativeIndices, position, value); } else { countNonDets += 1; - addToLinkedList(values, position, value); + addToLinkedList(position, value, type); + addToLinkedList64Bit(position, value, type); // addToLinkedList(valuesWithPositiveIndices, position, value); } } - private void addToLinkedList(final LinkedList testVector, final Integer index, final Term t) { - if (testVector.size() < index) { - for (int i = testVector.size(); i < index; i = i + 1) { - testVector.add(null); + private void addToLinkedList64Bit(final Integer index, final Term valueTerm, final String type) { + if (values64Bit.size() < index) { + for (int i = values64Bit.size(); i < index; i = i + 1) { + values64Bit.add(null); + } + } + String valueInRange = null; + switch (valueTerm.getSort().getName()) { + case SmtSortUtils.FLOATINGPOINT_SORT: { + assert valueTerm instanceof ApplicationTerm; + final ApplicationTerm cva = (ApplicationTerm) valueTerm; + String sign = cva.getParameters()[0].toStringDirect(); + sign = sign.replaceAll("[^01]", ""); + + String exponent = cva.getParameters()[1].toStringDirect(); + exponent = exponent.replaceAll("[^01]", ""); + + String significant = cva.getParameters()[2].toStringDirect(); + significant = significant.replaceAll("[^01]", ""); + + final String floatAsBitString = sign + exponent + significant; + final int intBits = (int) Long.parseLong(floatAsBitString, 2); + final float myFloat = Float.intBitsToFloat(intBits); + + valueInRange = myFloat + ""; + break; + } + case SmtSortUtils.BITVECTOR_SORT: { + final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(valueTerm.toStringDirect()); + m.find(); + valueInRange = m.group(1); + if (type.equals("int") || type.equals("long")) { // if signed + + if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 64) { + System.out.println("Warning Signed Bit-Vec: " + valueTerm); + final BigInteger value = new BigInteger(valueInRange); + if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { + // wenn 2147483648 dann -2,147,483,648 + final BigInteger newValue = new BigInteger("-9223372036854775808") + .add((value.subtract(new BigInteger("9223372036854775808")))); + + valueInRange = String.valueOf(newValue); + } + } } + break; } - testVector.add(index, t); + case SmtSortUtils.REAL_SORT: + case SmtSortUtils.INT_SORT: { + valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + + break; + } + + default: { + throw new AssertionError("Unexpected Sort For Test Output"); + } + } + + values64Bit.add(index, valueInRange); + } + + private void addToLinkedList(final Integer index, final Term valueTerm, final String type) { + if (values.size() < index) { + for (int i = values.size(); i < index; i = i + 1) { + values.add(null); + } + } + + String valueInRange = null; + switch (valueTerm.getSort().getName()) { + case SmtSortUtils.FLOATINGPOINT_SORT: { + assert valueTerm instanceof ApplicationTerm; + final ApplicationTerm cva = (ApplicationTerm) valueTerm; + String sign = cva.getParameters()[0].toStringDirect(); + sign = sign.replaceAll("[^01]", ""); + + String exponent = cva.getParameters()[1].toStringDirect(); + exponent = exponent.replaceAll("[^01]", ""); + + String significant = cva.getParameters()[2].toStringDirect(); + significant = significant.replaceAll("[^01]", ""); + + final String floatAsBitString = sign + exponent + significant; + final int intBits = (int) Long.parseLong(floatAsBitString, 2); + final float myFloat = Float.intBitsToFloat(intBits); + + valueInRange = myFloat + ""; + break; + } + case SmtSortUtils.BITVECTOR_SORT: { + final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(valueTerm.toStringDirect()); + m.find(); + valueInRange = m.group(1); + if (type.equals("int") || type.equals("long")) { // if signed + + if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 32) { + System.out.println("Warning Signed Bit-Vec: " + valueTerm); + final BigInteger value = new BigInteger(valueInRange); + if (value.compareTo(new BigInteger("2147483647")) == 1) { + // wenn 2147483648 dann -2,147,483,648 + final BigInteger newValue = + new BigInteger("-2147483648").add((value.subtract(new BigInteger("2147483648")))); + + valueInRange = String.valueOf(newValue); + } + } else { + need64Bit = true; + System.out.println("TestCase: Unexpected Bit-Vec Length: " + + SmtSortUtils.getBitvectorLength(valueTerm.getSort())); + } + } + break; + } + case SmtSortUtils.REAL_SORT: + case SmtSortUtils.INT_SORT: { + valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + final BigInteger value = new BigInteger(valueInRange); + if (type == "int" || type == "long") { + if (value.compareTo(new BigInteger("2147483647")) == 1) { + need64Bit = true; + } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + need64Bit = true; + } + } else { + if (value.compareTo(new BigInteger("4294967295")) == 1) { + need64Bit = true; + } + } + + switch (type) { + case "short": { + // -32,768 to 32,767 + + if (value.compareTo(new BigInteger("32767")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("32768")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-32768")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("32768")); + valueInRange = String.valueOf(newValue); + } + break; + } + case "ushort": { + // 0 to 65,535 + if (value.compareTo(new BigInteger("65535")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("65536")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(BigInteger.ZERO) == -1) { + final BigInteger newValue = new BigInteger("65536").add(value); + valueInRange = String.valueOf(newValue); + } + break; + } + case "int": { + // same as long? + } + case "long": { + if (value.compareTo(new BigInteger("2147483647")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("2147483648")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("2147483648")); + valueInRange = String.valueOf(newValue); + } + break; + } + case "uint": { + + } + case "ulong": { + if (value.compareTo(new BigInteger("4294967295")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("4294967296")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(BigInteger.ZERO) == -1) { + final BigInteger newValue = new BigInteger("4294967295").add(value); + valueInRange = String.valueOf(newValue); + } + break; + } + case "ulonglong": { + + // Cant be out of range? + break; + } + case "char": { + if (value.compareTo(new BigInteger("127")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("128")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-128")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("128")); + valueInRange = String.valueOf(newValue); + } + break; + } + case "uchar": { + if (value.compareTo(new BigInteger("255")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("256")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(BigInteger.ZERO) == -1) { + final BigInteger newValue = new BigInteger("256").add(value); + valueInRange = String.valueOf(newValue); + } + break; + } + default: + // TODO short, double etc. float nicht + System.out.println("TestCase: Unexpected Type Warning"); + } + break; + } + + default: { + throw new AssertionError("Unexpected Sort For Test Output"); + } + } + if (!valueInRange.equals(valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""))) { + System.out.println("TestCase: Warning Changed Export Value to fit in bounds: " + type); + } + values.add(index, valueInRange); + } private void addNegativPositionToLinkedList(final LinkedList testVector, final Integer index, final Term t) { @@ -234,4 +409,13 @@ public void addValuesWithNegativeIndex() { values.addAll(valuesWithNegativeIndices); values.addAll(valuesWithPositiveIndices); } + + public String getNonDetTypeFromName(final String payload) { + final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(payload); + m.find(); + System.out.println(m.group(1)); + + return m.group(1); + + } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 4c2adfd2539..f093f825019 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -67,6 +67,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.logic.TermVariable; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; /** * Check if a trace fulfills a specification. Provides an execution (that violates the specification) if the check was @@ -470,8 +471,16 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (indexedVar.toStringDirect().contains("nondet") && firstRepresentatives) { assert indexedRepresentatives.entrySet().size() == 2; // TODO Not sure if save, but by far the best solution - testV.addValueAssignment(valueT, index); // Only if nondetINT!!} - firstRepresentatives = false; + + if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { + final StatementSequence stsq = (StatementSequence) rpeb.mTrace.asList().get(index); + final String type = testV.getNonDetTypeFromName(stsq.getPayload().toString()); + testV.addValueAssignment(valueT, index, type); // Only if nondetINT!!} + firstRepresentatives = false; + } else { + throw new UnsupportedOperationException("Unexpected Statement"); + } + } } From 18d6e69de257faf17489658d29ff807c303274cb Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 4 Oct 2023 21:57:59 +0200 Subject: [PATCH 020/278] Write Input for each while loop iteration --- .../singletracecheck/TestExporter.java | 11 +++++-- .../singletracecheck/TraceCheck.java | 33 +++++++++++-------- .../CegarLoopResultReporter.java | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 3f11cb0b6d6..e473048d959 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -287,11 +287,17 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } break; } - case SmtSortUtils.REAL_SORT: + case SmtSortUtils.REAL_SORT: { + if (type.equals("float") || type.equals("double")) { + valueInRange = valueTerm.toStringDirect(); + System.out.println("TestCase: Unexpected Test Input Type: " + type); + break; + } + } case SmtSortUtils.INT_SORT: { valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); final BigInteger value = new BigInteger(valueInRange); - if (type == "int" || type == "long") { + if (type.equals("int") || type.equals("long")) { if (value.compareTo(new BigInteger("2147483647")) == 1) { need64Bit = true; } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { @@ -411,6 +417,7 @@ public void addValuesWithNegativeIndex() { } public String getNonDetTypeFromName(final String payload) { + System.out.println(payload); final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(payload); m.find(); System.out.println(m.group(1)); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index f093f825019..9996013af96 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -461,28 +461,35 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi final IProgramVar bv = entry.getKey(); final Map indexedRepresentatives = entry.getValue(); if (SmtUtils.isSortForWhichWeCanGetValues(bv.getTermVariable().getSort())) { - boolean firstRepresentatives = true; + boolean evenRepresentative = true; for (final var representative : indexedRepresentatives.entrySet()) { + final Integer index = representative.getKey(); final Term indexedVar = representative.getValue(); final Term valueT = funGetValue.apply(indexedVar); if (indexedVar instanceof ApplicationTerm) { assert ((ApplicationTerm) indexedVar).getParameters().length == 0; - if (indexedVar.toStringDirect().contains("nondet") && firstRepresentatives) { - assert indexedRepresentatives.entrySet().size() == 2; - // TODO Not sure if save, but by far the best solution - - if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { - final StatementSequence stsq = (StatementSequence) rpeb.mTrace.asList().get(index); - final String type = testV.getNonDetTypeFromName(stsq.getPayload().toString()); - testV.addValueAssignment(valueT, index, type); // Only if nondetINT!!} - firstRepresentatives = false; + if (indexedVar.toStringDirect().contains("nondet")) { + if (evenRepresentative) { + if (index >= 0) { + + assert indexedRepresentatives.entrySet().size() == 2; + // TODO Not sure if save, but by far the best solution + if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { + final StatementSequence stsq = + (StatementSequence) rpeb.mTrace.asList().get(index); + if (stsq.getPayload().toString().contains("nondet")) { + final String type = + testV.getNonDetTypeFromName(stsq.getPayload().toString()); + testV.addValueAssignment(valueT, index, type); // Only if nondetINT!!} + } + } + } + evenRepresentative = !evenRepresentative; } else { - throw new UnsupportedOperationException("Unexpected Statement"); + evenRepresentative = !evenRepresentative; } - } - } rpeb.addValueAtVarAssignmentPosition(bv, index, valueT); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index 4713801bca3..7b6fbef7aed 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -128,7 +128,7 @@ public void reportCegarLoopResult(final CegarLoopResult clres) { reportUnproveableResult(errorLoc, pe, localResult.getUnprovabilityReasons()); break; case TEST_GENERATION: - + // reportCounterexampleResult(errorLoc, localResult.getProgramExecution()); reportTestGenerationResult(errorLoc, localResult.getProgramExecution()); break; default: From 048b1600ffebc3b77ef4a7c74d3623ef6ec93646 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 5 Oct 2023 14:22:16 +0200 Subject: [PATCH 021/278] Changed intger to c type mapping --- .../singletracecheck/TestExporter.java | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index e473048d959..b5036534b73 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -312,55 +312,53 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St switch (type) { case "short": { // -32,768 to 32,767 - if (value.compareTo(new BigInteger("32767")) == 1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue); } else if (value.compareTo(new BigInteger("-32768")) == -1) { final BigInteger newValue = value.mod(new BigInteger("32768")); - valueInRange = String.valueOf(newValue); + valueInRange = String.valueOf(newValue.negate()); } break; } case "ushort": { // 0 to 65,535 - if (value.compareTo(new BigInteger("65535")) == 1) { - final BigInteger newValue = value.mod(new BigInteger("65536")); - valueInRange = String.valueOf(newValue); - } else if (value.compareTo(BigInteger.ZERO) == -1) { - final BigInteger newValue = new BigInteger("65536").add(value); - valueInRange = String.valueOf(newValue); - } + final BigInteger newValue = value.mod(new BigInteger("65536")); + valueInRange = String.valueOf(newValue); + break; } case "int": { - // same as long? - } - case "long": { if (value.compareTo(new BigInteger("2147483647")) == 1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue); } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); + valueInRange = String.valueOf(newValue.negate()); + } + break; + } + case "long": { + if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-9223372036854775808")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); + valueInRange = String.valueOf(newValue.negate()); } break; } case "uint": { - + final BigInteger newValue = value.mod(new BigInteger("4294967296")); + valueInRange = String.valueOf(newValue); + break; } case "ulong": { - if (value.compareTo(new BigInteger("4294967295")) == 1) { - final BigInteger newValue = value.mod(new BigInteger("4294967296")); - valueInRange = String.valueOf(newValue); - } else if (value.compareTo(BigInteger.ZERO) == -1) { - final BigInteger newValue = new BigInteger("4294967295").add(value); - valueInRange = String.valueOf(newValue); - } + final BigInteger newValue = value.mod(new BigInteger("18446744073709551616")); + valueInRange = String.valueOf(newValue); break; } case "ulonglong": { - // Cant be out of range? break; } @@ -370,18 +368,13 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St valueInRange = String.valueOf(newValue); } else if (value.compareTo(new BigInteger("-128")) == -1) { final BigInteger newValue = value.mod(new BigInteger("128")); - valueInRange = String.valueOf(newValue); + valueInRange = String.valueOf(newValue.negate()); } break; } case "uchar": { - if (value.compareTo(new BigInteger("255")) == 1) { - final BigInteger newValue = value.mod(new BigInteger("256")); - valueInRange = String.valueOf(newValue); - } else if (value.compareTo(BigInteger.ZERO) == -1) { - final BigInteger newValue = new BigInteger("256").add(value); - valueInRange = String.valueOf(newValue); - } + final BigInteger newValue = value.mod(new BigInteger("256")); + valueInRange = String.valueOf(newValue); break; } default: From 9106205a28eb96e30629f170c4e13a531d6e7671 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 5 Oct 2023 18:36:55 +0200 Subject: [PATCH 022/278] Long size depends on architecture, so we export two test cases --- .../singletracecheck/TestExporter.java | 96 +++++++++++++++---- 1 file changed, 79 insertions(+), 17 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index b5036534b73..ad25bf964eb 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -222,8 +222,82 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } case SmtSortUtils.REAL_SORT: case SmtSortUtils.INT_SORT: { + valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + final BigInteger value = new BigInteger(valueInRange); + + switch (type) { + case "short": { + // -32,768 to 32,767 + if (value.compareTo(new BigInteger("32767")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("32768")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-32768")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("32768")); + valueInRange = String.valueOf(newValue.negate()); + } + break; + } + case "ushort": { + // 0 to 65,535 + final BigInteger newValue = value.mod(new BigInteger("65536")); + valueInRange = String.valueOf(newValue); + break; + } + case "int": { + if (value.compareTo(new BigInteger("2147483647")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("2147483648")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("2147483648")); + valueInRange = String.valueOf(newValue.negate()); + } + break; + } + case "long": { + if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-9223372036854775808")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); + valueInRange = String.valueOf(newValue.negate()); + } + break; + } + case "uint": { + final BigInteger newValue = value.mod(new BigInteger("4294967296")); + valueInRange = String.valueOf(newValue); + break; + } + case "ulong": { + final BigInteger newValue = value.mod(new BigInteger("18446744073709551616")); + valueInRange = String.valueOf(newValue); + break; + } + case "ulonglong": { + // Cant be out of range? + break; + } + case "char": { + if (value.compareTo(new BigInteger("127")) == 1) { + final BigInteger newValue = value.mod(new BigInteger("128")); + valueInRange = String.valueOf(newValue); + } else if (value.compareTo(new BigInteger("-128")) == -1) { + final BigInteger newValue = value.mod(new BigInteger("128")); + valueInRange = String.valueOf(newValue.negate()); + } + break; + } + case "uchar": { + final BigInteger newValue = value.mod(new BigInteger("256")); + valueInRange = String.valueOf(newValue); + break; + } + default: + // TODO short, double etc. float nicht + System.out.println("TestCase: Unexpected Type Warning"); + } break; } @@ -233,6 +307,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } values64Bit.add(index, valueInRange); + } private void addToLinkedList(final Integer index, final Term valueTerm, final String type) { @@ -328,7 +403,8 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St break; } - case "int": { + case "int": + case "long": { if (value.compareTo(new BigInteger("2147483647")) == 1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue); @@ -338,23 +414,9 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } break; } - case "long": { - if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { - final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); - valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-9223372036854775808")) == -1) { - final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); - valueInRange = String.valueOf(newValue.negate()); - } - break; - } - case "uint": { - final BigInteger newValue = value.mod(new BigInteger("4294967296")); - valueInRange = String.valueOf(newValue); - break; - } + case "uint": case "ulong": { - final BigInteger newValue = value.mod(new BigInteger("18446744073709551616")); + final BigInteger newValue = value.mod(new BigInteger("4294967296")); valueInRange = String.valueOf(newValue); break; } From 8d93c099f1914ba2fbc2b3fc4366c3cf3539cc3b Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 6 Oct 2023 23:59:17 +0200 Subject: [PATCH 023/278] Added Test Export for double, fixed floats --- .../singletracecheck/TestExporter.java | 139 +++++++++++++----- .../singletracecheck/TraceCheck.java | 2 +- 2 files changed, 101 insertions(+), 40 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index ad25bf964eb..7994fab1f97 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -167,13 +167,17 @@ public void addValueAssignment(final Term value, final int position, final Strin } else { countNonDets += 1; addToLinkedList(position, value, type); - addToLinkedList64Bit(position, value, type); + if (need64Bit) { + addToLinkedList64Bit(position, value, type); + } + // addToLinkedList(valuesWithPositiveIndices, position, value); } } private void addToLinkedList64Bit(final Integer index, final Term valueTerm, final String type) { + need64Bit = false; if (values64Bit.size() < index) { for (int i = values64Bit.size(); i < index; i = i + 1) { values64Bit.add(null); @@ -207,7 +211,6 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin if (type.equals("int") || type.equals("long")) { // if signed if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 64) { - System.out.println("Warning Signed Bit-Vec: " + valueTerm); final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { // wenn 2147483648 dann -2,147,483,648 @@ -220,7 +223,13 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } break; } - case SmtSortUtils.REAL_SORT: + case SmtSortUtils.REAL_SORT: { + if (type.equals("float") || type.equals("double")) { + valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + + break; + } + } case SmtSortUtils.INT_SORT: { valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); @@ -276,7 +285,8 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin break; } case "ulonglong": { - // Cant be out of range? + final BigInteger newValue = value.mod(new BigInteger("18446744073709551616")); + valueInRange = String.valueOf(newValue); break; } case "char": { @@ -295,8 +305,6 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin break; } default: - // TODO short, double etc. float nicht - System.out.println("TestCase: Unexpected Type Warning"); } break; } @@ -320,65 +328,122 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - assert valueTerm instanceof ApplicationTerm; - final ApplicationTerm cva = (ApplicationTerm) valueTerm; - String sign = cva.getParameters()[0].toStringDirect(); - sign = sign.replaceAll("[^01]", ""); - - String exponent = cva.getParameters()[1].toStringDirect(); - exponent = exponent.replaceAll("[^01]", ""); - - String significant = cva.getParameters()[2].toStringDirect(); - significant = significant.replaceAll("[^01]", ""); - - final String floatAsBitString = sign + exponent + significant; - final int intBits = (int) Long.parseLong(floatAsBitString, 2); - final float myFloat = Float.intBitsToFloat(intBits); + if (type.equals("float")) { + if (((ApplicationTerm) valueTerm).getParameters().length == 3) { + assert valueTerm instanceof ApplicationTerm; + final ApplicationTerm cva = (ApplicationTerm) valueTerm; + String sign = cva.getParameters()[0].toStringDirect(); + sign = sign.replaceAll("[^01]", ""); + + String exponent = cva.getParameters()[1].toStringDirect(); + exponent = exponent.replaceAll("[^01]", ""); + + String significant = cva.getParameters()[2].toStringDirect(); + significant = significant.replaceAll("[^01]", ""); + final String floatAsBitString = sign + exponent + significant; + // final int intBits = Integer.parseInt(floatAsBitString, 2); + final int intBits = (int) Long.parseLong(floatAsBitString, 2); + final float asFloat = Float.intBitsToFloat(intBits); + valueInRange = asFloat + ""; + break; + } else { + if (valueTerm.toStringDirect().contains("+oo")) { + valueInRange = Float.POSITIVE_INFINITY + ""; + } else if (valueTerm.toStringDirect().contains("-oo")) { + valueInRange = Float.NEGATIVE_INFINITY + ""; + } else if (valueTerm.toStringDirect().contains("NaN")) { + valueInRange = Float.NaN + ""; + } else if (valueTerm.toStringDirect().contains("zero")) { + valueInRange = "0"; + } else { + throw new AssertionError("Unexpected Sort For Output Type"); + } + break; + } + } else if (type.equals("double")) { + assert valueTerm instanceof ApplicationTerm; + if (((ApplicationTerm) valueTerm).getParameters().length == 3) { + final ApplicationTerm cva = (ApplicationTerm) valueTerm; + String sign = cva.getParameters()[0].toStringDirect(); + sign = sign.replaceAll("[^01]", ""); + + String exponent = cva.getParameters()[1].toStringDirect(); + exponent = exponent.replaceAll("[^01]", ""); + + String significant = cva.getParameters()[2].toStringDirect(); + significant = significant.replaceAll("[^01]", ""); + final String floatAsBitString = sign + exponent + significant; + final long longBits = (new BigInteger(floatAsBitString, 2)).longValue(); + final double asDouble = Double.longBitsToDouble(longBits); + valueInRange = asDouble + ""; + break; + } else { + if (valueTerm.toStringDirect().contains("+oo")) { + valueInRange = Double.POSITIVE_INFINITY + ""; + } else if (valueTerm.toStringDirect().contains("-oo")) { + valueInRange = Double.NEGATIVE_INFINITY + ""; + } else if (valueTerm.toStringDirect().contains("NaN")) { + valueInRange = Double.NaN + ""; + } else if (valueTerm.toStringDirect().contains("zero")) { + valueInRange = "0"; + } else { + throw new AssertionError("Unexpected Sort For Output Type"); + } + break; + } + } else { + throw new AssertionError("Unexpected Sort For Output Type"); + } - valueInRange = myFloat + ""; - break; } case SmtSortUtils.BITVECTOR_SORT: { final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(valueTerm.toStringDirect()); m.find(); valueInRange = m.group(1); if (type.equals("int") || type.equals("long")) { // if signed - if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 32) { - System.out.println("Warning Signed Bit-Vec: " + valueTerm); final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("2147483647")) == 1) { // wenn 2147483648 dann -2,147,483,648 final BigInteger newValue = new BigInteger("-2147483648").add((value.subtract(new BigInteger("2147483648")))); - valueInRange = String.valueOf(newValue); } } else { need64Bit = true; - System.out.println("TestCase: Unexpected Bit-Vec Length: " - + SmtSortUtils.getBitvectorLength(valueTerm.getSort())); } + } else if (type.equals("char")) { + final BigInteger value = new BigInteger(valueInRange); + if (value.compareTo(new BigInteger("32767")) == 1) { + final BigInteger newValue = new BigInteger("-32768").add((value.subtract(new BigInteger("32768")))); + valueInRange = String.valueOf(newValue); + } + } else if (type.equals("short")) { + final BigInteger value = new BigInteger(valueInRange); + if (value.compareTo(new BigInteger("127")) == 1) { + final BigInteger newValue = new BigInteger("-128").add((value.subtract(new BigInteger("128")))); + valueInRange = String.valueOf(newValue); + } + throw new AssertionError("Unexpected Sort For Output Type"); } break; } case SmtSortUtils.REAL_SORT: { if (type.equals("float") || type.equals("double")) { - valueInRange = valueTerm.toStringDirect(); - System.out.println("TestCase: Unexpected Test Input Type: " + type); + valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); break; } } case SmtSortUtils.INT_SORT: { valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); final BigInteger value = new BigInteger(valueInRange); - if (type.equals("int") || type.equals("long")) { + if (type.equals("long")) { if (value.compareTo(new BigInteger("2147483647")) == 1) { need64Bit = true; } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { need64Bit = true; } - } else { + } else if (type.equals("ulong")) { if (value.compareTo(new BigInteger("4294967295")) == 1) { need64Bit = true; } @@ -421,7 +486,8 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St break; } case "ulonglong": { - // Cant be out of range? + final BigInteger newValue = value.mod(new BigInteger("18446744073709551616")); + valueInRange = String.valueOf(newValue); break; } case "char": { @@ -440,8 +506,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St break; } default: - // TODO short, double etc. float nicht - System.out.println("TestCase: Unexpected Type Warning"); + } break; } @@ -450,9 +515,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St throw new AssertionError("Unexpected Sort For Test Output"); } } - if (!valueInRange.equals(valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""))) { - System.out.println("TestCase: Warning Changed Export Value to fit in bounds: " + type); - } + values.add(index, valueInRange); } @@ -472,10 +535,8 @@ public void addValuesWithNegativeIndex() { } public String getNonDetTypeFromName(final String payload) { - System.out.println(payload); final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(payload); m.find(); - System.out.println(m.group(1)); return m.group(1); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 9996013af96..b467d49148f 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -471,7 +471,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi assert ((ApplicationTerm) indexedVar).getParameters().length == 0; if (indexedVar.toStringDirect().contains("nondet")) { if (evenRepresentative) { - if (index >= 0) { + if (index >= 0) { // TODO how can this be an issue? assert indexedRepresentatives.entrySet().size() == 2; // TODO Not sure if save, but by far the best solution From 64162a21f696bb8d4fbd801680dc7eac1c16206f Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 7 Oct 2023 22:32:08 +0200 Subject: [PATCH 024/278] added modulo for nondet_bool added dummy testcase --- .../singletracecheck/TestExporter.java | 30 +++++--------- .../TestCompMetaFilePrinter.java | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 7994fab1f97..ab7cdbcaf94 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -185,25 +185,6 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } String valueInRange = null; switch (valueTerm.getSort().getName()) { - case SmtSortUtils.FLOATINGPOINT_SORT: { - assert valueTerm instanceof ApplicationTerm; - final ApplicationTerm cva = (ApplicationTerm) valueTerm; - String sign = cva.getParameters()[0].toStringDirect(); - sign = sign.replaceAll("[^01]", ""); - - String exponent = cva.getParameters()[1].toStringDirect(); - exponent = exponent.replaceAll("[^01]", ""); - - String significant = cva.getParameters()[2].toStringDirect(); - significant = significant.replaceAll("[^01]", ""); - - final String floatAsBitString = sign + exponent + significant; - final int intBits = (int) Long.parseLong(floatAsBitString, 2); - final float myFloat = Float.intBitsToFloat(intBits); - - valueInRange = myFloat + ""; - break; - } case SmtSortUtils.BITVECTOR_SORT: { final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(valueTerm.toStringDirect()); m.find(); @@ -324,7 +305,6 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St values.add(null); } } - String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { @@ -424,7 +404,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St final BigInteger newValue = new BigInteger("-128").add((value.subtract(new BigInteger("128")))); valueInRange = String.valueOf(newValue); } - throw new AssertionError("Unexpected Sort For Output Type"); + } else if (type.equals("bool")) { + final BigInteger value = new BigInteger(valueInRange); + final BigInteger newValue = value.mod(new BigInteger("2")); + valueInRange = String.valueOf(newValue); } break; } @@ -450,6 +433,11 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } switch (type) { + case "bool": { + final BigInteger newValue = value.mod(new BigInteger("2")); + valueInRange = String.valueOf(newValue); + break; + } case "short": { // -32,768 to 32,767 if (value.compareTo(new BigInteger("32767")) == 1) { diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index 69ef83e59a8..41ad6289dc6 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -38,6 +38,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; @@ -94,6 +95,7 @@ public void printMetaFile() throws Exception { } else if (allInOneDirecotry) { Files.createDirectories(Paths.get("test-suite")); output = new FileOutputStream("test-suite/metadata.xml"); + createAndWriteDummyTestCase("test-suite/testcaseDummy.xml"); } else { final String outputDir = "testsuite_" + mTranslatedCFG.getFilename().substring( mTranslatedCFG.getFilename().lastIndexOf("\\") + 1, mTranslatedCFG.getFilename().length() - 2); @@ -103,11 +105,49 @@ public void printMetaFile() throws Exception { output = new FileOutputStream("tests/testsuite_" + outputDir + "/metadata.xml"); } writeXml(createXML(), output); + } catch (final IOException | TransformerException | ParserConfigurationException e) { throw e; } } + private void createAndWriteDummyTestCase(final String output) + throws ParserConfigurationException, TransformerConfigurationException, TransformerException { + // instance of a DocumentBuilderFactory + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + // use factory to get an instance of document builder + final DocumentBuilder db = dbf.newDocumentBuilder(); + // create instance of DOM + final Document doc = db.newDocument(); + + // create the root element + final Element rootEle = doc.createElement("testcase"); + + // create data elements and place them under root + + final Element element = doc.createElement("input"); + element.appendChild(doc.createTextNode("0")); + rootEle.appendChild(element); + + doc.appendChild(rootEle); + + final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + final Transformer transformer = transformerFactory.newTransformer(); + // pretty print XML + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + final DOMImplementation domImpl = doc.getImplementation(); + final DocumentType doctype = + domImpl.createDocumentType("testcase", "+//IDN sosy-lab.org//DTD test-format testcase 1.1//EN", + "https://sosy-lab.org/test-format/testcase-1.1.dtd"); + transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId()); + transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId()); + final DOMSource source = new DOMSource(doc); + final StreamResult result = new StreamResult(output); + + transformer.transform(source, result); + } + public Document createXML() throws ParserConfigurationException { final IPreferenceProvider ups = mServices.getPreferenceProvider(Activator.PLUGIN_ID); From 94ac8e0f1dbf390321a30dc48f3642ab34b0cfe0 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 8 Oct 2023 01:55:30 +0200 Subject: [PATCH 025/278] changed dummy input to newline --- .../ultimate/witnessprinter/TestCompMetaFilePrinter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java index 41ad6289dc6..c18684cc73d 100644 --- a/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java +++ b/trunk/source/WitnessPrinter/src/de/uni_freiburg/informatik/ultimate/witnessprinter/TestCompMetaFilePrinter.java @@ -126,9 +126,7 @@ private void createAndWriteDummyTestCase(final String output) // create data elements and place them under root - final Element element = doc.createElement("input"); - element.appendChild(doc.createTextNode("0")); - rootEle.appendChild(element); + rootEle.appendChild(doc.createTextNode("\n")); doc.appendChild(rootEle); From 6a5a36d1001b321a7bd30caaf6b2dceb97e1c4c6 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 20 Nov 2023 09:24:50 +0100 Subject: [PATCH 026/278] BugFix replace LinkedList with ArrayList --- .../singletracecheck/TestExporter.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index ab7cdbcaf94..d6c7e03f07a 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -6,6 +6,7 @@ import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedHashSet; @@ -85,7 +86,7 @@ public static final TestExporter getInstance() { } // TODO split exportation and creation of the testvectors. Means - final Document createXML(final LinkedList inputs) throws ParserConfigurationException { + final Document createXML(final ArrayList inputs) throws ParserConfigurationException { // instance of a DocumentBuilderFactory final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -153,10 +154,10 @@ public void findMakeFileAndDir() { class TestVector { - final LinkedList values = new LinkedList<>(); - final LinkedList values64Bit = new LinkedList<>(); - final LinkedList valuesWithNegativeIndices = new LinkedList<>(); - final LinkedList valuesWithPositiveIndices = new LinkedList<>(); + final ArrayList values = new ArrayList<>(); + final ArrayList values64Bit = new ArrayList<>(); + final ArrayList valuesWithNegativeIndices = new ArrayList<>(); + final ArrayList valuesWithPositiveIndices = new ArrayList<>(); int countNonDets = 0; boolean need64Bit = false; @@ -178,8 +179,8 @@ public void addValueAssignment(final Term value, final int position, final Strin private void addToLinkedList64Bit(final Integer index, final Term valueTerm, final String type) { need64Bit = false; - if (values64Bit.size() < index) { - for (int i = values64Bit.size(); i < index; i = i + 1) { + if (values64Bit.size() <= index) { + for (int i = values64Bit.size(); i <= index; i = i + 1) { values64Bit.add(null); } } @@ -295,13 +296,13 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } } - values64Bit.add(index, valueInRange); + values64Bit.set(index, valueInRange); } private void addToLinkedList(final Integer index, final Term valueTerm, final String type) { - if (values.size() < index) { - for (int i = values.size(); i < index; i = i + 1) { + if (values.size() <= index) { + for (int i = values.size(); i <= index; i = i + 1) { values.add(null); } } @@ -504,7 +505,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } } - values.add(index, valueInRange); + values.set(index, valueInRange); } From 52a78c429c71b3c24d54890d053389661cee95a4 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 21 Nov 2023 12:04:39 +0100 Subject: [PATCH 027/278] Added Hardcoded Support for Cover Error --- .../StandardFunctionHandler.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/standardfunctions/StandardFunctionHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/standardfunctions/StandardFunctionHandler.java index aea3c649078..3b8bdee82d1 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/standardfunctions/StandardFunctionHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/standardfunctions/StandardFunctionHandler.java @@ -119,6 +119,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Overapprox; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.IBoogieType; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; @@ -2407,8 +2408,14 @@ private Result handleMemCopyOrMove(final IDispatcher main, final IASTFunctionCal private Result handleErrorFunction(final IDispatcher main, final IASTFunctionCallExpression node, final ILocation loc, final String name) { final Expression falseLiteral = ExpressionFactory.createBooleanLiteral(loc, false); - final Statement st = - createReachabilityAssert(loc, name, mSettings.checkErrorFunction(), Spec.ERROR_FUNCTION, falseLiteral); + final boolean testCaseGeneration = true; + final Statement st; + if (!testCaseGeneration) { + st = createReachabilityAssert(loc, name, mSettings.checkErrorFunction(), Spec.ERROR_FUNCTION, falseLiteral); + } else { + st = createReachabilityAssert(loc, name, mSettings.checkErrorFunction(), Spec.TEST_GOAL_ANNOTATION, + falseLiteral); + } return new ExpressionResult(Collections.singletonList(st), null); } @@ -2453,6 +2460,12 @@ private Statement createReachabilityAssert(final ILocation loc, final String fun new Expression[] { new StringLiteral(loc, check.toString()), new StringLiteral(loc, functionName) }) }, expr); check.annotate(st); + final boolean testcasegen = true; + if (testcasegen) { + final TestGoalAnnotation tg = new TestGoalAnnotation(1); + tg.annotate(st); + } + if (checkMemoryleakInMain && mSettings.isSvcompMemtrackCompatibilityMode()) { new Overapprox("memtrack", loc).annotate(st); } From a0b6ed5473f15ae162d4756e6cdb6f8222c35604 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 21 Nov 2023 12:07:09 +0100 Subject: [PATCH 028/278] Variable Assignment Reuse via annotation --- .../base/CExpressionTranslator.java | 10 ++ .../implementation/base/CHandler.java | 16 +++ .../nestedword/operations/IsEmpty.java | 84 ++++++------- .../polynomials/PolynomialRelation.java | 82 +++++++------ .../singletracecheck/AnnotateAndAsserter.java | 112 +++++++++++++++++- .../singletracecheck/TraceCheck.java | 47 +++++++- .../traceabstraction/NwaCegarLoop.java | 37 ++++-- 7 files changed, 298 insertions(+), 90 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index 0bda02924f7..78c4c169a04 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -80,6 +80,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Overapprox; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.plugins.generator.cacsl2boogietranslator.preferences.CACSLPreferenceInitializer.PointerCheckMode; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; @@ -855,6 +856,14 @@ private ExpressionResult constructResultForConditionalOperator(final ILocation l chk.annotate(assertFalseElse); resultBuilder.addStatement(assertFalseElse); + // Annotations needed for variable assignment reuse + final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoThen.annotate(assertFalseThen); + final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoElse.annotate(assertFalseElse); + varAssignmentAnnoThen.setOppositeAnno(varAssignmentAnnoElse); + varAssignmentAnnoElse.setOppositeAnno(varAssignmentAnnoThen); + final Expression ite = ExpressionFactory.constructIfThenElseExpression(loc, opCondition.getLrValue().getValue(), opPositive.getLrValue().getValue(), opNegative.getLrValue().getValue()); @@ -896,6 +905,7 @@ private ExpressionResult constructResultForConditionalOperator(final ILocation l rtrStatement = addTestGoalsToConditionalOperator(loc, opCondition, ifStatements, elseStatements, secondArgIsVoid, thirdArgIsVoid, hook); + throw new IllegalArgumentException("Unexpected Test Goal location"); } else { rtrStatement = new IfStatement(loc, opCondition.getLrValue().getValue(), ifStatements.toArray(new Statement[ifStatements.size()]), diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index ee050a3a985..8cd7a9707b2 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -225,6 +225,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Check.Spec; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.Overapprox; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.model.acsl.ACSLNode; @@ -1769,6 +1770,14 @@ public Result visit(final IDispatcher main, final IASTIfStatement node) { elseArray.add(assertFalseElse); elseArray.addAll(elseStmt); + // Annotations needed for variable assignment reuse + final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoThen.annotate(assertFalseThen); + final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoElse.annotate(assertFalseElse); + varAssignmentAnnoThen.setOppositeAnno(varAssignmentAnnoElse); + varAssignmentAnnoElse.setOppositeAnno(varAssignmentAnnoThen); + ifStmt = new IfStatement(loc, cond.getValue(), thenArray.toArray(new Statement[thenArray.size()]), elseArray.toArray(new Statement[elseArray.size()])); @@ -3712,6 +3721,13 @@ private Result handleLoops(final IDispatcher main, final IASTStatement node, Res elseArray.add(assertFalseElse); elseArray.addAll(elseStmt); + final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoThen.annotate(assertFalseThen); + final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoElse.annotate(assertFalseElse); + varAssignmentAnnoThen.setOppositeAnno(varAssignmentAnnoElse); + varAssignmentAnnoElse.setOppositeAnno(varAssignmentAnnoThen); + ifStmt = new IfStatement(loc, cond, thenArray.toArray(new Statement[thenArray.size()]), elseArray.toArray(new Statement[elseArray.size()])); diff --git a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmpty.java b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmpty.java index 5ec70ab9896..a9c1b852ab9 100644 --- a/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmpty.java +++ b/trunk/source/Library-Automata/src/de/uni_freiburg/informatik/ultimate/automata/nestedword/operations/IsEmpty.java @@ -2,22 +2,22 @@ * Copyright (C) 2011-2015 Matthias Heizmann (heizmann@informatik.uni-freiburg.de) * Copyright (C) 2016 Christian Schilling (schillic@informatik.uni-freiburg.de) * Copyright (C) 2009-2016 University of Freiburg - * + * * This file is part of the ULTIMATE Automata Library. - * + * * The ULTIMATE Automata Library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * The ULTIMATE Automata Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with the ULTIMATE Automata Library. If not, see . - * + * * Additional permission under GNU GPL version 3 section 7: * If you modify the ULTIMATE Automata Library, or any covered work, by linking * or combining it with Eclipse RCP (or a modified version of Eclipse RCP), @@ -63,7 +63,7 @@ * length two or summary. *

* By default, the reachability graph is obtained by traversing the automaton in a BFS manner. - * + * * @author Matthias Heizmann (heizmann@informatik.uni-freiburg.de) * @author Christian Schilling (schillic@informatik.uni-freiburg.de) * @param @@ -74,7 +74,7 @@ public final class IsEmpty extends UnaryNwaOperation> { /** * Search strategy. - * + * * @author Christian Schilling (schillic@informatik.uni-freiburg.de) */ public enum SearchStrategy { @@ -202,20 +202,21 @@ public enum SearchStrategy { /** * Default constructor. Here we search a run from the initial states of the automaton to the final states of the * automaton. - * + * * @param services * Ultimate services * @param operand * input NWA */ - public IsEmpty(final AutomataLibraryServices services, final INwaOutgoingLetterAndTransitionProvider operand) + public IsEmpty(final AutomataLibraryServices services, + final INwaOutgoingLetterAndTransitionProvider operand) throws AutomataOperationCanceledException { this(services, operand, SearchStrategy.BFS); } /** * Default constructor with option to set search strategy. - * + * * @param services * Ultimate services * @param operand @@ -224,17 +225,18 @@ public IsEmpty(final AutomataLibraryServices services, final INwaOutgoingLetterA * search strategy * @see #IsEmpty(AutomataLibraryServices, INwaOutgoingLetterAndTransitionProvider) */ - public IsEmpty(final AutomataLibraryServices services, final INwaOutgoingLetterAndTransitionProvider operand, - final SearchStrategy strategy) throws AutomataOperationCanceledException { - this(services, operand, CoreUtil.constructHashSet(operand.getInitialStates()), Collections.emptySet(), null, true, - strategy); + public IsEmpty(final AutomataLibraryServices services, + final INwaOutgoingLetterAndTransitionProvider operand, final SearchStrategy strategy) + throws AutomataOperationCanceledException { + this(services, operand, CoreUtil.constructHashSet(operand.getInitialStates()), Collections.emptySet(), null, + true, strategy); } /** * Constructor that is not restricted to emptiness checks. The set of startStates defines where the run that we * search has to start. The set of forbiddenStates defines states that the run must not visit. The set of goalStates * defines where the run that we search has to end. - * + * * @param services * Ultimate services * @param operand @@ -254,10 +256,10 @@ public IsEmpty(final AutomataLibraryServices services, final INestedWordAutomato assert operand.getStates().containsAll(goalStates) : "unknown states"; } - private IsEmpty(final AutomataLibraryServices services, final INwaOutgoingLetterAndTransitionProvider operand, - final Set startStates, final Set forbiddenStates, final Set goalStates, - final boolean goalStateIsAcceptingState, final SearchStrategy strategy) - throws AutomataOperationCanceledException { + private IsEmpty(final AutomataLibraryServices services, + final INwaOutgoingLetterAndTransitionProvider operand, final Set startStates, + final Set forbiddenStates, final Set goalStates, final boolean goalStateIsAcceptingState, + final SearchStrategy strategy) throws AutomataOperationCanceledException { super(services); mOperand = operand; mDummyEmptyStackState = mOperand.getEmptyStackState(); @@ -315,11 +317,11 @@ private void enqueueAndMarkVisitedCall(final STATE state, final STATE callPred) markVisited(state, callPred); } - // The following implementation of dequeue is faster but leads to unsound - // results. See BugBfsEmptinessLowPriorityCallQueue.fat for details. - // Alternative workaround (where we may still use the low priority call queue): - // When final state is reached, process the whole call queue before - // computation of accepting run. + // The following implementation of dequeue is faster but leads to unsound + // results. See BugBfsEmptinessLowPriorityCallQueue.fat for details. + // Alternative workaround (where we may still use the low priority call queue): + // When final state is reached, process the whole call queue before + // computation of accepting run. /* /** * Dequeue a state pair. If available take a state pair that has been @@ -344,20 +346,20 @@ private IState[] dequeue() { */ private DoubleDecker dequeue() { switch (mStrategy) { - case BFS: - /* - * If available take a state pair that has been discovered by taking a call transition. If not take a - * state pair that has been discovered by taking an internal or a return transition or a summary. - */ - return dequeueGivenQueues(mQueueCall, mQueue); - case DFS: - /* - * If available take a state pair that has been discovered by taking an internal or a return transition - * or a summary. If not take a state pair that has been discovered by taking a call transition. - */ - return dequeueGivenQueues(mQueue, mQueueCall); - default: - throw new IllegalArgumentException("Unknown search strategy."); + case BFS: + /* + * If available take a state pair that has been discovered by taking a call transition. If not take a + * state pair that has been discovered by taking an internal or a return transition or a summary. + */ + return dequeueGivenQueues(mQueueCall, mQueue); + case DFS: + /* + * If available take a state pair that has been discovered by taking an internal or a return transition + * or a summary. If not take a state pair that has been discovered by taking a call transition. + */ + return dequeueGivenQueues(mQueue, mQueueCall); + default: + throw new IllegalArgumentException("Unknown search strategy."); } } @@ -459,7 +461,7 @@ private void getAcceptingRunHelperCall(final STATE state, final STATE stateK) { final LETTER symbol = transition.getLetter(); final STATE succ = transition.getSucc(); if (!mForbiddenStates.contains(succ)) { - //add these information even in already visited + // add these information even in already visited addRunInformationCall(succ, state, symbol, state, stateK); if (!wasVisited(succ, state)) { enqueueAndMarkVisitedCall(succ, state); @@ -513,7 +515,7 @@ private void processSummaries(final STATE state, final STATE stateK) { * Store for a state pair (succ,succK) in the reachability graph information about the predecessor (state,stateK) * under an internal transition and a run of length two from state to succ. *

- * + * * @param stateK * TODO Christian 2016-09-04: The parameter 'stateK' is not used. Is this intended? */ @@ -624,7 +626,7 @@ private void addSummary(final STATE stateBeforeCall, final STATE stateAfterRetur succ2ReturnSymbol = new HashMap<>(); mSummaryReturnSymbol.put(stateBeforeCall, succ2ReturnSymbol); } - //update only if there is not already an entry + // update only if there is not already an entry if (!succ2ReturnPred.containsKey(stateAfterReturn)) { succ2ReturnPred.put(stateAfterReturn, stateBeforeReturn); assert !succ2ReturnSymbol.containsKey(stateAfterReturn); diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/polynomials/PolynomialRelation.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/polynomials/PolynomialRelation.java index bb29f4687bd..b6ddd5781a1 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/polynomials/PolynomialRelation.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/polynomials/PolynomialRelation.java @@ -86,8 +86,7 @@ public class PolynomialRelation implements IBinaryRelation, ITermProvider { protected final RelationSymbol mRelationSymbol; protected final TrivialityStatus mTrivialityStatus; /** - * {@link PolynomialTerm}s or {@link AffineTerm}s ψ such that the relation ψ ▷ 0 - * is equivalent to the mOriginalTerm. + * {@link PolynomialTerm}s or {@link AffineTerm}s ψ such that the relation ψ ▷ 0 is equivalent to the mOriginalTerm. */ protected final AbstractGeneralizedAffineTerm mPolynomialTerm; @@ -95,9 +94,8 @@ public enum TransformInequality { NO_TRANFORMATION, STRICT2NONSTRICT, NONSTRICT2STRICT; /** - * For the TIR quantifier elimination technique (see {@link DualJunctionTir}), - * we prefer non-strict inequalities for the existential quantifier and we - * prefer strict inequalities for the universal quantifier. + * For the TIR quantifier elimination technique (see {@link DualJunctionTir}), we prefer non-strict inequalities + * for the existential quantifier and we prefer strict inequalities for the universal quantifier. */ public static TransformInequality determineTransformationForTir(final int quantifier) { TransformInequality result; @@ -167,12 +165,12 @@ private PolynomialRelation(final AbstractGeneralizedAffineTerm agat, final Re // Note that we always divide by a positive number and hence the relation symbol // will not change. final AbstractGeneralizedAffineTerm withoutConstant = agat.add(agat.getConstant().negate()); - final AbstractGeneralizedAffineTerm withoutConstantDivided = withoutConstant - .divInvertible(gcd); + final AbstractGeneralizedAffineTerm withoutConstantDivided = + withoutConstant.divInvertible(gcd); assert withoutConstantDivided != null : "Division problem"; final Rational newConstantRational = agat.getConstant().div(gcd); - final Rational newConstantRounded = getEquivalencePreservingRoundingMethod(mRelationSymbol) - .apply(newConstantRational); + final Rational newConstantRounded = + getEquivalencePreservingRoundingMethod(mRelationSymbol).apply(newConstantRational); mPolynomialTerm = withoutConstantDivided.add(newConstantRounded); mTrivialityStatus = computeTrivialityStatus(mPolynomialTerm, mRelationSymbol); break; @@ -195,11 +193,11 @@ private PolynomialRelation(final AbstractGeneralizedAffineTerm agat, final Re } /** - * If we have a relation of the form `r ▷ 0`, where r is a rational, in which - * direction can we round `r` (upwards, downwards) without changing the truth - * value of the relation. + * If we have a relation of the form `r ▷ 0`, where r is a rational, in which direction can we round `r` (upwards, + * downwards) without changing the truth value of the relation. * - * @param symb Convex inequality, i.e., one of the following \<=, \<, \>=, \>. + * @param symb + * Convex inequality, i.e., one of the following \<=, \<, \>=, \>. */ private static Function getEquivalencePreservingRoundingMethod(final RelationSymbol symb) { switch (symb) { @@ -265,19 +263,20 @@ public static PolynomialRelation of(final Script script, final RelationSymbol re (AbstractGeneralizedAffineTerm) lhsPoly, (AbstractGeneralizedAffineTerm) rhsPoly); } - public static PolynomialRelation of(final TransformInequality transformInequality, final RelationSymbol relationSymbol, - final AbstractGeneralizedAffineTerm polyLhs, final AbstractGeneralizedAffineTerm polyRhs) { - if (polyLhs.getSort() != polyRhs.getSort()) { - throw new AssertionError("Inconsistent sorts"); - } + public static PolynomialRelation of(final TransformInequality transformInequality, + final RelationSymbol relationSymbol, final AbstractGeneralizedAffineTerm polyLhs, + final AbstractGeneralizedAffineTerm polyRhs) { + // if (polyLhs.getSort() != polyRhs.getSort()) { + // throw new AssertionError("Inconsistent sorts"); + // } if (!SmtSortUtils.isNumericSort(polyLhs.getSort()) && !SmtSortUtils.isBitvecSort(polyLhs.getSort())) { throw new AssertionError("Unsupported sorts"); } if (relationSymbol.isConvexInequality() && SmtSortUtils.isBitvecSort(polyLhs.getSort())) { throw new AssertionError("Unsupported inequality/sort combination"); } - final AbstractGeneralizedAffineTerm difference = PolynomialTerm.sum(polyLhs, - PolynomialTerm.mul(polyRhs, Rational.MONE)); + final AbstractGeneralizedAffineTerm difference = + PolynomialTerm.sum(polyLhs, PolynomialTerm.mul(polyRhs, Rational.MONE)); final AbstractGeneralizedAffineTerm polyTerm; final RelationSymbol relationSymbolAfterTransformation; @@ -550,9 +549,8 @@ public Term toTerm(final Script script) { } /** - * Interpret the value as an integer given by the two's complement - * representation of the bitvector value. Return true iff this integer is - * negative. + * Interpret the value as an integer given by the two's complement representation of the bitvector value. Return + * true iff this integer is negative. */ private static boolean isNegativeAsSignedInt(final Rational value, final Sort sort) { if (!value.isIntegral()) { @@ -587,8 +585,8 @@ public SolvedBinaryRelation solveForSubject(final Script script, final Term subj final SolvedBinaryRelation result = new SolvedBinaryRelation(subject, solvedElpr.getRhs().toTerm(script), solvedElpr.getRelationSymbol()); final Term relationToTerm = result.toTerm(script); - assert script instanceof INonSolverScript || SmtUtils.checkEquivalence(toTerm(script), - relationToTerm, script) != LBool.SAT : "solveForSubject unsound"; + assert script instanceof INonSolverScript || SmtUtils.checkEquivalence(toTerm(script), relationToTerm, + script) != LBool.SAT : "solveForSubject unsound"; return result; } } @@ -624,9 +622,12 @@ public PolynomialRelation negate(final Script script) { } public PolynomialRelation mul(final Script script, final Rational r) { - final RelationSymbol resultRelationSymbol = ExplicitLhsPolynomialRelation.swapOfRelationSymbolRequired(r, - mPolynomialTerm.getSort()) ? mRelationSymbol.swapParameters() : mRelationSymbol; - return new PolynomialRelation((AbstractGeneralizedAffineTerm) PolynomialTermOperations.mul(mPolynomialTerm, r), + final RelationSymbol resultRelationSymbol = + ExplicitLhsPolynomialRelation.swapOfRelationSymbolRequired(r, mPolynomialTerm.getSort()) + ? mRelationSymbol.swapParameters() + : mRelationSymbol; + return new PolynomialRelation( + (AbstractGeneralizedAffineTerm) PolynomialTermOperations.mul(mPolynomialTerm, r), resultRelationSymbol); } @@ -641,20 +642,26 @@ public int hashCode() { @Override public boolean equals(final Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final PolynomialRelation other = (PolynomialRelation) obj; if (mPolynomialTerm == null) { - if (other.mPolynomialTerm != null) + if (other.mPolynomialTerm != null) { return false; - } else if (!mPolynomialTerm.equals(other.mPolynomialTerm)) + } + } else if (!mPolynomialTerm.equals(other.mPolynomialTerm)) { return false; - if (mRelationSymbol != other.mRelationSymbol) + } + if (mRelationSymbol != other.mRelationSymbol) { return false; + } return true; } @@ -674,10 +681,9 @@ private static AbstractGeneralizedAffineTerm transformToPolynomialTerm(final } /** - * If this {@link PolynomialRelation} has the form `x=l`, where x is a variable - * of the underlying (affine) polynomial relation and l is literal, the return - * this equality as a {@link SolvedBinaryRelation} where `x` is the left-hand - * side and `y` is the right-hand side. + * If this {@link PolynomialRelation} has the form `x=l`, where x is a variable of the underlying (affine) + * polynomial relation and l is literal, the return this equality as a {@link SolvedBinaryRelation} where `x` is the + * left-hand side and `y` is the right-hand side. */ public SolvedBinaryRelation isSimpleEquality(final Script script) { if (mRelationSymbol != RelationSymbol.EQ) { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index a515a298c99..8eecd43312e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -31,13 +31,17 @@ import java.util.TreeMap; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; +import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; +import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; /** * TODO: use quick check @@ -60,6 +64,8 @@ public class AnnotateAndAsserter { protected final TraceCheckStatisticsGenerator mTcbg; + public boolean mSucessfulReuse = false; + public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, final IUltimateServiceProvider services) { @@ -108,6 +114,9 @@ public void buildAnnotatedSsaAndAssertTerms() { // number that the pending context. The first pending context has // number -1, the second -2, ... int pendingContextCode = -1 - mSSA.getTrace().getPendingReturns().size(); + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; + ArrayList> varAssignmentPair = new ArrayList>(); + for (final Integer positionOfPendingReturn : mSSA.getTrace().getPendingReturns().keySet()) { assert mTrace.isPendingReturn(positionOfPendingReturn); { @@ -126,9 +135,109 @@ public void buildAnnotatedSsaAndAssertTerms() { mAnnotSSA.setOldVarAssignmentAtPos(positionOfPendingReturn, annotated); } pendingContextCode++; + if (reuseVarAssignmentsOfReachableErrorLocatiosn) { + System.out.println(mSSA.getTrace().getSymbol(positionOfPendingReturn)); + } } - mSatisfiable = mMgdScriptTc.getScript().checkSat(); + if (reuseVarAssignmentsOfReachableErrorLocatiosn) { + // final IPredicate errorStatePredecessor = + // (IPredicate) mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 2); + // final ISLPredicate test = (ISLPredicate) errorStatePredecessor; + + boolean reuse = false; + VarAssignmentReuseAnnotation vaAnnotation = null; + // TODO check mSSA.getTrace().length() - 1 > 0 + if (mSSA.getTrace().length() - 1 > 0) { + for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + vaAnnotation = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + varAssignmentPair = vaAnnotation.mVarAssignmentPair; + if (!vaAnnotation.mVarAssignmentPair.isEmpty()) { + reuse = true; + } else { + // TODO muss so sein wenn wir schlüsse auf else branch schließen wollen. + // Weil das ist die garantie, dass keine termination dazwischen stattfinden kann + // Wichtig dass wir nicht auf false setzten wenn wir hier das aktuelle testgoal lesen + reuse = false; + } + } + // if new input in trace. Set value for input and assert it. + // Create testcase with this value and the rest of the VA + } + } + } + if (reuse && vaAnnotation != null) { // ensure arraylist not empty + mMgdScriptTc.getScript().push(1); // Push und pop muss wo anders passieren, sonst ist das model weg + // in + // einem + final ArrayList andVa = new ArrayList(); + for (int i = 0; i < varAssignmentPair.size(); i++) { + varAssignmentPair.get(i); + if (mMgdScriptTc.getScript().getTheory() + .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, + varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1)) == null) { + System.out.println("TODO" + varAssignmentPair.get(i).getFirst().toStringDirect()); + System.out.println(mMgdScriptTc.getScript().getTheory() + .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, + varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1))); + reuse = false; + } else { + + final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), + mMgdScriptTc.getScript().getTheory() + .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, + varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1))); + andVa.add(SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, + varAssignmentPair.get(i).getSecond())); + } + } + + Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), andVa); + if (vaAnnotation.mIsNegated && !andVa.isEmpty()) { + varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); + // TODO evaluate if negated reuse is helpfull + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); + } else { + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); + } + + } + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + if (!reuse) { + System.out.println("NO REUSE"); + } else { + System.out.println("REUSE"); + } + if (mSatisfiable == LBool.UNSAT) { + if (reuse) { + // register "other branch" as reached by VA + // new VA will be added in trace check + System.out.println("REUSE UNSAT"); + vaAnnotation.mVAofOppositeBranch.removeCheck(); + vaAnnotation.negateVa(); + mMgdScriptTc.getScript().pop(1); + } + // Hier oder vor der IF + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + } else if (reuse) { + // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal + System.out.println("REUSE SUCCESSFULL"); + vaAnnotation.mVAofOppositeBranch.negateVa(); + mSucessfulReuse = true; + } + } else { + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + } + if (mSatisfiable == LBool.UNKNOWN) { + System.out.println("UNKNOWN"); + } // Report benchmarks mTcbg.reportNewCheckSat(); mTcbg.reportNewCodeBlocks(mTrace.length()); @@ -143,5 +252,4 @@ public LBool isInputSatisfiable() { public NestedFormulas getAnnotatedSsa() { return mAnnotSSA; } - } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index b467d49148f..18534252954 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -27,6 +27,7 @@ */ package de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -41,6 +42,8 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.IRunningTaskStackProvider; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.RunningTaskInfo; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; +import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; @@ -68,6 +71,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.logic.TermVariable; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; +import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; /** * Check if a trace fulfills a specification. Provides an execution (that violates the specification) if the check was @@ -304,7 +308,9 @@ protected FeasibilityCheckResult checkTrace() { mTraceCheckBenchmarkGenerator.stop(TraceCheckStatisticsDefinitions.SsaConstructionTime.toString()); mTraceCheckBenchmarkGenerator.start(TraceCheckStatisticsDefinitions.SatisfiabilityAnalysisTime.toString()); - if (mAssertCodeBlockOrder.getAssertCodeBlockOrderType() != AssertCodeBlockOrderType.NOT_INCREMENTALLY) { + if (mAssertCodeBlockOrder.getAssertCodeBlockOrderType() != AssertCodeBlockOrderType.NOT_INCREMENTALLY) + + { mAAA = new AnnotateAndAsserterWithStmtOrderPrioritization<>(mTcSmtManager, ssa, getAnnotateAndAsserterCodeBlocks(ssa), mTraceCheckBenchmarkGenerator, mAssertCodeBlockOrder, mServices); @@ -457,6 +463,9 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild private TestVector extractTestVector(final NestedSsaBuilder nsb, final Function funGetValue, final IcfgProgramExecutionBuilder rpeb) { final TestVector testV = new TestVector(); + final ArrayList varAssignment = new ArrayList(); + final ArrayList> varAssignmentPair = new ArrayList>(); + for (final var entry : nsb.getIndexedVarRepresentative().entrySet()) { final IProgramVar bv = entry.getKey(); final Map indexedRepresentatives = entry.getValue(); @@ -481,9 +490,24 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (stsq.getPayload().toString().contains("nondet")) { final String type = testV.getNonDetTypeFromName(stsq.getPayload().toString()); - testV.addValueAssignment(valueT, index, type); // Only if nondetINT!!} + testV.addValueAssignment(valueT, index, type); + final TermTransferrer test = new TermTransferrer( + mCfgManagedScript.getScript(), mTcSmtManager.getScript()); + + final Term varEqValue = SmtUtils.binaryEquality(mTcSmtManager.getScript(), + test.transform(indexedVar), test.transform(valueT)); + final Pair varValuePair = new Pair( + test.transform(indexedVar), test.transform(valueT)); + varAssignmentPair.add(varValuePair); + varAssignment.add(varEqValue); + // System.out.println(varEqValue); + // NEW annotate Variabel Assignment to test goal helper state for reuse + // later + } } + } else { + System.out.println("unexpected Index for nondet"); } evenRepresentative = !evenRepresentative; } else { @@ -496,6 +520,21 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } } + final boolean vaReuse = true; + if (vaReuse) { + + // TODO Add empty annotation to unreachable test goals? to prevent a reuse Not sure if needed + final IElement statementBranch = (IElement) nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation vaReuseAnno = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + vaReuseAnno.setVa(varAssignmentPair); + + } else { + assert false;// TODO + } + } return testV; } @@ -579,6 +618,10 @@ private void lockAndPrepareSolverForTraceCheck() { protected void cleanupAndUnlockSolver() { mTcSmtManager.echo(mTraceCheckLock, new QuotedObject("finished trace check")); + if (mAAA.mSucessfulReuse) { + mTcSmtManager.pop(mTraceCheckLock, 1); + } + mAAA.mSucessfulReuse = false; mTcSmtManager.pop(mTraceCheckLock, 1); mTcSmtManager.unlock(mTraceCheckLock); } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 060589d841b..1e41da25dd4 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -72,6 +72,7 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.TaskCanceledException.UserDefinedLimit; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; +import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; import de.uni_freiburg.informatik.ultimate.core.lib.results.DangerInvariantResult; import de.uni_freiburg.informatik.ultimate.core.model.models.annotation.IAnnotations; import de.uni_freiburg.informatik.ultimate.core.model.preferences.IPreferenceProvider; @@ -191,7 +192,7 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton longTraceRun(final INestedWordAutomaton abstraction, + private NestedRun runWithModifiedGoalSet(final INestedWordAutomaton abstraction, final Set possibleEndPoints) throws AutomataOperationCanceledException { return new IsEmpty<>(new AutomataLibraryServices(mServices), abstraction, abstraction.getInitialStates(), Collections.emptySet(), possibleEndPoints).getNestedRun(); @@ -283,7 +284,7 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro if (!mTestGeneration.equals(TestGenerationMode.NaiveMultiGoal)) { mTestGoalWorkingSet.clear(); // If Skips Unsat Long Traces activated } - mCounterexample = longTraceRun(mAbstraction, longTraceGoalStates); + mCounterexample = runWithModifiedGoalSet(mAbstraction, longTraceGoalStates); if (mCounterexample == null) { // mTestGoalTodoStack can be not Empty but mCounterexample can be null // If more testgoals than iterations if (mTestGeneration.equals(TestGenerationMode.NaiveMultiGoal)) { @@ -304,12 +305,34 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; } else { - mLogger.info("TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); - mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + if (mTestGeneration.equals(TestGenerationMode.Standard)) { + mLogger.info( + "TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); + mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); + + final Set newGoalSet = new HashSet<>(); + newGoalSet.addAll(mAbstraction.getFinalStates()); + for (final IPredicate testGoal : mAbstraction.getFinalStates()) { + final ISLPredicate testGoalISL = (ISLPredicate) testGoal; + if (testGoalISL.getProgramPoint().getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation pLocAnno = + (VarAssignmentReuseAnnotation) testGoalISL.getProgramPoint().getPayload() + .getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + + if (!pLocAnno.mIsActiveTestGoal) { + newGoalSet.remove(testGoal); + } + } - mCounterexample = - new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) - .getNestedRun(); + } + mCounterexample = runWithModifiedGoalSet(mAbstraction, newGoalSet); + } else { + + mCounterexample = + new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) + .getNestedRun(); + } } } finally { if (mWriteEvaluationToFile) { From 03b3eac1b50099a3bf35f0f982966726f12265d8 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 21 Nov 2023 12:19:03 +0100 Subject: [PATCH 029/278] VaAnnotationFile --- .../VarAssignmentReuseAnnotation.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java new file mode 100644 index 00000000000..5942cb02226 --- /dev/null +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -0,0 +1,62 @@ +package de.uni_freiburg.informatik.ultimate.core.lib.models.annotation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; +import de.uni_freiburg.informatik.ultimate.core.model.models.ModelUtils; +import de.uni_freiburg.informatik.ultimate.logic.Term; +import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; + +/* + * Annotation for states that represent a test goal + */ +public class VarAssignmentReuseAnnotation extends ModernAnnotations { + + private static final long serialVersionUID = 1L; + private static final String KEY = VarAssignmentReuseAnnotation.class.getName(); + private final Map mMap = new HashMap<>(); + public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated + public VarAssignmentReuseAnnotation mVAofOppositeBranch; + public boolean mIsNegated = false; + public boolean mIsActiveTestGoal = true; + + public VarAssignmentReuseAnnotation() { + } + + @Override + public Map getAnnotationsAsMap() { + return mMap; + } + + @Override + public String toString() { + return mMap.toString(); + } + + public static VarAssignmentReuseAnnotation getAnnotation(final IElement node) { + return ModelUtils.getAnnotation(node, KEY, a -> (VarAssignmentReuseAnnotation) a); + } + + public void annotate(final IElement node) { + node.getPayload().getAnnotations().put(KEY, this); + + } + + public void setOppositeAnno(final VarAssignmentReuseAnnotation vaOpppositeBranch) { + mVAofOppositeBranch = vaOpppositeBranch; + } + + public void setVa(final ArrayList> varAssignmentPair) { + mVarAssignmentPair = varAssignmentPair; + } + + public void negateVa() { + mIsNegated = true; + } + + public void removeCheck() { + mIsActiveTestGoal = false; + } +} From 2871f1b6fd7a36a1d03658b59218af391a5fb517 Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 22 Nov 2023 14:39:23 +0100 Subject: [PATCH 030/278] fixed reach error bug, fixed va reuse bug --- .../base/CExpressionTranslator.java | 23 +++++++++++-------- .../implementation/base/CHandler.java | 3 ++- .../singletracecheck/AnnotateAndAsserter.java | 2 ++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index 78c4c169a04..a93fc0e9969 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -901,11 +901,9 @@ private ExpressionResult constructResultForConditionalOperator(final ILocation l assignAuxVar(loc, opPositive, resultBuilder, auxvar, ifStatements, secondArgIsVoid); assignAuxVar(loc, opNegative, resultBuilder, auxvar, elseStatements, thirdArgIsVoid); final Statement rtrStatement; - if (mTestGenerationBranchCoverage) { - + if (mTestGenerationBranchCoverage) { // Setting is given by CHandler atm rtrStatement = addTestGoalsToConditionalOperator(loc, opCondition, ifStatements, elseStatements, secondArgIsVoid, thirdArgIsVoid, hook); - throw new IllegalArgumentException("Unexpected Test Goal location"); } else { rtrStatement = new IfStatement(loc, opCondition.getLrValue().getValue(), ifStatements.toArray(new Statement[ifStatements.size()]), @@ -1236,22 +1234,28 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); final TestGoalAnnotation tg1 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; - thenArray.add(assertFalseThen); - tg1.annotate(assertFalseThen); chk.annotate(assertFalseThen); + + // TODO problem when one arg is void. Until fix we do not set oppositeanno + final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoThen.annotate(assertFalseThen); + thenArray.add(assertFalseThen); } thenArray.addAll(ifStatements); if (!thirdArgIsVoid) { // TODO do we need a test goal either way? final Statement assertFalseElse = new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); - final TestGoalAnnotation tg2 = new TestGoalAnnotation(mTestGoalCount); mTestGoalCount += 1; tg2.annotate(assertFalseElse); chk.annotate(assertFalseElse); - elseArray.add(assertFalseElse); + // TODO problem when one arg is void. Until fix we do not set oppositeanno + final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoElse.annotate(assertFalseElse); + + elseArray.add(assertFalseElse); } elseArray.addAll(elseStatements); return new IfStatement(loc, opCondition.getLrValue().getValue(), @@ -1262,8 +1266,9 @@ public int getTestGoalCount() { return mTestGoalCount; } - public void setTestGoalCountAndFactory(final int testGoalCount, final LocationFactory locationFactory) { - mTestGenerationBranchCoverage = true; + public void setTestGoalCountAndFactory(final int testGoalCount, final LocationFactory locationFactory, + final boolean testGenerationBranchCoverage) { + mTestGenerationBranchCoverage = testGenerationBranchCoverage; mLocationFactory = locationFactory; mTestGoalCount = testGoalCount; } diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java index 8cd7a9707b2..2d57b96db37 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CHandler.java @@ -1145,7 +1145,8 @@ public Result visit(final IDispatcher main, final IASTConditionalExpression node ExpressionResult opNegative = (ExpressionResult) main.dispatch(node.getNegativeResultExpression()); opNegative = mExprResultTransformer.switchToRValue(opNegative, loc, node); if (mTestGenerationBranchCoverage) { - mCExpressionTranslator.setTestGoalCountAndFactory(mTestGoalCount, mLocationFactory); + mCExpressionTranslator.setTestGoalCountAndFactory(mTestGoalCount, mLocationFactory, + mTestGenerationBranchCoverage); final ExpressionResult result = mCExpressionTranslator.handleConditionalOperator(loc, opCondition, opPositive, opNegative, node); mTestGoalCount = mCExpressionTranslator.getTestGoalCount(); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 8eecd43312e..e670289e2b4 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -186,6 +186,8 @@ public void buildAnnotatedSsaAndAssertTerms() { .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1))); reuse = false; + mMgdScriptTc.getScript().pop(1); + break; } else { final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), From 6c8eeb890cc70f61207cc0633d007d63a54bb58a Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 22 Nov 2023 16:05:42 +0100 Subject: [PATCH 031/278] Bugfix reuse --- .../implementation/base/CExpressionTranslator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java index a93fc0e9969..55ca3397d7d 100644 --- a/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java +++ b/trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/CExpressionTranslator.java @@ -1229,6 +1229,10 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final final ArrayList thenArray = new ArrayList(); final ArrayList elseArray = new ArrayList(); final Check chk = new Check(Spec.TEST_GOAL_ANNOTATION); + final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); + final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoElse.setOppositeAnno(varAssignmentAnnoThen); + varAssignmentAnnoThen.setOppositeAnno(varAssignmentAnnoElse); if (!secondArgIsVoid) { // TODO do we need a test goal either way? final Statement assertFalseThen = new AssertStatement(loc, ExpressionFactory.createBooleanLiteral(loc, false)); @@ -1238,7 +1242,7 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final chk.annotate(assertFalseThen); // TODO problem when one arg is void. Until fix we do not set oppositeanno - final VarAssignmentReuseAnnotation varAssignmentAnnoThen = new VarAssignmentReuseAnnotation(); + varAssignmentAnnoThen.annotate(assertFalseThen); thenArray.add(assertFalseThen); } @@ -1252,7 +1256,6 @@ private IfStatement addTestGoalsToConditionalOperator(final ILocation loc, final chk.annotate(assertFalseElse); // TODO problem when one arg is void. Until fix we do not set oppositeanno - final VarAssignmentReuseAnnotation varAssignmentAnnoElse = new VarAssignmentReuseAnnotation(); varAssignmentAnnoElse.annotate(assertFalseElse); elseArray.add(assertFalseElse); From ea2a3342b0e9ae9c8710d9bc5a32ecc16b7297dd Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 23 Nov 2023 23:23:56 +0100 Subject: [PATCH 032/278] TestComp24 Final Version --- .../singletracecheck/AnnotateAndAsserter.java | 2 +- .../lib/tracecheckerutils/singletracecheck/TraceCheck.java | 4 +++- .../preferences/TraceAbstractionPreferenceInitializer.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index e670289e2b4..4df213f9737 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -114,7 +114,7 @@ public void buildAnnotatedSsaAndAssertTerms() { // number that the pending context. The first pending context has // number -1, the second -2, ... int pendingContextCode = -1 - mSSA.getTrace().getPendingReturns().size(); - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = false; ArrayList> varAssignmentPair = new ArrayList>(); for (final Integer positionOfPendingReturn : mSSA.getTrace().getPendingReturns().keySet()) { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 18534252954..5ec8b46c107 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -64,6 +64,8 @@ import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; +import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.FeasibilityCheckResult; +import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.TraceCheckLock; import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; import de.uni_freiburg.informatik.ultimate.logic.QuotedObject; import de.uni_freiburg.informatik.ultimate.logic.SMTLIBException; @@ -520,7 +522,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } } - final boolean vaReuse = true; + final boolean vaReuse = false; if (vaReuse) { // TODO Add empty annotation to unreachable test goals? to prevent a reuse Not sure if needed diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java index 740fdbdfa32..f25f0576725 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java @@ -497,7 +497,7 @@ public enum CoinflipMode { // Test Generation // ======================================================================== - private static final TestGenerationMode DEF_TEST_GEN_MODE = TestGenerationMode.None; + private static final TestGenerationMode DEF_TEST_GEN_MODE = TestGenerationMode.Standard; public static final String LABEL_TEST_GEN_MODE = "Test Generation Mode"; private static final String DESC_TEST_GEN_MODE = "None deactivates Test Generation, Standart standart Test Generation for Model Checkers, Search-MultiGoal uses the A* to find Multi Goal test cases and ignores ifeasible traces during the search, Naive-MultiGoal starts the CEGAR with the last added Test Goal and adds a new Test Goal every iteration"; From 9fedda7bd6ea66c30f80b51847dc995555aba8ec Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 28 Nov 2023 13:19:52 +0100 Subject: [PATCH 033/278] Activate VaReuse and reset default testgeneration to NONE --- .../singletracecheck/AnnotateAndAsserter.java | 2 +- .../lib/tracecheckerutils/singletracecheck/TraceCheck.java | 4 +--- .../preferences/TraceAbstractionPreferenceInitializer.java | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 4df213f9737..e670289e2b4 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -114,7 +114,7 @@ public void buildAnnotatedSsaAndAssertTerms() { // number that the pending context. The first pending context has // number -1, the second -2, ... int pendingContextCode = -1 - mSSA.getTrace().getPendingReturns().size(); - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = false; + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; ArrayList> varAssignmentPair = new ArrayList>(); for (final Integer positionOfPendingReturn : mSSA.getTrace().getPendingReturns().keySet()) { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 5ec8b46c107..18534252954 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -64,8 +64,6 @@ import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; -import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.FeasibilityCheckResult; -import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.TraceCheckLock; import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; import de.uni_freiburg.informatik.ultimate.logic.QuotedObject; import de.uni_freiburg.informatik.ultimate.logic.SMTLIBException; @@ -522,7 +520,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } } - final boolean vaReuse = false; + final boolean vaReuse = true; if (vaReuse) { // TODO Add empty annotation to unreachable test goals? to prevent a reuse Not sure if needed diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java index f25f0576725..740fdbdfa32 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/preferences/TraceAbstractionPreferenceInitializer.java @@ -497,7 +497,7 @@ public enum CoinflipMode { // Test Generation // ======================================================================== - private static final TestGenerationMode DEF_TEST_GEN_MODE = TestGenerationMode.Standard; + private static final TestGenerationMode DEF_TEST_GEN_MODE = TestGenerationMode.None; public static final String LABEL_TEST_GEN_MODE = "Test Generation Mode"; private static final String DESC_TEST_GEN_MODE = "None deactivates Test Generation, Standart standart Test Generation for Model Checkers, Search-MultiGoal uses the A* to find Multi Goal test cases and ignores ifeasible traces during the search, Naive-MultiGoal starts the CEGAR with the last added Test Goal and adds a new Test Goal every iteration"; From 4c8443af0fffc0e4de82500fc1dcd7a57b26fc93 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 11 Dec 2023 09:27:12 +0100 Subject: [PATCH 034/278] new reuse version --- .../singletracecheck/AnnotateAndAsserter.java | 230 ++++++++++++------ 1 file changed, 154 insertions(+), 76 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index e670289e2b4..a15f1328b20 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -26,18 +26,27 @@ */ package de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; +import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; +import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; +import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; +import de.uni_freiburg.informatik.ultimate.logic.FunctionSymbol; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; @@ -114,8 +123,6 @@ public void buildAnnotatedSsaAndAssertTerms() { // number that the pending context. The first pending context has // number -1, the second -2, ... int pendingContextCode = -1 - mSSA.getTrace().getPendingReturns().size(); - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; - ArrayList> varAssignmentPair = new ArrayList>(); for (final Integer positionOfPendingReturn : mSSA.getTrace().getPendingReturns().keySet()) { assert mTrace.isPendingReturn(positionOfPendingReturn); @@ -135,95 +142,92 @@ public void buildAnnotatedSsaAndAssertTerms() { mAnnotSSA.setOldVarAssignmentAtPos(positionOfPendingReturn, annotated); } pendingContextCode++; - if (reuseVarAssignmentsOfReachableErrorLocatiosn) { - System.out.println(mSSA.getTrace().getSymbol(positionOfPendingReturn)); - } } + VarAssignmentReuseAnnotation annotationOfCurrentTestGoal = null; + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; + final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); + if (lastStmt instanceof StatementSequence) { + final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; + if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { + annotationOfCurrentTestGoal = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + } + } + boolean nondetBetweenTestGoals = false; if (reuseVarAssignmentsOfReachableErrorLocatiosn) { - // final IPredicate errorStatePredecessor = - // (IPredicate) mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 2); - // final ISLPredicate test = (ISLPredicate) errorStatePredecessor; boolean reuse = false; - VarAssignmentReuseAnnotation vaAnnotation = null; - // TODO check mSSA.getTrace().length() - 1 > 0 - if (mSSA.getTrace().length() - 1 > 0) { - for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va - if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { - final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - vaAnnotation = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() - .get(VarAssignmentReuseAnnotation.class.getName()); - varAssignmentPair = vaAnnotation.mVarAssignmentPair; - if (!vaAnnotation.mVarAssignmentPair.isEmpty()) { - reuse = true; - } else { - // TODO muss so sein wenn wir schlüsse auf else branch schließen wollen. - // Weil das ist die garantie, dass keine termination dazwischen stattfinden kann - // Wichtig dass wir nicht auf false setzten wenn wir hier das aktuelle testgoal lesen - reuse = false; + final Pair> todoname = checkTraceForVAandNONDETS(); + if (todoname.getFirst() != null) { + final ArrayList> varAssignmentPairs = todoname.getFirst().mVarAssignmentPair; + if (varAssignmentPairs.isEmpty() || todoname.getSecond().isEmpty()) { + // No Reuse + System.out.println("NO REUSE"); + } else { + System.out.println(varAssignmentPairs); + reuse = true; + System.out.println("REUSE"); + final ArrayList termsFromVAs = new ArrayList(); + for (final String nondet : todoname.getSecond()) { + boolean nondetNotInVA = true; + for (int i = 0; i < varAssignmentPairs.size(); i++) { + // remove after debugging + if (mMgdScriptTc.getScript().getTheory() + .getFunction(varAssignmentPairs.get(i).getFirst().toStringDirect().substring(1, + varAssignmentPairs.get(i).getFirst().toStringDirect().length() + - 1)) == null) { + + throw new AssertionError("ALARMAPAMAA"); + + } + + // For this nondet in Trace we do not have an entry in the VA + if (varAssignmentPairs.get(i).getFirst().toStringDirect().contains(nondet)) { + nondetNotInVA = false; + final Term reuseVaTerm = createTermFromVA(varAssignmentPairs.get(i).getFirst(), + varAssignmentPairs.get(i).getSecond()); + termsFromVAs.add(reuseVaTerm); } } - // if new input in trace. Set value for input and assert it. - // Create testcase with this value and the rest of the VA + if (nondetNotInVA) { + System.out.println("ALARM: " + nondet + "not in VA"); + + nondetBetweenTestGoals = true; + + // TODO create a term somehow lmao + // termsFromVAs.add(); + // final Term reuseVaTerm = createTermForNondetNotInVa(); + // termsFromVAs.add(reuseVaTerm); + } } - } - } - if (reuse && vaAnnotation != null) { // ensure arraylist not empty - mMgdScriptTc.getScript().push(1); // Push und pop muss wo anders passieren, sonst ist das model weg - // in - // einem - final ArrayList andVa = new ArrayList(); - for (int i = 0; i < varAssignmentPair.size(); i++) { - varAssignmentPair.get(i); - if (mMgdScriptTc.getScript().getTheory() - .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, - varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1)) == null) { - System.out.println("TODO" + varAssignmentPair.get(i).getFirst().toStringDirect()); - System.out.println(mMgdScriptTc.getScript().getTheory() - .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, - varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1))); - reuse = false; - mMgdScriptTc.getScript().pop(1); - break; + if (!termsFromVAs.isEmpty()) { // TODO Needed? + Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), termsFromVAs); + if (todoname.getFirst().mIsNegated && !termsFromVAs.isEmpty()) { + varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); + } + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); } else { - - final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), - mMgdScriptTc.getScript().getTheory() - .getFunction(varAssignmentPair.get(i).getFirst().toStringDirect().substring(1, - varAssignmentPair.get(i).getFirst().toStringDirect().length() - 1))); - andVa.add(SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, - varAssignmentPair.get(i).getSecond())); + reuse = false; } } - - Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), andVa); - if (vaAnnotation.mIsNegated && !andVa.isEmpty()) { - varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); - // TODO evaluate if negated reuse is helpfull - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); - } else { - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); - } - } mSatisfiable = mMgdScriptTc.getScript().checkSat(); - if (!reuse) { - System.out.println("NO REUSE"); - } else { - System.out.println("REUSE"); - } + if (mSatisfiable == LBool.UNSAT) { if (reuse) { - // register "other branch" as reached by VA - // new VA will be added in trace check + // TODO register "other branch" as reached by VA !!!!!!ACHRUNG CURREN TBRANCH NCIHT WIE HIER + // new VA will be added in trace check //TODO are you sure? System.out.println("REUSE UNSAT"); - vaAnnotation.mVAofOppositeBranch.removeCheck(); - vaAnnotation.negateVa(); + if (!nondetBetweenTestGoals) { + annotationOfCurrentTestGoal.mVAofOppositeBranch.removeCheck(); + } + annotationOfCurrentTestGoal.mVAofOppositeBranch + .setVa(annotationOfCurrentTestGoal.mVarAssignmentPair); + // TODO VA annotate to opposite branch. + // if no nondet in between, copy from old else add new mMgdScriptTc.getScript().pop(1); } // Hier oder vor der IF @@ -231,7 +235,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal System.out.println("REUSE SUCCESSFULL"); - vaAnnotation.mVAofOppositeBranch.negateVa(); + todoname.getFirst().negateVa(); mSucessfulReuse = true; } } else { @@ -247,6 +251,42 @@ public void buildAnnotatedSsaAndAssertTerms() { mLogger.info("Conjunction of SSA is " + mSatisfiable); } + private Term createTermFromVA(final Term variable, final Term value) { + final FunctionSymbol varInCurrentScript = mMgdScriptTc.getScript().getTheory() + .getFunction(variable.toStringDirect().substring(1, variable.toStringDirect().length() - 1)); + if (varInCurrentScript == null) { + System.out.println(variable); + throw new AssertionError("unknown var " + variable); + } + + final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), varInCurrentScript); + + Term nondetValue = value; + switch (nondetVar.getSort().getName()) { + case SmtSortUtils.FLOATINGPOINT_SORT: { + + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), null, null, + valueAsAppterm.getParameters()); + break; + } + case SmtSortUtils.BITVECTOR_SORT: { + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + + final BigInteger constValue = new BigInteger(valueAsAppterm.getFunction().getName().substring(2)); + nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), + BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); + + break; + } + default: { + break; + } + } + return SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, nondetValue); + } + public LBool isInputSatisfiable() { return mSatisfiable; } @@ -254,4 +294,42 @@ public LBool isInputSatisfiable() { public NestedFormulas getAnnotatedSsa() { return mAnnotSSA; } + + private Pair> checkTraceForVAandNONDETS() { + VarAssignmentReuseAnnotation vaAnnotation = null; + final LinkedHashSet nondetsInTrace = new LinkedHashSet(); + if (mSSA.getTrace().length() - 1 > 0) { + for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + // If Nondet in Trace add to Set + if (statementBranch.toString().startsWith("havoc") + && statementBranch.toString().contains("nondet")) { + // TODO only one entry per nondet!!!!! bestcase already remove unnecessary chars + + for (final IProgramVar var : statementBranch.getTransformula().getAssignedVars()) { + statementBranch.getTransformula().getAssignedVars().toString(); + final Pattern pattern = Pattern.compile("nondet\\d+", Pattern.CASE_INSENSITIVE); + final Matcher matcher = pattern.matcher(var.toString()); + + if (matcher.find()) { + final String match = matcher.group(); + nondetsInTrace.add(var.toString()); + } + + } + + } + // If VA in Trace returns last found VA + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + vaAnnotation = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + } + } + } + } + return new Pair<>(vaAnnotation, nondetsInTrace); + } + } From 006e3db6519fab41f951d9b2ac3106c8cf3bdff1 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 11 Dec 2023 09:28:30 +0100 Subject: [PATCH 035/278] New import to annotate and assert --- trunk/source/Library-TraceCheckerUtils/META-INF/MANIFEST.MF | 1 + 1 file changed, 1 insertion(+) diff --git a/trunk/source/Library-TraceCheckerUtils/META-INF/MANIFEST.MF b/trunk/source/Library-TraceCheckerUtils/META-INF/MANIFEST.MF index db3f9a36e97..711bca0c3df 100644 --- a/trunk/source/Library-TraceCheckerUtils/META-INF/MANIFEST.MF +++ b/trunk/source/Library-TraceCheckerUtils/META-INF/MANIFEST.MF @@ -24,3 +24,4 @@ Require-Bundle: de.uni_freiburg.informatik.ultimate.lib.core, de.uni_freiburg.informatik.ultimate.smtsolver.external, de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder Automatic-Module-Name: de.uni.freiburg.informatik.ultimate.lib.tracecheckerutils +Import-Package: de.uni_freiburg.informatik.ultimate.boogie.ast From 0725c8f6ab1b5eb8e7181cb0e0b36fde0f5843cc Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 26 Dec 2023 14:35:54 +0100 Subject: [PATCH 036/278] choose arbitrary value for input beween test goals --- .../singletracecheck/AnnotateAndAsserter.java | 238 +++++++++++------- .../singletracecheck/TestExporter.java | 12 +- .../singletracecheck/TraceCheck.java | 47 ++-- .../VarAssignmentReuseAnnotation.java | 12 +- 4 files changed, 192 insertions(+), 117 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index a15f1328b20..086835e62e2 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -29,6 +29,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.TreeMap; import java.util.regex.Matcher; @@ -39,7 +40,6 @@ import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; -import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; @@ -74,6 +74,13 @@ public class AnnotateAndAsserter { protected final TraceCheckStatisticsGenerator mTcbg; public boolean mSucessfulReuse = false; + // private VarAssignmentReuseAnnotation mVAforReuse = null; //For BitVec, since we have sort problem for a guess + private VarAssignmentReuseAnnotation mVAforReuse; // Try to always use an VA, + // if problem SORT maybe + // just do it for int + final LinkedHashSet nondetsInTrace = new LinkedHashSet(); + final HashMap nondetNameToType = new HashMap<>(); + Integer mTestCaseUniqueIdentifier = 0; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, @@ -146,6 +153,7 @@ public void buildAnnotatedSsaAndAssertTerms() { VarAssignmentReuseAnnotation annotationOfCurrentTestGoal = null; final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); + if (lastStmt instanceof StatementSequence) { final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { @@ -153,57 +161,30 @@ public void buildAnnotatedSsaAndAssertTerms() { annotationOfCurrentTestGoal = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); } + System.out.println("HIER: " + lastStmtSeq.getSerialNumber()); } - boolean nondetBetweenTestGoals = false; - if (reuseVarAssignmentsOfReachableErrorLocatiosn) { - boolean reuse = false; - final Pair> todoname = checkTraceForVAandNONDETS(); - if (todoname.getFirst() != null) { - final ArrayList> varAssignmentPairs = todoname.getFirst().mVarAssignmentPair; - if (varAssignmentPairs.isEmpty() || todoname.getSecond().isEmpty()) { - // No Reuse + if (reuseVarAssignmentsOfReachableErrorLocatiosn) { + boolean reuse = true; + mVAforReuse = annotationOfCurrentTestGoal; + checkTraceForVAandNONDETS(); + if (mVAforReuse != null) { + final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; + // TODO trying to reuse always if int + if (nondetsInTrace.isEmpty() || annotationOfCurrentTestGoal.mUnsatWithVAs.contains(mVAforReuse)) { + // // No Reuse System.out.println("NO REUSE"); + reuse = false; } else { System.out.println(varAssignmentPairs); reuse = true; - System.out.println("REUSE"); - final ArrayList termsFromVAs = new ArrayList(); - for (final String nondet : todoname.getSecond()) { - boolean nondetNotInVA = true; - for (int i = 0; i < varAssignmentPairs.size(); i++) { - // remove after debugging - if (mMgdScriptTc.getScript().getTheory() - .getFunction(varAssignmentPairs.get(i).getFirst().toStringDirect().substring(1, - varAssignmentPairs.get(i).getFirst().toStringDirect().length() - - 1)) == null) { - - throw new AssertionError("ALARMAPAMAA"); - - } - - // For this nondet in Trace we do not have an entry in the VA - if (varAssignmentPairs.get(i).getFirst().toStringDirect().contains(nondet)) { - nondetNotInVA = false; - final Term reuseVaTerm = createTermFromVA(varAssignmentPairs.get(i).getFirst(), - varAssignmentPairs.get(i).getSecond()); - termsFromVAs.add(reuseVaTerm); - } - } - if (nondetNotInVA) { - System.out.println("ALARM: " + nondet + "not in VA"); - - nondetBetweenTestGoals = true; - - // TODO create a term somehow lmao - // termsFromVAs.add(); - // final Term reuseVaTerm = createTermForNondetNotInVa(); - // termsFromVAs.add(reuseVaTerm); - } + final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO + if (mVAforReuse.equals(annotationOfCurrentTestGoal)) { + System.out.println("CURRENT VA is reused"); } - if (!termsFromVAs.isEmpty()) { // TODO Needed? - Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), termsFromVAs); - if (todoname.getFirst().mIsNegated && !termsFromVAs.isEmpty()) { + if (!vaPairsAsTerms.isEmpty() && reuse) { // TODO Needed? + Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + if (mVAforReuse.mIsNegated && !vaPairsAsTerms.isEmpty()) { varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); } mMgdScriptTc.getScript().push(1); @@ -215,35 +196,51 @@ public void buildAnnotatedSsaAndAssertTerms() { } } mSatisfiable = mMgdScriptTc.getScript().checkSat(); - if (mSatisfiable == LBool.UNSAT) { if (reuse) { - // TODO register "other branch" as reached by VA !!!!!!ACHRUNG CURREN TBRANCH NCIHT WIE HIER - // new VA will be added in trace check //TODO are you sure? + annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); + // annotationOfCurrentTestGoal.mVAofOppositeBranch.setVa(mVAforReuse.mVarAssignmentPair); System.out.println("REUSE UNSAT"); - if (!nondetBetweenTestGoals) { - annotationOfCurrentTestGoal.mVAofOppositeBranch.removeCheck(); - } - annotationOfCurrentTestGoal.mVAofOppositeBranch - .setVa(annotationOfCurrentTestGoal.mVarAssignmentPair); - // TODO VA annotate to opposite branch. - // if no nondet in between, copy from old else add new + mMgdScriptTc.getScript().pop(1); + annotationOfCurrentTestGoal.mVAofOppositeBranch.removeCheck(); } // Hier oder vor der IF mSatisfiable = mMgdScriptTc.getScript().checkSat(); + if (mSatisfiable == LBool.SAT) { + // TODO + // register new model for 2nd check + // annotationOfCurrentTestGoal.setVa(null); + } } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal System.out.println("REUSE SUCCESSFULL"); - todoname.getFirst().negateVa(); + if (!mVAforReuse.equals(annotationOfCurrentTestGoal)) { + annotationOfCurrentTestGoal.setVa(mVAforReuse.mVarAssignmentPair); + if (mVAforReuse.mIsNegated) { + // TODO Instead, VA with actual Model vor 2nd Check + // mMgdScriptTc.getScript().getModel(); + // annotationOfCurrentTestGoal.negateVa(); //TODO ??? ACHTUNG DARF NICHT SEIN + + } + if (annotationOfCurrentTestGoal.checkCount == 2) { + mVAforReuse.negateVa(); + } + + } mSucessfulReuse = true; } } else { mSatisfiable = mMgdScriptTc.getScript().checkSat(); + // TODO no reuse, SAT, second checksat we can reuse + // TODO guessed reuse UNSAT, checksat sat, we guess the same for second checksat instead of reusing } if (mSatisfiable == LBool.UNKNOWN) { System.out.println("UNKNOWN"); } + + annotationOfCurrentTestGoal.checkCount += 1; + // Report benchmarks mTcbg.reportNewCheckSat(); mTcbg.reportNewCodeBlocks(mTrace.length()); @@ -251,36 +248,45 @@ public void buildAnnotatedSsaAndAssertTerms() { mLogger.info("Conjunction of SSA is " + mSatisfiable); } - private Term createTermFromVA(final Term variable, final Term value) { + private Term createTermFromVA(final String variableAsString, final Term value) { final FunctionSymbol varInCurrentScript = mMgdScriptTc.getScript().getTheory() - .getFunction(variable.toStringDirect().substring(1, variable.toStringDirect().length() - 1)); + .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); + System.out.println(variableAsString); if (varInCurrentScript == null) { - System.out.println(variable); - throw new AssertionError("unknown var " + variable); + throw new AssertionError("unknown var " + variableAsString); } final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), varInCurrentScript); - Term nondetValue = value; + final Term nondetValue; + switch (nondetVar.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - - final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - - nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), null, null, - valueAsAppterm.getParameters()); + if (value != null) { + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), null, + null, valueAsAppterm.getParameters()); + } else { + throw new AssertionError("TODO FLOATINGPOINT_SORT Default vlaue "); + } break; } case SmtSortUtils.BITVECTOR_SORT: { - final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - - final BigInteger constValue = new BigInteger(valueAsAppterm.getFunction().getName().substring(2)); - nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), - BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); - + if (value != null) { + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + final BigInteger constValue = new BigInteger(valueAsAppterm.getFunction().getName().substring(2)); + nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), + BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); + } else { + final BigInteger constValue = BigInteger.ZERO; + nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), + BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); + } break; } default: { + nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), + SmtSortUtils.getIntSort(mMgdScriptTc), BigInteger.ZERO); break; } } @@ -295,41 +301,93 @@ public NestedFormulas getAnnotatedSsa() { return mAnnotSSA; } - private Pair> checkTraceForVAandNONDETS() { - VarAssignmentReuseAnnotation vaAnnotation = null; - final LinkedHashSet nondetsInTrace = new LinkedHashSet(); + /* + * Iterates over trace and returns last VA and all Nondets in trace + */ + private void checkTraceForVAandNONDETS() { + mTestCaseUniqueIdentifier = mSSA.getTrace().hashCode(); if (mSSA.getTrace().length() - 1 > 0) { for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - // If Nondet in Trace add to Set + if (statementBranch.toString().startsWith("havoc") && statementBranch.toString().contains("nondet")) { - // TODO only one entry per nondet!!!!! bestcase already remove unnecessary chars - - for (final IProgramVar var : statementBranch.getTransformula().getAssignedVars()) { - statementBranch.getTransformula().getAssignedVars().toString(); - final Pattern pattern = Pattern.compile("nondet\\d+", Pattern.CASE_INSENSITIVE); - final Matcher matcher = pattern.matcher(var.toString()); - - if (matcher.find()) { - final String match = matcher.group(); - nondetsInTrace.add(var.toString()); - } - + final String traceTermAsString = mSSA.getFormulaFromNonCallPos(i).toStringDirect(); + final Pattern pattern = Pattern.compile("\\|.*nondet\\d[^\\|]*\\|", Pattern.CASE_INSENSITIVE); + final Matcher matcher = pattern.matcher(traceTermAsString); + if (matcher.find()) { + final String match = matcher.group(); + nondetsInTrace.add(match.toString()); + nondetNameToType.put(match.toString(), + TestVector.getNonDetTypeFromName(statementBranch.getPayload().toString())); } } // If VA in Trace returns last found VA if (statementBranch.getPayload().getAnnotations() .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - vaAnnotation = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() + mVAforReuse = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); } } } } - return new Pair<>(vaAnnotation, nondetsInTrace); + + } + + /* + * Checks wheter a nondet from the trace is in the VA or not. + * IF it is included it is in the first array list and otherwise in the second of PAIR + */ + private ArrayList checkIfNondetsOfTraceAreInVA() { + final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; + final ArrayList nondetInVA = new ArrayList(); + boolean inputBetweenTestGoals = false; + int nondetPositionCount = 0; + final TestVector testV = new TestVector(); + for (final String nondet : nondetsInTrace) { + boolean nondetNotInVA = true; + Term value = null; + for (int i = 0; i < varAssignmentPairs.size(); i++) { // TODO optimize in one loop over all nondets in trace + // This "nondet" in Trace is in the VA + if (varAssignmentPairs.get(i).getFirst().toStringDirect().contains(nondet)) { + nondetNotInVA = false; + value = varAssignmentPairs.get(i).getSecond(); + final Term reuseVaTerm = + createTermFromVA(varAssignmentPairs.get(i).getFirst().toStringDirect(), value); + nondetInVA.add(reuseVaTerm); + break; + } + } + + if (nondetNotInVA) { + // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! + System.out.println("ALARM: " + nondet + " not in VA"); + inputBetweenTestGoals = true; + value = null; // null will be used as value zero + final Term reuseVaTerm = createTermFromVA(nondet, value); + nondetInVA.add(reuseVaTerm); + } + + testV.addValueAssignment(value, nondetPositionCount, nondetNameToType.get(nondet)); + // increase at the end of loop + nondetPositionCount += 1; + } + if (inputBetweenTestGoals && mVAforReuse.checkCount == 2) { + exportTest(testV); + } + return nondetInVA; } + private void exportTest(final TestVector testV) { + try { + if (!testV.isEmpty()) { + TestExporter.getInstance().exportTests(testV, mTestCaseUniqueIdentifier, true); + } + } catch (final Exception e) { + // TODO TestGeneration Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index d6c7e03f07a..35e396fe145 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -167,6 +167,7 @@ public void addValueAssignment(final Term value, final int position, final Strin // addNegativPositionToLinkedList(valuesWithNegativeIndices, position, value); } else { countNonDets += 1; + addToLinkedList(position, value, type); if (need64Bit) { addToLinkedList64Bit(position, value, type); @@ -184,6 +185,10 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin values64Bit.add(null); } } + if (valueTerm == null) { + values64Bit.set(index, "0"); + return; + } String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.BITVECTOR_SORT: { @@ -306,6 +311,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St values.add(null); } } + if (valueTerm == null) { + values.set(index, "0"); + return; + } String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { @@ -523,10 +532,9 @@ public void addValuesWithNegativeIndex() { values.addAll(valuesWithPositiveIndices); } - public String getNonDetTypeFromName(final String payload) { + static public String getNonDetTypeFromName(final String payload) { final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(payload); m.find(); - return m.group(1); } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 18534252954..40a8483f12b 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -472,7 +472,6 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (SmtUtils.isSortForWhichWeCanGetValues(bv.getTermVariable().getSort())) { boolean evenRepresentative = true; for (final var representative : indexedRepresentatives.entrySet()) { - final Integer index = representative.getKey(); final Term indexedVar = representative.getValue(); final Term valueT = funGetValue.apply(indexedVar); @@ -482,28 +481,28 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (evenRepresentative) { if (index >= 0) { // TODO how can this be an issue? - assert indexedRepresentatives.entrySet().size() == 2; - // TODO Not sure if save, but by far the best solution - if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { - final StatementSequence stsq = - (StatementSequence) rpeb.mTrace.asList().get(index); - if (stsq.getPayload().toString().contains("nondet")) { - final String type = - testV.getNonDetTypeFromName(stsq.getPayload().toString()); - testV.addValueAssignment(valueT, index, type); - final TermTransferrer test = new TermTransferrer( - mCfgManagedScript.getScript(), mTcSmtManager.getScript()); - - final Term varEqValue = SmtUtils.binaryEquality(mTcSmtManager.getScript(), - test.transform(indexedVar), test.transform(valueT)); - final Pair varValuePair = new Pair( - test.transform(indexedVar), test.transform(valueT)); - varAssignmentPair.add(varValuePair); - varAssignment.add(varEqValue); - // System.out.println(varEqValue); - // NEW annotate Variabel Assignment to test goal helper state for reuse - // later - + if (indexedRepresentatives.entrySet().size() == 2) { // not 100sure if 2 is the + // right index + + // TODO Not sure if save, but by far the best solution + if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { + final StatementSequence stsq = + (StatementSequence) rpeb.mTrace.asList().get(index); + if (stsq.getPayload().toString().contains("nondet")) { + final String type = + TestVector.getNonDetTypeFromName(stsq.getPayload().toString()); + testV.addValueAssignment(valueT, index, type); + final TermTransferrer test = new TermTransferrer( + mCfgManagedScript.getScript(), mTcSmtManager.getScript()); + + final Term varEqValue = + SmtUtils.binaryEquality(mTcSmtManager.getScript(), + test.transform(indexedVar), test.transform(valueT)); + final Pair varValuePair = new Pair( + test.transform(indexedVar), test.transform(valueT)); + varAssignmentPair.add(varValuePair); + varAssignment.add(varEqValue); + } } } } else { @@ -530,7 +529,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi final VarAssignmentReuseAnnotation vaReuseAnno = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); vaReuseAnno.setVa(varAssignmentPair); - + vaReuseAnno.mIsNegated = false; } else { assert false;// TODO } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index 5942cb02226..1a5aed603d9 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; @@ -17,10 +18,15 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { private static final long serialVersionUID = 1L; private static final String KEY = VarAssignmentReuseAnnotation.class.getName(); private final Map mMap = new HashMap<>(); - public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated + public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated, + // order corresponds to + // test-case public VarAssignmentReuseAnnotation mVAofOppositeBranch; public boolean mIsNegated = false; public boolean mIsActiveTestGoal = true; + public boolean mUseCurrentTestGoal = false; // use this test goal instead of a previous + public HashSet mUnsatWithVAs = new HashSet<>(); + public Integer checkCount = 1; // is either 1 or 2 public VarAssignmentReuseAnnotation() { } @@ -48,10 +54,14 @@ public void setOppositeAnno(final VarAssignmentReuseAnnotation vaOpppositeBranch mVAofOppositeBranch = vaOpppositeBranch; } + /* + * Warning replaces the current VA + */ public void setVa(final ArrayList> varAssignmentPair) { mVarAssignmentPair = varAssignmentPair; } + // Do not negate here, only flag as negated. Negate the formula when asserting the term public void negateVa() { mIsNegated = true; } From 579a82d706dafbffa14a9fe3cb19520f419b2016 Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 10 Jan 2024 16:32:11 +0100 Subject: [PATCH 037/278] Fixed "Other Branch" optimisation. Ensuring that it is only used if the Va for reuse is the last in the trace and contains all inputs --- .../lib/smtlibutils/SmtSortUtils.java | 4 + .../singletracecheck/AnnotateAndAsserter.java | 269 ++++++++++++------ .../singletracecheck/TraceCheck.java | 62 ++-- .../VarAssignmentReuseAnnotation.java | 33 ++- 4 files changed, 251 insertions(+), 117 deletions(-) diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtSortUtils.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtSortUtils.java index f4094777ba0..ddfcffc40b9 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtSortUtils.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtSortUtils.java @@ -112,6 +112,10 @@ public static Sort getRealSort(final Script script) { return script.sort(REAL_SORT); } + public static Sort getFloatSort(final Script script, final BigInteger index1, final BigInteger index2) { + return script.sort(FLOATINGPOINT_SORT, new String[] { index1.toString(), index2.toString() }); + } + /** * @param size * number of bits diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 086835e62e2..5884618d698 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -31,6 +31,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashSet; +import java.util.Set; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,7 +47,9 @@ import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.TraceCheckerUtils; import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; +import de.uni_freiburg.informatik.ultimate.logic.ConstantTerm; import de.uni_freiburg.informatik.ultimate.logic.FunctionSymbol; +import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; @@ -74,13 +77,17 @@ public class AnnotateAndAsserter { protected final TraceCheckStatisticsGenerator mTcbg; public boolean mSucessfulReuse = false; - // private VarAssignmentReuseAnnotation mVAforReuse = null; //For BitVec, since we have sort problem for a guess - private VarAssignmentReuseAnnotation mVAforReuse; // Try to always use an VA, - // if problem SORT maybe - // just do it for int + private VarAssignmentReuseAnnotation mVAforReuse = null; + private VarAssignmentReuseAnnotation mCurrentVA; + private VarAssignmentReuseAnnotation mDefaultVA; final LinkedHashSet nondetsInTrace = new LinkedHashSet(); + final LinkedHashSet nondetsInTraceAfterPreviousVA = new LinkedHashSet(); final HashMap nondetNameToType = new HashMap<>(); - Integer mTestCaseUniqueIdentifier = 0; + private Integer mTestCaseUniqueIdentifier = 0; + private final Integer mHighestVaOrderInTrace = -1; + private boolean lastVaInTraceIsUsedForReuse = false; + + private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, @@ -150,97 +157,99 @@ public void buildAnnotatedSsaAndAssertTerms() { } pendingContextCode++; } - VarAssignmentReuseAnnotation annotationOfCurrentTestGoal = null; - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; - final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); - if (lastStmt instanceof StatementSequence) { - final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; - if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { - - annotationOfCurrentTestGoal = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() - .get(VarAssignmentReuseAnnotation.class.getName()); - } - System.out.println("HIER: " + lastStmtSeq.getSerialNumber()); - } + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; if (reuseVarAssignmentsOfReachableErrorLocatiosn) { boolean reuse = true; - mVAforReuse = annotationOfCurrentTestGoal; + boolean negatedReuse = false; + getCurrentVA(); checkTraceForVAandNONDETS(); - if (mVAforReuse != null) { - final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; - // TODO trying to reuse always if int - if (nondetsInTrace.isEmpty() || annotationOfCurrentTestGoal.mUnsatWithVAs.contains(mVAforReuse)) { - // // No Reuse - System.out.println("NO REUSE"); - reuse = false; - } else { - System.out.println(varAssignmentPairs); - reuse = true; - final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO - if (mVAforReuse.equals(annotationOfCurrentTestGoal)) { - System.out.println("CURRENT VA is reused"); - } - if (!vaPairsAsTerms.isEmpty() && reuse) { // TODO Needed? - Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); - if (mVAforReuse.mIsNegated && !vaPairsAsTerms.isEmpty()) { - varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); - } - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); - } else { - reuse = false; + if (mCurrentVA != null && mVAforReuse == null) { + mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); + mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); + mVAforReuse = mDefaultVA; + } + + if (nondetsInTrace.isEmpty() || mCurrentVA == null || mCurrentVA.mUnsatWithVAs.contains(mVAforReuse)) { + System.out.println("NO REUSE"); + reuse = false; + } else { + reuse = true; + final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO + + if (!vaPairsAsTerms.isEmpty()) { + Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { + negatedReuse = true; + varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); } + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); + } else { + reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) + // In this case previous test goal has not been checked yet. + } } + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + if (mSatisfiable == LBool.UNSAT) { if (reuse) { - annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); + // annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); // annotationOfCurrentTestGoal.mVAofOppositeBranch.setVa(mVAforReuse.mVarAssignmentPair); System.out.println("REUSE UNSAT"); mMgdScriptTc.getScript().pop(1); - annotationOfCurrentTestGoal.mVAofOppositeBranch.removeCheck(); + if (lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) { + if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + + mVAforReuse.mVarAssignmentPair.size()) { + System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); + } else { + System.out.println("No OtherBranch Optimopti Sizes dont match"); + } + + } else { + System.out.println("No OtherBranch Optimopti"); + } + + mVAforReuse.mNegatedVA = true; } // Hier oder vor der IF mSatisfiable = mMgdScriptTc.getScript().checkSat(); - if (mSatisfiable == LBool.SAT) { - // TODO - // register new model for 2nd check - // annotationOfCurrentTestGoal.setVa(null); + if (reuse) { + + if (mCurrentVA.secondCheck == true) { + mVAforReuse.mNegatedVA = false; + } + } + } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal System.out.println("REUSE SUCCESSFULL"); - if (!mVAforReuse.equals(annotationOfCurrentTestGoal)) { - annotationOfCurrentTestGoal.setVa(mVAforReuse.mVarAssignmentPair); - if (mVAforReuse.mIsNegated) { - // TODO Instead, VA with actual Model vor 2nd Check - // mMgdScriptTc.getScript().getModel(); - // annotationOfCurrentTestGoal.negateVa(); //TODO ??? ACHTUNG DARF NICHT SEIN - - } - if (annotationOfCurrentTestGoal.checkCount == 2) { - mVAforReuse.negateVa(); - } + if (mCurrentVA.secondCheck == true) { + mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; } + mSucessfulReuse = true; } + if (reuse) { + mCurrentVA.secondCheck = true; + } } else { mSatisfiable = mMgdScriptTc.getScript().checkSat(); - // TODO no reuse, SAT, second checksat we can reuse - // TODO guessed reuse UNSAT, checksat sat, we guess the same for second checksat instead of reusing } + if (mSatisfiable == LBool.UNKNOWN) { System.out.println("UNKNOWN"); } - annotationOfCurrentTestGoal.checkCount += 1; - // Report benchmarks mTcbg.reportNewCheckSat(); mTcbg.reportNewCodeBlocks(mTrace.length()); @@ -249,9 +258,14 @@ public void buildAnnotatedSsaAndAssertTerms() { } private Term createTermFromVA(final String variableAsString, final Term value) { - final FunctionSymbol varInCurrentScript = mMgdScriptTc.getScript().getTheory() - .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); - System.out.println(variableAsString); + FunctionSymbol varInCurrentScript = + mMgdScriptTc.getScript().getTheory().getDeclaredFunctions().get(variableAsString); + if (varInCurrentScript == null) { + varInCurrentScript = mMgdScriptTc.getScript().getTheory() + .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); + System.out.println(variableAsString); + } + if (varInCurrentScript == null) { throw new AssertionError("unknown var " + variableAsString); } @@ -267,7 +281,25 @@ private Term createTermFromVA(final String variableAsString, final Term value) { nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), null, null, valueAsAppterm.getParameters()); } else { - throw new AssertionError("TODO FLOATINGPOINT_SORT Default vlaue "); + // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) + // (_ +zero 2 4) + + final String[] indices = new String[2]; + indices[0] = "0"; + indices[1] = "0"; + + final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); + final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 8)); + final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 23)); + nondetValue = + SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + + // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, SmtSortUtils + // .getFloatSort(mMgdScriptTc.getScript(), BigInteger.valueOf(8), BigInteger.valueOf(23))); + } break; } @@ -284,12 +316,33 @@ private Term createTermFromVA(final String variableAsString, final Term value) { } break; } - default: { - nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), - SmtSortUtils.getIntSort(mMgdScriptTc), BigInteger.ZERO); + case SmtSortUtils.INT_SORT: { + + if (value != null) { + nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), + SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getIntSort(mMgdScriptTc)); + } else { + nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), + SmtSortUtils.getIntSort(mMgdScriptTc), BigInteger.ZERO); + } break; } + case SmtSortUtils.REAL_SORT: { + + if (value != null) { + nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), + SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getRealSort(mMgdScriptTc)); + } else { + nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), + SmtSortUtils.getRealSort(mMgdScriptTc), BigInteger.ZERO); + } + break; + } + default: { + throw new AssertionError("Unexpected Value Sort"); + } } + mValueAssignmentUsedForReuse.add(new Pair<>(nondetVar, nondetValue)); return SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, nondetValue); } @@ -311,29 +364,61 @@ private void checkTraceForVAandNONDETS() { if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - if (statementBranch.toString().startsWith("havoc") - && statementBranch.toString().contains("nondet")) { - final String traceTermAsString = mSSA.getFormulaFromNonCallPos(i).toStringDirect(); - final Pattern pattern = Pattern.compile("\\|.*nondet\\d[^\\|]*\\|", Pattern.CASE_INSENSITIVE); - final Matcher matcher = pattern.matcher(traceTermAsString); - if (matcher.find()) { - final String match = matcher.group(); - nondetsInTrace.add(match.toString()); - nondetNameToType.put(match.toString(), - TestVector.getNonDetTypeFromName(statementBranch.getPayload().toString())); + if (statementBranch.toString().contains("nondet")) { + + final Set nonTheorySymbolsInTerm = + SmtUtils.extractNonTheoryFunctionSymbols(mSSA.getFormulaFromValidNonCallPos(i)); + + for (final FunctionSymbol symbol : nonTheorySymbolsInTerm) { + final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)") + .matcher(statementBranch.getPayload().toString()); + if (m.find()) { + if (symbol.getName().contains("nondet")) { + nondetsInTrace.add(symbol.getName()); + nondetsInTraceAfterPreviousVA.add(symbol.getName()); + nondetNameToType.put(symbol.getName(), m.group(1)); + + } + } else { + System.out.println(symbol + " not in payload"); + } + } + // final String traceTermAsString = mSSA.getFormulaFromNonCallPos(i).toStringDirect(); + // final Pattern pattern = + // Pattern.compile("\\|[^\\|]*nondet\\d[^\\|]*\\|", Pattern.CASE_INSENSITIVE); + // final Matcher matcher = pattern.matcher(traceTermAsString); + // if (matcher.find()) { + // final String match = matcher.group(); + + // } + } // If VA in Trace returns last found VA if (statementBranch.getPayload().getAnnotations() .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - mVAforReuse = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() - .get(VarAssignmentReuseAnnotation.class.getName()); + + final VarAssignmentReuseAnnotation reuseCandidate = + (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { + mVAforReuse = reuseCandidate; + System.out.println("reuseCandidate: " + statementBranch.getSerialNumber() + + " vaOrderNumber: " + reuseCandidate.mVaOrder); + lastVaInTraceIsUsedForReuse = true; + } else { + System.out.println("Last INtrace: " + statementBranch.getSerialNumber() + + " vaOrderNumber: " + reuseCandidate.mVaOrder); + lastVaInTraceIsUsedForReuse = false; + } + + // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA + nondetsInTraceAfterPreviousVA.clear(); } } } } - } /* @@ -346,6 +431,7 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { boolean inputBetweenTestGoals = false; int nondetPositionCount = 0; final TestVector testV = new TestVector(); + for (final String nondet : nondetsInTrace) { boolean nondetNotInVA = true; Term value = null; @@ -359,10 +445,12 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { nondetInVA.add(reuseVaTerm); break; } + } - if (nondetNotInVA) { + if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! + System.out.println("ALARM: " + nondet + " not in VA"); inputBetweenTestGoals = true; value = null; // null will be used as value zero @@ -390,4 +478,17 @@ private void exportTest(final TestVector testV) { e.printStackTrace(); } } + + private void getCurrentVA() { + final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); + + if (lastStmt instanceof StatementSequence) { + final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; + if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { + mCurrentVA = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + } + System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); + } + } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 40a8483f12b..90c035b09eb 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -400,6 +400,7 @@ private IcfgProgramExecution computeRcfgProgramExecutionAndDecodeBranches(fin * Compute program execution in the case that the checked specification is violated (result of trace check is SAT). */ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuilder nsb) { + final int vaOrder = -1; final RelevantVariables relVars = new RelevantVariables<>(mNestedFormulas, mCsToolkit.getModifiableGlobalsTable()); final IcfgProgramExecutionBuilder rpeb = @@ -419,7 +420,20 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } rpeb.setBranchEncoders(i, beMapping); } + } else if (mTrace.getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mTrace.getSymbol(i); + + // If VA in Trace returns last found VA + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + + final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + reuseCandidate.mVaOrder = vaOrder; + + } } + } final Function funGetValue; @@ -432,7 +446,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final boolean mTestGeneration = true; if (mTestGeneration) { - final TestVector testV = extractTestVector(nsb, funGetValue, rpeb); + final TestVector testV = extractTestVector(nsb, funGetValue, rpeb, vaOrder); // testV.addValuesWithNegativeIndex(); System.out.println("Amount Of NonDets in TestCase: " + testV.countNonDets); final boolean mExportTests = true; @@ -461,7 +475,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild // does rpeb.addValueAtVarAssignmentPosition and creates a testVector at the same time private TestVector extractTestVector(final NestedSsaBuilder nsb, final Function funGetValue, - final IcfgProgramExecutionBuilder rpeb) { + final IcfgProgramExecutionBuilder rpeb, final int vaOrder) { final TestVector testV = new TestVector(); final ArrayList varAssignment = new ArrayList(); final ArrayList> varAssignmentPair = new ArrayList>(); @@ -481,30 +495,26 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (evenRepresentative) { if (index >= 0) { // TODO how can this be an issue? - if (indexedRepresentatives.entrySet().size() == 2) { // not 100sure if 2 is the - // right index - - // TODO Not sure if save, but by far the best solution - if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { - final StatementSequence stsq = - (StatementSequence) rpeb.mTrace.asList().get(index); - if (stsq.getPayload().toString().contains("nondet")) { - final String type = - TestVector.getNonDetTypeFromName(stsq.getPayload().toString()); - testV.addValueAssignment(valueT, index, type); - final TermTransferrer test = new TermTransferrer( - mCfgManagedScript.getScript(), mTcSmtManager.getScript()); - - final Term varEqValue = - SmtUtils.binaryEquality(mTcSmtManager.getScript(), - test.transform(indexedVar), test.transform(valueT)); - final Pair varValuePair = new Pair( - test.transform(indexedVar), test.transform(valueT)); - varAssignmentPair.add(varValuePair); - varAssignment.add(varEqValue); - } + // TODO Not sure if save, but by far the best solution + if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { + final StatementSequence stsq = + (StatementSequence) rpeb.mTrace.asList().get(index); + if (stsq.getPayload().toString().contains("nondet")) { + final String type = + TestVector.getNonDetTypeFromName(stsq.getPayload().toString()); + testV.addValueAssignment(valueT, index, type); + final TermTransferrer test = new TermTransferrer( + mCfgManagedScript.getScript(), mTcSmtManager.getScript()); + + final Term varEqValue = SmtUtils.binaryEquality(mTcSmtManager.getScript(), + test.transform(indexedVar), test.transform(valueT)); + final Pair varValuePair = new Pair( + test.transform(indexedVar), test.transform(valueT)); + varAssignmentPair.add(varValuePair); + varAssignment.add(varEqValue); } } + } else { System.out.println("unexpected Index for nondet"); } @@ -528,8 +538,8 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi .containsKey(VarAssignmentReuseAnnotation.class.getName())) { final VarAssignmentReuseAnnotation vaReuseAnno = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - vaReuseAnno.setVa(varAssignmentPair); - vaReuseAnno.mIsNegated = false; + vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1); + } else { assert false;// TODO } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index 1a5aed603d9..af00a99151c 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -17,18 +17,27 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { private static final long serialVersionUID = 1L; private static final String KEY = VarAssignmentReuseAnnotation.class.getName(); + public boolean secondCheck = false; + public boolean mNegatedVA = false; private final Map mMap = new HashMap<>(); public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated, // order corresponds to // test-case public VarAssignmentReuseAnnotation mVAofOppositeBranch; - public boolean mIsNegated = false; + public boolean mIsActiveTestGoal = true; public boolean mUseCurrentTestGoal = false; // use this test goal instead of a previous public HashSet mUnsatWithVAs = new HashSet<>(); public Integer checkCount = 1; // is either 1 or 2 + public VarAssignmentReuseAnnotation mDefaultVA = null; + + public boolean mLastChecked = false; // true after checksat, false if in a trace but no + + public Integer mVaOrder = -1; + public VarAssignmentReuseAnnotation() { + } @Override @@ -57,16 +66,26 @@ public void setOppositeAnno(final VarAssignmentReuseAnnotation vaOpppositeBranch /* * Warning replaces the current VA */ - public void setVa(final ArrayList> varAssignmentPair) { + public void setVa(final ArrayList> varAssignmentPair, final int vaOrder) { mVarAssignmentPair = varAssignmentPair; - } - - // Do not negate here, only flag as negated. Negate the formula when asserting the term - public void negateVa() { - mIsNegated = true; + mVaOrder = vaOrder; } public void removeCheck() { mIsActiveTestGoal = false; } + + /* + * there exist only 2 VA's that need to know the default. The first and its opposite + */ + public VarAssignmentReuseAnnotation setDefaultVa(final VarAssignmentReuseAnnotation defaultVA) { + if (mDefaultVA == null) { + if (defaultVA != null) { + mDefaultVA = defaultVA; + } else { + mDefaultVA = new VarAssignmentReuseAnnotation(); + } + } + return mDefaultVA; + } } From 6a95f3774a6e4ad81d056b2cc4d4797edb30fa18 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 15 Jan 2024 22:30:38 +0100 Subject: [PATCH 038/278] fixed optimisation output and double smt terms in test generation reuse --- .../singletracecheck/AnnotateAndAsserter.java | 80 ++++++++++++++----- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 5884618d698..94d4c465a8b 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -276,31 +276,69 @@ private Term createTermFromVA(final String variableAsString, final Term value) { switch (nondetVar.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - if (value != null) { - final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), null, - null, valueAsAppterm.getParameters()); - } else { - // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) - // (_ +zero 2 4) - final String[] indices = new String[2]; - indices[0] = "0"; - indices[1] = "0"; + System.out.println(nondetVar.getSort().getIndices()[1]); - final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); - final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 8)); - final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 23)); - nondetValue = - SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + if (nondetVar.getSort().getIndices()[1].equals("24")) { + if (value != null) { + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), + null, null, valueAsAppterm.getParameters()); + } else { + // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) + // (_ +zero 2 4) + + final String[] indices = new String[2]; + indices[0] = "0"; + indices[1] = "0"; + + final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); + final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 8)); + final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 23)); + nondetValue = + SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + + // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, + // SmtSortUtils + // .getFloatSort(mMgdScriptTc.getScript(), BigInteger.valueOf(8), BigInteger.valueOf(23))); - // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, SmtSortUtils - // .getFloatSort(mMgdScriptTc.getScript(), BigInteger.valueOf(8), BigInteger.valueOf(23))); + } + } else if (nondetVar.getSort().getIndices()[1].equals("53")) { + if (value != null) { + final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), + null, null, valueAsAppterm.getParameters()); + } else { + // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) + // (_ +zero 2 4) + + final String[] indices = new String[2]; + indices[0] = "0"; + indices[1] = "0"; + + final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); + final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 11)); + final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 52)); + nondetValue = + SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + + // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, + // SmtSortUtils + // .getFloatSort(mMgdScriptTc.getScript(), BigInteger.valueOf(8), BigInteger.valueOf(23))); + + } + + } else { + throw new AssertionError("Unexpected Float Sort Size"); } + break; } case SmtSortUtils.BITVECTOR_SORT: { @@ -462,7 +500,7 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { // increase at the end of loop nondetPositionCount += 1; } - if (inputBetweenTestGoals && mVAforReuse.checkCount == 2) { + if (inputBetweenTestGoals) { exportTest(testV); } return nondetInVA; From 7f6a1a9eb27ec70456b8fdb8132f4befda285f8c Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 15 Jan 2024 22:58:36 +0100 Subject: [PATCH 039/278] Fixed Nondet Value Regex Matcher --- .../singletracecheck/TestExporter.java | 7 ------- .../singletracecheck/TraceCheck.java | 11 +++++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 35e396fe145..fbe0593e0d6 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -531,11 +531,4 @@ public void addValuesWithNegativeIndex() { values.addAll(valuesWithNegativeIndices); values.addAll(valuesWithPositiveIndices); } - - static public String getNonDetTypeFromName(final String payload) { - final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(payload); - m.find(); - return m.group(1); - - } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 90c035b09eb..5b3ce23c136 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -35,6 +35,8 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import de.uni_freiburg.informatik.ultimate.automata.AutomataOperationCanceledException; import de.uni_freiburg.informatik.ultimate.automata.Word; @@ -499,9 +501,11 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (rpeb.mTrace.asList().get(index) instanceof StatementSequence) { final StatementSequence stsq = (StatementSequence) rpeb.mTrace.asList().get(index); - if (stsq.getPayload().toString().contains("nondet")) { - final String type = - TestVector.getNonDetTypeFromName(stsq.getPayload().toString()); + + final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)") + .matcher(stsq.getPayload().toString()); + if (m.find()) { + final String type = m.group(1); testV.addValueAssignment(valueT, index, type); final TermTransferrer test = new TermTransferrer( mCfgManagedScript.getScript(), mTcSmtManager.getScript()); @@ -514,7 +518,6 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi varAssignment.add(varEqValue); } } - } else { System.out.println("unexpected Index for nondet"); } From 63a0638e30742aed713e78e8612931e820afbcfe Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 29 Jan 2024 13:07:23 +0100 Subject: [PATCH 040/278] Fixed that other branch optimization creates testcases with the same name as the current branch. Readded UnsatWith to prevent unnecessary sat checks --- .../singletracecheck/AnnotateAndAsserter.java | 10 +++++++--- .../singletracecheck/TestExporter.java | 2 +- .../tracecheckerutils/singletracecheck/TraceCheck.java | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 94d4c465a8b..fd2f9a887b3 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -83,7 +83,7 @@ public class AnnotateAndAsserter { final LinkedHashSet nondetsInTrace = new LinkedHashSet(); final LinkedHashSet nondetsInTraceAfterPreviousVA = new LinkedHashSet(); final HashMap nondetNameToType = new HashMap<>(); - private Integer mTestCaseUniqueIdentifier = 0; + private String mTestCaseUniqueIdentifier = "0"; private final Integer mHighestVaOrderInTrace = -1; private boolean lastVaInTraceIsUsedForReuse = false; @@ -193,7 +193,10 @@ public void buildAnnotatedSsaAndAssertTerms() { } } + if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { + reuse = false; // Wie kann das überhaupt sein? + } mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (mSatisfiable == LBool.UNSAT) { @@ -201,7 +204,7 @@ public void buildAnnotatedSsaAndAssertTerms() { // annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); // annotationOfCurrentTestGoal.mVAofOppositeBranch.setVa(mVAforReuse.mVarAssignmentPair); System.out.println("REUSE UNSAT"); - + mCurrentVA.mUnsatWithVAs.add(mVAforReuse); mMgdScriptTc.getScript().pop(1); if (lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) { if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() @@ -396,7 +399,8 @@ public NestedFormulas getAnnotatedSsa() { * Iterates over trace and returns last VA and all Nondets in trace */ private void checkTraceForVAandNONDETS() { - mTestCaseUniqueIdentifier = mSSA.getTrace().hashCode(); + mTestCaseUniqueIdentifier = mTestCaseUniqueIdentifier + mSSA.getTrace().hashCode(); + mTestCaseUniqueIdentifier += mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1).hashCode(); if (mSSA.getTrace().length() - 1 > 0) { for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index fbe0593e0d6..c07883da11b 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -47,7 +47,7 @@ public class TestExporter { * 1: one directory for all programs * 2: one directory for each program */ - public void exportTests(final TestVector testV, final int i, final boolean allInOneFile) throws Exception { + public void exportTests(final TestVector testV, final String i, final boolean allInOneFile) throws Exception { FileOutputStream output; final String name = "testcase" + i; diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 5b3ce23c136..65af3b7f08d 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -454,7 +454,8 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final boolean mExportTests = true; if (mExportTests) { final boolean mExportAllInOneFile = true; - exportTest(testV, rpeb.mTrace.hashCode(), mExportAllInOneFile); + final String identifier = "" + rpeb.mTrace.hashCode(); + exportTest(testV, identifier, mExportAllInOneFile); } } else { for (final var entry : nsb.getIndexedVarRepresentative().entrySet()) { @@ -550,7 +551,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi return testV; } - private void exportTest(final TestVector testV, final int identifier, final boolean allInOneFile) { + private void exportTest(final TestVector testV, final String identifier, final boolean allInOneFile) { try { if (!testV.isEmpty()) { TestExporter.getInstance().exportTests(testV, identifier, allInOneFile); From ab093a05aa1995124f2de3fd4f2329f35cec3bd8 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 30 Jan 2024 16:28:13 +0100 Subject: [PATCH 041/278] Fixed UnsatWith --- .../singletracecheck/AnnotateAndAsserter.java | 23 +++++-------------- .../singletracecheck/TraceCheck.java | 4 ---- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index fd2f9a887b3..1c032473a41 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -161,8 +161,7 @@ public void buildAnnotatedSsaAndAssertTerms() { final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; if (reuseVarAssignmentsOfReachableErrorLocatiosn) { - boolean reuse = true; - boolean negatedReuse = false; + boolean reuse; getCurrentVA(); checkTraceForVAandNONDETS(); if (mCurrentVA != null && mVAforReuse == null) { @@ -171,9 +170,12 @@ public void buildAnnotatedSsaAndAssertTerms() { mVAforReuse = mDefaultVA; } - if (nondetsInTrace.isEmpty() || mCurrentVA == null || mCurrentVA.mUnsatWithVAs.contains(mVAforReuse)) { + if (nondetsInTrace.isEmpty() || mCurrentVA == null) { System.out.println("NO REUSE"); reuse = false; + } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { + reuse = false; // Wie kann das überhaupt sein? + System.out.println("NO REUSE since UNSAT With"); } else { reuse = true; final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO @@ -181,7 +183,6 @@ public void buildAnnotatedSsaAndAssertTerms() { if (!vaPairsAsTerms.isEmpty()) { Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { - negatedReuse = true; varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); } mMgdScriptTc.getScript().push(1); @@ -190,13 +191,8 @@ public void buildAnnotatedSsaAndAssertTerms() { } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. - } } - if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { - reuse = false; // Wie kann das überhaupt sein? - - } mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (mSatisfiable == LBool.UNSAT) { @@ -215,31 +211,24 @@ public void buildAnnotatedSsaAndAssertTerms() { } else { System.out.println("No OtherBranch Optimopti Sizes dont match"); } - } else { System.out.println("No OtherBranch Optimopti"); } - mVAforReuse.mNegatedVA = true; } // Hier oder vor der IF mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (reuse) { - if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = false; } - } - } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal System.out.println("REUSE SUCCESSFULL"); - if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; } - mSucessfulReuse = true; } if (reuse) { @@ -504,7 +493,7 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { // increase at the end of loop nondetPositionCount += 1; } - if (inputBetweenTestGoals) { + if (inputBetweenTestGoals && mVAforReuse.checkCount == 2) { exportTest(testV); } return nondetInVA; diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 65af3b7f08d..790ad5892cf 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -535,8 +535,6 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } final boolean vaReuse = true; if (vaReuse) { - - // TODO Add empty annotation to unreachable test goals? to prevent a reuse Not sure if needed final IElement statementBranch = (IElement) nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); if (statementBranch.getPayload().getAnnotations() .containsKey(VarAssignmentReuseAnnotation.class.getName())) { @@ -544,8 +542,6 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1); - } else { - assert false;// TODO } } return testV; From 38acd29d6cd873944e8f43fe0f2e267219322093 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 1 Feb 2024 23:39:05 +0100 Subject: [PATCH 042/278] deactivated reuse for evaluation deactivated unsatwith fixed that there is no otherbranch optimication if reusing negated va --- .../singletracecheck/AnnotateAndAsserter.java | 6 +++--- .../lib/tracecheckerutils/singletracecheck/TraceCheck.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 1c032473a41..90811385de8 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -158,7 +158,7 @@ public void buildAnnotatedSsaAndAssertTerms() { pendingContextCode++; } - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = false; if (reuseVarAssignmentsOfReachableErrorLocatiosn) { boolean reuse; @@ -200,9 +200,9 @@ public void buildAnnotatedSsaAndAssertTerms() { // annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); // annotationOfCurrentTestGoal.mVAofOppositeBranch.setVa(mVAforReuse.mVarAssignmentPair); System.out.println("REUSE UNSAT"); - mCurrentVA.mUnsatWithVAs.add(mVAforReuse); + // mCurrentVA.mUnsatWithVAs.add(mVAforReuse); mMgdScriptTc.getScript().pop(1); - if (lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) { + if ((lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) && !mVAforReuse.mNegatedVA) { if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size()) { System.out.println("OtherBranchRemoveCheck"); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 790ad5892cf..1b4dd3b9691 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -533,7 +533,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } } - final boolean vaReuse = true; + final boolean vaReuse = false; if (vaReuse) { final IElement statementBranch = (IElement) nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); if (statementBranch.getPayload().getAnnotations() From b5234f758d1d923da7f121ae64cc06f95562d434 Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 2 Feb 2024 13:10:03 +0100 Subject: [PATCH 043/278] reactivate reuse --- .../tracecheckerutils/singletracecheck/AnnotateAndAsserter.java | 2 +- .../lib/tracecheckerutils/singletracecheck/TraceCheck.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 90811385de8..757bc5283f0 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -158,7 +158,7 @@ public void buildAnnotatedSsaAndAssertTerms() { pendingContextCode++; } - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = false; + final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; if (reuseVarAssignmentsOfReachableErrorLocatiosn) { boolean reuse; diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 1b4dd3b9691..790ad5892cf 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -533,7 +533,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } } - final boolean vaReuse = false; + final boolean vaReuse = true; if (vaReuse) { final IElement statementBranch = (IElement) nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); if (statementBranch.getPayload().getAnnotations() From a64d573c2e367824178aa129beda8de8df156ba2 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 3 Feb 2024 16:46:11 +0100 Subject: [PATCH 044/278] minor fix --- .../singletracecheck/AnnotateAndAsserter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 757bc5283f0..bf95bf45fc8 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -270,12 +270,11 @@ private Term createTermFromVA(final String variableAsString, final Term value) { case SmtSortUtils.FLOATINGPOINT_SORT: { System.out.println(nondetVar.getSort().getIndices()[1]); - if (nondetVar.getSort().getIndices()[1].equals("24")) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), - null, null, valueAsAppterm.getParameters()); + valueAsAppterm.getSort().getIndices(), null, valueAsAppterm.getParameters()); } else { // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) // (_ +zero 2 4) @@ -493,7 +492,7 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { // increase at the end of loop nondetPositionCount += 1; } - if (inputBetweenTestGoals && mVAforReuse.checkCount == 2) { + if (inputBetweenTestGoals) { exportTest(testV); } return nondetInVA; From fa2aa90679d166aea76b0b577e9de982261dbbbd Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 3 Feb 2024 23:01:03 +0100 Subject: [PATCH 045/278] minor fix --- .../ultimate/lib/smtlibutils/SmtUtils.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtUtils.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtUtils.java index e7603c467a8..2f9f915d5af 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtUtils.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/SmtUtils.java @@ -270,7 +270,8 @@ public static Term simplify(final ManagedScript mgdScript, final Term formula, f public static ExtendedSimplificationResult simplifyWithStatistics(final ManagedScript mgdScript, final Term formula, final IUltimateServiceProvider services, final SimplificationTechnique simplificationTechnique) { - return simplifyWithStatistics(mgdScript, formula, mgdScript.term(null, "true"), services, simplificationTechnique); + return simplifyWithStatistics(mgdScript, formula, mgdScript.term(null, "true"), services, + simplificationTechnique); } public static ExtendedSimplificationResult simplifyWithStatistics(final ManagedScript mgdScript, final Term formula, @@ -1333,8 +1334,7 @@ private static Term comparison(final Script script, final String functionSymbol, } } if (SmtSortUtils.isNumericSort(lhs.getSort())) { - return PolynomialRelation.of(script, RelationSymbol.convert(functionSymbol), lhs, rhs) - .toTerm(script); + return PolynomialRelation.of(script, RelationSymbol.convert(functionSymbol), lhs, rhs).toTerm(script); } else { assert SmtSortUtils.isBitvecSort(lhs.getSort()); // TODO 20220908 Matthias: Minor improvements still possible. E.g., everything @@ -1513,6 +1513,9 @@ public static Term unfTerm(final Script script, final String funcname, final Str case "bvsge": result = BitvectorUtils.unfTerm(script, funcname, toBigIntegerArray(indices), params); break; + case "fp": + result = script.term(funcname, null, null, params); + break; default: result = script.term(funcname, indices, resultSort, params); break; @@ -1789,9 +1792,8 @@ public static Term divIntFlatten(final Script script, final Term divident, final } /** - * Convert `(div (div a1 ... an) d)` to `(div a1 ... d*an)` if `an` is a - * positive literal and convert it to `(div a1 ... an d)` otherwise. Note that - * the similar transformation would be unsound for negative literals, see + * Convert `(div (div a1 ... an) d)` to `(div a1 ... d*an)` if `an` is a positive literal and convert it to `(div a1 + * ... an d)` otherwise. Note that the similar transformation would be unsound for negative literals, see * {@link PolynomialTest#intDivision10} */ public static Term divIntFlatten(final Script script, final Term divident, final BigInteger divisorBigInt) { @@ -2306,10 +2308,8 @@ public static LBool checkEquivalence(final Term formula1, final Term formula2, f } /** - * @return LBool.UNSAT if the SMT solver was able to prove that the antecedent - * implies the succedent, LBool.SAT if the SMT was able to prove that - * the antecent does not imply the succedent, and LBool.UNKNOWN - * otherwise. + * @return LBool.UNSAT if the SMT solver was able to prove that the antecedent implies the succedent, LBool.SAT if + * the SMT was able to prove that the antecent does not imply the succedent, and LBool.UNKNOWN otherwise. */ public static LBool checkImplication(final Term antecedent, final Term succedent, final Script script) { final Term notImply = SmtUtils.and(script, antecedent, SmtUtils.not(script, succedent)); @@ -2715,15 +2715,12 @@ public static boolean isNeutralElement(final String booleanConnective, final Ter } /** - * Auxiliary method that replaces all free variables in a term by constant - * symbols (i.e., 0-ary function symbols). These constant symbols are declared - * in the script.
- * Use this method with caution. The constant symbols will live forever in the - * current stack frame, hence this method should be used in combination with - * push/pop in order to remove the constant symbols from the assertion stack - * after they are not needed any more.
- * The name for the new constant symbols are defined by the method - * {@link SmtUtils#termVariable2constant}). + * Auxiliary method that replaces all free variables in a term by constant symbols (i.e., 0-ary function symbols). + * These constant symbols are declared in the script.
+ * Use this method with caution. The constant symbols will live forever in the current stack frame, hence this + * method should be used in combination with push/pop in order to remove the constant symbols from the assertion + * stack after they are not needed any more.
+ * The name for the new constant symbols are defined by the method {@link SmtUtils#termVariable2constant}). */ public static Term replaceFreeVariablesByConstants(final Script script, final Term term) { final TermVariable[] vars = term.getFreeVars(); From 130ef25ecfab996d4d3c01ee44c9f2d93579ea45 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 10 Feb 2024 22:12:57 +0100 Subject: [PATCH 046/278] Potential Fix for hardness benchmarks (needs to be evaluated) Deactivated negated reuse, seems to help with hostid benchmark --- .../singletracecheck/AnnotateAndAsserter.java | 5 ++- .../singletracecheck/TestExporter.java | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index bf95bf45fc8..840a0a1bec3 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -181,9 +181,9 @@ public void buildAnnotatedSsaAndAssertTerms() { final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO if (!vaPairsAsTerms.isEmpty()) { - Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { - varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); + // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); } mMgdScriptTc.getScript().push(1); mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); @@ -269,7 +269,6 @@ private Term createTermFromVA(final String variableAsString, final Term value) { switch (nondetVar.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - System.out.println(nondetVar.getSort().getIndices()[1]); if (nondetVar.getSort().getIndices()[1].equals("24")) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index c07883da11b..9684be59fc5 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -306,6 +306,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin } private void addToLinkedList(final Integer index, final Term valueTerm, final String type) { + if (values.size() <= index) { for (int i = values.size(); i <= index; i = i + 1) { values.add(null); @@ -318,19 +319,22 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - if (type.equals("float")) { + if (type.equals("double")) { // if (type.equals("float")) { if (((ApplicationTerm) valueTerm).getParameters().length == 3) { assert valueTerm instanceof ApplicationTerm; - final ApplicationTerm cva = (ApplicationTerm) valueTerm; - String sign = cva.getParameters()[0].toStringDirect(); - sign = sign.replaceAll("[^01]", ""); - - String exponent = cva.getParameters()[1].toStringDirect(); - exponent = exponent.replaceAll("[^01]", ""); - - String significant = cva.getParameters()[2].toStringDirect(); - significant = significant.replaceAll("[^01]", ""); - final String floatAsBitString = sign + exponent + significant; + // final ApplicationTerm cva = (ApplicationTerm) valueTerm; + final String bitString = valueTerm.toStringDirect(); + final String floatAsBitString = bitString.replaceAll("[^01]", ""); + + // String sign = cva.getParameters()[0].toStringDirect(); + // sign = sign.replaceAll("[^01]", ""); + // + // String exponent = cva.getParameters()[1].toStringDirect(); + // exponent = exponent.replaceAll("[^01]", ""); + // + // String significant = cva.getParameters()[2].toStringDirect(); + // significant = significant.replaceAll("[^01]", ""); + // final String floatAsBitString = sign + exponent + significant; // final int intBits = Integer.parseInt(floatAsBitString, 2); final int intBits = (int) Long.parseLong(floatAsBitString, 2); final float asFloat = Float.intBitsToFloat(intBits); @@ -350,7 +354,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } break; } - } else if (type.equals("double")) { + } else { // if (type.equals("double")) { assert valueTerm instanceof ApplicationTerm; if (((ApplicationTerm) valueTerm).getParameters().length == 3) { final ApplicationTerm cva = (ApplicationTerm) valueTerm; @@ -381,9 +385,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } break; } - } else { - throw new AssertionError("Unexpected Sort For Output Type"); } + // else { + // throw new AssertionError("Unexpected Sort For Output Type" + type); + // } } case SmtSortUtils.BITVECTOR_SORT: { From 4d16fe82e2be1e159bf36864bf2307782268068b Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 15 Feb 2024 19:16:02 +0100 Subject: [PATCH 047/278] added setting for reuse --- .../singletracecheck/AnnotateAndAsserter.java | 83 +++++++++++-------- .../RcfgPreferenceInitializer.java | 32 +++++++ 2 files changed, 80 insertions(+), 35 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 840a0a1bec3..f773519166b 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -53,12 +53,14 @@ import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; /** * TODO: use quick check * - * @author Matthias Heizmann (heizmann@informatik.uni-freiburg.de) + * @author Matthias Heizmann (heizmann@informatik.uni-freiburg.de), Max Barth (Max.Barth@lmu.de) */ public class AnnotateAndAsserter { @@ -88,6 +90,7 @@ public class AnnotateAndAsserter { private boolean lastVaInTraceIsUsedForReuse = false; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); + final TestGenReuseMode mTestGenReuseMode; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, @@ -99,6 +102,10 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mSSA = nestedSSA; mAnnotateAndAssertCodeBlocks = aaacb; mTcbg = tcbg; + + mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) + .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + System.out.println(mTestGenReuseMode); } public void buildAnnotatedSsaAndAssertTerms() { @@ -158,9 +165,7 @@ public void buildAnnotatedSsaAndAssertTerms() { pendingContextCode++; } - final boolean reuseVarAssignmentsOfReachableErrorLocatiosn = true; - - if (reuseVarAssignmentsOfReachableErrorLocatiosn) { + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { boolean reuse; getCurrentVA(); checkTraceForVAandNONDETS(); @@ -184,10 +189,15 @@ public void buildAnnotatedSsaAndAssertTerms() { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); + // mMgdScriptTc.getScript().push(1); + // mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + // System.out.println("Negated REUSE: " + varAssignmentConjunction); + reuse = false; + } else { + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); } - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. @@ -197,22 +207,10 @@ public void buildAnnotatedSsaAndAssertTerms() { if (mSatisfiable == LBool.UNSAT) { if (reuse) { - // annotationOfCurrentTestGoal.mUnsatWithVAs.add(mVAforReuse); - // annotationOfCurrentTestGoal.mVAofOppositeBranch.setVa(mVAforReuse.mVarAssignmentPair); System.out.println("REUSE UNSAT"); - // mCurrentVA.mUnsatWithVAs.add(mVAforReuse); mMgdScriptTc.getScript().pop(1); - if ((lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) && !mVAforReuse.mNegatedVA) { - if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() - + mVAforReuse.mVarAssignmentPair.size()) { - System.out.println("OtherBranchRemoveCheck"); - mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); - } else { - System.out.println("No OtherBranch Optimopti Sizes dont match"); - } - } else { - System.out.println("No OtherBranch Optimopti"); + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + removeCheckIfCovered(); } mVAforReuse.mNegatedVA = true; } @@ -384,6 +382,7 @@ public NestedFormulas getAnnotatedSsa() { /* * Iterates over trace and returns last VA and all Nondets in trace + * TODO if not ReuseUNSAT mode, we dont really need to know which nondets are in trace */ private void checkTraceForVAandNONDETS() { mTestCaseUniqueIdentifier = mTestCaseUniqueIdentifier + mSSA.getTrace().hashCode(); @@ -474,24 +473,24 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { nondetInVA.add(reuseVaTerm); break; } - } + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { + // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! + + System.out.println("ALARM: " + nondet + " not in VA"); + inputBetweenTestGoals = true; + value = null; // null will be used as value zero + final Term reuseVaTerm = createTermFromVA(nondet, value); + nondetInVA.add(reuseVaTerm); + } - if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { - // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! - - System.out.println("ALARM: " + nondet + " not in VA"); - inputBetweenTestGoals = true; - value = null; // null will be used as value zero - final Term reuseVaTerm = createTermFromVA(nondet, value); - nondetInVA.add(reuseVaTerm); + testV.addValueAssignment(value, nondetPositionCount, nondetNameToType.get(nondet)); + // increase at the end of loop + nondetPositionCount += 1; } - - testV.addValueAssignment(value, nondetPositionCount, nondetNameToType.get(nondet)); - // increase at the end of loop - nondetPositionCount += 1; } - if (inputBetweenTestGoals) { + if (inputBetweenTestGoals && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { exportTest(testV); } return nondetInVA; @@ -520,4 +519,18 @@ private void getCurrentVA() { System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); } } + + private void removeCheckIfCovered() { + if ((lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) && !mVAforReuse.mNegatedVA) { + if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size()) { + System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); + } else { + System.out.println("No OtherBranch Optimopti Sizes dont match"); + } + } else { + System.out.println("No OtherBranch Optimopti"); + } + } } diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java index 824bd211eac..e8a7a01b197 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java @@ -134,12 +134,44 @@ protected UltimatePreferenceItem[] initDefaultPreferences() { new UltimatePreferenceItem<>(LABEL_DUMP_PATH, DEF_DUMP_PATH, PreferenceType.Directory), new UltimatePreferenceItem<>(LABEL_ADDITIONAL_SMT_OPTIONS, DEF_ADDITIONAL_SMT_OPTIONS, PreferenceType.KeyValue), + getTestGenerationSettings(), }; } + public UltimatePreferenceItem getTestGenerationSettings() { + return new UltimatePreferenceItem<>(LABEL_TEST_GEN_REUSE_MODE, DEF_TEST_GEN_REUSE_MODE, + DESC_TEST_GEN_REUSE_MODE, PreferenceType.Combo, TestGenReuseMode.values()); + } + public static IPreferenceProvider getPreferences(final IUltimateServiceProvider services) { return services.getPreferenceProvider(Activator.PLUGIN_ID); } + // Test Generation Reuse Mode + // ======================================================================== + private static final TestGenReuseMode DEF_TEST_GEN_REUSE_MODE = TestGenReuseMode.None; + public static final String LABEL_TEST_GEN_REUSE_MODE = "Reuse Mode for Test Generation"; + private static final String DESC_TEST_GEN_REUSE_MODE = + "None means no reuse, Reuse is without optimizations, ReuseUNSAT uses all optimiztations"; + + /** + * Differnt modes of Reusing Test Cases during Test Generation + * + * @author Max Barth (Max.Barth@gmx.de) + */ + public enum TestGenReuseMode { + /** + * No reuse during Test Generation. + */ + None, + /** + * Simple Reuse just without optimizations + */ + Reuse, + /** + * Reuse UNSAT by removing the check of the other branch and choosing values for inputs between testgoals + */ + ReuseUNSAT + } } From cca14d5c6e07738249d9983adc56ee439e255075 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 26 Feb 2024 14:04:24 +0100 Subject: [PATCH 048/278] Bugfic back to c of bools. C bool has value 0 if value is 0 and 1 otherwise --- .../singletracecheck/TestExporter.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 9684be59fc5..e3425852579 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -421,8 +421,14 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } } else if (type.equals("bool")) { final BigInteger value = new BigInteger(valueInRange); - final BigInteger newValue = value.mod(new BigInteger("2")); - valueInRange = String.valueOf(newValue); + if (value.equals(BigInteger.ZERO)) { + valueInRange = String.valueOf("0"); + } else { + valueInRange = String.valueOf("1"); + } + // final BigInteger value = new BigInteger(valueInRange); + // final BigInteger newValue = value.mod(new BigInteger("2")); + // valueInRange = String.valueOf(newValue); } break; } @@ -449,8 +455,13 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St switch (type) { case "bool": { - final BigInteger newValue = value.mod(new BigInteger("2")); - valueInRange = String.valueOf(newValue); + if (value.equals(BigInteger.ZERO)) { + valueInRange = String.valueOf("0"); + } else { + valueInRange = String.valueOf("1"); + } + // final BigInteger newValue = value.mod(new BigInteger("2")); + // valueInRange = String.valueOf(newValue); break; } case "short": { From 9617ea01096fa5cae7938ff5ebb656ae02239409 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 2 Mar 2024 11:03:32 +0100 Subject: [PATCH 049/278] - New BvToInt constraint mode for intand - Fixed bounds of signed c types in testexporter - enabled unproen testgeneration result for timeouts --- .../TranslationConstrainer.java | 63 +++++++++++++++++-- .../bvinttranslation/TranslationManager.java | 12 ++-- .../singletracecheck/TestExporter.java | 27 ++++---- .../lib/results/TestGenerationResult.java | 10 ++- .../CegarLoopResultReporter.java | 5 +- .../traceabstraction/NwaCegarLoop.java | 9 ++- 6 files changed, 97 insertions(+), 29 deletions(-) diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationConstrainer.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationConstrainer.java index 22aabdca8f2..3b07c902b82 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationConstrainer.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationConstrainer.java @@ -62,11 +62,11 @@ public enum ConstraintsForBitwiseOperations { /** * Overapproximation of all bit-wise functions by auxiliary variables */ - NONE + NONE, /** - * Overapproximation of all bit-wise functions by uninterpreted function - * symbol + * Overapproximation of all bit-wise functions by uninterpreted function symbol */ + MAX } public final ConstraintsForBitwiseOperations mMode; @@ -172,8 +172,7 @@ public Term getSelectConstraint(final Term bvterm, final Term intTerm) { /** * - * @return true iff the constraints define only an overapproximation of - * bvand. + * @return true iff the constraints define only an overapproximation of bvand. */ public boolean bvandConstraint(final Term intTerm, final int width) { if (mMode.equals(ConstraintsForBitwiseOperations.NONE)) { @@ -231,6 +230,14 @@ public boolean bvandConstraint(final Term intTerm, final int width) { case NONE: { throw new UnsupportedOperationException("Deal with this mode at the beginning of this method"); } + case MAX: { + final Term lowerBound = mScript.term("<=", Rational.ZERO.toTerm(intSort), apterm); + final Term upperBound = + mScript.term("<", apterm, SmtUtils.rational2Term(mScript, twoPowWidth, intSort)); + bvandMAXConstraints(width, translatedLHS, translatedRHS); + mBvandConstraintSet.add(lowerBound); + mBvandConstraintSet.add(upperBound); + } default: { throw new UnsupportedOperationException("Set Mode for bvand Constraints"); } @@ -258,6 +265,52 @@ private Term bvandSUMConstraints(final int width, final Term translatedLHS, fina } } + private void bvandMAXConstraints(final int width, final Term translatedLHS, final Term translatedRHS) { + + for (int i = 0; i < width; i++) { + final BigInteger pow = BigInteger.TWO.pow(i); + final Term divisionLHS = + SmtUtils.division(mScript, SmtSortUtils.getIntSort(mScript), translatedLHS, SmtUtils.rational2Term( + mScript, Rational.valueOf(pow, BigInteger.ONE), SmtSortUtils.getIntSort(mScript))); + + final Term divisionRHS = + SmtUtils.division(mScript, SmtSortUtils.getIntSort(mScript), translatedRHS, SmtUtils.rational2Term( + mScript, Rational.valueOf(pow, BigInteger.ONE), SmtSortUtils.getIntSort(mScript))); + + final Term divisionmIntand = SmtUtils.division(mScript, SmtSortUtils.getIntSort(mScript), + SmtUtils.unfTerm(mScript, mIntand, translatedLHS, translatedRHS), SmtUtils.rational2Term(mScript, + Rational.valueOf(pow, BigInteger.ONE), SmtSortUtils.getIntSort(mScript))); + + Term evenVar = mMgdScript.constructFreshTermVariable("evenVar" + i, SmtSortUtils.getIntSort(mScript)); + evenVar = SmtUtils.termVariable2constant(mScript, (TermVariable) evenVar, true); + Term oddVar = mMgdScript.constructFreshTermVariable("oddVar" + i, SmtSortUtils.getIntSort(mScript)); + oddVar = SmtUtils.termVariable2constant(mScript, (TermVariable) oddVar, true); + + final Term even = SmtUtils.mul(mScript, Rational.valueOf(BigInteger.TWO, BigInteger.ONE), evenVar); + + final Term odd = SmtUtils.sum(mScript, SmtSortUtils.getIntSort(mScript), + SmtUtils.mul(mScript, Rational.valueOf(BigInteger.TWO, BigInteger.ONE), oddVar), + SmtUtils.rational2Term(mScript, Rational.ONE, SmtSortUtils.getIntSort(mScript))); + + final Term constraintEvenLHS = + SmtUtils.not(mScript, SmtUtils.binaryBooleanEquality(mScript, divisionLHS, even)); + final Term constraintOddLHS = SmtUtils.binaryBooleanEquality(mScript, divisionLHS, odd); + final Term constraintEvenRHS = + SmtUtils.not(mScript, SmtUtils.binaryBooleanEquality(mScript, divisionRHS, even)); + final Term constraintOddRHS = SmtUtils.binaryBooleanEquality(mScript, divisionRHS, odd); + final Term constraintEvenINTAND = + SmtUtils.not(mScript, SmtUtils.binaryBooleanEquality(mScript, divisionmIntand, even)); + final Term constraintOddINTAND = SmtUtils.binaryBooleanEquality(mScript, divisionmIntand, odd); + + mBvandConstraintSet.add(SmtUtils.binaryBooleanEquality(mScript, + SmtUtils.and(mScript, constraintOddLHS, constraintOddRHS), constraintOddINTAND)); + + mBvandConstraintSet.add(SmtUtils.binaryBooleanEquality(mScript, + SmtUtils.and(mScript, constraintEvenLHS, constraintEvenRHS), constraintEvenINTAND)); + } + + } + public Term bvandSUMforReplacement(final int width, final Term translatedLHS, final Term translatedRHS) { final Sort intSort = SmtSortUtils.getIntSort(mScript); final BigInteger two = BigInteger.valueOf(2); diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationManager.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationManager.java index 2c3216eb3ec..ed0c239d92d 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationManager.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/TranslationManager.java @@ -66,7 +66,7 @@ public TranslationManager(final ManagedScript mgdscript, final ConstraintsForBit mReversedVarMap = new LinkedHashMap<>(); mConstraintSet = new HashSet<>(); - mTc = new TranslationConstrainer(mMgdScript, cfbo); + mTc = new TranslationConstrainer(mMgdScript, ConstraintsForBitwiseOperations.MAX); mIntand = mTc.getIntAndFunctionSymbol(); mNutzTransformation = useNutzTransformation; @@ -102,11 +102,12 @@ public Triple, Boolean> translateBvtoInt(final Term bitv } - public Triple, Boolean> translateBvtoIntTransferrer(final Term bitvecFromula, final Script scriptBV, final Script scriptINT) { + public Triple, Boolean> translateBvtoIntTransferrer(final Term bitvecFromula, final Script scriptBV, + final Script scriptINT) { mConstraintSet = new HashSet<>(); final TranslationConstrainer tc = new TranslationConstrainer(mMgdScript, mCfo); - final BvToIntTransferrer bvToInt = - new BvToIntTransferrer(scriptBV, scriptINT, mMgdScript, mVariableMap, tc, bitvecFromula.getFreeVars(), mNutzTransformation); + final BvToIntTransferrer bvToInt = new BvToIntTransferrer(scriptBV, scriptINT, mMgdScript, mVariableMap, tc, + bitvecFromula.getFreeVars(), mNutzTransformation); final Term integerFormulaNoConstraint; try { integerFormulaNoConstraint = bvToInt.transform(bitvecFromula); @@ -120,7 +121,7 @@ public Triple, Boolean> translateBvtoIntTransferrer(final Term b if (!mNutzTransformation) { mConstraintSet.addAll(tc.getConstraints()); mConstraintSet.addAll(bvToInt.mArraySelectConstraintMap.values()); - }else { + } else { mConstraintSet.addAll(tc.getBvandConstraints()); } if (!mConstraintSet.isEmpty() && !SmtSortUtils.isBoolSort(integerFormulaNoConstraint.getSort())) { @@ -133,7 +134,6 @@ public Triple, Boolean> translateBvtoIntTransferrer(final Term b } - /* * Method to translate from integer back to bit-vector requires mReversedVarMap to be filled returns the translation * result diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index e3425852579..965b323cd28 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -178,6 +178,7 @@ public void addValueAssignment(final Term value, final int position, final Strin } + // TODO singed bit not considered in value bounds!!! private void addToLinkedList64Bit(final Integer index, final Term valueTerm, final String type) { need64Bit = false; if (values64Bit.size() <= index) { @@ -201,7 +202,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { // wenn 2147483648 dann -2,147,483,648 - final BigInteger newValue = new BigInteger("-9223372036854775808") + final BigInteger newValue = new BigInteger("-9223372036854775807") .add((value.subtract(new BigInteger("9223372036854775808")))); valueInRange = String.valueOf(newValue); @@ -228,7 +229,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin if (value.compareTo(new BigInteger("32767")) == 1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-32768")) == -1) { + } else if (value.compareTo(new BigInteger("-32767")) == -1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue.negate()); } @@ -245,7 +246,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin if (value.compareTo(new BigInteger("2147483647")) == 1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + } else if (value.compareTo(new BigInteger("-2147483647")) == -1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue.negate()); } @@ -255,7 +256,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin if (value.compareTo(new BigInteger("9223372036854775807")) == 1) { final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-9223372036854775808")) == -1) { + } else if (value.compareTo(new BigInteger("-9223372036854775807")) == -1) { final BigInteger newValue = value.mod(new BigInteger("9223372036854775808")); valueInRange = String.valueOf(newValue.negate()); } @@ -280,7 +281,7 @@ private void addToLinkedList64Bit(final Integer index, final Term valueTerm, fin if (value.compareTo(new BigInteger("127")) == 1) { final BigInteger newValue = value.mod(new BigInteger("128")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-128")) == -1) { + } else if (value.compareTo(new BigInteger("-127")) == -1) { final BigInteger newValue = value.mod(new BigInteger("128")); valueInRange = String.valueOf(newValue.negate()); } @@ -399,9 +400,9 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 32) { final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("2147483647")) == 1) { - // wenn 2147483648 dann -2,147,483,648 + // wenn 2147483648 dann -2,147,483,647 final BigInteger newValue = - new BigInteger("-2147483648").add((value.subtract(new BigInteger("2147483648")))); + new BigInteger("-2147483647").add((value.subtract(new BigInteger("2147483648")))); valueInRange = String.valueOf(newValue); } } else { @@ -410,13 +411,13 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } else if (type.equals("char")) { final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("32767")) == 1) { - final BigInteger newValue = new BigInteger("-32768").add((value.subtract(new BigInteger("32768")))); + final BigInteger newValue = new BigInteger("-32767").add((value.subtract(new BigInteger("32768")))); valueInRange = String.valueOf(newValue); } } else if (type.equals("short")) { final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("127")) == 1) { - final BigInteger newValue = new BigInteger("-128").add((value.subtract(new BigInteger("128")))); + final BigInteger newValue = new BigInteger("-127").add((value.subtract(new BigInteger("128")))); valueInRange = String.valueOf(newValue); } } else if (type.equals("bool")) { @@ -444,7 +445,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (type.equals("long")) { if (value.compareTo(new BigInteger("2147483647")) == 1) { need64Bit = true; - } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + } else if (value.compareTo(new BigInteger("-2147483647")) == -1) { need64Bit = true; } } else if (type.equals("ulong")) { @@ -469,7 +470,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("32767")) == 1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-32768")) == -1) { + } else if (value.compareTo(new BigInteger("-32767")) == -1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue.negate()); } @@ -487,7 +488,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("2147483647")) == 1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { + } else if (value.compareTo(new BigInteger("-2147483647")) == -1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue.negate()); } @@ -508,7 +509,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("127")) == 1) { final BigInteger newValue = value.mod(new BigInteger("128")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-128")) == -1) { + } else if (value.compareTo(new BigInteger("-127")) == -1) { final BigInteger newValue = value.mod(new BigInteger("128")); valueInRange = String.valueOf(newValue.negate()); } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java index e880a5e6a08..080e1d3247a 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/TestGenerationResult.java @@ -5,9 +5,11 @@ public class TestGenerationResult implements IResult { protected final String mPlugin; + boolean mUnproven = false; - public TestGenerationResult(final String plugin) { + public TestGenerationResult(final String plugin, final boolean unproven) { mPlugin = plugin; + mUnproven = unproven; } @Override @@ -17,11 +19,17 @@ public final String getPlugin() { @Override public String getShortDescription() { + if (mUnproven) { + return "Unproven - TestGeneration"; + } return "TestGeneration"; } @Override public String getLongDescription() { + if (mUnproven) { + return "Unproven - TestGeneration"; + } return "TestGeneration"; } } \ No newline at end of file diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index 7b6fbef7aed..58d5e6a399b 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -163,10 +163,11 @@ private void reportPositiveResult(final IcfgLocation errorLoc) { private void reportTestGenerationResult(final IcfgLocation errorLoc, final IProgramExecution pe) { final List upreasons = UnprovabilityReason.getUnprovabilityReasons(pe); if (!upreasons.isEmpty()) { - reportUnproveableResult(errorLoc, pe, upreasons); + final IResult cexResult = new TestGenerationResult(mPluginName, true); + mReportFunction.accept(errorLoc, cexResult); return; } - final IResult cexResult = new TestGenerationResult(mPluginName); + final IResult cexResult = new TestGenerationResult(mPluginName, false); mReportFunction.accept(errorLoc, cexResult); } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 1e41da25dd4..208a07e4397 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -360,6 +360,11 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro return; } mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); + getIDsOfTestGoalsInTrace(); + CegarLoopIterations += 1; + } + + private void getIDsOfTestGoalsInTrace() { final List a = mCounterexample.getStateSequence(); mTestGoalsInCurrentTrace.clear(); for (int i = 0; i < a.size(); i++) { @@ -372,7 +377,6 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro } } } - CegarLoopIterations += 1; } private void writeEvalRowLongTrace() { @@ -424,6 +428,7 @@ private void writeEvalRow(final long estimatedTime, final double mLongTraceTime2 } + // TODO coverage calculation is wrong, different from testcov private String readEvalCoverage() { final StringBuilder resultStringBuilder = new StringBuilder(); String fileCOntentWithoutLastLine = ""; @@ -549,7 +554,7 @@ protected boolean refineAbstraction() throws AutomataLibraryException { subtrahendBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); subtrahend = mErrorGeneralizationEngine.getResultAfterEnhancement(); if (!mTestGeneration.equals(TestGenerationMode.None)) { - testGenerationCoverage(); + // testGenerationCoverage(); } } else { automatonType = AutomatonType.FLOYD_HOARE; From 9094e2d2048355584faf471ae6fabe6370a39b2b Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 3 Mar 2024 12:18:43 +0100 Subject: [PATCH 050/278] just do mod if signed c type --- .../singletracecheck/TestExporter.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 965b323cd28..9cd795d5fbe 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -397,27 +397,27 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St m.find(); valueInRange = m.group(1); if (type.equals("int") || type.equals("long")) { // if signed + final BigInteger value = new BigInteger(valueInRange); + if (value.compareTo(new BigInteger("2147483647")) == 1) { + // wenn 2147483648 dann -2,147,483,648 + final BigInteger newValue = + new BigInteger("-2147483648").add((value.subtract(new BigInteger("2147483648")))); + valueInRange = String.valueOf(newValue); + } if (SmtSortUtils.getBitvectorLength(valueTerm.getSort()) <= 32) { - final BigInteger value = new BigInteger(valueInRange); - if (value.compareTo(new BigInteger("2147483647")) == 1) { - // wenn 2147483648 dann -2,147,483,647 - final BigInteger newValue = - new BigInteger("-2147483647").add((value.subtract(new BigInteger("2147483648")))); - valueInRange = String.valueOf(newValue); - } } else { need64Bit = true; } } else if (type.equals("char")) { final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("32767")) == 1) { - final BigInteger newValue = new BigInteger("-32767").add((value.subtract(new BigInteger("32768")))); + final BigInteger newValue = new BigInteger("-32768").add((value.subtract(new BigInteger("32768")))); valueInRange = String.valueOf(newValue); } } else if (type.equals("short")) { final BigInteger value = new BigInteger(valueInRange); if (value.compareTo(new BigInteger("127")) == 1) { - final BigInteger newValue = new BigInteger("-127").add((value.subtract(new BigInteger("128")))); + final BigInteger newValue = new BigInteger("-128").add((value.subtract(new BigInteger("128")))); valueInRange = String.valueOf(newValue); } } else if (type.equals("bool")) { @@ -445,7 +445,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (type.equals("long")) { if (value.compareTo(new BigInteger("2147483647")) == 1) { need64Bit = true; - } else if (value.compareTo(new BigInteger("-2147483647")) == -1) { + } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { need64Bit = true; } } else if (type.equals("ulong")) { @@ -470,9 +470,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("32767")) == 1) { final BigInteger newValue = value.mod(new BigInteger("32768")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-32767")) == -1) { + } else if (value.compareTo(new BigInteger("-32768")) == -1) { final BigInteger newValue = value.mod(new BigInteger("32768")); - valueInRange = String.valueOf(newValue.negate()); + // valueInRange = String.valueOf(newValue.negate()); + valueInRange = String.valueOf(newValue); } break; } @@ -488,9 +489,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("2147483647")) == 1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-2147483647")) == -1) { + } else if (value.compareTo(new BigInteger("-2147483648")) == -1) { final BigInteger newValue = value.mod(new BigInteger("2147483648")); - valueInRange = String.valueOf(newValue.negate()); + // valueInRange = String.valueOf(newValue.negate()); + valueInRange = String.valueOf(newValue); } break; } @@ -509,9 +511,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St if (value.compareTo(new BigInteger("127")) == 1) { final BigInteger newValue = value.mod(new BigInteger("128")); valueInRange = String.valueOf(newValue); - } else if (value.compareTo(new BigInteger("-127")) == -1) { + } else if (value.compareTo(new BigInteger("-128")) == -1) { final BigInteger newValue = value.mod(new BigInteger("128")); - valueInRange = String.valueOf(newValue.negate()); + // valueInRange = String.valueOf(newValue.negate()); + valueInRange = String.valueOf(newValue); } break; } From 75bcaedcdf4527a7a6e8cc30e3627c37289fc958 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 14 Mar 2024 15:21:18 +0100 Subject: [PATCH 051/278] Test Generation: Added support for ONE_CEGAR_PER_ERROR_LOCATION and Timelimit --- .../informatik/ultimate/core/lib/results/ResultUtil.java | 9 +++++++++ .../traceabstraction/CegarLoopResultReporter.java | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/ResultUtil.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/ResultUtil.java index 5537f5718e4..44cfc4c7bd4 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/ResultUtil.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/results/ResultUtil.java @@ -254,6 +254,15 @@ public static IResult combineLocationResults(final IResult oldResult, final IRes || oldResult instanceof UnprovableResult) { return oldResult; } + if (oldResult instanceof TestGenerationResult || newResult instanceof TestGenerationResult) { + if (newResult instanceof PositiveResult) { + return newResult; + } + if (oldResult instanceof PositiveResult) { + return oldResult; + } + return newResult; + } assert oldResult instanceof PositiveResult : "Unsupported location-specific result: " + oldResult; return newResult; } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java index 58d5e6a399b..309e830d59e 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopResultReporter.java @@ -163,8 +163,9 @@ private void reportPositiveResult(final IcfgLocation errorLoc) { private void reportTestGenerationResult(final IcfgLocation errorLoc, final IProgramExecution pe) { final List upreasons = UnprovabilityReason.getUnprovabilityReasons(pe); if (!upreasons.isEmpty()) { - final IResult cexResult = new TestGenerationResult(mPluginName, true); - mReportFunction.accept(errorLoc, cexResult); + // final IResult cexResult = new TestGenerationResult(mPluginName, true); + // mReportFunction.accept(errorLoc, cexResult); + reportUnproveableResult(errorLoc, pe, upreasons); return; } final IResult cexResult = new TestGenerationResult(mPluginName, false); From 79b32922a31dc7ba661ab9d51e98bb1636721cef Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 26 Mar 2024 16:43:52 +0100 Subject: [PATCH 052/278] Reuse when Unsat solang kein function call im Trace ist --- .../singletracecheck/AnnotateAndAsserter.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index f773519166b..41b9ce13af0 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -52,6 +52,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -88,6 +89,7 @@ public class AnnotateAndAsserter { private String mTestCaseUniqueIdentifier = "0"; private final Integer mHighestVaOrderInTrace = -1; private boolean lastVaInTraceIsUsedForReuse = false; + private boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); final TestGenReuseMode mTestGenReuseMode; @@ -105,7 +107,6 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); - System.out.println(mTestGenReuseMode); } public void buildAnnotatedSsaAndAssertTerms() { @@ -173,6 +174,7 @@ public void buildAnnotatedSsaAndAssertTerms() { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; + System.out.println("Using Default to reuse since this is the first testgoal in the trace"); } if (nondetsInTrace.isEmpty() || mCurrentVA == null) { @@ -191,7 +193,8 @@ public void buildAnnotatedSsaAndAssertTerms() { // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); // mMgdScriptTc.getScript().push(1); // mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - // System.out.println("Negated REUSE: " + varAssignmentConjunction); + System.out.println( + "Va was already succesfully reused or No Nondets In Trace" + varAssignmentConjunction); reuse = false; } else { mMgdScriptTc.getScript().push(1); @@ -199,12 +202,15 @@ public void buildAnnotatedSsaAndAssertTerms() { System.out.println("REUSE: " + varAssignmentConjunction); } } else { + System.out.println("TODO previous test goal behind the current?"); reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. } } mSatisfiable = mMgdScriptTc.getScript().checkSat(); - + if (reuse) { + System.out.println("trying to reuse"); + } if (mSatisfiable == LBool.UNSAT) { if (reuse) { System.out.println("REUSE UNSAT"); @@ -387,6 +393,7 @@ public NestedFormulas getAnnotatedSsa() { private void checkTraceForVAandNONDETS() { mTestCaseUniqueIdentifier = mTestCaseUniqueIdentifier + mSSA.getTrace().hashCode(); mTestCaseUniqueIdentifier += mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1).hashCode(); + int callcount = 0; if (mSSA.getTrace().length() - 1 > 0) { for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { @@ -432,18 +439,19 @@ private void checkTraceForVAandNONDETS() { .get(VarAssignmentReuseAnnotation.class.getName()); if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { mVAforReuse = reuseCandidate; - System.out.println("reuseCandidate: " + statementBranch.getSerialNumber() - + " vaOrderNumber: " + reuseCandidate.mVaOrder); lastVaInTraceIsUsedForReuse = true; } else { - System.out.println("Last INtrace: " + statementBranch.getSerialNumber() - + " vaOrderNumber: " + reuseCandidate.mVaOrder); lastVaInTraceIsUsedForReuse = false; } // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA nondetsInTraceAfterPreviousVA.clear(); } + } else if (mSSA.getTrace().getSymbol(i) instanceof Call) { + callcount += 1; + if (callcount > 2) { // Ultiamte call and main call are ok + reuseUnsatpossible = false; + } } } } @@ -515,22 +523,21 @@ private void getCurrentVA() { if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { mCurrentVA = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); + } System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); } } private void removeCheckIfCovered() { - if ((lastVaInTraceIsUsedForReuse || mVAforReuse.equals(mDefaultVA)) && !mVAforReuse.mNegatedVA) { - if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size()) { - System.out.println("OtherBranchRemoveCheck"); - mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); - } else { - System.out.println("No OtherBranch Optimopti Sizes dont match"); - } + + if (reuseUnsatpossible || mCurrentVA.equals(mDefaultVA)) { + System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); } else { System.out.println("No OtherBranch Optimopti"); } + } } From c7920a5569687ef91847002fc914ce1f9374dd4d Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 26 Mar 2024 16:54:07 +0100 Subject: [PATCH 053/278] Nur reuse, wenn keine function calls in trace --- .../singletracecheck/AnnotateAndAsserter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 41b9ce13af0..433d190335e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -187,7 +187,7 @@ public void buildAnnotatedSsaAndAssertTerms() { reuse = true; final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO - if (!vaPairsAsTerms.isEmpty()) { + if (!vaPairsAsTerms.isEmpty() && reuseUnsatpossible) { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); @@ -202,7 +202,7 @@ public void buildAnnotatedSsaAndAssertTerms() { System.out.println("REUSE: " + varAssignmentConjunction); } } else { - System.out.println("TODO previous test goal behind the current?"); + System.out.println("TODO Experiment nur reusen wenn keine function calls?"); reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. } From d79ea0196c6ca60b4fa6c66f24faec09dda9245d Mon Sep 17 00:00:00 2001 From: Max barth Date: Wed, 27 Mar 2024 15:38:59 +0100 Subject: [PATCH 054/278] Normal Reuse but Reuse when unsat only when no functions calls in trace --- .../tracecheckerutils/singletracecheck/AnnotateAndAsserter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 433d190335e..9445adf5dd9 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -187,7 +187,7 @@ public void buildAnnotatedSsaAndAssertTerms() { reuse = true; final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO - if (!vaPairsAsTerms.isEmpty() && reuseUnsatpossible) { + if (!vaPairsAsTerms.isEmpty()) { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); From 8cc4293eba4564758f53d94e155dece316586f57 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 28 Mar 2024 16:09:16 +0100 Subject: [PATCH 055/278] Only Reuse when Unsat if CurrentVA not in function call other than main --- .../singletracecheck/AnnotateAndAsserter.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 9445adf5dd9..d807bca62cd 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -52,7 +52,6 @@ import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; -import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -393,7 +392,6 @@ public NestedFormulas getAnnotatedSsa() { private void checkTraceForVAandNONDETS() { mTestCaseUniqueIdentifier = mTestCaseUniqueIdentifier + mSSA.getTrace().hashCode(); mTestCaseUniqueIdentifier += mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1).hashCode(); - int callcount = 0; if (mSSA.getTrace().length() - 1 > 0) { for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { @@ -447,11 +445,6 @@ private void checkTraceForVAandNONDETS() { // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA nondetsInTraceAfterPreviousVA.clear(); } - } else if (mSSA.getTrace().getSymbol(i) instanceof Call) { - callcount += 1; - if (callcount > 2) { // Ultiamte call and main call are ok - reuseUnsatpossible = false; - } } } } @@ -517,8 +510,10 @@ private void exportTest(final TestVector testV) { private void getCurrentVA() { final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); - if (lastStmt instanceof StatementSequence) { + if (lastStmt.getPrecedingProcedure().equals("main")) { + reuseUnsatpossible = false; + } final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { mCurrentVA = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() From 24e8eccc71997fb11f7c0b5df9a93bb1643afcd3 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 31 Mar 2024 00:27:28 +0100 Subject: [PATCH 056/278] Second try, reuse only when not in function and reuse unsat only when not in function --- .../singletracecheck/AnnotateAndAsserter.java | 65 ++++++++++++------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index d807bca62cd..ddaf71d6239 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -87,7 +87,7 @@ public class AnnotateAndAsserter { final HashMap nondetNameToType = new HashMap<>(); private String mTestCaseUniqueIdentifier = "0"; private final Integer mHighestVaOrderInTrace = -1; - private boolean lastVaInTraceIsUsedForReuse = false; + private final boolean lastVaInTraceIsUsedForReuse = false; private boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); @@ -184,26 +184,38 @@ public void buildAnnotatedSsaAndAssertTerms() { System.out.println("NO REUSE since UNSAT With"); } else { reuse = true; - final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); // TODO - - if (!vaPairsAsTerms.isEmpty()) { - final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); - if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { - // varAssignmentConjunction = SmtUtils.not(mMgdScriptTc.getScript(), varAssignmentConjunction); - // mMgdScriptTc.getScript().push(1); - // mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println( - "Va was already succesfully reused or No Nondets In Trace" + varAssignmentConjunction); - reuse = false; + final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); + if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { // TODO Test Remove after evaluation + if (!vaPairsAsTerms.isEmpty() && reuseUnsatpossible) { + final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { + reuse = false; + } else { + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); + } } else { - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); + System.out.println("TODO Experiment nur reusen wenn keine function calls?"); + reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) + // In this case previous test goal has not been checked yet. } } else { - System.out.println("TODO Experiment nur reusen wenn keine function calls?"); - reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) - // In this case previous test goal has not been checked yet. + if (!vaPairsAsTerms.isEmpty()) { + final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { + System.out.println("Va was already succesfully reused or No Nondets In Trace" + + varAssignmentConjunction); + reuse = false; + } else { + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); + } + } else { + reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) + // In this case previous test goal has not been checked yet. + } } } mSatisfiable = mMgdScriptTc.getScript().checkSat(); @@ -435,12 +447,17 @@ private void checkTraceForVAandNONDETS() { final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); - if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { - mVAforReuse = reuseCandidate; - lastVaInTraceIsUsedForReuse = true; + + // if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { + mVAforReuse = reuseCandidate; + if (!statementBranch.getPrecedingProcedure().equals("main")) { + reuseUnsatpossible = false; } else { - lastVaInTraceIsUsedForReuse = false; + reuseUnsatpossible = true; } + // } else { + // lastVaInTraceIsUsedForReuse = false; + // } // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA nondetsInTraceAfterPreviousVA.clear(); @@ -511,9 +528,7 @@ private void exportTest(final TestVector testV) { private void getCurrentVA() { final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); if (lastStmt instanceof StatementSequence) { - if (lastStmt.getPrecedingProcedure().equals("main")) { - reuseUnsatpossible = false; - } + final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { mCurrentVA = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() From 5d6c9a8f480083fe5e66d29946061f882e3028a1 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 31 Mar 2024 00:39:01 +0100 Subject: [PATCH 057/278] Reactivated VAOrder, use last checked for reuse --- .../singletracecheck/AnnotateAndAsserter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index ddaf71d6239..5835c16dbbe 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -448,16 +448,16 @@ private void checkTraceForVAandNONDETS() { (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); - // if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { - mVAforReuse = reuseCandidate; - if (!statementBranch.getPrecedingProcedure().equals("main")) { - reuseUnsatpossible = false; + if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { + mVAforReuse = reuseCandidate; + if (!statementBranch.getPrecedingProcedure().equals("main")) { + reuseUnsatpossible = false; + } else { + reuseUnsatpossible = true; + } } else { - reuseUnsatpossible = true; + reuseUnsatpossible = false; } - // } else { - // lastVaInTraceIsUsedForReuse = false; - // } // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA nondetsInTraceAfterPreviousVA.clear(); From a0a24c2a2494565a91b3ac5cef8e153c1ed8c556 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 1 Apr 2024 12:37:43 +0200 Subject: [PATCH 058/278] Fix reuseunsat, readde no reuse if negated --- .../singletracecheck/AnnotateAndAsserter.java | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 5835c16dbbe..0734eb2732a 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -87,7 +87,7 @@ public class AnnotateAndAsserter { final HashMap nondetNameToType = new HashMap<>(); private String mTestCaseUniqueIdentifier = "0"; private final Integer mHighestVaOrderInTrace = -1; - private final boolean lastVaInTraceIsUsedForReuse = false; + private boolean lastVaInTraceIsUsedForReuse = false; private boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); @@ -179,44 +179,24 @@ public void buildAnnotatedSsaAndAssertTerms() { if (nondetsInTrace.isEmpty() || mCurrentVA == null) { System.out.println("NO REUSE"); reuse = false; + } else if (mVAforReuse.mNegatedVA) { + reuse = false; } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { reuse = false; // Wie kann das überhaupt sein? System.out.println("NO REUSE since UNSAT With"); } else { reuse = true; final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); - if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { // TODO Test Remove after evaluation - if (!vaPairsAsTerms.isEmpty() && reuseUnsatpossible) { - final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); - if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { - reuse = false; - } else { - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); - } - } else { - System.out.println("TODO Experiment nur reusen wenn keine function calls?"); - reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) - // In this case previous test goal has not been checked yet. - } + if (!vaPairsAsTerms.isEmpty()) { + final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + System.out.println("REUSE: " + varAssignmentConjunction); } else { - if (!vaPairsAsTerms.isEmpty()) { - final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); - if (mVAforReuse.mNegatedVA == true && !vaPairsAsTerms.isEmpty()) { - System.out.println("Va was already succesfully reused or No Nondets In Trace" - + varAssignmentConjunction); - reuse = false; - } else { - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); - } - } else { - reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) - // In this case previous test goal has not been checked yet. - } + reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) + // In this case previous test goal has not been checked yet. } + } mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (reuse) { @@ -449,13 +429,16 @@ private void checkTraceForVAandNONDETS() { .get(VarAssignmentReuseAnnotation.class.getName()); if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { + mVAforReuse = reuseCandidate; + lastVaInTraceIsUsedForReuse = true; if (!statementBranch.getPrecedingProcedure().equals("main")) { reuseUnsatpossible = false; } else { reuseUnsatpossible = true; } } else { + lastVaInTraceIsUsedForReuse = false; reuseUnsatpossible = false; } @@ -540,14 +523,24 @@ private void getCurrentVA() { } private void removeCheckIfCovered() { - - if (reuseUnsatpossible || mCurrentVA.equals(mDefaultVA)) { + if (!mVAforReuse.mNegatedVA) { + return; + } + if (mVAforReuse.equals(mDefaultVA)) { System.out.println("OtherBranchRemoveCheck"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); - } else { - System.out.println("No OtherBranch Optimopti"); + return; } + if (lastVaInTraceIsUsedForReuse && reuseUnsatpossible) { + // amount of nondets in VA + Between testgoals matches total amount of inputs + if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size()) { + System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); + } + + } } } From 3c24b777921bf9bfffcb303df19218269d3f4448 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 1 Apr 2024 12:47:01 +0200 Subject: [PATCH 059/278] Normal Reuse, only reuse vas annotated to test-goals that are not in a function --- .../singletracecheck/AnnotateAndAsserter.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 0734eb2732a..e79d605974f 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -199,6 +199,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } mSatisfiable = mMgdScriptTc.getScript().checkSat(); + if (reuse) { System.out.println("trying to reuse"); } @@ -429,8 +430,13 @@ private void checkTraceForVAandNONDETS() { .get(VarAssignmentReuseAnnotation.class.getName()); if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { - - mVAforReuse = reuseCandidate; + if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { + if (statementBranch.getPrecedingProcedure().equals("main")) { + mVAforReuse = reuseCandidate; + } + } else { + mVAforReuse = reuseCandidate; + } lastVaInTraceIsUsedForReuse = true; if (!statementBranch.getPrecedingProcedure().equals("main")) { reuseUnsatpossible = false; From 57324c4e760faf5a6052c6e3689137a43b528d64 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 1 Apr 2024 15:31:02 +0200 Subject: [PATCH 060/278] minor fix --- .../tracecheckerutils/singletracecheck/AnnotateAndAsserter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index e79d605974f..7d3b1bc81ae 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -529,7 +529,7 @@ private void getCurrentVA() { } private void removeCheckIfCovered() { - if (!mVAforReuse.mNegatedVA) { + if (mVAforReuse.mNegatedVA) { return; } if (mVAforReuse.equals(mDefaultVA)) { From 6137ec566aff15581c9c117ae87c842b7ce86d02 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 2 Apr 2024 21:12:11 +0200 Subject: [PATCH 061/278] Removed redundant SatCheck --- .../singletracecheck/AnnotateAndAsserter.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 7d3b1bc81ae..6bef2a06fe9 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -185,13 +185,13 @@ public void buildAnnotatedSsaAndAssertTerms() { reuse = false; // Wie kann das überhaupt sein? System.out.println("NO REUSE since UNSAT With"); } else { - reuse = true; final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); if (!vaPairsAsTerms.isEmpty()) { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); mMgdScriptTc.getScript().push(1); mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); System.out.println("REUSE: " + varAssignmentConjunction); + reuse = true; } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. @@ -210,13 +210,11 @@ public void buildAnnotatedSsaAndAssertTerms() { if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { removeCheckIfCovered(); } - mVAforReuse.mNegatedVA = true; - } - // Hier oder vor der IF - mSatisfiable = mMgdScriptTc.getScript().checkSat(); - if (reuse) { + mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = false; + } else { + mVAforReuse.mNegatedVA = true; } } } else if (reuse) { @@ -405,21 +403,8 @@ private void checkTraceForVAandNONDETS() { nondetNameToType.put(symbol.getName(), m.group(1)); } - } else { - System.out.println(symbol + " not in payload"); } - } - - // final String traceTermAsString = mSSA.getFormulaFromNonCallPos(i).toStringDirect(); - // final Pattern pattern = - // Pattern.compile("\\|[^\\|]*nondet\\d[^\\|]*\\|", Pattern.CASE_INSENSITIVE); - // final Matcher matcher = pattern.matcher(traceTermAsString); - // if (matcher.find()) { - // final String match = matcher.group(); - - // } - } // If VA in Trace returns last found VA if (statementBranch.getPayload().getAnnotations() From 7190344e7789ad879751052542fc3052e74e127d Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 4 Apr 2024 07:38:07 +0200 Subject: [PATCH 062/278] Possible Fix for having error automaton but not an active test-goal --- .../singletracecheck/AnnotateAndAsserter.java | 8 +++++++- .../models/annotation/VarAssignmentReuseAnnotation.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 6bef2a06fe9..c4336de0632 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -230,8 +230,11 @@ public void buildAnnotatedSsaAndAssertTerms() { } } else { mSatisfiable = mMgdScriptTc.getScript().checkSat(); - } + } + if (mSatisfiable == LBool.SAT && mCurrentVA != null) { + mCurrentVA.mCoveredTestGoal = true; + } if (mSatisfiable == LBool.UNKNOWN) { System.out.println("UNKNOWN"); } @@ -517,6 +520,9 @@ private void removeCheckIfCovered() { if (mVAforReuse.mNegatedVA) { return; } + if (mCurrentVA.mVAofOppositeBranch.mCoveredTestGoal) { + return; + } if (mVAforReuse.equals(mDefaultVA)) { System.out.println("OtherBranchRemoveCheck"); mCurrentVA.mVAofOppositeBranch.removeCheck(); diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index af00a99151c..1f39433e511 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -19,6 +19,7 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { private static final String KEY = VarAssignmentReuseAnnotation.class.getName(); public boolean secondCheck = false; public boolean mNegatedVA = false; + public boolean mCoveredTestGoal = false; private final Map mMap = new HashMap<>(); public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated, // order corresponds to From 2629c5c6b4c92b6aaa709b965a589db411ca50a8 Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 19 Apr 2024 13:36:42 +0200 Subject: [PATCH 063/278] BvToInt: Fix Unsoundness in SMT-Comp23 --- .../bvinttranslation/BvToIntTransferrer.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/BvToIntTransferrer.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/BvToIntTransferrer.java index cdf46467dfd..ca7f5fbd124 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/BvToIntTransferrer.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/smtlibutils/bvinttranslation/BvToIntTransferrer.java @@ -903,12 +903,12 @@ public void convertApplicationTerm(final ApplicationTerm appTerm, final Term[] a concatCount += 1; final Term multiplication = SmtUtils.unfTerm(mScript, "*", null, SmtSortUtils.getIntSort(mMgdScript), translatedLHS, maxNumber); - if (mNutzTransformation) { - moduloCount += 1; - setResult(SmtUtils.unfTerm(mScript, "+", null, SmtSortUtils.getIntSort(mMgdScript), - multiplication, SmtUtils.mod(mScript, translatedRHS, maxNumber))); - return; - } + // if (mNutzTransformation) { + // moduloCount += 1; + // setResult(SmtUtils.unfTerm(mScript, "+", null, SmtSortUtils.getIntSort(mMgdScript), + // multiplication, SmtUtils.mod(mScript, translatedRHS, maxNumber))); + // return; + // } setResult(SmtUtils.unfTerm(mScript, "+", null, SmtSortUtils.getIntSort(mMgdScript), multiplication, translatedRHS)); return; @@ -1005,7 +1005,8 @@ private Term translateBvudiv(final Term translatedLHS, final Term translatedRHS, SmtUtils.rational2Term(mScript, Rational.ZERO, intSort)); final Term thenTerm = SmtUtils.unfTerm(mScript, "-", null, SmtSortUtils.getIntSort(mMgdScript), maxNumber, SmtUtils.rational2Term(mScript, Rational.ONE, intSort)); - final Term elseTerm = SmtUtils.unfTerm(mScript, "div", null, SmtSortUtils.getIntSort(mMgdScript), lhs, rhs); + final Term elseTerm = SmtUtils.unfTerm(mScript, "div", null, SmtSortUtils.getIntSort(mMgdScript), translatedLHS, + translatedRHS); return SmtUtils.ite(mScript, ifTerm, thenTerm, elseTerm); } @@ -1029,13 +1030,13 @@ private Term translateBvurem(final Term translatedLHS, final Term translatedRHS, return SmtUtils.ite(mScript, ifTerm, thenTerm, elseTerm); } - private Term translateBvshl(Term translatedLHS, Term translatedRHS, final int width, final Term maxNumber) { + private Term translateBvshl(final Term translatedLHS, Term translatedRHS, final int width, final Term maxNumber) { final Sort intSort = SmtSortUtils.getIntSort(mScript); if (mNutzTransformation) { moduloCount += 2; translatedRHS = SmtUtils.mod(mScript, translatedRHS, maxNumber); - translatedLHS = SmtUtils.mod(mScript, translatedLHS, maxNumber); + // translatedLHS = SmtUtils.mod(mScript, translatedLHS, maxNumber); } if (translatedRHS instanceof ConstantTerm) { final Term shift = SmtUtils.unfTerm(mScript, "*", null, SmtSortUtils.getIntSort(mMgdScript), translatedLHS, @@ -1077,13 +1078,13 @@ private Term translateBvshl(Term translatedLHS, Term translatedRHS, final int wi } } - private Term translateBvlshr(Term translatedLHS, Term translatedRHS, final int width, final Term maxNumber) { + private Term translateBvlshr(final Term translatedLHS, Term translatedRHS, final int width, final Term maxNumber) { final Sort intSort = SmtSortUtils.getIntSort(mScript); if (mNutzTransformation) { moduloCount += 1; translatedRHS = SmtUtils.mod(mScript, translatedRHS, maxNumber); - translatedLHS = SmtUtils.mod(mScript, translatedLHS, maxNumber); + // translatedLHS = SmtUtils.mod(mScript, translatedLHS, maxNumber); } if (translatedRHS instanceof ConstantTerm) { @@ -1131,7 +1132,8 @@ private Term translateRelations(final ApplicationTerm appTerm, final FunctionSym } } - if (mNutzTransformation && SmtSortUtils.isArraySort(appTerm.getParameters()[0].getSort())) { + // This caused the unsoundness in SMTComp23 + if (false && mNutzTransformation && SmtSortUtils.isArraySort(appTerm.getParameters()[0].getSort())) { if (SmtSortUtils.isBitvecSort(appTerm.getParameters()[0].getSort().getArguments()[1])) { final TermVariable quantifiedVar = From 679dd153d745748ad10606106e4c27cf86f57f2a Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 22 Apr 2024 22:11:54 +0200 Subject: [PATCH 064/278] Instead of removing covered test goals from the A* goal set, we add them to the error automaton --- .../traceabstraction/NwaCegarLoop.java | 53 +++++++------------ .../ErrorGeneralizationEngine.java | 9 ++++ .../SimpleErrorAutomatonBuilder.java | 18 ++++++- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 208a07e4397..30b3ed640ca 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -298,41 +298,10 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) .getNestedRun(); } - } else if (mUseHeuristicEmptinessCheck) { - mCounterexample = new IsEmptyHeuristic<>(new AutomataLibraryServices(getServices()), abstraction, - IHeuristic.getHeuristic(mAStarHeuristic, mScoringMethod, mAStarRandomHeuristicSeed)) - .getNestedRun(); - - assert checkIsEmptyHeuristic(abstraction) : "IsEmptyHeuristic did not match IsEmpty"; } else { - if (mTestGeneration.equals(TestGenerationMode.Standard)) { - mLogger.info( - "TestGen, Time spent Search-MultiGoal Preprocess: " + mLongTraceTime / 1000000000 + "s"); - mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); - - final Set newGoalSet = new HashSet<>(); - newGoalSet.addAll(mAbstraction.getFinalStates()); - for (final IPredicate testGoal : mAbstraction.getFinalStates()) { - final ISLPredicate testGoalISL = (ISLPredicate) testGoal; - if (testGoalISL.getProgramPoint().getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - final VarAssignmentReuseAnnotation pLocAnno = - (VarAssignmentReuseAnnotation) testGoalISL.getProgramPoint().getPayload() - .getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - - if (!pLocAnno.mIsActiveTestGoal) { - newGoalSet.remove(testGoal); - } - } - - } - mCounterexample = runWithModifiedGoalSet(mAbstraction, newGoalSet); - } else { - - mCounterexample = - new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) - .getNestedRun(); - } + mCounterexample = + new IsEmpty<>(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) + .getNestedRun(); } } finally { if (mWriteEvaluationToFile) { @@ -522,6 +491,22 @@ protected void constructErrorAutomaton() throws AutomataOperationCanceledExcepti mIcfg.getCfgSmtToolkit().getSymbolTable(), mPredicateFactoryInterpolantAutomata, mAbstraction, mIteration); mInterpolAutomaton = null; + System.out.println(mAbstraction.getFinalStates().size()); + for (final IPredicate testGoal : mAbstraction.getFinalStates()) { + final ISLPredicate testGoalISL = (ISLPredicate) testGoal; + if (testGoalISL.getProgramPoint().getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation pLocAnno = + (VarAssignmentReuseAnnotation) testGoalISL.getProgramPoint().getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + if (!pLocAnno.mIsActiveTestGoal) { + mErrorGeneralizationEngine.addCoveredTestGoalToErrorAutomaton(testGoal, + mAbstraction.internalPredecessors(testGoal)); + } + } + + } + final NestedWordAutomaton resultBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); assert isInterpolantAutomatonOfSingleStateType(resultBeforeEnhancement); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java index ba780af3b0b..6700cf343bb 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/ErrorGeneralizationEngine.java @@ -44,6 +44,7 @@ import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWordAutomaton; import de.uni_freiburg.informatik.ultimate.automata.nestedword.VpAlphabet; +import de.uni_freiburg.informatik.ultimate.automata.nestedword.transitions.IncomingInternalTransition; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.RunningTaskInfo; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.results.StatisticsResult; @@ -457,4 +458,12 @@ private void presentResult(final Map> finalLoc2responsibleS mLogger.warn(builder); } } + + public void addCoveredTestGoalToErrorAutomaton(final IPredicate testGoal, + final Iterable> incomingedge) { + assert mErrorAutomatonBuilder instanceof SimpleErrorAutomatonBuilder; + ((SimpleErrorAutomatonBuilder) mErrorAutomatonBuilder).addCoveredTestGoalToErrorAutomaton(testGoal, + incomingedge); + + } } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java index f50764a54fb..e00274ff93c 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/errorabstraction/SimpleErrorAutomatonBuilder.java @@ -37,6 +37,7 @@ import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWordAutomataUtils; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWordAutomaton; import de.uni_freiburg.informatik.ultimate.automata.nestedword.VpAlphabet; +import de.uni_freiburg.informatik.ultimate.automata.nestedword.transitions.IncomingInternalTransition; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.TestGoalAnnotation; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; @@ -129,12 +130,25 @@ private void addCoveredTestGoalsToErrorAutomaton(final NestedWord trace, fina mResult.addInternalTransition(f, letter, errorStateAsBP); break; } - } - } } + } + } + + public void addCoveredTestGoalToErrorAutomaton(final IPredicate testGoal, + final Iterable> incomingedge) { + + final BasicPredicate errorStateAsBP = + new BasicPredicate(mResult.size(), null, testGoal.getFormula(), null, null, null); + mResult.addState(false, true, errorStateAsBP); + + for (final Iterator it = mResult.getInitialStates().iterator(); it.hasNext();) { + final IPredicate f = it.next(); + final L letter = incomingedge.iterator().next().getLetter(); + mResult.addInternalTransition(f, letter, errorStateAsBP); + break; } } From ef07720049810bd177ff3c58456ae401e8b562e0 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 30 Apr 2024 11:23:09 +0200 Subject: [PATCH 065/278] Make ReuseUnsat dependend on procedures calling location --- .../singletracecheck/AnnotateAndAsserter.java | 212 ++++++++++-------- .../singletracecheck/TraceCheck.java | 40 ++-- .../VarAssignmentReuseAnnotation.java | 9 +- 3 files changed, 146 insertions(+), 115 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index c4336de0632..c1f6cdd5c87 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -52,6 +52,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -85,9 +86,10 @@ public class AnnotateAndAsserter { final LinkedHashSet nondetsInTrace = new LinkedHashSet(); final LinkedHashSet nondetsInTraceAfterPreviousVA = new LinkedHashSet(); final HashMap nondetNameToType = new HashMap<>(); - private String mTestCaseUniqueIdentifier = "0"; + + final HashMap procedureToCallLoc = new HashMap<>(); + private final Integer mHighestVaOrderInTrace = -1; - private boolean lastVaInTraceIsUsedForReuse = false; private boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); @@ -130,12 +132,23 @@ public void buildAnnotatedSsaAndAssertTerms() { mAnnotateAndAssertCodeBlocks.annotateAndAssertLocalVarAssignemntCall(i)); mAnnotSSA.setOldVarAssignmentAtPos(i, mAnnotateAndAssertCodeBlocks.annotateAndAssertOldVarAssignemntCall(i)); + } else { if (mTrace.isReturnPosition(i) && mTrace.isPendingReturn(i)) { pendingReturnPositions.add(i); } mAnnotSSA.setFormulaAtNonCallPos(i, mAnnotateAndAssertCodeBlocks.annotateAndAssertNonCall(i)); } + if (mTrace.getSymbol(i) instanceof Call) { + final Call call = (Call) mTrace.getSymbol(i); + if (procedureToCallLoc.containsKey(call.getSucceedingProcedure())) { + procedureToCallLoc.remove(call.getSucceedingProcedure()); + } + procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); + } + if (i < mTrace.length() - 1) { + getVAandNONDETS(i); + } } assert callPositions.containsAll(mTrace.getCallPositions()); @@ -168,7 +181,6 @@ public void buildAnnotatedSsaAndAssertTerms() { if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { boolean reuse; getCurrentVA(); - checkTraceForVAandNONDETS(); if (mCurrentVA != null && mVAforReuse == null) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); @@ -185,7 +197,15 @@ public void buildAnnotatedSsaAndAssertTerms() { reuse = false; // Wie kann das überhaupt sein? System.out.println("NO REUSE since UNSAT With"); } else { - final ArrayList vaPairsAsTerms = checkIfNondetsOfTraceAreInVA(); + ArrayList vaPairsAsTerms; + if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { + vaPairsAsTerms = getNonDetsAsTermsReuse(); + } else if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + vaPairsAsTerms = getNonDetsAsTermsReuseUNSAT(); + } else { + throw new AssertionError("unexpected Reuse Mode"); + } + if (!vaPairsAsTerms.isEmpty()) { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); mMgdScriptTc.getScript().push(1); @@ -252,7 +272,6 @@ private Term createTermFromVA(final String variableAsString, final Term value) { if (varInCurrentScript == null) { varInCurrentScript = mMgdScriptTc.getScript().getTheory() .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); - System.out.println(variableAsString); } if (varInCurrentScript == null) { @@ -379,78 +398,82 @@ public NestedFormulas getAnnotatedSsa() { return mAnnotSSA; } - /* - * Iterates over trace and returns last VA and all Nondets in trace - * TODO if not ReuseUNSAT mode, we dont really need to know which nondets are in trace - */ - private void checkTraceForVAandNONDETS() { - mTestCaseUniqueIdentifier = mTestCaseUniqueIdentifier + mSSA.getTrace().hashCode(); - mTestCaseUniqueIdentifier += mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1).hashCode(); - if (mSSA.getTrace().length() - 1 > 0) { - for (int i = 0; i < mSSA.getTrace().length() - 1; i++) { // dont check current testgoal for va - if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { - final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - - if (statementBranch.toString().contains("nondet")) { - - final Set nonTheorySymbolsInTerm = - SmtUtils.extractNonTheoryFunctionSymbols(mSSA.getFormulaFromValidNonCallPos(i)); - - for (final FunctionSymbol symbol : nonTheorySymbolsInTerm) { - final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)") - .matcher(statementBranch.getPayload().toString()); - if (m.find()) { - if (symbol.getName().contains("nondet")) { - nondetsInTrace.add(symbol.getName()); - nondetsInTraceAfterPreviousVA.add(symbol.getName()); - nondetNameToType.put(symbol.getName(), m.group(1)); - - } - } - } - } - // If VA in Trace returns last found VA - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - - final VarAssignmentReuseAnnotation reuseCandidate = - (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() - .get(VarAssignmentReuseAnnotation.class.getName()); - - if (mVAforReuse == null || reuseCandidate.mVaOrder >= mVAforReuse.mVaOrder) { - if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { - if (statementBranch.getPrecedingProcedure().equals("main")) { - mVAforReuse = reuseCandidate; - } - } else { - mVAforReuse = reuseCandidate; - } - lastVaInTraceIsUsedForReuse = true; - if (!statementBranch.getPrecedingProcedure().equals("main")) { - reuseUnsatpossible = false; - } else { - reuseUnsatpossible = true; - } - } else { - lastVaInTraceIsUsedForReuse = false; - reuseUnsatpossible = false; - } + private String getUniqueIdentifierForTestCaseName() { + String identifier = "UnsatReuse" + mSSA.getTrace().hashCode(); + identifier += mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1).hashCode(); + return identifier; + } + + private void getVAandNONDETS(final int i) { + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + + ifStatementHasNondetAddToSet(i, statementBranch); + // If VA in Trace returns last found VA + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + + final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA - nondetsInTraceAfterPreviousVA.clear(); + mVAforReuse = reuseCandidate; + final String precedingProc = statementBranch.getPrecedingProcedure(); + // Check if annotated test-goal and current test-goal are in the same procedure + if (mVAforReuse.getPrecedingProcedure().equals(precedingProc) + && mVAforReuse.mLocationOfPrecedingProcedure.equals(procedureToCallLoc.get(precedingProc))) { + reuseUnsatpossible = true; + } else { + reuseUnsatpossible = false; + } + + // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA + nondetsInTraceAfterPreviousVA.clear(); + } + } + } + + private void ifStatementHasNondetAddToSet(final int i, final StatementSequence statementBranch) { + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (statementBranch.toString().contains("nondet")) { + final Set nonTheorySymbolsInTerm = + SmtUtils.extractNonTheoryFunctionSymbols(mSSA.getFormulaFromValidNonCallPos(i)); + + for (final FunctionSymbol symbol : nonTheorySymbolsInTerm) { + final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)") + .matcher(statementBranch.getPayload().toString()); + if (m.find()) { + if (symbol.getName().contains("nondet")) { + nondetsInTrace.add(symbol.getName()); + nondetsInTraceAfterPreviousVA.add(symbol.getName()); + nondetNameToType.put(symbol.getName(), m.group(1)); + } } } } } } - /* - * Checks wheter a nondet from the trace is in the VA or not. - * IF it is included it is in the first array list and otherwise in the second of PAIR - */ - private ArrayList checkIfNondetsOfTraceAreInVA() { + private ArrayList getNonDetsAsTermsReuse() { + assert mTestGenReuseMode.equals(TestGenReuseMode.Reuse); + final ArrayList nondetsAsTerms = new ArrayList(); + final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; + for (int i = 0; i < varAssignmentPairs.size(); i++) { // TODO optimize in one loop over all nondets in trace + // This "nondet" in Trace is in the VA + final String nondetInVA = varAssignmentPairs.get(i).getFirst().toStringDirect(); + if (nondetsInTrace.contains(nondetInVA)) { + final Term value = varAssignmentPairs.get(i).getSecond(); + final Term reuseVaTerm = createTermFromVA(varAssignmentPairs.get(i).getFirst().toStringDirect(), value); + nondetsAsTerms.add(reuseVaTerm); + } + } + return nondetsAsTerms; + } + + private ArrayList getNonDetsAsTermsReuseUNSAT() { + assert mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT); + final ArrayList nondetsAsTerms = new ArrayList(); final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; - final ArrayList nondetInVA = new ArrayList(); + boolean inputBetweenTestGoals = false; int nondetPositionCount = 0; final TestVector testV = new TestVector(); @@ -465,36 +488,36 @@ private ArrayList checkIfNondetsOfTraceAreInVA() { value = varAssignmentPairs.get(i).getSecond(); final Term reuseVaTerm = createTermFromVA(varAssignmentPairs.get(i).getFirst().toStringDirect(), value); - nondetInVA.add(reuseVaTerm); + nondetsAsTerms.add(reuseVaTerm); break; } } - if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { - if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { - // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! - - System.out.println("ALARM: " + nondet + " not in VA"); - inputBetweenTestGoals = true; - value = null; // null will be used as value zero - final Term reuseVaTerm = createTermFromVA(nondet, value); - nondetInVA.add(reuseVaTerm); - } - - testV.addValueAssignment(value, nondetPositionCount, nondetNameToType.get(nondet)); - // increase at the end of loop - nondetPositionCount += 1; + if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { + // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! + + System.out.println("ALARM: " + nondet + " not in VA"); + inputBetweenTestGoals = true; + value = null; // null will be used as value zero + final Term reuseVaTerm = createTermFromVA(nondet, value); + nondetsAsTerms.add(reuseVaTerm); } + + testV.addValueAssignment(value, nondetPositionCount, nondetNameToType.get(nondet)); + // increase at the end of loop + nondetPositionCount += 1; } - if (inputBetweenTestGoals && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (inputBetweenTestGoals) { exportTest(testV); } - return nondetInVA; + + return nondetsAsTerms; + } private void exportTest(final TestVector testV) { try { if (!testV.isEmpty()) { - TestExporter.getInstance().exportTests(testV, mTestCaseUniqueIdentifier, true); + TestExporter.getInstance().exportTests(testV, getUniqueIdentifierForTestCaseName(), true); } } catch (final Exception e) { // TODO TestGeneration Auto-generated catch block @@ -512,6 +535,7 @@ private void getCurrentVA() { .get(VarAssignmentReuseAnnotation.class.getName()); } + System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); } } @@ -524,19 +548,19 @@ private void removeCheckIfCovered() { return; } if (mVAforReuse.equals(mDefaultVA)) { - System.out.println("OtherBranchRemoveCheck"); + System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); return; } - if (lastVaInTraceIsUsedForReuse && reuseUnsatpossible) { + if (reuseUnsatpossible) { // amount of nondets in VA + Between testgoals matches total amount of inputs - if (nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size()) { - System.out.println("OtherBranchRemoveCheck"); - mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); - } + assert nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + + mVAforReuse.mVarAssignmentPair.size(); + System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 790ad5892cf..1b946530088 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -45,7 +45,6 @@ import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.RunningTaskInfo; import de.uni_freiburg.informatik.ultimate.core.lib.exceptions.ToolchainCanceledException; import de.uni_freiburg.informatik.ultimate.core.lib.models.annotation.VarAssignmentReuseAnnotation; -import de.uni_freiburg.informatik.ultimate.core.model.models.IElement; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.CfgSmtToolkit; @@ -72,6 +71,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.logic.TermVariable; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; @@ -155,6 +155,8 @@ public class TraceCheck implements ITraceCheck { protected final IIcfgSymbolTable mBoogie2SmtSymbolTable; protected final FeasibilityCheckResult mFeasibilityResult; + final HashMap mProcedureToCallLoc = new HashMap<>(); + /** * Check if trace fulfills specification given by precondition, postcondition and pending contexts. The * pendingContext maps the positions of pending returns to predicates which define possible variable valuations in @@ -422,20 +424,11 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } rpeb.setBranchEncoders(i, beMapping); } - } else if (mTrace.getSymbol(i) instanceof StatementSequence) { - final StatementSequence statementBranch = (StatementSequence) mTrace.getSymbol(i); - - // If VA in Trace returns last found VA - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - - final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch - .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - reuseCandidate.mVaOrder = vaOrder; - - } } - + if (mTrace.getSymbol(i) instanceof Call) { + final Call call = (Call) mTrace.getSymbol(i); + mProcedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); + } } final Function funGetValue; @@ -519,6 +512,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi varAssignment.add(varEqValue); } } + } else { System.out.println("unexpected Index for nondet"); } @@ -535,13 +529,19 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } final boolean vaReuse = true; if (vaReuse) { - final IElement statementBranch = (IElement) nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - final VarAssignmentReuseAnnotation vaReuseAnno = (VarAssignmentReuseAnnotation) statementBranch - .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1); + final L stmt = nsb.mSsa.getTrace().getSymbol(nsb.mSsa.getTrace().length() - 1); + if (stmt instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) stmt; + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation vaReuseAnno = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + vaReuseAnno.mPrecedingProcedure = statementBranch.getPrecedingProcedure(); + vaReuseAnno.mLocationOfPrecedingProcedure = + mProcedureToCallLoc.get(statementBranch.getPrecedingProcedure()); + vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1); + } } } return testV; diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index 1f39433e511..b029d393fe4 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -25,7 +25,8 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { // order corresponds to // test-case public VarAssignmentReuseAnnotation mVAofOppositeBranch; - + public String mPrecedingProcedure = ""; + public String mLocationOfPrecedingProcedure = ""; public boolean mIsActiveTestGoal = true; public boolean mUseCurrentTestGoal = false; // use this test goal instead of a previous public HashSet mUnsatWithVAs = new HashSet<>(); @@ -89,4 +90,10 @@ public VarAssignmentReuseAnnotation setDefaultVa(final VarAssignmentReuseAnnotat } return mDefaultVA; } + + public String getPrecedingProcedure() { + + return mPrecedingProcedure; + + } } From 02844a7c18f1b2b6c046857d440cfaf9b9f7955c Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 6 May 2024 15:00:51 +0200 Subject: [PATCH 066/278] Fixed Default Reuse --- .../singletracecheck/AnnotateAndAsserter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index c1f6cdd5c87..ebb0c03281d 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -181,14 +181,14 @@ public void buildAnnotatedSsaAndAssertTerms() { if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { boolean reuse; getCurrentVA(); - if (mCurrentVA != null && mVAforReuse == null) { + if (mCurrentVA != null && mVAforReuse == null && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; System.out.println("Using Default to reuse since this is the first testgoal in the trace"); } - if (nondetsInTrace.isEmpty() || mCurrentVA == null) { + if (nondetsInTrace.isEmpty() || mCurrentVA == null || mVAforReuse == null) { System.out.println("NO REUSE"); reuse = false; } else if (mVAforReuse.mNegatedVA) { @@ -433,7 +433,7 @@ private void getVAandNONDETS(final int i) { } private void ifStatementHasNondetAddToSet(final int i, final StatementSequence statementBranch) { - if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { if (statementBranch.toString().contains("nondet")) { final Set nonTheorySymbolsInTerm = SmtUtils.extractNonTheoryFunctionSymbols(mSSA.getFormulaFromValidNonCallPos(i)); @@ -460,7 +460,7 @@ private ArrayList getNonDetsAsTermsReuse() { for (int i = 0; i < varAssignmentPairs.size(); i++) { // TODO optimize in one loop over all nondets in trace // This "nondet" in Trace is in the VA final String nondetInVA = varAssignmentPairs.get(i).getFirst().toStringDirect(); - if (nondetsInTrace.contains(nondetInVA)) { + if (nondetsInTrace.contains(nondetInVA.substring(1, nondetInVA.length() - 1))) { final Term value = varAssignmentPairs.get(i).getSecond(); final Term reuseVaTerm = createTermFromVA(varAssignmentPairs.get(i).getFirst().toStringDirect(), value); nondetsAsTerms.add(reuseVaTerm); From bc13675c17ae767da0b757d3158fd5ddf72fdbf0 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 9 May 2024 23:39:17 +0200 Subject: [PATCH 067/278] Fix Match Prefix WIP --- .../singletracecheck/AnnotateAndAsserter.java | 111 ++++++++++++------ .../singletracecheck/TraceCheck.java | 2 +- .../VarAssignmentReuseAnnotation.java | 11 +- 3 files changed, 82 insertions(+), 42 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index ebb0c03281d..2c928ba569a 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -52,7 +52,6 @@ import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; -import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -86,13 +85,14 @@ public class AnnotateAndAsserter { final LinkedHashSet nondetsInTrace = new LinkedHashSet(); final LinkedHashSet nondetsInTraceAfterPreviousVA = new LinkedHashSet(); final HashMap nondetNameToType = new HashMap<>(); - + public ArrayList mVAsInPrefix = new ArrayList(); final HashMap procedureToCallLoc = new HashMap<>(); private final Integer mHighestVaOrderInTrace = -1; - private boolean reuseUnsatpossible = true; + private final boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); + final TestGenReuseMode mTestGenReuseMode; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, @@ -111,6 +111,10 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas } public void buildAnnotatedSsaAndAssertTerms() { + boolean reuse = true; + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + getReuseCandidate(); + } if (mAnnotSSA != null) { throw new AssertionError("already build"); } @@ -123,6 +127,7 @@ public void buildAnnotatedSsaAndAssertTerms() { final Collection callPositions = new ArrayList<>(); final Collection pendingReturnPositions = new ArrayList<>(); + int branchCount = 0; for (int i = 0; i < mTrace.length(); i++) { if (mTrace.isCallPosition(i)) { callPositions.add(i); @@ -139,15 +144,58 @@ public void buildAnnotatedSsaAndAssertTerms() { } mAnnotSSA.setFormulaAtNonCallPos(i, mAnnotateAndAssertCodeBlocks.annotateAndAssertNonCall(i)); } - if (mTrace.getSymbol(i) instanceof Call) { - final Call call = (Call) mTrace.getSymbol(i); - if (procedureToCallLoc.containsKey(call.getSucceedingProcedure())) { - procedureToCallLoc.remove(call.getSucceedingProcedure()); + // if (mTrace.getSymbol(i) instanceof Call) { + // final Call call = (Call) mTrace.getSymbol(i); + // if (procedureToCallLoc.containsKey(call.getSucceedingProcedure())) { + // procedureToCallLoc.remove(call.getSucceedingProcedure()); + // } + // procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); + // } + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + if (i < mTrace.length() - 1) { + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + + ifStatementHasNondetAddToSet(i, statementBranch); + // If VA in Trace returns last found VA + + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + + final VarAssignmentReuseAnnotation vaInTrace = + (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() + .get(VarAssignmentReuseAnnotation.class.getName()); + mVAsInPrefix.add(vaInTrace); + if (vaInTrace.equals(mCurrentVA)) { + nondetsInTraceAfterPreviousVA.clear(); + } else if (!vaInTrace.equals(mVAforReuse)) { + if (branchCount <= mVAforReuse.mVAsInPrefix.size()) { // + if (!mVAforReuse.mVAsInPrefix.get(branchCount).equals(vaInTrace)) { + reuse = false; + } + } else { + reuse = false; + } + + } + branchCount += 1; + // mVAforReuse = reuseCandidate; + // final String precedingProc = statementBranch.getPrecedingProcedure(); + // // Check if annotated test-goal and current test-goal are in the same procedure + // if (mVAforReuse.getPrecedingProcedure().equals(precedingProc) + // && + // mVAforReuse.mLocationOfPrecedingProcedure.equals(procedureToCallLoc.get(precedingProc))) + // { + // reuseUnsatpossible = true; + // } else { + // reuseUnsatpossible = false; + // } + // + // // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA + // nondetsInTraceAfterPreviousVA.clear(); + } + } } - procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); - } - if (i < mTrace.length() - 1) { - getVAandNONDETS(i); } } @@ -179,7 +227,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - boolean reuse; + getCurrentVA(); if (mCurrentVA != null && mVAforReuse == null && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); @@ -404,32 +452,20 @@ private String getUniqueIdentifierForTestCaseName() { return identifier; } - private void getVAandNONDETS(final int i) { - if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { - final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - - ifStatementHasNondetAddToSet(i, statementBranch); - // If VA in Trace returns last found VA - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - - final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch - .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - - mVAforReuse = reuseCandidate; - final String precedingProc = statementBranch.getPrecedingProcedure(); - // Check if annotated test-goal and current test-goal are in the same procedure - if (mVAforReuse.getPrecedingProcedure().equals(precedingProc) - && mVAforReuse.mLocationOfPrecedingProcedure.equals(procedureToCallLoc.get(precedingProc))) { - reuseUnsatpossible = true; - } else { - reuseUnsatpossible = false; + private void getReuseCandidate() { + for (int i = mTrace.length() - 2; i > 0; i--) { + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + mVAforReuse = reuseCandidate; + break; } - - // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA - nondetsInTraceAfterPreviousVA.clear(); } } + } private void ifStatementHasNondetAddToSet(final int i, final StatementSequence statementBranch) { @@ -550,7 +586,8 @@ private void removeCheckIfCovered() { if (mVAforReuse.equals(mDefaultVA)) { System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, + new ArrayList()); return; } @@ -560,7 +597,7 @@ private void removeCheckIfCovered() { + mVAforReuse.mVarAssignmentPair.size(); System.out.println("OtherBranchRemoveCheck"); mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); } } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 1b946530088..afd46f3c1e8 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -540,7 +540,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi vaReuseAnno.mPrecedingProcedure = statementBranch.getPrecedingProcedure(); vaReuseAnno.mLocationOfPrecedingProcedure = mProcedureToCallLoc.get(statementBranch.getPrecedingProcedure()); - vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1); + vaReuseAnno.setVa(varAssignmentPair, vaOrder + 1, mAAA.mVAsInPrefix); } } } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index b029d393fe4..7d807141889 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -21,9 +21,10 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { public boolean mNegatedVA = false; public boolean mCoveredTestGoal = false; private final Map mMap = new HashMap<>(); - public ArrayList> mVarAssignmentPair = new ArrayList>(); // check if negated, - // order corresponds to - // test-case + public ArrayList> mVarAssignmentPair = new ArrayList>(); + + public ArrayList mVAsInPrefix = new ArrayList(); + public VarAssignmentReuseAnnotation mVAofOppositeBranch; public String mPrecedingProcedure = ""; public String mLocationOfPrecedingProcedure = ""; @@ -68,9 +69,11 @@ public void setOppositeAnno(final VarAssignmentReuseAnnotation vaOpppositeBranch /* * Warning replaces the current VA */ - public void setVa(final ArrayList> varAssignmentPair, final int vaOrder) { + public void setVa(final ArrayList> varAssignmentPair, final int vaOrder, + final ArrayList VAsInPrefix) { mVarAssignmentPair = varAssignmentPair; mVaOrder = vaOrder; + mVAsInPrefix = VAsInPrefix; } public void removeCheck() { From a8408599f0e6d41fb6bd2aa172b12b090f52b2b9 Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 10 May 2024 00:09:09 +0200 Subject: [PATCH 068/278] Match prefix for resuse Fix --- .../singletracecheck/AnnotateAndAsserter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 2c928ba569a..dab96e06184 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -166,10 +166,8 @@ public void buildAnnotatedSsaAndAssertTerms() { (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); mVAsInPrefix.add(vaInTrace); - if (vaInTrace.equals(mCurrentVA)) { - nondetsInTraceAfterPreviousVA.clear(); - } else if (!vaInTrace.equals(mVAforReuse)) { - if (branchCount <= mVAforReuse.mVAsInPrefix.size()) { // + if (!vaInTrace.equals(mVAforReuse)) { + if (branchCount < mVAforReuse.mVAsInPrefix.size()) { // if (!mVAforReuse.mVAsInPrefix.get(branchCount).equals(vaInTrace)) { reuse = false; } @@ -177,6 +175,8 @@ public void buildAnnotatedSsaAndAssertTerms() { reuse = false; } + } else { + nondetsInTraceAfterPreviousVA.clear(); } branchCount += 1; // mVAforReuse = reuseCandidate; From e6fd0dfdf3161008ca9916cfc17cfa05a3e0da92 Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 10 May 2024 00:28:21 +0200 Subject: [PATCH 069/278] minor fix --- .../singletracecheck/AnnotateAndAsserter.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index dab96e06184..79889b0daee 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -87,7 +87,7 @@ public class AnnotateAndAsserter { final HashMap nondetNameToType = new HashMap<>(); public ArrayList mVAsInPrefix = new ArrayList(); final HashMap procedureToCallLoc = new HashMap<>(); - + private int mReuseCandidatePosition = 0; private final Integer mHighestVaOrderInTrace = -1; private final boolean reuseUnsatpossible = true; @@ -151,8 +151,9 @@ public void buildAnnotatedSsaAndAssertTerms() { // } // procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); // } - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + if (!mTestGenReuseMode.equals(TestGenReuseMode.None) && reuse) { if (i < mTrace.length() - 1) { + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); @@ -166,7 +167,8 @@ public void buildAnnotatedSsaAndAssertTerms() { (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); mVAsInPrefix.add(vaInTrace); - if (!vaInTrace.equals(mVAforReuse)) { + assert i <= mReuseCandidatePosition; + if (i < mReuseCandidatePosition) { if (branchCount < mVAforReuse.mVAsInPrefix.size()) { // if (!mVAforReuse.mVAsInPrefix.get(branchCount).equals(vaInTrace)) { reuse = false; @@ -174,8 +176,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } else { reuse = false; } - - } else { + } else if (i == mReuseCandidatePosition) { nondetsInTraceAfterPreviousVA.clear(); } branchCount += 1; @@ -244,7 +245,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { reuse = false; // Wie kann das überhaupt sein? System.out.println("NO REUSE since UNSAT With"); - } else { + } else if (reuse) { ArrayList vaPairsAsTerms; if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { vaPairsAsTerms = getNonDetsAsTermsReuse(); @@ -259,12 +260,13 @@ public void buildAnnotatedSsaAndAssertTerms() { mMgdScriptTc.getScript().push(1); mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); System.out.println("REUSE: " + varAssignmentConjunction); - reuse = true; } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. } + } else { + System.out.println("no reuse because prefix doesnt match"); } mSatisfiable = mMgdScriptTc.getScript().checkSat(); @@ -461,6 +463,7 @@ private void getReuseCandidate() { final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); mVAforReuse = reuseCandidate; + mReuseCandidatePosition = i; break; } } From 0c76f65f2f18bd444579b1f61a28b02e306c493d Mon Sep 17 00:00:00 2001 From: Max barth Date: Fri, 10 May 2024 00:32:58 +0200 Subject: [PATCH 070/278] Removed prints --- .../singletracecheck/AnnotateAndAsserter.java | 26 +++++++++---------- .../singletracecheck/TraceCheck.java | 4 --- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 79889b0daee..208d83f5844 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -234,17 +234,17 @@ public void buildAnnotatedSsaAndAssertTerms() { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; - System.out.println("Using Default to reuse since this is the first testgoal in the trace"); + // System.out.println("Using Default to reuse since this is the first testgoal in the trace"); } if (nondetsInTrace.isEmpty() || mCurrentVA == null || mVAforReuse == null) { - System.out.println("NO REUSE"); + // System.out.println("NO REUSE"); reuse = false; } else if (mVAforReuse.mNegatedVA) { reuse = false; } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { reuse = false; // Wie kann das überhaupt sein? - System.out.println("NO REUSE since UNSAT With"); + // System.out.println("NO REUSE since UNSAT With"); } else if (reuse) { ArrayList vaPairsAsTerms; if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { @@ -259,23 +259,23 @@ public void buildAnnotatedSsaAndAssertTerms() { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); mMgdScriptTc.getScript().push(1); mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - System.out.println("REUSE: " + varAssignmentConjunction); + // System.out.println("REUSE: " + varAssignmentConjunction); } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. } } else { - System.out.println("no reuse because prefix doesnt match"); + // System.out.println("no reuse because prefix doesnt match"); } mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (reuse) { - System.out.println("trying to reuse"); + // System.out.println("trying to reuse"); } if (mSatisfiable == LBool.UNSAT) { if (reuse) { - System.out.println("REUSE UNSAT"); + // System.out.println("REUSE UNSAT"); mMgdScriptTc.getScript().pop(1); if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { removeCheckIfCovered(); @@ -289,7 +289,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal - System.out.println("REUSE SUCCESSFULL"); + // System.out.println("REUSE SUCCESSFULL"); if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; } @@ -306,7 +306,7 @@ public void buildAnnotatedSsaAndAssertTerms() { mCurrentVA.mCoveredTestGoal = true; } if (mSatisfiable == LBool.UNKNOWN) { - System.out.println("UNKNOWN"); + // System.out.println("UNKNOWN"); } // Report benchmarks @@ -534,7 +534,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! - System.out.println("ALARM: " + nondet + " not in VA"); + // System.out.println("ALARM: " + nondet + " not in VA"); inputBetweenTestGoals = true; value = null; // null will be used as value zero final Term reuseVaTerm = createTermFromVA(nondet, value); @@ -575,7 +575,7 @@ private void getCurrentVA() { } - System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); + // System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); } } @@ -587,7 +587,7 @@ private void removeCheckIfCovered() { return; } if (mVAforReuse.equals(mDefaultVA)) { - System.out.println("OtherBranchRemoveCheckDefault"); + // System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, new ArrayList()); @@ -598,7 +598,7 @@ private void removeCheckIfCovered() { // amount of nondets in VA + Between testgoals matches total amount of inputs assert nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size(); - System.out.println("OtherBranchRemoveCheck"); + // System.out.println("OtherBranchRemoveCheck"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index afd46f3c1e8..4d9a91b6d3c 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -442,8 +442,6 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final boolean mTestGeneration = true; if (mTestGeneration) { final TestVector testV = extractTestVector(nsb, funGetValue, rpeb, vaOrder); - // testV.addValuesWithNegativeIndex(); - System.out.println("Amount Of NonDets in TestCase: " + testV.countNonDets); final boolean mExportTests = true; if (mExportTests) { final boolean mExportAllInOneFile = true; @@ -513,8 +511,6 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi } } - } else { - System.out.println("unexpected Index for nondet"); } evenRepresentative = !evenRepresentative; } else { From 0cd023b3f2942ff7bb6b07b2471a6a01dfa59b5e Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 12 May 2024 15:40:38 +0200 Subject: [PATCH 071/278] Version where we reuse always and only use optimization if prefixes match --- .../singletracecheck/AnnotateAndAsserter.java | 72 +++++++------------ 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 208d83f5844..baca7c31c90 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -89,7 +89,7 @@ public class AnnotateAndAsserter { final HashMap procedureToCallLoc = new HashMap<>(); private int mReuseCandidatePosition = 0; private final Integer mHighestVaOrderInTrace = -1; - private final boolean reuseUnsatpossible = true; + private boolean reuseUnsatpossible = true; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); @@ -112,7 +112,7 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas public void buildAnnotatedSsaAndAssertTerms() { boolean reuse = true; - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { getReuseCandidate(); } if (mAnnotSSA != null) { @@ -144,56 +144,36 @@ public void buildAnnotatedSsaAndAssertTerms() { } mAnnotSSA.setFormulaAtNonCallPos(i, mAnnotateAndAssertCodeBlocks.annotateAndAssertNonCall(i)); } - // if (mTrace.getSymbol(i) instanceof Call) { - // final Call call = (Call) mTrace.getSymbol(i); - // if (procedureToCallLoc.containsKey(call.getSucceedingProcedure())) { - // procedureToCallLoc.remove(call.getSucceedingProcedure()); - // } - // procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); - // } - if (!mTestGenReuseMode.equals(TestGenReuseMode.None) && reuse) { - if (i < mTrace.length() - 1) { - - if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { - final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); - - ifStatementHasNondetAddToSet(i, statementBranch); - // If VA in Trace returns last found VA - - if (statementBranch.getPayload().getAnnotations() - .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - - final VarAssignmentReuseAnnotation vaInTrace = - (VarAssignmentReuseAnnotation) statementBranch.getPayload().getAnnotations() - .get(VarAssignmentReuseAnnotation.class.getName()); + + // ensure we are not considering currentVA as reuseCandidate + if (i < mTrace.length() - 1 && !mTestGenReuseMode.equals(TestGenReuseMode.None)) { + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { + final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); + ifStatementHasNondetAddToSet(i, statementBranch); + if (statementBranch.getPayload().getAnnotations() + .containsKey(VarAssignmentReuseAnnotation.class.getName())) { + final VarAssignmentReuseAnnotation vaInTrace = (VarAssignmentReuseAnnotation) statementBranch + .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); + + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT) && reuse) { mVAsInPrefix.add(vaInTrace); assert i <= mReuseCandidatePosition; if (i < mReuseCandidatePosition) { if (branchCount < mVAforReuse.mVAsInPrefix.size()) { // if (!mVAforReuse.mVAsInPrefix.get(branchCount).equals(vaInTrace)) { - reuse = false; + reuseUnsatpossible = false; } } else { - reuse = false; + reuseUnsatpossible = false; } } else if (i == mReuseCandidatePosition) { nondetsInTraceAfterPreviousVA.clear(); } branchCount += 1; - // mVAforReuse = reuseCandidate; - // final String precedingProc = statementBranch.getPrecedingProcedure(); - // // Check if annotated test-goal and current test-goal are in the same procedure - // if (mVAforReuse.getPrecedingProcedure().equals(precedingProc) - // && - // mVAforReuse.mLocationOfPrecedingProcedure.equals(procedureToCallLoc.get(precedingProc))) - // { - // reuseUnsatpossible = true; - // } else { - // reuseUnsatpossible = false; - // } - // - // // ACHTUNG, dürfen wirklich nur die nondets sein zwischen currentVA und previousVA - // nondetsInTraceAfterPreviousVA.clear(); + + // Ensure we do not consider currentVA for reuse + } else if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { + mVAforReuse = vaInTrace; } } } @@ -228,13 +208,11 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - getCurrentVA(); if (mCurrentVA != null && mVAforReuse == null && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; - // System.out.println("Using Default to reuse since this is the first testgoal in the trace"); } if (nondetsInTrace.isEmpty() || mCurrentVA == null || mVAforReuse == null) { @@ -259,7 +237,7 @@ public void buildAnnotatedSsaAndAssertTerms() { final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); mMgdScriptTc.getScript().push(1); mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); - // System.out.println("REUSE: " + varAssignmentConjunction); + System.out.println("REUSE: " + varAssignmentConjunction); } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. @@ -289,7 +267,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } } else if (reuse) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal - // System.out.println("REUSE SUCCESSFULL"); + System.out.println("REUSE SUCCESSFULL"); if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; } @@ -455,6 +433,7 @@ private String getUniqueIdentifierForTestCaseName() { } private void getReuseCandidate() { + // start after currentVA for (int i = mTrace.length() - 2; i > 0; i--) { if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); @@ -567,19 +546,16 @@ private void exportTest(final TestVector testV) { private void getCurrentVA() { final L lastStmt = mSSA.getTrace().getSymbol(mSSA.getTrace().length() - 1); if (lastStmt instanceof StatementSequence) { - final StatementSequence lastStmtSeq = (StatementSequence) lastStmt; if (lastStmtSeq.getPayload().getAnnotations().containsKey(VarAssignmentReuseAnnotation.class.getName())) { mCurrentVA = (VarAssignmentReuseAnnotation) lastStmtSeq.getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); - } - - // System.out.println("CurrentVA: " + lastStmtSeq.getSerialNumber()); } } private void removeCheckIfCovered() { + assert mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT); if (mVAforReuse.mNegatedVA) { return; } From cf97a5e27230db788d8ed32e0b6f4a15d804036b Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 13 May 2024 16:14:38 +0200 Subject: [PATCH 072/278] Added setting for calloc --- .../singletracecheck/AnnotateAndAsserter.java | 72 ++++++++++++------- .../VarAssignmentReuseAnnotation.java | 4 +- .../RcfgPreferenceInitializer.java | 2 +- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index baca7c31c90..339b2b10185 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -52,6 +52,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Rational; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -89,8 +90,7 @@ public class AnnotateAndAsserter { final HashMap procedureToCallLoc = new HashMap<>(); private int mReuseCandidatePosition = 0; private final Integer mHighestVaOrderInTrace = -1; - private boolean reuseUnsatpossible = true; - + private boolean reuseUnsatpossible; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); final TestGenReuseMode mTestGenReuseMode; @@ -105,14 +105,15 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mSSA = nestedSSA; mAnnotateAndAssertCodeBlocks = aaacb; mTcbg = tcbg; - mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + reuseUnsatpossible = mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) + || mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc); } public void buildAnnotatedSsaAndAssertTerms() { boolean reuse = true; - if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { getReuseCandidate(); } if (mAnnotSSA != null) { @@ -147,6 +148,18 @@ public void buildAnnotatedSsaAndAssertTerms() { // ensure we are not considering currentVA as reuseCandidate if (i < mTrace.length() - 1 && !mTestGenReuseMode.equals(TestGenReuseMode.None)) { + + // calling loc version + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc)) { + if (mTrace.getSymbol(i) instanceof Call) { + final Call call = (Call) mTrace.getSymbol(i); + if (procedureToCallLoc.containsKey(call.getSucceedingProcedure())) { + procedureToCallLoc.remove(call.getSucceedingProcedure()); + } + procedureToCallLoc.put(call.getSucceedingProcedure(), call.getSource().toString()); + } + } + if (mSSA.getTrace().getSymbol(i) instanceof StatementSequence) { final StatementSequence statementBranch = (StatementSequence) mSSA.getTrace().getSymbol(i); ifStatementHasNondetAddToSet(i, statementBranch); @@ -155,16 +168,16 @@ public void buildAnnotatedSsaAndAssertTerms() { final VarAssignmentReuseAnnotation vaInTrace = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT) && reuse) { + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) && reuse) { mVAsInPrefix.add(vaInTrace); assert i <= mReuseCandidatePosition; if (i < mReuseCandidatePosition) { - if (branchCount < mVAforReuse.mVAsInPrefix.size()) { // - if (!mVAforReuse.mVAsInPrefix.get(branchCount).equals(vaInTrace)) { - reuseUnsatpossible = false; + if (branchCount < mVAforReuse.mVAsInVAPrefix.size()) { // + if (!mVAforReuse.mVAsInVAPrefix.get(branchCount).equals(vaInTrace)) { + reuse = false; } } else { - reuseUnsatpossible = false; + reuse = false; } } else if (i == mReuseCandidatePosition) { nondetsInTraceAfterPreviousVA.clear(); @@ -172,8 +185,20 @@ public void buildAnnotatedSsaAndAssertTerms() { branchCount += 1; // Ensure we do not consider currentVA for reuse - } else if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { + } else { mVAforReuse = vaInTrace; + nondetsInTraceAfterPreviousVA.clear(); + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc)) { + final String precedingProc = statementBranch.getPrecedingProcedure(); + // Check if annotated test-goal and current test-goal are in the same procedure + // And have the same calling location (incoming icfg edge) + if (!mVAforReuse.getPrecedingProcedure().equals(precedingProc) + && mVAforReuse.mLocationOfPrecedingProcedure + .equals(procedureToCallLoc.get(precedingProc))) { + reuseUnsatpossible = false; + } + } + } } } @@ -209,7 +234,7 @@ public void buildAnnotatedSsaAndAssertTerms() { if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { getCurrentVA(); - if (mCurrentVA != null && mVAforReuse == null && mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (mCurrentVA != null && mVAforReuse == null && reuseUnsatpossible) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; @@ -225,9 +250,9 @@ public void buildAnnotatedSsaAndAssertTerms() { // System.out.println("NO REUSE since UNSAT With"); } else if (reuse) { ArrayList vaPairsAsTerms; - if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse)) { + if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse) || !reuseUnsatpossible) { vaPairsAsTerms = getNonDetsAsTermsReuse(); - } else if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + } else if (reuseUnsatpossible) { vaPairsAsTerms = getNonDetsAsTermsReuseUNSAT(); } else { throw new AssertionError("unexpected Reuse Mode"); @@ -255,7 +280,7 @@ public void buildAnnotatedSsaAndAssertTerms() { if (reuse) { // System.out.println("REUSE UNSAT"); mMgdScriptTc.getScript().pop(1); - if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT)) { + if (reuseUnsatpossible) { removeCheckIfCovered(); } mSatisfiable = mMgdScriptTc.getScript().checkSat(); @@ -488,7 +513,7 @@ private ArrayList getNonDetsAsTermsReuse() { } private ArrayList getNonDetsAsTermsReuseUNSAT() { - assert mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT); + assert reuseUnsatpossible; final ArrayList nondetsAsTerms = new ArrayList(); final ArrayList> varAssignmentPairs = mVAforReuse.mVarAssignmentPair; @@ -510,7 +535,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { break; } } - if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet)) { + if (nondetNotInVA && nondetsInTraceAfterPreviousVA.contains(nondet) && reuseUnsatpossible) { // TODO verhindern, dass beim 2.checksat das hier nochmal gemacht wird!! // System.out.println("ALARM: " + nondet + " not in VA"); @@ -555,7 +580,7 @@ private void getCurrentVA() { } private void removeCheckIfCovered() { - assert mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSAT); + assert reuseUnsatpossible; if (mVAforReuse.mNegatedVA) { return; } @@ -570,14 +595,11 @@ private void removeCheckIfCovered() { return; } - if (reuseUnsatpossible) { - // amount of nondets in VA + Between testgoals matches total amount of inputs - assert nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() - + mVAforReuse.mVarAssignmentPair.size(); - // System.out.println("OtherBranchRemoveCheck"); - mCurrentVA.mVAofOppositeBranch.removeCheck(); - mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); + // amount of nondets in VA + Between testgoals matches total amount of inputs + assert nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size(); + // System.out.println("OtherBranchRemoveCheck"); + mCurrentVA.mVAofOppositeBranch.removeCheck(); + mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); - } } } diff --git a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java index 7d807141889..e9bd35d1ecc 100644 --- a/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java +++ b/trunk/source/Library-UltimateCore/src/de/uni_freiburg/informatik/ultimate/core/lib/models/annotation/VarAssignmentReuseAnnotation.java @@ -23,7 +23,7 @@ public class VarAssignmentReuseAnnotation extends ModernAnnotations { private final Map mMap = new HashMap<>(); public ArrayList> mVarAssignmentPair = new ArrayList>(); - public ArrayList mVAsInPrefix = new ArrayList(); + public ArrayList mVAsInVAPrefix = new ArrayList(); public VarAssignmentReuseAnnotation mVAofOppositeBranch; public String mPrecedingProcedure = ""; @@ -73,7 +73,7 @@ public void setVa(final ArrayList> varAssignmentPair, final int final ArrayList VAsInPrefix) { mVarAssignmentPair = varAssignmentPair; mVaOrder = vaOrder; - mVAsInPrefix = VAsInPrefix; + mVAsInVAPrefix = VAsInPrefix; } public void removeCheck() { diff --git a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java index e8a7a01b197..3d2c5fbe658 100644 --- a/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java +++ b/trunk/source/RCFGBuilder/src/de/uni_freiburg/informatik/ultimate/plugins/generator/rcfgbuilder/preferences/RcfgPreferenceInitializer.java @@ -172,6 +172,6 @@ public enum TestGenReuseMode { /** * Reuse UNSAT by removing the check of the other branch and choosing values for inputs between testgoals */ - ReuseUNSAT + ReuseUNSATmatchPrefix, ReuseUNSATmatchCalloc } } From 4b0b90b3932bf736f9844e84ed5807819bff6722 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 24 Jun 2024 12:59:02 +0200 Subject: [PATCH 073/278] Added support for Reuse + Mutligoal needs evaluation --- .../singletracecheck/AnnotateAndAsserter.java | 80 +++++++++++++++++-- .../singletracecheck/TraceCheck.java | 2 +- .../traceabstraction/NwaCegarLoop.java | 13 ++- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 339b2b10185..5b056408b53 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -41,6 +41,7 @@ import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IcfgEdge; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; @@ -53,6 +54,7 @@ import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.CodeBlock; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -115,6 +117,9 @@ public void buildAnnotatedSsaAndAssertTerms() { boolean reuse = true; if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { getReuseCandidate(); + if (mVAforReuse == null) { + reuse = false; + } } if (mAnnotSSA != null) { throw new AssertionError("already build"); @@ -167,7 +172,7 @@ public void buildAnnotatedSsaAndAssertTerms() { .containsKey(VarAssignmentReuseAnnotation.class.getName())) { final VarAssignmentReuseAnnotation vaInTrace = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - + // prefix if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) && reuse) { mVAsInPrefix.add(vaInTrace); assert i <= mReuseCandidatePosition; @@ -186,6 +191,7 @@ public void buildAnnotatedSsaAndAssertTerms() { // Ensure we do not consider currentVA for reuse } else { + // default reuse mVAforReuse = vaInTrace; nondetsInTraceAfterPreviousVA.clear(); if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc)) { @@ -241,13 +247,14 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (nondetsInTrace.isEmpty() || mCurrentVA == null || mVAforReuse == null) { - // System.out.println("NO REUSE"); reuse = false; } else if (mVAforReuse.mNegatedVA) { reuse = false; } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { reuse = false; // Wie kann das überhaupt sein? // System.out.println("NO REUSE since UNSAT With"); + } else if (mVAforReuse.mVarAssignmentPair.isEmpty()) { + reuse = false; } else if (reuse) { ArrayList vaPairsAsTerms; if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse) || !reuseUnsatpossible) { @@ -274,7 +281,7 @@ public void buildAnnotatedSsaAndAssertTerms() { mSatisfiable = mMgdScriptTc.getScript().checkSat(); if (reuse) { - // System.out.println("trying to reuse"); + System.out.println("trying to reuse"); } if (mSatisfiable == LBool.UNSAT) { if (reuse) { @@ -307,6 +314,9 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (mSatisfiable == LBool.SAT && mCurrentVA != null) { mCurrentVA.mCoveredTestGoal = true; + + // concreteExecution(); + } if (mSatisfiable == LBool.UNKNOWN) { // System.out.println("UNKNOWN"); @@ -319,6 +329,56 @@ public void buildAnnotatedSsaAndAssertTerms() { mLogger.info("Conjunction of SSA is " + mSatisfiable); } + /* + * In test case generation, we have a branching that is followed by a branching into assert true and assert !false. + * Where assert !false is an endpoint. + * The concrete value that reaches assert !false also satisfies assert true, where the program continues. + */ + private void concreteExecution() { + final L word = mTrace.getSymbol(mTrace.length() - 3); // test goal branching. -3 should be the real branching + // condition + + System.out.println("Branching word: " + word); + if (word instanceof IcfgEdge) { + ((IcfgEdge) word).getTarget(); + System.out.println(((IcfgEdge) word).getTarget().getOutgoingEdges()); + } + if (word instanceof CodeBlock) { + ((CodeBlock) word).getTarget(); + + System.out.println(((CodeBlock) word).getTarget().getOutgoingEdges()); + } + + // word formula + System.out.println(((IcfgEdge) word).getTransformula().getFormula()); + + for (final IcfgEdge outgoing : ((IcfgEdge) word).getTarget().getOutgoingEdges()) { + System.out.println("outgoing: " + outgoing); + System.out.println(outgoing.getTransformula().getFormula()); + System.out.println(outgoing.getTarget()); + for (final IcfgEdge outgoing2 : outgoing.getTarget().getOutgoingEdges()) { + System.out.println("outgoing2: " + outgoing2); + System.out.println(outgoing2.getTransformula().getFormula()); + System.out.println(outgoing2.getTarget()); + for (final IcfgEdge outgoing3 : outgoing2.getTarget().getOutgoingEdges()) { + System.out.println("outgoing3: " + outgoing3); + System.out.println(outgoing3.getTransformula().getFormula()); + System.out.println(outgoing3.getTarget()); + } + } + } + System.out.println("asd"); + /* + * letter bekommen wir vom automaten, vlt besser dass dann im tracecheck oder nwa zu machen sogar wobei nich so gut + */ + // final NestedWord traceContinued = mTrace; + // final NestedWord subwordBefore = traceContinued.getSubWord(mTrace.length() - 2, mTrace.length() - 1); + // final NestedWord subwordBefore = traceContinued.7getSubWord(mTrace.length() - 2, mTrace.length() - 1); + + // traceContinued.concatenate(new NestedWord<>(((Object) word).getLetter(), -2)); + // traceContinued.concatenate(subwordBefore); + } + private Term createTermFromVA(final String variableAsString, final Term value) { FunctionSymbol varInCurrentScript = mMgdScriptTc.getScript().getTheory().getDeclaredFunctions().get(variableAsString); @@ -466,9 +526,13 @@ private void getReuseCandidate() { .containsKey(VarAssignmentReuseAnnotation.class.getName())) { final VarAssignmentReuseAnnotation reuseCandidate = (VarAssignmentReuseAnnotation) statementBranch .getPayload().getAnnotations().get(VarAssignmentReuseAnnotation.class.getName()); - mVAforReuse = reuseCandidate; - mReuseCandidatePosition = i; - break; + if (!reuseCandidate.mVarAssignmentPair.isEmpty()) { + mVAforReuse = reuseCandidate; + mReuseCandidatePosition = i; + break; + } else { + mVAforReuse = null; + } } } } @@ -588,7 +652,7 @@ private void removeCheckIfCovered() { return; } if (mVAforReuse.equals(mDefaultVA)) { - // System.out.println("OtherBranchRemoveCheckDefault"); + System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, new ArrayList()); @@ -597,7 +661,7 @@ private void removeCheckIfCovered() { // amount of nondets in VA + Between testgoals matches total amount of inputs assert nondetsInTrace.size() == nondetsInTraceAfterPreviousVA.size() + mVAforReuse.mVarAssignmentPair.size(); - // System.out.println("OtherBranchRemoveCheck"); + System.out.println("OtherBranchRemoveCheck"); mCurrentVA.mVAofOppositeBranch.removeCheck(); mCurrentVA.mVAofOppositeBranch.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 4d9a91b6d3c..0af68a3b6b8 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -440,7 +440,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } final boolean mTestGeneration = true; - if (mTestGeneration) { + if (mTestGeneration && !mAAA.mSucessfulReuse) { // TODO check for bugs final TestVector testV = extractTestVector(nsb, funGetValue, rpeb, vaOrder); final boolean mExportTests = true; if (mExportTests) { diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index 30b3ed640ca..de33b3c05cb 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -496,10 +496,17 @@ protected void constructErrorAutomaton() throws AutomataOperationCanceledExcepti final ISLPredicate testGoalISL = (ISLPredicate) testGoal; if (testGoalISL.getProgramPoint().getPayload().getAnnotations() .containsKey(VarAssignmentReuseAnnotation.class.getName())) { - final VarAssignmentReuseAnnotation pLocAnno = + + final VarAssignmentReuseAnnotation pLocAnnoVA = (VarAssignmentReuseAnnotation) testGoalISL.getProgramPoint().getPayload().getAnnotations() .get(VarAssignmentReuseAnnotation.class.getName()); - if (!pLocAnno.mIsActiveTestGoal) { + // If it contains a VA it should contain a TG + assert testGoalISL.getProgramPoint().getPayload().getAnnotations() + .containsKey(TestGoalAnnotation.class.getName()); + final TestGoalAnnotation pLocAnnoTG = (TestGoalAnnotation) testGoalISL.getProgramPoint().getPayload() + .getAnnotations().get(TestGoalAnnotation.class.getName()); + + if (!pLocAnnoVA.mIsActiveTestGoal || mTestGoalWorkingSet.contains(pLocAnnoTG.mId)) { mErrorGeneralizationEngine.addCoveredTestGoalToErrorAutomaton(testGoal, mAbstraction.internalPredecessors(testGoal)); } @@ -540,6 +547,7 @@ protected boolean refineAbstraction() throws AutomataLibraryException { subtrahend = mErrorGeneralizationEngine.getResultAfterEnhancement(); if (!mTestGeneration.equals(TestGenerationMode.None)) { // testGenerationCoverage(); + // mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); // Done by constructing mutli goal automaton } } else { automatonType = AutomatonType.FLOYD_HOARE; @@ -579,7 +587,6 @@ private void testGenerationCoverage() { } } mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); - mTestGoalTodoStack.removeAll(mTestGoalsInCurrentTrace); } From 10d1d19d91ae13f014772c09b0e05841ddc52c62 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 12 Sep 2024 11:11:40 +0200 Subject: [PATCH 074/278] Removed Concrete execution method for now --- .../singletracecheck/AnnotateAndAsserter.java | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 5b056408b53..dbad5eb74fb 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -41,7 +41,6 @@ import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; -import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IcfgEdge; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; @@ -54,7 +53,6 @@ import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; -import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.CodeBlock; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; @@ -329,56 +327,6 @@ public void buildAnnotatedSsaAndAssertTerms() { mLogger.info("Conjunction of SSA is " + mSatisfiable); } - /* - * In test case generation, we have a branching that is followed by a branching into assert true and assert !false. - * Where assert !false is an endpoint. - * The concrete value that reaches assert !false also satisfies assert true, where the program continues. - */ - private void concreteExecution() { - final L word = mTrace.getSymbol(mTrace.length() - 3); // test goal branching. -3 should be the real branching - // condition - - System.out.println("Branching word: " + word); - if (word instanceof IcfgEdge) { - ((IcfgEdge) word).getTarget(); - System.out.println(((IcfgEdge) word).getTarget().getOutgoingEdges()); - } - if (word instanceof CodeBlock) { - ((CodeBlock) word).getTarget(); - - System.out.println(((CodeBlock) word).getTarget().getOutgoingEdges()); - } - - // word formula - System.out.println(((IcfgEdge) word).getTransformula().getFormula()); - - for (final IcfgEdge outgoing : ((IcfgEdge) word).getTarget().getOutgoingEdges()) { - System.out.println("outgoing: " + outgoing); - System.out.println(outgoing.getTransformula().getFormula()); - System.out.println(outgoing.getTarget()); - for (final IcfgEdge outgoing2 : outgoing.getTarget().getOutgoingEdges()) { - System.out.println("outgoing2: " + outgoing2); - System.out.println(outgoing2.getTransformula().getFormula()); - System.out.println(outgoing2.getTarget()); - for (final IcfgEdge outgoing3 : outgoing2.getTarget().getOutgoingEdges()) { - System.out.println("outgoing3: " + outgoing3); - System.out.println(outgoing3.getTransformula().getFormula()); - System.out.println(outgoing3.getTarget()); - } - } - } - System.out.println("asd"); - /* - * letter bekommen wir vom automaten, vlt besser dass dann im tracecheck oder nwa zu machen sogar wobei nich so gut - */ - // final NestedWord traceContinued = mTrace; - // final NestedWord subwordBefore = traceContinued.getSubWord(mTrace.length() - 2, mTrace.length() - 1); - // final NestedWord subwordBefore = traceContinued.7getSubWord(mTrace.length() - 2, mTrace.length() - 1); - - // traceContinued.concatenate(new NestedWord<>(((Object) word).getLetter(), -2)); - // traceContinued.concatenate(subwordBefore); - } - private Term createTermFromVA(final String variableAsString, final Term value) { FunctionSymbol varInCurrentScript = mMgdScriptTc.getScript().getTheory().getDeclaredFunctions().get(variableAsString); From 2c250e61e7eceb84f55ba8124cf9ee2d2c1608f5 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 14 Sep 2024 23:01:27 +0200 Subject: [PATCH 075/278] Prepared STTT Evaluation: New Statistics Reuse is tried on the CFG script Removed old statistics --- .../check_bvsge_bvashr1_64bit.smt2 | 45 ++++ .../AnnotateAndAssertCodeBlocks.java | 36 ++- ...nnotateAndAssertConjunctsOfCodeBlocks.java | 2 +- .../singletracecheck/AnnotateAndAsserter.java | 216 +++++++++++------- ...ndAsserterWithStmtOrderPrioritization.java | 9 +- .../singletracecheck/TraceCheck.java | 65 ++++-- .../TraceCheckStatisticsDefinitions.java | 11 +- .../TraceCheckStatisticsGenerator.java | 47 ++++ .../traceabstraction/AbstractCegarLoop.java | 2 + .../CegarLoopStatisticsDefinitions.java | 4 +- .../CegarLoopStatisticsGenerator.java | 9 + .../traceabstraction/CegarStatisticsType.java | 54 ++++- .../traceabstraction/NwaCegarLoop.java | 156 +------------ 13 files changed, 377 insertions(+), 279 deletions(-) create mode 100644 trunk/examples/local/2023smtcomp/BV/2018-Preiner-cav18/check_bvsge_bvashr1_64bit.smt2 diff --git a/trunk/examples/local/2023smtcomp/BV/2018-Preiner-cav18/check_bvsge_bvashr1_64bit.smt2 b/trunk/examples/local/2023smtcomp/BV/2018-Preiner-cav18/check_bvsge_bvashr1_64bit.smt2 new file mode 100644 index 00000000000..236b27443e5 --- /dev/null +++ b/trunk/examples/local/2023smtcomp/BV/2018-Preiner-cav18/check_bvsge_bvashr1_64bit.smt2 @@ -0,0 +1,45 @@ +(set-info :smt-lib-version 2.6) +(set-logic BV) +(set-info :source | +Generated by: Mathias Preiner +Generated on: 2018-04-06 +Application: Verification of invertibility conditions generated in [1]. +Target solver: Boolector, CVC4, Z3 +Publication: +[1] Solving Quantified Bit-Vectors using Invertibility Conditions + Aina Niemetz, Mathias Preiner, Andrew Reynolds, Clark Barrett and Cesare Tinelli + To appear in CAV 2018 +|) +(set-info :license "https://creativecommons.org/licenses/by/4.0/") +(set-info :category "crafted") +(set-info :status unsat) +(declare-fun s () (_ BitVec 64)) +(declare-fun t () (_ BitVec 64)) + +(define-fun udivtotal ((a (_ BitVec 64)) (b (_ BitVec 64))) (_ BitVec 64) + (ite (= b (_ bv0 64)) (bvnot (_ bv0 64)) (bvudiv a b)) +) +(define-fun uremtotal ((a (_ BitVec 64)) (b (_ BitVec 64))) (_ BitVec 64) + (ite (= b (_ bv0 64)) a (bvurem a b)) +) +(define-fun min () (_ BitVec 64) + (bvnot (bvlshr (bvnot (_ bv0 64)) (_ bv1 64))) +) +(define-fun max () (_ BitVec 64) + (bvnot min) +) + +(define-fun SC ((s (_ BitVec 64)) (t (_ BitVec 64))) Bool +(not (and (bvult t (bvnot t)) (bvslt s t))) +) + +(assert + (not + (and + (=> (SC s t) (exists ((x (_ BitVec 64))) (bvsge (bvashr s x) t))) + (=> (exists ((x (_ BitVec 64))) (bvsge (bvashr s x) t)) (SC s t)) + ) + ) +) +(check-sat) +(exit) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java index e28c9ffca7a..18d8e4a33f0 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java @@ -30,6 +30,7 @@ import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.TraceCheckLock; import de.uni_freiburg.informatik.ultimate.logic.Annotation; @@ -49,6 +50,10 @@ public class AnnotateAndAssertCodeBlocks { protected final Script mScript; protected final ManagedScript mMgdScript; + protected final ManagedScript mCfgManagedScript; // used for optimization during trace check, dann must not + // interdict + // interpolation + TermTransferrer mTermTransferrer = null; protected final Object mScriptLockOwner; protected final NestedWord mTrace; @@ -66,15 +71,26 @@ public class AnnotateAndAssertCodeBlocks { protected static final String PENDINGCONTEXT = "_PendingContext"; protected static final String LOCVARASSIGN_PENDINGCONTEXT = "_LocVarAssignPendingContext"; protected static final String OLDVARASSIGN_PENDINGCONTEXT = "_OldVarAssignPendingContext"; + Object mReuseLock; + boolean mCfgMgdScriptTcLockedBySbElse = false; public AnnotateAndAssertCodeBlocks(final ManagedScript csToolkit, final TraceCheckLock scriptLockOwner, - final NestedFormulas nestedSSA, final ILogger logger) { + final NestedFormulas nestedSSA, final ILogger logger, final ManagedScript cfgMgdScriptTc, + final Object reuseLock) { mLogger = logger; mMgdScript = csToolkit; mScriptLockOwner = scriptLockOwner; mScript = csToolkit.getScript(); mTrace = nestedSSA.getTrace(); mSSA = nestedSSA; + + // For Reuse Solver call: + mCfgManagedScript = cfgMgdScriptTc; + mReuseLock = reuseLock; + if (mReuseLock != null && mCfgManagedScript != null) { + mTermTransferrer = new TermTransferrer(mMgdScript.getScript(), mCfgManagedScript.getScript()); + } + } protected Term annotateAndAssertPrecondition() { @@ -187,6 +203,9 @@ protected String oldVarAssignemntPendingReturnAnnotation(final int pendingContex } protected Term annotateAndAssertTerm(final Term term, final String name) { + if (mCfgManagedScript != null && mReuseLock != null && !mCfgMgdScriptTcLockedBySbElse) { + annotateAndAssertTermToCFGscript(term, name); + } assert term.getFreeVars().length == 0 : "Term has free vars"; final Annotation annot = new Annotation(":named", name); final Term annotTerm = mScript.annotate(term, annot); @@ -195,10 +214,19 @@ protected Term annotateAndAssertTerm(final Term term, final String name) { return constantRepresentingAnnotatedTerm; } + protected void annotateAndAssertTermToCFGscript(final Term term, final String name) { + assert term.getFreeVars().length == 0 : "Term has free vars"; + mTermTransferrer.transform(term); + final Annotation annot = new Annotation(":named", name); + final Term annotTerm = mCfgManagedScript.getScript().annotate(term, annot); + mCfgManagedScript.assertTerm(mReuseLock, annotTerm); + // final Term constantRepresentingAnnotatedTerm = mCFGMgdScriptTc.getScript().term(name); + + } + /** - * Represents one conjunct in an annotated SSA. The annotated term is the term - * submitted to the solver (we have to use these named terms in order to obtain - * an unsatisfiable core). + * Represents one conjunct in an annotated SSA. The annotated term is the term submitted to the solver (we have to + * use these named terms in order to obtain an unsatisfiable core). * */ public static class AnnotatedSsaConjunct { diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java index 7206cf69f13..996486af42d 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java @@ -74,7 +74,7 @@ public AnnotateAndAssertConjunctsOfCodeBlocks(final ManagedScript mgdScriptTc, f final NestedFormulas nestedSSA, final NestedFormulas nestedFormulas, final ILogger logger, final ManagedScript mgdScriptCfg) { - super(mgdScriptTc, scriptLockOwner, nestedSSA, logger); + super(mgdScriptTc, scriptLockOwner, nestedSSA, logger, null, null); mNestedFormulas = nestedFormulas; mCsToolkitPredicates = mgdScriptCfg; } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index dbad5eb74fb..7d24a5e692e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -41,6 +41,7 @@ import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; @@ -50,6 +51,7 @@ import de.uni_freiburg.informatik.ultimate.logic.ConstantTerm; import de.uni_freiburg.informatik.ultimate.logic.FunctionSymbol; import de.uni_freiburg.informatik.ultimate.logic.Rational; +import de.uni_freiburg.informatik.ultimate.logic.Script; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; @@ -69,8 +71,10 @@ public class AnnotateAndAsserter { protected final ILogger mLogger; protected final ManagedScript mMgdScriptTc; + protected ManagedScript mCfgManagedScript; protected final NestedWord mTrace; - + final TermTransferrer mTermTransferrer; + Object mReuseLock; protected LBool mSatisfiable; protected final NestedFormulas mSSA; protected ModifiableNestedFormulas mAnnotSSA; @@ -92,27 +96,46 @@ public class AnnotateAndAsserter { private final Integer mHighestVaOrderInTrace = -1; private boolean reuseUnsatpossible; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); - - final TestGenReuseMode mTestGenReuseMode; + private final TraceCheckStatisticsGenerator mTraceCheckBenchmarkGenerator; + private final TestGenReuseMode mTestGenReuseMode; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, - final IUltimateServiceProvider services) { + final IUltimateServiceProvider services, final ManagedScript cfgMgdScriptTc, final Object reuseLock, + final TraceCheckStatisticsGenerator traceCheckStatisticsGenerator, final boolean noReuse) { mServices = services; mLogger = mServices.getLoggingService().getLogger(TraceCheckerUtils.PLUGIN_ID); mMgdScriptTc = mgdScriptTc; + mCfgManagedScript = cfgMgdScriptTc; mTrace = nestedSSA.getTrace(); mSSA = nestedSSA; mAnnotateAndAssertCodeBlocks = aaacb; mTcbg = tcbg; - mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) - .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + mTraceCheckBenchmarkGenerator = traceCheckStatisticsGenerator; + mReuseLock = reuseLock; + mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); + if (noReuse || mCfgManagedScript.isLocked()) { + mTestGenReuseMode = TestGenReuseMode.None; + mAnnotateAndAssertCodeBlocks.mCfgMgdScriptTcLockedBySbElse = true; + } else { + mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) + .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + } reuseUnsatpossible = mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) || mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc); } public void buildAnnotatedSsaAndAssertTerms() { - boolean reuse = true; + mTraceCheckBenchmarkGenerator.reportTraceChecks(); + boolean reuse = false; + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + System.out.println("Lock"); + + mCfgManagedScript.lock(mReuseLock); + mCfgManagedScript.push(mReuseLock, 1); + reuse = true; + } + if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { getReuseCandidate(); if (mVAforReuse == null) { @@ -173,7 +196,8 @@ public void buildAnnotatedSsaAndAssertTerms() { // prefix if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) && reuse) { mVAsInPrefix.add(vaInTrace); - assert i <= mReuseCandidatePosition; + assert i <= mReuseCandidatePosition; // we check only branches, (not current VA) + if (i < mReuseCandidatePosition) { if (branchCount < mVAforReuse.mVAsInVAPrefix.size()) { // if (!mVAforReuse.mVAsInVAPrefix.get(branchCount).equals(vaInTrace)) { @@ -264,57 +288,29 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (!vaPairsAsTerms.isEmpty()) { - final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); - mMgdScriptTc.getScript().push(1); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); + final Term varAssignmentConjunction = SmtUtils.and(mCfgManagedScript.getScript(), vaPairsAsTerms); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTermToCFGscript(varAssignmentConjunction, "Int"); System.out.println("REUSE: " + varAssignmentConjunction); } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) // In this case previous test goal has not been checked yet. } - } else { // System.out.println("no reuse because prefix doesnt match"); } - mSatisfiable = mMgdScriptTc.getScript().checkSat(); - - if (reuse) { - System.out.println("trying to reuse"); - } - if (mSatisfiable == LBool.UNSAT) { - if (reuse) { - // System.out.println("REUSE UNSAT"); - mMgdScriptTc.getScript().pop(1); - if (reuseUnsatpossible) { - removeCheckIfCovered(); - } - mSatisfiable = mMgdScriptTc.getScript().checkSat(); - if (mCurrentVA.secondCheck == true) { - mVAforReuse.mNegatedVA = false; - } else { - mVAforReuse.mNegatedVA = true; - } - } - } else if (reuse) { - // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal - System.out.println("REUSE SUCCESSFULL"); - if (mCurrentVA.secondCheck == true) { - mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; - } - mSucessfulReuse = true; - } - if (reuse) { - mCurrentVA.secondCheck = true; - } + } + if (reuse) { + System.out.println("REUSE CFG Script CHecksat"); + mTraceCheckBenchmarkGenerator.reportReuseTried(); + reuseCheckSAT(); } else { + System.out.println("NO REUSE TC Script CHecksat"); mSatisfiable = mMgdScriptTc.getScript().checkSat(); - } - if (mSatisfiable == LBool.SAT && mCurrentVA != null) { - mCurrentVA.mCoveredTestGoal = true; - - // concreteExecution(); - + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + System.out.println("UnLock"); + mCfgManagedScript.pop(mReuseLock, 1); + mCfgManagedScript.unlock(mReuseLock); } if (mSatisfiable == LBool.UNKNOWN) { // System.out.println("UNKNOWN"); @@ -325,21 +321,65 @@ public void buildAnnotatedSsaAndAssertTerms() { mTcbg.reportNewCodeBlocks(mTrace.length()); mTcbg.reportNewAssertedCodeBlocks(mTrace.length()); mLogger.info("Conjunction of SSA is " + mSatisfiable); + } - private Term createTermFromVA(final String variableAsString, final Term value) { - FunctionSymbol varInCurrentScript = - mMgdScriptTc.getScript().getTheory().getDeclaredFunctions().get(variableAsString); + private void reuseCheckSAT() { + System.out.println("trying to reuse"); + + final LBool reuseResult = mCfgManagedScript.getScript().checkSat(); + System.out.println("REUSE Result: " + reuseResult); + + if (reuseResult == LBool.SAT) { + // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal + System.out.println("REUSE SUCCESSFULL"); + mTraceCheckBenchmarkGenerator.reportSuccessfullReuse(); + // We check the same branch twice, for branch encoder + if (mCurrentVA.secondCheck == true) { + mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; + } + if (mCurrentVA != null) { + mCurrentVA.mCoveredTestGoal = true; + // concreteExecution(); + } + mSucessfulReuse = true; + // Since we do not create a counterexample after successfull reuse, we have to annotate here. + mCurrentVA.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); + mSatisfiable = reuseResult; + } else { + if (reuseUnsatpossible) { + removeCheckIfCovered(); + } + if (mCurrentVA.secondCheck == true) { + mVAforReuse.mNegatedVA = false; + } else { + mVAforReuse.mNegatedVA = true; + } + + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + } + + mCurrentVA.secondCheck = true; + } + + private Term createTermFromVA(final String variableAsString, final Term valueTCscript) { + Term value = null; + if (valueTCscript != null) { + value = mTermTransferrer.transform(valueTCscript); + } + + final Script reuseScript = mCfgManagedScript.getScript(); + FunctionSymbol varInCurrentScript = reuseScript.getTheory().getDeclaredFunctions().get(variableAsString); if (varInCurrentScript == null) { - varInCurrentScript = mMgdScriptTc.getScript().getTheory() - .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); + varInCurrentScript = + reuseScript.getTheory().getFunction(variableAsString.substring(1, variableAsString.length() - 1)); } if (varInCurrentScript == null) { throw new AssertionError("unknown var " + variableAsString); } - final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), varInCurrentScript); + final Term nondetVar = SmtUtils.unfTerm(reuseScript, varInCurrentScript); final Term nondetValue; @@ -349,7 +389,7 @@ private Term createTermFromVA(final String variableAsString, final Term value) { if (nondetVar.getSort().getIndices()[1].equals("24")) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), + nondetValue = SmtUtils.unfTerm(reuseScript, valueAsAppterm.getFunction().getName(), valueAsAppterm.getSort().getIndices(), null, valueAsAppterm.getParameters()); } else { // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) @@ -359,14 +399,13 @@ private Term createTermFromVA(final String variableAsString, final Term value) { indices[0] = "0"; indices[1] = "0"; - final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); - final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 8)); - final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 23)); - nondetValue = - SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + final Term bvConst0 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 1)); + final Term bvConst1 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 8)); + final Term bvConst2 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 23)); + nondetValue = SmtUtils.unfTerm(reuseScript, "fp", null, null, bvConst0, bvConst1, bvConst2); // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, // SmtSortUtils @@ -377,8 +416,8 @@ private Term createTermFromVA(final String variableAsString, final Term value) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), - null, null, valueAsAppterm.getParameters()); + nondetValue = SmtUtils.unfTerm(reuseScript, valueAsAppterm.getFunction().getName(), null, null, + valueAsAppterm.getParameters()); } else { // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) // (_ +zero 2 4) @@ -387,18 +426,17 @@ private Term createTermFromVA(final String variableAsString, final Term value) { indices[0] = "0"; indices[1] = "0"; - final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); - final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 11)); - final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, - SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 52)); - nondetValue = - SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); + final Term bvConst0 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 1)); + final Term bvConst1 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 11)); + final Term bvConst2 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, + SmtSortUtils.getBitvectorSort(reuseScript, 52)); + nondetValue = SmtUtils.unfTerm(reuseScript, "fp", null, null, bvConst0, bvConst1, bvConst2); - // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, + // nondetValue = SmtUtils.unfTerm(reuseScript, "_ FloatingPoint 0 0", indices, // SmtSortUtils - // .getFloatSort(mMgdScriptTc.getScript(), BigInteger.valueOf(8), BigInteger.valueOf(23))); + // .getFloatSort(reuseScript, BigInteger.valueOf(8), BigInteger.valueOf(23))); } @@ -412,11 +450,11 @@ private Term createTermFromVA(final String variableAsString, final Term value) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; final BigInteger constValue = new BigInteger(valueAsAppterm.getFunction().getName().substring(2)); - nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), + nondetValue = BitvectorUtils.constructTerm(reuseScript, BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); } else { final BigInteger constValue = BigInteger.ZERO; - nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), + nondetValue = BitvectorUtils.constructTerm(reuseScript, BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); } break; @@ -424,22 +462,22 @@ private Term createTermFromVA(final String variableAsString, final Term value) { case SmtSortUtils.INT_SORT: { if (value != null) { - nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), - SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getIntSort(mMgdScriptTc)); + nondetValue = SmtUtils.rational2Term(reuseScript, SmtUtils.toRational(((ConstantTerm) value)), + SmtSortUtils.getIntSort(mMgdScriptTc)); } else { - nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), - SmtSortUtils.getIntSort(mMgdScriptTc), BigInteger.ZERO); + nondetValue = SmtUtils.constructIntegerValue(reuseScript, SmtSortUtils.getIntSort(mMgdScriptTc), + BigInteger.ZERO); } break; } case SmtSortUtils.REAL_SORT: { if (value != null) { - nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), - SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getRealSort(mMgdScriptTc)); + nondetValue = SmtUtils.rational2Term(reuseScript, SmtUtils.toRational(((ConstantTerm) value)), + SmtSortUtils.getRealSort(mMgdScriptTc)); } else { - nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), - SmtSortUtils.getRealSort(mMgdScriptTc), BigInteger.ZERO); + nondetValue = SmtUtils.constructIntegerValue(reuseScript, SmtSortUtils.getRealSort(mMgdScriptTc), + BigInteger.ZERO); } break; } @@ -448,7 +486,7 @@ private Term createTermFromVA(final String variableAsString, final Term value) { } } mValueAssignmentUsedForReuse.add(new Pair<>(nondetVar, nondetValue)); - return SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, nondetValue); + return SmtUtils.binaryEquality(reuseScript, nondetVar, nondetValue); } public LBool isInputSatisfiable() { @@ -554,6 +592,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { inputBetweenTestGoals = true; value = null; // null will be used as value zero final Term reuseVaTerm = createTermFromVA(nondet, value); + nondetsAsTerms.add(reuseVaTerm); } @@ -562,9 +601,9 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { nondetPositionCount += 1; } if (inputBetweenTestGoals) { + mTraceCheckBenchmarkGenerator.reportInputVectorsExtended(); exportTest(testV); } - return nondetsAsTerms; } @@ -572,6 +611,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { private void exportTest(final TestVector testV) { try { if (!testV.isEmpty()) { + mTraceCheckBenchmarkGenerator.reportTestExported(); TestExporter.getInstance().exportTests(testV, getUniqueIdentifierForTestCaseName(), true); } } catch (final Exception e) { @@ -599,6 +639,8 @@ private void removeCheckIfCovered() { if (mCurrentVA.mVAofOppositeBranch.mCoveredTestGoal) { return; } + mTraceCheckBenchmarkGenerator.reportSuccessfullReuse(); + mTraceCheckBenchmarkGenerator.reportUNSAToptimizations(); if (mVAforReuse.equals(mDefaultVA)) { System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java index b8f5abdd45e..0aefc9883ae 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java @@ -40,7 +40,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; -import java.util.TreeSet; import java.util.stream.Collectors; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; @@ -100,7 +99,7 @@ public AnnotateAndAsserterWithStmtOrderPrioritization(final ManagedScript mgdScr final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, final AssertCodeBlockOrder assertCodeBlocksOrder, final IUltimateServiceProvider services) { - super(mgdScriptTc, nestedSSA, aaacb, tcbg, services); + super(mgdScriptTc, nestedSSA, aaacb, tcbg, services, null, null, null, true); mAssertCodeBlocksOrder = assertCodeBlocksOrder; mCheckSat = 0; } @@ -144,10 +143,10 @@ private void dfsPartitionStatementsAccordingToDepth(final Integer lowerInd int i = lowerIndex; while (i < upperIndex) { // Is the current statement a loop entry? - if (rwt.getImage(pps.get(i)).size() >= 2 && ((TreeSet) rwt.getImage(pps.get(i))).higher(i) != null - && ((TreeSet) rwt.getImage(pps.get(i))).higher(i) < upperIndex) { + if (rwt.getImage(pps.get(i)).size() >= 2 && rwt.getImage(pps.get(i)).higher(i) != null + && rwt.getImage(pps.get(i)).higher(i) < upperIndex) { // the new upper index is the last occurrence of the same location - final int newUpperIndex = ((TreeSet) rwt.getImage(pps.get(i))).lower(upperIndex); + final int newUpperIndex = rwt.getImage(pps.get(i)).lower(upperIndex); addStmtPositionToDepth(depth + 1, depth2Statements, i); // we consider the subtrace from i+1 to newUpperIndex as a loop // and apply the partitioning recursively on the subtrace diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 0af68a3b6b8..94bea522b88 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -55,7 +55,6 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.transitions.UnmodifiableTransFormula; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; -import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheck; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheckPreferences.AssertCodeBlockOrder; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheckPreferences.AssertCodeBlockOrderType; @@ -73,6 +72,8 @@ import de.uni_freiburg.informatik.ultimate.logic.TermVariable; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.StatementSequence; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer; +import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.preferences.RcfgPreferenceInitializer.TestGenReuseMode; import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.Pair; /** @@ -130,6 +131,8 @@ public class TraceCheck implements ITraceCheck { protected final ManagedScript mCfgManagedScript; protected final ManagedScript mTcSmtManager; protected final TraceCheckLock mTraceCheckLock = new TraceCheckLock(); + protected final TraceCheckLock mReuseLock = new TraceCheckLock(); + /** * Maps a procedure name to the set of global variables which may be modified by the procedure. The set of variables * is represented as a map where the identifier of the variable is mapped to the type of the variable. @@ -156,6 +159,7 @@ public class TraceCheck implements ITraceCheck { protected final FeasibilityCheckResult mFeasibilityResult; final HashMap mProcedureToCallLoc = new HashMap<>(); + private final TestGenReuseMode mTestGenReuseMode; /** * Check if trace fulfills specification given by precondition, postcondition and pending contexts. The @@ -218,6 +222,9 @@ protected TraceCheck(final IPredicate precondition, final IPredicate postconditi mAssertCodeBlockOrder = assertCodeBlockOrder; mTraceCheckBenchmarkGenerator = new TraceCheckStatisticsGenerator(collectInterpolatSequenceStatistics); + mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) + .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + boolean providesIcfgProgramExecution = false; IcfgProgramExecution icfgProgramExecution = null; FeasibilityCheckResult feasibilityResult = null; @@ -233,9 +240,13 @@ protected TraceCheck(final IPredicate precondition, final IPredicate postconditi cleanupAndUnlockSolver(); } } else if (computeRcfgProgramExecution && feasibilityResult.getLBool() == LBool.SAT) { - icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); - if (icfgProgramExecution != null) { - providesIcfgProgramExecution = true; + if (!mAAA.mSucessfulReuse) { + icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); + if (icfgProgramExecution != null) { + providesIcfgProgramExecution = true; + } + } else { + providesIcfgProgramExecution = false; } mTraceCheckFinished = true; } else if (!feasibilityResult.isSolverCrashed()) { @@ -320,10 +331,12 @@ protected FeasibilityCheckResult checkTrace() { mServices); } else { mAAA = new AnnotateAndAsserter<>(mTcSmtManager, ssa, getAnnotateAndAsserterCodeBlocks(ssa), - mTraceCheckBenchmarkGenerator, mServices); + mTraceCheckBenchmarkGenerator, mServices, mCfgManagedScript, mReuseLock, + mTraceCheckBenchmarkGenerator, false); // Report the asserted code blocks // mTraceCheckBenchmarkGenerator.reportnewAssertedCodeBlocks(mTrace.length()); } + FeasibilityCheckResult result = null; try { mAAA.buildAnnotatedSsaAndAssertTerms(); @@ -417,7 +430,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final Map beMapping = new HashMap<>(); for (final TermVariable tv : tf.getBranchEncoders()) { final String nameOfConstant = NestedSsaBuilder.branchEncoderConstantName(tv, i); - final Term indexedBe = mTcSmtManager.getScript().term(nameOfConstant); + final Term indexedBe = getIndexed(nameOfConstant); final Term value = getValue(indexedBe); final Boolean booleanValue = getBooleanValue(value); beMapping.put(tv, booleanValue); @@ -432,12 +445,13 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } final Function funGetValue; - if (mCfgManagedScript != mTcSmtManager) { - funGetValue = a -> new TermTransferrer(mTcSmtManager.getScript(), mCfgManagedScript.getScript()) - .transform(getValue(a)); - } else { - funGetValue = this::getValue; - } + // TODO check if this works + // if (mCfgManagedScript != mTcSmtManager) { + // funGetValue = a -> new TermTransferrer(mTcSmtManager.getScript(), mCfgManagedScript.getScript()) + // .transform(getValue(a)); + // } else { + funGetValue = this::getValue; + // } final boolean mTestGeneration = true; if (mTestGeneration && !mAAA.mSucessfulReuse) { // TODO check for bugs @@ -499,13 +513,11 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (m.find()) { final String type = m.group(1); testV.addValueAssignment(valueT, index, type); - final TermTransferrer test = new TermTransferrer( - mCfgManagedScript.getScript(), mTcSmtManager.getScript()); final Term varEqValue = SmtUtils.binaryEquality(mTcSmtManager.getScript(), - test.transform(indexedVar), test.transform(valueT)); - final Pair varValuePair = new Pair( - test.transform(indexedVar), test.transform(valueT)); + indexedVar, valueT); + final Pair varValuePair = + new Pair(indexedVar, valueT); varAssignmentPair.add(varValuePair); varAssignment.add(varEqValue); } @@ -546,6 +558,7 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi private void exportTest(final TestVector testV, final String identifier, final boolean allInOneFile) { try { if (!testV.isEmpty()) { + mTraceCheckBenchmarkGenerator.reportTestExported(); TestExporter.getInstance().exportTests(testV, identifier, allInOneFile); } } catch (final Exception e) { @@ -555,7 +568,17 @@ private void exportTest(final TestVector testV, final String identifier, final b } protected AnnotateAndAssertCodeBlocks getAnnotateAndAsserterCodeBlocks(final NestedFormulas ssa) { - return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger); + if (mTestGenReuseMode.equals(TestGenReuseMode.None)) { + return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger, null, null); + } else { + return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger, mCfgManagedScript, + mReuseLock); + } + + } + + private Term getIndexed(final String nameOfConstant) { + return mTcSmtManager.getScript().term(nameOfConstant); } private Term getValue(final Term term) { @@ -623,9 +646,9 @@ private void lockAndPrepareSolverForTraceCheck() { protected void cleanupAndUnlockSolver() { mTcSmtManager.echo(mTraceCheckLock, new QuotedObject("finished trace check")); - if (mAAA.mSucessfulReuse) { - mTcSmtManager.pop(mTraceCheckLock, 1); - } + // if (mAAA.mSucessfulReuse) { + // mTcSmtManager.pop(mTraceCheckLock, 1); + // } mAAA.mSucessfulReuse = false; mTcSmtManager.pop(mTraceCheckLock, 1); mTcSmtManager.unlock(mTraceCheckLock); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsDefinitions.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsDefinitions.java index 70ea34e9a2e..5e502112c34 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsDefinitions.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsDefinitions.java @@ -64,7 +64,16 @@ public enum TraceCheckStatisticsDefinitions implements IStatisticsElement { PerfectInterpolantSequences(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.DATA_BEFORE_KEY), InterpolantCoveringCapability(BackwardCoveringInformation.class, CoverageAnalysis.DEFAULT_AGGREGATION, - StatisticsType.DATA_BEFORE_KEY),; + StatisticsType.DATA_BEFORE_KEY), + + // Test Case Generation Statistics: + TraceChecks(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA), + TestsExported(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA), + ReusesTried(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA), + InputVectorsExtended(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA), + UNSAToptimizations(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA), + + SucessfullReuses(Integer.class, StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA); private final Class mClazz; private final Function> mAggr; diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsGenerator.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsGenerator.java index 43e64bee5cf..758c3693e4a 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsGenerator.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheckStatisticsGenerator.java @@ -58,6 +58,14 @@ public enum InterpolantType { private int mPerfectInterpolantSequences = 0; private BackwardCoveringInformation mInterpolantCoveringCapability = new BackwardCoveringInformation(0, 0); + // Test Case generation statistics: + private int mTraceChecks = 0; + private int mTestsExported = 0; + private int mReusesTried = 0; + private int mInputVectorsExtended = 0; + private int UNSAToptimizations = 0; + private int mSucessfullReuses = 0; + private final boolean mCollectInterpolatSequenceStatistics; public TraceCheckStatisticsGenerator(final boolean collectInterpolatSequenceStatistics) { @@ -174,6 +182,20 @@ public Object getValue(final String key) { return mPerfectInterpolantSequences; case InterpolantCoveringCapability: return mInterpolantCoveringCapability; + + // Test Case Generation: + case TraceChecks: + return mTraceChecks; + case TestsExported: + return mTestsExported; + case ReusesTried: + return mReusesTried; + case InputVectorsExtended: + return mInputVectorsExtended; + case UNSAToptimizations: + return UNSAToptimizations; + case SucessfullReuses: + return mSucessfullReuses; default: throw new AssertionError("unknown data"); } @@ -195,4 +217,29 @@ public boolean isCollectingInterpolantSequenceStatistics() { return mCollectInterpolatSequenceStatistics; } + // Test Case Generation: + public void reportTraceChecks() { + mTraceChecks++; + } + + public void reportTestExported() { + mTestsExported++; + } + + public void reportReuseTried() { + mReusesTried++; + } + + public void reportInputVectorsExtended() { + mInputVectorsExtended++; + } + + public void reportUNSAToptimizations() { + UNSAToptimizations++; + } + + public void reportSuccessfullReuse() { + mSucessfullReuses++; + } + } \ No newline at end of file diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java index 90ec9337303..27a1df76d93 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/AbstractCegarLoop.java @@ -494,6 +494,8 @@ private void iterate() throws AutomataLibraryException { + destroyedStorables.stream().collect(Collectors.joining(","))); } } + mLogger.info("CEGAR Iteration stats: " + ((CegarStatisticsType) mCegarLoopBenchmark.getBenchmarkType()) + .prettyprintBenchmarkDataNoStopWatch(mCegarLoopBenchmark, true)); } mResultBuilder.addResultForAllRemaining(Result.USER_LIMIT_ITERATIONS); diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsDefinitions.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsDefinitions.java index 4fb0b16b5f2..51995f2638b 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsDefinitions.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsDefinitions.java @@ -88,7 +88,9 @@ public enum CegarLoopStatisticsDefinitions implements IStatisticsElement { RefinementEngineStatistics(StatisticsType.STATISTICS_DATA_AGGREGATION, StatisticsType.KEY_BEFORE_DATA), - ReuseStatistics(StatisticsType.STATISTICS_DATA_AGGREGATION, StatisticsType.KEY_BEFORE_DATA); + ReuseStatistics(StatisticsType.STATISTICS_DATA_AGGREGATION, StatisticsType.KEY_BEFORE_DATA), + + ErrorAutomatonCreated(StatisticsType.INTEGER_ADDITION, StatisticsType.KEY_BEFORE_DATA); private final Function> mAggr; private final Function> mPrettyprinter; diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsGenerator.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsGenerator.java index 174267bcd6b..efd5a1220f5 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsGenerator.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarLoopStatisticsGenerator.java @@ -56,6 +56,9 @@ public class CegarLoopStatisticsGenerator extends StatisticsGeneratorWithStopwat private int mInterpolantAutomatonStates = 0; private int mPathProgramHistogramMaximum = 0; + // Test Case generation statistics: + private int mErrorAutomatonCreated = 0; + @Override public Collection getKeys() { return getBenchmarkType().getKeys(); @@ -177,6 +180,8 @@ public Object getValue(final String key) { return mHoareAnnotationData; case RefinementEngineStatistics: return mRefinementEngineStatistics; + case ErrorAutomatonCreated: + return mErrorAutomatonCreated; default: throw new AssertionError("unknown data"); } @@ -198,4 +203,8 @@ public String[] getStopwatches() { CegarLoopStatisticsDefinitions.DumpTime.toString(), CegarLoopStatisticsDefinitions.InitialAbstractionConstructionTime.toString(), }; } + + public void reportErrorAutomatonCreated() { + mErrorAutomatonCreated++; + } } diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarStatisticsType.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarStatisticsType.java index 437c3e45e8d..7450b177d6a 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarStatisticsType.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/CegarStatisticsType.java @@ -1,22 +1,22 @@ /* * Copyright (C) 2014-2015 Matthias Heizmann (heizmann@informatik.uni-freiburg.de) * Copyright (C) 2015 University of Freiburg - * + * * This file is part of the ULTIMATE TraceAbstraction plug-in. - * + * * The ULTIMATE TraceAbstraction plug-in is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * The ULTIMATE TraceAbstraction plug-in is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with the ULTIMATE TraceAbstraction plug-in. If not, see . - * + * * Additional permission under GNU GPL version 3 section 7: * If you modify the ULTIMATE TraceAbstraction plug-in, or any covered work, by linking * or combining it with Eclipse RCP (or a modified version of Eclipse RCP), @@ -26,8 +26,11 @@ */ package de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction; +import java.util.Collection; import java.util.function.Function; +import de.uni_freiburg.informatik.ultimate.util.statistics.IStatisticsDataProvider; +import de.uni_freiburg.informatik.ultimate.util.statistics.IStatisticsElement; import de.uni_freiburg.informatik.ultimate.util.statistics.StatisticsType; public class CegarStatisticsType extends StatisticsType { @@ -52,6 +55,47 @@ public static String prettyprintNanoseconds(final long time) { return seconds + "." + tenthDigit + "s"; } + public String prettyprintBenchmarkDataNoStopWatch(final IStatisticsDataProvider benchmarkData, + final boolean noStopwatch) { + return prettyprintBenchmarkData(getKeys(), benchmarkData, noStopwatch); + } + + @Override + public String prettyprintBenchmarkData(final IStatisticsDataProvider benchmarkData) { + return prettyprintBenchmarkData(getKeys(), benchmarkData, false); + } + + public static & IStatisticsElement> String prettyprintBenchmarkData( + final Collection keys, final IStatisticsDataProvider benchmarkData, final boolean noStopwatch) { + final StringBuilder sb = new StringBuilder(); + String delimiter = ""; + for (final String key : keys) { + sb.append(delimiter); + + final CegarLoopStatisticsDefinitions keyE = Enum.valueOf(CegarLoopStatisticsDefinitions.class, key); + switch (keyE) { + case OverallTime: + case EmptinessCheckTime: + case AutomataDifference: + case DeadEndRemovalTime: + case HoareAnnotationTime: + case BasicInterpolantAutomatonTime: + case InitialAbstractionConstructionTime: + case DumpTime: + if (noStopwatch) { + break; + } + default: + final Object value = benchmarkData.getValue(key); + sb.append(keyE.prettyprint(value)); + delimiter = ", "; + } + + } + return sb.toString(); + + } + public static class SizeIterationPair { final int mSize; final int mIteration; diff --git a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java index de33b3c05cb..ba4c19c3ce8 100644 --- a/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java +++ b/trunk/source/TraceAbstraction/src/de/uni_freiburg/informatik/ultimate/plugins/generator/traceabstraction/NwaCegarLoop.java @@ -29,19 +29,11 @@ */ package de.uni_freiburg.informatik.ultimate.plugins.generator.traceabstraction; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -147,18 +139,8 @@ public class NwaCegarLoop> extends BasicCegarLoop mTestGoalTodoStack = new ArrayList<>(); private final Set mTestGoalWorkingSet = new HashSet<>(); - private final Set mTestGoalsInCurrentTrace = new HashSet<>(); private Integer mCurrentTestGoalId; - // TestGeneration Statistiks - private final boolean mWriteEvaluationToFile = false; // TODO add setting or remove in final version - private final long startTime = System.nanoTime(); - private int CegarLoopIterations = 1; - private double Covered = 0; - private double CoveredLongTrace = 0; - private double mLongTraceTime = 0; - private int mTestsExported = 0; - public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton initialAbstraction, final IIcfg rootNode, final CfgSmtToolkit csToolkit, final PredicateFactory predicateFactory, final TAPreferences taPrefs, final Set errorLocs, @@ -174,7 +156,6 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton() : null; - // Heuristic Emptiness Check mUseHeuristicEmptinessCheck = taPrefs.useHeuristicEmptinessCheck(); mScoringMethod = taPrefs.getHeuristicEmptinessCheckScoringMethod(); mAStarHeuristic = taPrefs.getHeuristicEmptinessCheckAStarHeuristic(); @@ -185,10 +166,6 @@ public NwaCegarLoop(final DebugIdentifier name, final INestedWordAutomaton(new AutomataLibraryServices(getServices()), abstraction, mSearchStrategy) @@ -304,119 +280,8 @@ private void nwaCegarWithTestGeneration(final INwaOutgoingLetterAndTransitionPro .getNestedRun(); } } finally { - if (mWriteEvaluationToFile) { - final long estimatedTime = System.nanoTime() - startTime; - if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { - mLongTraceTime = System.nanoTime() - startTime; - writeEvalRow(estimatedTime, mLongTraceTime); - } - } mCegarLoopBenchmark.stop(CegarLoopStatisticsDefinitions.EmptinessCheckTime); } - if (mCounterexample == null) { - mLogger.info("TestGen, CEGAR Iterations: " + CegarLoopIterations); - mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); - if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { - mLongTraceTime = System.nanoTime() - startTime; - mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); - mLogger.info("TestGen, Coverage during Optimization: " + CoveredLongTrace / mErrorLocs.size()); - } - mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); - final long estimatedTime = System.nanoTime() - startTime; - if (mWriteEvaluationToFile) { - writeEvalRow(estimatedTime, mLongTraceTime); - } - return; - } - mLogger.info("TestGen, Amount of Tests Exported: " + mTestsExported); - getIDsOfTestGoalsInTrace(); - CegarLoopIterations += 1; - } - - private void getIDsOfTestGoalsInTrace() { - final List a = mCounterexample.getStateSequence(); - mTestGoalsInCurrentTrace.clear(); - for (int i = 0; i < a.size(); i++) { - if (a.get(i) instanceof ISLPredicate) { - final ISLPredicate stmt = (ISLPredicate) a.get(i); - if (stmt.getProgramPoint().getPayload().getAnnotations() - .containsKey(TestGoalAnnotation.class.getName())) { - mTestGoalsInCurrentTrace.add(((TestGoalAnnotation) stmt.getProgramPoint().getPayload() - .getAnnotations().get(TestGoalAnnotation.class.getName())).mId); - } - } - } - } - - private void writeEvalRowLongTrace() { - try (FileWriter fw = new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEval2.csv", true); - - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter out = new PrintWriter(bw)) { - out.println(String.format("%s", mTestGeneration.equals(TestGenerationMode.SearchMultiGoal))); - } catch (final IOException e) { - throw new AssertionError(e); - } - } - - private void writeEvalTestCaseNewRow() { - final File fold = new File("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalCoverage.csv"); - if (fold.exists() && !fold.isDirectory()) { - try (FileWriter fw = - new FileWriter("C:\\Users\\maxba\\ultimate\\testcomp\\TestGenerationEvalTestCases.csv", true); - - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter out = new PrintWriter(bw)) { - out.print("\n"); - } catch (final IOException e) { - throw new AssertionError(e); - } - } - } - - private void writeEvalRow(final long estimatedTime, final double mLongTraceTime2) { - String asd = ""; - final File fold = new File("TestGenerationEvalCoverage.csv"); - if (fold.exists() && !fold.isDirectory()) { - asd = readEvalCoverage(); - fold.delete(); - } - - try (FileWriter fw = new FileWriter("TestGenerationEvalCoverage.csv", true); - - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter out = new PrintWriter(bw)) { - fw.write(asd); - out.println( - String.format("Time: %s, Coverage: %s , LongTraceTime %s, CoverageLongTrace: %s, Iterations: %s", - estimatedTime / 1000, Covered / mErrorLocs.size(), mLongTraceTime2 / 1000, - CoveredLongTrace / mErrorLocs.size(), CegarLoopIterations)); - } catch (final IOException e) { - throw new AssertionError(e); - } - - } - - // TODO coverage calculation is wrong, different from testcov - private String readEvalCoverage() { - final StringBuilder resultStringBuilder = new StringBuilder(); - String fileCOntentWithoutLastLine = ""; - try (final FileReader fr = new FileReader("TestGenerationEvalCoverage.csv"); - final BufferedReader br = new BufferedReader(fr)) { - String line; - - while ((line = br.readLine()) != null) { - fileCOntentWithoutLastLine = resultStringBuilder.toString(); - resultStringBuilder.append(line).append("\n"); - - } - if (CegarLoopIterations == 1) { - return resultStringBuilder.toString(); - } - } catch (final IOException e) { - throw new AssertionError(e); - } - return fileCOntentWithoutLastLine; } private boolean checkIsEmptyHeuristic(final INwaOutgoingLetterAndTransitionProvider abstraction) @@ -491,7 +356,6 @@ protected void constructErrorAutomaton() throws AutomataOperationCanceledExcepti mIcfg.getCfgSmtToolkit().getSymbolTable(), mPredicateFactoryInterpolantAutomata, mAbstraction, mIteration); mInterpolAutomaton = null; - System.out.println(mAbstraction.getFinalStates().size()); for (final IPredicate testGoal : mAbstraction.getFinalStates()) { final ISLPredicate testGoalISL = (ISLPredicate) testGoal; if (testGoalISL.getProgramPoint().getPayload().getAnnotations() @@ -511,9 +375,10 @@ protected void constructErrorAutomaton() throws AutomataOperationCanceledExcepti mAbstraction.internalPredecessors(testGoal)); } } - } + mCegarLoopBenchmark.reportErrorAutomatonCreated(); + final NestedWordAutomaton resultBeforeEnhancement = mErrorGeneralizationEngine.getResultBeforeEnhancement(); assert isInterpolantAutomatonOfSingleStateType(resultBeforeEnhancement); @@ -573,23 +438,6 @@ protected boolean refineAbstraction() throws AutomataLibraryException { return !stillAccepted; } - // TestGoal Coverage for Statistic and removing covered TestGoals form Stack - private void testGenerationCoverage() { - mTestsExported += 1; - for (final Integer testgoal : mTestGoalsInCurrentTrace) { - if (mTestGoalTodoStack.contains(testgoal)) { - Covered += 1; - if (mTestGeneration.equals(TestGenerationMode.SearchMultiGoal)) { - CoveredLongTrace += 1; - mLogger.info("TestGen, Time spent Sear-MultiGoal Preprocess: " + mLongTraceTime); - mLogger.info("TestGen, Coverage: " + CoveredLongTrace / mErrorLocs.size()); - } - } - } - mLogger.info("TestGen, Coverage: " + Covered / mErrorLocs.size()); - - } - private void computeAutomataDifference(final INestedWordAutomaton minuend, final INwaOutgoingLetterAndTransitionProvider subtrahend, final INwaOutgoingLetterAndTransitionProvider subtrahendBeforeEnhancement, From 71e41b323c4bd7ce6180fd0c1a5022b6c2aa42ca Mon Sep 17 00:00:00 2001 From: Max barth Date: Sun, 15 Sep 2024 10:14:47 +0200 Subject: [PATCH 076/278] Bug Fix, unlock script if error occurs --- .../singletracecheck/AnnotateAndAsserter.java | 7 ++++--- .../lib/tracecheckerutils/singletracecheck/TraceCheck.java | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 7d24a5e692e..fbb46f6ad02 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -73,7 +73,7 @@ public class AnnotateAndAsserter { protected final ManagedScript mMgdScriptTc; protected ManagedScript mCfgManagedScript; protected final NestedWord mTrace; - final TermTransferrer mTermTransferrer; + TermTransferrer mTermTransferrer = null; Object mReuseLock; protected LBool mSatisfiable; protected final NestedFormulas mSSA; @@ -113,11 +113,12 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mTcbg = tcbg; mTraceCheckBenchmarkGenerator = traceCheckStatisticsGenerator; mReuseLock = reuseLock; - mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); - if (noReuse || mCfgManagedScript.isLocked()) { + + if (noReuse || mCfgManagedScript.isLocked() || mCfgManagedScript == null) { mTestGenReuseMode = TestGenReuseMode.None; mAnnotateAndAssertCodeBlocks.mCfgMgdScriptTcLockedBySbElse = true; } else { + mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 94bea522b88..f1b4accd698 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -349,6 +349,11 @@ protected FeasibilityCheckResult checkTrace() { } result = new FeasibilityCheckResult(isSafe, tcru, false); } catch (final SMTLIBException e) { + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + System.out.println("UnLock"); + mCfgManagedScript.pop(mReuseLock, 1); + mCfgManagedScript.unlock(mReuseLock); + } if (!mServices.getProgressMonitorService().continueProcessing()) { // there was a cancellation request, probably responsible for // abnormal solver termination From 5704f59cb2a71e7d3b86f662c9da8bde85edfb0e Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 16 Sep 2024 14:23:37 +0200 Subject: [PATCH 077/278] Bugfix unknown var in reusescript --- .../AnnotateAndAssertCodeBlocks.java | 18 +++++++++++++++--- .../singletracecheck/AnnotateAndAsserter.java | 13 ++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java index 18d8e4a33f0..76128a5d215 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java @@ -50,9 +50,9 @@ public class AnnotateAndAssertCodeBlocks { protected final Script mScript; protected final ManagedScript mMgdScript; - protected final ManagedScript mCfgManagedScript; // used for optimization during trace check, dann must not - // interdict - // interpolation + protected ManagedScript mCfgManagedScript; // used for optimization during trace check, dann must not + // interdict + // interpolation TermTransferrer mTermTransferrer = null; protected final Object mScriptLockOwner; protected final NestedWord mTrace; @@ -224,6 +224,18 @@ protected void annotateAndAssertTermToCFGscript(final Term term, final String na } + public void setUpReuse(final ManagedScript cfgScript, final Object lock) { + if (mCfgManagedScript == null) { + mCfgManagedScript = cfgScript; + } + if (mReuseLock == null) { + mReuseLock = lock; + } + if (mReuseLock != null && mCfgManagedScript != null) { + mTermTransferrer = new TermTransferrer(mMgdScript.getScript(), mCfgManagedScript.getScript()); + } + } + /** * Represents one conjunct in an annotated SSA. The annotated term is the term submitted to the solver (we have to * use these named terms in order to obtain an unsatisfiable core). diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index fbb46f6ad02..3492e02635c 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -121,6 +121,9 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + mAnnotateAndAssertCodeBlocks.setUpReuse(cfgMgdScriptTc, reuseLock); + } } reuseUnsatpossible = mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) || mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc); @@ -367,6 +370,7 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs Term value = null; if (valueTCscript != null) { value = mTermTransferrer.transform(valueTCscript); + // value = mTermTransferrer.tr } final Script reuseScript = mCfgManagedScript.getScript(); @@ -531,11 +535,10 @@ private void ifStatementHasNondetAddToSet(final int i, final StatementSequence s if (statementBranch.toString().contains("nondet")) { final Set nonTheorySymbolsInTerm = SmtUtils.extractNonTheoryFunctionSymbols(mSSA.getFormulaFromValidNonCallPos(i)); - - for (final FunctionSymbol symbol : nonTheorySymbolsInTerm) { - final Matcher m = Pattern.compile("__VERIFIER_nondet_(\\w*)") - .matcher(statementBranch.getPayload().toString()); - if (m.find()) { + final Matcher m = + Pattern.compile("__VERIFIER_nondet_(\\w*)").matcher(statementBranch.getPayload().toString()); + if (m.find()) { + for (final FunctionSymbol symbol : nonTheorySymbolsInTerm) { if (symbol.getName().contains("nondet")) { nondetsInTrace.add(symbol.getName()); nondetsInTraceAfterPreviousVA.add(symbol.getName()); From 8db44d33b630cb2e30071bdcaf3cda09af80307f Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 16 Sep 2024 15:17:06 +0200 Subject: [PATCH 078/278] Fix if value is real but sort is int --- .../lib/tracecheckerutils/singletracecheck/TestExporter.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 9cd795d5fbe..8c457b00cc9 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -441,6 +441,10 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } case SmtSortUtils.INT_SORT: { valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); + if (valueInRange.contains(".")) { + valueInRange = valueInRange.split("\\.")[0]; + + } final BigInteger value = new BigInteger(valueInRange); if (type.equals("long")) { if (value.compareTo(new BigInteger("2147483647")) == 1) { From 581c3b56179bbeedbda0a66d9c72498f2ddcf2c1 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 17 Sep 2024 20:35:08 +0200 Subject: [PATCH 079/278] assert to cfg script even if no reuse --- .../singletracecheck/AnnotateAndAsserter.java | 69 ++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 3492e02635c..04da39ac4cb 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -98,6 +98,8 @@ public class AnnotateAndAsserter { private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); private final TraceCheckStatisticsGenerator mTraceCheckBenchmarkGenerator; private final TestGenReuseMode mTestGenReuseMode; + private boolean mReuseWithCFGscript = true; + private boolean mCFGscriptLockedByUS = false; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, @@ -114,16 +116,18 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas mTraceCheckBenchmarkGenerator = traceCheckStatisticsGenerator; mReuseLock = reuseLock; + mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) + .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); + if (noReuse || mCfgManagedScript.isLocked() || mCfgManagedScript == null) { - mTestGenReuseMode = TestGenReuseMode.None; + mReuseWithCFGscript = false; mAnnotateAndAssertCodeBlocks.mCfgMgdScriptTcLockedBySbElse = true; } else { mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); - mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) - .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - mAnnotateAndAssertCodeBlocks.setUpReuse(cfgMgdScriptTc, reuseLock); - } + + // if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + mAnnotateAndAssertCodeBlocks.setUpReuse(cfgMgdScriptTc, reuseLock); + // } } reuseUnsatpossible = mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) || mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc); @@ -132,12 +136,15 @@ public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas public void buildAnnotatedSsaAndAssertTerms() { mTraceCheckBenchmarkGenerator.reportTraceChecks(); boolean reuse = false; - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + if (mReuseWithCFGscript) { System.out.println("Lock"); - + mCFGscriptLockedByUS = true; mCfgManagedScript.lock(mReuseLock); mCfgManagedScript.push(mReuseLock, 1); - reuse = true; + + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + reuse = true; + } } if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { @@ -200,21 +207,22 @@ public void buildAnnotatedSsaAndAssertTerms() { // prefix if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) && reuse) { mVAsInPrefix.add(vaInTrace); - assert i <= mReuseCandidatePosition; // we check only branches, (not current VA) - - if (i < mReuseCandidatePosition) { - if (branchCount < mVAforReuse.mVAsInVAPrefix.size()) { // - if (!mVAforReuse.mVAsInVAPrefix.get(branchCount).equals(vaInTrace)) { + if (i <= mReuseCandidatePosition) { // we check only branches, (not current VA) + if (i < mReuseCandidatePosition) { + if (branchCount < mVAforReuse.mVAsInVAPrefix.size()) { // + if (!mVAforReuse.mVAsInVAPrefix.get(branchCount).equals(vaInTrace)) { + reuse = false; + } + } else { reuse = false; } - } else { - reuse = false; + } else if (i == mReuseCandidatePosition) { + nondetsInTraceAfterPreviousVA.clear(); } - } else if (i == mReuseCandidatePosition) { - nondetsInTraceAfterPreviousVA.clear(); + branchCount += 1; + } else { + reuse = false; } - branchCount += 1; - // Ensure we do not consider currentVA for reuse } else { // default reuse @@ -307,15 +315,26 @@ public void buildAnnotatedSsaAndAssertTerms() { System.out.println("REUSE CFG Script CHecksat"); mTraceCheckBenchmarkGenerator.reportReuseTried(); reuseCheckSAT(); - } else { - System.out.println("NO REUSE TC Script CHecksat"); - mSatisfiable = mMgdScriptTc.getScript().checkSat(); - } - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { System.out.println("UnLock"); mCfgManagedScript.pop(mReuseLock, 1); mCfgManagedScript.unlock(mReuseLock); + mCFGscriptLockedByUS = false; + } else { + if (mCFGscriptLockedByUS) { + System.out.println("UnLock"); + mCfgManagedScript.pop(mReuseLock, 1); + mCfgManagedScript.unlock(mReuseLock); + mCFGscriptLockedByUS = false; + } + + System.out.println("NO REUSE TC Script CHecksat"); + mSatisfiable = mMgdScriptTc.getScript().checkSat(); } + // if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + // System.out.println("UnLock"); + // mCfgManagedScript.pop(mReuseLock, 1); + // mCfgManagedScript.unlock(mReuseLock); + // } if (mSatisfiable == LBool.UNKNOWN) { // System.out.println("UNKNOWN"); } From 6998d33abc19b5d7a098a1046b4b8253b4ab1a9e Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 19 Sep 2024 00:20:31 +0200 Subject: [PATCH 080/278] Reveted using cfg script for reuse, overhead too big --- .../AnnotateAndAssertCodeBlocks.java | 40 +---- ...nnotateAndAssertConjunctsOfCodeBlocks.java | 2 +- .../singletracecheck/AnnotateAndAsserter.java | 161 ++++++------------ ...ndAsserterWithStmtOrderPrioritization.java | 9 +- .../singletracecheck/TraceCheck.java | 62 +++---- 5 files changed, 83 insertions(+), 191 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java index 76128a5d215..a4349f5f5c9 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertCodeBlocks.java @@ -30,7 +30,6 @@ import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; -import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.tracecheckerutils.singletracecheck.TraceCheck.TraceCheckLock; import de.uni_freiburg.informatik.ultimate.logic.Annotation; @@ -50,10 +49,6 @@ public class AnnotateAndAssertCodeBlocks { protected final Script mScript; protected final ManagedScript mMgdScript; - protected ManagedScript mCfgManagedScript; // used for optimization during trace check, dann must not - // interdict - // interpolation - TermTransferrer mTermTransferrer = null; protected final Object mScriptLockOwner; protected final NestedWord mTrace; @@ -75,8 +70,7 @@ public class AnnotateAndAssertCodeBlocks { boolean mCfgMgdScriptTcLockedBySbElse = false; public AnnotateAndAssertCodeBlocks(final ManagedScript csToolkit, final TraceCheckLock scriptLockOwner, - final NestedFormulas nestedSSA, final ILogger logger, final ManagedScript cfgMgdScriptTc, - final Object reuseLock) { + final NestedFormulas nestedSSA, final ILogger logger) { mLogger = logger; mMgdScript = csToolkit; mScriptLockOwner = scriptLockOwner; @@ -84,13 +78,6 @@ public AnnotateAndAssertCodeBlocks(final ManagedScript csToolkit, final TraceChe mTrace = nestedSSA.getTrace(); mSSA = nestedSSA; - // For Reuse Solver call: - mCfgManagedScript = cfgMgdScriptTc; - mReuseLock = reuseLock; - if (mReuseLock != null && mCfgManagedScript != null) { - mTermTransferrer = new TermTransferrer(mMgdScript.getScript(), mCfgManagedScript.getScript()); - } - } protected Term annotateAndAssertPrecondition() { @@ -203,9 +190,6 @@ protected String oldVarAssignemntPendingReturnAnnotation(final int pendingContex } protected Term annotateAndAssertTerm(final Term term, final String name) { - if (mCfgManagedScript != null && mReuseLock != null && !mCfgMgdScriptTcLockedBySbElse) { - annotateAndAssertTermToCFGscript(term, name); - } assert term.getFreeVars().length == 0 : "Term has free vars"; final Annotation annot = new Annotation(":named", name); final Term annotTerm = mScript.annotate(term, annot); @@ -214,28 +198,6 @@ protected Term annotateAndAssertTerm(final Term term, final String name) { return constantRepresentingAnnotatedTerm; } - protected void annotateAndAssertTermToCFGscript(final Term term, final String name) { - assert term.getFreeVars().length == 0 : "Term has free vars"; - mTermTransferrer.transform(term); - final Annotation annot = new Annotation(":named", name); - final Term annotTerm = mCfgManagedScript.getScript().annotate(term, annot); - mCfgManagedScript.assertTerm(mReuseLock, annotTerm); - // final Term constantRepresentingAnnotatedTerm = mCFGMgdScriptTc.getScript().term(name); - - } - - public void setUpReuse(final ManagedScript cfgScript, final Object lock) { - if (mCfgManagedScript == null) { - mCfgManagedScript = cfgScript; - } - if (mReuseLock == null) { - mReuseLock = lock; - } - if (mReuseLock != null && mCfgManagedScript != null) { - mTermTransferrer = new TermTransferrer(mMgdScript.getScript(), mCfgManagedScript.getScript()); - } - } - /** * Represents one conjunct in an annotated SSA. The annotated term is the term submitted to the solver (we have to * use these named terms in order to obtain an unsatisfiable core). diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java index 996486af42d..7206cf69f13 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAssertConjunctsOfCodeBlocks.java @@ -74,7 +74,7 @@ public AnnotateAndAssertConjunctsOfCodeBlocks(final ManagedScript mgdScriptTc, f final NestedFormulas nestedSSA, final NestedFormulas nestedFormulas, final ILogger logger, final ManagedScript mgdScriptCfg) { - super(mgdScriptTc, scriptLockOwner, nestedSSA, logger, null, null); + super(mgdScriptTc, scriptLockOwner, nestedSSA, logger); mNestedFormulas = nestedFormulas; mCsToolkitPredicates = mgdScriptCfg; } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 04da39ac4cb..c24df8a2042 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -41,7 +41,6 @@ import de.uni_freiburg.informatik.ultimate.core.model.services.ILogger; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.structure.IAction; -import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.BitvectorUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtSortUtils; @@ -51,7 +50,6 @@ import de.uni_freiburg.informatik.ultimate.logic.ConstantTerm; import de.uni_freiburg.informatik.ultimate.logic.FunctionSymbol; import de.uni_freiburg.informatik.ultimate.logic.Rational; -import de.uni_freiburg.informatik.ultimate.logic.Script; import de.uni_freiburg.informatik.ultimate.logic.Script.LBool; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.plugins.generator.rcfgbuilder.cfg.Call; @@ -71,10 +69,7 @@ public class AnnotateAndAsserter { protected final ILogger mLogger; protected final ManagedScript mMgdScriptTc; - protected ManagedScript mCfgManagedScript; protected final NestedWord mTrace; - TermTransferrer mTermTransferrer = null; - Object mReuseLock; protected LBool mSatisfiable; protected final NestedFormulas mSSA; protected ModifiableNestedFormulas mAnnotSSA; @@ -96,55 +91,30 @@ public class AnnotateAndAsserter { private final Integer mHighestVaOrderInTrace = -1; private boolean reuseUnsatpossible; private final ArrayList> mValueAssignmentUsedForReuse = new ArrayList>(); - private final TraceCheckStatisticsGenerator mTraceCheckBenchmarkGenerator; private final TestGenReuseMode mTestGenReuseMode; - private boolean mReuseWithCFGscript = true; - private boolean mCFGscriptLockedByUS = false; public AnnotateAndAsserter(final ManagedScript mgdScriptTc, final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, - final IUltimateServiceProvider services, final ManagedScript cfgMgdScriptTc, final Object reuseLock, - final TraceCheckStatisticsGenerator traceCheckStatisticsGenerator, final boolean noReuse) { + final IUltimateServiceProvider services) { mServices = services; mLogger = mServices.getLoggingService().getLogger(TraceCheckerUtils.PLUGIN_ID); mMgdScriptTc = mgdScriptTc; - mCfgManagedScript = cfgMgdScriptTc; mTrace = nestedSSA.getTrace(); mSSA = nestedSSA; mAnnotateAndAssertCodeBlocks = aaacb; mTcbg = tcbg; - mTraceCheckBenchmarkGenerator = traceCheckStatisticsGenerator; - mReuseLock = reuseLock; - mTestGenReuseMode = RcfgPreferenceInitializer.getPreferences(services) .getEnum(RcfgPreferenceInitializer.LABEL_TEST_GEN_REUSE_MODE, TestGenReuseMode.class); - if (noReuse || mCfgManagedScript.isLocked() || mCfgManagedScript == null) { - mReuseWithCFGscript = false; - mAnnotateAndAssertCodeBlocks.mCfgMgdScriptTcLockedBySbElse = true; - } else { - mTermTransferrer = new TermTransferrer(mMgdScriptTc.getScript(), mCfgManagedScript.getScript()); - - // if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - mAnnotateAndAssertCodeBlocks.setUpReuse(cfgMgdScriptTc, reuseLock); - // } - } reuseUnsatpossible = mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix) || mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchCalloc); } public void buildAnnotatedSsaAndAssertTerms() { - mTraceCheckBenchmarkGenerator.reportTraceChecks(); + mTcbg.reportTraceChecks(); boolean reuse = false; - if (mReuseWithCFGscript) { - System.out.println("Lock"); - mCFGscriptLockedByUS = true; - mCfgManagedScript.lock(mReuseLock); - mCfgManagedScript.push(mReuseLock, 1); - - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - reuse = true; - } + if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { + reuse = true; } if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { @@ -300,8 +270,9 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (!vaPairsAsTerms.isEmpty()) { - final Term varAssignmentConjunction = SmtUtils.and(mCfgManagedScript.getScript(), vaPairsAsTerms); - mAnnotateAndAssertCodeBlocks.annotateAndAssertTermToCFGscript(varAssignmentConjunction, "Int"); + final Term varAssignmentConjunction = SmtUtils.and(mMgdScriptTc.getScript(), vaPairsAsTerms); + mMgdScriptTc.getScript().push(1); + mAnnotateAndAssertCodeBlocks.annotateAndAssertTerm(varAssignmentConjunction, "Int"); System.out.println("REUSE: " + varAssignmentConjunction); } else { reuse = false; // Can be empty if previous test goal is "behind" the current. (loops) @@ -313,28 +284,14 @@ public void buildAnnotatedSsaAndAssertTerms() { } if (reuse) { System.out.println("REUSE CFG Script CHecksat"); - mTraceCheckBenchmarkGenerator.reportReuseTried(); + mTcbg.reportReuseTried(); reuseCheckSAT(); - System.out.println("UnLock"); - mCfgManagedScript.pop(mReuseLock, 1); - mCfgManagedScript.unlock(mReuseLock); - mCFGscriptLockedByUS = false; - } else { - if (mCFGscriptLockedByUS) { - System.out.println("UnLock"); - mCfgManagedScript.pop(mReuseLock, 1); - mCfgManagedScript.unlock(mReuseLock); - mCFGscriptLockedByUS = false; - } + } else { System.out.println("NO REUSE TC Script CHecksat"); mSatisfiable = mMgdScriptTc.getScript().checkSat(); } - // if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - // System.out.println("UnLock"); - // mCfgManagedScript.pop(mReuseLock, 1); - // mCfgManagedScript.unlock(mReuseLock); - // } + if (mSatisfiable == LBool.UNKNOWN) { // System.out.println("UNKNOWN"); } @@ -350,13 +307,13 @@ public void buildAnnotatedSsaAndAssertTerms() { private void reuseCheckSAT() { System.out.println("trying to reuse"); - final LBool reuseResult = mCfgManagedScript.getScript().checkSat(); - System.out.println("REUSE Result: " + reuseResult); + mSatisfiable = mMgdScriptTc.getScript().checkSat(); + System.out.println("REUSE Result: " + mSatisfiable); - if (reuseResult == LBool.SAT) { + if (mSatisfiable == LBool.SAT) { // register "other branch" as not reachable with this VA. Add negated VA to other branch test goal System.out.println("REUSE SUCCESSFULL"); - mTraceCheckBenchmarkGenerator.reportSuccessfullReuse(); + mTcbg.reportSuccessfullReuse(); // We check the same branch twice, for branch encoder if (mCurrentVA.secondCheck == true) { mVAforReuse.mNegatedVA = !mVAforReuse.mNegatedVA; @@ -368,7 +325,7 @@ private void reuseCheckSAT() { mSucessfulReuse = true; // Since we do not create a counterexample after successfull reuse, we have to annotate here. mCurrentVA.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); - mSatisfiable = reuseResult; + } else { if (reuseUnsatpossible) { removeCheckIfCovered(); @@ -385,25 +342,19 @@ private void reuseCheckSAT() { mCurrentVA.secondCheck = true; } - private Term createTermFromVA(final String variableAsString, final Term valueTCscript) { - Term value = null; - if (valueTCscript != null) { - value = mTermTransferrer.transform(valueTCscript); - // value = mTermTransferrer.tr - } - - final Script reuseScript = mCfgManagedScript.getScript(); - FunctionSymbol varInCurrentScript = reuseScript.getTheory().getDeclaredFunctions().get(variableAsString); + private Term createTermFromVA(final String variableAsString, final Term value) { + FunctionSymbol varInCurrentScript = + mMgdScriptTc.getScript().getTheory().getDeclaredFunctions().get(variableAsString); if (varInCurrentScript == null) { - varInCurrentScript = - reuseScript.getTheory().getFunction(variableAsString.substring(1, variableAsString.length() - 1)); + varInCurrentScript = mMgdScriptTc.getScript().getTheory() + .getFunction(variableAsString.substring(1, variableAsString.length() - 1)); } if (varInCurrentScript == null) { throw new AssertionError("unknown var " + variableAsString); } - final Term nondetVar = SmtUtils.unfTerm(reuseScript, varInCurrentScript); + final Term nondetVar = SmtUtils.unfTerm(mMgdScriptTc.getScript(), varInCurrentScript); final Term nondetValue; @@ -413,7 +364,7 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs if (nondetVar.getSort().getIndices()[1].equals("24")) { if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - nondetValue = SmtUtils.unfTerm(reuseScript, valueAsAppterm.getFunction().getName(), + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), valueAsAppterm.getSort().getIndices(), null, valueAsAppterm.getParameters()); } else { // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) @@ -423,13 +374,14 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs indices[0] = "0"; indices[1] = "0"; - final Term bvConst0 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 1)); - final Term bvConst1 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 8)); - final Term bvConst2 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 23)); - nondetValue = SmtUtils.unfTerm(reuseScript, "fp", null, null, bvConst0, bvConst1, bvConst2); + final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); + final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 8)); + final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 23)); + nondetValue = + SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); // nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), "_ FloatingPoint 0 0", indices, // SmtSortUtils @@ -440,8 +392,8 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; - nondetValue = SmtUtils.unfTerm(reuseScript, valueAsAppterm.getFunction().getName(), null, null, - valueAsAppterm.getParameters()); + nondetValue = SmtUtils.unfTerm(mMgdScriptTc.getScript(), valueAsAppterm.getFunction().getName(), + null, null, valueAsAppterm.getParameters()); } else { // (fp (_ BitVec 1) (_ BitVec eb) (_ BitVec i) (_ FloatingPoint eb sb)) // (_ +zero 2 4) @@ -450,17 +402,14 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs indices[0] = "0"; indices[1] = "0"; - final Term bvConst0 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 1)); - final Term bvConst1 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 11)); - final Term bvConst2 = SmtUtils.rational2Term(reuseScript, Rational.ZERO, - SmtSortUtils.getBitvectorSort(reuseScript, 52)); - nondetValue = SmtUtils.unfTerm(reuseScript, "fp", null, null, bvConst0, bvConst1, bvConst2); - - // nondetValue = SmtUtils.unfTerm(reuseScript, "_ FloatingPoint 0 0", indices, - // SmtSortUtils - // .getFloatSort(reuseScript, BigInteger.valueOf(8), BigInteger.valueOf(23))); + final Term bvConst0 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 1)); + final Term bvConst1 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 11)); + final Term bvConst2 = SmtUtils.rational2Term(mMgdScriptTc.getScript(), Rational.ZERO, + SmtSortUtils.getBitvectorSort(mMgdScriptTc.getScript(), 52)); + nondetValue = + SmtUtils.unfTerm(mMgdScriptTc.getScript(), "fp", null, null, bvConst0, bvConst1, bvConst2); } @@ -474,11 +423,11 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs if (value != null) { final ApplicationTerm valueAsAppterm = (ApplicationTerm) value; final BigInteger constValue = new BigInteger(valueAsAppterm.getFunction().getName().substring(2)); - nondetValue = BitvectorUtils.constructTerm(reuseScript, + nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); } else { final BigInteger constValue = BigInteger.ZERO; - nondetValue = BitvectorUtils.constructTerm(reuseScript, + nondetValue = BitvectorUtils.constructTerm(mMgdScriptTc.getScript(), BitvectorUtils.constructBitvectorConstant(constValue, nondetVar.getSort())); } break; @@ -486,22 +435,22 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs case SmtSortUtils.INT_SORT: { if (value != null) { - nondetValue = SmtUtils.rational2Term(reuseScript, SmtUtils.toRational(((ConstantTerm) value)), - SmtSortUtils.getIntSort(mMgdScriptTc)); + nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), + SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getIntSort(mMgdScriptTc)); } else { - nondetValue = SmtUtils.constructIntegerValue(reuseScript, SmtSortUtils.getIntSort(mMgdScriptTc), - BigInteger.ZERO); + nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), + SmtSortUtils.getIntSort(mMgdScriptTc), BigInteger.ZERO); } break; } case SmtSortUtils.REAL_SORT: { if (value != null) { - nondetValue = SmtUtils.rational2Term(reuseScript, SmtUtils.toRational(((ConstantTerm) value)), - SmtSortUtils.getRealSort(mMgdScriptTc)); + nondetValue = SmtUtils.rational2Term(mMgdScriptTc.getScript(), + SmtUtils.toRational(((ConstantTerm) value)), SmtSortUtils.getRealSort(mMgdScriptTc)); } else { - nondetValue = SmtUtils.constructIntegerValue(reuseScript, SmtSortUtils.getRealSort(mMgdScriptTc), - BigInteger.ZERO); + nondetValue = SmtUtils.constructIntegerValue(mMgdScriptTc.getScript(), + SmtSortUtils.getRealSort(mMgdScriptTc), BigInteger.ZERO); } break; } @@ -510,7 +459,7 @@ private Term createTermFromVA(final String variableAsString, final Term valueTCs } } mValueAssignmentUsedForReuse.add(new Pair<>(nondetVar, nondetValue)); - return SmtUtils.binaryEquality(reuseScript, nondetVar, nondetValue); + return SmtUtils.binaryEquality(mMgdScriptTc.getScript(), nondetVar, nondetValue); } public LBool isInputSatisfiable() { @@ -624,7 +573,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { nondetPositionCount += 1; } if (inputBetweenTestGoals) { - mTraceCheckBenchmarkGenerator.reportInputVectorsExtended(); + mTcbg.reportInputVectorsExtended(); exportTest(testV); } return nondetsAsTerms; @@ -634,7 +583,7 @@ private ArrayList getNonDetsAsTermsReuseUNSAT() { private void exportTest(final TestVector testV) { try { if (!testV.isEmpty()) { - mTraceCheckBenchmarkGenerator.reportTestExported(); + mTcbg.reportTestExported(); TestExporter.getInstance().exportTests(testV, getUniqueIdentifierForTestCaseName(), true); } } catch (final Exception e) { @@ -662,8 +611,8 @@ private void removeCheckIfCovered() { if (mCurrentVA.mVAofOppositeBranch.mCoveredTestGoal) { return; } - mTraceCheckBenchmarkGenerator.reportSuccessfullReuse(); - mTraceCheckBenchmarkGenerator.reportUNSAToptimizations(); + mTcbg.reportSuccessfullReuse(); + mTcbg.reportUNSAToptimizations(); if (mVAforReuse.equals(mDefaultVA)) { System.out.println("OtherBranchRemoveCheckDefault"); mCurrentVA.mVAofOppositeBranch.removeCheck(); diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java index 0aefc9883ae..b8f5abdd45e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserterWithStmtOrderPrioritization.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.stream.Collectors; import de.uni_freiburg.informatik.ultimate.automata.nestedword.NestedWord; @@ -99,7 +100,7 @@ public AnnotateAndAsserterWithStmtOrderPrioritization(final ManagedScript mgdScr final NestedFormulas nestedSSA, final AnnotateAndAssertCodeBlocks aaacb, final TraceCheckStatisticsGenerator tcbg, final AssertCodeBlockOrder assertCodeBlocksOrder, final IUltimateServiceProvider services) { - super(mgdScriptTc, nestedSSA, aaacb, tcbg, services, null, null, null, true); + super(mgdScriptTc, nestedSSA, aaacb, tcbg, services); mAssertCodeBlocksOrder = assertCodeBlocksOrder; mCheckSat = 0; } @@ -143,10 +144,10 @@ private void dfsPartitionStatementsAccordingToDepth(final Integer lowerInd int i = lowerIndex; while (i < upperIndex) { // Is the current statement a loop entry? - if (rwt.getImage(pps.get(i)).size() >= 2 && rwt.getImage(pps.get(i)).higher(i) != null - && rwt.getImage(pps.get(i)).higher(i) < upperIndex) { + if (rwt.getImage(pps.get(i)).size() >= 2 && ((TreeSet) rwt.getImage(pps.get(i))).higher(i) != null + && ((TreeSet) rwt.getImage(pps.get(i))).higher(i) < upperIndex) { // the new upper index is the last occurrence of the same location - final int newUpperIndex = rwt.getImage(pps.get(i)).lower(upperIndex); + final int newUpperIndex = ((TreeSet) rwt.getImage(pps.get(i))).lower(upperIndex); addStmtPositionToDepth(depth + 1, depth2Statements, i); // we consider the subtrace from i+1 to newUpperIndex as a loop // and apply the partitioning recursively on the subtrace diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index f1b4accd698..33b060669ad 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -55,6 +55,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.transitions.UnmodifiableTransFormula; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheck; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheckPreferences.AssertCodeBlockOrder; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.tracecheck.ITraceCheckPreferences.AssertCodeBlockOrderType; @@ -131,7 +132,6 @@ public class TraceCheck implements ITraceCheck { protected final ManagedScript mCfgManagedScript; protected final ManagedScript mTcSmtManager; protected final TraceCheckLock mTraceCheckLock = new TraceCheckLock(); - protected final TraceCheckLock mReuseLock = new TraceCheckLock(); /** * Maps a procedure name to the set of global variables which may be modified by the procedure. The set of variables @@ -240,13 +240,9 @@ protected TraceCheck(final IPredicate precondition, final IPredicate postconditi cleanupAndUnlockSolver(); } } else if (computeRcfgProgramExecution && feasibilityResult.getLBool() == LBool.SAT) { - if (!mAAA.mSucessfulReuse) { - icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); - if (icfgProgramExecution != null) { - providesIcfgProgramExecution = true; - } - } else { - providesIcfgProgramExecution = false; + icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); + if (icfgProgramExecution != null) { + providesIcfgProgramExecution = true; } mTraceCheckFinished = true; } else if (!feasibilityResult.isSolverCrashed()) { @@ -331,8 +327,7 @@ protected FeasibilityCheckResult checkTrace() { mServices); } else { mAAA = new AnnotateAndAsserter<>(mTcSmtManager, ssa, getAnnotateAndAsserterCodeBlocks(ssa), - mTraceCheckBenchmarkGenerator, mServices, mCfgManagedScript, mReuseLock, - mTraceCheckBenchmarkGenerator, false); + mTraceCheckBenchmarkGenerator, mServices); // Report the asserted code blocks // mTraceCheckBenchmarkGenerator.reportnewAssertedCodeBlocks(mTrace.length()); } @@ -349,11 +344,6 @@ protected FeasibilityCheckResult checkTrace() { } result = new FeasibilityCheckResult(isSafe, tcru, false); } catch (final SMTLIBException e) { - if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { - System.out.println("UnLock"); - mCfgManagedScript.pop(mReuseLock, 1); - mCfgManagedScript.unlock(mReuseLock); - } if (!mServices.getProgressMonitorService().continueProcessing()) { // there was a cancellation request, probably responsible for // abnormal solver termination @@ -435,7 +425,7 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild final Map beMapping = new HashMap<>(); for (final TermVariable tv : tf.getBranchEncoders()) { final String nameOfConstant = NestedSsaBuilder.branchEncoderConstantName(tv, i); - final Term indexedBe = getIndexed(nameOfConstant); + final Term indexedBe = mTcSmtManager.getScript().term(nameOfConstant); final Term value = getValue(indexedBe); final Boolean booleanValue = getBooleanValue(value); beMapping.put(tv, booleanValue); @@ -450,13 +440,12 @@ private IcfgProgramExecution computeRcfgProgramExecution(final NestedSsaBuild } final Function funGetValue; - // TODO check if this works - // if (mCfgManagedScript != mTcSmtManager) { - // funGetValue = a -> new TermTransferrer(mTcSmtManager.getScript(), mCfgManagedScript.getScript()) - // .transform(getValue(a)); - // } else { - funGetValue = this::getValue; - // } + if (mCfgManagedScript != mTcSmtManager) { + funGetValue = a -> new TermTransferrer(mTcSmtManager.getScript(), mCfgManagedScript.getScript()) + .transform(getValue(a)); + } else { + funGetValue = this::getValue; + } final boolean mTestGeneration = true; if (mTestGeneration && !mAAA.mSucessfulReuse) { // TODO check for bugs @@ -518,11 +507,12 @@ private TestVector extractTestVector(final NestedSsaBuilder nsb, final Functi if (m.find()) { final String type = m.group(1); testV.addValueAssignment(valueT, index, type); - + final TermTransferrer test = new TermTransferrer( + mCfgManagedScript.getScript(), mTcSmtManager.getScript()); final Term varEqValue = SmtUtils.binaryEquality(mTcSmtManager.getScript(), - indexedVar, valueT); - final Pair varValuePair = - new Pair(indexedVar, valueT); + test.transform(indexedVar), test.transform(valueT)); + final Pair varValuePair = new Pair( + test.transform(indexedVar), test.transform(valueT)); varAssignmentPair.add(varValuePair); varAssignment.add(varEqValue); } @@ -573,17 +563,7 @@ private void exportTest(final TestVector testV, final String identifier, final b } protected AnnotateAndAssertCodeBlocks getAnnotateAndAsserterCodeBlocks(final NestedFormulas ssa) { - if (mTestGenReuseMode.equals(TestGenReuseMode.None)) { - return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger, null, null); - } else { - return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger, mCfgManagedScript, - mReuseLock); - } - - } - - private Term getIndexed(final String nameOfConstant) { - return mTcSmtManager.getScript().term(nameOfConstant); + return new AnnotateAndAssertCodeBlocks<>(mTcSmtManager, mTraceCheckLock, ssa, mLogger); } private Term getValue(final Term term) { @@ -651,9 +631,9 @@ private void lockAndPrepareSolverForTraceCheck() { protected void cleanupAndUnlockSolver() { mTcSmtManager.echo(mTraceCheckLock, new QuotedObject("finished trace check")); - // if (mAAA.mSucessfulReuse) { - // mTcSmtManager.pop(mTraceCheckLock, 1); - // } + if (mAAA.mSucessfulReuse) { + mTcSmtManager.pop(mTraceCheckLock, 1); + } mAAA.mSucessfulReuse = false; mTcSmtManager.pop(mTraceCheckLock, 1); mTcSmtManager.unlock(mTraceCheckLock); From 8a4f03cdb1f0911b7ab5c3dc45904e470d598cc6 Mon Sep 17 00:00:00 2001 From: Max barth Date: Thu, 19 Sep 2024 00:42:47 +0200 Subject: [PATCH 081/278] fix forgott to pop() and provide no programExecution in case of reuse --- .../singletracecheck/AnnotateAndAsserter.java | 1 + .../singletracecheck/TraceCheck.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index c24df8a2042..7e1bb4a4fb4 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -327,6 +327,7 @@ private void reuseCheckSAT() { mCurrentVA.setVa(mValueAssignmentUsedForReuse, mHighestVaOrderInTrace, mVAsInPrefix); } else { + mMgdScriptTc.getScript().pop(1); if (reuseUnsatpossible) { removeCheckIfCovered(); } diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java index 33b060669ad..4bb6cca8a2e 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TraceCheck.java @@ -240,9 +240,16 @@ protected TraceCheck(final IPredicate precondition, final IPredicate postconditi cleanupAndUnlockSolver(); } } else if (computeRcfgProgramExecution && feasibilityResult.getLBool() == LBool.SAT) { - icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); - if (icfgProgramExecution != null) { - providesIcfgProgramExecution = true; + if (!mAAA.mSucessfulReuse) { + icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); + if (icfgProgramExecution != null) { + providesIcfgProgramExecution = true; + } + } else { + providesIcfgProgramExecution = false; + // icfgProgramExecution = computeRcfgProgramExecutionAndDecodeBranches(managedScriptTc); + // if (icfgProgramExecution != null) { + // providesIcfgProgramExecution = true; } mTraceCheckFinished = true; } else if (!feasibilityResult.isSolverCrashed()) { From 4c3e5e064e023840b12ba05a70fc5804891ca439 Mon Sep 17 00:00:00 2001 From: Max barth Date: Sat, 21 Sep 2024 15:05:47 +0200 Subject: [PATCH 082/278] Fixed that we reuse for the first goal again --- .../singletracecheck/AnnotateAndAsserter.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java index 7e1bb4a4fb4..0dd58026e60 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/AnnotateAndAsserter.java @@ -120,7 +120,7 @@ public void buildAnnotatedSsaAndAssertTerms() { if (mTestGenReuseMode.equals(TestGenReuseMode.ReuseUNSATmatchPrefix)) { getReuseCandidate(); if (mVAforReuse == null) { - reuse = false; + reuse = true; } } if (mAnnotSSA != null) { @@ -154,6 +154,7 @@ public void buildAnnotatedSsaAndAssertTerms() { } // ensure we are not considering currentVA as reuseCandidate + if (i < mTrace.length() - 1 && !mTestGenReuseMode.equals(TestGenReuseMode.None)) { // calling loc version @@ -244,12 +245,13 @@ public void buildAnnotatedSsaAndAssertTerms() { if (!mTestGenReuseMode.equals(TestGenReuseMode.None)) { getCurrentVA(); - if (mCurrentVA != null && mVAforReuse == null && reuseUnsatpossible) { + + if (mCurrentVA != null && mVAforReuse == null && reuseUnsatpossible && branchCount == 0) { mDefaultVA = mCurrentVA.setDefaultVa(mDefaultVA); mDefaultVA = mCurrentVA.mVAofOppositeBranch.setDefaultVa(mDefaultVA); mVAforReuse = mDefaultVA; + reuse = true; } - if (nondetsInTrace.isEmpty() || mCurrentVA == null || mVAforReuse == null) { reuse = false; } else if (mVAforReuse.mNegatedVA) { @@ -257,9 +259,10 @@ public void buildAnnotatedSsaAndAssertTerms() { } else if (mCurrentVA.mUnsatWithVAs.contains(mVAforReuse) && mVAforReuse.mNegatedVA == false) { reuse = false; // Wie kann das überhaupt sein? // System.out.println("NO REUSE since UNSAT With"); - } else if (mVAforReuse.mVarAssignmentPair.isEmpty()) { + } else if (mVAforReuse.mVarAssignmentPair.isEmpty() && !mVAforReuse.equals(mDefaultVA)) { reuse = false; - } else if (reuse) { + } + if (reuse) { ArrayList vaPairsAsTerms; if (mTestGenReuseMode.equals(TestGenReuseMode.Reuse) || !reuseUnsatpossible) { vaPairsAsTerms = getNonDetsAsTermsReuse(); @@ -331,7 +334,7 @@ private void reuseCheckSAT() { if (reuseUnsatpossible) { removeCheckIfCovered(); } - if (mCurrentVA.secondCheck == true) { + if (mCurrentVA.secondCheck == true) { // can this even be the case? mVAforReuse.mNegatedVA = false; } else { mVAforReuse.mNegatedVA = true; From f0e5242aeb78b8a103248a6a2465ea14c4bfa452 Mon Sep 17 00:00:00 2001 From: Max barth Date: Mon, 30 Sep 2024 22:18:52 +0200 Subject: [PATCH 083/278] Switch Floats and Double. Why was it the other way around? --- .../lib/tracecheckerutils/singletracecheck/TestExporter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index 8c457b00cc9..d5823a38d98 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -320,7 +320,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St String valueInRange = null; switch (valueTerm.getSort().getName()) { case SmtSortUtils.FLOATINGPOINT_SORT: { - if (type.equals("double")) { // if (type.equals("float")) { + if (type.equals("float")) { if (((ApplicationTerm) valueTerm).getParameters().length == 3) { assert valueTerm instanceof ApplicationTerm; // final ApplicationTerm cva = (ApplicationTerm) valueTerm; @@ -355,7 +355,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } break; } - } else { // if (type.equals("double")) { + } else if (type.equals("double")) { assert valueTerm instanceof ApplicationTerm; if (((ApplicationTerm) valueTerm).getParameters().length == 3) { final ApplicationTerm cva = (ApplicationTerm) valueTerm; @@ -443,7 +443,6 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St valueInRange = valueTerm.toStringDirect().replaceAll("[\\(\\)\\s]", ""); if (valueInRange.contains(".")) { valueInRange = valueInRange.split("\\.")[0]; - } final BigInteger value = new BigInteger(valueInRange); if (type.equals("long")) { From 222e02f91d7a2d6db45d4f4bb296216e08c40854 Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 1 Oct 2024 10:44:59 +0200 Subject: [PATCH 084/278] Test Export: Potential fix for Floats --- .../singletracecheck/TestExporter.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java index d5823a38d98..16fee0f4691 100644 --- a/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java +++ b/trunk/source/Library-TraceCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/tracecheckerutils/singletracecheck/TestExporter.java @@ -337,7 +337,7 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St // significant = significant.replaceAll("[^01]", ""); // final String floatAsBitString = sign + exponent + significant; // final int intBits = Integer.parseInt(floatAsBitString, 2); - final int intBits = (int) Long.parseLong(floatAsBitString, 2); + final int intBits = new BigInteger(floatAsBitString, 2).intValue(); final float asFloat = Float.intBitsToFloat(intBits); valueInRange = asFloat + ""; break; @@ -393,6 +393,31 @@ private void addToLinkedList(final Integer index, final Term valueTerm, final St } case SmtSortUtils.BITVECTOR_SORT: { + if (valueTerm.toStringDirect().startsWith("(fp")) { + if (((ApplicationTerm) valueTerm).getParameters().length == 3) { + assert valueTerm instanceof ApplicationTerm; + // final ApplicationTerm cva = (ApplicationTerm) valueTerm; + final String bitString = valueTerm.toStringDirect(); + final String floatAsBitString = bitString.replaceAll("[^01]", ""); + + // String sign = cva.getParameters()[0].toStringDirect(); + // sign = sign.replaceAll("[^01]", ""); + // + // String exponent = cva.getParameters()[1].toStringDirect(); + // exponent = exponent.replaceAll("[^01]", ""); + // + // String significant = cva.getParameters()[2].toStringDirect(); + // significant = significant.replaceAll("[^01]", ""); + // final String floatAsBitString = sign + exponent + significant; + // final int intBits = Integer.parseInt(floatAsBitString, 2); + final int intBits = new BigInteger(floatAsBitString, 2).intValue(); + final float myFloat = Float.intBitsToFloat(intBits); + + valueInRange = myFloat + ""; + break; + } + } + final Matcher m = Pattern.compile("\\(_\\sbv(\\d+)\\s\\d+\\)").matcher(valueTerm.toStringDirect()); m.find(); valueInRange = m.group(1); From 71f30c0d7cc91030e37b4d5d472635b317ea1ccc Mon Sep 17 00:00:00 2001 From: Max barth Date: Tue, 29 Oct 2024 22:18:10 +0100 Subject: [PATCH 085/278] Parallel Trace Abstraction v1 --- .../boogie/Boogie2SmtSymbolTable.java | 15 +- .../modelcheckerutils/cfg/CfgSmtToolkit.java | 7 + .../cfg/ModifiableGlobalsTable.java | 19 +- .../cfg/transitions/TransFormulaBuilder.java | 56 ++- .../cfg/transitions/TransFormulaUtils.java | 56 ++- .../transitions/UnmodifiableTransFormula.java | 41 ++ .../IncrementalHoareTripleChecker.java | 81 ++-- .../MonolithicHoareTripleChecker.java | 1 + .../smt/MonolithicImplicationChecker.java | 34 +- .../smt/predicates/BasicPredicateFactory.java | 23 ++ .../smt/predicates/PredicateTransformer.java | 204 +++++++++- .../smt/predicates/PredicateUnifier.java | 44 ++- .../smt/predicates/PredicateUtils.java | 183 ++++++++- .../TermDomainOperationProvider.java | 10 + .../smt/predicates/TermVarsProc.java | 39 +- .../HistoryRecordingScript.java | 356 +++++++++++++++++- .../PartialQuantifierElimination.java | 83 +++- .../IterativePredicateTransformer.java | 1 + .../AnnotateAndAssertCodeBlocks.java | 74 +++- ...nnotateAndAssertConjunctsOfCodeBlocks.java | 14 +- .../InterpolatingTraceCheckCraig.java | 14 +- .../NestedInterpolantsBuilder.java | 35 +- .../singletracecheck/NestedSsaBuilder.java | 38 +- .../singletracecheck/TraceCheckSpWp.java | 31 +- .../core/lib/util/MonitoredProcess.java | 13 +- .../ultimate/core/model/services/ILogger.java | 6 +- .../traceabstraction/AbstractCegarLoop.java | 8 +- .../traceabstraction/BasicCegarLoop.java | 12 +- .../traceabstraction/CegarLoopFactory.java | 9 +- .../traceabstraction/NwaCegarLoop.java | 10 +- .../tracehandling/StrategyFactory.java | 20 +- 31 files changed, 1375 insertions(+), 162 deletions(-) diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/boogie/Boogie2SmtSymbolTable.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/boogie/Boogie2SmtSymbolTable.java index 8022c242568..56f5d10f93e 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/boogie/Boogie2SmtSymbolTable.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/boogie/Boogie2SmtSymbolTable.java @@ -83,12 +83,11 @@ import de.uni_freiburg.informatik.ultimate.util.datastructures.relation.HashRelation; /** - * Stores a mapping from Boogie identifiers to {@link ProgramVar}s and a mapping - * from TermVariables that are representatives of {@link ProgramVar}s to their - * {@link ProgramVar}. + * Stores a mapping from Boogie identifiers to {@link ProgramVar}s and a mapping from TermVariables that are + * representatives of {@link ProgramVar}s to their {@link ProgramVar}. * - * TODO 2018-09-15 Matthias: This class was build before we had - * {@link DeclarationInformation} and might be unnecessarily complicated. + * TODO 2018-09-15 Matthias: This class was build before we had {@link DeclarationInformation} and might be + * unnecessarily complicated. * * @author Matthias Heizmann * @@ -647,7 +646,8 @@ private void declareParams(final String procId, final VarList[] vl, final IBoogieType type = vl[i].getType().getBoogieType(); final String[] ids = vl[i].getIdentifiers(); for (int j = 0; j < ids.length; j++) { - final LocalProgramVar pv = constructLocalProgramVar(ids[j], procId, type, vl[i], declarationInformation); + final LocalProgramVar pv = + constructLocalProgramVar(ids[j], procId, type, vl[i], declarationInformation); putNew(procId, ids[j], pv, specMap); params.add(pv); } @@ -790,4 +790,7 @@ private static Stream getAll(final Map> map, fi return map.entrySet().stream().flatMap(a -> a.getValue().entrySet().stream()).map(a -> fun.apply(a.getValue())); } + public Map getSmtVar2ProgramVarMap() { + return mSmtVar2ProgramVar; + } } diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/CfgSmtToolkit.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/CfgSmtToolkit.java index 064adf5d457..5c65b784732 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/CfgSmtToolkit.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/CfgSmtToolkit.java @@ -80,6 +80,13 @@ public ManagedScript getManagedScript() { return mManagedScript; } + public CfgSmtToolkit getCfgSmtToolkitWithFreshScript(final IUltimateServiceProvider services, + final SolverSettings solverSettings) { + return new CfgSmtToolkit(mModifiableGlobalsTable, createFreshManagedScript(services, solverSettings), + mSymbolTable, mProcedures, mInParams, mInParams, mIcfgEdgeFactory, mConcurrencyInformation, + mSmtFunctionsAndAxioms); + } + /** * Similar to {@link CfgSmtToolkit#createFreshManagedScript(SolverSettings, String)}, but use a default solver id as * defined in {@link SolverSettings}. diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/ModifiableGlobalsTable.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/ModifiableGlobalsTable.java index 04340d16ca3..a56d8f223ab 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/ModifiableGlobalsTable.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/ModifiableGlobalsTable.java @@ -33,6 +33,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramOldVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.logic.Script; import de.uni_freiburg.informatik.ultimate.logic.Term; @@ -102,10 +103,24 @@ public static Term constructConstantOldVarEquality(final IProgramNonOldVar bv, f return SmtUtils.binaryEquality(script, oldConstant, nonOldConstant); } + /** + * Return equality (= g oldg) where g is the default constant of the BoogieNonOldVar bv and oldg is the default + * constant of the corresponding oldVar. If primed is true, we return the primed constant instead of the default + * constant. + * + * @param termTransfer + */ + public static Term transferredConstructConstantOldVarEquality(final TermTransferrer termTransfer, + final IProgramNonOldVar bv, final boolean primed, final Script script) { + final IProgramOldVar oldVar = bv.getOldVar(); + final Term nonOldConstant = termTransfer.transform((primed ? bv.getPrimedConstant() : bv.getDefaultConstant())); + final Term oldConstant = + termTransfer.transform((primed ? oldVar.getPrimedConstant() : oldVar.getDefaultConstant())); + return SmtUtils.binaryEquality(script, oldConstant, nonOldConstant); + } /** - * @return - * the contents of this ModifiedGlobalsTable as a hash relation + * @return the contents of this ModifiedGlobalsTable as a hash relation */ public HashRelation getProcToGlobals() { // if we have an unmodifiableHashRelation some day, use that diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaBuilder.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaBuilder.java index b5a84a32b1c..ad991577a79 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaBuilder.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaBuilder.java @@ -46,6 +46,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.TransferrerWithVariableCache; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.TermVarsProc; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; @@ -63,11 +64,11 @@ * @author Matthias Heizmann (heizmann@informatik.uni-freiburg.de) */ public class TransFormulaBuilder { - private final Map mInVars; - private final Map mOutVars; - private final Set mNonTheoryConsts; - private final Set mAuxVars; - private final Set mBranchEncoders; + private Map mInVars; + private Map mOutVars; + private Set mNonTheoryConsts; + private Set mAuxVars; + private Set mBranchEncoders; private Infeasibility mInfeasibility = null; private Term mFormula = null; private boolean mConstructionFinished = false; @@ -308,6 +309,40 @@ public void ensureInternalNormalForm() { } } + private void transferEverythingToWorker(final ManagedScript script) { + if (((HistoryRecordingScript) script.getScript()).getMainScript() != null) { + + final TermTransferrer termTF = new TermTransferrer( + ((HistoryRecordingScript) script.getScript()).getMainScript().getScript(), (script.getScript())); + + mFormula = termTF.transform(mFormula); + mInVars = transferMap(termTF, mInVars); + mOutVars = transferMap(termTF, mOutVars); + mAuxVars = transferSet(termTF, mAuxVars); + mBranchEncoders = transferSet(termTF, mBranchEncoders); + + } else { + return; + } + } + + private Map transferMap(final TermTransferrer termTF, + final Map inputMap) { + final HashMap outMap = new HashMap<>(); + for (final Entry entry : inputMap.entrySet()) { + outMap.put(entry.getKey(), (TermVariable) termTF.transform(entry.getValue())); + } + return outMap; + } + + private Set transferSet(final TermTransferrer termTF, final Set inputSet) { + final Set outSet = new HashSet<>(); + for (final TermVariable var : inputSet) { + outSet.add((TermVariable) termTF.transform(var)); + } + return outSet; + } + public UnmodifiableTransFormula finishConstruction(final ManagedScript script) { if (mFormula == null) { throw new IllegalStateException("cannot finish without formula"); @@ -316,10 +351,15 @@ public UnmodifiableTransFormula finishConstruction(final ManagedScript script) { throw new IllegalStateException("cannot finish without feasibility status"); } mConstructionFinished = true; + + transferEverythingToWorker(script); + removeSuperfluousVars(mFormula, mInVars, mOutVars, mAuxVars); + return new UnmodifiableTransFormula(mFormula, Collections.unmodifiableMap(mInVars), Collections.unmodifiableMap(mOutVars), ImmutableSet.of(mNonTheoryConsts), ImmutableSet.of(mAuxVars), ImmutableSet.of(mBranchEncoders), mInfeasibility, script); + } /** @@ -707,7 +747,7 @@ public static UnmodifiableTransFormula transferTransformula(final TransferrerWit final TermVariable newTv; if (entry.getValue() == tf.getInVars().get(entry.getKey())) { - //inVar and outVar are similar + // inVar and outVar are similar newTv = newInVars.get(newPv); } else { if (constructFreshVariables) { @@ -722,8 +762,8 @@ public static UnmodifiableTransFormula transferTransformula(final TransferrerWit final Set newAuxVars = new HashSet<>(); for (final TermVariable auxVar : tf.getAuxVars()) { - final TermVariable newAuxVar = script.constructFreshTermVariable("auxVar", - tt.getTransferrer().transferSort(auxVar.getSort())); + final TermVariable newAuxVar = + script.constructFreshTermVariable("auxVar", tt.getTransferrer().transferSort(auxVar.getSort())); tt.getTransferrer().getTransferMapping().put(auxVar, newAuxVar); newAuxVars.add(newAuxVar); } diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaUtils.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaUtils.java index 2249401866d..1dc3cfa6c03 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaUtils.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/TransFormulaUtils.java @@ -60,6 +60,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.PredicateTransformer; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.TermDomainOperationProvider; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.DagSizePrinter; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.IncrementalPlicationChecker.Validity; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; @@ -944,8 +946,8 @@ public static UnmodifiableTransFormula negate(final UnmodifiableTransFormula tf, if (!tf.getBranchEncoders().isEmpty()) { throw new AssertionError("I think this does not make sense with branch enconders"); } - final Term withoutAuxVars = quantifyAndTryToEliminateAuxVars(services, mgdScript, tf.getFormula(), - tf.getAuxVars()); + final Term withoutAuxVars = + quantifyAndTryToEliminateAuxVars(services, mgdScript, tf.getFormula(), tf.getAuxVars()); final Term formula = SmtUtils.not(mgdScript.getScript(), withoutAuxVars); final TransFormulaBuilder tfb = new TransFormulaBuilder(tf.getInVars(), tf.getOutVars(), @@ -957,9 +959,8 @@ public static UnmodifiableTransFormula negate(final UnmodifiableTransFormula tf, } /** - * Given a list of {@link UnmodifiableTransFormula}s tf1,..., tfn that represent - * relations R1,...,Rn, construct a {@link UnmodifiableTransFormula} that - * represents the intersection R1∩...∩Rn. + * Given a list of {@link UnmodifiableTransFormula}s tf1,..., tfn that represent relations R1,...,Rn, construct a + * {@link UnmodifiableTransFormula} that represents the intersection R1∩...∩Rn. */ public static UnmodifiableTransFormula intersect(final ManagedScript mgdScript, final UnmodifiableTransFormula... tfs) { @@ -978,16 +979,15 @@ public static UnmodifiableTransFormula intersect(final ManagedScript mgdScript, } /** - * Given term and auxvars of a {@link Transformula}. Quantify all auxvars - * existentially and try to eliminate quantifiers. + * Given term and auxvars of a {@link Transformula}. Quantify all auxvars existentially and try to eliminate + * quantifiers. * - * TODO 20220720 Matthias: Fix POLY_PAC as simplification? Maybe this and the - * elimination procedure should become a parameter of this method. + * TODO 20220720 Matthias: Fix POLY_PAC as simplification? Maybe this and the elimination procedure should become a + * parameter of this method. */ private static Term quantifyAndTryToEliminateAuxVars(final IUltimateServiceProvider services, final ManagedScript maScript, final Term term, final Set auxVars) { - final Term quantifiedTerm = - SmtUtils.quantifier(maScript.getScript(), QuantifiedFormula.EXISTS, auxVars, term); + final Term quantifiedTerm = SmtUtils.quantifier(maScript.getScript(), QuantifiedFormula.EXISTS, auxVars, term); final Term resultTerm = PartialQuantifierElimination.eliminate(services, maScript, quantifiedTerm, SimplificationTechnique.POLY_PAC); return resultTerm; @@ -1268,6 +1268,15 @@ public static String prettyPrint(final TransFormula tf) { return sb.toString(); } + private static Set transferSet(final TermTransferrer termTF, final Set inputSet) { + final Set outSet = new HashSet<>(); + for (final TermVariable var : inputSet) { + // maybe we could use the TV mapping from historyrecordingscript + outSet.add((TermVariable) termTF.transform(var)); + } + return outSet; + } + /** * Replace each term of the form (store a k v) by the conjunction (store a k aux) /\ (= aux v) for a fresh auxiliary * variable aux. Motivation: The term (store a k v) carries two information: (1) This term and the array a are @@ -1277,14 +1286,33 @@ public static String prettyPrint(final TransFormula tf) { */ public static UnmodifiableTransFormula decoupleArrayValues(final UnmodifiableTransFormula tf, final ManagedScript mgdScript) { - final Map oldAuxVar2newAuxVar = mgdScript.constructFreshCopies(tf.getAuxVars()); - final Term renamed = Substitution.apply(mgdScript, oldAuxVar2newAuxVar, tf.getFormula()); - final Triple, List> decoupled = decoupleArrayValues(renamed, mgdScript); + + Set auxVars = tf.getAuxVars(); + Term formula = tf.getFormula(); + + if (((HistoryRecordingScript) mgdScript.getScript()).getMainScript() != null) { + + final TermTransferrer termTF = + new TermTransferrer(((HistoryRecordingScript) mgdScript.getScript()).getMainScript().getScript(), + (mgdScript.getScript())); + + formula = termTF.transform(tf.getFormula()); + + auxVars = transferSet(termTF, auxVars); + } + final TransFormulaBuilder tfb = new TransFormulaBuilder(tf.getInVars(), tf.getOutVars(), false, tf.getNonTheoryConsts(), false, tf.getBranchEncoders(), false); + + final Map oldAuxVar2newAuxVar = mgdScript.constructFreshCopies(auxVars); + final Term renamed = Substitution.apply(mgdScript, oldAuxVar2newAuxVar, formula); + final Triple, List> decoupled = decoupleArrayValues(renamed, mgdScript); + final ArrayList resultConjuncts = new ArrayList<>(decoupled.getThird()); resultConjuncts.add(decoupled.getFirst()); + final Term resultTerm = SmtUtils.and(mgdScript.getScript(), resultConjuncts); + tfb.setFormula(resultTerm); for (final TermVariable auxVar : oldAuxVar2newAuxVar.values()) { tfb.addAuxVar(auxVar); diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/UnmodifiableTransFormula.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/UnmodifiableTransFormula.java index 47a7fd9dc3f..c5524246849 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/UnmodifiableTransFormula.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/cfg/transitions/UnmodifiableTransFormula.java @@ -39,6 +39,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramConst; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.ProgramVarUtils; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.Substitution; @@ -116,6 +118,11 @@ public enum Infeasibility { */ public static Term computeClosedFormula(final Term formula, final Map inVars, final Map outVars, final Set auxVars, final ManagedScript script) { + + if (((HistoryRecordingScript) script.getScript()).getMainScript() != null) { + return transferAndComputeClosedFormula(formula, inVars, outVars, auxVars, script); + } + final Map substitutionMapping = new HashMap<>(); for (final Entry entry : inVars.entrySet()) { final TermVariable inTermVar = entry.getValue(); @@ -138,6 +145,40 @@ public static Term computeClosedFormula(final Term formula, final Map inVars, + final Map outVars, final Set auxVars, final ManagedScript script) { + final TermTransferrer termTF = new TermTransferrer( + ((HistoryRecordingScript) script.getScript()).getMainScript().getScript(), (script.getScript())); + + final Map substitutionMapping = new HashMap<>(); + for (final Entry entry : inVars.entrySet()) { + final TermVariable inTermVar = entry.getValue(); + assert !substitutionMapping.containsKey(inTermVar); + assert inTermVar.getTheory().equals(script.getScript().getTheory()); + substitutionMapping.put(inTermVar, termTF.transform(getConstantForInVar(entry.getKey()))); + } + for (final Entry entry : outVars.entrySet()) { + final IProgramVar outVar = entry.getKey(); + final TermVariable outTermVar = entry.getValue(); + assert outTermVar.getTheory().equals(script.getScript().getTheory()); + if (inVars.get(outVar) == outTermVar) { + // is handled above + continue; + } + substitutionMapping.put(outTermVar, + termTF.transform(getConstantForOutVar(entry.getKey(), inVars, outVars))); + } + for (final TermVariable auxVarTv : auxVars) { + final Term auxVarConst = ProgramVarUtils.constructConstantForAuxVar(script, auxVarTv); + assert auxVarConst.getTheory().equals(script.getScript().getTheory()); + assert auxVarTv.getTheory().equals(script.getScript().getTheory()); + substitutionMapping.put(auxVarTv, auxVarConst); + } + + assert formula.getTheory().equals(script.getScript().getTheory()); + return Substitution.apply(script, substitutionMapping, formula); + } + /** * Return the constant (resp. 0-ary function symbol) that represents the inVar of the {@link IProgramVar} pv in the * closed form of the formula of an {@link UnmodifiableTransFormula}. diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/hoaretriple/IncrementalHoareTripleChecker.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/hoaretriple/IncrementalHoareTripleChecker.java index adeabbaff28..ada9c264089 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/hoaretriple/IncrementalHoareTripleChecker.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/hoaretriple/IncrementalHoareTripleChecker.java @@ -54,6 +54,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.ProgramVarUtils; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.IPredicate; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.IncrementalPlicationChecker; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.IncrementalPlicationChecker.Validity; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; @@ -282,7 +284,8 @@ public void clearAssertionStack() { @Override public void releaseLock() { clearAssertionStack(); - assert !mManagedScript.isLocked() : "script should not be locked"; + assert !mManagedScript.isLocked() : "script should not be locked! Thread: " + Thread.currentThread().getId() + + " Script: " + mManagedScript; } private LBool assertPrecondition(final IPredicate p) { @@ -561,7 +564,20 @@ private LBool assertPostcondInternal(final IPredicate p) { public static Term constructPostcondFormula(final IPredicate p, final IInternalAction action, final ModifiableGlobalsTable mgt, final ManagedScript mgdScript, final Object lock) { final Set assignedVars = action.getTransformula().getAssignedVars(); - Term renamedFormula = renameVarsToPrimedConstants(assignedVars, p.getFormula(), mgdScript, lock); + + final Term predicateFormula = p.getFormula(); + /* + * Warning, WorkerPredicateFactory without term transferrer produces worker predicates + * Thus after synchro we need them to be moved to main script + * + * Maybe we can change IPredicate to deal with these cases + */ + if (((HistoryRecordingScript) mgdScript.getScript()).mAfterSynchronisation) { + assert p.getFormula().getTheory() + .equals(((HistoryRecordingScript) mgdScript.getScript()).getMainScript().getScript().getTheory()); + } + + Term renamedFormula = renameVarsToPrimedConstants(assignedVars, predicateFormula, mgdScript, lock); final String succProc = action.getSucceedingProcedure(); final Set modifiableGlobals = mgt.getModifiedBoogieVars(succProc); renamedFormula = renameNonModifiableOldGlobalsToDefaultConstantOfNonOldVar(p.getVars(), modifiableGlobals, @@ -767,8 +783,8 @@ private static Term renameVarsToDefaultConstants(final Set replacees = new ArrayList<>(); final ArrayList replacers = new ArrayList<>(); for (final IProgramVar bv : set) { - replacees.add(bv.getTermVariable()); - replacers.add(bv.getDefaultConstant()); + replacees.add((TermVariable) transferBoogieVarOrConstStatic(managedScript, bv.getTermVariable())); + replacers.add(transferBoogieVarOrConstStatic(managedScript, bv.getDefaultConstant())); } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); final Term[] values = replacers.toArray(new Term[replacers.size()]); @@ -780,8 +796,8 @@ private Term renameVarsToDefaultConstants(final Map b final ArrayList replacers = new ArrayList<>(); for (final Entry bv : bv2tv.entrySet()) { - replacees.add(bv.getValue()); - replacers.add(bv.getKey().getDefaultConstant()); + replacees.add((TermVariable) transferBoogieVarOrConst(bv.getValue())); + replacers.add(transferBoogieVarOrConst(bv.getKey().getDefaultConstant())); } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); final Term[] values = replacers.toArray(new Term[replacers.size()]); @@ -793,14 +809,35 @@ private static Term renameVarsToPrimedConstants(final Set boogieVar final ArrayList replacees = new ArrayList<>(); final ArrayList replacers = new ArrayList<>(); for (final IProgramVar bv : boogieVars) { - replacees.add(bv.getTermVariable()); - replacers.add(bv.getPrimedConstant()); + + replacees.add((TermVariable) transferBoogieVarOrConstStatic(managedScript, bv.getTermVariable())); + replacers.add(transferBoogieVarOrConstStatic(managedScript, bv.getPrimedConstant())); } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); final Term[] values = replacers.toArray(new Term[replacers.size()]); return managedScript.let(lock, vars, values, formula); } + private Term transferBoogieVarOrConst(Term bvVarOrConst) { + if (((HistoryRecordingScript) mManagedScript.getScript()).getMainScript() != null) { + final TermTransferrer tf = new TermTransferrer( + ((HistoryRecordingScript) mManagedScript.getScript()).getMainScript().getScript(), + (mManagedScript.getScript())); + bvVarOrConst = tf.transform(bvVarOrConst); + } + return bvVarOrConst; + } + + private static Term transferBoogieVarOrConstStatic(final ManagedScript managedScript, Term bvVarOrConst) { + if (((HistoryRecordingScript) managedScript.getScript()).getMainScript() != null) { + final TermTransferrer tf = new TermTransferrer( + ((HistoryRecordingScript) managedScript.getScript()).getMainScript().getScript(), + (managedScript.getScript())); + bvVarOrConst = tf.transform(bvVarOrConst); + } + return bvVarOrConst; + } + private Term renameVarsToHierConstants(final Set boogieVars, final Term formula) { final ArrayList replacees = new ArrayList<>(); final ArrayList replacers = new ArrayList<>(); @@ -817,8 +854,8 @@ private Term renameVarsToHierConstants(final Map bv2t final ArrayList replacees = new ArrayList<>(); final ArrayList replacers = new ArrayList<>(); for (final Entry entry : bv2tv.entrySet()) { - replacees.add(entry.getValue()); - replacers.add(getOrConstructHierConstant(entry.getKey())); + replacees.add((TermVariable) transferBoogieVarOrConst(entry.getValue())); + replacers.add(transferBoogieVarOrConst(getOrConstructHierConstant(entry.getKey()))); } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); final Term[] values = replacers.toArray(new Term[replacers.size()]); @@ -829,10 +866,10 @@ private Term renameAuxVarsToCorrespondingConstants(final Set auxVa final ArrayList replacees = new ArrayList<>(); final ArrayList replacers = new ArrayList<>(); for (final TermVariable auxVarTv : auxVars) { - replacees.add(auxVarTv); + replacees.add((TermVariable) transferBoogieVarOrConst(auxVarTv)); final Term correspondingConstant = mManagedScript.term(this, ProgramVarUtils.generateConstantIdentifierForAuxVar(auxVarTv)); - replacers.add(correspondingConstant); + replacers.add(transferBoogieVarOrConst(correspondingConstant)); } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); final Term[] values = replacers.toArray(new Term[replacers.size()]); @@ -861,8 +898,8 @@ private Term renameNonModifiableNonOldGlobalsToDefaultConstants(final Set replacers = new ArrayList<>(); for (final IProgramVar bv : boogieVars) { if (bv.isGlobal() && bv instanceof IProgramNonOldVar && !modifiableGlobalsCallee.contains(bv)) { - replacees.add(bv.getTermVariable()); - replacers.add(bv.getDefaultConstant()); + replacees.add((TermVariable) transferBoogieVarOrConst(bv.getTermVariable())); + replacers.add(transferBoogieVarOrConst(bv.getDefaultConstant())); } } final TermVariable[] vars = replacees.toArray(new TermVariable[replacees.size()]); @@ -884,8 +921,8 @@ private static Term renameNonModifiableOldGlobalsToDefaultConstantOfNonOldVar(fi if (modifiableGlobalsCaller.contains(nonOldVar)) { // do nothing } else { - replacees.add(bv.getTermVariable()); - replacers.add(nonOldVar.getDefaultConstant()); + replacees.add((TermVariable) transferBoogieVarOrConstStatic(mgdScript, bv.getTermVariable())); + replacers.add(transferBoogieVarOrConstStatic(mgdScript, nonOldVar.getDefaultConstant())); } } @@ -909,8 +946,8 @@ private Term renameNonModifiableGlobalsToDefaultConstants(final Map succedent is valid. + * Check if implication antecedent ==> succedent is valid. */ public Validity checkImplication(final IPredicate antecedent, final boolean affirmAntecedentNeitherValidNorUnsat, final IPredicate succedent, final boolean affirmSuccedentNeitherValidNorUnsat) { - return checkImplication(antecedent.getFormula(), antecedent.getClosedFormula(), affirmAntecedentNeitherValidNorUnsat, - succedent.getFormula(), succedent.getClosedFormula(), affirmSuccedentNeitherValidNorUnsat); + return checkImplication(antecedent.getFormula(), antecedent.getClosedFormula(), + affirmAntecedentNeitherValidNorUnsat, succedent.getFormula(), succedent.getClosedFormula(), + affirmSuccedentNeitherValidNorUnsat); } /** - * Check if implication antecedent ==> succedent is valid. + * Check if implication antecedent ==> succedent is valid. */ - public Validity checkImplication(final Term antecedent, final Term antecedentClosedFormula, final boolean affirmAntecedentNeitherValidNorUnsat, - final Term succedent, final Term succedentClosedFormula, final boolean affirmSuccedentNeitherValidNorUnsat) { + public Validity checkImplication(final Term antecedent, final Term antecedentClosedFormulaMain, + final boolean affirmAntecedentNeitherValidNorUnsat, final Term succedent, + final Term succedentClosedFormulaMain, final boolean affirmSuccedentNeitherValidNorUnsat) { if (affirmAntecedentNeitherValidNorUnsat && affirmSuccedentNeitherValidNorUnsat) { final Validity dataflowAnalysisResult = dataflowBasedImplicationCheck(antecedent, succedent); if (dataflowAnalysisResult == Validity.INVALID) { return dataflowAnalysisResult; } } + Term succedentClosedFormula = succedentClosedFormulaMain; + Term antecedentClosedFormula = antecedentClosedFormulaMain; + // succedentClosedFormula comes from PredicateUnifier thus is from main script but we do a worker checksat here + if (((HistoryRecordingScript) mManagedScript.getScript()).getMainScript() != null) { + final TermTransferrer tf = new TermTransferrer( + ((HistoryRecordingScript) mManagedScript.getScript()).getMainScript().getScript(), + mManagedScript.getScript()); + succedentClosedFormula = tf.transform(succedentClosedFormula); + antecedentClosedFormula = tf.transform(antecedentClosedFormula); + } + if (mManagedScript.isLocked()) { mManagedScript.requestLockRelease(); } diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/BasicPredicateFactory.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/BasicPredicateFactory.java index 4b70bd1216e..3d31fcd549a 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/BasicPredicateFactory.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/BasicPredicateFactory.java @@ -26,6 +26,7 @@ */ package de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -40,6 +41,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.ModelCheckerUtils; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.IIcfgSymbolTable; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SmtUtils.SimplificationTechnique; @@ -203,6 +206,26 @@ private Term xJunctTerm(final Collection terms, final SimplificationTechni if (terms.stream().anyMatch(this::isDontCare)) { return mDontCareTerm; } + if (((HistoryRecordingScript) mScript).getMainScript() != null) { + final TermTransferrer tf = + new TermTransferrer(((HistoryRecordingScript) mScript).getMainScript().getScript(), mScript); + + if (terms.isEmpty()) { + return tf.transform(funGetNeutralElement.get()); + } + + final List newTerms = new ArrayList<>(); + + for (final Term t : terms) { + newTerms.add(tf.transform(t)); + } + final Term xJunct = funCreateXJunct.apply(mScript, newTerms); + if (st != SimplificationTechnique.NONE) { + return SmtUtils.simplify(mMgdScript, xJunct, mServices, st); + } + return xJunct; + + } if (terms.isEmpty()) { return funGetNeutralElement.get(); } diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateTransformer.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateTransformer.java index 73273b7a8ee..0adf362ec08 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateTransformer.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateTransformer.java @@ -43,6 +43,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramNonOldVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.CallReturnPyramideInstanceProvider.Instance; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.logic.TermVariable; @@ -82,6 +84,10 @@ public PredicateTransformer(final ManagedScript mgdScript, * quantified. */ public C strongestPostcondition(final P p, final R transRel) { + if (((HistoryRecordingScript) mMgdScript.getScript()).getMainScript() != null) { + return transferredStrongestPostcondition(p, transRel); + } + final C constraint = mOperationProvider.getConstraint(p); if (mOperationProvider.isConstraintUnsatisfiable(constraint)) { return constraint; @@ -131,6 +137,89 @@ public C strongestPostcondition(final P p, final R transRel) { return mOperationProvider.projectExistentially(varsToProject, conjunction); } + private C transferredStrongestPostcondition(final P p, final R transRel) { + + /* + * Parallel only supports TermDomainOperationProvider + */ + assert mOperationProvider instanceof TermDomainOperationProvider; + + final TermDomainOperationProvider termOperationProvider = (TermDomainOperationProvider) mOperationProvider; + + final TermTransferrer tf = new TermTransferrer( + ((HistoryRecordingScript) mMgdScript.getScript()).getMainScript().getScript(), mMgdScript.getScript()); + + // TODO is this unchecked cast a Problem? + final C constraint = (C) tf.transform(termOperationProvider.getConstraint((IPredicate) p)); + if (termOperationProvider.isConstraintUnsatisfiable((Term) constraint)) { + return constraint; + } + final Set varsToProject = new HashSet<>(); + final IValueConstruction substituentConstruction = pv -> { + final TermVariable result = constructFreshTermVariableTransferred(mMgdScript, pv); + varsToProject.add(result); + return result; + }; + final ConstructionCache termVariablesForPredecessor = + new ConstructionCache<>(substituentConstruction); + + final Map substitutionForTransFormula = new HashMap<>(); + final Map substitutionForPredecessor = new HashMap<>(); + + for (final Entry entry : transRel.getInVars().entrySet()) { + + final IProgramVar pv = entry.getKey(); + final TermVariable tv = (TermVariable) tf.transform(entry.getValue()); + boolean specialCase = false; + if (transRel.getOutVars().get(pv) != null) { + if (tv == tf.transform(transRel.getOutVars().get(pv))) { + // special case, variable unchanged will be renamed when + // considering outVars + specialCase = true; + } + } + + if (!specialCase) { + final TermVariable substituent = + (TermVariable) tf.transform(termVariablesForPredecessor.getOrConstruct(pv)); + assert tv.getTheory().equals(substituent.getTheory()); + substitutionForTransFormula.put(tv, substituent); + if (p.getVars().contains(pv)) { + substitutionForPredecessor.put(tf.transform(pv.getTermVariable()), substituent); + } + } + } + + for (final Entry entry : transRel.getOutVars().entrySet()) { + + final IProgramVar pv = entry.getKey(); + final TermVariable tv = (TermVariable) tf.transform(entry.getValue()); + substitutionForTransFormula.put(tv, tf.transform(pv.getTermVariable())); + + if (!transRel.getInVars().containsKey(pv) && p.getVars().contains(pv)) { + final TermVariable substituent = + (TermVariable) tf.transform(termVariablesForPredecessor.getOrConstruct(pv)); + assert tf.transform(pv.getTermVariable()).getTheory().equals(substituent.getTheory()); + substitutionForPredecessor.put(tf.transform(pv.getTermVariable()), substituent); + } + } + + final C renamedRelationConstraint = mOperationProvider.renameVariables(substitutionForTransFormula, + mOperationProvider.getConstraintFromTransitionRelation(transRel)); + final C renamedPredecessor = mOperationProvider.renameVariables(substitutionForPredecessor, constraint); + + final C conjunction = + mOperationProvider.constructConjunction(toList(renamedRelationConstraint, renamedPredecessor)); + + // Add aux vars to varsToQuantify + + for (final TermVariable aux : transRel.getAuxVars()) { + varsToProject.add((TermVariable) tf.transform(aux)); + } + return mOperationProvider.projectExistentially(varsToProject, conjunction); + + } + public C strongestPostconditionCall(final P callPred, final R localVarAssignments, final R globalVarAssignments, final R oldVarAssignments, final Set modifiableGlobalsOfCalledProcedure) { if (!globalVarAssignments.getAuxVars().isEmpty()) { @@ -202,9 +291,12 @@ public C strongestPostconditionReturn(final P returnPred, final P callPred, fina return mOperationProvider.projectExistentially(addAuxVarsOfCall(callTF, crpip.getFreshTermVariables()), result); } + public C weakestPrecondition(final P p, final R tf) { + if (((HistoryRecordingScript) mMgdScript.getScript()).getMainScript() != null) { + return transferredWeakestPrecondition(p, tf); + } - public C weakestPrecondition(final P p, final R tf) { final C constraint = mOperationProvider.getConstraint(p); if (mOperationProvider.isConstraintValid(constraint)) { return constraint; @@ -223,6 +315,38 @@ public C weakestPrecondition(final P p, final R tf) { return mOperationProvider.projectUniversally(pRename.getVarsToProject(), disjunction); } + private C transferredWeakestPrecondition(final P p, final R tf) { + /* + * Parallel only supports TermDomainOperationProvider + */ + assert mOperationProvider instanceof TermDomainOperationProvider; + + final TermDomainOperationProvider termOperationProvider = (TermDomainOperationProvider) mOperationProvider; + + final TermTransferrer termTF = new TermTransferrer( + ((HistoryRecordingScript) mMgdScript.getScript()).getMainScript().getScript(), mMgdScript.getScript()); + + // TODO is this unchecked cast a Problem? + + final C constraint = (C) termTF.transform(termOperationProvider.getConstraint((IPredicate) p)); + if (mOperationProvider.isConstraintValid(constraint)) { + return constraint; + } + + final PreRenaming pRename = new PreRenaming(p, tf); + + final C renamedRelationConstraint = mOperationProvider.renameVariables(pRename.getSubstitutionForRelation(), + mOperationProvider.getConstraintFromTransitionRelation(tf)); + + final C renamedPredecessor = + mOperationProvider.renameVariables(pRename.getSubstitutionForSuccessor(), constraint); + + final C disjunction = mOperationProvider.constructDisjunction( + toList(mOperationProvider.constructNegation(renamedRelationConstraint), renamedPredecessor)); + + return mOperationProvider.projectUniversally(pRename.getVarsToProject(), disjunction); + } + public C weakestPreconditionCall(final P callSucc, final R callTF, final R globalVarsAssignments, final R oldVarAssignments, final Set modifiableGlobals) { if (!globalVarsAssignments.getAuxVars().isEmpty()) { @@ -232,7 +356,6 @@ public C weakestPreconditionCall(final P callSucc, final R callTF, final R globa throw new AssertionError(TransFormulaUtils.OLD_VAR_ASSIGNMENTS_MUST_NOT_CONTAIN_AUX_VARS); } - final CallReturnPyramideInstanceProvider crpip = new CallReturnPyramideInstanceProvider(mMgdScript, Collections.emptySet(), callTF.getAssignedVars(), modifiableGlobals, Instance.BEFORE_CALL); final C callSuccTerm = renamePredicateToInstance(callSucc, Instance.AFTER_CALL, crpip); @@ -383,6 +506,15 @@ private static List toList(final E... elems) { return Arrays.asList(elems); } + private TermVariable constructFreshTermVariableTransferred(final ManagedScript freshVarConstructor, + final IProgramVar pv) { + final TermTransferrer tf = new TermTransferrer( + ((HistoryRecordingScript) mMgdScript.getScript()).getMainScript().getScript(), mMgdScript.getScript()); + + return freshVarConstructor.constructFreshTermVariable(pv.getGloballyUniqueId(), + tf.transferSort(pv.getTermVariable().getSort())); + } + private static TermVariable constructFreshTermVariable(final ManagedScript freshVarConstructor, final IProgramVar pv) { return freshVarConstructor.constructFreshTermVariable(pv.getGloballyUniqueId(), pv.getTermVariable().getSort()); @@ -401,6 +533,18 @@ private final class PreRenaming { private PreRenaming(final P p, final R tf) { mVarsToProject = new HashSet<>(); + mSubstitutionForRelation = new HashMap<>(); + mSubstitutionForSuccessor = new HashMap<>(); + + if (((HistoryRecordingScript) mMgdScript.getScript()).getMainScript() != null) { + transferredRename(p, tf); + } else { + rename(p, tf); + } + + } + + private void rename(final P p, final R tf) { final IValueConstruction substituentConstruction = pv -> { final TermVariable result = constructFreshTermVariable(mMgdScript, pv); mVarsToProject.add(result); @@ -410,9 +554,6 @@ private PreRenaming(final P p, final R tf) { final ConstructionCache termVariablesForSuccessor = new ConstructionCache<>(substituentConstruction); - mSubstitutionForRelation = new HashMap<>(); - mSubstitutionForSuccessor = new HashMap<>(); - for (final Entry entry : tf.getOutVars().entrySet()) { final IProgramVar pv = entry.getKey(); if (entry.getValue() == tf.getInVars().get(pv)) { @@ -437,6 +578,59 @@ private PreRenaming(final P p, final R tf) { mVarsToProject.addAll(tf.getAuxVars()); } + private void transferredRename(final P p, final R tf) { + final IValueConstruction substituentConstruction = pv -> { + final TermVariable result = constructFreshTermVariableTransferred(mMgdScript, pv); + mVarsToProject.add(result); + return result; + }; + + final ConstructionCache termVariablesForSuccessor = + new ConstructionCache<>(substituentConstruction); + + final TermTransferrer termTF = + new TermTransferrer(((HistoryRecordingScript) mMgdScript.getScript()).getMainScript().getScript(), + mMgdScript.getScript()); + + for (final Entry entry : tf.getOutVars().entrySet()) { + + final IProgramVar pv = entry.getKey(); + final TermVariable tv = (TermVariable) termTF.transform(entry.getValue()); + // if tf.getInVars().get(pv) == null, then nullPointer since we cant tranfrom null term + boolean specialCase = false; + if (tf.getInVars().get(pv) != null) { + if (entry.getValue() == termTF.transform(tf.getInVars().get(pv))) { + // special case, variable unchanged will be renamed when + // considering outVars + specialCase = true; + } + } + if (!specialCase) { + final TermVariable substituent = + (TermVariable) termTF.transform(termVariablesForSuccessor.getOrConstruct(pv)); + mSubstitutionForRelation.put(tv, substituent); + if (p.getVars().contains(pv)) { + mSubstitutionForSuccessor.put(termTF.transform(pv.getTermVariable()), substituent); + } + } + } + + for (final Entry entry : tf.getInVars().entrySet()) { + final IProgramVar pv = entry.getKey(); + final TermVariable tv = (TermVariable) termTF.transform(entry.getValue()); + mSubstitutionForRelation.put(tv, termTF.transform(pv.getTermVariable())); + + if (!tf.getOutVars().containsKey(pv) && p.getVars().contains(pv)) { + final TermVariable substituent = + (TermVariable) termTF.transform(termVariablesForSuccessor.getOrConstruct(pv)); + mSubstitutionForSuccessor.put(termTF.transform(pv.getTermVariable()), substituent); + } + } + for (final TermVariable aux : tf.getAuxVars()) { + mVarsToProject.add((TermVariable) termTF.transform(aux)); + } + } + public Set getVarsToProject() { return mVarsToProject; } diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateUnifier.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateUnifier.java index 8686291451a..f3db8be2fbf 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateUnifier.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/PredicateUnifier.java @@ -45,6 +45,8 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.MonolithicImplicationChecker; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.predicates.PredicateUnifierStatisticsGenerator.PredicateUnifierStatisticsType; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.TermTransferrer; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.CommuhashNormalForm; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.IncrementalPlicationChecker.Validity; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; @@ -277,7 +279,14 @@ public IPredicate getOrConstructPredicateForDisjunction(final Collection vars) { for (final TermVariable tv : term.getFreeVars()) { - final IProgramVar bv = mSymbolTable.getProgramVar(tv); + IProgramVar bv = null; + if (((HistoryRecordingScript) mMgdScript.getScript()).getMainScript() != null) { + bv = mSymbolTable.getProgramVar(((HistoryRecordingScript) mMgdScript.getScript()).getMainTv(tv)); + } + if (bv == null) { + bv = mSymbolTable.getProgramVar(tv); + } + if (bv == null) { throw new AssertionError("Variable " + tv + " has no corresponding BoogieVar, hence seems " + "to be some auxiliary variable and may not " @@ -324,16 +333,29 @@ protected IPredicate postProcessPredicateForDisjunction(final IPredicate unified /** * Variant of getOrConstruct methods where we can provide information about implied/explied predicates. */ - private IPredicate getOrConstructPredicate(final Term term, final HashMap impliedPredicates, + private IPredicate getOrConstructPredicate(final Term termWorker, + final HashMap impliedPredicates, final HashMap expliedPredicates, final IPredicate originalPredicate, final UnaryOperator predicatePostProcessor) { + Term term = termWorker; + + if (((HistoryRecordingScript) mScript).getMainScript() != null) { + final TermTransferrer tf = + new TermTransferrer(((HistoryRecordingScript) mScript).getMainScript().getScript(), mScript); + term = tf.transform(term); + } final TermVarsProc tvp = TermVarsProc.computeTermVarsProc(term, mMgdScript, mSymbolTable); + mPredicateUnifierBenchmarkGenerator.continueTime(); mPredicateUnifierBenchmarkGenerator.incrementGetRequests(); assert varsIsSupersetOfFreeTermVariables(term, tvp.getVars()); final Term withoutAnnotation = stripAnnotation(term); + for (final Term key : mTerm2Predicates.keySet()) { + assert key.getTheory().equals(mMgdScript.getScript().getTheory()); + } + { IPredicate p = mTerm2Predicates.get(withoutAnnotation); if (p != null) { @@ -345,7 +367,15 @@ private IPredicate getOrConstructPredicate(final Term term, final HashMap predicate public static Term computeClosedFormula(final Term formula, final Set boogieVars, final ManagedScript mgdScript) { final Map substitutionMapping = new HashMap<>(); + + final Term closedTerm; + if (((HistoryRecordingScript) mgdScript.getScript()).getMainScript() != null) { + + final TermTransferrer tf = + new TermTransferrer(((HistoryRecordingScript) mgdScript.getScript()).getMainScript().getScript(), + mgdScript.getScript()); + for (final IProgramVar bv : boogieVars) { + substitutionMapping.put(tf.transform(bv.getTermVariable()), tf.transform(bv.getDefaultConstant())); + } + + final Term transferredFormula = tf.transform(formula); + closedTerm = Substitution.apply(mgdScript, substitutionMapping, transferredFormula); + assert closedTerm.getFreeVars().length == 0; + return closedTerm; + + } + for (final IProgramVar bv : boogieVars) { substitutionMapping.put(bv.getTermVariable(), bv.getDefaultConstant()); } - final Term closedTerm = Substitution.apply(mgdScript, substitutionMapping, formula); + + closedTerm = Substitution.apply(mgdScript, substitutionMapping, formula); + assert closedTerm.getFreeVars().length == 0; return closedTerm; + } // public static LBool isInductiveHelper(Boogie2SMT boogie2smt, @@ -217,12 +240,19 @@ public static Term formulaWithIndexedVars(final UnmodifiableTransFormula tf, fin final int idxOutVar, final Set assignedVars, final Map indexedConstants, final Script script) { assert (assignedVars != null && assignedVars.isEmpty()); + + for (final Term con : indexedConstants.values()) { + assert con.getTheory().equals(script.getTheory()); + } + final Set notYetSubst = new HashSet<>(); notYetSubst.addAll(Arrays.asList(tf.getFormula().getFreeVars())); Term fTrans = tf.getFormula(); + assert fTrans.getTheory().equals(script.getTheory()); final Map reverseMapping = new HashMap<>(); for (final IProgramVar inVar : tf.getInVars().keySet()) { final TermVariable tv = tf.getInVars().get(inVar); + assert tv.getTheory().equals(script.getTheory()); reverseMapping.put(tv, inVar); Term cIndex; if (inVar.isOldvar()) { @@ -230,13 +260,16 @@ public static Term formulaWithIndexedVars(final UnmodifiableTransFormula tf, fin } else { cIndex = getIndexedConstant(inVar, idxInVar, indexedConstants, script); } + assert cIndex.getTheory().equals(script.getTheory()); final TermVariable[] vars = { tv }; final Term[] values = { cIndex }; + fTrans = script.let(vars, values, fTrans); notYetSubst.remove(tv); } for (final IProgramVar outVar : tf.getOutVars().keySet()) { final TermVariable tv = tf.getOutVars().get(outVar); + assert tv.getTheory().equals(script.getTheory()); reverseMapping.put(tv, outVar); if (tf.getInVars().get(outVar) != tv) { assignedVars.add(outVar); @@ -246,6 +279,7 @@ public static Term formulaWithIndexedVars(final UnmodifiableTransFormula tf, fin } else { cIndex = getIndexedConstant(outVar, idxOutVar, indexedConstants, script); } + assert cIndex.getTheory().equals(script.getTheory()); final TermVariable[] vars = { tv }; final Term[] values = { cIndex }; fTrans = script.let(vars, values, fTrans); @@ -260,6 +294,7 @@ public static Term formulaWithIndexedVars(final UnmodifiableTransFormula tf, fin } else { cIndex = reverseMapping.get(tv).getDefaultConstant(); } + assert cIndex.getTheory().equals(script.getTheory()); final TermVariable[] vars = { tv }; final Term[] values = { cIndex }; fTrans = script.let(vars, values, fTrans); @@ -291,8 +326,15 @@ public static Term getIndexedConstant(final String id, final Sort sort, final in public static LBool isInductiveHelper(final Script script, final IPredicate precond, final IPredicate postcond, final UnmodifiableTransFormula tf, final Set modifiableGlobalsPred, final Set modifiableGlobalsSucc) { - script.push(1); + if (((HistoryRecordingScript) script).getMainScript() != null) { + return transferredIsInductiveHelper(script, precond, postcond, tf, modifiableGlobalsPred, + modifiableGlobalsSucc); + } + + // TODO make old + + script.push(1); final List conjuncts = new ArrayList<>(); { // add oldvar equalities for precond and tf @@ -316,12 +358,20 @@ public static LBool isInductiveHelper(final Script script, final IPredicate prec { // add precond final Term precondRenamed = precond.getClosedFormula(); + assert precondRenamed != null; conjuncts.add(precondRenamed); } { // add tf - final Term tfRenamed = tf.getClosedFormula(); + // tf comes from main script and needs to be on worker since we do a worker checksat here + Term tfRenamed = tf.getClosedFormula(); + if (((HistoryRecordingScript) script).getMainScript() != null) { + final TermTransferrer termTransfer = + new TermTransferrer(((HistoryRecordingScript) script).getMainScript().getScript(), script); + tfRenamed = termTransfer.transform(tfRenamed); + + } assert tfRenamed != null; conjuncts.add(tfRenamed); @@ -341,13 +391,116 @@ public static LBool isInductiveHelper(final Script script, final IPredicate prec } } { - final Term postcondRenamed = rename(script, postcond, tf.getAssignedVars()); + Term postcondRenamed = rename(script, postcond, tf.getAssignedVars()); + if (((HistoryRecordingScript) script).getMainScript() != null) { + final TermTransferrer termTransfer = + new TermTransferrer(((HistoryRecordingScript) script).getMainScript().getScript(), script); + postcondRenamed = termTransfer.transform(postcondRenamed); + + } conjuncts.add(SmtUtils.not(script, postcondRenamed)); } - script.assertTerm(SmtUtils.and(script, conjuncts)); + + // some conjunct besides the tf.closedFormula comes from main script + List transferredConjuncts = new ArrayList(); + if (((HistoryRecordingScript) script).getMainScript() != null) { + for (int i = 0; i < conjuncts.size(); i++) { + final TermTransferrer termTransfer = + new TermTransferrer(((HistoryRecordingScript) script).getMainScript().getScript(), script); + transferredConjuncts.add(termTransfer.transform(conjuncts.get(i))); + } + } else { + transferredConjuncts = conjuncts; + } + script.assertTerm(SmtUtils.and(script, transferredConjuncts)); final LBool result = script.checkSat(); script.pop(1); + + return result; + } + + public static LBool transferredIsInductiveHelper(final Script script, final IPredicate precond, + final IPredicate postcond, final UnmodifiableTransFormula tf, + final Set modifiableGlobalsPred, final Set modifiableGlobalsSucc) { + final TermTransferrer termTransfer = + new TermTransferrer(((HistoryRecordingScript) script).getMainScript().getScript(), script); + + script.push(1); + + final List conjuncts = new ArrayList<>(); + { + // add oldvar equalities for precond and tf + final Set unprimedOldVarEqualities = new HashSet<>(); + final Set primedOldVarEqualities = new HashSet<>(); + + findNonModifiablesGlobals(precond.getVars(), modifiableGlobalsPred, Collections.emptySet(), + unprimedOldVarEqualities, primedOldVarEqualities); + findNonModifiablesGlobals(tf.getInVars().keySet(), modifiableGlobalsPred, Collections.emptySet(), + unprimedOldVarEqualities, primedOldVarEqualities); + findNonModifiablesGlobals(tf.getOutVars().keySet(), modifiableGlobalsSucc, tf.getAssignedVars(), + unprimedOldVarEqualities, primedOldVarEqualities); + + for (final IProgramNonOldVar bv : unprimedOldVarEqualities) { + conjuncts.add(ModifiableGlobalsTable.transferredConstructConstantOldVarEquality(termTransfer, bv, false, + script)); + } + for (final IProgramNonOldVar bv : primedOldVarEqualities) { + conjuncts.add(ModifiableGlobalsTable.transferredConstructConstantOldVarEquality(termTransfer, bv, true, + script)); + } + } + { + // add precond + final Term precondRenamed = termTransfer.transform(precond.getClosedFormula()); + + assert precondRenamed != null; + conjuncts.add(precondRenamed); + } + { + + final Term tfRenamed = termTransfer.transform(tf.getClosedFormula()); + + assert tfRenamed != null; + conjuncts.add(tfRenamed); + + } + { + // add oldvar equalities for postcond + final Set unprimedOldVarEqualities = new HashSet<>(); + final Set primedOldVarEqualities = new HashSet<>(); + + findNonModifiablesGlobals(postcond.getVars(), modifiableGlobalsSucc, tf.getAssignedVars(), + unprimedOldVarEqualities, primedOldVarEqualities); + for (final IProgramNonOldVar bv : unprimedOldVarEqualities) { + conjuncts.add(ModifiableGlobalsTable.transferredConstructConstantOldVarEquality(termTransfer, bv, false, + script)); + } + for (final IProgramNonOldVar bv : primedOldVarEqualities) { + conjuncts.add(ModifiableGlobalsTable.transferredConstructConstantOldVarEquality(termTransfer, bv, true, + script)); + } + } + { + final Term postcondRenamed = termTransfer.transform(rename(script, postcond, tf.getAssignedVars())); + + conjuncts.add(SmtUtils.not(script, postcondRenamed)); + } + + // some conjunct besides the tf.closedFormula comes from main script + List transferredConjuncts = new ArrayList(); + if (((HistoryRecordingScript) script).getMainScript() != null) { + for (int i = 0; i < conjuncts.size(); i++) { + transferredConjuncts.add(termTransfer.transform(conjuncts.get(i))); + } + } else { + transferredConjuncts = conjuncts; + } + script.assertTerm(SmtUtils.and(script, transferredConjuncts)); + final LBool result = script.checkSat(); + + script.pop(1); + return result; } @@ -383,6 +536,26 @@ private static void findNonModifiablesGlobals(final Set vars, private static Term rename(final Script script, final IPredicate postcond, final Set assignedVars) { final Map substitutionMapping = new HashMap<>(); + + if (((HistoryRecordingScript) script).getMainScript() != null) { + final TermTransferrer tf = + new TermTransferrer(((HistoryRecordingScript) script).getMainScript().getScript(), script); + + for (final IProgramVar bv : postcond.getVars()) { + Term constant; + if (assignedVars.contains(bv)) { + constant = tf.transform(bv.getPrimedConstant()); + } else { + constant = tf.transform(bv.getDefaultConstant()); + } + substitutionMapping.put(tf.transform(bv.getTermVariable()), constant); + } + final Term result = + (PureSubstitution.apply(script, substitutionMapping, tf.transform(postcond.getFormula()))); + assert result.getFreeVars().length == 0 : "there are free vars"; + return result; + } + for (final IProgramVar bv : postcond.getVars()) { Term constant; if (assignedVars.contains(bv)) { diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermDomainOperationProvider.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermDomainOperationProvider.java index 9dfdd07cc57..43c6e509a46 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermDomainOperationProvider.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermDomainOperationProvider.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import de.uni_freiburg.informatik.ultimate.core.model.services.IUltimateServiceProvider; @@ -53,6 +54,7 @@ public class TermDomainOperationProvider implements IDomainSpecificOperationProv public TermDomainOperationProvider(final IUltimateServiceProvider services, final ManagedScript mgdScript) { mServices = services; mMgdScript = mgdScript; + } @Override @@ -77,6 +79,11 @@ public Term getConstraintFromTransitionRelation(final TransFormula tf) { @Override public Term renameVariables(final Map substitutionForTransFormula, final Term constraint) { + for (final Entry entry : substitutionForTransFormula.entrySet()) { + assert mMgdScript.getScript().getTheory().equals(entry.getValue().getTheory()); + assert mMgdScript.getScript().getTheory().equals(entry.getKey().getTheory()); + } + assert mMgdScript.getScript().getTheory().equals(constraint.getTheory()); final Term renamedTransFormula = Substitution.apply(mMgdScript, substitutionForTransFormula, constraint); return renamedTransFormula; } @@ -106,6 +113,9 @@ public Term projectUniversally(final Set varsToProjectAway, final return constructQuantifiedFormula(Script.FORALL, varsToProjectAway, constraint); } + /* + * Does check-sats, therefore needs to be worker script + */ private Term constructQuantifiedFormula(final int quantifier, final Set varsToQuantify, final Term term) { final Term quantified = SmtUtils.quantifier(mMgdScript.getScript(), quantifier, varsToQuantify, term); diff --git a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermVarsProc.java b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermVarsProc.java index 2c9dfd2ba58..190ec1a22ee 100644 --- a/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermVarsProc.java +++ b/trunk/source/Library-ModelCheckerUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/predicates/TermVarsProc.java @@ -35,6 +35,7 @@ import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.IIcfgSymbolTable; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramFunction; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.cfg.variables.IProgramVar; +import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.HistoryRecordingScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.SubTermFinder; import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; @@ -80,9 +81,8 @@ public Set getFuns() { } /** - * Given a term in which every free variable is the TermVariable of a BoogieVar. - * Compute the BoogieVars of the free variables and the procedures of these - * BoogieVariables. + * Given a term in which every free variable is the TermVariable of a BoogieVar. Compute the BoogieVars of the free + * variables and the procedures of these BoogieVariables. */ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScript mgdScript, final IIcfgSymbolTable symbolTable) { @@ -90,9 +90,8 @@ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScr } /** - * Given a term in which every free variable is the TermVariable of a BoogieVar. - * Compute the BoogieVars of the free variables and the procedures of these - * BoogieVariables. + * Given a term in which every free variable is the TermVariable of a BoogieVar. Compute the BoogieVars of the free + * variables and the procedures of these BoogieVariables. */ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScript mgdScript, final Function funTermVar2ProgVar, @@ -100,7 +99,24 @@ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScr final HashSet vars = new HashSet<>(); final Set procs = new HashSet<>(); for (final TermVariable tv : term.getFreeVars()) { - final IProgramVar bv = funTermVar2ProgVar.apply(tv); + /* + * tv is from worker script + * + * cannot call funTermVar2ProgVar.apply(tv) + * instead we need to map tc to main.tc and then apply. + * I doubt we can use termtransferrer for that + * + * Wenn wir worker script erstellen, können wir eine tv map erstellen oder? + * + * Das geht jetzt + */ + IProgramVar bv = null; + if (((HistoryRecordingScript) mgdScript.getScript()).getMainScript() != null) { + bv = funTermVar2ProgVar.apply(((HistoryRecordingScript) mgdScript.getScript()).getMainTv(tv)); + } + if (bv == null) { + bv = funTermVar2ProgVar.apply(tv); + } if (bv == null) { throw new AssertionError("No corresponding IProgramVar for " + tv); } @@ -109,8 +125,8 @@ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScr procs.add(bv.getProcedure()); } } - final Predicate isNonTheoryApplicationTerm = (x -> ((x instanceof ApplicationTerm) - && !((ApplicationTerm) x).getFunction().isIntern())); + final Predicate isNonTheoryApplicationTerm = + (x -> ((x instanceof ApplicationTerm) && !((ApplicationTerm) x).getFunction().isIntern())); final Set nonTheoryAppTerms = findNonTheoryApplicationTerms(term); Set programFunctions; if (nonTheoryAppTerms.isEmpty()) { @@ -126,14 +142,13 @@ public static TermVarsProc computeTermVarsProc(final Term term, final ManagedScr } programFunctions = DataStructureUtils.getUnmodifiable(tmp); } - final Term closedTerm = PredicateUtils.computeClosedFormula(term, vars, mgdScript); return new TermVarsProc(term, vars, programFunctions, procs.toArray(new String[procs.size()]), closedTerm); } public static Set findNonTheoryApplicationTerms(final Term term) { - final Predicate isNonTheoryApplicationTerm = (x -> ((x instanceof ApplicationTerm) - && !((ApplicationTerm) x).getFunction().isIntern())); + final Predicate isNonTheoryApplicationTerm = + (x -> ((x instanceof ApplicationTerm) && !((ApplicationTerm) x).getFunction().isIntern())); final Set tmp = SubTermFinder.find(term, isNonTheoryApplicationTerm, false); final Set nonTheoryAppTerms = tmp; return nonTheoryAppTerms; diff --git a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/scripttransfer/HistoryRecordingScript.java b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/scripttransfer/HistoryRecordingScript.java index ecc0db72063..f8bac6af9b9 100644 --- a/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/scripttransfer/HistoryRecordingScript.java +++ b/trunk/source/Library-SmtLibUtils/src/de/uni_freiburg/informatik/ultimate/lib/modelcheckerutils/smt/scripttransfer/HistoryRecordingScript.java @@ -26,19 +26,31 @@ */ package de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.ArrayDeque; import java.util.Collections; import java.util.Deque; +import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import de.uni_freiburg.informatik.ultimate.lib.modelcheckerutils.smt.scripttransfer.ISmtDeclarable.IllegalSmtDeclarableUsageException; +import de.uni_freiburg.informatik.ultimate.lib.smtlibutils.ManagedScript; +import de.uni_freiburg.informatik.ultimate.logic.Annotation; +import de.uni_freiburg.informatik.ultimate.logic.Assignments; +import de.uni_freiburg.informatik.ultimate.logic.DataType; +import de.uni_freiburg.informatik.ultimate.logic.FunctionSymbol; +import de.uni_freiburg.informatik.ultimate.logic.Logics; +import de.uni_freiburg.informatik.ultimate.logic.Model; +import de.uni_freiburg.informatik.ultimate.logic.QuotedObject; import de.uni_freiburg.informatik.ultimate.logic.SMTLIBException; import de.uni_freiburg.informatik.ultimate.logic.Script; import de.uni_freiburg.informatik.ultimate.logic.Sort; import de.uni_freiburg.informatik.ultimate.logic.Term; import de.uni_freiburg.informatik.ultimate.logic.TermVariable; +import de.uni_freiburg.informatik.ultimate.logic.Theory; import de.uni_freiburg.informatik.ultimate.logic.WrapperScript; /** @@ -53,58 +65,101 @@ */ public class HistoryRecordingScript extends WrapperScript { - private final Deque mHistory; + public final Deque mHistory; private final Map mSymbolTable; private int mCurrentStackLevel; + public HistoryRecordingScript mCurrentlyUsedScript = this; + private ManagedScript mMainScript = null; + public boolean mAfterSynchronisation = false; + + public HashMap workerTermVariableToMainTermVariable; + + private TermTransferrer mTf = null; public HistoryRecordingScript(final Script script) { super(script); mHistory = new ArrayDeque<>(); mSymbolTable = new Hashtable<>(); + workerTermVariableToMainTermVariable = new HashMap<>(); mCurrentStackLevel = 0; } + public void setMainScript(final ManagedScript mainScript) { + mMainScript = mainScript; + mTf = new TermTransferrer(mMainScript.getScript(), this); + } + + public ManagedScript getMainScript() { + return mMainScript; + } + + /* + * maps for the termvariables for boogievars + */ + public void addTermVariableToMap(final TermVariable workerTv, final TermVariable mainTv) { + workerTermVariableToMainTermVariable.put(workerTv, mainTv); + } + + public TermVariable getMainTv(final TermVariable workerTv) { + return workerTermVariableToMainTermVariable.get(workerTv); + } + + public void synchronizeWorkerAndMain() { + mAfterSynchronisation = true; + transferHistoryFromRecord(mMainScript.getScript()); + mCurrentlyUsedScript = (HistoryRecordingScript) mMainScript.getScript(); + } + @Override public void defineFun(final String fun, final TermVariable[] params, final Sort resultSort, final Term definition) throws SMTLIBException { - super.defineFun(fun, params, resultSort, definition); + mCurrentlyUsedScript.mScript.defineFun(fun, params, resultSort, definition); insert(DeclarableFunctionSymbol.createFromScriptDefineFun(fun, params, resultSort, definition)); } @Override public void resetAssertions() { - super.resetAssertions(); + mCurrentlyUsedScript.mScript.resetAssertions(); + removeStackLevelsFromHistory(mCurrentStackLevel); } @Override public void reset() { - super.reset(); + mCurrentlyUsedScript.mScript.reset(); + mHistory.clear(); mSymbolTable.clear(); } @Override public void defineSort(final String sort, final Sort[] sortParams, final Sort definition) { - super.defineSort(sort, sortParams, definition); + mCurrentlyUsedScript.mScript.defineSort(sort, sortParams, definition); + insert(DeclarableSortSymbol.createFromScriptDefineSort(sort, sortParams, definition)); } @Override public void declareFun(final String fun, final Sort[] paramSorts, final Sort resultSort) { - super.declareFun(fun, paramSorts, resultSort); + if (mCurrentlyUsedScript.mScript.getTheory().mFunFactory.get(fun) != null + || mCurrentlyUsedScript.mScript.getTheory().mDeclaredFuns.get(fun) != null) { + return; + } + mCurrentlyUsedScript.mScript.declareFun(fun, paramSorts, resultSort); + insert(DeclarableFunctionSymbol.createFromScriptDeclareFun(fun, paramSorts, resultSort)); } @Override public void declareSort(final String sort, final int arity) { - super.declareSort(sort, arity); + mCurrentlyUsedScript.mScript.declareSort(sort, arity); insert(DeclarableSortSymbol.createFromScriptDeclareSort(sort, arity)); } @Override public void push(final int levels) { - super.push(levels); + mCurrentlyUsedScript.mScript.push(levels); + assert levels > 0; for (int i = 0; i < levels; ++i) { mHistory.push(StackMarker.INSTANCE); @@ -114,7 +169,8 @@ public void push(final int levels) { @Override public void pop(final int levels) { - super.pop(levels); + mCurrentlyUsedScript.mScript.pop(levels); + removeStackLevelsFromHistory(levels); } @@ -169,6 +225,7 @@ public void transferHistoryFromRecord(final Script script) { continue; } elem.defineOrDeclare(script); + } } @@ -228,6 +285,287 @@ public String toString() { return getClass().getSimpleName() + ": " + mHistory; } + /** + * Find the first {@link Script} instance that has the given type or is a subtype of the given type in the stack of + * {@link Script} instances represented by this {@link WrapperScript}. + * + * @param + * The type of {@link Script} to search for. + * @param clazz + * The {@link Class} instance representing the type. + * @return A {@link Script} instance if one can be found or null. + */ + @Override + @SuppressWarnings("unchecked") + public T findBacking(final Class clazz) { + final Iterator