aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-01-23 15:02:47 +0100
committerAndrey Konovalov <andreyknvl@google.com>2017-01-23 18:13:06 +0100
commitb323c5aaa9b926ba43a9c5435b62b4fce992ff94 (patch)
tree2620c3928f0b1b27f401565eb3d162dd2f254b11 /prog/mutation.go
parentcd23722cf2dabd28d83fa321c3cbf50a956d3fb7 (diff)
prog: add FieldName to Type
FieldName() is the name of the struct field or union option with this type. TypeName() is now always the name of the type.
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 2136c86f8..9841d31ca 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -184,8 +184,12 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
}
case *sys.UnionType:
optType := a.Options[r.Intn(len(a.Options))]
- for optType.Name() == arg.OptionType.Name() {
+ maxIters := 1000
+ for i := 0; optType.FieldName() == arg.OptionType.FieldName(); i++ {
optType = a.Options[r.Intn(len(a.Options))]
+ if i >= maxIters {
+ panic(fmt.Sprintf("couldn't generate a different union option after %v iterations, type: %+v", maxIters, a))
+ }
}
p.removeArg(c, arg.Option)
opt, calls := r.generateArg(s, optType)
@@ -303,7 +307,7 @@ func Minimize(p0 *Prog, callIndex0 int, pred func(*Prog, int) bool, crash bool)
var rec func(p *Prog, call *Call, arg *Arg, path string) bool
rec = func(p *Prog, call *Call, arg *Arg, path string) bool {
- path += fmt.Sprintf("-%v", arg.Type.Name())
+ path += fmt.Sprintf("-%v", arg.Type.FieldName())
switch typ := arg.Type.(type) {
case *sys.StructType:
for _, innerArg := range arg.Inner {
@@ -438,7 +442,7 @@ func (p *Prog) TrimAfter(idx int) {
}
func mutationArgs(c *Call) (args, bases []*Arg) {
- foreachArg(c, func(arg, base *Arg, parent *[]*Arg) {
+ foreachArg(c, func(arg, base *Arg, _ *[]*Arg) {
switch typ := arg.Type.(type) {
case *sys.StructType:
if isSpecialStruct(typ) == nil {