Class PanamaWastRunner

java.lang.Object
ai.tegmentum.wasmtime4j.panama.PanamaWastRunner

public final class PanamaWastRunner extends Object
Panama FFI wrapper for executing WAST (WebAssembly Test) files using Wasmtime's native WAST parser.

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 Details

    • executeWastFile

      public static ai.tegmentum.wasmtime4j.wast.WastExecutionResult executeWastFile(String filePath)
      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 empty
      RuntimeException - if the native execution fails catastrophically
    • executeWastFile

      public static ai.tegmentum.wasmtime4j.wast.WastExecutionResult executeWastFile(Path path)
      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 null
      RuntimeException - 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 empty
      RuntimeException - 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 reporting
      wastContent - the WAST content as UTF-8 encoded bytes
      Returns:
      the execution results
      Throws:
      IllegalArgumentException - if filename or wastContent is null
      RuntimeException - if the native execution fails
    • executeWastFileOrThrow

      public static void executeWastFileOrThrow(String filePath)
      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

      public static void executeWastStringOrThrow(String filename, String wastContent)
      Convenience method to execute WAST content and throw an exception if it fails.
      Parameters:
      filename - the filename for error reporting
      wastContent - the WAST content
      Throws:
      ai.tegmentum.wasmtime4j.wast.WastRunner.WastExecutionException - if any directives fail or execution errors occur