diff --git a/fuzzer/fuzzer.go b/fuzzer/fuzzer.go index b39e79d..4fb163a 100644 --- a/fuzzer/fuzzer.go +++ b/fuzzer/fuzzer.go @@ -42,9 +42,21 @@ import ( var ( outputDir = "out" + EnvKey = "FUZZYDIR" shouldTrace = false ) +// SetFuzzyVMDir sets the output directory for FuzzyVM +// If the environment variable FUZZYDIR is set, the output directory +// will be set to that, otherwise it will be set to a temp dir (for unit tests) +func SetFuzzyVMDir() { + if dir, ok := os.LookupEnv(EnvKey); ok { + outputDir = dir + } else { + outputDir = os.TempDir() + } +} + // Fuzz is the entry point for go-fuzz func Fuzz(data []byte) int { // Too little data destroys our performance and makes it hard for the generator diff --git a/fuzzer/fuzzer_test.go b/fuzzer/fuzzer_test.go index c7cc6e4..dcec339 100644 --- a/fuzzer/fuzzer_test.go +++ b/fuzzer/fuzzer_test.go @@ -28,7 +28,7 @@ import ( ) func init() { - outputDir = os.TempDir() + SetFuzzyVMDir() var directories []string for i := 0; i < 256; i++ { directories = append(directories, fmt.Sprintf("%v/%v", outputDir, common.Bytes2Hex([]byte{byte(i)}))) diff --git a/main.go b/main.go index bfec3db..654b1a7 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" "github.com/urfave/cli/v2" @@ -141,6 +142,14 @@ func startGenerator(genThreads int) *exec.Cmd { cmd := exec.Command(cmdName, "test", "--fuzz", target, "--parallel", fmt.Sprint(genThreads), dir) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + // Set the output directory + path, err := os.Getwd() + if err != nil { + panic(err) + } + directory := filepath.Join(path, outputRootDir) + env := append(os.Environ(), fmt.Sprintf("%v=%v", fuzzer.EnvKey, directory)) + cmd.Env = env if err := cmd.Start(); err != nil { panic(err) }