diff options
| -rw-r--r-- | prog/rand.go | 22 | ||||
| -rw-r--r-- | prog/resources_test.go | 8 |
2 files changed, 18 insertions, 12 deletions
diff --git a/prog/rand.go b/prog/rand.go index 3fbaaaa87..0ca509e62 100644 --- a/prog/rand.go +++ b/prog/rand.go @@ -737,32 +737,38 @@ func (r *randGen) generateArgImpl(s *state, typ Type, dir Dir, ignoreSpecial boo } func (a *ResourceType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) { + canRecurse := false if !r.inGenerateResource { // Don't allow recursion for resourceCentric/createResource. // That can lead to generation of huge programs and may be very slow // (esp. if we are generating some failing attempts in createResource already). r.inGenerateResource = true defer func() { r.inGenerateResource = false }() - + canRecurse = true + } + if canRecurse && r.nOutOf(8, 10) || + !canRecurse && r.nOutOf(19, 20) { + arg = r.existingResource(s, a, dir) + if arg != nil { + return + } + } + if canRecurse { if r.oneOf(4) { arg, calls = r.resourceCentric(s, a, dir) if arg != nil { return } } - if r.oneOf(3) { + if r.nOutOf(4, 5) { + // If we could not reuse a resource, let's prefer resource creation over + // random int substitution. arg, calls = r.createResource(s, a, dir) if arg != nil { return } } } - if r.nOutOf(9, 10) { - arg = r.existingResource(s, a, dir) - if arg != nil { - return - } - } special := a.SpecialValues() arg = MakeResultArg(a, dir, nil, special[r.Intn(len(special))]) return diff --git a/prog/resources_test.go b/prog/resources_test.go index ca1a25965..c4da48e1e 100644 --- a/prog/resources_test.go +++ b/prog/resources_test.go @@ -196,7 +196,7 @@ func TestPreferPreciseResources(t *testing.T) { target, rs, _ := initRandomTargetTest(t, "test", "64") r := newRand(target, rs) counts := map[string]int{} - for i := 0; i < 1500; i++ { + for i := 0; i < 2000; i++ { s := newState(target, target.DefaultChoiceTable(), nil) calls := r.generateParticularCall(s, target.SyscallMap["test$consume_subtype_of_common"]) @@ -207,7 +207,7 @@ func TestPreferPreciseResources(t *testing.T) { counts[call.Meta.Name]++ } } - assert.Greater(t, counts["test$produce_common"], 15) - assert.Greater(t, counts["test$also_produce_common"], 15) - assert.Greater(t, counts["test$produce_subtype_of_common"], 100) + assert.Greater(t, counts["test$produce_common"], 70) + assert.Greater(t, counts["test$also_produce_common"], 70) + assert.Greater(t, counts["test$produce_subtype_of_common"], 1000) } |
