Skip to content

Commit

Permalink
Adding a regression test of memory allocation failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamstolis committed May 13, 2021
1 parent 596650f commit a158000
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.junit.Test;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.exception.AbstractTruffleException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.ExceptionType;
Expand Down Expand Up @@ -779,6 +780,20 @@ public void testTableImport() throws IOException, InterruptedException {
});
}

@Test
public void testMemoryAllocationFailure() {
// Memory allocation should either succeed or throw an interop
// exception (not an internal error like OutOfMemoryError).
try {
Object[] memories = new Object[5];
for (int i = 0; i < memories.length; i++) {
memories[i] = Memory.create(new MemoryDescriptor(32767, 32767));
}
} catch (AbstractTruffleException ex) {
Assert.assertTrue("Should throw interop exception", InteropLibrary.getUncached(ex).isException(ex));
}
}

private static void runTest(Consumer<WasmContext> testCase) throws IOException {
final Context.Builder contextBuilder = Context.newBuilder("wasm");
contextBuilder.option("wasm.Builtins", "testutil:testutil");
Expand Down

0 comments on commit a158000

Please sign in to comment.