diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2026-01-26 16:44:09 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2026-01-26 17:04:48 +0000 |
| commit | e7922f79bc8da0b8ef96a080e463141bb5e79694 (patch) | |
| tree | 2f5905aae03c3cfd1b657d755668db6565f07972 /pkg/aflow/test_tool.go | |
| parent | cf894e043b8ae1ea6e4093d14f327ad678fa4cf3 (diff) | |
pkg/aflow: add helper for tool testing
Add simple codeeditor tests to test testing.
Diffstat (limited to 'pkg/aflow/test_tool.go')
| -rw-r--r-- | pkg/aflow/test_tool.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/aflow/test_tool.go b/pkg/aflow/test_tool.go new file mode 100644 index 000000000..4b9cb6a4a --- /dev/null +++ b/pkg/aflow/test_tool.go @@ -0,0 +1,49 @@ +// Copyright 2026 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 aflow + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestTool(t *testing.T, tool Tool, initState, initArgs, wantResults any, wantError string) { + type toolTester interface { + checkTestTypes(t *testing.T, ctx *verifyContext, state, args, results any) ( + map[string]any, map[string]any, map[string]any) + } + vctx := newVerifyContext() + state, args, results := tool.(toolTester).checkTestTypes(t, vctx, initState, initArgs, wantResults) + tool.verify(vctx) + if err := vctx.finalize(); err != nil { + t.Fatal(err) + } + // Just ensure it does not crash. + _ = tool.declaration() + // We don't init all fields, init more, if necessary. + ctx := &Context{ + state: state, + } + defer ctx.close() + gotResults, err := tool.execute(ctx, args) + gotError := "" + if err != nil { + gotError = err.Error() + } + require.Equal(t, wantError, gotError) + require.Equal(t, results, gotResults) +} + +func FuzzTool(t *testing.T, tool Tool, initState, initArgs any) (map[string]any, error) { + type toolFuzzer interface { + checkFuzzTypes(t *testing.T, state, args any) (map[string]any, map[string]any) + } + state, args := tool.(toolFuzzer).checkFuzzTypes(t, initState, initArgs) + ctx := &Context{ + state: state, + } + defer ctx.close() + return tool.execute(ctx, args) +} |
