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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright 2025 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 main
import (
"encoding/json"
"os"
"testing"
"github.com/google/syzkaller/pkg/build"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/syz-cluster/pkg/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReadSectionHashes(t *testing.T) {
hashes := build.SectionHashes{
Text: map[string]string{"A": "1"},
Data: map[string]string{"B": "2"},
}
jsonData, err := json.Marshal(hashes)
require.NoError(t, err)
file, err := osutil.WriteTempFile(jsonData)
require.NoError(t, err)
defer os.Remove(file)
fromFile, err := readSectionHashes(file)
require.NoError(t, err)
assert.Equal(t, hashes, fromFile)
}
// nolint: dupl
func TestShouldSkipFuzzing(t *testing.T) {
t.Run("one empty", func(t *testing.T) {
assert.False(t, shouldSkipFuzzing(
build.SectionHashes{},
build.SectionHashes{
Text: map[string]string{"A": "1"},
},
))
})
t.Run("equal symbols", func(t *testing.T) {
assert.True(t, shouldSkipFuzzing(
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "D": "2"},
},
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "D": "2"},
},
))
})
t.Run("ignore known variables", func(t *testing.T) {
assert.True(t, shouldSkipFuzzing(
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "raw_data": "A", "vermagic": "A"},
},
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "raw_data": "B", "vermagic": "B"},
},
))
})
t.Run("same len, different hashes", func(t *testing.T) {
assert.False(t, shouldSkipFuzzing(
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
},
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "different"},
},
))
assert.False(t, shouldSkipFuzzing(
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "D": "2"},
},
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
Data: map[string]string{"C": "1", "D": "different"},
},
))
})
t.Run("different len, same hashes", func(t *testing.T) {
assert.False(t, shouldSkipFuzzing(
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2"},
},
build.SectionHashes{
Text: map[string]string{"A": "1", "B": "2", "C": "new"},
},
))
})
}
func TestBugTitleRe(t *testing.T) {
assert.True(t, titleMatchesFilter(&api.FuzzConfig{}, "any title must match"))
assert.True(t, titleMatchesFilter(&api.FuzzConfig{
BugTitleRe: `^Prefix:`,
}, "Prefix: must pass"))
assert.False(t, titleMatchesFilter(&api.FuzzConfig{
BugTitleRe: `^Prefix:`,
}, "Without prefix"))
}
|