aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorVeronica Radu <veronicaradu@google.com>2019-10-07 15:35:15 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-10-10 14:37:42 +0200
commit1a3bad9041ac075f3e2ae7f20528203704e87b28 (patch)
tree04308eec31470e16bb2ba7506c4ae4f6afc76e2c /prog/mutation.go
parenta4efa8c091bb41968c2a2e198fa239625ed8a24e (diff)
prog: mutate length of output buffers
Update #480
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 8e59880a5..3f5129f4d 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -306,19 +306,22 @@ func (t *ProcType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*C
}
func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {
+ minLen, maxLen := uint64(0), maxBlobLen
+ if t.Kind == BufferBlobRange {
+ minLen, maxLen = t.RangeBegin, t.RangeEnd
+ }
a := arg.(*DataArg)
+ if t.Dir() == DirOut {
+ mutateBufferSize(r, a, minLen, maxLen)
+ return
+ }
switch t.Kind {
case BufferBlobRand, BufferBlobRange:
data := append([]byte{}, a.Data()...)
- minLen, maxLen := uint64(0), maxBlobLen
- if t.Kind == BufferBlobRange {
- minLen, maxLen = t.RangeBegin, t.RangeEnd
- }
a.data = mutateData(r, data, minLen, maxLen)
case BufferString:
data := append([]byte{}, a.Data()...)
if r.bin() {
- minLen, maxLen := uint64(0), maxBlobLen
if t.TypeSize != 0 {
minLen, maxLen = t.TypeSize, t.TypeSize
}
@@ -337,6 +340,18 @@ func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []
return
}
+func mutateBufferSize(r *randGen, arg *DataArg, minLen, maxLen uint64) {
+ for oldSize := arg.Size(); oldSize == arg.Size(); {
+ arg.size += uint64(r.Intn(33)) - 16
+ if arg.size < minLen {
+ arg.size = minLen
+ }
+ if arg.size > maxLen {
+ arg.size = maxLen
+ }
+ }
+}
+
func (t *ArrayType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {
// TODO: swap elements of the array
a := arg.(*GroupArg)
@@ -464,7 +479,9 @@ func (ma *mutationArgs) collectArg(arg Arg, ctx *ArgCtx) {
return
}
- if typ.Dir() == DirOut || !typ.Varlen() && typ.Size() == 0 {
+ _, isArrayTyp := typ.(*ArrayType)
+ _, isBufferTyp := typ.(*BufferType)
+ if !isBufferTyp && !isArrayTyp && typ.Dir() == DirOut || !typ.Varlen() && typ.Size() == 0 {
return
}
@@ -577,6 +594,9 @@ func (t *LenType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (
}
func (t *BufferType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {
+ if t.Dir() == DirOut && !t.Varlen() {
+ return dontMutate, false
+ }
return 0.8 * maxPriority, false
}