aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 21:26:50 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 21:26:50 +0000
commite89651789b217efbb060e07c022caf1573d567ba (patch)
tree4326989273960aa2b2aed927f2b879bda4ff2eb9 /src/test/java
parentf0ee4f2251f02bdba1243a39f5c1ea639b86c4df (diff)
Support 64-bit memories
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmObjdump.java3
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java8
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java83
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java26
5 files changed, 87 insertions, 37 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java
index b8b7f531..59c24bf7 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/PatioToWasmTests.java
@@ -25,7 +25,7 @@ import java.util.List;
public class PatioToWasmTests extends PatioExampleTests {
@Override
protected ExecutionResult run(PatioCompilationUnit patio) throws IOException, InterruptedException {
- var wasmModule = PatioToWasm.generateCompilationUnit(patio);
+ var wasmModule = PatioToWasm.generateCompilationUnit(patio, WasmTarget.WASM32);
wasmModule = WasmBackend.generateNativeRuntime(wasmModule);
@@ -64,7 +64,7 @@ public class PatioToWasmTests extends PatioExampleTests {
executablePath
);
- WasmBinaryFormatTesting.validate(executablePath);
+ WasmBinaryFormatTesting.validate(executablePath, WasmTarget.WASM32);
return TestProcessRunner.runCaptureOutput(Lists.concat(
WasmTesting.BINARY_RUNNER,
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmObjdump.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmObjdump.java
index 60133124..761a2dba 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmObjdump.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/WasmObjdump.java
@@ -23,6 +23,7 @@ public class WasmObjdump {
}
public static String objdump(Path path) throws IOException, InterruptedException {
- return TestProcessRunner.runCaptureOutput(List.of("wasm-objdump", "-dx", path.toString())).throwOnError().stdout();
+ var command = List.of("wasm-objdump", "-dx", path.toString());
+ return TestProcessRunner.runCaptureOutput(command).throwOnError().stdout();
}
}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
index e70a5348..a0541da0 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatInstructionsTests.java
@@ -11,7 +11,7 @@ import org.shedlang.compiler.testing.snapshots.Snapshotter;
import java.io.IOException;
import java.util.List;
-import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModule;
+import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModuleWasm32;
@ExtendWith({SnapshotResolver.class})
public class WasmBinaryFormatInstructionsTests {
@@ -40,7 +40,7 @@ public class WasmBinaryFormatInstructionsTests {
))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -65,7 +65,7 @@ public class WasmBinaryFormatInstructionsTests {
))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -113,7 +113,7 @@ public class WasmBinaryFormatInstructionsTests {
))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java
index e4b304b8..7054c4cf 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatModulesTests.java
@@ -14,7 +14,8 @@ import org.shedlang.compiler.testing.snapshots.Snapshotter;
import java.io.IOException;
import java.util.List;
-import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModule;
+import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModuleWasm32;
+import static org.shedlang.compiler.backends.wasm.structure.binary.WasmBinaryFormatTesting.serializeModuleWasm64;
@ExtendWith({SnapshotResolver.class})
public class WasmBinaryFormatModulesTests {
@@ -22,7 +23,7 @@ public class WasmBinaryFormatModulesTests {
public void canSerializeEmptyModule(Snapshotter snapshotter) throws IOException, InterruptedException {
var module = WasmModule.EMPTY;
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -36,7 +37,7 @@ public class WasmBinaryFormatModulesTests {
List.of(WasmValueType.F32, WasmValueType.F64)
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -69,7 +70,7 @@ public class WasmBinaryFormatModulesTests {
new WasmExpression(List.of(new WasmI64Const(0)))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -88,7 +89,7 @@ public class WasmBinaryFormatModulesTests {
new WasmImportDescriptor.Func("Identifier2", new WasmFuncType(List.of(WasmValueType.I32), List.of()))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -111,20 +112,22 @@ public class WasmBinaryFormatModulesTests {
new WasmImportDescriptor.Func("Identifier1", new WasmFuncType(List.of(), List.of()))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@Test
public void canSerializeModuleWithTableImports(Snapshotter snapshotter) throws IOException, InterruptedException {
+ // Import tables with limits both with and without a maximum.
+ // 64-bit indices are not supported for tables, even in wasm64.
var module = WasmModule.EMPTY
.addImport(new WasmImport(
"ModuleName1",
"EntityName1",
new WasmImportDescriptor.Table(new WasmTableType(
WasmReferenceType.EXTERN_REF,
- WasmLimits.min(1)
+ WasmLimits.min32(1)
))
))
.addImport(new WasmImport(
@@ -132,27 +135,43 @@ public class WasmBinaryFormatModulesTests {
"EntityName2",
new WasmImportDescriptor.Table(new WasmTableType(
WasmReferenceType.FUNC_REF,
- WasmLimits.range(2, 5)
+ WasmLimits.range32(2, 5)
))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@Test
- public void canSerializeModuleWithMemoryImports(Snapshotter snapshotter) throws IOException, InterruptedException {
+ public void canSerializeModuleWith32BitMemoryImports(Snapshotter snapshotter) throws IOException, InterruptedException {
var module = WasmModule.EMPTY
.addImport(new WasmImport(
"ModuleName1",
"EntityName1",
new WasmImportDescriptor.Memory(new WasmMemoryType(
- WasmLimits.min(1)
+ WasmLimits.min(WasmIndexType.I32, 1)
))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
+
+ snapshotter.assertSnapshot(result);
+ }
+
+ @Test
+ public void canSerializeModuleWith64BitMemoryImports(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var module = WasmModule.EMPTY
+ .addImport(new WasmImport(
+ "ModuleName1",
+ "EntityName1",
+ new WasmImportDescriptor.Memory(new WasmMemoryType(
+ WasmLimits.min(WasmIndexType.I64, 1)
+ ))
+ ));
+
+ var result = serializeModuleWasm64(module);
snapshotter.assertSnapshot(result);
}
@@ -177,7 +196,7 @@ public class WasmBinaryFormatModulesTests {
)
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -187,26 +206,38 @@ public class WasmBinaryFormatModulesTests {
var module = WasmModule.EMPTY
.addTable(new WasmTable(new WasmTableType(
WasmReferenceType.FUNC_REF,
- WasmLimits.min(1)
+ WasmLimits.min32(1)
)))
.addTable(new WasmTable(new WasmTableType(
WasmReferenceType.EXTERN_REF,
- WasmLimits.range(2, 3)
+ WasmLimits.range32(2, 3)
+ )));
+
+ var result = serializeModuleWasm32(module);
+
+ snapshotter.assertSnapshot(result);
+ }
+
+ @Test
+ public void canSerializeModuleWith32BitMemories(Snapshotter snapshotter) throws IOException, InterruptedException {
+ var module = WasmModule.EMPTY
+ .addMemory(new WasmMemory(new WasmMemoryType(
+ WasmLimits.min(WasmIndexType.I32, 1)
)));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@Test
- public void canSerializeModuleWithMemories(Snapshotter snapshotter) throws IOException, InterruptedException {
+ public void canSerializeModuleWith64BitMemories(Snapshotter snapshotter) throws IOException, InterruptedException {
var module = WasmModule.EMPTY
.addMemory(new WasmMemory(new WasmMemoryType(
- WasmLimits.min(1)
+ WasmLimits.min(WasmIndexType.I64, 1)
)));
- var result = serializeModule(module);
+ var result = serializeModuleWasm64(module);
snapshotter.assertSnapshot(result);
}
@@ -225,7 +256,7 @@ public class WasmBinaryFormatModulesTests {
new WasmExpression(List.of(new WasmI64Const(9)))
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -256,14 +287,14 @@ public class WasmBinaryFormatModulesTests {
))
.addTable(new WasmTable(new WasmTableType(
WasmReferenceType.FUNC_REF,
- WasmLimits.min(1)
+ WasmLimits.min32(1)
)))
.addElementSegment(WasmElementSegment.funcIndicesActive(List.of(
new WasmFuncIndex(0),
new WasmFuncIndex(2)
)));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -271,7 +302,7 @@ public class WasmBinaryFormatModulesTests {
@Test
public void canSerializeModuleWithDataSegments(Snapshotter snapshotter) throws IOException, InterruptedException {
var module = WasmModule.EMPTY
- .addMemory(new WasmMemory(new WasmMemoryType(WasmLimits.min(10))))
+ .addMemory(new WasmMemory(new WasmMemoryType(WasmLimits.min32(10))))
.addDataSegment(new WasmDataSegment(
".data",
new byte[] { 1, 2, 3, 4 },
@@ -304,7 +335,7 @@ public class WasmBinaryFormatModulesTests {
)
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -336,7 +367,7 @@ public class WasmBinaryFormatModulesTests {
.addInitFunc(new WasmInitFunc(0, new WasmFuncName("f3")))
.addInitFunc(new WasmInitFunc(4, new WasmFuncName("f1")));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
@@ -360,7 +391,7 @@ public class WasmBinaryFormatModulesTests {
List.of(WasmValueType.I32, WasmValueType.I64)
));
- var result = serializeModule(module);
+ var result = serializeModuleWasm32(module);
snapshotter.assertSnapshot(result);
}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
index cc9fd5fa..69a03800 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatTesting.java
@@ -1,12 +1,15 @@
package org.shedlang.compiler.backends.wasm.structure.binary;
+import org.shedlang.compiler.backends.wasm.WasmTarget;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmModule;
import org.shedlang.compiler.testing.TestProcessRunner;
+import org.shedlang.compiler.util.P;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.List;
import static org.shedlang.compiler.backends.wasm.structure.WasmObjdump.objdump;
@@ -15,7 +18,18 @@ public class WasmBinaryFormatTesting {
private WasmBinaryFormatTesting() {
}
- static String serializeModule(WasmModule module) throws IOException, InterruptedException {
+ static String serializeModuleWasm32(WasmModule module) throws IOException, InterruptedException {
+ return serializeModule(module, WasmTarget.WASM32);
+ }
+
+ static String serializeModuleWasm64(WasmModule module) throws IOException, InterruptedException {
+ return serializeModule(module, WasmTarget.WASM64);
+ }
+
+ private static String serializeModule(
+ WasmModule module,
+ WasmTarget target
+ ) throws IOException, InterruptedException {
Files.createDirectories(Path.of("tests-tmp"));
var temporaryDirectory = Files.createTempDirectory(Path.of("tests-tmp"), "WasmBinaryFormat");
var modulePath = temporaryDirectory.resolve("module.wasm");
@@ -25,13 +39,17 @@ public class WasmBinaryFormatTesting {
WasmBinaryFormatModules.serializeModule(module, outputStream);
}
- validate(modulePath);
+ validate(modulePath, target);
return objdump(modulePath);
}
- public static void validate(Path path) throws IOException, InterruptedException {
- TestProcessRunner.runCaptureOutput(List.of("wasm-validate", "--enable-exceptions", path.toString()))
+ public static void validate(Path path, WasmTarget target) throws IOException, InterruptedException {
+ var command = P.vector("wasm-validate", "--enable-exceptions")
+ .plusAll(target.wabtFlags())
+ .plus(path.toString());
+
+ TestProcessRunner.runCaptureOutput(command)
.throwOnError();
}
}