github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-kfuzztest/main.go (about) 1 // Copyright 2025 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 //go:build linux 5 6 package main 7 8 import ( 9 "context" 10 "flag" 11 "fmt" 12 "os" 13 14 manager "github.com/google/syzkaller/pkg/kfuzztest-manager" 15 "github.com/google/syzkaller/pkg/osutil" 16 ) 17 18 var ( 19 flagVmlinux = flag.String("vmlinux", "vmlinux", "path to vmlinux binary") 20 flagCooldown = flag.Int("cooldown", 0, "cooldown between KFuzzTest target invocations in seconds") 21 flagThreads = flag.Int("threads", 2, "number of threads") 22 flagDisplayInterval = flag.Int("display", 5, "number of seconds between console outputs") 23 ) 24 25 func main() { 26 usage := func() { 27 w := flag.CommandLine.Output() 28 fmt.Fprintf(w, "usage: %s [flags] [enabled targets]\n\n", os.Args[0]) 29 fmt.Fprintln(w, `Args: 30 One fuzz test name per enabled fuzz test arg. If empty, defaults to 31 all discovered targets.`) 32 fmt.Fprintln(w, `Example: 33 ./syz-kfuzztest -vmlinux ~/kernel/vmlinux fuzz_target_0 fuzz_target_1`) 34 fmt.Fprintln(w, "Flags:") 35 flag.PrintDefaults() 36 } 37 flag.Usage = usage 38 flag.Parse() 39 enabledTargets := flag.Args() 40 41 cfg := manager.Config{ 42 VmlinuxPath: *flagVmlinux, 43 Cooldown: uint32(*flagCooldown), 44 DisplayInterval: uint32(*flagDisplayInterval), 45 NumThreads: *flagThreads, 46 EnabledTargets: enabledTargets, 47 } 48 49 ctx, cancel := context.WithCancel(context.Background()) 50 defer cancel() 51 52 shutdownChan := make(chan struct{}) 53 osutil.HandleInterrupts(shutdownChan) 54 go func() { 55 <-shutdownChan 56 cancel() 57 }() 58 59 mgr, err := manager.NewKFuzzTestManager(ctx, cfg) 60 if err != nil { 61 panic(err) 62 } 63 mgr.Run(ctx) 64 }