This notably changes NewRuntimeJIT to NewRuntimeCompiler as well renames packages from jit to compiler. This clarifies the implementation is AOT, not JIT, at least when clarified to where it occurs (Runtime.CompileModule). In doing so, we reduce any concern that compilation will happen during function execution. We also free ourselves to create a JIT option without confusion in the future via CompileConfig or otherwise. Fixes #560 Signed-off-by: Adrian Cole <adrian@tetrate.io>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package compiler
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
)
|
|
|
|
var testCode, _ = io.ReadAll(io.LimitReader(rand.Reader, 8*1024))
|
|
|
|
func Test_mmapCodeSegment(t *testing.T) {
|
|
requireSupportedOSArch(t)
|
|
newCode, err := mmapCodeSegment(testCode)
|
|
require.NoError(t, err)
|
|
// Verify that the mmap is the same as the original.
|
|
require.Equal(t, testCode, newCode)
|
|
// TODO: test newCode can executed.
|
|
|
|
t.Run("panic on zero length", func(t *testing.T) {
|
|
captured := require.CapturePanic(func() {
|
|
_, _ = mmapCodeSegment(make([]byte, 0))
|
|
})
|
|
require.EqualError(t, captured, "BUG: mmapCodeSegment with zero length")
|
|
})
|
|
}
|
|
|
|
func Test_munmapCodeSegment(t *testing.T) {
|
|
requireSupportedOSArch(t)
|
|
|
|
// Errors if never mapped
|
|
require.Error(t, munmapCodeSegment(testCode))
|
|
|
|
newCode, err := mmapCodeSegment(testCode)
|
|
require.NoError(t, err)
|
|
// First munmap should succeed.
|
|
require.NoError(t, munmapCodeSegment(newCode))
|
|
// Double munmap should fail.
|
|
require.Error(t, munmapCodeSegment(newCode))
|
|
|
|
t.Run("panic on zero length", func(t *testing.T) {
|
|
captured := require.CapturePanic(func() {
|
|
_ = munmapCodeSegment(make([]byte, 0))
|
|
})
|
|
require.EqualError(t, captured, "BUG: munmapCodeSegment with zero length")
|
|
})
|
|
}
|