feat(verify): add universal --fuzz differential testing driven by // func signatures
Assisted-by: Qwen 3.8 Max Preview
This commit is contained in:
+40
-1
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
// version is the release version, stamped at build time via
|
||||
// -ldflags "-X main.version=…" (defaulting to the current release).
|
||||
var version = "0.25.0"
|
||||
var version = "0.26.0"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
@@ -492,6 +492,8 @@ With -profile, the static basic-block structure is listed for each function.
|
||||
abi := fs.Bool("abi", false, "run ABI-checking calls (sentinel registers + red zone)")
|
||||
profile := fs.Bool("profile", false, "list basic-block structure per function")
|
||||
groundTruth := fs.Bool("ground-truth", false, "compare machine code byte-for-byte against go tool asm")
|
||||
fuzz := fs.Bool("fuzz", false, "differential fuzz: JIT both gasm and go-tool-asm versions, compare outputs")
|
||||
fuzzN := fs.Int("n", 1000, "number of fuzz iterations per function")
|
||||
fs.Parse(args)
|
||||
if fs.NArg() != 1 {
|
||||
fmt.Fprintln(os.Stderr, "usage: gasm verify [-smoke] [-abi] [-profile] <file.s>")
|
||||
@@ -568,6 +570,43 @@ With -profile, the static basic-block structure is listed for each function.
|
||||
rc = 1
|
||||
}
|
||||
}
|
||||
|
||||
// Differential fuzz: JIT both gasm and go-tool-asm, compare outputs.
|
||||
// Each function runs in a subprocess so a crash (partial functions like
|
||||
// decoders that fault on malformed input) doesn't kill the whole run.
|
||||
if *fuzz {
|
||||
gt, err := verify.GroundTruth(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gasm verify: fuzz: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
src, err := readSource(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gasm verify: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
sigs := verify.ExtractSignatures(src)
|
||||
fuzzed := 0
|
||||
for _, name := range names {
|
||||
sig, ok := sigs[name]
|
||||
if !ok {
|
||||
fmt.Printf(" %s: SKIP (no // func signature)\n", name)
|
||||
continue
|
||||
}
|
||||
goCode, ok := gt[name]
|
||||
if !ok {
|
||||
fmt.Printf(" %s: SKIP (not in go tool asm output)\n", name)
|
||||
continue
|
||||
}
|
||||
res := k.FuzzFunc(name, sig, goCode, *fuzzN, int64(fuzzed*7+42))
|
||||
fmt.Printf(" %s\n", res)
|
||||
if !res.OK() {
|
||||
rc = 1
|
||||
}
|
||||
fuzzed++
|
||||
}
|
||||
fmt.Printf("fuzz: %d functions tested, %d iterations each\n", fuzzed, *fuzzN)
|
||||
}
|
||||
for _, name := range names {
|
||||
fl, _ := k.Func(name)
|
||||
flags := ""
|
||||
|
||||
Reference in New Issue
Block a user