aboutsummaryrefslogtreecommitdiffstats
path: root/syz-kfuzztest/main.go
blob: e46ecc257c9a2587bb3ff78ef01b551eb585c6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 main

import (
	"context"
	"flag"
	"fmt"
	"os"

	manager "github.com/google/syzkaller/pkg/kfuzztest-manager"
	"github.com/google/syzkaller/pkg/osutil"
)

var (
	flagVmlinux         = flag.String("vmlinux", "vmlinux", "path to vmlinux binary")
	flagCooldown        = flag.Int("cooldown", 0, "cooldown between KFuzzTest target invocations in seconds")
	flagThreads         = flag.Int("threads", 2, "number of threads")
	flagDisplayInterval = flag.Int("display", 5, "number of seconds between console outputs")
)

func main() {
	usage := func() {
		w := flag.CommandLine.Output()
		fmt.Fprintf(w, "usage: %s [flags] [enabled targets]\n\n", os.Args[0])
		fmt.Fprintln(w, `Args:
  One fuzz test name per enabled fuzz test arg. If empty, defaults to
  all discovered targets.`)
		fmt.Fprintln(w, `Example:
  ./syz-kfuzztest -vmlinux ~/kernel/vmlinux fuzz_target_0 fuzz_target_1`)
		fmt.Fprintln(w, "Flags:")
		flag.PrintDefaults()
	}
	flag.Usage = usage
	flag.Parse()
	enabledTargets := flag.Args()

	cfg := manager.Config{
		VmlinuxPath:     *flagVmlinux,
		Cooldown:        uint32(*flagCooldown),
		DisplayInterval: uint32(*flagDisplayInterval),
		NumThreads:      *flagThreads,
		EnabledTargets:  enabledTargets,
	}

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	shutdownChan := make(chan struct{})
	osutil.HandleInterrupts(shutdownChan)
	go func() {
		<-shutdownChan
		cancel()
	}()

	mgr, err := manager.NewKFuzzTestManager(ctx, cfg)
	if err != nil {
		panic(err)
	}
	mgr.Run(ctx)
}