Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using wabt compiled to wasm #337

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Module;
import com.dylibso.chicory.runtime.ModuleType;
import com.dylibso.chicory.wabt.Wat2Wasm;
import com.dylibso.chicory.wasm.exceptions.MalformedException;
import com.dylibso.chicory.wat2wasm.Wat2Wasm;
import java.io.File;

public class TestModule {
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</developers>

<modules>
<module>wat2wasm</module>
<module>wabt</module>
<module>wasm-support-plugin</module>
<module>test-gen-plugin</module>
<module>wasi-test-gen-plugin</module>
Expand Down Expand Up @@ -89,6 +89,9 @@
<commons-io.version>2.16.1</commons-io.version>
<jmh.version>1.37</jmh.version>

<!-- Latest published version of Chicory used to run wabt tools -->
<chicory.latest.version>0.0.10</chicory.latest.version>

<maven-plugin-api.version>3.9.6</maven-plugin-api.version>
<maven-plugin-annotations.version>3.13.0</maven-plugin-annotations.version>

Expand Down Expand Up @@ -116,7 +119,7 @@
<dependencies>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wat2wasm</artifactId>
<artifactId>wabt</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Module;
import com.dylibso.chicory.runtime.ModuleType;
import com.dylibso.chicory.wabt.Wat2Wasm;
import com.dylibso.chicory.wasm.exceptions.MalformedException;
import com.dylibso.chicory.wat2wasm.Wat2Wasm;
import java.io.File;

public class TestModule {
Expand Down
22 changes: 22 additions & 0 deletions test-gen-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
<description>A Maven Plugin to generate tests from the WebAssembly testsuite</description>

<dependencies>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wabt</artifactId>
<exclusions>
<exclusion>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm</artifactId>
</exclusion>
<exclusion>
<groupId>com.dylibso.chicory</groupId>
<artifactId>log</artifactId>
</exclusion>
<exclusion>
<groupId>com.dylibso.chicory</groupId>
<artifactId>runtime</artifactId>
</exclusion>
<exclusion>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasi</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,19 @@ public class JavaTestGen {

private final List<String> excludedInvalidWasts;

private final boolean useAot;

public JavaTestGen(
Log log,
File baseDir,
File sourceTargetFolder,
List<String> excludedTests,
List<String> excludedMalformedWasts,
List<String> excludedInvalidWasts,
boolean useAot) {
List<String> excludedInvalidWasts) {
this.log = log;
this.baseDir = baseDir;
this.sourceTargetFolder = sourceTargetFolder;
this.excludedTests = excludedTests;
this.excludedMalformedWasts = excludedMalformedWasts;
this.excludedInvalidWasts = excludedInvalidWasts;
this.useAot = useAot;
}

public CompilationUnit generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.dylibso.chicory.maven.Constants.SPEC_JSON;

import com.dylibso.chicory.maven.wast.Wast;
import com.dylibso.chicory.wabt.Wast2Json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.javaparser.utils.SourceRoot;
import java.io.File;
Expand Down Expand Up @@ -75,21 +76,6 @@ public class TestGenMojo extends AbstractMojo {
@Parameter(required = true, defaultValue = "${project.build.directory}/compiled-wast")
private File compiledWastTargetFolder;

/**
* Wabt version
* Accepts a specific version or "latest" to query the GH API
*/
@Parameter(required = true, property = "wabtVersion", defaultValue = "1.0.34")
private String wabtVersion;

@Parameter(
required = true,
defaultValue = "https://github.com/WebAssembly/wabt/releases/download/")
private String wabtReleasesURL;

@Parameter(required = true, defaultValue = "${project.build.directory}/wabt")
private File wabtDownloadTargetFolder;

/**
* Include list for the wast files that should generate an ordered spec.
*/
Expand Down Expand Up @@ -117,9 +103,6 @@ public class TestGenMojo extends AbstractMojo {
@Parameter(defaultValue = "[]")
private List<String> excludedWasts;

@Parameter(required = false, defaultValue = "false")
private boolean useAot;

/**
* The current Maven project.
*/
Expand All @@ -137,23 +120,14 @@ public void execute() throws MojoExecutionException {

// Instantiate the utilities
var testSuiteDownloader = new TestSuiteDownloader(log);
var wast2Json =
new Wast2JsonWrapper(
log,
wabtDownloadTargetFolder,
wabtReleasesURL,
wabtVersion,
osName,
compiledWastTargetFolder);
var testGen =
new JavaTestGen(
log,
project.getBasedir(),
sourceDestinationFolder,
excludedTests,
excludedMalformedWasts,
excludedInvalidWasts,
useAot);
excludedInvalidWasts);

JavaParserMavenUtils.makeJavaParserLogToMavenOutput(getLog());

Expand Down Expand Up @@ -188,14 +162,11 @@ public void execute() throws MojoExecutionException {
"Some wast files are not included or excluded: " + allWastFiles);
}

wast2Json.fetch();

// generate the tests
final SourceRoot dest = new SourceRoot(sourceDestinationFolder.toPath());
final SourceRoot importSourceRoot = new SourceRoot(importsSourcesFolder.toPath());

TestGenerator testGenerator =
new TestGenerator(wast2Json, testGen, importSourceRoot, dest);
TestGenerator testGenerator = new TestGenerator(testGen, importSourceRoot, dest);

includedWasts.stream().parallel().forEach(testGenerator::generateTests);

Expand Down Expand Up @@ -226,17 +197,11 @@ private static void validate(List<String> items, String name, boolean requireSor

private class TestGenerator {

private final Wast2JsonWrapper wast2Json;
private final JavaTestGen testGen;
private final SourceRoot importSourceRoot;
private final SourceRoot dest;

private TestGenerator(
Wast2JsonWrapper wast2Json,
JavaTestGen testGen,
SourceRoot importSourceRoot,
SourceRoot dest) {
this.wast2Json = wast2Json;
private TestGenerator(JavaTestGen testGen, SourceRoot importSourceRoot, SourceRoot dest) {
this.testGen = testGen;
this.importSourceRoot = importSourceRoot;
this.dest = dest;
Expand All @@ -249,29 +214,33 @@ private void generateTests(String spec) {
throw new IllegalArgumentException(
"Wast file " + wastFile.getAbsolutePath() + " not found");
}
var retries = 3;
File specFile = null;
File wasmFilesFolder = null;
Wast wast = null;

while (true) {
try {
wasmFilesFolder =
wast2Json.execute(testsuiteFolder.toPath().resolve(spec).toFile());
specFile = wasmFilesFolder.toPath().resolve(SPEC_JSON).toFile();

assert (specFile.exists());
var plainName = wastFile.getName().replace(".wast", "");
File wasmFilesFolder = compiledWastTargetFolder.toPath().resolve(plainName).toFile();
specFile = wasmFilesFolder.toPath().resolve(SPEC_JSON).toFile();
if (!wasmFilesFolder.mkdirs()) {
log.warn("Could not create folder: " + wasmFilesFolder);
}

// High parallelism introduces some flakiness
var retry = 3;
while (retry > 0) {
try {
var wast2json =
Wast2Json.builder().withFile(wastFile).withOutput(specFile).build();
wast2json.process();
wast = new ObjectMapper().readValue(specFile, Wast.class);
break;
} catch (Exception e) {
if (retries > 0) {
--retries;
} else {
throw new RuntimeException(e);
}
retry--;
}
}
if (retry <= 0) {
throw new RuntimeException("Failed to generate test sources");
}

var name = specFile.toPath().getParent().toFile().getName();
var cu = testGen.generate(name, wast, wasmFilesFolder, importSourceRoot);
dest.add(cu);
Expand Down
Loading
Loading