Search in sources :

Example 1 with EvoSuiteRemoteAddress

use of org.evosuite.runtime.testdata.EvoSuiteRemoteAddress in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(RemoteAddressPrimitiveStatement s, Scope scope) {
    EvoSuiteRemoteAddress conc_remote_address = s.getValue();
    VariableReference varRef = s.getReturnValue();
    String varRefName = varRef.getName();
    ReferenceExpression addressRef;
    if (conc_remote_address == null) {
        addressRef = env.heap.getReference(null);
        if (addressRef.getConcreteValue() != null) {
            throw new IllegalStateException("Expected null concrete value");
        }
    } else {
        addressRef = env.heap.getReference(conc_remote_address);
        if (addressRef.getConcreteValue() == null) {
            throw new IllegalStateException("Expected non-null concrete value");
        }
    }
    symb_references.put(varRefName, addressRef);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoSuiteRemoteAddress(org.evosuite.runtime.testdata.EvoSuiteRemoteAddress) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 2 with EvoSuiteRemoteAddress

use of org.evosuite.runtime.testdata.EvoSuiteRemoteAddress in project evosuite by EvoSuite.

the class RemoteAddressPrimitiveStatement method randomize.

@Override
public void randomize() {
    EvoSuiteRemoteAddress addr;
    // TODO parameter
    double threshold = 0.8;
    boolean accessed = Randomness.nextDouble() <= threshold;
    if (accessed && !tc.getAccessedEnvironment().getViewOfRemoteContactedPorts().isEmpty()) {
        // use an address that the SUT tried to contact
        EndPointInfo info = Randomness.choice(tc.getAccessedEnvironment().getViewOfRemoteContactedPorts());
        String host = info.getHost();
        // TODO check why it can be a 0 here
        int port = info.getPort();
        port = getPort(port);
        addr = new EvoSuiteRemoteAddress(host, port);
    } else {
        /*
                make up an address based on string/int constants.
                this is needed to handle the cases when the SUT get
                an incoming message, and then check its remote address.

                TODO: here we could validate if host/port values are
                indeed valid. However, as this is kind of special case,
                and likely not so common, it doesn't have high priority.
             */
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        String host = constantPool.getRandomString();
        int port = constantPool.getRandomInt();
        port = getPort(port);
        addr = new EvoSuiteRemoteAddress(host, port);
    }
    setValue(addr);
}
Also used : EvoSuiteRemoteAddress(org.evosuite.runtime.testdata.EvoSuiteRemoteAddress) ConstantPool(org.evosuite.seeding.ConstantPool) EndPointInfo(org.evosuite.runtime.vnet.EndPointInfo)

Aggregations

EvoSuiteRemoteAddress (org.evosuite.runtime.testdata.EvoSuiteRemoteAddress)2 EndPointInfo (org.evosuite.runtime.vnet.EndPointInfo)1 ConstantPool (org.evosuite.seeding.ConstantPool)1 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1