Search in sources :

Example 21 with Exp

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

the class FreeVarTest method varUseExp.

@Test
public void varUseExp() {
    Exp e = getSecondExp("{ Bool b = True; Bool c = b; }");
    assertEquals(e.getFreeVars(), "b");
}
Also used : Exp(abs.frontend.ast.Exp) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 22 with Exp

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

the class FreeVarTest method fnApp.

@Test
public void fnApp() {
    Exp e = getSecondExp("def Unit f(Bool b) = Unit; { Bool b; Unit u = f(b); }");
    assertEquals(e.getFreeVars(), "b");
}
Also used : Exp(abs.frontend.ast.Exp) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 23 with Exp

use of abs.frontend.ast.Exp 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 24 with Exp

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

the class MethodTestCaseBuilder method makePreviousCalls.

@Override
List<Exp> makePreviousCalls(String testName, Set<String> heapNames, List<PreviousCall> calls) {
    // task interleaving
    List<Exp> expressions = new ArrayList<Exp>();
    for (PreviousCall call : calls) {
        // test execution
        List<ABSData> callInputArguments = getCallArgs(call);
        String methodName = removeClassName(getMethodName(call));
        expressions.add(makeMethodCall(testName, heapNames, methodName, callInputArguments, false));
    }
    return expressions;
}
Also used : ArrayList(java.util.ArrayList) ABSData(apet.testCases.ABSData) PureExp(abs.frontend.ast.PureExp) Exp(abs.frontend.ast.Exp) PreviousCall(apet.testCases.PreviousCall)

Aggregations

Exp (abs.frontend.ast.Exp)24 FrontendTest (abs.frontend.FrontendTest)22 Test (org.junit.Test)22 PureExp (abs.frontend.ast.PureExp)2 ABSData (apet.testCases.ABSData)2 PreviousCall (apet.testCases.PreviousCall)2 Block (abs.frontend.ast.Block)1 ClassDecl (abs.frontend.ast.ClassDecl)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1 EqExp (abs.frontend.ast.EqExp)1 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)1 MethodImpl (abs.frontend.ast.MethodImpl)1 NullExp (abs.frontend.ast.NullExp)1 ReturnStmt (abs.frontend.ast.ReturnStmt)1 Stmt (abs.frontend.ast.Stmt)1 VarUse (abs.frontend.ast.VarUse)1 ABSObject (apet.testCases.ABSObject)1 ABSRef (apet.testCases.ABSRef)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1