1
0
mirror of https://github.com/taigrr/gopher-os synced 2026-03-24 09:52:25 -07:00

acpi: add Makefile target for fuzzing and AML parser fuzzer

The fuzzer can be invoked by running: "make test-fuzz". The AML parser
test suite has been augmented with a special "TestParserCrashers"
function that can be used to replay corpuses identified by go-fuzz as
causing parser crashes.

The test can be invoked as:

go test -v -run TestParserCrashers -aml-replace-crashers-from
$BUILD/fuzz/corpus/src_gopheros_device_acpi_aml/crashers

where $BUILD is the output directory (default: build/) defined in the
Makefile.
This commit is contained in:
Achilleas Anagnostopoulos
2018-03-06 19:19:36 +00:00
parent d7028ed73d
commit ddbddd2ea2
3 changed files with 96 additions and 3 deletions

View File

@@ -16,9 +16,41 @@ import (
)
var (
regenExpFiles = flag.Bool("aml-regenerate-parser-exp-files", false, "Regenerate the expected output files for AML parser tests against real AML files")
regenExpFiles = flag.Bool("aml-regenerate-parser-exp-files", false, "Regenerate the expected output files for AML parser tests against real AML files")
replayCrashersFrom = flag.String("aml-replay-crashers-from", "", "Replay go-fuzz generated crasher files from this folder")
)
// TestParserCrashers scans through the crasher corpus generated by go-fuzz and
// pipes each corpus through the AML parser.
func TestParserCrashers(t *testing.T) {
if *replayCrashersFrom == "" {
t.Skip("-aml-replay-crashers-from not specified; skipping")
return
}
fuzzFiles, err := filepath.Glob(filepath.Join(*replayCrashersFrom, "*"))
if err != nil {
t.Fatal(err)
}
for _, fuzzFile := range fuzzFiles {
// corpus files lack an extension
if filepath.Ext(fuzzFile) != "" {
continue
}
data, err := ioutil.ReadFile(fuzzFile)
if err != nil {
t.Fatal(err)
}
t.Logf("trying to parse crash corpus: %q", fuzzFile)
p, resolver := parserForMockPayload(t, data)
_ = p.ParseAML(0, "DSDT", resolver.LookupTable("DSDT"))
}
}
func TestParser(t *testing.T) {
flag.Parse()