Class PanamaWastRunner
This class provides methods to execute WAST files directly using Wasmtime's built-in test execution engine via the Panama Foreign Function Interface, ensuring 100% compatibility with Wasmtime's own test behavior.
WAST files are the standard test format used by the WebAssembly specification and contain module definitions along with test assertions (e.g., assert_return, assert_trap, assert_invalid).
Thread Safety: This class is thread-safe. Multiple threads can execute WAST files concurrently.
Example Usage:
// Execute a WAST file
WastExecutionResult result = PanamaWastRunner.executeWastFile("tests/test.wast");
if (result.allPassed()) {
System.out.println("All tests passed!");
} else {
System.out.println("Failed: " + result.getFailedDirectives() + " directives");
}
// Execute WAST content from a string
String wastContent = "(module (func (export \"test\") (result i32) i32.const 42))";
WastExecutionResult result = PanamaWastRunner.executeWastString("inline.wast", wastContent);
-
Method Summary
Modifier and TypeMethodDescriptionstatic ai.tegmentum.wasmtime4j.wast.WastExecutionResultexecuteWastBytes(String filename, byte[] wastContent) Executes WAST content from a byte array.static ai.tegmentum.wasmtime4j.wast.WastExecutionResultexecuteWastFile(String filePath) Executes a WAST file from disk.static ai.tegmentum.wasmtime4j.wast.WastExecutionResultexecuteWastFile(Path path) Executes a WAST file from a Path object.static voidexecuteWastFileOrThrow(String filePath) Convenience method to execute a WAST file and throw an exception if it fails.static ai.tegmentum.wasmtime4j.wast.WastExecutionResultexecuteWastString(String filename, String wastContent) Executes WAST content from a string.static voidexecuteWastStringOrThrow(String filename, String wastContent) Convenience method to execute WAST content and throw an exception if it fails.
-
Method Details
-
executeWastFile
Executes a WAST file from disk.This method loads and executes a WAST file using Wasmtime's native WAST parser. The file should be in standard WAST format with module definitions and test assertions.
- Parameters:
filePath- the path to the WAST file to execute (must exist and be readable)- Returns:
- the execution results containing pass/fail information
- Throws:
IllegalArgumentException- if filePath is null or emptyRuntimeException- if the native execution fails catastrophically
-
executeWastFile
Executes a WAST file from a Path object.- Parameters:
path- the path to the WAST file- Returns:
- the execution results
- Throws:
IllegalArgumentException- if path is nullRuntimeException- if the native execution fails
-
executeWastString
public static ai.tegmentum.wasmtime4j.wast.WastExecutionResult executeWastString(String filename, String wastContent) Executes WAST content from a string.This method executes WAST content provided as a string, which is useful for inline test definitions or dynamically generated tests.
- Parameters:
filename- the filename to use for error reporting (not a real file)wastContent- the WAST content to execute (in standard WAST text format)- Returns:
- the execution results
- Throws:
IllegalArgumentException- if filename or wastContent is null or emptyRuntimeException- if the native execution fails
-
executeWastBytes
public static ai.tegmentum.wasmtime4j.wast.WastExecutionResult executeWastBytes(String filename, byte[] wastContent) Executes WAST content from a byte array.This is the most efficient method for executing WAST content that is already in byte form (e.g., read from a file or network).
- Parameters:
filename- the filename to use for error reportingwastContent- the WAST content as UTF-8 encoded bytes- Returns:
- the execution results
- Throws:
IllegalArgumentException- if filename or wastContent is nullRuntimeException- if the native execution fails
-
executeWastFileOrThrow
Convenience method to execute a WAST file and throw an exception if it fails.- Parameters:
filePath- the path to the WAST file- Throws:
ai.tegmentum.wasmtime4j.wast.WastRunner.WastExecutionException- if any directives fail or execution errors occur
-
executeWastStringOrThrow
Convenience method to execute WAST content and throw an exception if it fails.- Parameters:
filename- the filename for error reportingwastContent- the WAST content- Throws:
ai.tegmentum.wasmtime4j.wast.WastRunner.WastExecutionException- if any directives fail or execution errors occur
-