Files
chains/evm/cevm/metal_resource_test.go
zeekay a0b4f9aaec evm: cgo is not a claim that luxcpp is installed
The evm plugin turns cgo on for blst. Doing so also pulled in two
optional native backends keyed on bare cgo, neither of which a build
host carries by default, so `go build ./evm` needed a luxcpp and a
luxgpu install or it did not compile:

  # github.com/luxfi/chains/evm/cevm
  # [pkg-config --cflags -- lux-cevm lux-crypto-secp256k1]
  Package lux-cevm was not found in the pkg-config search path.

  # github.com/luxfi/accel/ops/code
  code_cpu.go:102:10: fatal error: lux/gpu/hqc.h:
  No such file or directory

Both are the same conflation: "a C compiler exists" is being written
where "this C library is installed" is meant. evm/cevm gets the second
predicate it was missing, lux_cevm_native, and accel v1.3.2 restores
lux_hqc_native on its side. cevm_nocgo.go and cevm_secp256k1_nocgo.go
already mirrored the full API for exactly this case, so the default
build takes them and reports CPUSequential; -tags=lux_cevm_native links
libevm/libevm-gpu unchanged.

The tests move with the predicate they actually need. TestABIVersion
locks the linked library's ABI constant, so it belongs beside
TestLibraryABIVersion in the native file rather than in the untagged
one, where it asserted 6 against the stub's documented 0 and failed
every CGO_ENABLED=0 run.

Verified: all twelve VMs build at their images.json cgo setting;
go build ./... and go test ./evm/cevm/... green at CGO=0 and CGO=1;
-tags=lux_cevm_native still selects cevm_cgo.go + cevm_secp256k1.go.
2026-08-21 00:14:14 -07:00

39 lines
1.2 KiB
Go

//go:build cgo && lux_cevm_native
package cevm
import (
"slices"
"testing"
)
// TestMetalSustainedExecution guards the fix in luxcpp/cevm's
// EvmKernelHost::create(): it used to compile evm_kernel.metal and allocate a
// command queue and pipeline states on every call, so a process doing
// sustained work piled up Metal objects until the driver faulted. The crash
// needed volume to show up — any single execution was fine, which is why it
// survived as long as it did.
//
// Executing the same trivial block many times reproduces that in seconds. It
// is a resource test, so it asserts only that every run completes; opcode
// semantics are covered by TestOpcodeCoverage_GPU_vs_CPU.
func TestMetalSustainedExecution(t *testing.T) {
if !slices.Contains(AvailableBackends(), GPUMetal) {
t.Skip("no Metal backend on this host")
}
var from [20]byte
from[19] = 0x42
tx := Transaction{
From: from,
GasLimit: 100_000,
GasPrice: 1,
Code: []byte{0x60, 0x01, 0x00}, // PUSH1 1; STOP
}
const runs = 250
for i := range runs {
if _, err := ExecuteBlock(GPUMetal, 1, []Transaction{tx}, nil, nil); err != nil {
t.Fatalf("run %d of %d failed: %v", i+1, runs, err)
}
}
}