Skip to content

Commit 55b687b

Browse files
authored
Improved some test coverage. (#192)
Fixed one small issue in the process: - Modified `wasmtime_engine_increment_epoch` to return `void` instead of `IntPtr`. Based on signature from these docs: https://docs.wasmtime.dev/c-api/engine_8h.html
1 parent 992efb0 commit 55b687b

File tree

7 files changed

+133
-1
lines changed

7 files changed

+133
-1
lines changed

src/Engine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static class Native
8484
public static extern void wasm_engine_delete(IntPtr engine);
8585

8686
[DllImport(LibraryName)]
87-
public static extern IntPtr wasmtime_engine_increment_epoch(IntPtr engine);
87+
public static extern void wasmtime_engine_increment_epoch(IntPtr engine);
8888
}
8989

9090
private readonly Handle handle;

tests/ConfigTests.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using FluentAssertions;
34
using Xunit;
45

@@ -16,6 +17,15 @@ public void ItSetsCompilerStrategy()
1617
using var engine = new Engine(config);
1718
}
1819

20+
[Fact]
21+
public void ItFailsSettingNonexistantCompilerStrategy()
22+
{
23+
var config = new Config();
24+
25+
var act = () => { config.WithCompilerStrategy((CompilerStrategy)123); };
26+
act.Should().Throw<ArgumentOutOfRangeException>();
27+
}
28+
1929
[Fact]
2030
public void ItSetsProfilingStrategy()
2131
{
@@ -26,6 +36,15 @@ public void ItSetsProfilingStrategy()
2636
using var engine = new Engine(config);
2737
}
2838

39+
[Fact]
40+
public void ItFailsSettingNonexistantProfilingStrategy()
41+
{
42+
var config = new Config();
43+
44+
var act = () => { config.WithProfilingStrategy((ProfilingStrategy)123); };
45+
act.Should().Throw<ArgumentOutOfRangeException>();
46+
}
47+
2948
[Fact]
3049
public void ItSetsOptimizationLevel()
3150
{
@@ -36,6 +55,15 @@ public void ItSetsOptimizationLevel()
3655
using var engine = new Engine(config);
3756
}
3857

58+
[Fact]
59+
public void ItFailsSettingNonexistantOptimizationLevel()
60+
{
61+
var config = new Config();
62+
63+
var act = () => { config.WithOptimizationLevel((OptimizationLevel)123); };
64+
act.Should().Throw<ArgumentOutOfRangeException>();
65+
}
66+
3967
[Fact]
4068
public void ItSetsNanCanonicalization()
4169
{
@@ -55,5 +83,71 @@ public void ItSetsEpochInterruption()
5583

5684
using var engine = new Engine(config);
5785
}
86+
87+
[Fact]
88+
public void ItSetsDebugInfo()
89+
{
90+
var config = new Config();
91+
92+
config.WithDebugInfo(true);
93+
94+
using var engine = new Engine(config);
95+
}
96+
97+
[Fact]
98+
public void ItSetsThreads()
99+
{
100+
var config = new Config();
101+
config.WithWasmThreads(true);
102+
103+
using var engine = new Engine(config);
104+
using var module = Module.FromTextFile(engine, Path.Combine("Modules", "SharedMemory.wat"));
105+
}
106+
107+
[Fact]
108+
public void ItSetsSIMD()
109+
{
110+
var config = new Config();
111+
config.WithSIMD(false);
112+
113+
Action act = () =>
114+
{
115+
using var engine = new Engine(config);
116+
using var module = Module.FromTextFile(engine, Path.Combine("Modules", "SIMD.wat"));
117+
};
118+
119+
act.Should().Throw<WasmtimeException>();
120+
}
121+
122+
[Fact]
123+
public void ItSetsBulkMemory()
124+
{
125+
var config = new Config();
126+
config.WithBulkMemory(false);
127+
config.WithReferenceTypes(false);
128+
129+
Action act = () =>
130+
{
131+
using var engine = new Engine(config);
132+
using var module = Module.FromTextFile(engine, Path.Combine("Modules", "BulkMemory.wat"));
133+
};
134+
135+
act.Should().Throw<WasmtimeException>();
136+
}
137+
138+
[Fact]
139+
public void ItSetsMultiValue()
140+
{
141+
var config = new Config();
142+
config.WithMultiValue(false);
143+
144+
Action act = () =>
145+
{
146+
using var engine = new Engine(config);
147+
using var module = Module.FromTextFile(engine, Path.Combine("Modules", "MultiValue.wat"));
148+
};
149+
150+
act.Should().Throw<WasmtimeException>();
151+
}
58152
}
59153
}

tests/GlobalImportBindingTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ public void ItFailsToInstantiateWhenGlobalIsMut()
106106
.WithMessage("incompatible import type for `::global_i32`*");
107107
}
108108

109+
[Fact]
110+
public void ItFailsBindingGlobalsWithWrongType()
111+
{
112+
var global_i32_mut = new Global(Store, ValueKind.Int32, 0, Mutability.Mutable);
113+
114+
global_i32_mut.Wrap<float>().Should().BeNull();
115+
global_i32_mut.Wrap<double>().Should().BeNull();
116+
global_i32_mut.Wrap<uint>().Should().BeNull();
117+
}
118+
119+
[Fact]
120+
public void ItFailsMutatingImmutableGlobal()
121+
{
122+
var global_i32_mut = new Global(Store, ValueKind.Int32, 0, Mutability.Immutable);
123+
Action action = () => global_i32_mut.Wrap<int>()!.SetValue(3);
124+
action.Should().Throw<InvalidOperationException>();
125+
}
126+
109127
[Fact]
110128
public void ItBindsTheGlobalsCorrectly()
111129
{

tests/Modules/BulkMemory.wat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(func (param $dst i32) (param $src i32) (param $size i32) (result i32)
3+
local.get $dst
4+
local.get $src
5+
local.get $size
6+
memory.copy
7+
local.get $dst
8+
)
9+
)

tests/Modules/MultiValue.wat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(module
2+
(func $echo_tuple2 (result i32 i32) i32.const 1 i32.const 2)
3+
(export "$echo_tuple2" (func $echo_tuple2))
4+
)

tests/Modules/SIMD.wat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(module
2+
(func $echo_v128 (param v128) (result v128) local.get 0)
3+
(export "$echo_v128" (func $echo_v128))
4+
)

tests/Modules/SharedMemory.wat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(module
2+
(memory 1 1 shared)
3+
)

0 commit comments

Comments
 (0)