// Copyright (c) 2026 Petr Balvín (https://petrbalvin.org) // SPDX-License-Identifier: BSD-3-Clause package parser import ( "os" "path/filepath" "testing" ) // FuzzParse hammers the parser with arbitrary input. The contract: no panic, // and always a usable file, whether or not diagnostics were reported. The // seed corpus carries the repository's kernels, so a plain `go test` run // replays every seed as a regression case and CI exercises them without any // fuzzing budget. func FuzzParse(f *testing.F) { for _, pattern := range []string{ "../testdata/*.s", "../testdata/verify/*.s", } { files, _ := filepath.Glob(pattern) for _, path := range files { if b, err := os.ReadFile(path); err == nil { f.Add(string(b)) } } } f.Add("TEXT ·f(SB), NOSPLIT, $0\n\tRET\n") f.Add("garbage ### ??? ::: \xff\xfe\n") f.Add("#define A(x) x+1\nTEXT ·f(SB), $0\n\tA(2)\n\tRET\n") f.Add("DATA t<>+0(SB)/8, $1\nGLOBL t<>(SB), RODATA, $8\n") f.Add("TEXT ·f(SB), $0\n\tJMP (AX)\n\tCALL (BX)\n\tRET\n") f.Fuzz(func(t *testing.T, src string) { file, _ := Parse("fuzz.s", src) if file == nil { t.Fatal("Parse returned a nil file") } }) }