forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutOfBoundsMemoryAccessTests.cs
50 lines (37 loc) · 1.38 KB
/
OutOfBoundsMemoryAccessTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using FluentAssertions;
using Xunit;
namespace Wasmtime.Tests
{
public class OutOfBoundsMemoryAccessFixture : ModuleFixture
{
protected override string ModuleFileName => "OutOfBoundsMemoryAccess.wat";
}
public class OutOfBoundsMemoryAccessTests : IClassFixture<OutOfBoundsMemoryAccessFixture>
{
public OutOfBoundsMemoryAccessTests(OutOfBoundsMemoryAccessFixture fixture)
{
Fixture = fixture;
Fixture.Host.ClearDefinitions();
}
private OutOfBoundsMemoryAccessFixture Fixture { get; set; }
[Fact]
public void ItDoesNotThrowsOnOutOfBoundsMemoryAccess()
{
var mem = Fixture.Host.DefineMemory("", "mem", minimum: 2, maximum: 2);
using var instance = Fixture.Host.Instantiate(Fixture.Module);
mem.ReadByte(65535).Should().Be(1);
mem.ReadByte(65536).Should().Be(2);
}
[Fact]
public void ItThrowsOnOutOfBoundsMemoryAccess()
{
var mem = Fixture.Host.DefineMemory("", "mem", minimum: 1, maximum: 1);
Action action = () => { using var instance = Fixture.Host.Instantiate(Fixture.Module); };
action
.Should()
.Throw<TrapException>()
.WithMessage("wasm trap: out of bounds memory access, source location: @-");
}
}
}