fix(verify): gate JIT verification to amd64 until trampolines are hardened
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package verify
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// requireArchHost skips unless the test binary runs on the named GOARCH: the
|
||||
// JIT executes native code, so an arm64 kernel only runs on an arm64 CPU
|
||||
// (real hardware or qemu-user emulation).
|
||||
func requireArchHost(t *testing.T, goarch string) {
|
||||
t.Helper()
|
||||
if runtime.GOARCH != goarch {
|
||||
t.Skipf("runs only on %s hosts (this host is %s)", goarch, runtime.GOARCH)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlainCallArm64 checks the bare JIT call path (no ABI sentinels) on
|
||||
// arm64: the trampoline, the kernel and the result read-back.
|
||||
func TestPlainCallArm64(t *testing.T) {
|
||||
requireArchHost(t, "arm64")
|
||||
|
||||
k, err := Load("../testdata/verify/abi_arm64.s")
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
t.Cleanup(k.Close)
|
||||
|
||||
args := make([]byte, 24)
|
||||
PutUint64(args, 0, 3)
|
||||
PutUint64(args, 8, 4)
|
||||
out, err := k.CallFunc("cleanAdd", args)
|
||||
if err != nil {
|
||||
t.Fatalf("CallFunc: %v", err)
|
||||
}
|
||||
if got := int64(GetUint64(out, 16)); got != 7 {
|
||||
t.Errorf("cleanAdd(3, 4) = %d, want 7", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlainCallRiscv64 is TestPlainCallArm64 for riscv64.
|
||||
func TestPlainCallRiscv64(t *testing.T) {
|
||||
requireArchHost(t, "riscv64")
|
||||
|
||||
k, err := Load("../testdata/verify/abi_riscv64.s")
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
t.Cleanup(k.Close)
|
||||
|
||||
args := make([]byte, 24)
|
||||
PutUint64(args, 0, 3)
|
||||
PutUint64(args, 8, 4)
|
||||
out, err := k.CallFunc("cleanAdd", args)
|
||||
if err != nil {
|
||||
t.Fatalf("CallFunc: %v", err)
|
||||
}
|
||||
if got := int64(GetUint64(out, 16)); got != 7 {
|
||||
t.Errorf("cleanAdd(3, 4) = %d, want 7", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlainCallLoong64 is TestPlainCallArm64 for loong64.
|
||||
func TestPlainCallLoong64(t *testing.T) {
|
||||
requireArchHost(t, "loong64")
|
||||
|
||||
k, err := Load("../testdata/verify/abi_loong64.s")
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
t.Cleanup(k.Close)
|
||||
|
||||
args := make([]byte, 24)
|
||||
PutUint64(args, 0, 3)
|
||||
PutUint64(args, 8, 4)
|
||||
out, err := k.CallFunc("cleanAdd", args)
|
||||
if err != nil {
|
||||
t.Fatalf("CallFunc: %v", err)
|
||||
}
|
||||
if got := int64(GetUint64(out, 16)); got != 7 {
|
||||
t.Errorf("cleanAdd(3, 4) = %d, want 7", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user