diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-05-21 15:35:03 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-21 16:18:44 +0200 |
| commit | b5c5dd778688b4ce3e51da11f7bd9e14d034b764 (patch) | |
| tree | cc5cd3337d8b3d766af4ff2266382410e0c5e17d | |
| parent | 4053862c2605da2c3cfdf9f866f8588cf5716ebd (diff) | |
prog: speed up TestPrioDeterminism
Make it faster + disable in race mode (still too slow).
| -rw-r--r-- | prog/prio.go | 22 | ||||
| -rw-r--r-- | prog/prio_test.go | 9 |
2 files changed, 17 insertions, 14 deletions
diff --git a/prog/prio.go b/prog/prio.go index e5966aa65..bda5df470 100644 --- a/prog/prio.go +++ b/prog/prio.go @@ -49,22 +49,22 @@ func (target *Target) calcStaticPriorities() [][]float32 { } sort.Strings(keys) for _, key := range keys { - var calls []int - for call := range uses[key] { - calls = append(calls, call) + weights := make([]weights, 0, len(uses[key])) + for _, weight := range uses[key] { + weights = append(weights, weight) } - sort.Ints(calls) - for _, c0 := range calls { - w0 := uses[key][c0] - for _, c1 := range calls { - w1 := uses[key][c1] - if c0 == c1 { + sort.Slice(weights, func(i, j int) bool { + return weights[i].call < weights[j].call + }) + for _, w0 := range weights { + for _, w1 := range weights { + if w0.call == w1.call { // Self-priority is assigned below. continue } // The static priority is assigned based on the direction of arguments. A higher priority will be // assigned when c0 is a call that produces a resource and c1 a call that uses that resource. - prios[c0][c1] += w0.inout*w1.in + 0.7*w0.inout*w1.inout + prios[w0.call][w1.call] += w0.inout*w1.in + 0.7*w0.inout*w1.inout } } } @@ -131,6 +131,7 @@ func (target *Target) calcResourceUsage() map[string]map[int]weights { } type weights struct { + call int in float32 inout float32 } @@ -141,6 +142,7 @@ func noteUsage(uses map[string]map[int]weights, c *Syscall, weight float32, dir uses[id] = make(map[int]weights) } callWeight := uses[id][c.ID] + callWeight.call = c.ID if dir != DirOut { if weight > uses[id][c.ID].in { callWeight.in = weight diff --git a/prog/prio_test.go b/prog/prio_test.go index dede67e5f..a09bd5438 100644 --- a/prog/prio_test.go +++ b/prog/prio_test.go @@ -7,8 +7,6 @@ import ( "math/rand" "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestNormalizePrio(t *testing.T) { @@ -71,6 +69,9 @@ func TestStaticPriorities(t *testing.T) { } func TestPrioDeterminism(t *testing.T) { + if raceEnabled { + t.Skip("skipping in race mode, too slow") + } target, rs, iters := initTest(t) ct := target.DefaultChoiceTable() var corpus []*Prog @@ -79,8 +80,8 @@ func TestPrioDeterminism(t *testing.T) { } ct0 := target.BuildChoiceTable(corpus, nil) ct1 := target.BuildChoiceTable(corpus, nil) - if diff := cmp.Diff(ct0.runs, ct1.runs); diff != "" { - t.Fatal(diff) + if !reflect.DeepEqual(ct0.runs, ct1.runs) { + t.Fatal("non-deterministic ChoiceTable") } for i := 0; i < iters; i++ { seed := rs.Int63() |
