Skip to content

Commit

Permalink
main: set output directory properly (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Dec 8, 2023
1 parent 9f36b6e commit 0dce721
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fuzzer/fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})))
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"

"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0dce721

Please sign in to comment.