diff options
Diffstat (limited to 'pkg/manager/diff_test.go')
| -rw-r--r-- | pkg/manager/diff_test.go | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/pkg/manager/diff_test.go b/pkg/manager/diff_test.go index f2408f13b..9e27dc288 100644 --- a/pkg/manager/diff_test.go +++ b/pkg/manager/diff_test.go @@ -4,6 +4,7 @@ package manager import ( + "fmt" "testing" "github.com/google/syzkaller/pkg/mgrconfig" @@ -24,6 +25,10 @@ int main(void) { }`, "c.c": `int main(void) { }`, })) + baseHashes, patchedHashes := dummySymbolHashes(), dummySymbolHashes() + baseHashes["function"] = "hash1" + patchedHashes["function"] = "hash2" + PatchFocusAreas(cfg, [][]byte{ []byte(`diff --git a/b.c b/b.c index 103167d..fbf7a68 100644 @@ -34,7 +39,7 @@ index 103167d..fbf7a68 100644 \ No newline at end of file +int main(void) { return 1; } \ No newline at end of file`), - // Also, emulate an update to te header.h. + // Also, emulate an update to header.h. []byte(`diff --git a/header.h b/header.h index 103167d..fbf7a68 100644 --- a/header.h @@ -44,11 +49,18 @@ index 103167d..fbf7a68 100644 \ No newline at end of file +Test2 \ No newline at end of file`), - }) + }, baseHashes, patchedHashes) assert.Equal(t, []mgrconfig.FocusArea{ { - Name: modifiedArea, + Name: symbolsArea, + Filter: mgrconfig.CovFilterCfg{ + Functions: []string{"function"}, + }, + Weight: 6.0, + }, + { + Name: filesArea, Filter: mgrconfig.CovFilterCfg{ Files: []string{"b.c", "header.h"}, }, @@ -66,3 +78,32 @@ index 103167d..fbf7a68 100644 }, }, cfg.Experimental.FocusAreas) } + +func dummySymbolHashes() map[string]string { + ret := map[string]string{} + for i := 0; i < 100; i++ { + ret[fmt.Sprint(i)] = fmt.Sprint(i) + } + return ret +} + +func TestModifiedSymbols(t *testing.T) { + t.Run("too many changed", func(t *testing.T) { + ret := modifiedSymbols(map[string]string{ + "functionA": "hash1", + "functionB": "hash2", + }, map[string]string{ + "functionA": "hash1", + "functionB": "hash is not hash2", + }) + assert.Empty(t, ret) + }) + t.Run("less than threshold", func(t *testing.T) { + base, patched := dummySymbolHashes(), dummySymbolHashes() + base["function"] = "hash1" + patched["function"] = "hash2" + base["function2"] = "hash1" + patched["function2"] = "hash2" + assert.Equal(t, []string{"function", "function2"}, modifiedSymbols(base, patched)) + }) +} |
