Skip to content

Commit

Permalink
allow Graphs to use fuzzing filters and fix completion of filters
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Jul 26, 2014
1 parent 8881d03 commit 2af6de3
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions bin/tavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/zimmski/tavor/log"
"github.com/zimmski/tavor/parser"
reduceStrategy "github.com/zimmski/tavor/reduce/strategy"
"github.com/zimmski/tavor/token"
)

const (
Expand Down Expand Up @@ -48,7 +49,7 @@ var opts struct {
} `group:"Format file options"`

Fuzz struct {
Filters []FuzzFilter `long:"filter" description:"Fuzzing filter to apply"`
Filters FuzzFilters `long:"filter" description:"Fuzzing filter to apply"`
ListFilters bool `long:"list-filters" description:"List all available fuzzing filters"`
Strategy FuzzStrategy `long:"strategy" description:"The fuzzing strategy" default:"random"`
ListStrategies bool `long:"list-strategies" description:"List all available fuzzing strategies"`
Expand All @@ -58,6 +59,8 @@ var opts struct {
} `command:"fuzz" description:"Fuzz the given format file"`

Graph struct {
Filters FuzzFilters `long:"filter" description:"Fuzzing filter to apply"`
ListFilters bool `long:"list-filters" description:"List all available fuzzing filters"`
} `command:"graph" description:"Generate a DOT file out of the internal AST"`

Reduce struct {
Expand All @@ -73,8 +76,9 @@ var opts struct {
}

type FuzzFilter string
type FuzzFilters []FuzzFilter

func (s *FuzzFilter) Complete(match string) []flags.Completion {
func (s FuzzFilters) Complete(match string) []flags.Completion {
var items []flags.Completion

for _, name := range fuzzFilter.List() {
Expand Down Expand Up @@ -138,7 +142,7 @@ func checkArguments() string {
fmt.Printf("Tavor v%s\n", tavor.Version)

os.Exit(returnOk)
} else if opts.Fuzz.ListFilters {
} else if opts.Fuzz.ListFilters || opts.Graph.ListFilters {
for _, name := range fuzzFilter.List() {
fmt.Println(name)
}
Expand Down Expand Up @@ -214,6 +218,31 @@ func folderExists(folder string) error {
return nil
}

func applyFilters(filterNames []FuzzFilter, doc token.Token) token.Token {
if len(filterNames) != 0 {
var err error
var filters []fuzzFilter.Filter

for _, name := range filterNames {
filt, err := fuzzFilter.New(string(name))
if err != nil {
exitError(err.Error())
}

filters = append(filters, filt)

log.Infof("Using %s fuzzing filter", name)
}

doc, err = fuzzFilter.ApplyFilters(filters, doc)
if err != nil {
exitError(err.Error())
}
}

return doc
}

func main() {
command := checkArguments()

Expand Down Expand Up @@ -244,25 +273,7 @@ func main() {

switch command {
case "fuzz":
if len(opts.Fuzz.Filters) != 0 {
var filters []fuzzFilter.Filter

for _, name := range opts.Fuzz.Filters {
filt, err := fuzzFilter.New(string(name))
if err != nil {
exitError(err.Error())
}

filters = append(filters, filt)

log.Infof("Using %s fuzzing filter", name)
}

doc, err = fuzzFilter.ApplyFilters(filters, doc)
if err != nil {
exitError(err.Error())
}
}
doc = applyFilters(opts.Fuzz.Filters, doc)

log.Infof("Counted %d overall permutations", doc.PermutationsAll())

Expand Down Expand Up @@ -313,6 +324,8 @@ func main() {
ch <- i
}
case "graph":
doc = applyFilters(opts.Graph.Filters, doc)

graph.WriteDot(doc, os.Stdout)
case "reduce", "validate":
inputFile := opts.Validate.InputFile
Expand Down

0 comments on commit 2af6de3

Please sign in to comment.