Search in sources :

Example 1 with GlobalRegistry

use of org.graalvm.wasm.GlobalRegistry in project graal by oracle.

the class WasmFileSuite method assertContextEqual.

private static void assertContextEqual(ContextState expectedState, ContextState actualState) {
    // Compare memories
    final WasmMemory expectedMemory = expectedState.memory();
    final WasmMemory actualMemory = actualState.memory();
    if (expectedMemory == null) {
        Assert.assertNull("Memory should be null", actualMemory);
    } else {
        Assert.assertNotNull("Memory should not be null", actualMemory);
        Assert.assertEquals("Mismatch in memory lengths", expectedMemory.byteSize(), actualMemory.byteSize());
        for (int ptr = 0; ptr < expectedMemory.byteSize(); ptr++) {
            byte expectedByte = (byte) expectedMemory.load_i32_8s(null, ptr);
            byte actualByte = (byte) actualMemory.load_i32_8s(null, ptr);
            Assert.assertEquals("Memory mismatch at offset " + ptr + ",", expectedByte, actualByte);
        }
    }
    // Compare globals
    final GlobalRegistry firstGlobals = expectedState.globals();
    final GlobalRegistry lastGlobals = actualState.globals();
    Assert.assertEquals("Mismatch in global counts.", firstGlobals.count(), lastGlobals.count());
    for (int address = 0; address < firstGlobals.count(); address++) {
        long first = firstGlobals.loadAsLong(address);
        long last = lastGlobals.loadAsLong(address);
        Assert.assertEquals("Mismatch in global at " + address + ". ", first, last);
    }
    // Check number of opened file descriptors
    Assert.assertEquals("Mismatch in file descriptor counts.", expectedState.openedFdCount, actualState.openedFdCount);
}
Also used : GlobalRegistry(org.graalvm.wasm.GlobalRegistry) WasmMemory(org.graalvm.wasm.memory.WasmMemory)

Example 2 with GlobalRegistry

use of org.graalvm.wasm.GlobalRegistry in project graal by oracle.

the class WasmFileSuite method saveContext.

private static ContextState saveContext(WasmContext context) {
    Assert.assertTrue("Currently, only 0 or 1 memories can be saved.", context.memories().count() <= 1);
    final WasmMemory currentMemory = context.memories().count() == 1 ? context.memories().memory(0).duplicate() : null;
    final GlobalRegistry globals = context.globals().duplicate();
    return new ContextState(currentMemory, globals, context.fdManager().size());
}
Also used : GlobalRegistry(org.graalvm.wasm.GlobalRegistry) WasmMemory(org.graalvm.wasm.memory.WasmMemory)

Aggregations

GlobalRegistry (org.graalvm.wasm.GlobalRegistry)2 WasmMemory (org.graalvm.wasm.memory.WasmMemory)2