* Add a wasmtime-specific `wasmtime_wat2wasm` C API This commit implements a wasmtime-specific C API for converting the text format to the binary format. An upstream spec issue exists for adding this to the C API, but in the meantime we can experiment with our own version of this API and use it in the C# extension, for example! Closes #1000 * Reorder arguments * Use wasm_byte_vec_t for input `*.wat` * Mark wat input as const * Return an error message and use `fixed` * Actually include the error message * Use `fixed` in `Module.cs` as well
170 lines
4.9 KiB
C#
170 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace Wasmtime.Tests
|
|
{
|
|
public class FunctionImportsFixture : ModuleFixture
|
|
{
|
|
protected override string ModuleFileName => "FunctionImports.wat";
|
|
}
|
|
|
|
public class FunctionImportsTests : IClassFixture<FunctionImportsFixture>
|
|
{
|
|
public FunctionImportsTests(FunctionImportsFixture fixture)
|
|
{
|
|
Fixture = fixture;
|
|
}
|
|
|
|
private FunctionImportsFixture Fixture { get; set; }
|
|
|
|
[Theory]
|
|
[MemberData(nameof(GetFunctionImports))]
|
|
public void ItHasTheExpectedFunctionImports(string importModule, string importName, ValueKind[] expectedParameters, ValueKind[] expectedResults)
|
|
{
|
|
var import = Fixture.Module.Imports.Functions.Where(f => f.ModuleName == importModule && f.Name == importName).FirstOrDefault();
|
|
import.Should().NotBeNull();
|
|
import.Parameters.Should().Equal(expectedParameters);
|
|
import.Results.Should().Equal(expectedResults);
|
|
}
|
|
|
|
[Fact]
|
|
public void ItHasTheExpectedNumberOfExportedFunctions()
|
|
{
|
|
GetFunctionImports().Count().Should().Be(Fixture.Module.Imports.Functions.Count);
|
|
}
|
|
|
|
public static IEnumerable<object[]> GetFunctionImports()
|
|
{
|
|
yield return new object[] {
|
|
"",
|
|
"no_params_no_results",
|
|
Array.Empty<ValueKind>(),
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_i32_param_no_results",
|
|
new ValueKind[] {
|
|
ValueKind.Int32
|
|
},
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_i64_param_no_results",
|
|
new ValueKind[] {
|
|
ValueKind.Int64
|
|
},
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_f32_param_no_results",
|
|
new ValueKind[] {
|
|
ValueKind.Float32
|
|
},
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_f64_param_no_results",
|
|
new ValueKind[] {
|
|
ValueKind.Float64
|
|
},
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_param_of_each_type",
|
|
new ValueKind[] {
|
|
ValueKind.Int32,
|
|
ValueKind.Int64,
|
|
ValueKind.Float32,
|
|
ValueKind.Float64
|
|
},
|
|
Array.Empty<ValueKind>()
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"no_params_one_i32_result",
|
|
Array.Empty<ValueKind>(),
|
|
new ValueKind[] {
|
|
ValueKind.Int32,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"no_params_one_i64_result",
|
|
Array.Empty<ValueKind>(),
|
|
new ValueKind[] {
|
|
ValueKind.Int64,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"no_params_one_f32_result",
|
|
Array.Empty<ValueKind>(),
|
|
new ValueKind[] {
|
|
ValueKind.Float32,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"no_params_one_f64_result",
|
|
Array.Empty<ValueKind>(),
|
|
new ValueKind[] {
|
|
ValueKind.Float64,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_result_of_each_type",
|
|
Array.Empty<ValueKind>(),
|
|
new ValueKind[] {
|
|
ValueKind.Int32,
|
|
ValueKind.Int64,
|
|
ValueKind.Float32,
|
|
ValueKind.Float64,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"",
|
|
"one_param_and_result_of_each_type",
|
|
new ValueKind[] {
|
|
ValueKind.Int32,
|
|
ValueKind.Int64,
|
|
ValueKind.Float32,
|
|
ValueKind.Float64,
|
|
},
|
|
new ValueKind[] {
|
|
ValueKind.Int32,
|
|
ValueKind.Int64,
|
|
ValueKind.Float32,
|
|
ValueKind.Float64,
|
|
}
|
|
};
|
|
|
|
yield return new object[] {
|
|
"other",
|
|
"function_from_module",
|
|
Array.Empty<ValueKind>(),
|
|
Array.Empty<ValueKind>(),
|
|
};
|
|
}
|
|
}
|
|
}
|