1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright 2024 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package symbolizer
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCache(t *testing.T) {
called := make(map[cacheKey]bool)
inner := func(bin string, pcs ...uint64) ([]Frame, error) {
var res []Frame
for _, pc := range pcs {
key := cacheKey{bin, pc}
assert.False(t, called[key])
called[key] = true
if bin == "error" {
return nil, fmt.Errorf("error %v", pc)
}
res = append(res, Frame{PC: pc, Func: bin + "_func"})
}
return res, nil
}
var cache Cache
check := func(bin string, pc uint64, frames []Frame, err error) {
gotFrames, gotErr := cache.Symbolize(inner, bin, pc)
assert.Equal(t, gotFrames, frames)
assert.Equal(t, gotErr, err)
}
check("foo", 1, []Frame{{PC: 1, Func: "foo_func"}}, nil)
check("foo", 1, []Frame{{PC: 1, Func: "foo_func"}}, nil)
check("foo", 2, []Frame{{PC: 2, Func: "foo_func"}}, nil)
check("foo", 1, []Frame{{PC: 1, Func: "foo_func"}}, nil)
check("error", 10, nil, errors.New("error 10"))
check("error", 10, nil, errors.New("error 10"))
check("error", 11, nil, errors.New("error 11"))
}
|