Skip to content

Commit ebb1853

Browse files
FlorentRevestdvyukov
authored andcommitted
tools/syz-aflow: support setting a custom cache size
This is useful to save time when iterating on syz-aflow changes. Note that this also sets a cache size of 10GB by default
1 parent b492d50 commit ebb1853

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tools/syz-aflow/aflow.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func main() {
3232
flagInput = flag.String("input", "", "input json file with workflow arguments")
3333
flagWorkdir = flag.String("workdir", "", "directory for kernel checkout, kernel builds, etc")
3434
flagModel = flag.String("model", aflow.DefaultModel, "use this LLM model")
35+
flagCacheSize = flag.String("cache-size", "10GB", "max cache size (e.g. 100MB, 5GB, 1TB)")
3536
flagDownloadBug = flag.String("download-bug", "", "extid of a bug to download from the dashboard"+
3637
" and save into -input file")
3738
)
@@ -51,12 +52,38 @@ func main() {
5152
}
5253
return
5354
}
54-
if err := run(context.Background(), *flagModel, *flagFlow, *flagInput, *flagWorkdir); err != nil {
55+
cacheSize, err := parseSize(*flagCacheSize)
56+
if err != nil {
57+
tool.Fail(err)
58+
}
59+
if err := run(context.Background(), *flagModel, *flagFlow, *flagInput, *flagWorkdir, cacheSize); err != nil {
5560
tool.Fail(err)
5661
}
5762
}
5863

59-
func run(ctx context.Context, model, flowName, inputFile, workdir string) error {
64+
func parseSize(s string) (uint64, error) {
65+
var size uint64
66+
var suffix string
67+
if _, err := fmt.Sscanf(s, "%d%s", &size, &suffix); err != nil {
68+
return 0, fmt.Errorf("failed to parse cache size %q: %w", s, err)
69+
}
70+
switch suffix {
71+
case "KB":
72+
size <<= 10
73+
case "MB":
74+
size <<= 20
75+
case "GB":
76+
size <<= 30
77+
case "TB":
78+
size <<= 40
79+
case "":
80+
default:
81+
return 0, fmt.Errorf("unknown size suffix %q", suffix)
82+
}
83+
return size, nil
84+
}
85+
86+
func run(ctx context.Context, model, flowName, inputFile, workdir string, cacheSize uint64) error {
6087
flow := aflow.Flows[flowName]
6188
if flow == nil {
6289
return fmt.Errorf("workflow %q is not found", flowName)
@@ -69,7 +96,7 @@ func run(ctx context.Context, model, flowName, inputFile, workdir string) error
6996
if err := json.Unmarshal(inputData, &inputs); err != nil {
7097
return err
7198
}
72-
cache, err := aflow.NewCache(filepath.Join(workdir, "cache"), 0)
99+
cache, err := aflow.NewCache(filepath.Join(workdir, "cache"), cacheSize)
73100
if err != nil {
74101
return err
75102
}

0 commit comments

Comments
 (0)