Debian Codegraph @

allocator/nonmoving_test.go

raw symbols SCIP
1 package allocator
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7 "github.com/tetratelabs/wazero/experimental"
8 )
9
10 func TestNonMoving(t *testing.T) {
11 tests := []struct {
12 name string
13 mem experimental.LinearMemory
14 cap uint64
15 }{
16 {
17 name: "native",
18 mem: NewNonMoving().Allocate(10, 20),
19 cap: pageSize,
20 },
21 // The non-slice allocators are available on all normal platforms. Rather than requiring qemu to test slice
22 // allocator, we just go ahead and test it in addition to the native one. On platforms other than unix/windows,
23 // it will test the same allocator twice, which is fine.
24 {
25 name: "slice",
26 mem: sliceAlloc(10, 20),
27 cap: 20,
28 },
29 }
30
31 for _, tc := range tests {
32 tc := tc
33 t.Run(tc.name, func(t *testing.T) {
34 mem := tc.mem
35 defer mem.Free()
36
37 buf := mem.Reallocate(5)
38 require.Len(t, buf, 5)
39 require.EqualValues(t, tc.cap, cap(buf))
40 base := &buf[0]
41
42 buf = mem.Reallocate(5)
43 require.Len(t, buf, 5)
44 require.Equal(t, base, &buf[0])
45
46 buf = mem.Reallocate(10)
47 require.Len(t, buf, 10)
48 require.Equal(t, base, &buf[0])
49
50 buf = mem.Reallocate(20)
51 require.Len(t, buf, 20)
52 require.Equal(t, base, &buf[0])
53 })
54 }
55 }