Search in sources :

Example 1 with DataTypeUse

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

the class ASTBasedABSTestRunnerGenerator method generateWaitSyncAST.

private WhileStmt generateWaitSyncAST() {
    WhileStmt ws = new WhileStmt();
    ws.setCondition(getFnApp("hasNext", new VarUse(futs)));
    Block body = new Block();
    DataTypeUse u = getType("Pair", getType("Set", getType("Fut", getType("Unit"))), getType("Fut", getType("Unit")));
    body.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(futs))));
    body.addStmtNoTransform(getVAssign(fut, getFnApp("snd", new VarUse("nt"))));
    body.addStmtNoTransform(getVAssign(futs, getFnApp("fst", new VarUse("nt"))));
    body.addStmtNoTransform(getExpStmt(new GetExp(new VarUse("fut"))));
    // Attach body at the end, since JastAdd will avoid touching ASTs without parents.
    ws.setBody(body);
    return ws;
}
Also used : 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) GetExp(abs.frontend.ast.GetExp) VarUse(abs.frontend.ast.VarUse)

Example 2 with DataTypeUse

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

the class AbsASTBuilderUtil method getType.

public static final DataTypeUse getType(String n, TypeUse... types) {
    if (types.length > 0) {
        ParametricDataTypeUse set = new ParametricDataTypeUse();
        set.setName(n);
        for (TypeUse d : types) {
            set.addParam(d);
        }
        return set;
    } else {
        DataTypeUse set = new DataTypeUse();
        set.setName(n);
        return set;
    }
}
Also used : TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse)

Example 3 with DataTypeUse

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

the class DeadlockPreanalysis method processFieldDecl.

private void processFieldDecl(FieldDecl field) {
    System.out.println("Processing Field Declaration: " + field.getName());
    if (field.getChild(0) instanceof DataTypeUse) {
        DataTypeUse type = (DataTypeUse) field.getChild(0);
        dataFieldDecls.put(field, hasFutureVariables(type));
    }
}
Also used : DataTypeUse(abs.frontend.ast.DataTypeUse)

Example 4 with DataTypeUse

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

the class ABSUnitTestCaseBuilder method buildTestCase.

/**
 * @param testCase
 * @param testClass
 * @param method
 * @param access
 * @param unitUnderTest
 */
void buildTestCase(TestCase testCase, ClassDecl testClass, MethodImpl method, Access access, String unitUnderTest) {
    // initial arg
    List<ABSData> inputArguments = getInputArgs(testCase);
    String testName = method.getMethodSig().getName();
    Block block = method.getBlock();
    Map<String, InterfaceTypeUse> typesOfObjectInHeap = new HashMap<String, InterfaceTypeUse>();
    for (ABSData d : inputArguments) {
        typesOfObjectInHeap.putAll(getTypesFromABSData(testName, d));
    }
    Map<ABSRef, ABSObject> initial = getInitialState(testCase);
    for (ABSObject obj : initial.values()) {
        typesOfObjectInHeap.putAll(getTypesFromABSObject(testName, obj));
    }
    Set<String> initialHeapNames = referenceNames(initial.keySet());
    createObjectsInHeap(testName, initialHeapNames, typesOfObjectInHeap, testClass, initial, block);
    List<PreviousCall> calls = getPreviousCalls(testCase);
    List<Exp> previous = makePreviousCalls(testName, initialHeapNames, calls);
    for (Exp pc : previous) {
        // does not care about return value
        block.addStmtNoTransform(getExpStmt(pc));
    }
    // test execution
    Exp test = makeTestExecution(testName, initialHeapNames, unitUnderTest, inputArguments);
    final boolean hasReturnValue;
    if (access instanceof DataTypeUse && ((DataTypeUse) access).getName().equals("Unit")) {
        // no return value
        block.addStmtNoTransform(getExpStmt(test));
        hasReturnValue = false;
    } else {
        block.addStmtNoTransform(getVarDecl("returnValue", access.treeCopyNoTransform(), test));
        hasReturnValue = true;
    }
    Map<ABSRef, ABSObject> finalHeap = getAfterState(testCase);
    if (finalHeap.isEmpty()) {
        // the method under test is side-effect free?
        // use the initial heap as oracle
        finalHeap = initial;
    }
    Set<String> finalHeapNames = referenceNames(finalHeap.keySet());
    // need to remember which objects in the heap we have already handled.
    Set<String> visited = new HashSet<String>();
    // assertions of object states can be done in the heap assertions
    if (hasReturnValue) {
        ABSData rd = getReturnData(testCase);
        PureExp exp = pureExpBuilder.createPureExpression(testName, finalHeapNames, rd);
        block.addStmtNoTransform(getExpStmt(getCall(new VarUse(ASSERT_HELPER), "assertTrue", true, new EqExp(new VarUse("returnValue"), exp))));
    }
    // check return value (using deltas)
    makeGetAndAssertStatements(testName, finalHeapNames, testClass, finalHeap, visited, block);
}
Also used : HashMap(java.util.HashMap) DataTypeUse(abs.frontend.ast.DataTypeUse) ABSObject(apet.testCases.ABSObject) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse) EqExp(abs.frontend.ast.EqExp) ABSRef(apet.testCases.ABSRef) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) Block(abs.frontend.ast.Block) ABSData(apet.testCases.ABSData) EqExp(abs.frontend.ast.EqExp) PureExp(abs.frontend.ast.PureExp) Exp(abs.frontend.ast.Exp) NullExp(abs.frontend.ast.NullExp) PreviousCall(apet.testCases.PreviousCall) HashSet(java.util.HashSet)

Example 5 with DataTypeUse

use of abs.frontend.ast.DataTypeUse 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)

Aggregations

DataTypeUse (abs.frontend.ast.DataTypeUse)6 VarUse (abs.frontend.ast.VarUse)4 Block (abs.frontend.ast.Block)3 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)3 EqExp (abs.frontend.ast.EqExp)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 MainBlock (abs.frontend.ast.MainBlock)2 NullExp (abs.frontend.ast.NullExp)2 PureExp (abs.frontend.ast.PureExp)2 TypeUse (abs.frontend.ast.TypeUse)2 WhileStmt (abs.frontend.ast.WhileStmt)2 ABSRef (apet.testCases.ABSRef)2 HashSet (java.util.HashSet)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 Exp (abs.frontend.ast.Exp)1 GetExp (abs.frontend.ast.GetExp)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MethodSig (abs.frontend.ast.MethodSig)1 ABSData (apet.testCases.ABSData)1 ABSObject (apet.testCases.ABSObject)1