diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-07-18 13:25:28 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-07-22 14:49:22 +0000 |
| commit | 6ce0983056e7e9efff04681de67e6310b88fdc16 (patch) | |
| tree | ccaa5d515f42645bc9cb9b3366c28533b6ba9b89 /pkg/manager/diff_test.go | |
| parent | 055e9354ef02e1231d7e2c369f57baf59b98011d (diff) | |
pkg/manager: add a test for PatchFocusAreas
For that, make a part of the tar_test.go reusable.
Diffstat (limited to 'pkg/manager/diff_test.go')
| -rw-r--r-- | pkg/manager/diff_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/manager/diff_test.go b/pkg/manager/diff_test.go new file mode 100644 index 000000000..f2408f13b --- /dev/null +++ b/pkg/manager/diff_test.go @@ -0,0 +1,68 @@ +// 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 manager + +import ( + "testing" + + "github.com/google/syzkaller/pkg/mgrconfig" + "github.com/google/syzkaller/pkg/osutil" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPatchFocusAreas(t *testing.T) { + cfg := &mgrconfig.Config{ + KernelSrc: t.TempDir(), + } + require.NoError(t, osutil.FillDirectory(cfg.KernelSrc, map[string]string{ + "header.h": `Test`, + "a.c": `#include <header.h> +int main(void) { }`, + "b.c": `int main(void) { }`, + "c.c": `int main(void) { }`, + })) + + PatchFocusAreas(cfg, [][]byte{ + []byte(`diff --git a/b.c b/b.c +index 103167d..fbf7a68 100644 +--- a/b.c ++++ b/b.c +@@ -1 +1 @@ +-int main(void) { } +\ 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. + []byte(`diff --git a/header.h b/header.h +index 103167d..fbf7a68 100644 +--- a/header.h ++++ b/header.h +@@ -1 +1 @@ +-Test +\ No newline at end of file ++Test2 +\ No newline at end of file`), + }) + + assert.Equal(t, []mgrconfig.FocusArea{ + { + Name: modifiedArea, + Filter: mgrconfig.CovFilterCfg{ + Files: []string{"b.c", "header.h"}, + }, + Weight: 3.0, + }, + { + Name: includesArea, + Filter: mgrconfig.CovFilterCfg{ + Files: []string{"a.c"}, + }, + Weight: 2.0, + }, + { + Weight: 1.0, + }, + }, cfg.Experimental.FocusAreas) +} |
