aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2016-09-21 16:52:55 +0200
committerAndrey Konovalov <andreyknvl@google.com>2016-10-04 18:49:57 +0200
commitc99cbdbe58f7817a2ee6064e72db25fc1d067b41 (patch)
treeaa1bc1092c27601f9531d87b2b2a25e5d1063d7b /prog
parente73ddfcb3ac418fc690b982f70da15b898096fa5 (diff)
Emit BufferBlob for array[int8]
Diffstat (limited to 'prog')
-rw-r--r--prog/mutation.go20
-rw-r--r--prog/prio.go2
-rw-r--r--prog/rand.go12
3 files changed, 24 insertions, 10 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index f50f60e06..068ebb849 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -67,7 +67,7 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
size = size1
case sys.BufferType:
switch a.Kind {
- case sys.BufferBlob:
+ case sys.BufferBlobRand, sys.BufferBlobRange:
var data []byte
switch arg.Kind {
case ArgData:
@@ -80,10 +80,16 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
default:
panic(fmt.Sprintf("bad arg kind for BufferType: %v", arg.Kind))
}
- arg.Data = mutateData(r, data)
+ minLen := int(0)
+ maxLen := ^int(0)
+ if a.Kind == sys.BufferBlobRange {
+ minLen = int(a.RangeBegin)
+ maxLen = int(a.RangeEnd)
+ }
+ arg.Data = mutateData(r, data, minLen, maxLen)
case sys.BufferString:
if r.bin() {
- arg.Data = mutateData(r, append([]byte{}, arg.Data...))
+ arg.Data = mutateData(r, append([]byte{}, arg.Data...), int(0), ^int(0))
} else {
arg.Data = r.randString(s)
}
@@ -424,16 +430,22 @@ func swap64(v uint64) uint64 {
return v
}
-func mutateData(r *randGen, data []byte) []byte {
+func mutateData(r *randGen, data []byte, minLen, maxLen int) []byte {
const maxInc = 35
for stop := false; !stop; stop = r.bin() {
r.choose(
100, func() {
// Append byte.
+ if len(data) == maxLen {
+ return
+ }
data = append(data, byte(r.rand(256)))
},
100, func() {
// Remove byte.
+ if len(data) == minLen {
+ return
+ }
if len(data) == 0 {
return
}
diff --git a/prog/prio.go b/prog/prio.go
index 9291b3d09..8983c1c92 100644
--- a/prog/prio.go
+++ b/prog/prio.go
@@ -80,7 +80,7 @@ func calcStaticPriorities() [][]float32 {
}
case sys.BufferType:
switch a.Kind {
- case sys.BufferBlob, sys.BufferFilesystem, sys.BufferAlgType, sys.BufferAlgName:
+ case sys.BufferBlobRand, sys.BufferBlobRange, sys.BufferFilesystem, sys.BufferAlgType, sys.BufferAlgName:
case sys.BufferString:
noteUsage(0.2, "str")
case sys.BufferSockaddr:
diff --git a/prog/rand.go b/prog/rand.go
index 26063b626..b96ecbe9a 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -706,14 +706,16 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir, sizes map[stri
return arg, nil, nil
case sys.BufferType:
switch a.Kind {
- case sys.BufferBlob:
+ case sys.BufferBlobRand, sys.BufferBlobRange:
sz := r.randBufLen()
- if dir == DirOut {
- return nil, constArg(sz), nil
+ if a.Kind == sys.BufferBlobRange {
+ sz = r.randRange(int(a.RangeBegin), int(a.RangeEnd))
}
data := make([]byte, sz)
- for i := range data {
- data[i] = byte(r.Intn(256))
+ if dir != DirOut {
+ for i := range data {
+ data[i] = byte(r.Intn(256))
+ }
}
return dataArg(data), constArg(sz), nil
case sys.BufferString: