1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08: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

@@ -11,13 +11,18 @@ iso_target := $(BUILD_DIR)/kernel-$(ARCH).iso
# this: make run GO=go1.8
GO ?= go
# Prepend build path to GOPATH so the compiled packages and linter dependencies
# Prepend build path to GOPATH so the compiled packages and linter dependencies
# end up inside the build folder
GOPATH := $(BUILD_ABS_DIR):$(shell pwd):$(GOPATH)
FUZZ_PKG_LIST := src/gopheros/device/acpi/aml
# To append more entries to the above list use the following syntax
# FUZZ_PKG_LIST += path-to-pkg
ifeq ($(OS), Linux)
export SHELL := /bin/bash -o pipefail
LD := ld
AS := nasm
@@ -143,7 +148,7 @@ run-vbox: iso
VBoxManage storageattach $(VBOX_VM_NAME) --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive \
--medium $(iso_target) || true
VBoxManage startvm $(VBOX_VM_NAME)
# When building gdb target disable optimizations (-N) and inlining (l) of Go code
gdb: GC_FLAGS += -N -l
gdb: iso
@@ -185,12 +190,28 @@ lint: lint-check-deps
src/...
lint-check-deps:
@echo [go get] installing linter dependencies
@GOPATH=$(GOPATH) $(GO) get -u -t gopkg.in/alecthomas/gometalinter.v1
@GOPATH=$(GOPATH) PATH=$(BUILD_ABS_DIR)/bin:$(PATH) gometalinter.v1 --install >/dev/null
test:
GOPATH=$(GOPATH) $(GO) test -cover gopheros/...
fuzz-deps:
@mkdir -p $(BUILD_DIR)/fuzz
@echo [go get] installing go-fuzz dependencies
@GOPATH=$(GOPATH) $(GO) get -u github.com/dvyukov/go-fuzz/...
%.fuzzpkg: %
@echo [go-fuzz] fuzzing: $<
@GOPATH=$(GOPATH) PATH=$(BUILD_ABS_DIR)/bin:$(PATH) go-fuzz-build -o $(BUILD_ABS_DIR)/fuzz/$(subst /,_,$<).zip $(subst src/,,$<)
@mkdir -p $(BUILD_ABS_DIR)/fuzz/corpus/$(subst /,_,$<)/corpus
@echo [go-fuzz] + grepping for corpus file hints in $<
@grep "go-fuzz-corpus+=" $</*fuzz.go | cut -d'=' -f2 | tr '\n' '\0' | xargs -0 -I@ sh -c 'export F="@"; cp $$F $(BUILD_ABS_DIR)/fuzz/corpus/$(subst /,_,$<)/corpus/ && echo "[go fuzz] + copy extra corpus file: $$F"'
@go-fuzz -bin=$(BUILD_ABS_DIR)/fuzz/$(subst /,_,$<).zip -workdir=$(BUILD_ABS_DIR)/fuzz/corpus/$(subst /,_,$<) 2>&1 | sed -e "s/^/ | /g"
test-fuzz: fuzz-deps $(addsuffix .fuzzpkg,$(FUZZ_PKG_LIST))
collect-coverage:
GOPATH=$(GOPATH) sh coverage.sh