Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/csource/csource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func TestGenerate(t *testing.T) {
t.Parallel()
checked := make(map[string]bool)
for _, target := range prog.AllTargets() {
// Auto-generated descriptions currently do not properly mark arch-specific syscalls, see
// https://github.com/google/syzkaller/issues/5410#issuecomment-3570190241.
// Until it's fixed, let's remove these syscalls from csource tests.
ct := target.NoAutoChoiceTable()
sysTarget := targets.Get(target.OS, target.Arch)
if runtime.GOOS != sysTarget.BuildOS {
continue
Expand All @@ -50,32 +54,32 @@ func TestGenerate(t *testing.T) {
if full || !testing.Short() {
checked[target.OS] = true
t.Parallel()
testTarget(t, target, full)
testTarget(t, target, full, ct)
}
testPseudoSyscalls(t, target)
testPseudoSyscalls(t, target, ct)
})
}
}

func testPseudoSyscalls(t *testing.T, target *prog.Target) {
func testPseudoSyscalls(t *testing.T, target *prog.Target, ct *prog.ChoiceTable) {
// Use options that are as minimal as possible.
// We want to ensure that the code can always be compiled.
opts := Options{
Slowdown: 1,
}
rs := testutil.RandSource(t)
for _, meta := range target.PseudoSyscalls() {
p := target.GenSampleProg(meta, rs)
p := target.GenSampleProg(meta, rs, ct)
t.Run(fmt.Sprintf("single_%s", meta.CallName), func(t *testing.T) {
t.Parallel()
testOne(t, p, opts)
})
}
}

func testTarget(t *testing.T, target *prog.Target, full bool) {
func testTarget(t *testing.T, target *prog.Target, full bool, ct *prog.ChoiceTable) {
rs := testutil.RandSource(t)
p := target.Generate(rs, 10, target.DefaultChoiceTable())
p := target.Generate(rs, 10, ct)
// Turns out that fully minimized program can trigger new interesting warnings,
// e.g. about NULL arguments for functions that require non-NULL arguments in syz_ functions.
// We could append both AllSyzProg as-is and a minimized version of it,
Expand Down
4 changes: 2 additions & 2 deletions prog/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ func (target *Target) PseudoSyscalls() []*Syscall {
}

// GenSampleProg generates a single sample program for the call.
func (target *Target) GenSampleProg(meta *Syscall, rs rand.Source) *Prog {
func (target *Target) GenSampleProg(meta *Syscall, rs rand.Source, ct *ChoiceTable) *Prog {
r := newRand(target, rs)
s := newState(target, target.DefaultChoiceTable(), nil)
s := newState(target, ct, nil)
p := &Prog{
Target: target,
}
Expand Down
11 changes: 11 additions & 0 deletions prog/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,17 @@ func (target *Target) DefaultChoiceTable() *ChoiceTable {
return target.defaultChoiceTable
}

func (target *Target) NoAutoChoiceTable() *ChoiceTable {
calls := map[*Syscall]bool{}
for _, c := range target.Syscalls {
if c.Attrs.Automatic {
continue
}
calls[c] = true
}
return target.BuildChoiceTable(nil, calls)
}

func (target *Target) RequiredGlobs() []string {
globs := make(map[string]bool)
ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) {
Expand Down