OLD | NEW |
---|---|
1 package generator | 1 package generator |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "io/ioutil" | 5 "io/ioutil" |
6 "os" | 6 "os" |
7 "path/filepath" | 7 "path/filepath" |
8 "strings" | 8 "strings" |
9 | 9 |
10 go_metrics "github.com/rcrowley/go-metrics" | |
11 "github.com/skia-dev/glog" | 10 "github.com/skia-dev/glog" |
12 "go.skia.org/infra/fuzzer/go/common" | 11 "go.skia.org/infra/fuzzer/go/common" |
13 "go.skia.org/infra/fuzzer/go/config" | 12 "go.skia.org/infra/fuzzer/go/config" |
14 "go.skia.org/infra/go/exec" | 13 "go.skia.org/infra/go/exec" |
15 "go.skia.org/infra/go/fileutil" | 14 "go.skia.org/infra/go/fileutil" |
16 "go.skia.org/infra/go/gs" | 15 "go.skia.org/infra/go/gs" |
16 "go.skia.org/infra/go/metrics2" | |
17 "google.golang.org/cloud/storage" | 17 "google.golang.org/cloud/storage" |
18 ) | 18 ) |
19 | 19 |
20 type Generator struct { | 20 type Generator struct { |
21 Category string | 21 Category string |
22 » fuzzProcessCount go_metrics.Counter | 22 » fuzzProcessCount *metrics2.Counter |
23 fuzzProcesses []exec.Process | 23 fuzzProcesses []exec.Process |
24 } | 24 } |
25 | 25 |
26 func New(category string) *Generator { | 26 func New(category string) *Generator { |
27 return &Generator{ | 27 return &Generator{ |
28 Category: category, | 28 Category: category, |
29 fuzzProcesses: nil, | 29 fuzzProcesses: nil, |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 // Start starts up 1 goroutine running a "master" afl-fuzz and n-1 "slave" afl-f uzz processes, where | 33 // Start starts up 1 goroutine running a "master" afl-fuzz and n-1 "slave" afl-f uzz processes, where |
34 // n is specified by config.Generator.NumFuzzProcesses. Output goes to | 34 // n is specified by config.Generator.NumFuzzProcesses. Output goes to |
35 // config.Generator.AflOutputPath/[category]. | 35 // config.Generator.AflOutputPath/[category]. |
36 func (g *Generator) Start() error { | 36 func (g *Generator) Start() error { |
37 if config.Generator.SkipGeneration { | |
38 glog.Info("Skipping generation because flag was set.") | |
39 return nil | |
40 } | |
37 executable, err := g.setup() | 41 executable, err := g.setup() |
38 if err != nil { | 42 if err != nil { |
39 return fmt.Errorf("Failed %s generator setup: %s", g.Category, e rr) | 43 return fmt.Errorf("Failed %s generator setup: %s", g.Category, e rr) |
40 } | 44 } |
41 | 45 |
42 masterCmd := &exec.Command{ | 46 masterCmd := &exec.Command{ |
43 Name: "./afl-fuzz", | 47 Name: "./afl-fuzz", |
44 Args: common.GenerationArgsFor(g.Category, executable, "fuz zer0", true), | 48 Args: common.GenerationArgsFor(g.Category, executable, "fuz zer0", true), |
45 Dir: config.Generator.AflRoot, | 49 Dir: config.Generator.AflRoot, |
46 LogStdout: true, | 50 LogStdout: true, |
47 LogStderr: true, | 51 LogStderr: true, |
48 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warnin g afl-fuzz spits out about dynamic scaling of cpu frequency | 52 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warnin g afl-fuzz spits out about dynamic scaling of cpu frequency |
49 } | 53 } |
50 if config.Generator.WatchAFL { | 54 if config.Generator.WatchAFL { |
51 masterCmd.Stdout = os.Stdout | 55 masterCmd.Stdout = os.Stdout |
52 } | 56 } |
53 | 57 |
54 g.fuzzProcesses = append(g.fuzzProcesses, g.run(masterCmd)) | 58 g.fuzzProcesses = append(g.fuzzProcesses, g.run(masterCmd)) |
55 | 59 |
56 fuzzCount := config.Generator.NumFuzzProcesses | 60 fuzzCount := config.Generator.NumFuzzProcesses |
57 if fuzzCount <= 0 { | 61 if fuzzCount <= 0 { |
58 // TODO(kjlubick): Make this actually an intelligent number base d on the number of cores. | 62 // TODO(kjlubick): Make this actually an intelligent number base d on the number of cores. |
59 fuzzCount = 10 | 63 fuzzCount = 10 |
60 } | 64 } |
61 » g.fuzzProcessCount = go_metrics.NewRegisteredCounter("afl_fuzz_process_c ount", go_metrics.DefaultRegistry) | 65 » g.fuzzProcessCount = metrics2.NewCounter("afl_fuzz_process_count", map[s tring]string{"category": g.Category}) |
borenet
2016/02/10 15:32:32
Dashes
kjlubick
2016/02/10 16:14:29
Done
| |
62 g.fuzzProcessCount.Inc(int64(fuzzCount)) | 66 g.fuzzProcessCount.Inc(int64(fuzzCount)) |
63 for i := 1; i < fuzzCount; i++ { | 67 for i := 1; i < fuzzCount; i++ { |
64 fuzzerName := fmt.Sprintf("fuzzer%d", i) | 68 fuzzerName := fmt.Sprintf("fuzzer%d", i) |
65 slaveCmd := &exec.Command{ | 69 slaveCmd := &exec.Command{ |
66 Name: "./afl-fuzz", | 70 Name: "./afl-fuzz", |
67 Args: common.GenerationArgsFor(g.Category, executab le, fuzzerName, false), | 71 Args: common.GenerationArgsFor(g.Category, executab le, fuzzerName, false), |
68 Dir: config.Generator.AflRoot, | 72 Dir: config.Generator.AflRoot, |
69 LogStdout: true, | 73 LogStdout: true, |
70 LogStderr: true, | 74 LogStderr: true, |
71 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warning afl-fuzz spits out about dynamic scaling of cpu frequency | 75 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warning afl-fuzz spits out about dynamic scaling of cpu frequency |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 glog.Errorf("[%s] Problem downloading %s from Google Sto rage, continuing anyway", g.Category, item.Name) | 175 glog.Errorf("[%s] Problem downloading %s from Google Sto rage, continuing anyway", g.Category, item.Name) |
172 return | 176 return |
173 } | 177 } |
174 fileName := filepath.Join(seedPath, strings.SplitAfter(name, gsF older)[1]) | 178 fileName := filepath.Join(seedPath, strings.SplitAfter(name, gsF older)[1]) |
175 if err = ioutil.WriteFile(fileName, content, 0644); err != nil & & !os.IsExist(err) { | 179 if err = ioutil.WriteFile(fileName, content, 0644); err != nil & & !os.IsExist(err) { |
176 glog.Errorf("[%s] Problem creating binary seed file %s, continuing anyway", g.Category, fileName) | 180 glog.Errorf("[%s] Problem creating binary seed file %s, continuing anyway", g.Category, fileName) |
177 } | 181 } |
178 }) | 182 }) |
179 return err | 183 return err |
180 } | 184 } |
OLD | NEW |