Skip to content

Commit

Permalink
Hide coverage implementation details from the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
antithesis-shomik committed Aug 29, 2024
1 parent 31a4f6e commit 20d56cb
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 53 deletions.
25 changes: 0 additions & 25 deletions ffi/src/main/java/com/antithesis/ffi/internal/FfiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

public class FfiHandler implements OutputHandler {

private static long offset = -1;

public static Optional<OutputHandler> get() {
try {
FfiWrapperJNI.loadLibrary();
Expand All @@ -28,27 +26,4 @@ public long random() {
return FfiWrapperJNI.fuzz_get_random();
}

@Override
public long initializeModuleCoverage(long edgeCount, String symbolFilePath) {
if (offset != -1) {
// A Java application may not contain multiple "modules" in Antithesis terms.
throw new IllegalStateException("Antithesis Java instrumentation has already been initialized.");
}
if (edgeCount > Integer.MAX_VALUE || edgeCount < 1) {
throw new IllegalArgumentException("Antithesis Java instrumentation supports [1 ," + Integer.MAX_VALUE + "] edges");
}
offset = FfiWrapperJNI.init_coverage_module(edgeCount, symbolFilePath);
String msg = String.format("Initialized Java module at offset 0x%016x with %d edges; symbol file %s", offset, edgeCount, symbolFilePath);
// TODO: (@shomik) logger.info(msg);
return offset;
}

@Override
public void notifyModuleEdge(long edgePlusModule) {
// Right now, the Java implementation defers completely to the native library.
// See instrumentation.h to understand the logic here. The shim (i.e. StaticModule.java)
// is responsible for handling the return value.
FfiWrapperJNI.notify_coverage(edgePlusModule);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ public interface OutputHandler {
void output(String value);

long random();

long initializeModuleCoverage(long edgeCount, String symbolFilePath);

void notifyModuleEdge(long edgePlusModule);
}

17 changes: 0 additions & 17 deletions sdk/src/main/java/com/antithesis/sdk/internal/HandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ public long random() {
return new Random().nextLong();
}

@Override
public long initializeModuleCoverage(long edgeCount, String symbolFilePath) {
return edgeCount;
}

@Override
public void notifyModuleEdge(long edgePlusModule) {
}
}

private static class LocalHandler implements OutputHandler {
Expand Down Expand Up @@ -102,7 +94,6 @@ public void output(final String value) {
writer.write("\n");
writer.flush();
} catch (IOException ignored) {
// TODO (@shomik) logging
}
}

Expand All @@ -111,14 +102,6 @@ public long random() {
return new Random().nextLong();
}

@Override
public long initializeModuleCoverage(long edgeCount, String symbolFilePath) {
return 0;
}

@Override
public void notifyModuleEdge(long edgePlusModule) {
}
}

}
7 changes: 0 additions & 7 deletions sdk/src/main/java/com/antithesis/sdk/internal/Internal.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,4 @@ public static void dispatchOutput(final ObjectNode s) {
}
}

public static long dispatchInitializeModuleCoverage(long edgeCount, String symbolFilePath) {
return HandlerFactory.get().initializeModuleCoverage(edgeCount, symbolFilePath);
}

public static void dispatchNotifyModuleEdge(long edgePlusModule) {
HandlerFactory.get().notifyModuleEdge(edgePlusModule);
}
}

0 comments on commit 20d56cb

Please sign in to comment.