Skip to content

Commit

Permalink
hostname infos
Browse files Browse the repository at this point in the history
  • Loading branch information
seran committed Oct 4, 2023
1 parent ef1d018 commit 1624ff9
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class BootTimeInfoDto {
* Information about the external services used inside the SUT
*/
public List<ExternalServiceInfoDto> externalServicesDto;

/**
* Collections of hostnames collected through InetAddressReplacement
*/
public List<HostnameInfoDto> hostnameInfoDtos;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.evomaster.client.java.controller.api.dto;

import java.util.Objects;

public class HostnameInfoDto {

public String remoteHostname;

public Boolean resolved;

public HostnameInfoDto(){};

public HostnameInfoDto(String remoteHostname, Boolean resolved) {
this.remoteHostname = remoteHostname;
this.resolved = resolved;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HostnameInfoDto that = (HostnameInfoDto) o;
return Objects.equals(remoteHostname, that.remoteHostname) && Objects.equals(resolved, that.resolved);
}

@Override
public int hashCode() {
return Objects.hash(remoteHostname, resolved);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public StatementDescription(String line, String method) {
*/
private final Set<ExternalServiceInfo> externalServices = new CopyOnWriteArraySet<>();

private final Set<HostnameInfo> hostnameInfos = new CopyOnWriteArraySet<>();

/**
* info for external services which have been referred to the default setup (eg, specified ip and port)
*/
Expand Down Expand Up @@ -265,6 +267,10 @@ public void addExternalService(ExternalServiceInfo hostInfo) {
externalServices.add(hostInfo);
}

public void addHostnameInfo(HostnameInfo hostnameInfo) {
hostnameInfos.add(hostnameInfo);
}

public Set<ExternalServiceInfo> getExternalServices() {
return Collections.unmodifiableSet(externalServices);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.evomaster.client.java.instrumentation;

import java.io.Serializable;

public class HostnameInfo implements Serializable {
private final String remoteHostname;

/**
* Will be true if the hostname resolved, otherwise false;
*/
private final Boolean resolved;

public HostnameInfo(String remoteHostname, Boolean resolved) {
this.remoteHostname = remoteHostname;
this.resolved = resolved;
}

public String getHostname() {
return remoteHostname;
}

public Boolean getResolved() {
return resolved;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes;

import org.evomaster.client.java.instrumentation.ExternalServiceInfo;
import org.evomaster.client.java.instrumentation.HostnameInfo;
import org.evomaster.client.java.instrumentation.coverage.methodreplacement.ExternalServiceInfoUtils;
import org.evomaster.client.java.instrumentation.coverage.methodreplacement.MethodReplacementClass;
import org.evomaster.client.java.instrumentation.coverage.methodreplacement.Replacement;
import org.evomaster.client.java.instrumentation.coverage.methodreplacement.UsageFilter;
import org.evomaster.client.java.instrumentation.shared.ExternalServiceSharedUtils;
import org.evomaster.client.java.instrumentation.shared.ReplacementCategory;
import org.evomaster.client.java.instrumentation.shared.ReplacementType;
import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;
Expand Down Expand Up @@ -44,12 +43,15 @@ public static InetAddress getByName(String host) throws UnknownHostException {
}
return InetAddress.getByName(host);
} catch (UnknownHostException e) {
ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo(
ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL,
host,
-1
);
ExecutionTracer.addExternalServiceHost(remoteHostInfo);
// ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo(
// ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL,
// host,
// -1,
// false
// );
HostnameInfo hostnameInfo = new HostnameInfo(host, false);
// ExecutionTracer.addExternalServiceHost(remoteHostInfo);
ExecutionTracer.addHostnameInfo(hostnameInfo);
throw e;
}
}
Expand All @@ -71,12 +73,15 @@ public static InetAddress[] getAllByName(String host) throws UnknownHostExceptio
}
return InetAddress.getAllByName(host);
} catch (UnknownHostException e) {
ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo(
ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL,
host,
-1
);
ExecutionTracer.addExternalServiceHost(remoteHostInfo);
// ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo(
// ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL,
// host,
// -1,
// false
// );
HostnameInfo hostnameInfo = new HostnameInfo(host, false);
// ExecutionTracer.addExternalServiceHost(remoteHostInfo);
ExecutionTracer.addHostnameInfo(hostnameInfo);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Methods of this class will be injected in the SUT to
Expand Down Expand Up @@ -674,6 +672,10 @@ public static void executingBranchJump(
updateBranch(className, line, branchId, t);
}

public static void addHostnameInfo(HostnameInfo hostnameInfo) {
getCurrentAdditionalInfo().addHostnameInfo(hostnameInfo);
}

/**
* Add the external HTTP/S hostname to the additional info to keep track.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.evomaster.core.problem.externalservice

import org.evomaster.core.search.EnvironmentAction
import org.evomaster.core.search.StructuralElement
import org.evomaster.core.search.gene.Gene

class DomainNameAction : EnvironmentAction(listOf()) {
override fun getName(): String {
return ""
}

override fun seeTopGenes(): List<out Gene> {
return listOf()
}

override fun copyContent(): StructuralElement {
return DomainNameAction()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.evomaster.core.problem.externalservice

open class HostnameInfo (
val remoteHostName: String,
val resolved: Boolean
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ open class HttpExternalServiceInfo(
fun toExternalService() : ExternalService {
return ExternalService(remoteHostname, remotePort)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.evomaster.client.java.instrumentation.shared.ExternalServiceSharedUti
import org.evomaster.core.EMConfig
import org.evomaster.core.Lazy
import org.evomaster.core.problem.externalservice.ExternalService
import org.evomaster.core.problem.externalservice.HostnameInfo
import org.evomaster.core.problem.externalservice.httpws.*
import org.evomaster.core.problem.externalservice.httpws.HttpWsExternalServiceUtils.generateRandomIPAddress
import org.evomaster.core.problem.externalservice.httpws.HttpWsExternalServiceUtils.isAddressAvailable
Expand Down Expand Up @@ -64,6 +65,9 @@ class HttpWsExternalServiceHandler {
*/
private val skippedExternalServices: MutableList<ExternalService> = mutableListOf()


private val hostnames: MutableList<HostnameInfo> = mutableListOf()

/**
* Contains last used loopback address for reference when creating
* a new address
Expand Down Expand Up @@ -110,6 +114,12 @@ class HttpWsExternalServiceHandler {
}
}

fun addHostname(hostnameInfo: HostnameInfo) {
if (config.externalServiceIPSelectionStrategy != EMConfig.ExternalServiceIPSelectionStrategy.NONE) {
hostnames.add(hostnameInfo);
}
}

private fun registerHttpExternalServiceInfo(externalServiceInfo: HttpExternalServiceInfo) {
if (skippedExternalServices.contains(externalServiceInfo.toExternalService())) {
return
Expand Down Expand Up @@ -321,4 +331,4 @@ class HttpWsExternalServiceHandler {
return output
}

}
}

0 comments on commit 1624ff9

Please sign in to comment.