Search in sources :

Example 11 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ABSUnitTestCaseBuilder method makeOracle.

void makeOracle(String testName, Set<String> heapNames, Map<ABSRef, ABSObject> finalHeap, String actual, Access access, ABSData data, Set<String> visited, Block block) {
    InterfaceDecl inf = null;
    if (access instanceof DataTypeUse) {
        inf = getDecl(model, InterfaceDecl.class, new DeclNamePredicate<InterfaceDecl>(((DataTypeUse) access).getName()));
    }
    PureExp exp = pureExpBuilder.createPureExpression(testName, heapNames, data);
    block.addStmtNoTransform(getExpStmt(getCall(new VarUse(ASSERT_HELPER), "assertTrue", true, new EqExp(new VarUse(actual), exp))));
    if (inf != null && !(exp instanceof NullExp)) {
        String ref = getABSDataValue(data);
        for (ABSRef r : finalHeap.keySet()) {
            if (getABSDataValue(r).equals(ref)) {
                makeGetAndAssertStatementsForHeapRef(testName, heapNames, finalHeap, r, finalHeap.get(r), visited, block);
                break;
            }
        }
    }
}
Also used : EqExp(abs.frontend.ast.EqExp) DataTypeUse(abs.frontend.ast.DataTypeUse) ABSRef(apet.testCases.ABSRef) DeclNamePredicate(abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate) NullExp(abs.frontend.ast.NullExp) InterfaceDecl(abs.frontend.ast.InterfaceDecl) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse)

Example 12 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class MethodTestCaseBuilder method makeMethodCall.

private Call makeMethodCall(String testName, Set<String> heapNames, String methodName, List<ABSData> inArgs, boolean sync) {
    if (inArgs.size() == 0) {
        throw new IllegalStateException("Inputs for a method must at least have a reference");
    }
    ABSData r = inArgs.get(0);
    if (!(r instanceof ABSRef)) {
        throw new IllegalStateException("Inputs for a method must at least have a reference");
    }
    PureExp[] ps = new PureExp[inArgs.size() - 1];
    for (int i = 1; i < inArgs.size(); i++) {
        ABSData d = inArgs.get(i);
        PureExp exp = pureExpBuilder.createPureExpression(testName, heapNames, d);
        ps[i - 1] = exp;
    }
    String rn = getABSDataValue(r);
    VarUse var = new VarUse(heapRefBuilder.heapReferenceForTest(testName, rn));
    Call call = getCall(var, methodName, sync, ps);
    return call;
}
Also used : Call(abs.frontend.ast.Call) PreviousCall(apet.testCases.PreviousCall) AbsASTBuilderUtil.getCall(abs.backend.tests.AbsASTBuilderUtil.getCall) ABSRef(apet.testCases.ABSRef) ABSData(apet.testCases.ABSData) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse)

Example 13 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateAsyncTestCallAST.

private void generateAsyncTestCallAST(Block block, String objectRef, MethodSig method) {
    List<PureExp> args = new List<>();
    if (method.getNumParam() > 0) {
        args.add(new VarUse(dataValue));
    }
    block.addStmtNoTransform(getVAssign(fut, new AsyncCall(new VarUse(objectRef), method.getName(), args)));
    block.addStmtNoTransform(getVAssign(futs, getFnApp("Insert", new VarUse(fut), new VarUse(futs))));
}
Also used : List(abs.frontend.ast.List) PureExp(abs.frontend.ast.PureExp) AsyncCall(abs.frontend.ast.AsyncCall) VarUse(abs.frontend.ast.VarUse)

Example 14 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestClassImplAST.

private Set<TypeUse> generateTestClassImplAST(InterfaceDecl inf, ClassDecl clazz, MainBlock block) {
    Set<TypeUse> accesses = new HashSet<>();
    TypeUse dataType = generateDataPointsAST(inf, clazz, accesses, block);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        Block thisBlock = block;
        WhileStmt ws = null;
        if (method.getNumParam() > 0) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            ws = new WhileStmt();
            ws.setCondition(getFnApp("hasNext", new VarUse(dataPointSet)));
            Block body = new Block();
            thisBlock = body;
            DataTypeUse u = getType("Pair", getType("Set", (TypeUse) dataType.copy()), (TypeUse) dataType.copy());
            thisBlock.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(dataPointSet))));
            thisBlock.addStmtNoTransform(getVarDecl(dataValue, (TypeUse) dataType.copy(), getFnApp("snd", new VarUse("nt"))));
            thisBlock.addStmtNoTransform(getVAssign(dataPointSet, getFnApp("fst", new VarUse("nt"))));
            ws.setBody(body);
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            String objectRef = uncap(namePrefix) + instance;
            thisBlock.addStmtNoTransform(newObj(inf, clazz, objectRef, false));
            generateAsyncTestCallAST(thisBlock, objectRef, method);
        }
        if (ws != null) {
            block.addStmtNoTransform(ws);
        }
        instance++;
    }
    return accesses;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) VarUse(abs.frontend.ast.VarUse) HashSet(java.util.HashSet)

Example 15 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateDataPointsAST.

private TypeUse generateDataPointsAST(InterfaceDecl key, ClassDecl clazz, Set<TypeUse> use, MainBlock block) {
    MethodSig dataPoint = findDataPoints(key);
    if (dataPoint == null) {
        return null;
    }
    Access rt = dataPoint.getReturnType();
    if (!(rt instanceof ParametricDataTypeUse)) {
        return null;
    }
    ParametricDataTypeUse prt = (ParametricDataTypeUse) rt;
    if (!prt.getName().equals("Set")) {
        return null;
    }
    // Set has only one type parameter
    TypeUse u = (TypeUse) prt.getParam(0).copy();
    use.add(u);
    String objName = uncap(clazz.getName()) + "dataPoint";
    String dataSet = dataPointSetName(clazz);
    block.addStmtNoTransform(newObj(key, clazz, objName, true));
    block.addStmtNoTransform(getVarDecl(dataSet, prt.copy(), new SyncCall(new VarUse(objName), dataPoint.getName(), new List<>())));
    return u;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) SyncCall(abs.frontend.ast.SyncCall) Access(abs.frontend.ast.Access) VarUse(abs.frontend.ast.VarUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse)

Aggregations

VarUse (abs.frontend.ast.VarUse)15 PureExp (abs.frontend.ast.PureExp)6 DataTypeUse (abs.frontend.ast.DataTypeUse)5 Block (abs.frontend.ast.Block)4 ParamDecl (abs.frontend.ast.ParamDecl)4 ABSData (apet.testCases.ABSData)4 ABSRef (apet.testCases.ABSRef)4 MethodSig (abs.frontend.ast.MethodSig)3 NullExp (abs.frontend.ast.NullExp)3 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)3 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)2 AbsASTBuilderUtil.getCall (abs.backend.tests.AbsASTBuilderUtil.getCall)2 Call (abs.frontend.ast.Call)2 ClassDecl (abs.frontend.ast.ClassDecl)2 EqExp (abs.frontend.ast.EqExp)2 FieldDecl (abs.frontend.ast.FieldDecl)2 GetExp (abs.frontend.ast.GetExp)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 MainBlock (abs.frontend.ast.MainBlock)2 TypeUse (abs.frontend.ast.TypeUse)2