diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-10 14:28:27 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-01-11 14:13:27 +0000 |
| commit | dda5a9889e432dc7e9efe71a39292073fa6f6c00 (patch) | |
| tree | aff1da5e8b86de5f14c9482f7c983ec34b2060f4 /prog/resources_test.go | |
| parent | 00f3cc59cbd59389deb590c4a852ea30d8c93499 (diff) | |
prog: prefer precise constructors
During resource argument generation, we used to randomly select one of
the matching resources. With so many descendants of fd, this becomes
quite inefficient and most of the time syzkaller fails to build correct
programs.
Give precise resource contructions priority. Experiment with other
resource types only in 1/3 of cases.
Diffstat (limited to 'prog/resources_test.go')
| -rw-r--r-- | prog/resources_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/prog/resources_test.go b/prog/resources_test.go index 222e93c00..ca1a25965 100644 --- a/prog/resources_test.go +++ b/prog/resources_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/google/syzkaller/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestResourceCtors(t *testing.T) { @@ -190,3 +191,23 @@ func testCreateResource(t *testing.T, target *Target, calls map[*Syscall]bool, r }) } } + +func TestPreferPreciseResources(t *testing.T) { + target, rs, _ := initRandomTargetTest(t, "test", "64") + r := newRand(target, rs) + counts := map[string]int{} + for i := 0; i < 1500; i++ { + s := newState(target, target.DefaultChoiceTable(), nil) + calls := r.generateParticularCall(s, + target.SyscallMap["test$consume_subtype_of_common"]) + for _, call := range calls { + if call.Meta.Name == "test$consume_subtype_of_common" { + continue + } + counts[call.Meta.Name]++ + } + } + assert.Greater(t, counts["test$produce_common"], 15) + assert.Greater(t, counts["test$also_produce_common"], 15) + assert.Greater(t, counts["test$produce_subtype_of_common"], 100) +} |
